comparison rathaxes_correctly_use_chunk_and_template_sequences_parameters_in_e1000.patch @ 62:b43bed449cc2

Start a series on the e1000 sample
author Louis Opter <louis@lse.epitech.net>
date Fri, 17 Feb 2012 15:15:28 +0100
parents
children b820c4604946
comparison
equal deleted inserted replaced
61:ebe4df228703 62:b43bed449cc2
1 # HG changeset patch
2 # Parent d759597ad67d463fa77467b2443120315980c70b
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
5
6 diff --git a/rathaxes/samples/e1000/ethernet.blt b/rathaxes/samples/e1000/ethernet.blt
7 --- a/rathaxes/samples/e1000/ethernet.blt
8 +++ b/rathaxes/samples/e1000/ethernet.blt
9 @@ -1,5 +1,10 @@
10 with Ethernet, PCI, LKM, Log
11 {
12 + /*
13 + * Unlike PCI::Device, Ethernet::Device doesn't match the struct net_device
14 + * from Linux. Ethernet::Device is the type that we use in the private
15 + * field of the struct net_device.
16 + */
17 template type Ethernet::Device()
18 {
19 chunk LKM::includes()
20 @@ -10,7 +15,14 @@
21
22 chunk ::decl()
23 {
24 - struct rtx_ethernet_dev
25 + /*
26 + * So, at first sight, it sucks to typedef it as pointer but (for
27 + * now) it makes sense for two reasons:
28 + * - This structure will always be used through a pointer;
29 + * - This remove the ambiguity of pointer/not-pointer in the
30 + * ::init() chunk.
31 + */
32 + typedef struct rtx_ethernet_dev
33 {
34 /*
35 * I think it's useless to use the ${PCI::Device} "abstraction"
36 @@ -21,12 +33,18 @@
37
38 /* while waiting on issue #8 */
39 struct rtx_e1000_ctx hw_ctx;
40 - };
41 + } *rtx_ethernet_dev_p;
42 }
43
44 - chunk ::init(net_dev)
45 + chunk ::init(net_dev, pci_dev)
46 {
47 - ${self} = ${net_dev};
48 + ${self} = netdev_priv(${net_dev});
49 + /*
50 + * We can use -> because we know that ${self} will be always a
51 + * pointer ("thanks" to the typedef)
52 + */
53 + ${self}->pci_dev = ${pci_dev};
54 + ${self}->net_dev = ${net_dev};
55 }
56
57 map
58 @@ -45,7 +63,7 @@
59 {
60 static int rtx_ethernet_open(struct net_device *dev)
61 {
62 - struct rtx_ethernet_dev* rtx_ether_dev = netdev_priv(dev);
63 + struct rtx_ethernet_dev* rtx_ether_dev = netdev_priv(dev);
64 struct rtx_e1000_ctx* ctx = &rtx_ether_dev->hw_ctx;
65
66 ${pointcut ::IMPLEMENTATION};
67 @@ -121,7 +139,7 @@
68 }
69 }
70
71 - template sequence Ethernet::init(PCI::Device pdev)
72 + template sequence Ethernet::init()
73 {
74 chunk LKM::data()
75 {
76 @@ -133,18 +151,20 @@
77 };
78 }
79
80 - chunk PCI::pci_probe_hook()
81 + /* For now the type is not handled, so we just omit it (see #17) */
82 + chunk PCI::pci_probe_hook(/* PCI::Device */ pdev)
83 {
84 /*
85 * This typedef is needed to workaround a bug in CNorm __std__
86 * dialect.
87 */
88 typedef int ${Ethernet::Device};
89 - ${Ethernet::Device} *rtx_ether_ctx;
90 - struct net_device *net_dev;
91 +
92 + ${Ethernet::Device} rtx_ether_ctx;
93 + struct net_device *net_dev;
94 int error;
95
96 - error = 0;
97 + /* Initialize the net_device structure */
98 net_dev = alloc_etherdev(sizeof(*rtx_ether_ctx));
99 if (net_dev == 0)
100 {
101 @@ -152,53 +172,42 @@
102 /*
103 * Again, the error should be "raised" in the parent context.
104 *
105 - * Here we know that we should return ENOMEM because *we* wrote
106 + * Here we know that we can return ENOMEM because *we* wrote
107 * the parent context.
108 */
109 return -ENOMEM;
110 }
111 + SET_NETDEV_DEV(net_dev, &${pdev}->dev);
112 strlcpy(net_dev->name, ${config.ifname}, sizeof(net_dev->name));
113 - net_dev->irq = pdev->irq;
114 - // Maybe we should try ${rtx_ether_ctx.init()} here:
115 - rtx_ether_ctx = netdev_priv(net_dev);
116 - //rtx_ether_ctx->pci_dev = ${pdev};
117 - rtx_ether_ctx->pci_dev = pdev; // In the meantime do it directly
118 - rtx_ether_ctx->net_dev = net_dev;
119 + net_dev->irq = ${pdev}->irq;
120 + net_dev->netdev_ops = &rtx_ether_ops;
121
122 - /*
123 - * The substitution of ${pdev} fails here. I also tried to add a
124 - * "substitute method" to the PCI::Device that was just doing
125 - * "${self}" but it didn't work either (it was subsituted by a
126 - * placeholder, e.g: _1).
127 - *
128 - * That's why we cheated a bit and named all the arguments pdev.
129 - */
130 - //SET_NETDEV_DEV(net_dev, &${pdev}->dev);
131 - SET_NETDEV_DEV(net_dev, &pdev->dev);
132 - net_dev->netdev_ops = &rtx_ether_ops;
133 - if ((error = register_netdev(net_dev)))
134 + error = register_netdev(net_dev);
135 + if (error)
136 {
137 ${Log::info("Cannot register the driver")};
138 return error;
139 }
140
141 - /* same problem as above with ${pdev} */
142 - //pci_set_drvdata(${pdev}, net_dev);
143 - pci_set_drvdata(pdev, net_dev);
144 + /* Initialize our context held by the net_device structure */
145 + ${rtx_ether_ctx.init(local.net_dev, pdev)};
146 +
147 + pci_set_drvdata(${pdev}, net_dev);
148
149 ${pointcut Ethernet::create_device};
150 }
151
152 + /* This chunk should be remove (see #26) */
153 chunk ::CALL
154 {
155 }
156 }
157
158 - template sequence Ethernet::exit(PCI::Device pdev)
159 + template sequence Ethernet::exit()
160 {
161 - chunk PCI::pci_remove_hook()
162 + chunk PCI::pci_remove_hook(/* PCI::Device */ pdev)
163 {
164 - struct net_device *net_dev = pci_get_drvdata(pdev);
165 + struct net_device *net_dev = pci_get_drvdata(${pdev});
166
167 ${pointcut Ethernet::destroy_device};
168
169 @@ -210,6 +219,7 @@
170 free_netdev(net_dev);
171 }
172
173 + /* This chunk should be remove (see #26) */
174 chunk ::CALL
175 {
176 }
177 diff --git a/rathaxes/samples/e1000/ethernet.rti b/rathaxes/samples/e1000/ethernet.rti
178 --- a/rathaxes/samples/e1000/ethernet.rti
179 +++ b/rathaxes/samples/e1000/ethernet.rti
180 @@ -28,18 +28,16 @@
181 provided chunk LKM::code;
182 }
183
184 - provided sequence Ethernet::init(PCI::Device)
185 + provided sequence Ethernet::init()
186 {
187 provided chunk LKM::data;
188 provided chunk PCI::pci_probe_hook;
189 - provided chunk ::CALL;
190
191 provided pointcut Ethernet::create_device;
192 }
193
194 - provided sequence Ethernet::exit(PCI::Device)
195 + provided sequence Ethernet::exit()
196 {
197 - provided chunk ::CALL;
198 provided chunk PCI::pci_remove_hook;
199
200 provided pointcut Ethernet::destroy_device;
201 diff --git a/rathaxes/samples/e1000/pci.blt b/rathaxes/samples/e1000/pci.blt
202 --- a/rathaxes/samples/e1000/pci.blt
203 +++ b/rathaxes/samples/e1000/pci.blt
204 @@ -22,7 +22,7 @@
205 }
206 }
207
208 - template sequence PCI::probe(PCI::Device pdev)
209 + template sequence PCI::probe()
210 {
211 chunk LKM::prototypes()
212 {
213 @@ -41,7 +41,8 @@
214 if (err < 0)
215 goto fail;
216
217 - ${pointcut PCI::pci_probe_hook};
218 + /* Use local. to reference a local C variable: */
219 + ${pointcut PCI::pci_probe_hook(local.pdev)};
220
221 return 0;
222
223 @@ -50,12 +51,13 @@
224 }
225 }
226
227 + /* This chunk should be remove (see #26) */
228 chunk ::CALL
229 {
230 }
231 }
232
233 - template sequence PCI::remove(PCI::Device pdev)
234 + template sequence PCI::remove()
235 {
236 chunk LKM::prototypes()
237 {
238 @@ -66,12 +68,13 @@
239 {
240 static void rtx_pci_remove(struct pci_dev *pdev)
241 {
242 - ${pointcut PCI::pci_remove_hook};
243 + ${pointcut PCI::pci_remove_hook(local.pdev)};
244
245 pci_disable_device(pdev);
246 }
247 }
248
249 + /* This chunk should be remove (see #26) */
250 chunk ::CALL()
251 {
252 }
253 @@ -125,6 +128,8 @@
254 * This sequence is just "intermediate" code that will just inject
255 * itself in the hook LKM::init_bus_hook for which this sequence
256 * has a chunk (see above chunk).
257 + *
258 + * -> Should be removed see #26
259 */
260 }
261 }
262 @@ -136,6 +141,7 @@
263 pci_unregister_driver(&rtx_pci_driver);
264 }
265
266 + /* This chunk should be removed */
267 chunk ::CALL
268 {
269 }
270 diff --git a/rathaxes/samples/e1000/pci.rti b/rathaxes/samples/e1000/pci.rti
271 --- a/rathaxes/samples/e1000/pci.rti
272 +++ b/rathaxes/samples/e1000/pci.rti
273 @@ -18,7 +18,7 @@
274 provided chunk LKM::deinit_bus_hook;
275 }
276
277 - provided sequence PCI::probe(PCI::Device)
278 + provided sequence PCI::probe()
279 {
280 provided chunk LKM::prototypes;
281 provided chunk LKM::code;
282 @@ -26,7 +26,7 @@
283 provided pointcut PCI::pci_probe_hook;
284 }
285
286 - provided sequence PCI::remove(PCI::Device)
287 + provided sequence PCI::remove()
288 {
289 provided chunk LKM::prototypes;
290 provided chunk LKM::code;