Mercurial > archived > louis > epitech > mq > rathaxes
comparison rathaxes_e1000_move_the_interrupt_init_and_cleanup_into_ethernet.patch @ 104:c4c33ac02b93
First try at splitting the type nightmare and the refactoring
author | Louis Opter <louis@lse.epita.fr> |
---|---|
date | Fri, 22 Mar 2013 00:06:00 -0700 |
parents | |
children | fb20f01ea997 |
comparison
equal
deleted
inserted
replaced
103:d9af98faac8a | 104:c4c33ac02b93 |
---|---|
1 # HG changeset patch | |
2 # Parent 68c4f142af579e558314cdeebd091fc5abd62014 | |
3 | |
4 diff --git a/rathaxes/samples/e1000/e1000.blt b/rathaxes/samples/e1000/e1000.blt | |
5 --- a/rathaxes/samples/e1000/e1000.blt | |
6 +++ b/rathaxes/samples/e1000/e1000.blt | |
7 @@ -249,7 +249,6 @@ | |
8 { | |
9 int bars; | |
10 unsigned char /* __iomem */ *ioaddr; | |
11 - int irq; | |
12 | |
13 ${e1000::RxRing} rx_ring; | |
14 ${e1000::TxRing} tx_ring; | |
15 @@ -267,14 +266,12 @@ | |
16 | |
17 chunk Ethernet::adapter_init_context(Ethernet::Device rtx_ether_ctx, | |
18 Builtin::number bars, | |
19 - Builtin::symbol ioaddr, | |
20 - Builtin::number irq) | |
21 + Builtin::symbol ioaddr) | |
22 { | |
23 { | |
24 ${e1000::Context} *hw_ctx = &${rtx_ether_ctx}->hw_ctx; | |
25 hw_ctx->bars = ${bars}; | |
26 hw_ctx->ioaddr = ${ioaddr}; | |
27 - hw_ctx->irq = ${irq}; | |
28 } | |
29 } | |
30 | |
31 @@ -606,68 +603,6 @@ | |
32 } | |
33 } | |
34 | |
35 - template sequence e1000::setup_interrupt_handler(Ethernet::Device rtx_ether_ctx) | |
36 - { | |
37 - chunk LKM::includes() | |
38 - { | |
39 - #include <linux/interrupt.h> | |
40 - } | |
41 - | |
42 - chunk LKM::prototypes() | |
43 - { | |
44 - static int e1000_setup_interrupt_handler(${Ethernet::Device} *); | |
45 - } | |
46 - | |
47 - chunk LKM::code() | |
48 - { | |
49 - static int e1000_setup_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx) | |
50 - { | |
51 - int error; | |
52 - | |
53 - error = request_irq(rtx_ether_ctx->hw_ctx.irq, | |
54 - rtx_ethernet_interrupt_handler, | |
55 - IRQF_SHARED, | |
56 - ${config.name}, | |
57 - rtx_ether_ctx); | |
58 - | |
59 - if (error) | |
60 - ${Log::info("cannot register the interrupt handler")}; | |
61 - | |
62 - return error; | |
63 - } | |
64 - } | |
65 - | |
66 - chunk ::CALL() | |
67 - { | |
68 - int error = e1000_setup_interrupt_handler(${rtx_ether_ctx}); | |
69 - if (error) | |
70 - { | |
71 - return error; | |
72 - } | |
73 - } | |
74 - } | |
75 - | |
76 - template sequence free_interrupt_handler(Ethernet::Device rtx_ether_ctx) | |
77 - { | |
78 - chunk prototypes() | |
79 - { | |
80 - static void e1000_free_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx); | |
81 - } | |
82 - | |
83 - chunk code() | |
84 - { | |
85 - static void e1000_free_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx) | |
86 - { | |
87 - free_irq(rtx_ether_ctx->hw_ctx.irq, rtx_ether_ctx); | |
88 - } | |
89 - } | |
90 - | |
91 - chunk ::CALL() | |
92 - { | |
93 - e1000_free_interrupt_handler(${rtx_ether_ctx}); | |
94 - } | |
95 - } | |
96 - | |
97 template sequence activate_device_interruption(Ethernet::Device rtx_ether_ctx) | |
98 { | |
99 chunk ::CALL() | |
100 diff --git a/rathaxes/samples/e1000/e1000.rti b/rathaxes/samples/e1000/e1000.rti | |
101 --- a/rathaxes/samples/e1000/e1000.rti | |
102 +++ b/rathaxes/samples/e1000/e1000.rti | |
103 @@ -13,8 +13,7 @@ | |
104 /* Callbacks/Hooks which should probably be in the front-end: */ | |
105 chunk Ethernet::adapter_init_context(Ethernet::Device, | |
106 Builtin::number, | |
107 - Builtin::symbol, | |
108 - Builtin::number); | |
109 + Builtin::symbol); | |
110 chunk Ethernet::adapter_reset(Ethernet::Device); | |
111 chunk Ethernet::adapter_load_mac_address(Ethernet::Device); | |
112 } | |
113 @@ -85,21 +84,6 @@ | |
114 provided chunk ::CALL(); | |
115 } | |
116 | |
117 - provided sequence setup_interrupt_handler(Ethernet::Device) | |
118 - { | |
119 - provided chunk LKM::includes(); // works without this one | |
120 - provided chunk LKM::prototypes(); | |
121 - provided chunk LKM::code(); | |
122 - provided chunk ::CALL(); | |
123 - } | |
124 - | |
125 - provided sequence free_interrupt_handler(Ethernet::Device) | |
126 - { | |
127 - provided chunk LKM::prototypes(); | |
128 - provided chunk LKM::code(); | |
129 - provided chunk ::CALL(); | |
130 - } | |
131 - | |
132 provided sequence activate_device_interruption(Ethernet::Device) | |
133 { | |
134 provided chunk ::CALL(); | |
135 diff --git a/rathaxes/samples/e1000/ethernet.blt b/rathaxes/samples/e1000/ethernet.blt | |
136 --- a/rathaxes/samples/e1000/ethernet.blt | |
137 +++ b/rathaxes/samples/e1000/ethernet.blt | |
138 @@ -1,4 +1,4 @@ | |
139 -with Ethernet, PCI, LKM, Log | |
140 +with Ethernet, PCI, LKM, Log, Builtin | |
141 { | |
142 template type Ethernet::ProtocolId() | |
143 { | |
144 @@ -111,6 +111,11 @@ | |
145 | |
146 template sequence Ethernet::open(Ethernet::Device dev) | |
147 { | |
148 + chunk LKM::includes() | |
149 + { | |
150 + #include <linux/interrupt.h> | |
151 + } | |
152 + | |
153 chunk LKM::prototypes() | |
154 { | |
155 static int rtx_ethernet_open(struct net_device *); | |
156 @@ -123,9 +128,28 @@ | |
157 ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(dev); | |
158 | |
159 ${cast local.rtx_ether_ctx as Ethernet::Device}; | |
160 + | |
161 + int error; | |
162 + { | |
163 + ${Log::info("installing the interrupt handler")}; | |
164 + } | |
165 + error = request_irq(${local.rtx_ether_ctx.irq}, | |
166 + rtx_ethernet_interrupt_handler, | |
167 + IRQF_SHARED, | |
168 + ${config.name}, | |
169 + ${local.rtx_net_dev.k_net_dev}); | |
170 + if (error) | |
171 + { | |
172 + ${Log::info("Cannot register the interrupt handler")}; | |
173 + goto error; | |
174 + } | |
175 + | |
176 ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; | |
177 | |
178 return 0; | |
179 + | |
180 + error: | |
181 + return error; | |
182 } | |
183 } | |
184 } | |
185 @@ -165,7 +189,16 @@ | |
186 ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(dev); | |
187 | |
188 ${cast local.rtx_ether_ctx as Ethernet::Device}; | |
189 - ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; | |
190 + | |
191 + /* TODO: change this pointcut into a pointcut/adapter/callback: */ | |
192 + { | |
193 + ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; | |
194 + } | |
195 + | |
196 + free_irq(${local.rtx_ether_ctx.irq}, ${local.rtx_net_dev.k_net_dev}); | |
197 + { | |
198 + ${Log::info("interrupt handler free'ed")}; | |
199 + } | |
200 | |
201 return 0; | |
202 } | |
203 @@ -267,14 +300,11 @@ | |
204 */ | |
205 int bars = ${rtx_pci_dev.bars}; | |
206 unsigned char /* __iomem */ *ioaddr = ${rtx_pci_dev.ioaddr}; | |
207 - int irq = ${rtx_pci_dev.irq}; | |
208 ${cast local.bars as Builtin::number}; | |
209 - ${cast local.irq as Builtin::number}; | |
210 ${cast local.rtx_ether_ctx as Ethernet::Device}; | |
211 ${pointcut Ethernet::adapter_init_context(local.rtx_ether_ctx, | |
212 local.bars, | |
213 - local.ioaddr, | |
214 - local.irq)}; | |
215 + local.ioaddr)}; | |
216 ${pointcut Ethernet::adapter_reset(local.rtx_ether_ctx)}; | |
217 ${pointcut Ethernet::adapter_load_mac_address(local.rtx_ether_ctx)}; | |
218 memcpy(${local.rtx_ether_ctx.perm_addr}, | |
219 diff --git a/rathaxes/samples/e1000/ethernet.rti b/rathaxes/samples/e1000/ethernet.rti | |
220 --- a/rathaxes/samples/e1000/ethernet.rti | |
221 +++ b/rathaxes/samples/e1000/ethernet.rti | |
222 @@ -40,6 +40,7 @@ | |
223 | |
224 required sequence open(Ethernet::Device) | |
225 { | |
226 + provided chunk LKM::includes(); | |
227 provided chunk LKM::prototypes(); | |
228 provided chunk LKM::code(); | |
229 } | |
230 @@ -69,8 +70,7 @@ | |
231 | |
232 provided pointcut Ethernet::adapter_init_context(Ethernet::Device, | |
233 Builtin::number, | |
234 - Builtin::symbol, | |
235 - Builtin::number); | |
236 + Builtin::symbol); | |
237 provided pointcut Ethernet::adapter_reset(Ethernet::Device); | |
238 provided pointcut Ethernet::adapter_load_mac_address(Ethernet::Device); | |
239 } | |
240 diff --git a/rathaxes/samples/e1000/lkm.rtx b/rathaxes/samples/e1000/lkm.rtx | |
241 --- a/rathaxes/samples/e1000/lkm.rtx | |
242 +++ b/rathaxes/samples/e1000/lkm.rtx | |
243 @@ -4,13 +4,6 @@ | |
244 { | |
245 Log::info("opening the device"); | |
246 | |
247 - /* | |
248 - * Maybe e1000::create_device should be called from here, to be | |
249 - * more coherent. | |
250 - */ | |
251 - | |
252 - e1000::setup_interrupt_handler(dev); | |
253 - Log::info("interrupt handler installed"); | |
254 | |
255 e1000::set_up_device(dev); | |
256 Log::info("device activated"); | |
257 @@ -32,9 +25,6 @@ | |
258 */ | |
259 e1000::free_rx_tx(dev); | |
260 Log::info("free'ed up rx/tx resources"); | |
261 - | |
262 - e1000::free_interrupt_handler(dev); | |
263 - Log::info("interrupt handler free'ed"); | |
264 } | |
265 | |
266 Ethernet::interrupt_handler(Ethernet::Device dev) |