[518] | 1 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 2 | // File : dma_driver.h |
---|
| 3 | // Date : 01/11/2013 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
[518] | 6 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 7 | // The dma_driver.c and dma_driver.h files are part ot the GIET-VM nano-kernel. |
---|
| 8 | // This driver supports the SoCLib vci_multi_dma component. |
---|
| 9 | // |
---|
| 10 | // It can exist several DMA controlers in the architecture (one per cluster), |
---|
| 11 | // and each controller can contain several channels. |
---|
| 12 | // |
---|
| 13 | // There is (NB_CLUSTERS * NB_DMA_CHANNELS) channels, indexed by a global index: |
---|
| 14 | // dma_id = cluster_xy * NB_DMA_CHANNELS + loc_id |
---|
| 15 | // |
---|
| 16 | // A DMA channel is a private ressource allocated to a given processor. |
---|
[529] | 17 | // It is exclusively used by the kernel to speedup data transfers, and |
---|
[437] | 18 | // there is no lock protecting exclusive access to the channel. |
---|
| 19 | // As the kernel uses a polling policy on the DMA_STATUS register to detect |
---|
| 20 | // transfer completion, the DMA IRQ is not used. |
---|
| 21 | // |
---|
| 22 | // The virtual base address of the segment associated to a channel is: |
---|
| 23 | // SEG_DMA_BASE + cluster_xy * PERI_CLUSTER_INCREMENT + DMA_SPAN * channel_id |
---|
| 24 | // |
---|
[529] | 25 | // The SEG_DMA_BASE virtual address must be defined in the hard_config.h file. |
---|
[518] | 26 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 27 | |
---|
| 28 | #ifndef _GIET_DMA_DRIVER_H_ |
---|
| 29 | #define _GIET_DMA_DRIVER_H_ |
---|
| 30 | |
---|
[518] | 31 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 32 | // Multi DMA registers offset |
---|
[518] | 33 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 34 | |
---|
| 35 | enum DMA_registers |
---|
| 36 | { |
---|
| 37 | DMA_SRC = 0, |
---|
| 38 | DMA_DST = 1, |
---|
| 39 | DMA_LEN = 2, |
---|
| 40 | DMA_RESET = 3, |
---|
| 41 | DMA_IRQ_DISABLE = 4, |
---|
| 42 | DMA_SRC_EXT = 5, |
---|
| 43 | DMA_DST_EXT = 6, |
---|
| 44 | /**/ |
---|
| 45 | DMA_END = 7, |
---|
| 46 | DMA_SPAN = 8, |
---|
| 47 | }; |
---|
| 48 | |
---|
| 49 | enum SoclibDmaStatus |
---|
| 50 | { |
---|
| 51 | DMA_SUCCESS = 0, |
---|
| 52 | DMA_READ_ERROR = 1, |
---|
| 53 | DMA_IDLE = 2, |
---|
| 54 | DMA_WRITE_ERROR = 3, |
---|
| 55 | DMA_BUSY = 4, |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | |
---|
[518] | 59 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 60 | // low-level access functions |
---|
[518] | 61 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 62 | |
---|
[437] | 63 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 64 | // This function disables interrupts for one DMA channel in one cluster. |
---|
[529] | 65 | // In case of error (illegal DMA channel), an error |
---|
| 66 | // message is displayed on TTY0, and system crash. |
---|
[437] | 67 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 68 | extern void _dma_disable_irq( unsigned int cluster_xy, |
---|
| 69 | unsigned int channel_id ); |
---|
[258] | 70 | |
---|
[437] | 71 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 72 | // This function re-initialises one DMA channel in one cluster after transfer |
---|
| 73 | // completion. It actually forces the channel to return in IDLE state. |
---|
[529] | 74 | // In case of error (illegal DMA channel), an error |
---|
| 75 | // message is displayed on TTY0, and system crash. |
---|
[437] | 76 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 77 | extern void _dma_reset_channel( unsigned int cluster_xy, |
---|
[258] | 78 | unsigned int channel_id ); |
---|
| 79 | |
---|
[437] | 80 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 81 | // This function returns the status of a DMA channel in a given cluster. |
---|
| 82 | // In case of error (illegal DMA channel), an error |
---|
| 83 | // message is displayed on TTY0, and system crash. |
---|
[437] | 84 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 85 | extern void _dma_get_status( unsigned int cluster_xy, |
---|
| 86 | unsigned int channel_id, |
---|
| 87 | unsigned int* status ); |
---|
[258] | 88 | |
---|
[437] | 89 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 90 | // This function sets the physical address (including 64 bits extension) |
---|
| 91 | // for the source and destination buffers in a DMA channel in a given cluster |
---|
| 92 | // and sets the transfer size to lauch the transfer. |
---|
[529] | 93 | // In case of error (illegal DMA channel), an error |
---|
| 94 | // message is displayed on TTY0, and system crash. |
---|
[437] | 95 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[343] | 96 | extern void _dma_start_transfer( unsigned int cluster_xy, |
---|
| 97 | unsigned int channel_id, |
---|
| 98 | unsigned long long dst_paddr, |
---|
| 99 | unsigned long long src_paddr, |
---|
| 100 | unsigned int size ); |
---|
[258] | 101 | |
---|
[437] | 102 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 103 | // higher level access function |
---|
| 104 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 105 | |
---|
[518] | 106 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 107 | // This function copies a source memory buffer to a destination memory buffer, |
---|
| 108 | // using directly physical addresses. |
---|
| 109 | // This blocking function is supposed to be used by the kernel only, |
---|
| 110 | // and uses a polling policy on DMA_STATUS register to detect completion. |
---|
| 111 | // Therefore, the DMA_IRQ is NOT used. |
---|
| 112 | // The source and destination buffers base addresses must be word aligned, |
---|
| 113 | // and the buffer's size must be multiple of 4. |
---|
| 114 | // In case of error (buffer unmapped, unaligned, or DMA_STATUS error), an error |
---|
| 115 | // message is displayed on TTY0, and system crash. |
---|
[518] | 116 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[343] | 117 | extern void _dma_physical_copy( unsigned int cluster_xy, |
---|
| 118 | unsigned int channel_id, |
---|
| 119 | unsigned long long dst_paddr, |
---|
| 120 | unsigned long long src_paddr, |
---|
| 121 | unsigned int size ); |
---|
| 122 | |
---|
[518] | 123 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 124 | // This function copies a source memory buffer to a destination memory buffer, |
---|
| 125 | // making virtual to physical address translation: the MMU should be activated. |
---|
| 126 | // The source and destination buffers base addresses must be word aligned, |
---|
| 127 | // and the buffer's size must be multiple of 4. |
---|
| 128 | // In case of error (buffer unmapped, unaligned, or DMA_STATUS error), an error |
---|
| 129 | // message is displayed on TTY0, and system crash. |
---|
[518] | 130 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[343] | 131 | extern void _dma_copy( unsigned int cluster_xy, |
---|
| 132 | unsigned int channel_id, |
---|
| 133 | unsigned int dst_vaddr, |
---|
| 134 | unsigned int src_vaddr, |
---|
[258] | 135 | unsigned int size ); |
---|
| 136 | |
---|
[518] | 137 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 138 | // Interrupt Service Routine. |
---|
[518] | 139 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[320] | 140 | extern void _dma_isr( unsigned int irq_type, |
---|
| 141 | unsigned int irq_id, |
---|
| 142 | unsigned int channel ); |
---|
| 143 | |
---|
[258] | 144 | |
---|
| 145 | #endif |
---|
| 146 | |
---|
| 147 | // Local Variables: |
---|
| 148 | // tab-width: 4 |
---|
| 149 | // c-basic-offset: 4 |
---|
| 150 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 151 | // indent-tabs-mode: nil |
---|
| 152 | // End: |
---|
| 153 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 154 | |
---|