comparison rathaxes_correctly_use_chunk_and_template_sequences_parameters_in_e1000.patch @ 63:b820c4604946

WIP on the e1000 sample
author Louis Opter <louis@lse.epitech.net>
date Sat, 18 Feb 2012 01:26:14 +0100
parents b43bed449cc2
children 8dc1a3bf372a
comparison
equal deleted inserted replaced
62:b43bed449cc2 63:b820c4604946
1 # HG changeset patch 1 # HG changeset patch
2 # Parent d759597ad67d463fa77467b2443120315980c70b 2 # Parent 293f1b3181e2a2339e31d7cdb0637a019b96d3cc
3 # User Louis Opter <louis@lse.epitech.net>, David Pineau <dav.pineau@gmail.com> 3 # User Louis Opter <louis@lse.epitech.net>, David Pineau <dav.pineau@gmail.com>
4 rathaxes: correctly use chunk and template sequences parameters in the e1000 sample 4 rathaxes: correctly use chunk and template sequences parameters in the e1000 sample
5 5
6 diff --git a/rathaxes/samples/e1000/e1000.blt b/rathaxes/samples/e1000/e1000.blt
7 --- a/rathaxes/samples/e1000/e1000.blt
8 +++ b/rathaxes/samples/e1000/e1000.blt
9 @@ -15,18 +15,20 @@
10
11 chunk ::decl()
12 {
13 - struct rtx_e1000_ctx
14 + /*
15 + * Yes, this typedef looks ugly but read the remark about
16 + * Ethernet::Device in ethernet.blt.
17 + */
18 + typedef struct rtx_e1000_ctx
19 {
20 int bars;
21 unsigned char /* __iomem */ *ioaddr;
22 int irq;
23 - };
24 + } *rtx_e1000_ctx_p;
25 }
26
27 - chunk ::init(bars, ioaddr)
28 + chunk ::init()
29 {
30 - ${self}.bars = ${bars};
31 - ${self}.ioaddr = ${ioaddr};
32 }
33
34 map
35 @@ -136,58 +138,74 @@
36
37 template sequence e1000::create_device()
38 {
39 - chunk Ethernet::create_device()
40 + chunk Ethernet::create_device(/* PCI::Device */ pdev, /* Ethernet::Device */ rtx_ether_ctx)
41 {
42 - rtx_ether_ctx->hw_ctx.irq = pdev->irq;
43 - rtx_ether_ctx->hw_ctx.bars = pci_select_bars(pdev, IORESOURCE_MEM);
44 - if (pci_enable_device_mem(pdev))
45 + /*
46 + * PCI init stuff:
47 + *
48 + * Some of that code should be moved in the PCI blts, also at some
49 + * point maybe we could do that completely automatically in the PCI
50 + * blts.
51 + */
52 +
53 + /*
54 + * We could have used an init function here but since we can't init
55 + * all the fields at once (see, ioaddr) and cannot call a C
56 + * function within a placeholder (${}), it wasn't really worth it.
57 + */
58 + ${rtx_ether_ctx}->bars = pci_select_bars(${pdev}, IORESOURCE_MEM);
59 + ${rtx_ether_ctx}->irq = ${pdev}->irq;
60 +
61 + if (pci_enable_device_mem(${pdev}))
62 {
63 ${Log::info("e1000::create: pci_enable_device_mem failed")};
64 }
65 -
66 - if (pci_request_selected_regions(pdev, rtx_ether_ctx->hw_ctx.bars, ${config.name}))
67 + if (pci_request_selected_regions(${pdev}, ${rtx_ether_ctx}->hw_ctx.bars, ${config.name}))
68 {
69 ${Log::info("e1000::create: pci_request_selected_regions failed")};
70 }
71 -
72 if (${config.set_master})
73 {
74 - pci_set_master(pdev);
75 + pci_set_master(${pdev});
76 }
77
78 /* 0 here is for BAR_0: */
79 - rtx_ether_ctx->hw_ctx.ioaddr = pci_ioremap_bar(pdev, 0);
80 - if (!rtx_ether_ctx->hw_ctx.ioaddr)
81 + ${rtx_ether_ctx}->hw_ctx.ioaddr = pci_ioremap_bar(${pdev}, 0);
82 + if (!${rtx_ether_ctx}->hw_ctx.ioaddr)
83 {
84 ${Log::info("e1000::create: pci_ioremap_bar failed")};
85 }
86
87 + /*
88 + * The really device specific algorithm starts here (so it should
89 + * certainly be written in the frontend):
90 + */
91 +
92 /* Reset the card */
93 - rtx_e1000_register_write32(&rtx_ether_ctx->hw_ctx, E1000_CTRL, E1000_CMD_RST);
94 + rtx_e1000_register_write32(&${rtx_ether_ctx}->hw_ctx, E1000_CTRL, E1000_CMD_RST);
95 udelay(10);
96
97 - /* Now we can load its mac address */
98 + /* Now we can load its mac address (thanks minix code) */
99 int i = 0;
100 - for (i = 0 /* < this is not generated! */; i < 3; ++i)
101 + for (i = 0 /* < this is not generated! (cnorm bug) */; i < 3; ++i)
102 {
103 - rtx_e1000_register_write32(&rtx_ether_ctx->hw_ctx, E1000_EEPROM_READ, (i << 8) | 1);
104 + rtx_e1000_register_write32(&${rtx_ether_ctx}->hw_ctx, E1000_EEPROM_READ, (i << 8) | 1);
105
106 int value;
107 - /* Should be a do { } while(); but the compiler doesn't do { } while(); yet. */
108 - value = rtx_e1000_register_read32(&rtx_ether_ctx->hw_ctx, E1000_EEPROM_READ);
109 - while ((value & (1 << 4)) == 0)
110 - value = rtx_e1000_register_read32(&rtx_ether_ctx->hw_ctx, E1000_EEPROM_READ);
111 + do
112 + value = rtx_e1000_register_read32(&${rtx_ether_ctx}->hw_ctx, E1000_EEPROM_READ);
113 + while ((value & (1 << 4)) == 0);
114 value >>= 16;
115
116 - rtx_ether_ctx->net_dev->dev_addr[i * 2] = value & 0xff;
117 - rtx_ether_ctx->net_dev->dev_addr[i * 2 + 1] = (value >> 8) & 0xff;
118 + ${rtx_ether_ctx}->net_dev->dev_addr[i * 2] = value & 0xff;
119 + ${rtx_ether_ctx}->net_dev->dev_addr[i * 2 + 1] = (value >> 8) & 0xff;
120 }
121
122 - memcpy(rtx_ether_ctx->net_dev->perm_addr,
123 - rtx_ether_ctx->net_dev->dev_addr,
124 - rtx_ether_ctx->net_dev->addr_len);
125 + memcpy(${rtx_ether_ctx}->net_dev->perm_addr,
126 + ${rtx_ether_ctx}->net_dev->dev_addr,
127 + ${rtx_ether_ctx}->net_dev->addr_len);
128
129 - { /* < mais lol. */
130 + { /* < See #10 */
131 ${Log::info("e1000::create: mac address loaded from the EEPROM")};
132 }
133 }
134 @@ -199,15 +217,14 @@
135
136 template sequence e1000::destroy_device()
137 {
138 - chunk Ethernet::destroy_device
139 + chunk Ethernet::destroy_device(/* PCI::Device */ pdev, /* Ethernet::Device */ rtx_ether_ctx)
140 {
141 /*
142 * Here, we should have some checks to avoid to free resources that
143 * haven't been allocated. (e.g: in case of previous errors).
144 */
145 - struct rtx_ethernet_dev* rtx_ether_ctx = netdev_priv(net_dev);
146 - iounmap(rtx_ether_ctx->hw_ctx.ioaddr);
147 - pci_release_selected_regions(pdev, rtx_ether_ctx->hw_ctx.bars);
148 + iounmap(${rtx_ether_ctx}->hw_ctx.ioaddr);
149 + pci_release_selected_regions(${pdev}, ${rtx_ether_ctx}->hw_ctx.bars);
150 }
151
152 chunk ::CALL
153 @@ -275,7 +292,7 @@
154
155 chunk ::CALL()
156 {
157 - rtx_e1000_register_read32(&${ctx}, ${reg_offset});
158 + rtx_e1000_register_read32(${ctx}, ${reg_offset});
159 }
160 }
161
162 @@ -296,7 +313,7 @@
163
164 chunk ::CALL()
165 {
166 - rtx_e1000_register_write32(&${ctx}, ${reg_offset});
167 + rtx_e1000_register_write32(${ctx}, ${reg_offset});
168 }
169 }
170
171 @@ -320,7 +337,7 @@
172 }
173 }
174
175 - template sequence e1000::setup_interrupt_handler()
176 + template sequence e1000::setup_interrupt_handler(Ethernet::Device ctx)
177 {
178 chunk LKM::includes()
179 {
180 @@ -352,13 +369,13 @@
181 }
182 }
183
184 - chunk ::CALL()
185 + chunk ::CALL
186 {
187 // this is an hack for the scope
188 (void)1;
189 {
190 int error;
191 - error = e1000_setup_interrupt_handler(rtx_ether_dev);
192 + error = e1000_setup_interrupt_handler(${ctx});
193 if (error)
194 {
195 return error;
196 diff --git a/rathaxes/samples/e1000/e1000.rti b/rathaxes/samples/e1000/e1000.rti
197 --- a/rathaxes/samples/e1000/e1000.rti
198 +++ b/rathaxes/samples/e1000/e1000.rti
199 @@ -1,25 +1,22 @@
200 interface e1000 : Socket, Ethernet, PCI, LKM
201 {
202 provided type e1000::Context;
203 + /*
204 + * These two types should actually be registers definitions in the frontend:
205 + */
206 provided type e1000::Register;
207 provided type e1000::Commands;
208
209 - /*
210 - * This sequence should receive an argument like Ethernet::Device, but it is
211 - * unclear about how this argument should be bound to a variable/argument in
212 - * the instrumented C code.
213 - *
214 - * Here again, we rely on the fact that *we* wrote the parent context and
215 - * named the C variables we need/use with the same name everywhere.
216 - */
217 provided sequence e1000::create_device()
218 {
219 + /* should take PCI::Device and Ethernet::Device args: */
220 provided chunk Ethernet::create_device;
221 provided chunk ::CALL;
222 }
223
224 provided sequence e1000::destroy_device()
225 {
226 + /* should take PCI::Device and Ethernet::Device args: */
227 provided chunk Ethernet::destroy_device;
228 provided chunk ::CALL;
229 }
230 @@ -35,9 +32,9 @@
231 provided chunk ::CALL;
232 }
233
234 - provided sequence e1000::setup_interrupt_handler()
235 + provided sequence e1000::setup_interrupt_handler(Ethernet::Device)
236 {
237 - provided chunk LKM::includes; // work without this one
238 + provided chunk LKM::includes; // works without this one
239 provided chunk LKM::prototypes;
240 provided chunk LKM::code;
241 provided chunk ::CALL;
6 diff --git a/rathaxes/samples/e1000/ethernet.blt b/rathaxes/samples/e1000/ethernet.blt 242 diff --git a/rathaxes/samples/e1000/ethernet.blt b/rathaxes/samples/e1000/ethernet.blt
7 --- a/rathaxes/samples/e1000/ethernet.blt 243 --- a/rathaxes/samples/e1000/ethernet.blt
8 +++ b/rathaxes/samples/e1000/ethernet.blt 244 +++ b/rathaxes/samples/e1000/ethernet.blt
9 @@ -1,5 +1,10 @@ 245 @@ -1,5 +1,10 @@
10 with Ethernet, PCI, LKM, Log 246 with Ethernet, PCI, LKM, Log
96 - error = 0; 332 - error = 0;
97 + /* Initialize the net_device structure */ 333 + /* Initialize the net_device structure */
98 net_dev = alloc_etherdev(sizeof(*rtx_ether_ctx)); 334 net_dev = alloc_etherdev(sizeof(*rtx_ether_ctx));
99 if (net_dev == 0) 335 if (net_dev == 0)
100 { 336 {
101 @@ -152,53 +172,42 @@ 337 @@ -152,64 +172,54 @@
102 /* 338 /*
103 * Again, the error should be "raised" in the parent context. 339 * Again, the error should be "raised" in the parent context.
104 * 340 *
105 - * Here we know that we should return ENOMEM because *we* wrote 341 - * Here we know that we should return ENOMEM because *we* wrote
106 + * Here we know that we can return ENOMEM because *we* wrote 342 + * Here we know that we can return ENOMEM because *we* wrote
141 - /* same problem as above with ${pdev} */ 377 - /* same problem as above with ${pdev} */
142 - //pci_set_drvdata(${pdev}, net_dev); 378 - //pci_set_drvdata(${pdev}, net_dev);
143 - pci_set_drvdata(pdev, net_dev); 379 - pci_set_drvdata(pdev, net_dev);
144 + /* Initialize our context held by the net_device structure */ 380 + /* Initialize our context held by the net_device structure */
145 + ${rtx_ether_ctx.init(local.net_dev, pdev)}; 381 + ${rtx_ether_ctx.init(local.net_dev, pdev)};
382
383 - ${pointcut Ethernet::create_device};
384 + pci_set_drvdata(${pdev}, net_dev);
146 + 385 +
147 + pci_set_drvdata(${pdev}, net_dev); 386 + ${pointcut Ethernet::create_device(pdev, local.rtx_ether_ctx)};
148 387 }
149 ${pointcut Ethernet::create_device}; 388
150 } 389 + /* This chunk should be removed (see #26) */
151
152 + /* This chunk should be remove (see #26) */
153 chunk ::CALL 390 chunk ::CALL
154 { 391 {
155 } 392 }
156 } 393 }
157 394
160 { 397 {
161 - chunk PCI::pci_remove_hook() 398 - chunk PCI::pci_remove_hook()
162 + chunk PCI::pci_remove_hook(/* PCI::Device */ pdev) 399 + chunk PCI::pci_remove_hook(/* PCI::Device */ pdev)
163 { 400 {
164 - struct net_device *net_dev = pci_get_drvdata(pdev); 401 - struct net_device *net_dev = pci_get_drvdata(pdev);
402 + /* workaround for cnorm unstrict */
403 + typedef int ${Ethernet::device};
404
405 - ${pointcut Ethernet::destroy_device};
165 + struct net_device *net_dev = pci_get_drvdata(${pdev}); 406 + struct net_device *net_dev = pci_get_drvdata(${pdev});
166 407 + ${Ethernet::device} rtx_ether_ctx = netdev_priv(net_dev);
167 ${pointcut Ethernet::destroy_device}; 408 +
168 409 + ${pointcut Ethernet::destroy_device(pdev, local.rtx_ether_ctx)};
169 @@ -210,6 +219,7 @@ 410
411 unregister_netdev(net_dev);
412 - /*
413 - * If we had some cleanup todo with struct rtx_ether_ctx we would
414 - * do a netdev_priv(net_dev) here and do it.
415 - */
170 free_netdev(net_dev); 416 free_netdev(net_dev);
171 } 417 }
172 418
173 + /* This chunk should be remove (see #26) */ 419 + /* This chunk should be removed (see #26) */
174 chunk ::CALL 420 chunk ::CALL
175 { 421 {
176 } 422 }
177 diff --git a/rathaxes/samples/e1000/ethernet.rti b/rathaxes/samples/e1000/ethernet.rti 423 diff --git a/rathaxes/samples/e1000/ethernet.rti b/rathaxes/samples/e1000/ethernet.rti
178 --- a/rathaxes/samples/e1000/ethernet.rti 424 --- a/rathaxes/samples/e1000/ethernet.rti
179 +++ b/rathaxes/samples/e1000/ethernet.rti 425 +++ b/rathaxes/samples/e1000/ethernet.rti
180 @@ -28,18 +28,16 @@ 426 @@ -28,19 +28,17 @@
181 provided chunk LKM::code; 427 provided chunk LKM::code;
182 } 428 }
183 429
184 - provided sequence Ethernet::init(PCI::Device) 430 - provided sequence Ethernet::init(PCI::Device)
185 + provided sequence Ethernet::init() 431 + provided sequence Ethernet::init()
186 { 432 {
187 provided chunk LKM::data; 433 provided chunk LKM::data;
188 provided chunk PCI::pci_probe_hook; 434 - provided chunk PCI::pci_probe_hook;
189 - provided chunk ::CALL; 435 - provided chunk ::CALL;
436 + provided chunk PCI::pci_probe_hook; /* should take a PCI::Device arg */
190 437
191 provided pointcut Ethernet::create_device; 438 provided pointcut Ethernet::create_device;
192 } 439 }
193 440
194 - provided sequence Ethernet::exit(PCI::Device) 441 - provided sequence Ethernet::exit(PCI::Device)
195 + provided sequence Ethernet::exit() 442 + provided sequence Ethernet::exit()
196 { 443 {
197 - provided chunk ::CALL; 444 - provided chunk ::CALL;
198 provided chunk PCI::pci_remove_hook; 445 - provided chunk PCI::pci_remove_hook;
446 + provided chunk PCI::pci_remove_hook; /* should take a PCI::Device arg */
199 447
200 provided pointcut Ethernet::destroy_device; 448 provided pointcut Ethernet::destroy_device;
449 }
450 diff --git a/rathaxes/samples/e1000/lkm.rtx b/rathaxes/samples/e1000/lkm.rtx
451 --- a/rathaxes/samples/e1000/lkm.rtx
452 +++ b/rathaxes/samples/e1000/lkm.rtx
453 @@ -3,7 +3,7 @@
454 Ethernet::open(Ethernet::Device dev)
455 {
456 Log::info("Open the device");
457 - e1000::setup_interrupt_handler();
458 + e1000::setup_interrupt_handler(dev);
459 Log::info("Interrupt handler installed");
460 e1000::set_up_device();
461 e1000::activate_device_interruption();
201 diff --git a/rathaxes/samples/e1000/pci.blt b/rathaxes/samples/e1000/pci.blt 462 diff --git a/rathaxes/samples/e1000/pci.blt b/rathaxes/samples/e1000/pci.blt
202 --- a/rathaxes/samples/e1000/pci.blt 463 --- a/rathaxes/samples/e1000/pci.blt
203 +++ b/rathaxes/samples/e1000/pci.blt 464 +++ b/rathaxes/samples/e1000/pci.blt
204 @@ -22,7 +22,7 @@ 465 @@ -22,7 +22,7 @@
205 } 466 }
277 - provided sequence PCI::probe(PCI::Device) 538 - provided sequence PCI::probe(PCI::Device)
278 + provided sequence PCI::probe() 539 + provided sequence PCI::probe()
279 { 540 {
280 provided chunk LKM::prototypes; 541 provided chunk LKM::prototypes;
281 provided chunk LKM::code; 542 provided chunk LKM::code;
282 @@ -26,7 +26,7 @@ 543 @@ -26,11 +26,11 @@
283 provided pointcut PCI::pci_probe_hook; 544 provided pointcut PCI::pci_probe_hook;
284 } 545 }
285 546
286 - provided sequence PCI::remove(PCI::Device) 547 - provided sequence PCI::remove(PCI::Device)
287 + provided sequence PCI::remove() 548 + provided sequence PCI::remove()
288 { 549 {
289 provided chunk LKM::prototypes; 550 provided chunk LKM::prototypes;
290 provided chunk LKM::code; 551 provided chunk LKM::code;
552
553 - provided pointcut PCI::pci_remove_hook;
554 + provided pointcut PCI::pci_remove_hook; /* Should take a PCI::Device arg */
555 }
556 }