comparison rathaxes_samples_e1000_add_a_dma_abstraction.patch @ 112:bfe10def90e3

Wip
author Louis Opter <louis@lse.epita.fr>
date Fri, 19 Jul 2013 19:12:10 -0700
parents b072f682823d
children 5a663f8f0e54
comparison
equal deleted inserted replaced
111:b072f682823d 112:bfe10def90e3
7 15 in the LDD3. 7 15 in the LDD3.
8 8
9 This will be useful to remove Linux specific DMA code from 9 This will be useful to remove Linux specific DMA code from
10 e1000::set_up_device which should be only device independent code. 10 e1000::set_up_device which should be only device independent code.
11 11
12 12 diff --git a/rathaxes/samples/e1000/CMakeLists.txt b/rathaxes/samples/e1000/CMakeLists.txt
13 --- a/rathaxes/samples/e1000/CMakeLists.txt
14 +++ b/rathaxes/samples/e1000/CMakeLists.txt
15 @@ -5,6 +5,7 @@
16 log.rti
17 lkm.rti
18 device.rti
19 + dma.rti
20 pci.rti
21 socket.rti
22 ethernet.rti
23 @@ -12,8 +13,9 @@
24 BLT
25 log.blt
26 lkm.blt
27 + device.blt
28 + dma.blt
29 pci.blt
30 - device.blt
31 socket.blt
32 e1000.blt
33 ethernet.blt)
34 diff --git a/rathaxes/samples/e1000/dma.blt b/rathaxes/samples/e1000/dma.blt
35 new file mode 100644
36 --- /dev/null
37 +++ b/rathaxes/samples/e1000/dma.blt
38 @@ -0,0 +1,81 @@
39 +with DMA, Builtin, LKM, Device
40 +{
41 + template type AbstractDMAHandle()
42 + {
43 + chunk LKM::includes()
44 + {
45 + #include <linux/dma-mapping.h>
46 + }
47 +
48 + decl data_types()
49 + {
50 + dma_addr_t data;
51 + }
52 +
53 + map
54 + {
55 + k_dma_handle: ((dma_addr_t *)${self});
56 + }
57 + }
58 +
59 + template type AbstractDMADirection()
60 + {
61 + decl data_types()
62 + {
63 + enum dma_data_direction data;
64 + }
65 +
66 + map
67 + {
68 + k_dma_direction: ((enum dma_data_direction)${self});
69 + }
70 + }
71 +
72 + template type DMADirection()
73 + {
74 + decl data_types()
75 + {
76 + RTX_DMA_BIDIRECTIONAL = DMA_BIDIRECTIONAL,
77 + RTX_DMA_TO_DEVICE = DMA_TO_DEVICE,
78 + RTX_DMA_FROM_DEVICE = DMA_FROM_DEVICE
79 + }
80 +
81 + map
82 + {
83 + /* XXX: we should use ${AbstractDMADirection} here: */
84 + dma_direction: ((enum dma_data_direction)${self});
85 + }
86 + }
87 +
88 + template sequence map(Device::AbstractDevice dev, Builtin::symbol buf, Builtin::number size, DMADirection dir)
89 + {
90 + chunk ::CALL()
91 + {
92 + dma_map_single(${dev.k_device}, ${buf}, ${size}, ${dir.dma_direction});
93 + }
94 + }
95 +
96 + template sequence unmap(Device::AbstractDevice dev, AbstractDMAHandle handle, Builtin::number size, DMADirection dir)
97 + {
98 + chunk ::CALL()
99 + {
100 + dma_unmap_single(${dev.k_device}, ${handle.k_dma_handle}, ${size}, ${dir.dma_direction});
101 + }
102 + }
103 +
104 + template sequence alloc_coherent(Device::AbstractDevice dev, Builtin::number size, AbstractDMAHandle handle)
105 + {
106 + chunk ::CALL()
107 + {
108 + dma_alloc_coherent(${dev.k_device}, ${size}, ${handle.k_dma_handle}, GFP_KERNEL);
109 + }
110 + }
111 +
112 + template sequence free_coherent(Device::AbstractDevice dev, Builtin::number size, Builtin::symbol addr, AbstractDMAHandle handle)
113 + {
114 + chunk ::CALL()
115 + {
116 + dma_free_coherent(${dev.k_device}, ${size}, ${addr}, ${handle.k_dma_handle});
117 + }
118 + }
119 +}
13 diff --git a/rathaxes/samples/e1000/dma.rti b/rathaxes/samples/e1000/dma.rti 120 diff --git a/rathaxes/samples/e1000/dma.rti b/rathaxes/samples/e1000/dma.rti
14 new file mode 100644 121 new file mode 100644
15 --- /dev/null 122 --- /dev/null
16 +++ b/rathaxes/samples/e1000/dma.rti 123 +++ b/rathaxes/samples/e1000/dma.rti
17 @@ -0,0 +1,34 @@ 124 @@ -0,0 +1,42 @@
18 +interface DMA : Builtin, LKM, Device 125 +interface DMA : Builtin, LKM, Device
19 +{ 126 +{
20 + provided type AbstractDMAHandle 127 + provided type AbstractDMAHandle
21 + { 128 + {
22 + chunk LKM::includes(); 129 + chunk LKM::includes();
23 + decl data_types(); 130 + decl data_types();
24 + attribute Builtin::symbol.scalar k_dma_handle; 131 + attribute Builtin::symbol.scalar k_dma_handle;
25 + } 132 + }
26 + 133 +
27 + provided type Direction 134 + provided type AbstractDMADirection
28 + { 135 + {
29 + decl data_types(); 136 + decl data_types();
137 + attribute Builtin::symbol.scalar k_dma_direction;
30 + } 138 + }
31 + 139 +
32 + provided sequence map(Device::AbstractDevice, Builtin::symbol, Builtin::number, Direction) 140 + provided type DMADirection
33 + { 141 + {
34 + provided chunk ::CALL(); /* -> AbstractDMAHandle */ 142 + decl data_types();
143 + attribute AbstractDMADirection.scalar dma_direction;
35 + } 144 + }
36 + 145 +
37 + provided sequence unmap(Device::AbstractDevice, AbstractDMAHandle, Builtin::number, Direction) 146 + provided sequence map(Device::AbstractDevice, Builtin::symbol, Builtin::number, DMADirection)
147 + {
148 + provided chunk ::CALL(); /* -> DMAHandle */
149 + }
150 +
151 + provided sequence unmap(Device::AbstractDevice, AbstractDMAHandle, Builtin::number, DMADirection)
38 + { 152 + {
39 + provided chunk ::CALL(); 153 + provided chunk ::CALL();
40 + } 154 + }
41 + 155 +
42 + provided sequence alloc_coherent(Device::AbstractDevice, Builtin::number, Builtin::symbol) 156 + provided sequence alloc_coherent(Device::AbstractDevice, Builtin::number, AbstractDMAHandle)
43 + { 157 + {
44 + provided chunk ::CALL(); /* -> AbstractDMAHandle + addr returned via the symbol */ 158 + /* return the addr and the handle via the AbstractDMAHandle ptr: */
159 + provided chunk ::CALL();
45 + } 160 + }
46 + 161 +
47 + provided sequence free_coherent(Device::AbstractDevice, Builtin::number, Builtin::symbol, AbstractDMAHandle) 162 + provided sequence free_coherent(Device::AbstractDevice, Builtin::number, Builtin::symbol, AbstractDMAHandle)
48 + { 163 + {
49 + provided chunk ::CALL(); 164 + provided chunk ::CALL();