[1] | 1 | /* |
---|
[4] | 2 | * soclib_dma.c - soclib Multi Channels DMA driver implementation |
---|
[1] | 3 | * |
---|
[4] | 4 | * Author Alain Greiner (2017) |
---|
| 5 | |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
[1] | 7 | * |
---|
[4] | 8 | * This file is part of ALMOS-MKH. |
---|
[1] | 9 | * |
---|
[4] | 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
[1] | 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
[4] | 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
[1] | 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
[4] | 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
[1] | 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[4] | 24 | #include <hal_types.h> |
---|
| 25 | #include <chdev.h> |
---|
| 26 | #include <dev_dma.h> |
---|
[1] | 27 | #include <thread.h> |
---|
| 28 | #include <soclib_dma.h> |
---|
| 29 | |
---|
[4] | 30 | /////////////////////////////////////// |
---|
| 31 | void soclib_dma_init( chdev_t * chdev ) |
---|
[1] | 32 | { |
---|
[4] | 33 | // get hardware device cluster and local pointer |
---|
| 34 | cxy_t dma_cxy = GET_CXY( chdev->base ); |
---|
| 35 | uint32_t * dma_ptr = (uint32_t *)GET_PTR( chdev->base ); |
---|
[1] | 36 | |
---|
[4] | 37 | // enable interrupts |
---|
| 38 | hal_remote_sw( XPTR( dma_cxy , dma_ptr + DMA_IRQ_DISABLED ) , 0 ); |
---|
[1] | 39 | |
---|
[4] | 40 | } // soclib_dma_init() |
---|
[1] | 41 | |
---|
[4] | 42 | ////////////////////////////////////////////////////////////////// |
---|
| 43 | void __attribute__ ((noinline)) soclib_dma_cmd( xptr_t thread_xp ) |
---|
[1] | 44 | { |
---|
[4] | 45 | xptr_t dev_xp; // extended pointer on DMA devive |
---|
| 46 | xptr_t dst_xp; // extended pointer on destination buffer |
---|
| 47 | xptr_t src_xp; // extended pointer on source buffer |
---|
| 48 | uint32_t size; // buffer size |
---|
[1] | 49 | |
---|
[4] | 50 | // get client thread cluster and local pointer |
---|
| 51 | cxy_t thread_cxy = GET_CXY( thread_xp ); |
---|
| 52 | thread_t * thread_ptr = (thread_t *)GET_PTR( thread_xp ); |
---|
[1] | 53 | |
---|
[4] | 54 | // get command arguments and extended pointer on DMA device |
---|
| 55 | dev_xp = (xptr_t)hal_remote_lwd( XPTR( thread_cxy , &thread_ptr->command.dma.dev_xp ) ); |
---|
| 56 | dst_xp = (xptr_t)hal_remote_lwd( XPTR( thread_cxy , &thread_ptr->command.dma.dst_xp ) ); |
---|
| 57 | src_xp = (xptr_t)hal_remote_lwd( XPTR( thread_cxy , &thread_ptr->command.dma.src_xp ) ); |
---|
| 58 | size = hal_remote_lw ( XPTR( thread_cxy , &thread_ptr->command.dma.size ) ); |
---|
[1] | 59 | |
---|
[4] | 60 | // get DMA device cluster and local pointer |
---|
| 61 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
| 62 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); |
---|
[1] | 63 | |
---|
[4] | 64 | // get extended pointer on SOCLIB-DMA peripheral |
---|
| 65 | xptr_t dma_xp = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->base ) ); |
---|
[1] | 66 | |
---|
[4] | 67 | // get SOCLIB_DMA device cluster and local pointer |
---|
| 68 | cxy_t dma_cxy = GET_CXY( dma_xp ); |
---|
| 69 | uint32_t * dma_ptr = (uint32_t *)GET_PTR( dma_xp ); |
---|
[1] | 70 | |
---|
[4] | 71 | // get DMA channel index and channel base address |
---|
| 72 | uint32_t * base = dma_ptr + DMA_SPAN * dev_ptr->channel; |
---|
[1] | 73 | |
---|
[4] | 74 | // split dst and src buffers addresses in two 32 bits words |
---|
| 75 | uint32_t dst_lsb = (uint32_t)(dst_xp); |
---|
| 76 | uint32_t dst_msb = (uint32_t)(dst_xp>>32); |
---|
| 77 | uint32_t src_lsb = (uint32_t)(src_xp); |
---|
| 78 | uint32_t src_msb = (uint32_t)(src_xp>>32); |
---|
[1] | 79 | |
---|
[4] | 80 | // set SOCLIB_DMA registers to start tranfer operation |
---|
| 81 | hal_remote_sw( XPTR( dma_cxy , base + DMA_SRC ) , src_lsb ); |
---|
| 82 | hal_remote_sw( XPTR( dma_cxy , base + DMA_SRC_EXT ) , src_msb ); |
---|
| 83 | hal_remote_sw( XPTR( dma_cxy , base + DMA_DST ) , dst_lsb ); |
---|
| 84 | hal_remote_sw( XPTR( dma_cxy , base + DMA_DST_EXT ) , dst_msb ); |
---|
| 85 | hal_remote_sw( XPTR( dma_cxy , base + DMA_LEN ) , size ); |
---|
[1] | 86 | |
---|
[4] | 87 | // Block and deschedule server thread |
---|
| 88 | thread_block( CURRENT_THREAD , THREAD_BLOCKED_DEV_ISR ); |
---|
| 89 | sched_yield(); |
---|
| 90 | |
---|
| 91 | } // soclib_dma_cmd() |
---|
[1] | 92 | |
---|
[4] | 93 | ///////////////////////////////////////////////////////////////// |
---|
| 94 | void __attribute__ ((noinline)) soclib_dma_isr( chdev_t * chdev ) |
---|
[1] | 95 | { |
---|
[4] | 96 | // get extended pointer on client thread |
---|
| 97 | xptr_t root = XPTR( local_cxy , &chdev->wait_root ); |
---|
| 98 | xptr_t client_xp = XLIST_FIRST_ELEMENT( root , thread_t , wait_list ); |
---|
[1] | 99 | |
---|
[4] | 100 | // get extended pointer on server thread |
---|
| 101 | xptr_t server_xp = XPTR( local_cxy , &chdev->server ); |
---|
[1] | 102 | |
---|
[4] | 103 | // get client thread cluster and local pointer |
---|
| 104 | cxy_t client_cxy = GET_CXY( client_xp ); |
---|
| 105 | thread_t * client_ptr = (thread_t *)GET_PTR( client_xp ); |
---|
[1] | 106 | |
---|
[4] | 107 | // get SOCLIB_DMA peripheral cluster and local pointer |
---|
| 108 | cxy_t dma_cxy = GET_CXY( chdev->base ); |
---|
| 109 | uint32_t * dma_ptr = (uint32_t *)GET_PTR( chdev->base ); |
---|
[1] | 110 | |
---|
[4] | 111 | // get DMA channel base address |
---|
| 112 | uint32_t * base = dma_ptr + (DMA_SPAN * chdev->channel); |
---|
[1] | 113 | |
---|
[4] | 114 | // get DMA status register |
---|
| 115 | uint32_t status = hal_remote_lw( XPTR( dma_cxy , base + DMA_LEN ) ); |
---|
[1] | 116 | |
---|
[4] | 117 | // acknowledge IRQ |
---|
| 118 | hal_remote_sw( XPTR( dma_cxy , base + DMA_RESET ) , 0 ); |
---|
[1] | 119 | |
---|
[4] | 120 | // set operation status in command |
---|
| 121 | error_t error = ( status != DMA_SUCCESS ); |
---|
| 122 | hal_remote_sw( XPTR( client_cxy , &client_ptr->command.dma.error ) , error ); |
---|
[1] | 123 | |
---|
[4] | 124 | // unblock server thread |
---|
| 125 | thread_unblock( server_xp , THREAD_BLOCKED_DEV_ISR ); |
---|
[1] | 126 | |
---|
[4] | 127 | // unblock client thread |
---|
| 128 | thread_unblock( client_xp , THREAD_BLOCKED_IO ); |
---|
[1] | 129 | |
---|
[4] | 130 | } // soclib_dma_isr() |
---|
[1] | 131 | |
---|
| 132 | |
---|
| 133 | |
---|