Mercurial > archived > louis > epitech > mq > rathaxes
comparison rathaxes_samples_e1000_add_a_dma_abstraction.patch @ 115:5a663f8f0e54
WIP, fix another small bug in rathaxes sequence calls
author | Louis Opter <louis@lse.epita.fr> |
---|---|
date | Mon, 22 Jul 2013 13:52:00 -0700 |
parents | bfe10def90e3 |
children | f3c7e9b0c5cf |
comparison
equal
deleted
inserted
replaced
114:8eac160e5f1c | 115:5a663f8f0e54 |
---|---|
1 # HG changeset patch | 1 # HG changeset patch |
2 # Parent 0f12e80e810de1a9927db1f25dbea49acd73ae3c | 2 # Parent af7a1f8589d632497e2f2574570f5153cae59b91 |
3 e1000: start a DMA allocation/mapping abstraction | 3 e1000: start a DMA allocation/mapping abstraction |
4 | 4 |
5 It currently matches a lot the Linux DMA API but it should be usable by | 5 It currently matches a lot the Linux DMA API but it should be usable by |
6 other OSes too. The Linux DMA API is described at the end of the chapter | 6 other OSes too. The Linux DMA API is described at the end of the chapter |
7 15 in the LDD3. | 7 15 in the LDD3. |
33 ethernet.blt) | 33 ethernet.blt) |
34 diff --git a/rathaxes/samples/e1000/dma.blt b/rathaxes/samples/e1000/dma.blt | 34 diff --git a/rathaxes/samples/e1000/dma.blt b/rathaxes/samples/e1000/dma.blt |
35 new file mode 100644 | 35 new file mode 100644 |
36 --- /dev/null | 36 --- /dev/null |
37 +++ b/rathaxes/samples/e1000/dma.blt | 37 +++ b/rathaxes/samples/e1000/dma.blt |
38 @@ -0,0 +1,81 @@ | 38 @@ -0,0 +1,89 @@ |
39 +with DMA, Builtin, LKM, Device | 39 +with DMA, Builtin, LKM, Device |
40 +{ | 40 +{ |
41 + template type AbstractDMAHandle() | 41 + template type DMA::AbstractDMAHandle() |
42 + { | 42 + { |
43 + chunk LKM::includes() | 43 + chunk LKM::includes() |
44 + { | 44 + { |
45 + #include <linux/dma-mapping.h> | 45 + #include <linux/dma-mapping.h> |
46 + } | 46 + } |
50 + dma_addr_t data; | 50 + dma_addr_t data; |
51 + } | 51 + } |
52 + | 52 + |
53 + map | 53 + map |
54 + { | 54 + { |
55 + k_dma_handle: ((dma_addr_t *)${self}); | 55 + k_dma_handle: ((dma_addr_t)${self}); |
56 + } | 56 + } |
57 + } | 57 + } |
58 + | 58 + |
59 + template type AbstractDMADirection() | 59 + template type DMA::AbstractDMADirection() |
60 + { | 60 + { |
61 + decl data_types() | 61 + decl data_types() |
62 + { | 62 + { |
63 + enum dma_data_direction data; | 63 + enum dma_data_direction data; |
64 + } | 64 + } |
67 + { | 67 + { |
68 + k_dma_direction: ((enum dma_data_direction)${self}); | 68 + k_dma_direction: ((enum dma_data_direction)${self}); |
69 + } | 69 + } |
70 + } | 70 + } |
71 + | 71 + |
72 + template type DMADirection() | 72 + template type DMA::DMADirection() |
73 + { | 73 + { |
74 + decl data_types() | 74 + decl data_types() |
75 + { | 75 + { |
76 + RTX_DMA_BIDIRECTIONAL = DMA_BIDIRECTIONAL, | 76 + RTX_DMA_BIDIRECTIONAL = DMA_BIDIRECTIONAL, |
77 + RTX_DMA_TO_DEVICE = DMA_TO_DEVICE, | 77 + RTX_DMA_TO_DEVICE = DMA_TO_DEVICE, |
78 + RTX_DMA_FROM_DEVICE = DMA_FROM_DEVICE | 78 + RTX_DMA_FROM_DEVICE = DMA_FROM_DEVICE |
79 + } | 79 + } |
80 + | 80 + |
81 + map | 81 + map |
82 + { | 82 + { |
83 + /* XXX: we should use ${AbstractDMADirection} here: */ | 83 + /* XXX: we should use ${DMA::AbstractDMADirection} here: */ |
84 + dma_direction: ((enum dma_data_direction)${self}); | 84 + dma_direction: ((enum dma_data_direction)${self}); |
85 + } | 85 + } |
86 + } | 86 + } |
87 + | 87 + |
88 + template sequence map(Device::AbstractDevice dev, Builtin::symbol buf, Builtin::number size, DMADirection dir) | 88 + template sequence map(Device::AbstractDevice dev, Builtin::symbol buf, Builtin::number size, DMA::DMADirection dir) |
89 + { | 89 + { |
90 + chunk ::CALL() | 90 + chunk ::CALL() |
91 + { | 91 + { |
92 + dma_map_single(${dev.k_device}, ${buf}, ${size}, ${dir.dma_direction}); | 92 + ((${DMA::DMA::AbstractDMAHandle})dma_map_single(${dev.k_device}, ${buf}, ${size}, ${dir.dma_direction})); |
93 + } | 93 + } |
94 + } | 94 + } |
95 + | 95 + |
96 + template sequence unmap(Device::AbstractDevice dev, AbstractDMAHandle handle, Builtin::number size, DMADirection dir) | 96 + template sequence unmap(Device::AbstractDevice dev, DMA::AbstractDMAHandle handle, Builtin::number size, DMA::DMADirection dir) |
97 + { | 97 + { |
98 + chunk ::CALL() | 98 + chunk ::CALL() |
99 + { | 99 + { |
100 + dma_unmap_single(${dev.k_device}, ${handle.k_dma_handle}, ${size}, ${dir.dma_direction}); | 100 + dma_unmap_single(${dev.k_device}, ${handle.k_dma_handle}, ${size}, ${dir.dma_direction}); |
101 + } | 101 + } |
102 + } | 102 + } |
103 + | 103 + |
104 + template sequence alloc_coherent(Device::AbstractDevice dev, Builtin::number size, AbstractDMAHandle handle) | 104 + template sequence mapping_error(Device::AbstractDevice dev, DMA::AbstractDMAHandle handle) |
105 + { | |
106 + chunk ::CALL() | |
107 + { | |
108 + dma_mapping_error(${dev.k_device}, ${handle.k_dma_handle}); | |
109 + } | |
110 + } | |
111 + | |
112 + template sequence alloc_coherent(Device::AbstractDevice dev, Builtin::number size, DMA::AbstractDMAHandle handle) | |
105 + { | 113 + { |
106 + chunk ::CALL() | 114 + chunk ::CALL() |
107 + { | 115 + { |
108 + dma_alloc_coherent(${dev.k_device}, ${size}, ${handle.k_dma_handle}, GFP_KERNEL); | 116 + dma_alloc_coherent(${dev.k_device}, ${size}, &${handle.k_dma_handle}, GFP_KERNEL); |
109 + } | 117 + } |
110 + } | 118 + } |
111 + | 119 + |
112 + template sequence free_coherent(Device::AbstractDevice dev, Builtin::number size, Builtin::symbol addr, AbstractDMAHandle handle) | 120 + template sequence free_coherent(Device::AbstractDevice dev, Builtin::number size, Builtin::symbol addr, DMA::AbstractDMAHandle handle) |
113 + { | 121 + { |
114 + chunk ::CALL() | 122 + chunk ::CALL() |
115 + { | 123 + { |
116 + dma_free_coherent(${dev.k_device}, ${size}, ${addr}, ${handle.k_dma_handle}); | 124 + dma_free_coherent(${dev.k_device}, ${size}, ${addr}, ${handle.k_dma_handle}); |
117 + } | 125 + } |
119 +} | 127 +} |
120 diff --git a/rathaxes/samples/e1000/dma.rti b/rathaxes/samples/e1000/dma.rti | 128 diff --git a/rathaxes/samples/e1000/dma.rti b/rathaxes/samples/e1000/dma.rti |
121 new file mode 100644 | 129 new file mode 100644 |
122 --- /dev/null | 130 --- /dev/null |
123 +++ b/rathaxes/samples/e1000/dma.rti | 131 +++ b/rathaxes/samples/e1000/dma.rti |
124 @@ -0,0 +1,42 @@ | 132 @@ -0,0 +1,48 @@ |
125 +interface DMA : Builtin, LKM, Device | 133 +interface DMA : Builtin, LKM, Device |
126 +{ | 134 +{ |
127 + provided type AbstractDMAHandle | 135 + provided type AbstractDMAHandle |
128 + { | 136 + { |
129 + chunk LKM::includes(); | 137 + chunk LKM::includes(); |
151 + provided sequence unmap(Device::AbstractDevice, AbstractDMAHandle, Builtin::number, DMADirection) | 159 + provided sequence unmap(Device::AbstractDevice, AbstractDMAHandle, Builtin::number, DMADirection) |
152 + { | 160 + { |
153 + provided chunk ::CALL(); | 161 + provided chunk ::CALL(); |
154 + } | 162 + } |
155 + | 163 + |
164 + /* XXX: Until we have a real error handling mechanism: */ | |
165 + provided sequence mapping_error(Device::AbstractDevice, AbstractDMAHandle) | |
166 + { | |
167 + provided chunk ::CALL(); /* -> != 0 if the mapping failed */ | |
168 + } | |
169 + | |
156 + provided sequence alloc_coherent(Device::AbstractDevice, Builtin::number, AbstractDMAHandle) | 170 + provided sequence alloc_coherent(Device::AbstractDevice, Builtin::number, AbstractDMAHandle) |
157 + { | 171 + { |
158 + /* return the addr and the handle via the AbstractDMAHandle ptr: */ | 172 + /* return the addr and the handle via the AbstractDMAHandle ptr: */ |
159 + provided chunk ::CALL(); | 173 + provided chunk ::CALL(); |
160 + } | 174 + } |