source: trunk/hal/tsar_mips32/drivers/soclib_dma.c @ 197

Last change on this file since 197 was 75, checked in by max@…, 7 years ago

Create the drivers/ sub-directory in each hal, and move soclib
into it. Note that soclib is not valid for x86_64, but more
changes will come.

File size: 5.0 KB
RevLine 
[75]1/*
2 * soclib_dma.c - soclib Multi Channels DMA driver implementation
3 *
4 * Author     Alain Greiner (2017)
5
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
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 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
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
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <hal_types.h>
25#include <chdev.h>
26#include <dev_dma.h>
27#include <thread.h>
28#include <soclib_dma.h>
29
30///////////////////////////////////////
31void soclib_dma_init( chdev_t * chdev )
32{
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 );
36
37    // enable interrupts
38        hal_remote_sw( XPTR( dma_cxy , dma_ptr + DMA_IRQ_DISABLED ) , 0 );
39
40} // soclib_dma_init()
41
42//////////////////////////////////////////////////////////////////
43void __attribute__ ((noinline)) soclib_dma_cmd( xptr_t thread_xp )
44{
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
49
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 );
53
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   ) );
59
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 );
63
64    // get extended pointer on SOCLIB-DMA peripheral
65    xptr_t     dma_xp = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->base ) );
66
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 );
70
71    // get DMA channel index and channel base address
72    uint32_t * base = dma_ptr + DMA_SPAN * dev_ptr->channel;
73
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);
79
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    );
86
87    // Block and deschedule server thread
88    thread_block( CURRENT_THREAD , THREAD_BLOCKED_DEV_ISR );
89    sched_yield();
90   
91} // soclib_dma_cmd()
92
93/////////////////////////////////////////////////////////////////
94void __attribute__ ((noinline)) soclib_dma_isr( chdev_t * chdev )
95{
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 );
99
100    // get extended pointer on server thread
101    xptr_t server_xp = XPTR( local_cxy , &chdev->server );
102
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 );
106
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 );
110
111    // get DMA channel base address
112    uint32_t * base = dma_ptr + (DMA_SPAN * chdev->channel);
113
114    // get DMA status register
115        uint32_t status = hal_remote_lw( XPTR( dma_cxy , base + DMA_LEN ) );   
116
117    // acknowledge IRQ
118    hal_remote_sw( XPTR( dma_cxy , base + DMA_RESET ) , 0 );
119
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 );
123
124    // unblock server thread
125    thread_unblock( server_xp , THREAD_BLOCKED_DEV_ISR );
126
127    // unblock client thread
128    thread_unblock( client_xp , THREAD_BLOCKED_IO );
129
130} // soclib_dma_isr()
131
132
133
Note: See TracBrowser for help on using the repository browser.