Mercurial > archived > louis > epitech > mq > rathaxes
comparison rathaxes_rewrite_create_and_destroy_device_in_the_e1000_sample.patch @ 99:e2c237d6c37b
Update patches against David's new decl system
author | Louis Opter <louis@lse.epita.fr> |
---|---|
date | Thu, 22 Nov 2012 22:47:25 -0800 |
parents | ffdb018893e2 |
children |
comparison
equal
deleted
inserted
replaced
98:147519512c3d | 99:e2c237d6c37b |
---|---|
1 # HG changeset patch | 1 # HG changeset patch |
2 # Parent d65cd0228e5c25692e6f37d0524e61ae26102a33 | 2 # Parent 23c454cb9c1efef0cdcb239505343e893bcd6303 |
3 rathaxes: rehaul the device initialization/destruction in the e1000 sample | 3 rathaxes: rehaul the device initialization/destruction in the e1000 sample |
4 | 4 |
5 - Add several chunks on the e1000::Context; these chunks perform | 5 - Add several chunks on the e1000::Context; these chunks perform |
6 low-level, device-dependant operations and should be move in the | 6 low-level, device-dependant operations and should be move in the |
7 front-end at some point. They weave into pointcuts defined by the | 7 front-end at some point. They weave into pointcuts defined by the |
19 -with e1000, Ethernet, Socket, PCI, LKM, Log | 19 -with e1000, Ethernet, Socket, PCI, LKM, Log |
20 +with e1000, Ethernet, Socket, PCI, LKM, Log, Builtin | 20 +with e1000, Ethernet, Socket, PCI, LKM, Log, Builtin |
21 { | 21 { |
22 template type e1000::RxDescriptor() | 22 template type e1000::RxDescriptor() |
23 { | 23 { |
24 @@ -268,6 +268,22 @@ | 24 @@ -251,22 +251,8 @@ |
25 | 25 |
26 template type e1000::Context() | 26 template type e1000::Context() |
27 { | 27 { |
28 + chunk ::decl() | 28 - chunk Ethernet::SubContext() |
29 + { | 29 - { |
30 + struct rtx_e1000_ctx | 30 - /* |
31 + { | 31 - * Force the generation of the structure in the "headers" part, we |
32 + int bars; | 32 - * have to do this since we do not use the structure in this blt |
33 + unsigned char /* __iomem */ *ioaddr; | 33 - * (we hacked a bit and used it in ethernet.blt directly). |
34 + unsigned int irq; | 34 - */ |
35 + | 35 - ${e1000::Context} hw_ctx; |
36 + /* we can't use the Rathaxes type here (#8) */ | 36 - } |
37 + //${e1000::RxRing} rx_ring; | 37 - |
38 + //${e1000::TxRing} tx_ring; | 38 decl data_types() |
39 + struct rtx_e1000_rx_ring rx_ring; | |
40 + struct rtx_e1000_tx_ring tx_ring; | |
41 + }; | |
42 + } | |
43 + | |
44 chunk Ethernet::SubContext() | |
45 { | |
46 /* | |
47 @@ -278,28 +294,58 @@ | |
48 ${e1000::Context} hw_ctx; | |
49 } | |
50 | |
51 - chunk ::decl() | |
52 + chunk Ethernet::adapter_init_context(Ethernet::Device rtx_ether_ctx, | |
53 + Builtin::number bars, | |
54 + Builtin::symbol ioaddr, | |
55 + Builtin::number irq) | |
56 { | 39 { |
57 - /* | 40 - /* |
58 - * Yes, this typedef looks ugly but read the remark about | 41 - * Yes, this typedef looks ugly but read the remark about |
59 - * Ethernet::Device in ethernet.blt. | 42 - * Ethernet::Device in ethernet.blt. |
60 - */ | 43 - */ |
61 - struct rtx_e1000_ctx | 44 struct rtx_e1000_ctx |
62 { | 45 { |
63 - int bars; | 46 int bars; |
64 - unsigned char /* __iomem */ *ioaddr; | 47 @@ -281,8 +267,68 @@ |
65 - int irq; | 48 }; |
66 - | 49 } |
67 - /* we can't use the Rathaxes type here (#8) */ | 50 |
68 - //${e1000::RxRing} rx_ring; | 51 - method init() |
69 - //${e1000::TxRing} tx_ring; | 52 + chunk Ethernet::SubContext() |
70 - struct rtx_e1000_rx_ring rx_ring; | 53 { |
71 - struct rtx_e1000_tx_ring tx_ring; | 54 + /* |
72 - }; | 55 + * Force the generation of the structure in the "headers" part, we |
56 + * have to do this since we do not use the structure in this blt | |
57 + * (we hacked a bit and used it in ethernet.blt directly). | |
58 + */ | |
59 + ${e1000::Context} hw_ctx; | |
60 + } | |
61 + | |
62 + chunk Ethernet::adapter_init_context(Ethernet::Device rtx_ether_ctx, | |
63 + Builtin::number bars, | |
64 + Builtin::symbol ioaddr, | |
65 + Builtin::number irq) | |
66 + { | |
67 + { | |
73 + struct rtx_e1000_ctx *hw_ctx = &${rtx_ether_ctx}->hw_ctx; | 68 + struct rtx_e1000_ctx *hw_ctx = &${rtx_ether_ctx}->hw_ctx; |
74 + hw_ctx->bars = ${bars}; | 69 + hw_ctx->bars = ${bars}; |
75 + hw_ctx->ioaddr = ${ioaddr}; | 70 + hw_ctx->ioaddr = ${ioaddr}; |
76 + hw_ctx->irq = ${irq}; | 71 + hw_ctx->irq = ${irq}; |
77 + } | 72 + } |
78 } | 73 + } |
79 | 74 + |
80 - chunk ::init() | |
81 + chunk Ethernet::adapter_reset(Ethernet::Device rtx_ether_ctx) | 75 + chunk Ethernet::adapter_reset(Ethernet::Device rtx_ether_ctx) |
82 { | 76 + { |
83 + { | 77 + { |
84 + struct rtx_e1000_ctx *hw_ctx = &${rtx_ether_ctx}->hw_ctx; | 78 + struct rtx_e1000_ctx *hw_ctx = &${rtx_ether_ctx}->hw_ctx; |
85 + rtx_e1000_register_write32(hw_ctx, E1000_CTRL, E1000_CMD_RST); | 79 + rtx_e1000_register_write32(hw_ctx, E1000_CTRL, E1000_CMD_RST); |
86 + udelay(10); | 80 + udelay(10); |
87 + } | 81 + } |
118 + ${Log::info("e1000::create: mac address loaded from the EEPROM")}; | 112 + ${Log::info("e1000::create: mac address loaded from the EEPROM")}; |
119 + } | 113 + } |
120 } | 114 } |
121 | 115 |
122 map | 116 map |
123 @@ -477,91 +523,6 @@ | 117 @@ -445,91 +491,6 @@ |
124 } | 118 } |
125 } | 119 } |
126 | 120 |
127 - template sequence e1000::create_device() | 121 - template sequence e1000::create_device() |
128 - { | 122 - { |
222 - required variable Builtin::symbol set_master; | 216 - required variable Builtin::symbol set_master; |
223 - | 217 - |
224 required variable Builtin::number rx_ring_size; | 218 required variable Builtin::number rx_ring_size; |
225 required variable Builtin::number tx_ring_size; | 219 required variable Builtin::number tx_ring_size; |
226 required variable Builtin::number rx_buffer_len; | 220 required variable Builtin::number rx_buffer_len; |
227 @@ -10,9 +7,18 @@ | 221 @@ -13,6 +10,14 @@ |
228 | |
229 provided type Context | |
230 { | |
231 + method decl(); | |
232 + | |
233 chunk Ethernet::SubContext(); | 222 chunk Ethernet::SubContext(); |
234 - method decl(); | 223 decl data_types(); |
235 - method init(); | 224 method init(); |
236 + | 225 + |
237 + /* Callbacks/Hooks which should probably be in the front-end: */ | 226 + /* Callbacks/Hooks which should probably be in the front-end: */ |
238 + chunk Ethernet::adapter_init_context(Ethernet::Device, | 227 + chunk Ethernet::adapter_init_context(Ethernet::Device, |
239 + Builtin::number, | 228 + Builtin::number, |
240 + Builtin::symbol, | 229 + Builtin::symbol, |
241 + Builtin::number); | 230 + Builtin::number); |
242 +// chunk Ethernet::adapter_init_context(Ethernet::Device); | |
243 + chunk Ethernet::adapter_reset(Ethernet::Device); | 231 + chunk Ethernet::adapter_reset(Ethernet::Device); |
244 + chunk Ethernet::adapter_load_mac_address(Ethernet::Device); | 232 + chunk Ethernet::adapter_load_mac_address(Ethernet::Device); |
245 } | 233 } |
246 | 234 |
247 provided type RxDescriptor | 235 provided type RxDescriptor |
248 @@ -76,18 +82,6 @@ | 236 @@ -70,18 +75,6 @@ |
249 chunk ::decl(); | 237 decl data_types(); |
250 } | 238 } |
251 | 239 |
252 - provided sequence create_device() | 240 - provided sequence create_device() |
253 - { | 241 - { |
254 - provided chunk Ethernet::create_device(PCI::AbstractDevice, Ethernet::Device); | 242 - provided chunk Ethernet::create_device(PCI::AbstractDevice, Ethernet::Device); |
407 +interface Ethernet : Socket, PCI, LKM, Builtin | 395 +interface Ethernet : Socket, PCI, LKM, Builtin |
408 { | 396 { |
409 required variable Builtin::string ifname; | 397 required variable Builtin::string ifname; |
410 | 398 |
411 @@ -23,6 +23,9 @@ | 399 @@ -23,6 +23,9 @@ |
412 method decl(); | 400 decl data_types(); |
413 method init(Ethernet::AbstractDevice, PCI::AbstractDevice); | 401 method init(Ethernet::AbstractDevice, PCI::AbstractDevice); |
414 pointcut Ethernet::SubContext(); | 402 pointcut Ethernet::SubContext(); |
415 + | 403 + |
416 + attribute PCI::AbstractDevice pci_device; | 404 + attribute PCI::AbstractDevice pci_device; |
417 + attribute Ethernet::AbstractDevice net_device; | 405 + attribute Ethernet::AbstractDevice net_device; |
454 Ethernet::ifname = "rtx%d"; | 442 Ethernet::ifname = "rtx%d"; |
455 | 443 |
456 diff --git a/rathaxes/samples/e1000/pci.blt b/rathaxes/samples/e1000/pci.blt | 444 diff --git a/rathaxes/samples/e1000/pci.blt b/rathaxes/samples/e1000/pci.blt |
457 --- a/rathaxes/samples/e1000/pci.blt | 445 --- a/rathaxes/samples/e1000/pci.blt |
458 +++ b/rathaxes/samples/e1000/pci.blt | 446 +++ b/rathaxes/samples/e1000/pci.blt |
459 @@ -12,12 +12,102 @@ | 447 @@ -12,15 +12,105 @@ |
460 struct pci_dev; | 448 struct pci_dev; |
461 } | 449 } |
462 | 450 |
463 - chunk ::init(PCI::AbstractDevice) | 451 - method init(PCI::AbstractDevice) |
464 + chunk ::init(PCI::AbstractDevice) | 452 + method init(PCI::AbstractDevice) |
465 { | 453 { |
466 } | 454 } |
467 | 455 |
468 + chunk set_context(Builtin::symbol ctx) | 456 + method set_context(Builtin::symbol ctx) |
469 + { | 457 + { |
470 + pci_set_drvdata(${self}, ${ctx}); | 458 + pci_set_drvdata(${self}, ${ctx}); |
471 + } | 459 + } |
472 + | 460 + |
473 map | 461 map |
474 { | 462 { |
475 + context: pci_get_drvdata(${self}); | 463 + context: pci_get_drvdata(${self}); |
476 + } | 464 } |
477 + } | 465 } |
478 + | 466 |
479 + template type PCI::Device() | 467 + template type PCI::Device() |
480 + { | 468 + { |
481 + chunk ::decl() | 469 + decl data_types() |
482 + { | 470 + { |
483 + struct rtx_pci_dev | 471 + struct rtx_pci_dev |
484 + { | 472 + { |
485 + struct pci_dev *pdev; | 473 + struct pci_dev *pdev; |
486 + int bars; | 474 + int bars; |
488 + unsigned char /* __iomem */ *ioaddr; | 476 + unsigned char /* __iomem */ *ioaddr; |
489 + void *context; | 477 + void *context; |
490 + }; | 478 + }; |
491 + } | 479 + } |
492 + | 480 + |
493 + chunk ::init(PCI::AbstractDevice pdev) | 481 + method init(PCI::AbstractDevice pdev) |
494 + { | 482 + { |
495 + ${self}->pdev = ${pdev}; | 483 + ${self}->pdev = ${pdev}; |
496 + ${self}->bars = pci_select_bars(${pdev}, IORESOURCE_MEM); | 484 + ${self}->bars = pci_select_bars(${pdev}, IORESOURCE_MEM); |
497 + ${self}->ioaddr = NULL; | 485 + ${self}->ioaddr = NULL; |
498 + ${self}->context = NULL; | 486 + ${self}->context = NULL; |
526 + pci_release_selected_regions(self->pdev, self->bars); | 514 + pci_release_selected_regions(self->pdev, self->bars); |
527 + pci_disable_device(self->pdev); | 515 + pci_disable_device(self->pdev); |
528 + } | 516 + } |
529 + } | 517 + } |
530 + | 518 + |
531 + chunk enable() | 519 + method enable() |
532 + { | 520 + { |
533 + rtx_pci_device_enable(${self}); | 521 + rtx_pci_device_enable(${self}); |
534 + } | 522 + } |
535 + | 523 + |
536 + chunk disable() | 524 + method disable() |
537 + { | 525 + { |
538 + rtx_pci_device_disable(${self}); | 526 + rtx_pci_device_disable(${self}); |
539 + } | 527 + } |
540 + | 528 + |
541 + chunk select_ioaddr(Builtin::number bar) | 529 + method select_ioaddr(Builtin::number bar) |
542 + { | 530 + { |
543 + ${self}->ioaddr = pci_ioremap_bar(${self}->pdev, ${bar}); | 531 + ${self}->ioaddr = pci_ioremap_bar(${self}->pdev, ${bar}); |
544 + } | 532 + } |
545 + | 533 + |
546 + chunk set_context(Builtin::symbol ctx) | 534 + method set_context(Builtin::symbol ctx) |
547 + { | 535 + { |
548 + ${self}->context = ctx; | 536 + ${self}->context = ctx; |
549 + } | 537 + } |
550 + | 538 + |
551 + map | 539 + map |
555 + pci_device: ${self}->pdev; | 543 + pci_device: ${self}->pdev; |
556 + irq: ${self}->pdev->irq; | 544 + irq: ${self}->pdev->irq; |
557 + bars: ${self}->bars; | 545 + bars: ${self}->bars; |
558 + ioaddr: ${self}->ioaddr; | 546 + ioaddr: ${self}->ioaddr; |
559 + BAR_0: 0; | 547 + BAR_0: 0; |
560 } | 548 + } |
561 } | 549 + } |
562 | 550 + |
551 template sequence probe() | |
552 { | |
553 chunk LKM::prototypes() | |
563 @@ -34,24 +124,67 @@ | 554 @@ -34,24 +124,67 @@ |
564 static int /* __devinit */ rtx_pci_probe(struct pci_dev *pdev, | 555 static int /* __devinit */ rtx_pci_probe(struct pci_dev *pdev, |
565 const struct pci_device_id *pdev_id) | 556 const struct pci_device_id *pdev_id) |
566 { | 557 { |
567 - int err; | 558 - int err; |
657 } | 648 } |
658 | 649 |
659 diff --git a/rathaxes/samples/e1000/pci.rti b/rathaxes/samples/e1000/pci.rti | 650 diff --git a/rathaxes/samples/e1000/pci.rti b/rathaxes/samples/e1000/pci.rti |
660 --- a/rathaxes/samples/e1000/pci.rti | 651 --- a/rathaxes/samples/e1000/pci.rti |
661 +++ b/rathaxes/samples/e1000/pci.rti | 652 +++ b/rathaxes/samples/e1000/pci.rti |
662 @@ -1,14 +1,40 @@ | 653 @@ -1,14 +1,41 @@ |
663 -interface PCI : LKM | 654 -interface PCI : LKM |
664 +interface PCI : LKM, Builtin, Device | 655 +interface PCI : LKM, Builtin, Device |
665 { | 656 { |
666 + required variable Builtin::string LKM::name; | 657 + required variable Builtin::string LKM::name; |
667 + required variable Builtin::number PCI::vendor_id; | 658 + required variable Builtin::number PCI::vendor_id; |
668 + required variable Builtin::number PCI::product_id; | 659 + required variable Builtin::number PCI::product_id; |
669 + | 660 + |
670 provided type PCI::AbstractDevice | 661 provided type PCI::AbstractDevice |
671 { | 662 { |
663 + decl data_types(); | |
664 + | |
672 chunk LKM::includes(); | 665 chunk LKM::includes(); |
673 + | 666 - decl data_types(); |
674 method decl(); | |
675 method init(PCI::AbstractDevice); | 667 method init(PCI::AbstractDevice); |
676 + method set_context(Builtin::symbol); | 668 + method set_context(Builtin::symbol); |
677 + | 669 + |
678 + attribute Builtin::symbol context; | 670 + attribute Builtin::symbol context; |
679 } | 671 } |
680 | 672 |
681 - required variable Builtin::number PCI::vendor_id; | 673 - required variable Builtin::number PCI::vendor_id; |
682 - required variable Builtin::number PCI::product_id; | 674 - required variable Builtin::number PCI::product_id; |
683 + provided type PCI::Device | 675 + provided type PCI::Device |
684 + { | 676 + { |
677 + decl data_types(); | |
678 + | |
685 + chunk LKM::prototypes(); | 679 + chunk LKM::prototypes(); |
686 + chunk LKM::code(); | 680 + chunk LKM::code(); |
687 + | 681 + |
688 + method decl(); | |
689 + method init(PCI::AbstractDevice); | 682 + method init(PCI::AbstractDevice); |
690 + method enable(); | 683 + method enable(); |
691 + method disable(); | 684 + method disable(); |
692 + method select_ioaddr(Builtin::number); | 685 + method select_ioaddr(Builtin::number); |
693 + method set_context(Builtin::symbol); | 686 + method set_context(Builtin::symbol); |
701 + attribute Builtin::number bars; | 694 + attribute Builtin::number bars; |
702 + } | 695 + } |
703 | 696 |
704 provided sequence register() | 697 provided sequence register() |
705 { | 698 { |
706 @@ -28,7 +54,7 @@ | 699 @@ -28,7 +55,7 @@ |
707 provided chunk LKM::prototypes(); | 700 provided chunk LKM::prototypes(); |
708 provided chunk LKM::code(); | 701 provided chunk LKM::code(); |
709 | 702 |
710 - provided pointcut PCI::pci_probe_hook(PCI::AbstractDevice); | 703 - provided pointcut PCI::pci_probe_hook(PCI::AbstractDevice); |
711 + provided pointcut PCI::pci_probe_hook(PCI::Device); | 704 + provided pointcut PCI::pci_probe_hook(PCI::Device); |
712 } | 705 } |
713 | 706 |
714 provided sequence remove() | 707 provided sequence remove() |
715 @@ -36,6 +62,6 @@ | 708 @@ -36,6 +63,6 @@ |
716 provided chunk LKM::prototypes(); | 709 provided chunk LKM::prototypes(); |
717 provided chunk LKM::code(); | 710 provided chunk LKM::code(); |
718 | 711 |
719 - provided pointcut PCI::pci_remove_hook(PCI::AbstractDevice); | 712 - provided pointcut PCI::pci_remove_hook(PCI::AbstractDevice); |
720 + provided pointcut PCI::pci_remove_hook(PCI::Device); | 713 + provided pointcut PCI::pci_remove_hook(PCI::Device); |