Mercurial > archived > louis > epitech > mq > rathaxes
comparison rathaxes_rewrite_create_and_destroy_device_in_the_e1000_sample.patch @ 96:3e715b3e0ecd
Start a series to cleanup/refactor the e1000 sample a little bit
author | Louis Opter <louis@lse.epita.fr> |
---|---|
date | Sun, 18 Nov 2012 02:19:07 +0100 |
parents | |
children | ffdb018893e2 |
comparison
equal
deleted
inserted
replaced
95:4e7107e284de | 96:3e715b3e0ecd |
---|---|
1 # HG changeset patch | |
2 # Parent a7ba4e6eae2c9086c0b9876494165bf21ad1f405 | |
3 rathaxes: rewrite the {create,destroy}_device functions in the e1000 sample | |
4 | |
5 diff --git a/rathaxes/samples/e1000/e1000.blt b/rathaxes/samples/e1000/e1000.blt | |
6 --- a/rathaxes/samples/e1000/e1000.blt | |
7 +++ b/rathaxes/samples/e1000/e1000.blt | |
8 @@ -1,4 +1,4 @@ | |
9 -with e1000, Ethernet, Socket, PCI, LKM, Log | |
10 +with e1000, Ethernet, Socket, PCI, LKM, Log, Builtin | |
11 { | |
12 template type e1000::RxDescriptor() | |
13 { | |
14 @@ -288,7 +288,7 @@ | |
15 { | |
16 int bars; | |
17 unsigned char /* __iomem */ *ioaddr; | |
18 - int irq; | |
19 + unsigned int irq; | |
20 | |
21 /* we can't use the Rathaxes type here (#8) */ | |
22 //${e1000::RxRing} rx_ring; | |
23 @@ -298,8 +298,11 @@ | |
24 }; | |
25 } | |
26 | |
27 - chunk ::init() | |
28 + chunk ::init(Builtin::number bars, Builtin::number ioaddr, Builtin::number irq) | |
29 { | |
30 + ${self}->bars = ${bars}; | |
31 + ${self}->ioaddr = ${ioaddr}; | |
32 + ${self}->irq = irq; | |
33 } | |
34 | |
35 map | |
36 @@ -479,40 +482,16 @@ | |
37 | |
38 template sequence e1000::create_device() | |
39 { | |
40 - chunk Ethernet::create_device(PCI::AbstractDevice pdev, Ethernet::Device rtx_ether_ctx) | |
41 + chunk Ethernet::create_device(Ethernet::Device rtx_ether_ctx, | |
42 + Builtin::number bars, | |
43 + Builtin::number ioaddr, | |
44 + Builtin::number irq) | |
45 { | |
46 - /* | |
47 - * PCI init stuff: | |
48 - * | |
49 - * Some of that code should certainly be moved in the PCI/Ethernet | |
50 - * blts, also at some point maybe we could do that completely | |
51 - * automatically in the PCI/Ethernet blts. | |
52 - */ | |
53 + /* XXX: Use the rathaxes type directly here (#51): */ | |
54 + struct rtx_e1000_ctx *hw_ctx = &${rtx_ether_ctx}->hw_ctx; | |
55 + ${cast local.hw_ctx as e1000::Context}; | |
56 | |
57 - /* | |
58 - * We could have used an init function here but since we can't init | |
59 - * all the fields at once (see, ioaddr) and cannot call a C | |
60 - * function within a placeholder (${}), it wasn't really worth it. | |
61 - */ | |
62 - ${rtx_ether_ctx}->hw_ctx.bars = pci_select_bars(${pdev}, IORESOURCE_MEM); | |
63 - ${rtx_ether_ctx}->hw_ctx.irq = ${pdev}->irq; | |
64 - | |
65 - if (pci_enable_device_mem(${pdev})) | |
66 - ${Log::info("e1000::create: pci_enable_device_mem failed")}; | |
67 - if (pci_request_selected_regions(${pdev}, ${rtx_ether_ctx}->hw_ctx.bars, ${config.name})) | |
68 - ${Log::info("e1000::create: pci_request_selected_regions failed")}; | |
69 - if (${config.set_master}) | |
70 - pci_set_master(${pdev}); | |
71 - | |
72 - /* 0 here is for BAR_0: */ | |
73 - ${rtx_ether_ctx}->hw_ctx.ioaddr = pci_ioremap_bar(${pdev}, 0); | |
74 - if (!${rtx_ether_ctx}->hw_ctx.ioaddr) | |
75 - ${Log::info("e1000::create: pci_ioremap_bar failed")}; | |
76 - | |
77 - /* | |
78 - * The really device specific algorithm starts here (so it should | |
79 - * certainly be written in the frontend): | |
80 - */ | |
81 + ${local.hw_ctx.init(bars, ioaddr, irq)}; | |
82 | |
83 /* Reset the card */ | |
84 rtx_e1000_register_write32(&${rtx_ether_ctx}->hw_ctx, E1000_CTRL, E1000_CMD_RST); | |
85 @@ -533,6 +512,7 @@ | |
86 ${rtx_ether_ctx}->net_dev->dev_addr[i * 2 + 1] = (value >> 8) & 0xff; | |
87 } | |
88 | |
89 + /* XXX: use ${rtx_ether_ctx.set_mac_address()}; : */ | |
90 memcpy(${rtx_ether_ctx}->net_dev->perm_addr, | |
91 ${rtx_ether_ctx}->net_dev->dev_addr, | |
92 ${rtx_ether_ctx}->net_dev->addr_len); | |
93 diff --git a/rathaxes/samples/e1000/e1000.rti b/rathaxes/samples/e1000/e1000.rti | |
94 --- a/rathaxes/samples/e1000/e1000.rti | |
95 +++ b/rathaxes/samples/e1000/e1000.rti | |
96 @@ -1,8 +1,5 @@ | |
97 interface e1000 : Socket, Ethernet, PCI, LKM, Builtin | |
98 { | |
99 - /* XXX: This should be in pci.rti, also maybe we need a bool type */ | |
100 - required variable Builtin::symbol set_master; | |
101 - | |
102 required variable Builtin::number rx_ring_size; | |
103 required variable Builtin::number tx_ring_size; | |
104 required variable Builtin::number rx_buffer_len; | |
105 @@ -12,7 +9,8 @@ | |
106 { | |
107 chunk Ethernet::SubContext(); | |
108 method decl(); | |
109 - method init(); | |
110 + /* XXX: used types: */ | |
111 + method init(Builtin::number, Builtin::number, Builtin::number); | |
112 } | |
113 | |
114 provided type RxDescriptor | |
115 diff --git a/rathaxes/samples/e1000/ethernet.blt b/rathaxes/samples/e1000/ethernet.blt | |
116 --- a/rathaxes/samples/e1000/ethernet.blt | |
117 +++ b/rathaxes/samples/e1000/ethernet.blt | |
118 @@ -111,6 +111,13 @@ | |
119 ${self}->net_dev = ${net_dev}; | |
120 } | |
121 | |
122 + chunk set_mac_address(Builtin::number addr) | |
123 + { | |
124 + memcpy(${self}->net_dev->perm_addr, | |
125 + ${self}->net_dev->dev_addr, | |
126 + ${self}->net_dev->addr_len); | |
127 + } | |
128 + | |
129 map | |
130 { | |
131 } | |
132 @@ -249,9 +256,26 @@ | |
133 /* Initialize our context held by the net_device structure */ | |
134 ${rtx_ether_ctx.init(local.net_dev, pdev)}; | |
135 | |
136 + /* XXX: The following code should probably part of PCI:: */ | |
137 + | |
138 pci_set_drvdata(${pdev}, net_dev); | |
139 | |
140 - ${pointcut Ethernet::create_device(pdev, local.rtx_ether_ctx)}; | |
141 + int bars = pci_select_bars(${pdev}, IORESOURCE_MEM); | |
142 + | |
143 + if (pci_enable_device_mem(${pdev})) | |
144 + ${Log::info("pci_enable_device_mem failed")}; | |
145 + if (pci_request_selected_regions(${pdev}, bars, ${config.name})) | |
146 + ${Log::info("pci_request_selected_regions failed")}; | |
147 + if (${config.set_master}) | |
148 + pci_set_master(${pdev}); | |
149 + | |
150 + /* 0 here is for BAR_0: */ | |
151 + unsigned char /* __iomem */ *ioaddr = pci_ioremap_bar(${pdev}, 0); | |
152 + if (!ioaddr) | |
153 + ${Log::info("pci_ioremap_bar failed")}; | |
154 + | |
155 + unsigned int irq = net_dev->irq; | |
156 + ${pointcut Ethernet::create_device(local.rtx_ether_ctx, local.bars, local.ioaddr, local.irq)}; | |
157 } | |
158 | |
159 /* This chunk should be removed (see #26) */ | |
160 diff --git a/rathaxes/samples/e1000/ethernet.rti b/rathaxes/samples/e1000/ethernet.rti | |
161 --- a/rathaxes/samples/e1000/ethernet.rti | |
162 +++ b/rathaxes/samples/e1000/ethernet.rti | |
163 @@ -1,5 +1,8 @@ | |
164 -interface Ethernet : Socket, PCI, LKM | |
165 +interface Ethernet : Socket, PCI, LKM, Builtin | |
166 { | |
167 + /* XXX: This should be in pci.rti, also maybe we need a bool type */ | |
168 + required variable Builtin::symbol set_master; | |
169 + | |
170 required variable Builtin::string ifname; | |
171 | |
172 provided type ProtocolId | |
173 @@ -22,6 +25,8 @@ | |
174 chunk LKM::includes(); | |
175 method decl(); | |
176 method init(Ethernet::AbstractDevice, PCI::AbstractDevice); | |
177 + method set_mac_address(Builtin::number); | |
178 + | |
179 pointcut Ethernet::SubContext(); | |
180 } | |
181 | |
182 @@ -54,7 +59,10 @@ | |
183 provided chunk LKM::data(); | |
184 provided chunk PCI::pci_probe_hook(PCI::AbstractDevice); | |
185 | |
186 - provided pointcut Ethernet::create_device(PCI::AbstractDevice, Ethernet::Device); | |
187 + provided pointcut Ethernet::create_device(Ethernet::Device, | |
188 + Builtin::number, | |
189 + Builtin::number, | |
190 + Builtin::number); | |
191 } | |
192 | |
193 provided sequence exit() |