Mercurial > archived > louis > epitech > mq > rathaxes
comparison rathaxes_trying_to_fix_the_abstract_type_nightmare_in_e1000.patch @ 102:8e8aa342078b
Close the series on the slides and backup some wip on the abstract type nightmare in e1000
author | Louis Opter <louis@lse.epita.fr> |
---|---|
date | Thu, 28 Feb 2013 23:30:59 -0800 |
parents | |
children | d9af98faac8a |
comparison
equal
deleted
inserted
replaced
101:315f4f9697c6 | 102:8e8aa342078b |
---|---|
1 # HG changeset patch | |
2 # Parent 21cb4b0b59ebfc3350ded6f9cea2b44203437ab2 | |
3 diff --git a/rathaxes/samples/e1000/device.blt b/rathaxes/samples/e1000/device.blt | |
4 --- a/rathaxes/samples/e1000/device.blt | |
5 +++ b/rathaxes/samples/e1000/device.blt | |
6 @@ -18,7 +18,7 @@ | |
7 | |
8 map | |
9 { | |
10 - data: ${self}->data; | |
11 + k_device: ((struct device *)${self}); | |
12 } | |
13 } | |
14 } | |
15 diff --git a/rathaxes/samples/e1000/device.rti b/rathaxes/samples/e1000/device.rti | |
16 --- a/rathaxes/samples/e1000/device.rti | |
17 +++ b/rathaxes/samples/e1000/device.rti | |
18 @@ -5,6 +5,6 @@ | |
19 decl data_types(); | |
20 chunk LKM::includes(); | |
21 method init(); | |
22 - attribute Builtin::symbol data; | |
23 + attribute Builtin::symbol k_device; | |
24 } | |
25 } | |
26 diff --git a/rathaxes/samples/e1000/e1000.blt b/rathaxes/samples/e1000/e1000.blt | |
27 --- a/rathaxes/samples/e1000/e1000.blt | |
28 +++ b/rathaxes/samples/e1000/e1000.blt | |
29 @@ -249,7 +249,6 @@ | |
30 { | |
31 int bars; | |
32 unsigned char /* __iomem */ *ioaddr; | |
33 - int irq; | |
34 | |
35 ${e1000::RxRing} rx_ring; | |
36 ${e1000::TxRing} tx_ring; | |
37 @@ -267,14 +266,12 @@ | |
38 | |
39 chunk Ethernet::adapter_init_context(Ethernet::Device rtx_ether_ctx, | |
40 Builtin::number bars, | |
41 - Builtin::symbol ioaddr, | |
42 - Builtin::number irq) | |
43 + Builtin::symbol ioaddr) | |
44 { | |
45 { | |
46 ${e1000::Context} *hw_ctx = &${rtx_ether_ctx}->hw_ctx; | |
47 hw_ctx->bars = ${bars}; | |
48 hw_ctx->ioaddr = ${ioaddr}; | |
49 - hw_ctx->irq = ${irq}; | |
50 } | |
51 } | |
52 | |
53 @@ -606,68 +603,6 @@ | |
54 } | |
55 } | |
56 | |
57 - template sequence e1000::setup_interrupt_handler(Ethernet::Device rtx_ether_ctx) | |
58 - { | |
59 - chunk LKM::includes() | |
60 - { | |
61 - #include <linux/interrupt.h> | |
62 - } | |
63 - | |
64 - chunk LKM::prototypes() | |
65 - { | |
66 - static int e1000_setup_interrupt_handler(${Ethernet::Device} *); | |
67 - } | |
68 - | |
69 - chunk LKM::code() | |
70 - { | |
71 - static int e1000_setup_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx) | |
72 - { | |
73 - int error; | |
74 - | |
75 - error = request_irq(rtx_ether_ctx->hw_ctx.irq, | |
76 - rtx_ethernet_interrupt_handler, | |
77 - IRQF_SHARED, | |
78 - ${config.name}, | |
79 - rtx_ether_ctx); | |
80 - | |
81 - if (error) | |
82 - ${Log::info("cannot register the interrupt handler")}; | |
83 - | |
84 - return error; | |
85 - } | |
86 - } | |
87 - | |
88 - chunk ::CALL() | |
89 - { | |
90 - int error = e1000_setup_interrupt_handler(${rtx_ether_ctx}); | |
91 - if (error) | |
92 - { | |
93 - return error; | |
94 - } | |
95 - } | |
96 - } | |
97 - | |
98 - template sequence free_interrupt_handler(Ethernet::Device rtx_ether_ctx) | |
99 - { | |
100 - chunk prototypes() | |
101 - { | |
102 - static void e1000_free_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx); | |
103 - } | |
104 - | |
105 - chunk code() | |
106 - { | |
107 - static void e1000_free_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx) | |
108 - { | |
109 - free_irq(rtx_ether_ctx->hw_ctx.irq, rtx_ether_ctx); | |
110 - } | |
111 - } | |
112 - | |
113 - chunk ::CALL() | |
114 - { | |
115 - e1000_free_interrupt_handler(${rtx_ether_ctx}); | |
116 - } | |
117 - } | |
118 - | |
119 template sequence activate_device_interruption(Ethernet::Device rtx_ether_ctx) | |
120 { | |
121 chunk ::CALL() | |
122 @@ -816,12 +751,10 @@ | |
123 * Allocate the skbuffs, map them for DMA, and write their address | |
124 * in the corresponding descriptor. | |
125 */ | |
126 - ${Ethernet::AbstractDevice} *rtx_ether_dev = ${rtx_ether_ctx.net_device}; | |
127 - ${cast local.rtx_ether_dev as Ethernet::AbstractDevice}; | |
128 for (i = 0; i != ${config.rx_ring_size}; ++i) | |
129 { | |
130 - hw_ctx->rx_ring.skbuffs[i].skbuff = (${Socket::AbstractSKBuff}*) netdev_alloc_skb( | |
131 - &${rtx_ether_dev.netdev}, | |
132 + hw_ctx->rx_ring.skbuffs[i].skbuff = (${Socket::AbstractSKBuff}*)netdev_alloc_skb( | |
133 + ${rtx_ether_ctx.net_device}, | |
134 ${config.rx_buffer_len}); | |
135 if (!hw_ctx->rx_ring.skbuffs[i].skbuff) | |
136 { | |
137 @@ -830,7 +763,7 @@ | |
138 } | |
139 hw_ctx->rx_ring.skbuffs[i].dma_handle = dma_map_single( | |
140 &${rtx_ether_ctx.device}, | |
141 - &hw_ctx->rx_ring.skbuffs[i].skbuff->data, | |
142 + (struct sk_buff *)hw_ctx->rx_ring.skbuffs[i].skbuff, /* XXX leaking cast */ | |
143 ${config.rx_buffer_len}, | |
144 DMA_FROM_DEVICE); | |
145 int dma_error = dma_mapping_error(&${rtx_ether_ctx.device}, | |
146 @@ -933,7 +866,8 @@ | |
147 ${config.rx_buffer_len}, | |
148 DMA_FROM_DEVICE); | |
149 err_skbuffs_map: | |
150 - dev_kfree_skb(&hw_ctx->rx_ring.skbuffs[i].skbuff->data); | |
151 + /* XXX leaking cast: */ | |
152 + dev_kfree_skb((struct sk_buff *)hw_ctx->rx_ring.skbuffs[i].skbuff); | |
153 } | |
154 | |
155 dma_free_coherent(&${rtx_ether_ctx.device}, hw_ctx->rx_ring.size, | |
156 @@ -1042,9 +976,9 @@ | |
157 | |
158 ${Log::info("xmit: skbuff details:")}; | |
159 /* | |
160 - * skb is not expand on the bound C variable (should be rtx_skbuff), | |
161 - * which is funny because it works for the sequence template call | |
162 - * right after. | |
163 + * skb does not expand on the bound C variable (should be | |
164 + * rtx_skbuff), which is funny because it works for the | |
165 + * sequence template call right after. | |
166 */ | |
167 /* | |
168 * XXX: doesn't work (I tried to pass self explicitely too): | |
169 @@ -1077,8 +1011,8 @@ | |
170 | |
171 /* 2. Map the data */ | |
172 | |
173 - /* XXX: ${local.skb.map_to(local.devp)}; */ | |
174 - if (rtx_socket_skbuff_map(&skb, &${devp.data}, DMA_TO_DEVICE)) | |
175 + /* XXX: ${local.skb.map_to(devp.k_device)}; */ | |
176 + if (rtx_socket_skbuff_map(&skb, ${devp.k_device}, DMA_TO_DEVICE)) | |
177 { | |
178 ${Log::info("xmit: can't DMA map a SKbuff")}; | |
179 goto err_skb_map_to; | |
180 @@ -1097,7 +1031,7 @@ | |
181 err_offload: | |
182 err_skb_map_to: | |
183 /* XXX: ${local.skb.unmap_to_and_free(local.dev)}; */ | |
184 - rtx_socket_skbuff_unmap_and_free(&skb, &${devp.data}, DMA_TO_DEVICE); | |
185 + rtx_socket_skbuff_unmap_and_free(&skb, &${devp.k_device}, DMA_TO_DEVICE); | |
186 return NETDEV_TX_OK; | |
187 } | |
188 } | |
189 diff --git a/rathaxes/samples/e1000/e1000.rti b/rathaxes/samples/e1000/e1000.rti | |
190 --- a/rathaxes/samples/e1000/e1000.rti | |
191 +++ b/rathaxes/samples/e1000/e1000.rti | |
192 @@ -13,8 +13,7 @@ | |
193 /* Callbacks/Hooks which should probably be in the front-end: */ | |
194 chunk Ethernet::adapter_init_context(Ethernet::Device, | |
195 Builtin::number, | |
196 - Builtin::symbol, | |
197 - Builtin::number); | |
198 + Builtin::symbol); | |
199 chunk Ethernet::adapter_reset(Ethernet::Device); | |
200 chunk Ethernet::adapter_load_mac_address(Ethernet::Device); | |
201 } | |
202 @@ -85,21 +84,6 @@ | |
203 provided chunk ::CALL(); | |
204 } | |
205 | |
206 - provided sequence setup_interrupt_handler(Ethernet::Device) | |
207 - { | |
208 - provided chunk LKM::includes(); // works without this one | |
209 - provided chunk LKM::prototypes(); | |
210 - provided chunk LKM::code(); | |
211 - provided chunk ::CALL(); | |
212 - } | |
213 - | |
214 - provided sequence free_interrupt_handler(Ethernet::Device) | |
215 - { | |
216 - provided chunk LKM::prototypes(); | |
217 - provided chunk LKM::code(); | |
218 - provided chunk ::CALL(); | |
219 - } | |
220 - | |
221 provided sequence activate_device_interruption(Ethernet::Device) | |
222 { | |
223 provided chunk ::CALL(); | |
224 diff --git a/rathaxes/samples/e1000/ethernet.blt b/rathaxes/samples/e1000/ethernet.blt | |
225 --- a/rathaxes/samples/e1000/ethernet.blt | |
226 +++ b/rathaxes/samples/e1000/ethernet.blt | |
227 @@ -1,4 +1,4 @@ | |
228 -with Ethernet, PCI, LKM, Log | |
229 +with Ethernet, PCI, LKM, Log, Builtin | |
230 { | |
231 template type Ethernet::ProtocolId() | |
232 { | |
233 @@ -51,7 +51,7 @@ | |
234 { | |
235 decl data_types() | |
236 { | |
237 - struct net_device ndev; | |
238 + struct net_device data; | |
239 } | |
240 | |
241 chunk LKM::includes() | |
242 @@ -59,9 +59,15 @@ | |
243 #include <linux/netdevice.h> | |
244 } | |
245 | |
246 + method init(Builtin::symbol dev) | |
247 + { | |
248 + ${self} = (${Ethernet::AbstractDevice} *)${dev}; | |
249 + } | |
250 + | |
251 map | |
252 { | |
253 - netdev: ${self}->ndev; | |
254 + k_net_dev: ((struct net_device *)${self}); | |
255 + rtx_ether_ctx: netdev_priv((struct net_device *)${self}); | |
256 } | |
257 } | |
258 | |
259 @@ -88,29 +94,43 @@ | |
260 #include <linux/etherdevice.h> | |
261 } | |
262 | |
263 - method init(Ethernet::AbstractDevice net_dev, PCI::AbstractDevice pci_dev) | |
264 + /* XXX: if the first arg is not called rtx_net_dev, it breaks. */ | |
265 + method init(Ethernet::AbstractDevice rtx_net_dev, PCI::AbstractDevice pci_dev) | |
266 { | |
267 - ${self} = netdev_priv(&${net_dev.netdev}); | |
268 + ${self} = ${rtx_net_dev.rtx_ether_ctx}; | |
269 /* | |
270 * We can use -> because we know that ${self} will be always a | |
271 * pointer, but the ambiguity sucks. | |
272 */ | |
273 ${self}->pci_dev = ${pci_dev}; | |
274 - ${self}->net_dev = ${net_dev}; | |
275 + ${self}->net_dev = ${rtx_net_dev}; | |
276 } | |
277 | |
278 map | |
279 { | |
280 - device: ${self}->pci_dev->data.dev; | |
281 + /* | |
282 + * XXX: I'd like to be able to do things like: | |
283 + * device: ${self.pci_dev.k_pci_dev}->dev; | |
284 + * | |
285 + * Btw, should this be ${PCI::AbstractDevice} instead of directly | |
286 + * struct pci_dev? | |
287 + */ | |
288 + device: ((struct pci_dev *)(${self})->pci_dev)->dev; | |
289 pci_device: ${self}->pci_dev; | |
290 net_device: ${self}->net_dev; | |
291 - perm_addr: ${self}->net_dev->ndev.perm_addr; | |
292 - dev_addr: ${self}->net_dev->ndev.dev_addr; | |
293 + perm_addr: ((struct net_device *)(${self})->net_dev)->perm_addr; | |
294 + dev_addr: ((struct net_device *)(${self})->net_dev)->dev_addr; | |
295 + irq: ((struct pci_dev *)(${self})->pci_dev)->irq; | |
296 } | |
297 } | |
298 | |
299 template sequence Ethernet::open(Ethernet::Device dev) | |
300 { | |
301 + chunk LKM::includes() | |
302 + { | |
303 + #include <linux/interrupt.h> | |
304 + } | |
305 + | |
306 chunk LKM::prototypes() | |
307 { | |
308 static int rtx_ethernet_open(struct net_device *); | |
309 @@ -120,12 +140,40 @@ | |
310 { | |
311 static int rtx_ethernet_open(struct net_device *dev) | |
312 { | |
313 - ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(dev); | |
314 + /* | |
315 + * XXX The casts are here because the compiler doesn't resolve | |
316 + * "enclosed" type (e.g: local.var.enclosed) correctly. | |
317 + */ | |
318 + ${Ethernet::AbstractDevice} *rtx_net_dev; | |
319 + ${cast local.rtx_net_dev as Ethernet::AbstractDevice}; | |
320 + { /* XXX: I end up with a placeholder if I don't open a scope */ | |
321 + ${local.rtx_net_dev.init(local.dev)}; | |
322 + } | |
323 | |
324 + ${Ethernet::Device} *rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx}; | |
325 ${cast local.rtx_ether_ctx as Ethernet::Device}; | |
326 + | |
327 + int error; | |
328 + { | |
329 + ${Log::info("installing the interrupt handler")}; | |
330 + } | |
331 + error = request_irq(${local.rtx_ether_ctx.irq}, | |
332 + rtx_ethernet_interrupt_handler, | |
333 + IRQF_SHARED, | |
334 + ${config.name}, | |
335 + ${local.rtx_net_dev.k_net_dev}); | |
336 + if (error) | |
337 + { | |
338 + ${Log::info("Cannot register the interrupt handler")}; | |
339 + goto error; | |
340 + } | |
341 + | |
342 ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; | |
343 | |
344 return 0; | |
345 + | |
346 + error: | |
347 + return error; | |
348 } | |
349 } | |
350 } | |
351 @@ -162,11 +210,23 @@ | |
352 { | |
353 static int rtx_ethernet_close(struct net_device *dev) | |
354 { | |
355 - ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(dev); | |
356 + ${Ethernet::AbstractDevice} *rtx_net_dev; | |
357 + ${cast local.rtx_net_dev as Ethernet::AbstractDevice}; | |
358 + { /* XXX: I end up with a placeholder if I don't open a scope */ | |
359 + ${local.rtx_net_dev.init(local.dev)}; | |
360 + } | |
361 | |
362 + ${Ethernet::Device} *rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx}; | |
363 ${cast local.rtx_ether_ctx as Ethernet::Device}; | |
364 + | |
365 + /* TODO: change this pointcut into a pointcut/adapter/callback: */ | |
366 ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; | |
367 | |
368 + free_irq(${local.rtx_ether_ctx.irq}, ${local.rtx_net_dev.k_net_dev}); | |
369 + { | |
370 + ${Log::info("interrupt handler free'ed")}; | |
371 + } | |
372 + | |
373 return 0; | |
374 } | |
375 } | |
376 @@ -187,9 +247,13 @@ | |
377 { | |
378 static enum irqreturn rtx_ethernet_interrupt_handler(int irq, void *dev_id) | |
379 { | |
380 - ${Ethernet::Device} *rtx_ether_ctx = dev_id; | |
381 + ${Ethernet::AbstractDevice} *rtx_net_dev = dev_id; | |
382 + ${cast local.rtx_net_dev as Ethernet::AbstractDevice}; | |
383 | |
384 + ${Ethernet::Device} *rtx_ether_ctx; | |
385 ${cast local.rtx_ether_ctx as Ethernet::Device}; | |
386 + rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx}; | |
387 + | |
388 ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; | |
389 | |
390 return IRQ_NONE; | |
391 @@ -219,23 +283,26 @@ | |
392 */ | |
393 chunk PCI::pci_probe_hook(PCI::Device rtx_pci_dev) | |
394 { | |
395 + ${Ethernet::AbstractDevice} *rtx_net_dev; | |
396 ${Ethernet::Device} *rtx_ether_ctx; | |
397 - ${Ethernet::AbstractDevice} *net_dev; | |
398 - ${cast local.net_dev as Ethernet::AbstractDevice}; | |
399 + ${cast local.rtx_net_dev as Ethernet::AbstractDevice}; | |
400 | |
401 - net_dev = (${Ethernet::AbstractDevice}*) alloc_etherdev(sizeof(*rtx_ether_ctx)); | |
402 - if (!net_dev) | |
403 + /* Cast the result back into our "transparent wrapper" type */ | |
404 + rtx_net_dev = (${Ethernet::AbstractDevice}*)alloc_etherdev(sizeof(*rtx_ether_ctx)); | |
405 + if (!rtx_net_dev) | |
406 { | |
407 ${Log::info("cannot allocate the ethernet device context")}; | |
408 error = -ENOMEM; | |
409 goto fail; | |
410 } | |
411 - SET_NETDEV_DEV(&${local.net_dev.netdev}, ${rtx_pci_dev.device}); | |
412 - strlcpy(${local.net_dev.netdev}.name, ${config.ifname}, sizeof(${local.net_dev.netdev}.name)); | |
413 - ${local.net_dev.netdev}.irq = ${rtx_pci_dev.irq}; | |
414 - ${local.net_dev.netdev}.netdev_ops = &rtx_ether_ops; | |
415 + SET_NETDEV_DEV(${local.rtx_net_dev.k_net_dev}, ${rtx_pci_dev.device}); | |
416 + strlcpy(${local.rtx_net_dev.k_net_dev}->name, | |
417 + ${config.ifname}, | |
418 + sizeof(${local.rtx_net_dev.k_net_dev}->name)); | |
419 + ${local.rtx_net_dev.k_net_dev}->irq = ${rtx_pci_dev.irq}; | |
420 + ${local.rtx_net_dev.k_net_dev}->netdev_ops = &rtx_ether_ops; | |
421 | |
422 - error = register_netdev(&${local.net_dev.netdev}); | |
423 + error = register_netdev(${local.rtx_net_dev.k_net_dev}); | |
424 if (error) | |
425 { | |
426 ${Log::info("cannot register the driver in the net subsystem")}; | |
427 @@ -247,14 +314,11 @@ | |
428 * XXX: the cast is here because the compiler resolve the | |
429 * type of rtx_pci_dev.pci_device to the type of | |
430 * rtx_pci_dev instead of the type of rtx_pci_dev.pci_device. | |
431 - * | |
432 - * Also, I'm getting placeholder in the generated code if | |
433 - * I don't open a scope here. | |
434 */ | |
435 - { | |
436 - ${PCI::AbstractDevice} *rtx_pdev = ${rtx_pci_dev.pci_device}; | |
437 - ${cast local.rtx_pdev as PCI::AbstractDevice}; | |
438 - ${local.rtx_ether_ctx.init(local.net_dev, local.rtx_pdev)}; | |
439 + ${PCI::AbstractDevice} *workaround = ${rtx_pci_dev.pci_device}; | |
440 + ${cast local.workaround as PCI::AbstractDevice}; | |
441 + { /* XXX: I end up with a placeholder if I don't open a scope */ | |
442 + ${local.rtx_ether_ctx.init(local.rtx_net_dev, local.workaround)}; | |
443 } | |
444 | |
445 /* Register ourselves in the parent context: */ | |
446 @@ -267,19 +331,16 @@ | |
447 */ | |
448 int bars = ${rtx_pci_dev.bars}; | |
449 unsigned char /* __iomem */ *ioaddr = ${rtx_pci_dev.ioaddr}; | |
450 - int irq = ${rtx_pci_dev.irq}; | |
451 ${cast local.bars as Builtin::number}; | |
452 - ${cast local.irq as Builtin::number}; | |
453 ${cast local.rtx_ether_ctx as Ethernet::Device}; | |
454 ${pointcut Ethernet::adapter_init_context(local.rtx_ether_ctx, | |
455 local.bars, | |
456 - local.ioaddr, | |
457 - local.irq)}; | |
458 + local.ioaddr)}; | |
459 ${pointcut Ethernet::adapter_reset(local.rtx_ether_ctx)}; | |
460 ${pointcut Ethernet::adapter_load_mac_address(local.rtx_ether_ctx)}; | |
461 memcpy(${local.rtx_ether_ctx.perm_addr}, | |
462 ${local.rtx_ether_ctx.dev_addr}, | |
463 - ${local.net_dev.netdev}.addr_len); | |
464 + ${local.rtx_net_dev.k_net_dev}->addr_len); | |
465 } | |
466 | |
467 /* This chunk should be removed (see #26) */ | |
468 @@ -296,15 +357,15 @@ | |
469 */ | |
470 chunk PCI::pci_remove_hook(PCI::Device rtx_pci_dev) | |
471 { | |
472 - ${Ethernet::Device} *rtx_ether_ctx = ${rtx_pci_dev.context}; | |
473 - ${Ethernet::AbstractDevice} *rtx_ether_dev = (${Ethernet::AbstractDevice}*) ${local.rtx_ether_ctx.net_device}; | |
474 - | |
475 + ${Ethernet::Device} *rtx_ether_ctx = ${rtx_pci_dev.rtx_drv_context}; | |
476 + ${cast local.rtx_ether_ctx as Ethernet::Device}; /* XXX */ | |
477 BUG_ON(!rtx_ether_ctx); | |
478 | |
479 - ${cast local.rtx_ether_ctx as Ethernet::Device}; | |
480 - ${cast local.rtx_ether_dev as Ethernet::AbstractDevice}; | |
481 - unregister_netdev(&${local.rtx_ether_dev.netdev}); | |
482 - free_netdev(&${local.rtx_ether_dev.netdev}); | |
483 + ${Ethernet::AbstractDevice} *rtx_net_dev = ${local.rtx_ether_ctx.net_device}; | |
484 + ${cast local.rtx_net_dev as Ethernet::AbstractDevice}; /* XXX */ | |
485 + | |
486 + unregister_netdev(${local.rtx_net_dev.k_net_dev}); | |
487 + free_netdev(${local.rtx_net_dev.k_net_dev}); | |
488 } | |
489 | |
490 /* This chunk should be removed (see #26) */ | |
491 diff --git a/rathaxes/samples/e1000/ethernet.rti b/rathaxes/samples/e1000/ethernet.rti | |
492 --- a/rathaxes/samples/e1000/ethernet.rti | |
493 +++ b/rathaxes/samples/e1000/ethernet.rti | |
494 @@ -16,8 +16,15 @@ | |
495 provided type AbstractDevice | |
496 { | |
497 chunk LKM::includes(); | |
498 + method init(Builtin::symbol); | |
499 decl data_types(); | |
500 - attribute Builtin::symbol netdev; | |
501 + | |
502 + attribute Builtin::symbol k_net_dev; | |
503 + /* | |
504 + * XXX: should be a Ethernet::Device, but that causes a circular | |
505 + * dependency. | |
506 + */ | |
507 + attribute Builtin::symbol rtx_ether_ctx; | |
508 } | |
509 | |
510 provided type Device | |
511 @@ -34,12 +41,14 @@ | |
512 * I'd like to use better names here, but I'd like to understand the | |
513 * difference between the two first: | |
514 */ | |
515 - attribute Builtin::symbol perm_addr; | |
516 - attribute Builtin::symbol dev_addr; | |
517 + attribute Builtin::symbol perm_addr; | |
518 + attribute Builtin::symbol dev_addr; | |
519 + attribute Builtin::symbol irq; | |
520 } | |
521 | |
522 required sequence open(Ethernet::Device) | |
523 { | |
524 + provided chunk LKM::includes(); | |
525 provided chunk LKM::prototypes(); | |
526 provided chunk LKM::code(); | |
527 } | |
528 @@ -69,8 +78,7 @@ | |
529 | |
530 provided pointcut Ethernet::adapter_init_context(Ethernet::Device, | |
531 Builtin::number, | |
532 - Builtin::symbol, | |
533 - Builtin::number); | |
534 + Builtin::symbol); | |
535 provided pointcut Ethernet::adapter_reset(Ethernet::Device); | |
536 provided pointcut Ethernet::adapter_load_mac_address(Ethernet::Device); | |
537 } | |
538 diff --git a/rathaxes/samples/e1000/lkm.rtx b/rathaxes/samples/e1000/lkm.rtx | |
539 --- a/rathaxes/samples/e1000/lkm.rtx | |
540 +++ b/rathaxes/samples/e1000/lkm.rtx | |
541 @@ -4,13 +4,6 @@ | |
542 { | |
543 Log::info("opening the device"); | |
544 | |
545 - /* | |
546 - * Maybe e1000::create_device should be called from here, to be | |
547 - * more coherent. | |
548 - */ | |
549 - | |
550 - e1000::setup_interrupt_handler(dev); | |
551 - Log::info("interrupt handler installed"); | |
552 | |
553 e1000::set_up_device(dev); | |
554 Log::info("device activated"); | |
555 @@ -32,9 +25,6 @@ | |
556 */ | |
557 e1000::free_rx_tx(dev); | |
558 Log::info("free'ed up rx/tx resources"); | |
559 - | |
560 - e1000::free_interrupt_handler(dev); | |
561 - Log::info("interrupt handler free'ed"); | |
562 } | |
563 | |
564 Ethernet::interrupt_handler(Ethernet::Device dev) | |
565 diff --git a/rathaxes/samples/e1000/pci.blt b/rathaxes/samples/e1000/pci.blt | |
566 --- a/rathaxes/samples/e1000/pci.blt | |
567 +++ b/rathaxes/samples/e1000/pci.blt | |
568 @@ -16,15 +16,15 @@ | |
569 { | |
570 } | |
571 | |
572 - method set_context(Builtin::symbol ctx) | |
573 + method set_rtx_context(Builtin::symbol ctx) | |
574 { | |
575 - pci_set_drvdata(&${self}->data, ${ctx}); | |
576 + pci_set_drvdata(${self.k_pci_dev}, ${ctx}); | |
577 } | |
578 | |
579 map | |
580 { | |
581 - data: ${self}->data; | |
582 - drv_data: pci_get_drvdata(&${self}->data); | |
583 + k_pci_dev: ((struct pci_dev *)${self}); | |
584 + rtx_pci_ctx: pci_get_drvdata((struct pci_dev *)${self}); | |
585 } | |
586 } | |
587 | |
588 @@ -52,13 +52,13 @@ | |
589 int error; | |
590 ${PCI::AbstractDevice} *enable_pdev = self->pdev; | |
591 ${cast local.enable_pdev as PCI::AbstractDevice}; | |
592 - error = pci_enable_device(&${local.enable_pdev.data}); | |
593 + error = pci_enable_device(${local.enable_pdev.k_pci_dev}); | |
594 if (error) | |
595 return error; | |
596 - error = pci_request_selected_regions(&${local.enable_pdev.data}, self->bars, ${config.name}); | |
597 + error = pci_request_selected_regions(${local.enable_pdev.k_pci_dev}, self->bars, ${config.name}); | |
598 if (error) | |
599 return error; | |
600 - pci_set_master(&${local.enable_pdev.data}); | |
601 + pci_set_master(${local.enable_pdev.k_pci_dev}); | |
602 return 0; | |
603 } | |
604 | |
605 @@ -68,8 +68,8 @@ | |
606 ${cast local.disable_pdev as PCI::AbstractDevice}; | |
607 if (self->ioaddr) | |
608 iounmap(self->ioaddr); | |
609 - pci_release_selected_regions(&${local.disable_pdev.data}, self->bars); | |
610 - pci_disable_device(&${local.disable_pdev.data}); | |
611 + pci_release_selected_regions(${local.disable_pdev.k_pci_dev}, self->bars); | |
612 + pci_disable_device(${local.disable_pdev.k_pci_dev}); | |
613 } | |
614 } | |
615 | |
616 @@ -78,7 +78,7 @@ | |
617 ${PCI::AbstractDevice} * workaround = (${PCI::AbstractDevice}*)pdev; | |
618 ${cast local.workaround as PCI::AbstractDevice}; | |
619 ${self}->pdev = ${pdev}; | |
620 - ${self}->bars = pci_select_bars(&${local.workaround.data}, IORESOURCE_MEM); | |
621 + ${self}->bars = pci_select_bars(${local.workaround.k_pci_dev}, IORESOURCE_MEM); | |
622 ${self}->ioaddr = NULL; | |
623 ${self}->context = NULL; | |
624 } | |
625 @@ -97,18 +97,18 @@ | |
626 { | |
627 ${PCI::AbstractDevice} *select_ioaddr_pdev = ${self}->pdev; | |
628 ${cast local.select_ioaddr_pdev as PCI::AbstractDevice}; | |
629 - ${self}->ioaddr = pci_ioremap_bar(&${local.select_ioaddr_pdev.data}, ${bar}); | |
630 + ${self}->ioaddr = pci_ioremap_bar(${local.select_ioaddr_pdev.k_pci_dev}, ${bar}); | |
631 } | |
632 | |
633 - method set_context(Builtin::symbol ctx) | |
634 + method set_rtx_drv_context(Builtin::symbol ctx) | |
635 { | |
636 ${self}->context = ctx; | |
637 } | |
638 | |
639 map | |
640 { | |
641 - context: ${self}->context; | |
642 - device: &${self}->pdev->data.dev; | |
643 + rtx_drv_context: ${self}->context; | |
644 + device: &((struct pci_dev *)(${self})->pdev->dev); | |
645 pci_device: ${self}->pdev; | |
646 irq: ${self}->pdev->data.irq; | |
647 bars: ${self}->bars; | |
648 @@ -151,7 +151,7 @@ | |
649 ${local.rtx_pci_dev.init(local.rtx_pdev)}; | |
650 } | |
651 | |
652 - /* ${local.pdev.set_context(local.rtx_pci_dev)}; */ | |
653 + /* ${local.pdev.set_rtx_context(local.rtx_pci_dev)}; */ | |
654 pci_set_drvdata(pdev, rtx_pci_dev); | |
655 | |
656 /* ${local.rtx_pci_dev.enable()}; */ | |
657 @@ -184,7 +184,7 @@ | |
658 return 0; | |
659 | |
660 fail: | |
661 - /* ${local.pdev.set_context(NULL)}; */ | |
662 + /* ${local.pdev.set_rtx_drv_context(NULL)}; */ | |
663 pci_set_drvdata(pdev, NULL); | |
664 kfree(rtx_pci_dev); | |
665 return error; | |
666 @@ -210,7 +210,7 @@ | |
667 { | |
668 ${PCI::AbstractDevice} *rtx_pdev = (${PCI::AbstractDevice}*)pdev; | |
669 ${cast local.rtx_pdev as PCI::AbstractDevice}; | |
670 - ${PCI::Device} *rtx_pci_dev = ${rtx_pdev.drv_data}; | |
671 + ${PCI::Device} *rtx_pci_dev = ${rtx_pdev.rtx_pci_ctx}; | |
672 | |
673 BUG_ON(!rtx_pci_dev); | |
674 | |
675 diff --git a/rathaxes/samples/e1000/pci.rti b/rathaxes/samples/e1000/pci.rti | |
676 --- a/rathaxes/samples/e1000/pci.rti | |
677 +++ b/rathaxes/samples/e1000/pci.rti | |
678 @@ -10,10 +10,15 @@ | |
679 | |
680 chunk LKM::includes(); | |
681 method init(PCI::AbstractDevice); | |
682 - method set_context(Builtin::symbol); | |
683 + /* | |
684 + * XXX: the argument should be a PCI::Device but that causes a circular | |
685 + * dependency: | |
686 + */ | |
687 + method set_rtx_context(Builtin::symbol); | |
688 | |
689 - attribute Builtin::symbol data; | |
690 - attribute Builtin::symbol drv_data; | |
691 + attribute Builtin::symbol k_pci_dev; | |
692 + /* XXX: should be PCI::Device (see above point) */ | |
693 + attribute Builtin::symbol rtx_pci_ctx; | |
694 } | |
695 | |
696 provided type PCI::Device | |
697 @@ -27,9 +32,9 @@ | |
698 method enable(); | |
699 method disable(); | |
700 method select_ioaddr(Builtin::number); | |
701 - method set_context(Builtin::symbol); | |
702 + method set_rtx_drv_context(Builtin::symbol); | |
703 | |
704 - attribute Builtin::symbol context; | |
705 + attribute Builtin::symbol rtx_drv_context; | |
706 attribute Device::AbstractDevice device; | |
707 attribute PCI::AbstractDevice pci_device; | |
708 attribute Builtin::symbol ioaddr; | |
709 diff --git a/rathaxes/samples/e1000/socket.blt b/rathaxes/samples/e1000/socket.blt | |
710 --- a/rathaxes/samples/e1000/socket.blt | |
711 +++ b/rathaxes/samples/e1000/socket.blt | |
712 @@ -14,7 +14,7 @@ | |
713 | |
714 map | |
715 { | |
716 - data: ${self}->data; | |
717 + k_sk_buff: ((struct sk_buff *)${self}); | |
718 } | |
719 } | |
720 | |
721 @@ -131,22 +131,22 @@ | |
722 | |
723 method map_to(Device::AbstractDevice dev) | |
724 { | |
725 - rtx_socket_skbuff_map(${self}, &${dev.data}, DMA_TO_DEVICE); | |
726 + rtx_socket_skbuff_map(${self}, ${dev.k_device}, DMA_TO_DEVICE); | |
727 } | |
728 | |
729 method map_from(Device::AbstractDevice dev) | |
730 { | |
731 - rtx_socket_skbuff_map(${self}, &${dev.data}, DMA_FROM_DEVICE); | |
732 + rtx_socket_skbuff_map(${self}, ${dev.k_device}, DMA_FROM_DEVICE); | |
733 } | |
734 | |
735 method unmap_to_and_free(Device::AbstractDevice dev) | |
736 { | |
737 - rtx_socket_skbuff_unmap_and_free(${self}, &${dev.data}, DMA_TO_DEVICE); | |
738 + rtx_socket_skbuff_unmap_and_free(${self}, ${dev.k_device}, DMA_TO_DEVICE); | |
739 } | |
740 | |
741 method unmap_from_and_free(Device::AbstractDevice dev) | |
742 { | |
743 - rtx_socket_skbuff_unmap_and_free(${self}, &${dev.data}, DMA_FROM_DEVICE); | |
744 + rtx_socket_skbuff_unmap_and_free(${self}, ${dev.k_device}, DMA_FROM_DEVICE); | |
745 } | |
746 | |
747 map | |
748 diff --git a/rathaxes/samples/e1000/socket.rti b/rathaxes/samples/e1000/socket.rti | |
749 --- a/rathaxes/samples/e1000/socket.rti | |
750 +++ b/rathaxes/samples/e1000/socket.rti | |
751 @@ -5,7 +5,7 @@ | |
752 { | |
753 chunk LKM::includes(); | |
754 decl data_types(); | |
755 - attribute Builtin::symbol data; | |
756 + attribute Builtin::symbol k_sk_buff; | |
757 } | |
758 | |
759 provided type SKBuff |