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

Last change on this file since 99 was 23, checked in by alain, 7 years ago

Introduce syscalls.

File size: 4.4 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 <soclib_dma.h>
35
36/////////////////////////////////////////////////////////////////////////////////////////
37// Extern global variables
38/////////////////////////////////////////////////////////////////////////////////////////
39
40extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
41
42extern chdev_icu_input_t  chdev_icu_input;   // allocated in kernel_init.c
43
44////////////////////////////////////
45void dev_dma_init( chdev_t * chdev )
46{
47    // get implementation & channel from DMA chdev descriptor
48    uint32_t impl    = chdev->impl;
49    uint32_t channel = chdev->channel;
50
51    // set chdev name
52    snprintf( chdev->name , 16 , "dma_%d_%x" , channel , local_cxy );
53
54    // set field "cmd", "isr", and call the relevant driver init function
55    if( impl == IMPL_DMA_SCL )
56    {
57        chdev->cmd = &soclib_dma_cmd;
58        chdev->isr = &soclib_dma_isr;
59        soclib_dma_init( chdev );
60    }
61    else
62    {
63        assert( false , __FUNCTION__ , "undefined DMA implementation" );
64    }
65
66    // get DMA HWI IRQ index
67    uint32_t hwi_id = chdev_icu_input.dma[channel];
68
69    // enable HWI IRQ in local ICU, and update  interrupt vector
70    // the selected core is defined by the DMA channel index
71    dev_icu_enable_irq( channel , HWI_TYPE , hwi_id , chdev );
72
73    // create server thread
74    thread_t * new_thread;
75    error_t    error;
76
77    error = thread_kernel_create( &new_thread,
78                                  THREAD_DEV,
79                                  &chdev_sequencial_server,
80                                  chdev,
81                                  cluster_select_local_core() );
82    if( error )
83    {
84        assert( false , __FUNCTION__ , "cannot create server thread" );
85    }
86
87    // initialises server field in DMA chdev descriptor
88    chdev->server = new_thread;
89   
90    // start server thread
91    thread_unblock( XPTR( local_cxy , new_thread ) , THREAD_BLOCKED_GLOBAL );
92   
93} // dev_dma_init()
94
95////////////////////////////////////////////////
96error_t dev_dma_remote_memcpy( xptr_t    dst_xp,
97                               xptr_t    src_xp,
98                               uint32_t  size )
99{
100    thread_t * this = CURRENT_THREAD;
101
102    dma_dmsg("\n[INFO] %s : enters for thread %x / dst = %l /src = %l / size = %x\n",
103              __FUNCTION__ , this->trdid , dst_xp , src_xp , size );
104
105    // select DMA channel corresponding to core lid
106    uint32_t channel = this->core->lid;
107
108    // get extended pointer on selected DMA chdev descriptor
109    xptr_t  dev_xp = chdev_dir.dma[channel];
110
111    assert( (dev_xp != XPTR_NULL) , __FUNCTION__ , "undefined DMA chdev descriptor" );
112
113    // register command in calling thread descriptor
114    this->command.dma.dev_xp  = dev_xp;
115    this->command.dma.dst_xp  = dst_xp;
116    this->command.dma.src_xp  = src_xp;
117    this->command.dma.size    = size;
118
119    // register client thread in waiting queue, activate server thread
120    // block client thread on THREAD_BLOCKED_IO and deschedule.
121    // it is re-activated by the ISR signaling IO operation completion.
122    chdev_register_command( dev_xp , this );
123
124    dma_dmsg("\n[INFO] %s : completes for thread %x / error = %d\n", 
125             __FUNCTION__ ,  this->trdid , this->command.dma.error );
126
127    // return I/O operation status from calling thread descriptor
128    return this->command.dma.error; 
129
130}  // dev_dma_remote_memcpy()
131
Note: See TracBrowser for help on using the repository browser.