# HG changeset patch
# Parent e201e5967e6fdec65fff42256b9a1418bc24b9be
rathaxes: change the abstract type notation in the e1000 sample

Starting with ra24db32bf134 Rathaxes types are generated differently: you
don't define entire structures anymore, but only the fields. And the
compiler generate a typedef'ed structure on top of it.

This works fine, except for "abstract types" (the types defined by —and
used to interact with— the kernel). We need to define these types as
Rathaxes types to interact with them, in Rathaxes, but with
ra24db32bf134 it means that we loose (hide) the original type from the
kernel, making it very difficult to use "abstract types" with the
kernels APIs.

For example, here the hypothetical generated struct for the abstract
type "struct net_device" from Linux would be:

typedef struct {
    struct net_device   data;
} rtx_GeneratedType;

And here is how we have to use it:

rtx_GeneratedType *my_struct;
kernel_api_function(&my_struct->data);

This &my_struct->data is actually always a nop, but it's confusing and
hard to understand.

This changeset changes the notation to:

rtx_GeneratedType *my_struct;
kernel_api_function((struct net_device *)my_struct);

Which is, I believe, more intuitive and coherent with how you would
initialize the my_struct pointer here with a return value from the
kernel (i.e: with a cast into rtx_GeneratedType *).

diff --git a/rathaxes/samples/e1000/device.blt b/rathaxes/samples/e1000/device.blt
--- a/rathaxes/samples/e1000/device.blt
+++ b/rathaxes/samples/e1000/device.blt
@@ -18,7 +18,7 @@
 
         map
         {
-            data:   ${self}->data;
+            k_device: ((struct device *)${self});
         }
     }
 }
diff --git a/rathaxes/samples/e1000/device.rti b/rathaxes/samples/e1000/device.rti
--- a/rathaxes/samples/e1000/device.rti
+++ b/rathaxes/samples/e1000/device.rti
@@ -5,6 +5,6 @@
         decl        data_types();
         chunk       LKM::includes();
         method      init();
-        attribute   Builtin::symbol.scalar data;
+        attribute   Builtin::symbol.scalar k_device;
     }
 }
diff --git a/rathaxes/samples/e1000/e1000.blt b/rathaxes/samples/e1000/e1000.blt
--- a/rathaxes/samples/e1000/e1000.blt
+++ b/rathaxes/samples/e1000/e1000.blt
@@ -171,8 +171,8 @@
 
             static int          rtx_e1000_tx_ring_tso_cksum_offload(${e1000::TxRing.ref} self, ${Socket::SKBuff.ref} skb)
             {
-                ${Socket::AbstractSKBuff.ref} abs_skb = skb->skbuff;
-                return skb_is_gso(&${local.abs_skb.data}) || ${local.abs_skb.data}.ip_summed == CHECKSUM_PARTIAL;
+                ${Socket::AbstractSKBuff.ref} k_skb = skb->skbuff;
+                return skb_is_gso(${local.k_skb.k_sk_buff}) || ${local.k_skb.k_sk_buff}->ip_summed == CHECKSUM_PARTIAL;
             }
 
             static void         rtx_e1000_tx_ring_put(${e1000::TxRing.ref} self, ${Socket::SKBuff.ref} skb)
@@ -187,16 +187,16 @@
                  * code shouldn't be aware of it and use something more
                  * abstract.
                  */
-                ${Socket::AbstractSKBuff.ref} abs_skb = skb->skbuff;
+                ${Socket::AbstractSKBuff.ref} k_skb = skb->skbuff;
                 ${e1000::TxDescriptor.ref} tx_desc = &self->base[self->tail];
                 tx_desc->lower.data = cpu_to_le32(
                         E1000_TXD_CMD_EOP  |
                         E1000_TXD_CMD_IFCS |
                         E1000_TXD_CMD_RS   |
-                        skb_headlen(&${local.abs_skb.data}));
+                        skb_headlen(${local.k_skb.k_sk_buff}));
                 tx_desc->upper.data = 0;
                 tx_desc->buff_addr = cpu_to_le64(skb->dma_handle);
-                memcpy(&self->skbuffs[self->tail], skb, sizeof(*skb));
+                memcpy(&self->skbuffs[self->tail], ${local.k_skb.k_sk_buff}, sizeof(*${local.k_skb.k_sk_buff}));
                 self->tail = (self->tail + 1) % ${config.tx_ring_size};
             }
 
@@ -732,7 +732,7 @@
             hw_ctx->rx_ring.size = ${config.rx_ring_size} * sizeof(*hw_ctx->rx_ring.base);
             hw_ctx->rx_ring.size = ALIGN(hw_ctx->rx_ring.size, 4096);
             hw_ctx->rx_ring.base = dma_alloc_coherent(
-                    &${rtx_ether_ctx.device},
+                    ${rtx_ether_ctx.device},
                     hw_ctx->rx_ring.size,
                     &hw_ctx->rx_ring.dma_base,
                     GFP_KERNEL);
@@ -750,11 +750,10 @@
              * Allocate the skbuffs, map them for DMA, and write their address
              * in the corresponding descriptor.
              */
-            ${Ethernet::AbstractDevice.ref} rtx_ether_dev = ${rtx_ether_ctx.net_device};
             for (i = 0; i != ${config.rx_ring_size}; ++i)
             {
-                hw_ctx->rx_ring.skbuffs[i].skbuff = (${Socket::AbstractSKBuff.ref})netdev_alloc_skb(
-                        &${rtx_ether_dev.netdev},
+                hw_ctx->rx_ring.skbuffs[i].skbuff = (${Socket::AbstractSKBuff}*)netdev_alloc_skb(
+                        ${rtx_ether_ctx.net_device.k_net_dev}, /* XXX: .k_net_dev isn't expanded here */
                         ${config.rx_buffer_len});
                 if (!hw_ctx->rx_ring.skbuffs[i].skbuff)
                 {
@@ -762,11 +761,11 @@
                     goto err_skbuffs_alloc;
                 }
                 hw_ctx->rx_ring.skbuffs[i].dma_handle = dma_map_single(
-                        &${rtx_ether_ctx.device},
-                        &hw_ctx->rx_ring.skbuffs[i].skbuff->data,
+                        ${rtx_ether_ctx.device},
+                        (struct sk_buff *)hw_ctx->rx_ring.skbuffs[i].skbuff, /* XXX leaking cast */
                         ${config.rx_buffer_len},
                         DMA_FROM_DEVICE);
-                int dma_error = dma_mapping_error(&${rtx_ether_ctx.device},
+                int dma_error = dma_mapping_error(${rtx_ether_ctx.device},
                         hw_ctx->rx_ring.skbuffs[i].dma_handle);
                 if (dma_error)
                 {
@@ -818,7 +817,7 @@
             hw_ctx->tx_ring.size = ${config.tx_ring_size} * sizeof(*hw_ctx->tx_ring.base);
             hw_ctx->tx_ring.size = ALIGN(hw_ctx->tx_ring.size, 4096);
             hw_ctx->tx_ring.base = dma_alloc_coherent(
-                    &${rtx_ether_ctx.device},
+                    ${rtx_ether_ctx.device},
                     hw_ctx->tx_ring.size,
                     &hw_ctx->tx_ring.dma_base,
                     GFP_KERNEL);
@@ -861,15 +860,16 @@
             while (i--)
             {
                 dma_unmap_single(
-                        &${rtx_ether_ctx.device},
+                        ${rtx_ether_ctx.device},
                         hw_ctx->rx_ring.skbuffs[i].dma_handle,
                         ${config.rx_buffer_len},
                         DMA_FROM_DEVICE);
         err_skbuffs_map:
-                dev_kfree_skb(&hw_ctx->rx_ring.skbuffs[i].skbuff->data);
+                /* XXX leaking cast: */
+                dev_kfree_skb((struct sk_buff *)hw_ctx->rx_ring.skbuffs[i].skbuff);
             }
 
-            dma_free_coherent(&${rtx_ether_ctx.device}, hw_ctx->rx_ring.size,
+            dma_free_coherent(${rtx_ether_ctx.device}, hw_ctx->rx_ring.size,
                     hw_ctx->rx_ring.base, hw_ctx->rx_ring.dma_base);
         err_rx_ring_alloc:
             return -ENOMEM;
@@ -887,8 +887,12 @@
     {
         chunk   ::CALL()
         {
-            ${e1000::Context.ref} hw_ctx;
-            hw_ctx = &${rtx_ether_ctx}->hw_ctx;
+            /*
+             * XXX: Not generated if named "hw_ctx" (which is funny because
+             * it's used and works in the template right above this one):
+             */
+            ${e1000::Context.ref} hw_ctx_;
+            hw_ctx_ = &${rtx_ether_ctx}->hw_ctx;
 
             /*
              * Free the rx ring:
@@ -898,22 +902,26 @@
             for (int i = 0; i != ${config.rx_ring_size}; ++i)
             {
                 dma_unmap_single(
-                        &${rtx_ether_ctx.device},
-                        (dma_addr_t)hw_ctx->rx_ring.skbuffs[i].dma_handle,
+                        ${rtx_ether_ctx.device},
+                        (dma_addr_t)hw_ctx_->rx_ring.skbuffs[i].dma_handle,
                         ${config.rx_buffer_len},
                         DMA_FROM_DEVICE);
-                dev_kfree_skb(&hw_ctx->rx_ring.skbuffs[i].skbuff->data);
+                /* XXX Leaking cast
+                 * (We should go through the rtx types (Socket::SKBuff,
+                 * AbstractSKBuff)
+                 */
+                dev_kfree_skb((struct sk_buff *)hw_ctx_->rx_ring.skbuffs[i].skbuff);
             }
-            dma_free_coherent(&${rtx_ether_ctx.device}, hw_ctx->rx_ring.size,
-                    hw_ctx->rx_ring.base, hw_ctx->rx_ring.dma_base);
+            dma_free_coherent(${rtx_ether_ctx.device}, hw_ctx_->rx_ring.size,
+                    hw_ctx_->rx_ring.base, hw_ctx_->rx_ring.dma_base);
             ${Log::info("free_rx_tx: rx ring free'ed")};
 
             /*
              * Free the tx ring:
              * - Free the descriptors array.
              */
-            dma_free_coherent(&${rtx_ether_ctx.device}, hw_ctx->tx_ring.size,
-                    hw_ctx->tx_ring.base, hw_ctx->tx_ring.dma_base);
+            dma_free_coherent(${rtx_ether_ctx.device}, hw_ctx_->tx_ring.size,
+                    hw_ctx_->tx_ring.base, hw_ctx_->tx_ring.dma_base);
             ${Log::info("free_rx_tx: tx ring free'ed")};
         }
     }
@@ -971,13 +979,13 @@
             ${local.skb.init(kernel_skb)};
             hw_ctx = &${rtx_ether_ctx}->hw_ctx;
             tx_ring = &hw_ctx->tx_ring;
-            devp = (${Device::AbstractDevice.ref})&${rtx_ether_ctx.device};
+            devp = (${Device::AbstractDevice.ref})${rtx_ether_ctx.device};
 
             ${Log::info("xmit: skbuff details:")};
             /*
-             * skb is not expand on the bound C variable (should be rtx_skbuff),
-             * which is funny because it works for the sequence template call
-             * right after.
+             * skb does not expand on the bound C variable (should be
+             * rtx_skbuff), which is funny because it works for the
+             * sequence template call right after.
              */
             /*
              * XXX: doesn't work (I tried to pass self explicitely too):
@@ -1010,8 +1018,8 @@
 
             /* 2. Map the data */
 
-            /* XXX: ${local.skb.map_to(local.devp)}; */
-            if (rtx_socket_skbuff_map(&skb, &${devp.data}, DMA_TO_DEVICE))
+            /* XXX: ${local.skb.map_to(devp.k_device)}; */
+            if (rtx_socket_skbuff_map(&skb, ${devp.k_device}, DMA_TO_DEVICE))
             {
                 ${Log::info("xmit: can't DMA map a SKbuff")};
                 goto err_skb_map_to;
@@ -1030,7 +1038,7 @@
         err_offload:
         err_skb_map_to:
             /* XXX: ${local.skb.unmap_to_and_free(local.dev)}; */
-            rtx_socket_skbuff_unmap_and_free(&skb, &${devp.data}, DMA_TO_DEVICE);
+            rtx_socket_skbuff_unmap_and_free(&skb, ${devp.k_device}, DMA_TO_DEVICE);
             return NETDEV_TX_OK;
         }
     }
diff --git a/rathaxes/samples/e1000/ethernet.blt b/rathaxes/samples/e1000/ethernet.blt
--- a/rathaxes/samples/e1000/ethernet.blt
+++ b/rathaxes/samples/e1000/ethernet.blt
@@ -51,7 +51,7 @@
     {
         decl  data_types()
         {
-            struct net_device ndev;
+            struct net_device   data;
         }
 
         chunk LKM::includes()
@@ -59,11 +59,16 @@
             #include <linux/netdevice.h>
         }
 
+        method  init(Builtin::symbol dev)
+        {
+            ${self} = (${Ethernet::AbstractDevice} *)${dev};
+        }
+
         map
         {
-            netdev: ${self}->ndev;
+            k_net_dev: ((struct net_device *)${self});
             /* This could be another init method for Ethernet::Device: */
-            rtx_ether_ctx: netdev_priv(&${self}->ndev);
+            rtx_ether_ctx: netdev_priv((struct net_device *)${self});
         }
     }
 
@@ -90,25 +95,33 @@
             #include <linux/etherdevice.h>
         }
 
-        method init(Ethernet::AbstractDevice net_dev, PCI::AbstractDevice pci_dev)
+        /* XXX: if the first arg is not called rtx_net_dev, it breaks. */
+        method init(Ethernet::AbstractDevice rtx_net_dev, PCI::AbstractDevice pci_dev)
         {
-            ${self} = netdev_priv(&${net_dev.netdev});
+            ${self} = ${rtx_net_dev.rtx_ether_ctx}; 
             /*
              * We can use -> because we know that ${self} will be always a
              * pointer, but the ambiguity sucks.
              */
             ${self}->pci_dev = ${pci_dev};
-            ${self}->net_dev = ${net_dev};
+            ${self}->net_dev = ${rtx_net_dev};
         }
 
         map
         {
-            device: ${self}->pci_dev->data.dev;
+            /*
+             * XXX: I'd like to be able to do things like:
+             * device: ${self.pci_dev.k_pci_dev}->dev;
+             *
+             * Also, using ${PCI::AbstractDevice} instead of directly struct
+             * pci_dev doesn't work.
+             */
+            device: (&((struct pci_dev *)(${self})->pci_dev)->dev);
             pci_device: ${self}->pci_dev;
             net_device: ${self}->net_dev;
-            perm_addr: ${self}->net_dev->ndev.perm_addr;
-            dev_addr: ${self}->net_dev->ndev.dev_addr;
-            irq: ${self}->pci_dev->data.irq;
+            perm_addr: ((struct net_device *)(${self})->net_dev)->perm_addr;
+            dev_addr: ((struct net_device *)(${self})->net_dev)->dev_addr;
+            irq: ((struct pci_dev *)(${self})->pci_dev)->irq;
         }
     }
 
@@ -128,7 +141,15 @@
         {
             static int  rtx_ethernet_open(struct net_device *dev)
             {
-                ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(dev);
+                /*
+                 * XXX The casts are here because the compiler doesn't resolve
+                 * "enclosed" type (e.g: local.var.enclosed) correctly.
+                 */
+                ${Ethernet::AbstractDevice.ref} rtx_net_dev;
+                { /* XXX: I end up with a placeholder if I don't open a scope */
+                    ${local.rtx_net_dev.init(local.dev)};
+                }
+                ${Ethernet::Device.ref} rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx};
 
                 int error;
                 {
@@ -181,7 +202,12 @@
         {
             static int  rtx_ethernet_close(struct net_device *dev)
             {
-                ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(dev);
+                ${Ethernet::AbstractDevice.ref} rtx_net_dev;
+                { /* XXX: I end up with a placeholder if I don't open a scope */
+                    ${local.rtx_net_dev.init(local.dev)};
+                }
+
+                ${Ethernet::Device.ref} rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx};
 
                 /* TODO: change this pointcut into a pointcut/adapter/callback: */
                 {
@@ -246,22 +272,24 @@
          */
         chunk PCI::pci_probe_hook(PCI::Device rtx_pci_dev)
         {
+            ${Ethernet::AbstractDevice.ref} rtx_net_dev;
             ${Ethernet::Device.ref} rtx_ether_ctx;
-            ${Ethernet::AbstractDevice.ref} net_dev;
 
-            net_dev = (${Ethernet::AbstractDevice.ref})alloc_etherdev(sizeof(*rtx_ether_ctx));
-            if (!net_dev)
+            rtx_net_dev = (${Ethernet::AbstractDevice.ref})alloc_etherdev(sizeof(*rtx_ether_ctx));
+            if (!rtx_net_dev)
             {
                 ${Log::info("cannot allocate the ethernet device context")};
                 error = -ENOMEM;
                 goto fail;
             }
-            SET_NETDEV_DEV(&${local.net_dev.netdev}, ${rtx_pci_dev.device});
-            strlcpy(${local.net_dev.netdev}.name, ${config.ifname}, sizeof(${local.net_dev.netdev}.name));
-            ${local.net_dev.netdev}.irq = ${rtx_pci_dev.irq};
-            ${local.net_dev.netdev}.netdev_ops = &rtx_ether_ops;
+            SET_NETDEV_DEV(${local.rtx_net_dev.k_net_dev}, ${rtx_pci_dev.device});
+            strlcpy(${local.rtx_net_dev.k_net_dev}->name,
+                    ${config.ifname},
+                    sizeof(${local.rtx_net_dev.k_net_dev}->name));
+            ${local.rtx_net_dev.k_net_dev}->irq = ${rtx_pci_dev.irq};
+            ${local.rtx_net_dev.k_net_dev}->netdev_ops = &rtx_ether_ops;
 
-            error = register_netdev(&${local.net_dev.netdev});
+            error = register_netdev(${local.rtx_net_dev.k_net_dev});
             if (error)
             {
                 ${Log::info("cannot register the driver in the net subsystem")};
@@ -273,13 +301,11 @@
              * XXX: the cast is here because the compiler resolve the
              * type of rtx_pci_dev.pci_device to the type of
              * rtx_pci_dev instead of the type of rtx_pci_dev.pci_device.
-             *
-             * Also, I'm getting placeholder in the generated code if
-             * I don't open a scope here.
              */
-            {
-                ${PCI::AbstractDevice.ref} rtx_pdev = ${rtx_pci_dev.pci_device};
-                ${local.rtx_ether_ctx.init(local.net_dev, local.rtx_pdev)};
+            ${PCI::AbstractDevice.ref} workaround = ${rtx_pci_dev.pci_device};
+            ${cast local.workaround as PCI::AbstractDevice};
+            { /* XXX: I end up with a placeholder if I don't open a scope */
+                ${local.rtx_ether_ctx.init(local.rtx_net_dev, local.workaround)};
             }
 
             /* Register ourselves in the parent context: */
@@ -300,7 +326,7 @@
             ${pointcut Ethernet::adapter_load_mac_address(local.rtx_ether_ctx)};
             memcpy(${local.rtx_ether_ctx.perm_addr},
                    ${local.rtx_ether_ctx.dev_addr},
-                   ${local.net_dev.netdev}.addr_len);
+                   ${local.rtx_net_dev.k_net_dev}->addr_len);
         }
 
         /* This chunk should be removed (see #26) */
@@ -317,13 +343,12 @@
          */
         chunk   PCI::pci_remove_hook(PCI::Device rtx_pci_dev)
         {
-            ${Ethernet::Device.ref} rtx_ether_ctx = ${rtx_pci_dev.context};
-            ${Ethernet::AbstractDevice.ref} rtx_ether_dev = (${Ethernet::AbstractDevice.ref})${local.rtx_ether_ctx.net_device};
-
+            ${Ethernet::Device.ref} rtx_ether_ctx = ${rtx_pci_dev.rtx_drv_context};
             BUG_ON(!rtx_ether_ctx);
 
-            unregister_netdev(&${local.rtx_ether_dev.netdev});
-            free_netdev(&${local.rtx_ether_dev.netdev});
+            ${Ethernet::AbstractDevice.ref} rtx_net_dev = ${local.rtx_ether_ctx.net_device};
+            unregister_netdev(${local.rtx_net_dev.k_net_dev});
+            free_netdev(${local.rtx_net_dev.k_net_dev});
         }
 
         /* This chunk should be removed (see #26) */
diff --git a/rathaxes/samples/e1000/ethernet.rti b/rathaxes/samples/e1000/ethernet.rti
--- a/rathaxes/samples/e1000/ethernet.rti
+++ b/rathaxes/samples/e1000/ethernet.rti
@@ -16,13 +16,14 @@
     provided type   AbstractDevice
     {
         chunk       LKM::includes();
+        method      init(Builtin::symbol);
         decl        data_types();
-        attribute   Builtin::symbol.scalar netdev;
+        attribute   Builtin::symbol.scalar  k_net_dev;
         /*
          * XXX: should be a Ethernet::Device, but that causes a circular
          * dependency:
          */
-        attribute   Builtin::symbol.scalar rtx_ether_ctx;
+        attribute   Builtin::symbol.scalar  rtx_ether_ctx;
     }
 
     provided type   Device
diff --git a/rathaxes/samples/e1000/pci.blt b/rathaxes/samples/e1000/pci.blt
--- a/rathaxes/samples/e1000/pci.blt
+++ b/rathaxes/samples/e1000/pci.blt
@@ -16,15 +16,15 @@
         {
         }
 
-        method  set_context(Builtin::symbol ctx)
+        method  set_rtx_context(Builtin::symbol ctx)
         {
-            pci_set_drvdata(&${self}->data, ${ctx});
+            pci_set_drvdata(${self.k_pci_dev}, ${ctx});
         }
 
         map
         {
-            data: ${self}->data;
-            drv_data: pci_get_drvdata(&${self}->data);
+            k_pci_dev: ((struct pci_dev *)${self});
+            rtx_pci_ctx: pci_get_drvdata((struct pci_dev *)${self});
         }
     }
 
@@ -51,13 +51,13 @@
             {
                 int error;
                 ${PCI::AbstractDevice.ref} enable_pdev = self->pdev;
-                error = pci_enable_device(&${local.enable_pdev.data});
+                error = pci_enable_device(${local.enable_pdev.k_pci_dev});
                 if (error)
                     return error;
-                error = pci_request_selected_regions(&${local.enable_pdev.data}, self->bars, ${config.name});
+                error = pci_request_selected_regions(${local.enable_pdev.k_pci_dev}, self->bars, ${config.name});
                 if (error)
                     return error;
-                pci_set_master(&${local.enable_pdev.data});
+                pci_set_master(${local.enable_pdev.k_pci_dev});
                 return 0;
             }
 
@@ -66,8 +66,8 @@
                 ${PCI::AbstractDevice.ref}  disable_pdev = self->pdev;
                 if (self->ioaddr)
                     iounmap(self->ioaddr);
-                pci_release_selected_regions(&${local.disable_pdev.data}, self->bars);
-                pci_disable_device(&${local.disable_pdev.data});
+                pci_release_selected_regions(${local.disable_pdev.k_pci_dev}, self->bars);
+                pci_disable_device(${local.disable_pdev.k_pci_dev});
             }
         }
 
@@ -75,7 +75,7 @@
         {
             ${PCI::AbstractDevice.ref} workaround = (${PCI::AbstractDevice.ref})pdev;
             ${self}->pdev = ${pdev};
-            ${self}->bars = pci_select_bars(&${local.workaround.data}, IORESOURCE_MEM);
+            ${self}->bars = pci_select_bars(${local.workaround.k_pci_dev}, IORESOURCE_MEM);
             ${self}->ioaddr = NULL;
             ${self}->context = NULL;
         }
@@ -93,20 +93,20 @@
         method  select_ioaddr(Builtin::number bar)
         {
             ${PCI::AbstractDevice.ref} select_ioaddr_pdev = ${self}->pdev;
-            ${self}->ioaddr = pci_ioremap_bar(&${local.select_ioaddr_pdev.data}, ${bar});
+            ${self}->ioaddr = pci_ioremap_bar(${local.select_ioaddr_pdev.k_pci_dev}, ${bar});
         }
 
-        method  set_context(Builtin::symbol ctx)
+        method  set_rtx_drv_context(Builtin::symbol ctx)
         {
             ${self}->context = ctx;
         }
 
         map
         {
-            context: ${self}->context;
-            device: &${self}->pdev->data.dev;
+            rtx_drv_context: ${self}->context;
+            device: &((struct pci_dev *)(${self})->pdev)->dev;
             pci_device: ${self}->pdev;
-            irq: ${self}->pdev->data.irq;
+            irq: ((struct pci_dev *)(${self})->pdev)->irq;
             bars: ${self}->bars;
             ioaddr: ${self}->ioaddr;
             BAR_0: 0;
@@ -146,7 +146,7 @@
                     ${local.rtx_pci_dev.init(local.rtx_pdev)};
                 }
 
-                /* ${local.pdev.set_context(local.rtx_pci_dev)}; */
+                /* ${local.pdev.set_rtx_context(local.rtx_pci_dev)}; */
                 pci_set_drvdata(pdev, rtx_pci_dev);
 
                 /* ${local.rtx_pci_dev.enable()}; */
@@ -173,7 +173,7 @@
                 return 0;
 
             fail:
-                /* ${local.pdev.set_context(NULL)}; */
+                /* ${local.pdev.set_rtx_drv_context(NULL)}; */
                 pci_set_drvdata(pdev, NULL);
                 kfree(rtx_pci_dev);
                 return error;
@@ -198,8 +198,7 @@
             static void rtx_pci_remove(struct pci_dev *pdev)
             {
                 ${PCI::AbstractDevice.ref} rtx_pdev = (${PCI::AbstractDevice.ref})pdev;
-                ${PCI::Device.ref} rtx_pci_dev = ${rtx_pdev.drv_data};
-
+                ${PCI::Device.ref} rtx_pci_dev = ${rtx_pdev.rtx_pci_ctx};
                 BUG_ON(!rtx_pci_dev);
 
                 ${pointcut PCI::pci_remove_hook(local.rtx_pci_dev)};
diff --git a/rathaxes/samples/e1000/pci.rti b/rathaxes/samples/e1000/pci.rti
--- a/rathaxes/samples/e1000/pci.rti
+++ b/rathaxes/samples/e1000/pci.rti
@@ -10,10 +10,15 @@
 
         chunk       LKM::includes();
         method      init(PCI::AbstractDevice);
-        method      set_context(Builtin::symbol);
-
-        attribute   Builtin::symbol.scalar data;
-        attribute   Builtin::symbol.scalar drv_data;
+        /*
+         * XXX: the argument should be a PCI::Device but that causes a circular
+         * dependency:
+         */
+        method      set_rtx_context(Builtin::symbol);
+ 
+        attribute   Builtin::symbol.scalar k_pci_dev;
+        /* XXX: should be PCI::Device (see above point) */
+        attribute   Builtin::symbol.scalar rtx_pci_ctx;
     }
 
     provided type   PCI::Device
@@ -27,9 +32,10 @@
         method      enable();
         method      disable();
         method      select_ioaddr(Builtin::number);
-        method      set_context(Builtin::symbol);
 
-        attribute   Builtin::symbol.scalar      context;
+        method      set_rtx_drv_context(Builtin::symbol);
+ 
+        attribute   Builtin::symbol.scalar      rtx_drv_context;
         attribute   Device::AbstractDevice.ref  device;
         attribute   PCI::AbstractDevice.ref     pci_device;
         attribute   Builtin::symbol.ref         ioaddr;
diff --git a/rathaxes/samples/e1000/socket.blt b/rathaxes/samples/e1000/socket.blt
--- a/rathaxes/samples/e1000/socket.blt
+++ b/rathaxes/samples/e1000/socket.blt
@@ -14,7 +14,7 @@
 
         map
         {
-            data: ${self}->data;
+            k_sk_buff: ((struct sk_buff *)${self});
         }
     }
 
@@ -45,11 +45,11 @@
                  * arguments yet.
                  */
                 ${Socket::AbstractSKBuff.ref} skb = self->skbuff;
-                ${Ethernet::ProtocolId} ethernet_proto = { .id = be16_to_cpu(${local.skb.data}.protocol) };
+                ${Ethernet::ProtocolId} ethernet_proto = { .id = be16_to_cpu(${local.skb.k_sk_buff}->protocol) };
                 static const char * const ip_summed_values[] = {
                     "none", "unnecessary", "complete", "partial"
                 };
-                struct skb_shared_info *shinfo = skb_shinfo(&${local.skb.data});
+                struct skb_shared_info *shinfo = skb_shinfo(${local.skb.k_sk_buff});
 
                 pr_info(
                         "\t protocol = %#-5x (%s) ip_summed = %d (%s)\n"
@@ -58,8 +58,8 @@
                         "\t gso_size = %-5u gso_segs = %-5u gso_type = %-5u",
                         /* XXX: can't use ${local.ethernet_proto.id} here (issue #52): */
                         ethernet_proto.id, ${local.ethernet_proto.str},
-                        ${local.skb.data}.ip_summed, ip_summed_values[${local.skb.data}.ip_summed],
-                        ${local.skb.data}.len, ${local.skb.data}.data_len, skb_headlen(&${local.skb.data}),
+                        ${local.skb.k_sk_buff}->ip_summed, ip_summed_values[${local.skb.k_sk_buff}->ip_summed],
+                        ${local.skb.k_sk_buff}->len, ${local.skb.k_sk_buff}->data_len, skb_headlen(${local.skb.k_sk_buff}),
                         shinfo->nr_frags, shinfo->gso_size, shinfo->gso_segs, shinfo->gso_type
                 );
             }
@@ -70,14 +70,13 @@
             {
                 ${Socket::AbstractSKBuff.ref}   skb = self->skbuff;
 
-                WARN_ON(!skb);
-                WARN_ON(!${local.skb.data}.data);
+                WARN_ON(!${local.skb.k_sk_buff});
                 WARN_ON(self->dma_handle);
 
                 self->dma_handle = dma_map_single(
                         dev,
-                        &${local.skb.data}.data,
-                        skb_headlen(&${local.skb.data}),
+                        ${local.skb.k_sk_buff},
+                        skb_headlen(${local.skb.k_sk_buff}),
                         direction);
                 int err = dma_mapping_error(dev, self->dma_handle);
                 if (err)
@@ -94,18 +93,17 @@
             {
                 ${Socket::AbstractSKBuff.ref}   skb = self->skbuff;
 
-                WARN_ON(!${local.skb});
-                WARN_ON(!${local.skb.data}.data);
+                WARN_ON(!${local.skb.k_sk_buff});
 
                 if (self->dma_handle)
                 {
                     dma_unmap_single(dev,
                             self->dma_handle,
-                            skb_headlen(&${local.skb.data}),
+                            skb_headlen(${local.skb.k_sk_buff}),
                             direction);
                     self->dma_handle = 0;
                 }
-                dev_kfree_skb_any(&${local.skb.data});
+                dev_kfree_skb_any(${local.skb.k_sk_buff});
                 self->skbuff = 0;
             }
         }
@@ -128,22 +126,22 @@
 
         method   map_to(Device::AbstractDevice dev)
         {
-            rtx_socket_skbuff_map(${self}, &${dev.data}, DMA_TO_DEVICE);
+            rtx_socket_skbuff_map(${self}, ${dev.k_device}, DMA_TO_DEVICE);
         }
 
         method   map_from(Device::AbstractDevice dev)
         {
-            rtx_socket_skbuff_map(${self}, &${dev.data}, DMA_FROM_DEVICE);
+            rtx_socket_skbuff_map(${self}, ${dev.k_device}, DMA_FROM_DEVICE);
         }
 
         method   unmap_to_and_free(Device::AbstractDevice dev)
         {
-            rtx_socket_skbuff_unmap_and_free(${self}, &${dev.data}, DMA_TO_DEVICE);
+            rtx_socket_skbuff_unmap_and_free(${self}, ${dev.k_device}, DMA_TO_DEVICE);
         }
 
         method   unmap_from_and_free(Device::AbstractDevice dev)
         {
-            rtx_socket_skbuff_unmap_and_free(${self}, &${dev.data}, DMA_FROM_DEVICE);
+            rtx_socket_skbuff_unmap_and_free(${self}, ${dev.k_device}, DMA_FROM_DEVICE);
         }
 
         map
diff --git a/rathaxes/samples/e1000/socket.rti b/rathaxes/samples/e1000/socket.rti
--- a/rathaxes/samples/e1000/socket.rti
+++ b/rathaxes/samples/e1000/socket.rti
@@ -5,7 +5,7 @@
     {
         chunk       LKM::includes();
         decl        data_types();
-        attribute   Builtin::symbol.scalar data;
+        attribute   Builtin::symbol.scalar k_sk_buff;
     }
 
     provided type   SKBuff
