comparison rathaxes_change_the_abstract_type_notation_in_the_e1000_sample.patch @ 108:7efe3212db3a

Put the patches on e1000 above the patches on the compiler
author Louis Opter <louis@lse.epita.fr>
date Sun, 31 Mar 2013 20:00:09 -0700
parents f42751b8ca99
children
comparison
equal deleted inserted replaced
107:f42751b8ca99 108:7efe3212db3a
1 # HG changeset patch 1 # HG changeset patch
2 # Parent 6122a310f97196aadba20973d9218aa24528bd3d 2 # Parent e201e5967e6fdec65fff42256b9a1418bc24b9be
3 rathaxes: change the abstract type notation in the e1000 sample 3 rathaxes: change the abstract type notation in the e1000 sample
4 4
5 Starting with ra24db32bf134 Rathaxes types are generated differently: you 5 Starting with ra24db32bf134 Rathaxes types are generated differently: you
6 don't define entire structures anymore, but only the fields. And the 6 don't define entire structures anymore, but only the fields. And the
7 compiler generate a typedef'ed structure on top of it. 7 compiler generate a typedef'ed structure on top of it.
61 } 61 }
62 } 62 }
63 diff --git a/rathaxes/samples/e1000/e1000.blt b/rathaxes/samples/e1000/e1000.blt 63 diff --git a/rathaxes/samples/e1000/e1000.blt b/rathaxes/samples/e1000/e1000.blt
64 --- a/rathaxes/samples/e1000/e1000.blt 64 --- a/rathaxes/samples/e1000/e1000.blt
65 +++ b/rathaxes/samples/e1000/e1000.blt 65 +++ b/rathaxes/samples/e1000/e1000.blt
66 @@ -171,13 +171,17 @@ 66 @@ -171,8 +171,8 @@
67 67
68 static int rtx_e1000_tx_ring_tso_cksum_offload(${e1000::TxRing} *self, ${Socket::SKBuff} *skb) 68 static int rtx_e1000_tx_ring_tso_cksum_offload(${e1000::TxRing.ref} self, ${Socket::SKBuff.ref} skb)
69 { 69 {
70 - ${Socket::AbstractSKBuff} *abs_skb = skb->skbuff; 70 - ${Socket::AbstractSKBuff.ref} abs_skb = skb->skbuff;
71 - ${cast local.abs_skb as Socket::AbstractSKBuff};
72 - return skb_is_gso(&${local.abs_skb.data}) || ${local.abs_skb.data}.ip_summed == CHECKSUM_PARTIAL; 71 - return skb_is_gso(&${local.abs_skb.data}) || ${local.abs_skb.data}.ip_summed == CHECKSUM_PARTIAL;
73 + /* XXX We can't use ${skb} here because it's a pointer */ 72 + ${Socket::AbstractSKBuff.ref} k_skb = skb->skbuff;
74 + ${Socket::AbstractSKBuff} *k_skb = skb->skbuff;
75 + ${cast local.k_skb as Socket::AbstractSKBuff};
76 + return skb_is_gso(${local.k_skb.k_sk_buff}) || ${local.k_skb.k_sk_buff}->ip_summed == CHECKSUM_PARTIAL; 73 + return skb_is_gso(${local.k_skb.k_sk_buff}) || ${local.k_skb.k_sk_buff}->ip_summed == CHECKSUM_PARTIAL;
77 } 74 }
78 75
79 static void rtx_e1000_tx_ring_put(${e1000::TxRing} *self, ${Socket::SKBuff} *skb) 76 static void rtx_e1000_tx_ring_put(${e1000::TxRing.ref} self, ${Socket::SKBuff.ref} skb)
80 { 77 @@ -187,16 +187,16 @@
81 + /* XXX We can't use ${skb} here because it's a pointer */
82 + ${Socket::AbstractSKBuff} *k_skb = skb->skbuff;
83 + ${cast local.k_skb as Socket::AbstractSKBuff};
84 WARN_ON(!skb);
85
86 /*
87 @@ -188,17 +192,15 @@
88 * code shouldn't be aware of it and use something more 78 * code shouldn't be aware of it and use something more
89 * abstract. 79 * abstract.
90 */ 80 */
91 - ${Socket::AbstractSKBuff} *abs_skb = skb->skbuff; 81 - ${Socket::AbstractSKBuff.ref} abs_skb = skb->skbuff;
92 - ${cast local.abs_skb as Socket::AbstractSKBuff}; 82 + ${Socket::AbstractSKBuff.ref} k_skb = skb->skbuff;
93 ${e1000::TxDescriptor} *tx_desc = &self->base[self->tail]; 83 ${e1000::TxDescriptor.ref} tx_desc = &self->base[self->tail];
94 tx_desc->lower.data = cpu_to_le32( 84 tx_desc->lower.data = cpu_to_le32(
95 E1000_TXD_CMD_EOP | 85 E1000_TXD_CMD_EOP |
96 E1000_TXD_CMD_IFCS | 86 E1000_TXD_CMD_IFCS |
97 E1000_TXD_CMD_RS | 87 E1000_TXD_CMD_RS |
98 - skb_headlen(&${local.abs_skb.data})); 88 - skb_headlen(&${local.abs_skb.data}));
102 - memcpy(&self->skbuffs[self->tail], skb, sizeof(*skb)); 92 - memcpy(&self->skbuffs[self->tail], skb, sizeof(*skb));
103 + memcpy(&self->skbuffs[self->tail], ${local.k_skb.k_sk_buff}, sizeof(*${local.k_skb.k_sk_buff})); 93 + memcpy(&self->skbuffs[self->tail], ${local.k_skb.k_sk_buff}, sizeof(*${local.k_skb.k_sk_buff}));
104 self->tail = (self->tail + 1) % ${config.tx_ring_size}; 94 self->tail = (self->tail + 1) % ${config.tx_ring_size};
105 } 95 }
106 96
107 @@ -733,7 +735,7 @@ 97 @@ -732,7 +732,7 @@
108 hw_ctx->rx_ring.size = ${config.rx_ring_size} * sizeof(*hw_ctx->rx_ring.base); 98 hw_ctx->rx_ring.size = ${config.rx_ring_size} * sizeof(*hw_ctx->rx_ring.base);
109 hw_ctx->rx_ring.size = ALIGN(hw_ctx->rx_ring.size, 4096); 99 hw_ctx->rx_ring.size = ALIGN(hw_ctx->rx_ring.size, 4096);
110 hw_ctx->rx_ring.base = dma_alloc_coherent( 100 hw_ctx->rx_ring.base = dma_alloc_coherent(
111 - &${rtx_ether_ctx.device}, 101 - &${rtx_ether_ctx.device},
112 + ${rtx_ether_ctx.device}, 102 + ${rtx_ether_ctx.device},
113 hw_ctx->rx_ring.size, 103 hw_ctx->rx_ring.size,
114 &hw_ctx->rx_ring.dma_base, 104 &hw_ctx->rx_ring.dma_base,
115 GFP_KERNEL); 105 GFP_KERNEL);
116 @@ -751,12 +753,10 @@ 106 @@ -750,11 +750,10 @@
117 * Allocate the skbuffs, map them for DMA, and write their address 107 * Allocate the skbuffs, map them for DMA, and write their address
118 * in the corresponding descriptor. 108 * in the corresponding descriptor.
119 */ 109 */
120 - ${Ethernet::AbstractDevice} *rtx_ether_dev = ${rtx_ether_ctx.net_device}; 110 - ${Ethernet::AbstractDevice.ref} rtx_ether_dev = ${rtx_ether_ctx.net_device};
121 - ${cast local.rtx_ether_dev as Ethernet::AbstractDevice};
122 for (i = 0; i != ${config.rx_ring_size}; ++i) 111 for (i = 0; i != ${config.rx_ring_size}; ++i)
123 { 112 {
124 - hw_ctx->rx_ring.skbuffs[i].skbuff = (${Socket::AbstractSKBuff}*) netdev_alloc_skb( 113 - hw_ctx->rx_ring.skbuffs[i].skbuff = (${Socket::AbstractSKBuff.ref})netdev_alloc_skb(
125 - &${rtx_ether_dev.netdev}, 114 - &${rtx_ether_dev.netdev},
126 + hw_ctx->rx_ring.skbuffs[i].skbuff = (${Socket::AbstractSKBuff}*)netdev_alloc_skb( 115 + hw_ctx->rx_ring.skbuffs[i].skbuff = (${Socket::AbstractSKBuff}*)netdev_alloc_skb(
127 + ${rtx_ether_ctx.net_device.k_net_dev}, /* XXX: .k_net_dev isn't expanded here */ 116 + ${rtx_ether_ctx.net_device.k_net_dev}, /* XXX: .k_net_dev isn't expanded here */
128 ${config.rx_buffer_len}); 117 ${config.rx_buffer_len});
129 if (!hw_ctx->rx_ring.skbuffs[i].skbuff) 118 if (!hw_ctx->rx_ring.skbuffs[i].skbuff)
130 { 119 {
131 @@ -764,11 +764,11 @@ 120 @@ -762,11 +761,11 @@
132 goto err_skbuffs_alloc; 121 goto err_skbuffs_alloc;
133 } 122 }
134 hw_ctx->rx_ring.skbuffs[i].dma_handle = dma_map_single( 123 hw_ctx->rx_ring.skbuffs[i].dma_handle = dma_map_single(
135 - &${rtx_ether_ctx.device}, 124 - &${rtx_ether_ctx.device},
136 - &hw_ctx->rx_ring.skbuffs[i].skbuff->data, 125 - &hw_ctx->rx_ring.skbuffs[i].skbuff->data,
141 - int dma_error = dma_mapping_error(&${rtx_ether_ctx.device}, 130 - int dma_error = dma_mapping_error(&${rtx_ether_ctx.device},
142 + int dma_error = dma_mapping_error(${rtx_ether_ctx.device}, 131 + int dma_error = dma_mapping_error(${rtx_ether_ctx.device},
143 hw_ctx->rx_ring.skbuffs[i].dma_handle); 132 hw_ctx->rx_ring.skbuffs[i].dma_handle);
144 if (dma_error) 133 if (dma_error)
145 { 134 {
146 @@ -820,7 +820,7 @@ 135 @@ -818,7 +817,7 @@
147 hw_ctx->tx_ring.size = ${config.tx_ring_size} * sizeof(*hw_ctx->tx_ring.base); 136 hw_ctx->tx_ring.size = ${config.tx_ring_size} * sizeof(*hw_ctx->tx_ring.base);
148 hw_ctx->tx_ring.size = ALIGN(hw_ctx->tx_ring.size, 4096); 137 hw_ctx->tx_ring.size = ALIGN(hw_ctx->tx_ring.size, 4096);
149 hw_ctx->tx_ring.base = dma_alloc_coherent( 138 hw_ctx->tx_ring.base = dma_alloc_coherent(
150 - &${rtx_ether_ctx.device}, 139 - &${rtx_ether_ctx.device},
151 + ${rtx_ether_ctx.device}, 140 + ${rtx_ether_ctx.device},
152 hw_ctx->tx_ring.size, 141 hw_ctx->tx_ring.size,
153 &hw_ctx->tx_ring.dma_base, 142 &hw_ctx->tx_ring.dma_base,
154 GFP_KERNEL); 143 GFP_KERNEL);
155 @@ -863,15 +863,16 @@ 144 @@ -861,15 +860,16 @@
156 while (i--) 145 while (i--)
157 { 146 {
158 dma_unmap_single( 147 dma_unmap_single(
159 - &${rtx_ether_ctx.device}, 148 - &${rtx_ether_ctx.device},
160 + ${rtx_ether_ctx.device}, 149 + ${rtx_ether_ctx.device},
170 - dma_free_coherent(&${rtx_ether_ctx.device}, hw_ctx->rx_ring.size, 159 - dma_free_coherent(&${rtx_ether_ctx.device}, hw_ctx->rx_ring.size,
171 + dma_free_coherent(${rtx_ether_ctx.device}, hw_ctx->rx_ring.size, 160 + dma_free_coherent(${rtx_ether_ctx.device}, hw_ctx->rx_ring.size,
172 hw_ctx->rx_ring.base, hw_ctx->rx_ring.dma_base); 161 hw_ctx->rx_ring.base, hw_ctx->rx_ring.dma_base);
173 err_rx_ring_alloc: 162 err_rx_ring_alloc:
174 return -ENOMEM; 163 return -ENOMEM;
175 @@ -889,8 +890,13 @@ 164 @@ -887,8 +887,12 @@
176 { 165 {
177 chunk ::CALL() 166 chunk ::CALL()
178 { 167 {
179 - ${e1000::Context} *hw_ctx; 168 - ${e1000::Context.ref} hw_ctx;
180 - hw_ctx = &${rtx_ether_ctx}->hw_ctx; 169 - hw_ctx = &${rtx_ether_ctx}->hw_ctx;
181 + /* 170 + /*
182 + * XXX: Not generated if named "hw_ctx" (which is funny because 171 + * XXX: Not generated if named "hw_ctx" (which is funny because
183 + * it's used and works in the template right above this one): 172 + * it's used and works in the template right above this one):
184 + */ 173 + */
185 + ${e1000::Context} *hw_ctx_; 174 + ${e1000::Context.ref} hw_ctx_;
186 + ${cast local.hw_ctx_ as e1000::Context};
187 + hw_ctx_ = &${rtx_ether_ctx}->hw_ctx; 175 + hw_ctx_ = &${rtx_ether_ctx}->hw_ctx;
188 176
189 /* 177 /*
190 * Free the rx ring: 178 * Free the rx ring:
191 @@ -900,22 +906,23 @@ 179 @@ -898,22 +902,26 @@
192 for (int i = 0; i != ${config.rx_ring_size}; ++i) 180 for (int i = 0; i != ${config.rx_ring_size}; ++i)
193 { 181 {
194 dma_unmap_single( 182 dma_unmap_single(
195 - &${rtx_ether_ctx.device}, 183 - &${rtx_ether_ctx.device},
196 - (dma_addr_t)hw_ctx->rx_ring.skbuffs[i].dma_handle, 184 - (dma_addr_t)hw_ctx->rx_ring.skbuffs[i].dma_handle,
197 + ${rtx_ether_ctx.device}, 185 + ${rtx_ether_ctx.device},
198 + (dma_addr_t)hw_ctx_->rx_ring.skbuffs[i].dma_handle, 186 + (dma_addr_t)hw_ctx_->rx_ring.skbuffs[i].dma_handle,
199 ${config.rx_buffer_len}, 187 ${config.rx_buffer_len},
200 DMA_FROM_DEVICE); 188 DMA_FROM_DEVICE);
201 - dev_kfree_skb(&hw_ctx->rx_ring.skbuffs[i].skbuff->data); 189 - dev_kfree_skb(&hw_ctx->rx_ring.skbuffs[i].skbuff->data);
202 + /* XXX Go through the rtx types (Socket::SKBuff, AbstractSKBuff) */ 190 + /* XXX Leaking cast
203 + dev_kfree_skb(hw_ctx_->rx_ring.skbuffs[i].skbuff); 191 + * (We should go through the rtx types (Socket::SKBuff,
192 + * AbstractSKBuff)
193 + */
194 + dev_kfree_skb((struct sk_buff *)hw_ctx_->rx_ring.skbuffs[i].skbuff);
204 } 195 }
205 - dma_free_coherent(&${rtx_ether_ctx.device}, hw_ctx->rx_ring.size, 196 - dma_free_coherent(&${rtx_ether_ctx.device}, hw_ctx->rx_ring.size,
206 - hw_ctx->rx_ring.base, hw_ctx->rx_ring.dma_base); 197 - hw_ctx->rx_ring.base, hw_ctx->rx_ring.dma_base);
207 + dma_free_coherent(${rtx_ether_ctx.device}, hw_ctx_->rx_ring.size, 198 + dma_free_coherent(${rtx_ether_ctx.device}, hw_ctx_->rx_ring.size,
208 + hw_ctx_->rx_ring.base, hw_ctx_->rx_ring.dma_base); 199 + hw_ctx_->rx_ring.base, hw_ctx_->rx_ring.dma_base);
217 + dma_free_coherent(${rtx_ether_ctx.device}, hw_ctx_->tx_ring.size, 208 + dma_free_coherent(${rtx_ether_ctx.device}, hw_ctx_->tx_ring.size,
218 + hw_ctx_->tx_ring.base, hw_ctx_->tx_ring.dma_base); 209 + hw_ctx_->tx_ring.base, hw_ctx_->tx_ring.dma_base);
219 ${Log::info("free_rx_tx: tx ring free'ed")}; 210 ${Log::info("free_rx_tx: tx ring free'ed")};
220 } 211 }
221 } 212 }
222 @@ -973,13 +980,13 @@ 213 @@ -971,13 +979,13 @@
223 ${local.skb.init(kernel_skb)}; 214 ${local.skb.init(kernel_skb)};
224 hw_ctx = &${rtx_ether_ctx}->hw_ctx; 215 hw_ctx = &${rtx_ether_ctx}->hw_ctx;
225 tx_ring = &hw_ctx->tx_ring; 216 tx_ring = &hw_ctx->tx_ring;
226 - devp = (${Device::AbstractDevice}*) &${rtx_ether_ctx.device}; 217 - devp = (${Device::AbstractDevice.ref})&${rtx_ether_ctx.device};
227 + devp = (${Device::AbstractDevice}*)${rtx_ether_ctx.device}; 218 + devp = (${Device::AbstractDevice.ref})${rtx_ether_ctx.device};
228 219
229 ${Log::info("xmit: skbuff details:")}; 220 ${Log::info("xmit: skbuff details:")};
230 /* 221 /*
231 - * skb is not expand on the bound C variable (should be rtx_skbuff), 222 - * skb is not expand on the bound C variable (should be rtx_skbuff),
232 - * which is funny because it works for the sequence template call 223 - * which is funny because it works for the sequence template call
235 + * rtx_skbuff), which is funny because it works for the 226 + * rtx_skbuff), which is funny because it works for the
236 + * sequence template call right after. 227 + * sequence template call right after.
237 */ 228 */
238 /* 229 /*
239 * XXX: doesn't work (I tried to pass self explicitely too): 230 * XXX: doesn't work (I tried to pass self explicitely too):
240 @@ -1012,8 +1019,8 @@ 231 @@ -1010,8 +1018,8 @@
241 232
242 /* 2. Map the data */ 233 /* 2. Map the data */
243 234
244 - /* XXX: ${local.skb.map_to(local.devp)}; */ 235 - /* XXX: ${local.skb.map_to(local.devp)}; */
245 - if (rtx_socket_skbuff_map(&skb, &${devp.data}, DMA_TO_DEVICE)) 236 - if (rtx_socket_skbuff_map(&skb, &${devp.data}, DMA_TO_DEVICE))
246 + /* XXX: ${local.skb.map_to(devp.k_device)}; */ 237 + /* XXX: ${local.skb.map_to(devp.k_device)}; */
247 + if (rtx_socket_skbuff_map(&skb, ${devp.k_device}, DMA_TO_DEVICE)) 238 + if (rtx_socket_skbuff_map(&skb, ${devp.k_device}, DMA_TO_DEVICE))
248 { 239 {
249 ${Log::info("xmit: can't DMA map a SKbuff")}; 240 ${Log::info("xmit: can't DMA map a SKbuff")};
250 goto err_skb_map_to; 241 goto err_skb_map_to;
251 @@ -1032,7 +1039,7 @@ 242 @@ -1030,7 +1038,7 @@
252 err_offload: 243 err_offload:
253 err_skb_map_to: 244 err_skb_map_to:
254 /* XXX: ${local.skb.unmap_to_and_free(local.dev)}; */ 245 /* XXX: ${local.skb.unmap_to_and_free(local.dev)}; */
255 - rtx_socket_skbuff_unmap_and_free(&skb, &${devp.data}, DMA_TO_DEVICE); 246 - rtx_socket_skbuff_unmap_and_free(&skb, &${devp.data}, DMA_TO_DEVICE);
256 + rtx_socket_skbuff_unmap_and_free(&skb, ${devp.k_device}, DMA_TO_DEVICE); 247 + rtx_socket_skbuff_unmap_and_free(&skb, ${devp.k_device}, DMA_TO_DEVICE);
327 + dev_addr: ((struct net_device *)(${self})->net_dev)->dev_addr; 318 + dev_addr: ((struct net_device *)(${self})->net_dev)->dev_addr;
328 + irq: ((struct pci_dev *)(${self})->pci_dev)->irq; 319 + irq: ((struct pci_dev *)(${self})->pci_dev)->irq;
329 } 320 }
330 } 321 }
331 322
332 @@ -128,8 +141,17 @@ 323 @@ -128,7 +141,15 @@
333 { 324 {
334 static int rtx_ethernet_open(struct net_device *dev) 325 static int rtx_ethernet_open(struct net_device *dev)
335 { 326 {
336 - ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(dev); 327 - ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(dev);
337 + /* 328 + /*
338 + * XXX The casts are here because the compiler doesn't resolve 329 + * XXX The casts are here because the compiler doesn't resolve
339 + * "enclosed" type (e.g: local.var.enclosed) correctly. 330 + * "enclosed" type (e.g: local.var.enclosed) correctly.
340 + */ 331 + */
341 + ${Ethernet::AbstractDevice} *rtx_net_dev; 332 + ${Ethernet::AbstractDevice.ref} rtx_net_dev;
342 + ${cast local.rtx_net_dev as Ethernet::AbstractDevice};
343 + { /* XXX: I end up with a placeholder if I don't open a scope */ 333 + { /* XXX: I end up with a placeholder if I don't open a scope */
344 + ${local.rtx_net_dev.init(local.dev)}; 334 + ${local.rtx_net_dev.init(local.dev)};
345 + } 335 + }
346 336 + ${Ethernet::Device.ref} rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx};
347 + ${Ethernet::Device} *rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx};
348 ${cast local.rtx_ether_ctx as Ethernet::Device};
349 337
350 int error; 338 int error;
351 @@ -189,8 +211,13 @@ 339 {
340 @@ -181,7 +202,12 @@
352 { 341 {
353 static int rtx_ethernet_close(struct net_device *dev) 342 static int rtx_ethernet_close(struct net_device *dev)
354 { 343 {
355 - ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(dev); 344 - ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(dev);
356 + ${Ethernet::AbstractDevice} *rtx_net_dev; 345 + ${Ethernet::AbstractDevice.ref} 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 */ 346 + { /* XXX: I end up with a placeholder if I don't open a scope */
359 + ${local.rtx_net_dev.init(local.dev)}; 347 + ${local.rtx_net_dev.init(local.dev)};
360 + } 348 + }
361 349 +
362 + ${Ethernet::Device} *rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx}; 350 + ${Ethernet::Device.ref} rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx};
363 ${cast local.rtx_ether_ctx as Ethernet::Device};
364 351
365 /* TODO: change this pointcut into a pointcut/adapter/callback: */ 352 /* TODO: change this pointcut into a pointcut/adapter/callback: */
366 @@ -225,6 +252,7 @@ 353 {
367 { 354 @@ -246,22 +272,24 @@
368 ${Ethernet::AbstractDevice} *rtx_net_dev = dev_id;
369 ${cast local.rtx_net_dev as Ethernet::AbstractDevice};
370 +
371 ${Ethernet::Device} *rtx_ether_ctx;
372 ${cast local.rtx_ether_ctx as Ethernet::Device};
373 rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx};
374 @@ -258,23 +286,26 @@
375 */ 355 */
376 chunk PCI::pci_probe_hook(PCI::Device rtx_pci_dev) 356 chunk PCI::pci_probe_hook(PCI::Device rtx_pci_dev)
377 { 357 {
378 + ${Ethernet::AbstractDevice} *rtx_net_dev; 358 + ${Ethernet::AbstractDevice.ref} rtx_net_dev;
379 ${Ethernet::Device} *rtx_ether_ctx; 359 ${Ethernet::Device.ref} rtx_ether_ctx;
380 - ${Ethernet::AbstractDevice} *net_dev; 360 - ${Ethernet::AbstractDevice.ref} net_dev;
381 - ${cast local.net_dev as Ethernet::AbstractDevice}; 361
382 + ${cast local.rtx_net_dev as Ethernet::AbstractDevice}; 362 - net_dev = (${Ethernet::AbstractDevice.ref})alloc_etherdev(sizeof(*rtx_ether_ctx));
383
384 - net_dev = (${Ethernet::AbstractDevice}*) alloc_etherdev(sizeof(*rtx_ether_ctx));
385 - if (!net_dev) 363 - if (!net_dev)
386 + /* Cast the result back into our "transparent wrapper" type */ 364 + rtx_net_dev = (${Ethernet::AbstractDevice.ref})alloc_etherdev(sizeof(*rtx_ether_ctx));
387 + rtx_net_dev = (${Ethernet::AbstractDevice}*)alloc_etherdev(sizeof(*rtx_ether_ctx));
388 + if (!rtx_net_dev) 365 + if (!rtx_net_dev)
389 { 366 {
390 ${Log::info("cannot allocate the ethernet device context")}; 367 ${Log::info("cannot allocate the ethernet device context")};
391 error = -ENOMEM; 368 error = -ENOMEM;
392 goto fail; 369 goto fail;
405 - error = register_netdev(&${local.net_dev.netdev}); 382 - error = register_netdev(&${local.net_dev.netdev});
406 + error = register_netdev(${local.rtx_net_dev.k_net_dev}); 383 + error = register_netdev(${local.rtx_net_dev.k_net_dev});
407 if (error) 384 if (error)
408 { 385 {
409 ${Log::info("cannot register the driver in the net subsystem")}; 386 ${Log::info("cannot register the driver in the net subsystem")};
410 @@ -286,14 +317,11 @@ 387 @@ -273,13 +301,11 @@
411 * XXX: the cast is here because the compiler resolve the 388 * XXX: the cast is here because the compiler resolve the
412 * type of rtx_pci_dev.pci_device to the type of 389 * type of rtx_pci_dev.pci_device to the type of
413 * rtx_pci_dev instead of the type of rtx_pci_dev.pci_device. 390 * rtx_pci_dev instead of the type of rtx_pci_dev.pci_device.
414 - * 391 - *
415 - * Also, I'm getting placeholder in the generated code if 392 - * Also, I'm getting placeholder in the generated code if
416 - * I don't open a scope here. 393 - * I don't open a scope here.
417 */ 394 */
418 - { 395 - {
419 - ${PCI::AbstractDevice} *rtx_pdev = ${rtx_pci_dev.pci_device}; 396 - ${PCI::AbstractDevice.ref} rtx_pdev = ${rtx_pci_dev.pci_device};
420 - ${cast local.rtx_pdev as PCI::AbstractDevice};
421 - ${local.rtx_ether_ctx.init(local.net_dev, local.rtx_pdev)}; 397 - ${local.rtx_ether_ctx.init(local.net_dev, local.rtx_pdev)};
422 + ${PCI::AbstractDevice} *workaround = ${rtx_pci_dev.pci_device}; 398 + ${PCI::AbstractDevice.ref} workaround = ${rtx_pci_dev.pci_device};
423 + ${cast local.workaround as PCI::AbstractDevice}; 399 + ${cast local.workaround as PCI::AbstractDevice};
424 + { /* XXX: I end up with a placeholder if I don't open a scope */ 400 + { /* XXX: I end up with a placeholder if I don't open a scope */
425 + ${local.rtx_ether_ctx.init(local.rtx_net_dev, local.workaround)}; 401 + ${local.rtx_ether_ctx.init(local.rtx_net_dev, local.workaround)};
426 } 402 }
427 403
428 /* Register ourselves in the parent context: */ 404 /* Register ourselves in the parent context: */
429 @@ -315,7 +343,7 @@ 405 @@ -300,7 +326,7 @@
430 ${pointcut Ethernet::adapter_load_mac_address(local.rtx_ether_ctx)}; 406 ${pointcut Ethernet::adapter_load_mac_address(local.rtx_ether_ctx)};
431 memcpy(${local.rtx_ether_ctx.perm_addr}, 407 memcpy(${local.rtx_ether_ctx.perm_addr},
432 ${local.rtx_ether_ctx.dev_addr}, 408 ${local.rtx_ether_ctx.dev_addr},
433 - ${local.net_dev.netdev}.addr_len); 409 - ${local.net_dev.netdev}.addr_len);
434 + ${local.rtx_net_dev.k_net_dev}->addr_len); 410 + ${local.rtx_net_dev.k_net_dev}->addr_len);
435 } 411 }
436 412
437 /* This chunk should be removed (see #26) */ 413 /* This chunk should be removed (see #26) */
438 @@ -332,15 +360,15 @@ 414 @@ -317,13 +343,12 @@
439 */ 415 */
440 chunk PCI::pci_remove_hook(PCI::Device rtx_pci_dev) 416 chunk PCI::pci_remove_hook(PCI::Device rtx_pci_dev)
441 { 417 {
442 - ${Ethernet::Device} *rtx_ether_ctx = ${rtx_pci_dev.context}; 418 - ${Ethernet::Device.ref} rtx_ether_ctx = ${rtx_pci_dev.context};
443 - ${Ethernet::AbstractDevice} *rtx_ether_dev = (${Ethernet::AbstractDevice}*) ${local.rtx_ether_ctx.net_device}; 419 - ${Ethernet::AbstractDevice.ref} rtx_ether_dev = (${Ethernet::AbstractDevice.ref})${local.rtx_ether_ctx.net_device};
444 - 420 -
445 + ${Ethernet::Device} *rtx_ether_ctx = ${rtx_pci_dev.rtx_drv_context}; 421 + ${Ethernet::Device.ref} rtx_ether_ctx = ${rtx_pci_dev.rtx_drv_context};
446 + ${cast local.rtx_ether_ctx as Ethernet::Device}; /* XXX */
447 BUG_ON(!rtx_ether_ctx); 422 BUG_ON(!rtx_ether_ctx);
448 423
449 - ${cast local.rtx_ether_ctx as Ethernet::Device};
450 - ${cast local.rtx_ether_dev as Ethernet::AbstractDevice};
451 - unregister_netdev(&${local.rtx_ether_dev.netdev}); 424 - unregister_netdev(&${local.rtx_ether_dev.netdev});
452 - free_netdev(&${local.rtx_ether_dev.netdev}); 425 - free_netdev(&${local.rtx_ether_dev.netdev});
453 + ${Ethernet::AbstractDevice} *rtx_net_dev = ${local.rtx_ether_ctx.net_device}; 426 + ${Ethernet::AbstractDevice.ref} rtx_net_dev = ${local.rtx_ether_ctx.net_device};
454 + ${cast local.rtx_net_dev as Ethernet::AbstractDevice}; /* XXX */
455 +
456 + unregister_netdev(${local.rtx_net_dev.k_net_dev}); 427 + unregister_netdev(${local.rtx_net_dev.k_net_dev});
457 + free_netdev(${local.rtx_net_dev.k_net_dev}); 428 + free_netdev(${local.rtx_net_dev.k_net_dev});
458 } 429 }
459 430
460 /* This chunk should be removed (see #26) */ 431 /* This chunk should be removed (see #26) */
471 + attribute Builtin::symbol.scalar k_net_dev; 442 + attribute Builtin::symbol.scalar k_net_dev;
472 /* 443 /*
473 * XXX: should be a Ethernet::Device, but that causes a circular 444 * XXX: should be a Ethernet::Device, but that causes a circular
474 * dependency: 445 * dependency:
475 */ 446 */
476 - attribute Builtin::symbol rtx_ether_ctx; 447 - attribute Builtin::symbol.scalar rtx_ether_ctx;
477 + attribute Builtin::symbol.scalar rtx_ether_ctx; 448 + attribute Builtin::symbol.scalar rtx_ether_ctx;
478 } 449 }
479 450
480 provided type Device 451 provided type Device
481 diff --git a/rathaxes/samples/e1000/pci.blt b/rathaxes/samples/e1000/pci.blt 452 diff --git a/rathaxes/samples/e1000/pci.blt b/rathaxes/samples/e1000/pci.blt
499 + k_pci_dev: ((struct pci_dev *)${self}); 470 + k_pci_dev: ((struct pci_dev *)${self});
500 + rtx_pci_ctx: pci_get_drvdata((struct pci_dev *)${self}); 471 + rtx_pci_ctx: pci_get_drvdata((struct pci_dev *)${self});
501 } 472 }
502 } 473 }
503 474
504 @@ -52,13 +52,13 @@ 475 @@ -51,13 +51,13 @@
476 {
505 int error; 477 int error;
506 ${PCI::AbstractDevice} *enable_pdev = self->pdev; 478 ${PCI::AbstractDevice.ref} enable_pdev = self->pdev;
507 ${cast local.enable_pdev as PCI::AbstractDevice};
508 - error = pci_enable_device(&${local.enable_pdev.data}); 479 - error = pci_enable_device(&${local.enable_pdev.data});
509 + error = pci_enable_device(${local.enable_pdev.k_pci_dev}); 480 + error = pci_enable_device(${local.enable_pdev.k_pci_dev});
510 if (error) 481 if (error)
511 return error; 482 return error;
512 - error = pci_request_selected_regions(&${local.enable_pdev.data}, self->bars, ${config.name}); 483 - error = pci_request_selected_regions(&${local.enable_pdev.data}, self->bars, ${config.name});
516 - pci_set_master(&${local.enable_pdev.data}); 487 - pci_set_master(&${local.enable_pdev.data});
517 + pci_set_master(${local.enable_pdev.k_pci_dev}); 488 + pci_set_master(${local.enable_pdev.k_pci_dev});
518 return 0; 489 return 0;
519 } 490 }
520 491
521 @@ -68,8 +68,8 @@ 492 @@ -66,8 +66,8 @@
522 ${cast local.disable_pdev as PCI::AbstractDevice}; 493 ${PCI::AbstractDevice.ref} disable_pdev = self->pdev;
523 if (self->ioaddr) 494 if (self->ioaddr)
524 iounmap(self->ioaddr); 495 iounmap(self->ioaddr);
525 - pci_release_selected_regions(&${local.disable_pdev.data}, self->bars); 496 - pci_release_selected_regions(&${local.disable_pdev.data}, self->bars);
526 - pci_disable_device(&${local.disable_pdev.data}); 497 - pci_disable_device(&${local.disable_pdev.data});
527 + pci_release_selected_regions(${local.disable_pdev.k_pci_dev}, self->bars); 498 + pci_release_selected_regions(${local.disable_pdev.k_pci_dev}, self->bars);
528 + pci_disable_device(${local.disable_pdev.k_pci_dev}); 499 + pci_disable_device(${local.disable_pdev.k_pci_dev});
529 } 500 }
530 } 501 }
531 502
532 @@ -78,7 +78,7 @@ 503 @@ -75,7 +75,7 @@
533 ${PCI::AbstractDevice} * workaround = (${PCI::AbstractDevice}*)pdev; 504 {
534 ${cast local.workaround as PCI::AbstractDevice}; 505 ${PCI::AbstractDevice.ref} workaround = (${PCI::AbstractDevice.ref})pdev;
535 ${self}->pdev = ${pdev}; 506 ${self}->pdev = ${pdev};
536 - ${self}->bars = pci_select_bars(&${local.workaround.data}, IORESOURCE_MEM); 507 - ${self}->bars = pci_select_bars(&${local.workaround.data}, IORESOURCE_MEM);
537 + ${self}->bars = pci_select_bars(${local.workaround.k_pci_dev}, IORESOURCE_MEM); 508 + ${self}->bars = pci_select_bars(${local.workaround.k_pci_dev}, IORESOURCE_MEM);
538 ${self}->ioaddr = NULL; 509 ${self}->ioaddr = NULL;
539 ${self}->context = NULL; 510 ${self}->context = NULL;
540 } 511 }
541 @@ -97,20 +97,20 @@ 512 @@ -93,20 +93,20 @@
542 { 513 method select_ioaddr(Builtin::number bar)
543 ${PCI::AbstractDevice} *select_ioaddr_pdev = ${self}->pdev; 514 {
544 ${cast local.select_ioaddr_pdev as PCI::AbstractDevice}; 515 ${PCI::AbstractDevice.ref} select_ioaddr_pdev = ${self}->pdev;
545 - ${self}->ioaddr = pci_ioremap_bar(&${local.select_ioaddr_pdev.data}, ${bar}); 516 - ${self}->ioaddr = pci_ioremap_bar(&${local.select_ioaddr_pdev.data}, ${bar});
546 + ${self}->ioaddr = pci_ioremap_bar(${local.select_ioaddr_pdev.k_pci_dev}, ${bar}); 517 + ${self}->ioaddr = pci_ioremap_bar(${local.select_ioaddr_pdev.k_pci_dev}, ${bar});
547 } 518 }
548 519
549 - method set_context(Builtin::symbol ctx) 520 - method set_context(Builtin::symbol ctx)
562 - irq: ${self}->pdev->data.irq; 533 - irq: ${self}->pdev->data.irq;
563 + irq: ((struct pci_dev *)(${self})->pdev)->irq; 534 + irq: ((struct pci_dev *)(${self})->pdev)->irq;
564 bars: ${self}->bars; 535 bars: ${self}->bars;
565 ioaddr: ${self}->ioaddr; 536 ioaddr: ${self}->ioaddr;
566 BAR_0: 0; 537 BAR_0: 0;
567 @@ -151,7 +151,7 @@ 538 @@ -146,7 +146,7 @@
568 ${local.rtx_pci_dev.init(local.rtx_pdev)}; 539 ${local.rtx_pci_dev.init(local.rtx_pdev)};
569 } 540 }
570 541
571 - /* ${local.pdev.set_context(local.rtx_pci_dev)}; */ 542 - /* ${local.pdev.set_context(local.rtx_pci_dev)}; */
572 + /* ${local.pdev.set_rtx_context(local.rtx_pci_dev)}; */ 543 + /* ${local.pdev.set_rtx_context(local.rtx_pci_dev)}; */
573 pci_set_drvdata(pdev, rtx_pci_dev); 544 pci_set_drvdata(pdev, rtx_pci_dev);
574 545
575 /* ${local.rtx_pci_dev.enable()}; */ 546 /* ${local.rtx_pci_dev.enable()}; */
576 @@ -184,7 +184,7 @@ 547 @@ -173,7 +173,7 @@
577 return 0; 548 return 0;
578 549
579 fail: 550 fail:
580 - /* ${local.pdev.set_context(NULL)}; */ 551 - /* ${local.pdev.set_context(NULL)}; */
581 + /* ${local.pdev.set_rtx_drv_context(NULL)}; */ 552 + /* ${local.pdev.set_rtx_drv_context(NULL)}; */
582 pci_set_drvdata(pdev, NULL); 553 pci_set_drvdata(pdev, NULL);
583 kfree(rtx_pci_dev); 554 kfree(rtx_pci_dev);
584 return error; 555 return error;
585 @@ -210,7 +210,7 @@ 556 @@ -198,8 +198,7 @@
586 { 557 static void rtx_pci_remove(struct pci_dev *pdev)
587 ${PCI::AbstractDevice} *rtx_pdev = (${PCI::AbstractDevice}*)pdev; 558 {
588 ${cast local.rtx_pdev as PCI::AbstractDevice}; 559 ${PCI::AbstractDevice.ref} rtx_pdev = (${PCI::AbstractDevice.ref})pdev;
589 - ${PCI::Device} *rtx_pci_dev = ${rtx_pdev.drv_data}; 560 - ${PCI::Device.ref} rtx_pci_dev = ${rtx_pdev.drv_data};
590 + ${PCI::Device} *rtx_pci_dev = ${rtx_pdev.rtx_pci_ctx}; 561 -
591 562 + ${PCI::Device.ref} rtx_pci_dev = ${rtx_pdev.rtx_pci_ctx};
592 BUG_ON(!rtx_pci_dev); 563 BUG_ON(!rtx_pci_dev);
593 564
565 ${pointcut PCI::pci_remove_hook(local.rtx_pci_dev)};
594 diff --git a/rathaxes/samples/e1000/pci.rti b/rathaxes/samples/e1000/pci.rti 566 diff --git a/rathaxes/samples/e1000/pci.rti b/rathaxes/samples/e1000/pci.rti
595 --- a/rathaxes/samples/e1000/pci.rti 567 --- a/rathaxes/samples/e1000/pci.rti
596 +++ b/rathaxes/samples/e1000/pci.rti 568 +++ b/rathaxes/samples/e1000/pci.rti
597 @@ -10,10 +10,15 @@ 569 @@ -10,10 +10,15 @@
598 570
637 - data: ${self}->data; 609 - data: ${self}->data;
638 + k_sk_buff: ((struct sk_buff *)${self}); 610 + k_sk_buff: ((struct sk_buff *)${self});
639 } 611 }
640 } 612 }
641 613
642 @@ -46,11 +46,12 @@ 614 @@ -45,11 +45,11 @@
615 * arguments yet.
643 */ 616 */
644 ${Socket::AbstractSKBuff} *skb = self->skbuff; 617 ${Socket::AbstractSKBuff.ref} skb = self->skbuff;
645 ${cast local.skb as Socket::AbstractSKBuff};
646 - ${Ethernet::ProtocolId} ethernet_proto = { .id = be16_to_cpu(${local.skb.data}.protocol) }; 618 - ${Ethernet::ProtocolId} ethernet_proto = { .id = be16_to_cpu(${local.skb.data}.protocol) };
647 + ${Ethernet::ProtocolId} ethernet_proto = { .id = be16_to_cpu(${local.skb.k_sk_buff}->protocol) }; 619 + ${Ethernet::ProtocolId} ethernet_proto = { .id = be16_to_cpu(${local.skb.k_sk_buff}->protocol) };
648 +
649 static const char * const ip_summed_values[] = { 620 static const char * const ip_summed_values[] = {
650 "none", "unnecessary", "complete", "partial" 621 "none", "unnecessary", "complete", "partial"
651 }; 622 };
652 - struct skb_shared_info *shinfo = skb_shinfo(&${local.skb.data}); 623 - struct skb_shared_info *shinfo = skb_shinfo(&${local.skb.data});
653 + struct skb_shared_info *shinfo = skb_shinfo(${local.skb.k_sk_buff}); 624 + struct skb_shared_info *shinfo = skb_shinfo(${local.skb.k_sk_buff});
654 625
655 pr_info( 626 pr_info(
656 "\t protocol = %#-5x (%s) ip_summed = %d (%s)\n" 627 "\t protocol = %#-5x (%s) ip_summed = %d (%s)\n"
657 @@ -59,8 +60,8 @@ 628 @@ -58,8 +58,8 @@
658 "\t gso_size = %-5u gso_segs = %-5u gso_type = %-5u", 629 "\t gso_size = %-5u gso_segs = %-5u gso_type = %-5u",
659 /* XXX: can't use ${local.ethernet_proto.id} here (issue #52): */ 630 /* XXX: can't use ${local.ethernet_proto.id} here (issue #52): */
660 ethernet_proto.id, ${local.ethernet_proto.str}, 631 ethernet_proto.id, ${local.ethernet_proto.str},
661 - ${local.skb.data}.ip_summed, ip_summed_values[${local.skb.data}.ip_summed], 632 - ${local.skb.data}.ip_summed, ip_summed_values[${local.skb.data}.ip_summed],
662 - ${local.skb.data}.len, ${local.skb.data}.data_len, skb_headlen(&${local.skb.data}), 633 - ${local.skb.data}.len, ${local.skb.data}.data_len, skb_headlen(&${local.skb.data}),
663 + ${local.skb.k_sk_buff}->ip_summed, ip_summed_values[${local.skb.k_sk_buff}->ip_summed], 634 + ${local.skb.k_sk_buff}->ip_summed, ip_summed_values[${local.skb.k_sk_buff}->ip_summed],
664 + ${local.skb.k_sk_buff}->len, ${local.skb.k_sk_buff}->data_len, skb_headlen(${local.skb.k_sk_buff}), 635 + ${local.skb.k_sk_buff}->len, ${local.skb.k_sk_buff}->data_len, skb_headlen(${local.skb.k_sk_buff}),
665 shinfo->nr_frags, shinfo->gso_size, shinfo->gso_segs, shinfo->gso_type 636 shinfo->nr_frags, shinfo->gso_size, shinfo->gso_segs, shinfo->gso_type
666 ); 637 );
667 } 638 }
668 @@ -72,14 +73,13 @@ 639 @@ -70,14 +70,13 @@
669 ${Socket::AbstractSKBuff} *skb = self->skbuff; 640 {
670 ${cast local.skb as Socket::AbstractSKBuff}; 641 ${Socket::AbstractSKBuff.ref} skb = self->skbuff;
671 642
672 - WARN_ON(!skb); 643 - WARN_ON(!skb);
673 - WARN_ON(!${local.skb.data}.data); 644 - WARN_ON(!${local.skb.data}.data);
674 + WARN_ON(!${local.skb.k_sk_buff}); 645 + WARN_ON(!${local.skb.k_sk_buff});
675 WARN_ON(self->dma_handle); 646 WARN_ON(self->dma_handle);
681 + ${local.skb.k_sk_buff}, 652 + ${local.skb.k_sk_buff},
682 + skb_headlen(${local.skb.k_sk_buff}), 653 + skb_headlen(${local.skb.k_sk_buff}),
683 direction); 654 direction);
684 int err = dma_mapping_error(dev, self->dma_handle); 655 int err = dma_mapping_error(dev, self->dma_handle);
685 if (err) 656 if (err)
686 @@ -97,18 +97,17 @@ 657 @@ -94,18 +93,17 @@
687 ${Socket::AbstractSKBuff} *skb = self->skbuff; 658 {
688 ${cast local.skb as Socket::AbstractSKBuff}; 659 ${Socket::AbstractSKBuff.ref} skb = self->skbuff;
689 660
690 - WARN_ON(!${local.skb}); 661 - WARN_ON(!${local.skb});
691 - WARN_ON(!${local.skb.data}.data); 662 - WARN_ON(!${local.skb.data}.data);
692 + WARN_ON(!${local.skb.k_sk_buff}); 663 + WARN_ON(!${local.skb.k_sk_buff});
693 664
703 - dev_kfree_skb_any(&${local.skb.data}); 674 - dev_kfree_skb_any(&${local.skb.data});
704 + dev_kfree_skb_any(${local.skb.k_sk_buff}); 675 + dev_kfree_skb_any(${local.skb.k_sk_buff});
705 self->skbuff = 0; 676 self->skbuff = 0;
706 } 677 }
707 } 678 }
708 @@ -131,22 +130,22 @@ 679 @@ -128,22 +126,22 @@
709 680
710 method map_to(Device::AbstractDevice dev) 681 method map_to(Device::AbstractDevice dev)
711 { 682 {
712 - rtx_socket_skbuff_map(${self}, &${dev.data}, DMA_TO_DEVICE); 683 - rtx_socket_skbuff_map(${self}, &${dev.data}, DMA_TO_DEVICE);
713 + rtx_socket_skbuff_map(${self}, ${dev.k_device}, DMA_TO_DEVICE); 684 + rtx_socket_skbuff_map(${self}, ${dev.k_device}, DMA_TO_DEVICE);