source: trunk/kernel/devices/dev_dma.c @ 261

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

Hide soclib_dma.

File size: 3.9 KB
Line 
1/*
2 * dev_dma.c - DMA (Interrupt Controler Unit) generic device API implementation.
3 *
4 * Authors   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 PARTDMALAR 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 <hal_special.h>
26#include <chdev.h>
27#include <thread.h>
28#include <cluster.h>
29#include <printk.h>
30#include <memcpy.h>
31#include <spinlock.h>
32#include <soclib_dma.h>
33#include <dev_dma.h>
34#include <hal_drivers.h>
35
36/////////////////////////////////////////////////////////////////////////////////////////
37// Extern global variables
38/////////////////////////////////////////////////////////////////////////////////////////
39
40extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
41
42//////////////////////////////////
43void dev_dma_init( chdev_t * dma )
44{
45    // get implementation & channel from DMA dma descriptor
46    uint32_t impl    = dma->impl;
47    uint32_t channel = dma->channel;
48
49    // set dma name
50    snprintf( dma->name , 16 , "dma_%d_%x" , channel , local_cxy );
51
52    // call driver init function
53    hal_drivers_dma_init( dma, impl );
54
55    // bind IRQ to the core defined by the DMA channel
56    dev_pic_bind_irq( channel , dma );
57
58    // enable IRQ
59    dev_pic_enable_irq( channel, XPTR( local_cxy , dma ) );
60
61    // create server thread
62    thread_t * new_thread;
63    error_t    error;
64
65    error = thread_kernel_create( &new_thread,
66                                  THREAD_DEV,
67                                  &chdev_sequencial_server,
68                                  dma,
69                                  cluster_select_local_core() );
70    if( error )
71    {
72        assert( false , __FUNCTION__ , "cannot create server thread" );
73    }
74
75    // initialises server field in DMA chdev descriptor
76    dma->server = new_thread;
77   
78    // start server thread
79    thread_unblock( XPTR( local_cxy , new_thread ) , THREAD_BLOCKED_GLOBAL );
80
81} // dev_dma_init()
82
83////////////////////////////////////////////////
84error_t dev_dma_remote_memcpy( xptr_t    dst_xp,
85                               xptr_t    src_xp,
86                               uint32_t  size )
87{
88    thread_t * this = CURRENT_THREAD;
89
90    dma_dmsg("\n[INFO] %s : enters for thread %x / dst = %l /src = %l / size = %x\n",
91              __FUNCTION__ , this->trdid , dst_xp , src_xp , size );
92
93    // select DMA channel corresponding to core lid
94    uint32_t channel = this->core->lid;
95
96    // get extended pointer on selected DMA chdev descriptor
97    xptr_t  dev_xp = chdev_dir.dma[channel];
98
99    assert( (dev_xp != XPTR_NULL) , __FUNCTION__ , "undefined DMA chdev descriptor" );
100
101    // register command in calling thread descriptor
102    this->command.dma.dev_xp  = dev_xp;
103    this->command.dma.dst_xp  = dst_xp;
104    this->command.dma.src_xp  = src_xp;
105    this->command.dma.size    = size;
106
107    // register client thread in waiting queue, activate server thread
108    // block client thread on THREAD_BLOCKED_IO and deschedule.
109    // it is re-activated by the ISR signaling IO operation completion.
110    chdev_register_command( dev_xp , this );
111
112    dma_dmsg("\n[INFO] %s : completes for thread %x / error = %d\n", 
113             __FUNCTION__ ,  this->trdid , this->command.dma.error );
114
115    // return I/O operation status from calling thread descriptor
116    return this->command.dma.error; 
117
118}  // dev_dma_remote_memcpy()
119
Note: See TracBrowser for help on using the repository browser.