# HG changeset patch # User Louis Opter # Date 1372828768 25200 # Node ID b83b0432a45b217ac89d792f4125da78d0d98100 # Parent 3523e795bdf9c868b0253e0a844e7ff03e192f5b Finish the serie about the ref/scalar refactor + interrupt handler cleanups diff -r 3523e795bdf9 -r b83b0432a45b E1000_UpdateToScalarRef --- a/E1000_UpdateToScalarRef Mon Apr 01 00:56:28 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,570 +0,0 @@ -# HG changeset patch -# User David Pineau -# Parent c9b5caeeebc6f7778a9cc5bcea67355fbbdc1120 -Update the e1000 sample with the new features - -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 -@@ -87,7 +87,7 @@ - decl data_types() - { - unsigned int size; -- ${e1000::RxDescriptor} *base; -+ ${e1000::RxDescriptor.ref} base; - dma_addr_t dma_base; - ${Socket::SKBuff} skbuffs[${config.rx_ring_size}]; - } -@@ -124,7 +124,7 @@ - { - unsigned int size; - /* XXX: can't use ${e1000::TxDescriptor} here: */ -- ${e1000::TxDescriptor} *base; /* rename to descs */ -+ ${e1000::TxDescriptor.ref} base; /* rename to descs */ - dma_addr_t dma_base; - ${Socket::SKBuff} skbuffs[${config.tx_ring_size}]; - unsigned short head; -@@ -133,20 +133,20 @@ - - chunk LKM::prototypes() - { -- static void rtx_e1000_tx_ring_clean(${e1000::TxRing} *); -- static unsigned int rtx_e1000_tx_ring_descriptors_remaining(${e1000::TxRing} *); -- static int rtx_e1000_tx_ring_tso_cksum_offload(${e1000::TxRing} *, ${Socket::SKBuff} *); -- static void rtx_e1000_tx_ring_put(${e1000::TxRing} *, ${Socket::SKBuff} *); -+ static void rtx_e1000_tx_ring_clean(${e1000::TxRing.ref}); -+ static unsigned int rtx_e1000_tx_ring_descriptors_remaining(${e1000::TxRing.ref}); -+ static int rtx_e1000_tx_ring_tso_cksum_offload(${e1000::TxRing.ref}, ${Socket::SKBuff.ref}); -+ static void rtx_e1000_tx_ring_put(${e1000::TxRing.ref}, ${Socket::SKBuff.ref}); - /* FIXME: See issue #54 */ -- static void rtx_e1000_tx_ring_start_xmit(${e1000::TxRing} *, /*const*/ ${e1000::Context} *); -+ static void rtx_e1000_tx_ring_start_xmit(${e1000::TxRing.ref}, /*const*/ ${e1000::Context.ref}); - } - - chunk LKM::code() - { -- static void rtx_e1000_tx_ring_clean(${e1000::TxRing} *self) -+ static void rtx_e1000_tx_ring_clean(${e1000::TxRing.ref} self) - { -- ${e1000::TxDescriptor} *tx_desc; -- bool done; -+ ${e1000::TxDescriptor.ref} tx_desc; -+ bool done; - - for (; self->head != self->tail; self->head++) - { -@@ -159,7 +159,7 @@ - pr_info("%s: tx_ring_clean: moving head to %d/%d", ${config.name}, self->head, ${config.tx_ring_size}); - } - -- static unsigned int rtx_e1000_tx_ring_descriptors_remaining(${e1000::TxRing} *self) -+ static unsigned int rtx_e1000_tx_ring_descriptors_remaining(${e1000::TxRing.ref} self) - { - if (self->tail == self->head) /* ring is empty */ - return 256; /* XXX: ${config.tx_ring_size}; */ -@@ -169,14 +169,13 @@ - return self->head - self->tail; - } - -- static int rtx_e1000_tx_ring_tso_cksum_offload(${e1000::TxRing} *self, ${Socket::SKBuff} *skb) -+ static int rtx_e1000_tx_ring_tso_cksum_offload(${e1000::TxRing.ref} self, ${Socket::SKBuff.ref} skb) - { -- ${Socket::AbstractSKBuff} *abs_skb = skb->skbuff; -- ${cast local.abs_skb as Socket::AbstractSKBuff}; -+ ${Socket::AbstractSKBuff.ref} abs_skb = skb->skbuff; - return skb_is_gso(&${local.abs_skb.data}) || ${local.abs_skb.data}.ip_summed == CHECKSUM_PARTIAL; - } - -- static void rtx_e1000_tx_ring_put(${e1000::TxRing} *self, ${Socket::SKBuff} *skb) -+ static void rtx_e1000_tx_ring_put(${e1000::TxRing.ref} self, ${Socket::SKBuff.ref} skb) - { - WARN_ON(!skb); - -@@ -188,9 +187,8 @@ - * code shouldn't be aware of it and use something more - * abstract. - */ -- ${Socket::AbstractSKBuff} *abs_skb = skb->skbuff; -- ${cast local.abs_skb as Socket::AbstractSKBuff}; -- ${e1000::TxDescriptor} *tx_desc = &self->base[self->tail]; -+ ${Socket::AbstractSKBuff.ref} abs_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 | -@@ -203,7 +201,7 @@ - } - - /* FIXME: See issue #54 */ -- static void rtx_e1000_tx_ring_start_xmit(${e1000::TxRing} *self, /*const*/ ${e1000::Context} *hw_ctx) -+ static void rtx_e1000_tx_ring_start_xmit(${e1000::TxRing.ref} self, /*const*/ ${e1000::Context.ref} hw_ctx) - { - pr_info("%s: start_xmit: moving tail to %d/%d", ${config.name}, self->tail, ${config.tx_ring_size}); - rtx_e1000_register_write32(hw_ctx, E1000_TDT, self->tail); -@@ -271,7 +269,7 @@ - Builtin::number irq) - { - { -- ${e1000::Context} *hw_ctx = &${rtx_ether_ctx}->hw_ctx; -+ ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx; - hw_ctx->bars = ${bars}; - hw_ctx->ioaddr = ${ioaddr}; - hw_ctx->irq = ${irq}; -@@ -281,8 +279,9 @@ - chunk Ethernet::adapter_reset(Ethernet::Device rtx_ether_ctx) - { - { -- ${e1000::Context} *hw_ctx = &${rtx_ether_ctx}->hw_ctx; -- rtx_e1000_register_write32(hw_ctx, E1000_CTRL, E1000_CMD_RST); -+ /* XXX Naming this variable 'hw_ctx' kicks the decl out of the generated code */ -+ ${e1000::Context.ref} tmp_hw_ctx = &${rtx_ether_ctx}->hw_ctx; -+ rtx_e1000_register_write32(tmp_hw_ctx, E1000_CTRL, E1000_CMD_RST); - udelay(10); - } - } -@@ -290,7 +289,7 @@ - chunk Ethernet::adapter_load_mac_address(Ethernet::Device rtx_ether_ctx) - { - { -- ${e1000::Context} *hw_ctx = &${rtx_ether_ctx}->hw_ctx; -+ ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx; - /* Shamelessly borrowed from Minix */ - for (int i = 0; i < 3; ++i) - { -@@ -469,12 +468,12 @@ - { - chunk LKM::prototypes() - { -- static void rtx_e1000_print_status(${e1000::Context} *); -+ static void rtx_e1000_print_status(${e1000::Context.ref}); - } - - chunk LKM::code() - { -- static void rtx_e1000_print_status(${e1000::Context} *hw_ctx) -+ static void rtx_e1000_print_status(${e1000::Context.ref} hw_ctx) - { - unsigned int status = rtx_e1000_register_read32(hw_ctx, E1000_STATUS); - ${Log::info("card status:")}; -@@ -519,13 +518,13 @@ - chunk LKM::prototypes() - { - /* FIXME: See issue #54 */ -- static unsigned int rtx_e1000_register_read32(/*const*/ ${e1000::Context} *, unsigned int); -+ static unsigned int rtx_e1000_register_read32(/*const*/ ${e1000::Context.ref}, unsigned int); - } - - chunk LKM::code() - { - /* FIXME: See issue #54 */ -- static unsigned int rtx_e1000_register_read32(/*const*/ ${e1000::Context} *ctx, unsigned int reg_offset) -+ static unsigned int rtx_e1000_register_read32(/*const*/ ${e1000::Context.ref} ctx, unsigned int reg_offset) - { - return ioread32(ctx->ioaddr + reg_offset); - } -@@ -542,13 +541,13 @@ - chunk LKM::prototypes() - { - /* FIXME: See issue #54 */ -- static void rtx_e1000_register_write32(/*const*/ ${e1000::Context} *, unsigned int, unsigned int); -+ static void rtx_e1000_register_write32(/*const*/ ${e1000::Context.ref}, unsigned int, unsigned int); - } - - chunk LKM::code() - { - /* FIXME: See issue #54 */ -- static void rtx_e1000_register_write32(/*const*/ ${e1000::Context} *ctx, unsigned int reg_offset, unsigned int value) -+ static void rtx_e1000_register_write32(/*const*/ ${e1000::Context.ref} ctx, unsigned int reg_offset, unsigned int value) - { - iowrite32(value, ctx->ioaddr + reg_offset); - } -@@ -565,13 +564,13 @@ - chunk LKM::prototypes() - { - /* FIXME: See issue #54 */ -- static void rtx_e1000_register_set32(/*const*/ ${e1000::Context} *, unsigned int, unsigned int); -+ static void rtx_e1000_register_set32(/*const*/ ${e1000::Context.ref}, unsigned int, unsigned int); - } - - chunk LKM::code() - { - /* FIXME: See issue #54 */ -- static void rtx_e1000_register_set32(/*const*/ ${e1000::Context} *ctx, unsigned int reg_offset, unsigned int value) -+ static void rtx_e1000_register_set32(/*const*/ ${e1000::Context.ref} ctx, unsigned int reg_offset, unsigned int value) - { - iowrite32(rtx_e1000_register_read32(ctx, reg_offset) | value, ctx->ioaddr + reg_offset); - } -@@ -588,13 +587,13 @@ - chunk LKM::prototypes() - { - /* FIXME: See issue #54 */ -- static void rtx_e1000_register_unset32(/*const*/ ${e1000::Context} *, unsigned int, unsigned int); -+ static void rtx_e1000_register_unset32(/*const*/ ${e1000::Context.ref}, unsigned int, unsigned int); - } - - chunk LKM::code() - { - /* FIXME: See issue #54 */ -- static void rtx_e1000_register_unset32(/*const*/ ${e1000::Context} *ctx, unsigned int reg_offset, unsigned int value) -+ static void rtx_e1000_register_unset32(/*const*/ ${e1000::Context.ref} ctx, unsigned int reg_offset, unsigned int value) - { - iowrite32(rtx_e1000_register_read32(ctx, reg_offset) & ~value, ctx->ioaddr + reg_offset); - } -@@ -707,7 +706,7 @@ - * e1000::Context? (but we would need to make it point back to - * the struct net_device) - */ -- ${e1000::Context} *hw_ctx; -+ ${e1000::Context.ref} hw_ctx; - hw_ctx = &${rtx_ether_ctx}->hw_ctx; - - /* -@@ -816,11 +815,10 @@ - * Allocate the skbuffs, map them for DMA, and write their address - * in the corresponding descriptor. - */ -- ${Ethernet::AbstractDevice} *rtx_ether_dev = ${rtx_ether_ctx.net_device}; -- ${cast local.rtx_ether_dev as Ethernet::AbstractDevice}; -+ ${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}*) netdev_alloc_skb( -+ hw_ctx->rx_ring.skbuffs[i].skbuff = (${Socket::AbstractSKBuff.ref})netdev_alloc_skb( - &${rtx_ether_dev.netdev}, - ${config.rx_buffer_len}); - if (!hw_ctx->rx_ring.skbuffs[i].skbuff) -@@ -954,7 +952,7 @@ - { - chunk ::CALL() - { -- ${e1000::Context} *hw_ctx; -+ ${e1000::Context.ref} hw_ctx; - hw_ctx = &${rtx_ether_ctx}->hw_ctx; - - /* -@@ -1031,14 +1029,14 @@ - */ - - ${Socket::SKBuff} skb; -- ${e1000::Context} *hw_ctx; -- ${e1000::TxRing} *tx_ring; -- ${Device::AbstractDevice} *devp; -+ ${e1000::Context.ref} hw_ctx; -+ ${e1000::TxRing.ref} tx_ring; -+ ${Device::AbstractDevice.ref} devp; - - ${local.skb.init(kernel_skb)}; - hw_ctx = &${rtx_ether_ctx}->hw_ctx; - tx_ring = &hw_ctx->tx_ring; -- devp = (${Device::AbstractDevice}*) &${rtx_ether_ctx.device}; -+ devp = (${Device::AbstractDevice.ref})&${rtx_ether_ctx.device}; - - ${Log::info("xmit: skbuff details:")}; - /* -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 -@@ -73,8 +73,8 @@ - * I think it's useless to use the ${PCI::AbstractDevice} "abstraction" - * here, since we already are in a Linux specific context. - */ -- ${PCI::AbstractDevice} *pci_dev; -- ${Ethernet::AbstractDevice} *net_dev; -+ ${PCI::AbstractDevice.ref} pci_dev; -+ ${Ethernet::AbstractDevice.ref} net_dev; - - /* - * In the long-term, this may disappear for a new concept allowing -@@ -120,9 +120,8 @@ - { - static int rtx_ethernet_open(struct net_device *dev) - { -- ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(dev); -+ ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(dev); - -- ${cast local.rtx_ether_ctx as Ethernet::Device}; - ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; - - return 0; -@@ -141,10 +140,8 @@ - { - static int rtx_ethernet_xmit(struct sk_buff* kernel_skb, struct net_device *net_dev) - { -- ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(net_dev); -- ${Socket::AbstractSKBuff} *rtx_skb = (${Socket::AbstractSKBuff}*) kernel_skb; -- ${cast local.rtx_skb as Socket::AbstractSKBuff}; -- ${cast local.rtx_ether_ctx as Ethernet::Device}; -+ ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(net_dev); -+ ${Socket::AbstractSKBuff.ref} rtx_skb = (${Socket::AbstractSKBuff.ref}) kernel_skb; - - ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx, local.rtx_skb)}; - } -@@ -162,9 +159,8 @@ - { - static int rtx_ethernet_close(struct net_device *dev) - { -- ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(dev); -+ ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(dev); - -- ${cast local.rtx_ether_ctx as Ethernet::Device}; - ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; - - return 0; -@@ -187,9 +183,8 @@ - { - static enum irqreturn rtx_ethernet_interrupt_handler(int irq, void *dev_id) - { -- ${Ethernet::Device} *rtx_ether_ctx = dev_id; -+ ${Ethernet::Device.ref} rtx_ether_ctx = dev_id; - -- ${cast local.rtx_ether_ctx as Ethernet::Device}; - ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; - - return IRQ_NONE; -@@ -219,11 +214,10 @@ - */ - chunk PCI::pci_probe_hook(PCI::Device rtx_pci_dev) - { -- ${Ethernet::Device} *rtx_ether_ctx; -- ${Ethernet::AbstractDevice} *net_dev; -- ${cast local.net_dev as Ethernet::AbstractDevice}; -+ ${Ethernet::Device.ref} rtx_ether_ctx; -+ ${Ethernet::AbstractDevice.ref} net_dev; - -- net_dev = (${Ethernet::AbstractDevice}*) alloc_etherdev(sizeof(*rtx_ether_ctx)); -+ net_dev = (${Ethernet::AbstractDevice.ref})alloc_etherdev(sizeof(*rtx_ether_ctx)); - if (!net_dev) - { - ${Log::info("cannot allocate the ethernet device context")}; -@@ -252,8 +246,7 @@ - * I don't open a scope here. - */ - { -- ${PCI::AbstractDevice} *rtx_pdev = ${rtx_pci_dev.pci_device}; -- ${cast local.rtx_pdev as PCI::AbstractDevice}; -+ ${PCI::AbstractDevice.ref} rtx_pdev = ${rtx_pci_dev.pci_device}; - ${local.rtx_ether_ctx.init(local.net_dev, local.rtx_pdev)}; - } - -@@ -270,7 +263,6 @@ - int irq = ${rtx_pci_dev.irq}; - ${cast local.bars as Builtin::number}; - ${cast local.irq as Builtin::number}; -- ${cast local.rtx_ether_ctx as Ethernet::Device}; - ${pointcut Ethernet::adapter_init_context(local.rtx_ether_ctx, - local.bars, - local.ioaddr, -@@ -296,13 +288,11 @@ - */ - chunk PCI::pci_remove_hook(PCI::Device rtx_pci_dev) - { -- ${Ethernet::Device} *rtx_ether_ctx = ${rtx_pci_dev.context}; -- ${Ethernet::AbstractDevice} *rtx_ether_dev = (${Ethernet::AbstractDevice}*) ${local.rtx_ether_ctx.net_device}; -+ ${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}; - - BUG_ON(!rtx_ether_ctx); - -- ${cast local.rtx_ether_ctx as Ethernet::Device}; -- ${cast local.rtx_ether_dev as Ethernet::AbstractDevice}; - unregister_netdev(&${local.rtx_ether_dev.netdev}); - free_netdev(&${local.rtx_ether_dev.netdev}); - } -@@ -313,4 +303,3 @@ - } - } - } -- -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 -@@ -34,8 +34,8 @@ - * I'd like to use better names here, but I'd like to understand the - * difference between the two first: - */ -- attribute Builtin::symbol.scalar perm_addr; -- attribute Builtin::symbol.scalar dev_addr; -+ attribute Builtin::symbol.ref perm_addr; -+ attribute Builtin::symbol.ref dev_addr; - } - - required sequence open(Ethernet::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 -@@ -32,7 +32,7 @@ - { - decl data_types() - { -- ${PCI::AbstractDevice} *pdev; -+ ${PCI::AbstractDevice.ref} pdev; - int bars; - /* It could be an array at some point: */ - unsigned char /* __iomem */ *ioaddr; -@@ -41,17 +41,16 @@ - - chunk LKM::prototypes() - { -- static int rtx_pci_device_enable(${PCI::Device} *); -- static void rtx_pci_device_disable(${PCI::Device} *); -+ static int rtx_pci_device_enable(${PCI::Device.ref}); -+ static void rtx_pci_device_disable(${PCI::Device.ref}); - } - - chunk LKM::code() - { -- static int rtx_pci_device_enable(${PCI::Device} *self) -+ static int rtx_pci_device_enable(${PCI::Device.ref} self) - { - int error; -- ${PCI::AbstractDevice} *enable_pdev = self->pdev; -- ${cast local.enable_pdev as PCI::AbstractDevice}; -+ ${PCI::AbstractDevice.ref} enable_pdev = self->pdev; - error = pci_enable_device(&${local.enable_pdev.data}); - if (error) - return error; -@@ -62,10 +61,9 @@ - return 0; - } - -- static void rtx_pci_device_disable(${PCI::Device} *self) -+ static void rtx_pci_device_disable(${PCI::Device.ref} self) - { -- ${PCI::AbstractDevice} *disable_pdev = self->pdev; -- ${cast local.disable_pdev as PCI::AbstractDevice}; -+ ${PCI::AbstractDevice.ref} disable_pdev = self->pdev; - if (self->ioaddr) - iounmap(self->ioaddr); - pci_release_selected_regions(&${local.disable_pdev.data}, self->bars); -@@ -75,8 +73,7 @@ - - method init(PCI::AbstractDevice pdev) - { -- ${PCI::AbstractDevice} * workaround = (${PCI::AbstractDevice}*)pdev; -- ${cast local.workaround as PCI::AbstractDevice}; -+ ${PCI::AbstractDevice.ref} workaround = (${PCI::AbstractDevice.ref})pdev; - ${self}->pdev = ${pdev}; - ${self}->bars = pci_select_bars(&${local.workaround.data}, IORESOURCE_MEM); - ${self}->ioaddr = NULL; -@@ -95,8 +92,7 @@ - - method select_ioaddr(Builtin::number bar) - { -- ${PCI::AbstractDevice} *select_ioaddr_pdev = ${self}->pdev; -- ${cast local.select_ioaddr_pdev as PCI::AbstractDevice}; -+ ${PCI::AbstractDevice.ref} select_ioaddr_pdev = ${self}->pdev; - ${self}->ioaddr = pci_ioremap_bar(&${local.select_ioaddr_pdev.data}, ${bar}); - } - -@@ -131,9 +127,8 @@ - const struct pci_device_id *pdev_id) - { - int error; -- ${PCI::Device} *rtx_pci_dev; -- ${PCI::AbstractDevice} *rtx_pdev = (${PCI::AbstractDevice}*)pdev; -- ${cast local.rtx_pdev as PCI::AbstractDevice}; -+ ${PCI::Device.ref} rtx_pci_dev; -+ ${PCI::AbstractDevice.ref} rtx_pdev = (${PCI::AbstractDevice.ref})pdev; - - rtx_pci_dev = kmalloc(sizeof(*rtx_pci_dev), GFP_KERNEL); - if (!rtx_pci_dev) -@@ -173,12 +168,6 @@ - goto fail; - } - -- /* -- * XXX: We have to cast here because the compiler is -- * confused by the fact that rtx_pci_dev is a -- * pointer. -- */ -- ${cast local.rtx_pci_dev as PCI::Device}; - ${pointcut PCI::pci_probe_hook(local.rtx_pci_dev)}; - - return 0; -@@ -208,14 +197,11 @@ - { - static void rtx_pci_remove(struct pci_dev *pdev) - { -- ${PCI::AbstractDevice} *rtx_pdev = (${PCI::AbstractDevice}*)pdev; -- ${cast local.rtx_pdev as PCI::AbstractDevice}; -- ${PCI::Device} *rtx_pci_dev = ${rtx_pdev.drv_data}; -+ ${PCI::AbstractDevice.ref} rtx_pdev = (${PCI::AbstractDevice.ref})pdev; -+ ${PCI::Device.ref} rtx_pci_dev = ${rtx_pdev.drv_data}; - - BUG_ON(!rtx_pci_dev); - -- /* XXX: compiler confused by the pointer type. */ -- ${cast local.rtx_pci_dev as PCI::Device}; - ${pointcut PCI::pci_remove_hook(local.rtx_pci_dev)}; - - /* ${local.rtx_pci_dev.disable()}; */ -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 -@@ -22,20 +22,20 @@ - { - decl data_types() - { -- ${Socket::AbstractSKBuff} *skbuff; -- dma_addr_t dma_handle; -+ ${Socket::AbstractSKBuff.ref} skbuff; -+ dma_addr_t dma_handle; - } - - chunk LKM::prototypes() - { -- static void rtx_socket_skbuff_dump_infos(${Socket::SKBuff} *); -- static int rtx_socket_skbuff_map(${Socket::SKBuff} *, struct device *, enum dma_data_direction); -- static void rtx_socket_skbuff_unmap_and_free(${Socket::SKBuff} *, struct device *, enum dma_data_direction); -+ static void rtx_socket_skbuff_dump_infos(${Socket::SKBuff.ref}); -+ static int rtx_socket_skbuff_map(${Socket::SKBuff.ref}, struct device *, enum dma_data_direction); -+ static void rtx_socket_skbuff_unmap_and_free(${Socket::SKBuff.ref}, struct device *, enum dma_data_direction); - } - - chunk LKM::code() - { -- static void rtx_socket_skbuff_dump_infos(${Socket::SKBuff} *self) -+ static void rtx_socket_skbuff_dump_infos(${Socket::SKBuff.ref} self) - { - WARN_ON(!self->skbuff); - -@@ -44,8 +44,7 @@ - * but Rathaxes doesn't support functions with a variable number of - * arguments yet. - */ -- ${Socket::AbstractSKBuff} *skb = self->skbuff; -- ${cast local.skb as Socket::AbstractSKBuff}; -+ ${Socket::AbstractSKBuff.ref} skb = self->skbuff; - ${Ethernet::ProtocolId} ethernet_proto = { .id = be16_to_cpu(${local.skb.data}.protocol) }; - static const char * const ip_summed_values[] = { - "none", "unnecessary", "complete", "partial" -@@ -65,12 +64,11 @@ - ); - } - -- static int rtx_socket_skbuff_map(${Socket::SKBuff} *self, -+ static int rtx_socket_skbuff_map(${Socket::SKBuff.ref} self, - struct device *dev, - enum dma_data_direction direction) - { -- ${Socket::AbstractSKBuff} *skb = self->skbuff; -- ${cast local.skb as Socket::AbstractSKBuff}; -+ ${Socket::AbstractSKBuff.ref} skb = self->skbuff; - - WARN_ON(!skb); - WARN_ON(!${local.skb.data}.data); -@@ -90,12 +88,11 @@ - return 0; - } - -- static void rtx_socket_skbuff_unmap_and_free(${Socket::SKBuff} *self, -+ static void rtx_socket_skbuff_unmap_and_free(${Socket::SKBuff.ref} self, - struct device *dev, - enum dma_data_direction direction) - { -- ${Socket::AbstractSKBuff} *skb = self->skbuff; -- ${cast local.skb as Socket::AbstractSKBuff}; -+ ${Socket::AbstractSKBuff.ref} skb = self->skbuff; - - WARN_ON(!${local.skb}); - WARN_ON(!${local.skb.data}.data); diff -r 3523e795bdf9 -r b83b0432a45b FixRecursiveTypeFieldResolution --- a/FixRecursiveTypeFieldResolution Mon Apr 01 00:56:28 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -# HG changeset patch -# User David Pineau -# Parent b0ffdcc59bfa94a5b97dfa7117d73e2a2d7cf999 -Fix the recursive field resolution within types. - -diff --git a/rathaxes/compiler/passes/common/rtxResolve.inc.cws b/rathaxes/compiler/passes/common/rtxResolve.inc.cws ---- a/rathaxes/compiler/passes/common/rtxResolve.inc.cws -+++ b/rathaxes/compiler/passes/common/rtxResolve.inc.cws -@@ -739,9 +739,13 @@ - local source_type; - - // First retrieve the type of the value we just resolved. -- if (getArraySize(subidentifiers) != 0) -+ if (getArraySize(subidentifiers) == 1) - { -- ref source_type = theChunk.type_map[varName]; -+ // If there's a resval argument for it, then take the source type from there -+ // Otherwise, use the chunk's type_map. -+ if (rtxNodeArg_getRType(self, source_type) == false) -+ { ref source_type = theChunk.type_map[varName]; } -+ rtxNodeArg_getRType(self, source_type); - } - else - { -@@ -1100,6 +1104,7 @@ - return false; - } - -+ - if (instanceChunk(resVals, c_tree.body, source_tree) != false) - { - rtxResolve_InsertCode(theBlock, startIdx, phName, phIdx, c_tree.body); -@@ -1115,6 +1120,7 @@ - if (errcount != 0) - return false; - } -+ - return true; - } - -@@ -1309,39 +1315,69 @@ - placeHolder : node, out_node : node, source_tree : reference) - { - traceLine("rtxResolve: type_map<"+T+"> for variable '"+mappedIds#[0]+"' ("+toString(mappedIds)+")"); -- local theTemplate; - local identifiers; -- -- if (rtxLink_FindUniqueTemplate(theRtype, source_tree.config, theTemplate) == false) -- return false; -+ local actual_resVals; -+ local actual_rtype; -+ setall actual_rtype = theRtype; -+ setall actual_resVals = resolverValues; - - setall identifiers = mappedIds; - removeFirstElement(identifiers); - if (getArraySize(identifiers) > 0) - { -- // Now that we have selected an unique template, load the tree+script -- local subtree; -- rtxLink_LoadItem(theTemplate, subtree); -- localref theMapping = subtree.mapping.body.block[identifiers#front]; -- -- // Call the right mapping function (based on hash + identifier mapped). -- traceLine("type_map<"+T+">: type_map<" + T + ">: Calling mapping key : " -- + theMapping.instanceKey); -- -- if (instanceMapping(resolverValues, subtree, source_tree) == false) -+ local self_arg; -+ local prev_expr; -+ if (rtxNodeArgs_GetArgByName(resolverValues, "self", self_arg) == false) - { -- traceLine(RED + "[Error] type_map<"+T+">: instanceMapping<\""+theMapping.instanceKey+"\"> failed"); -- traceLine(RED + " for mapping at " + placeHolder#parent.location + "." + DEFAULT_COLOR); -+ traceLine(RED + "[Error] type_map<"+T+">: Could not retrieve self." + DEFAULT_COLOR); - return false; - } -+ rtxNodeArg_getValue(self_arg, prev_expr); - -- setall out_node = theMapping.body.expr; -+ while (getArraySize(identifiers) > 0) -+ { -+ local theTemplate; -+ local subtree; -+ if (rtxLink_FindUniqueTemplate(actual_rtype, source_tree.config, theTemplate) == false) -+ return false; -+ rtxLink_LoadItem(theTemplate, subtree); -+ localref theMapping = subtree.mapping.body.block[identifiers#front]; -+ -+ // Call the right mapping function (based on hash + identifier mapped). -+ traceLine("type_map<"+T+">: type_map<" + T + ">: Calling mapping key : " -+ + theMapping.instanceKey); -+ -+ if (instanceMapping(actual_resVals, subtree, source_tree) == false) -+ { -+ traceLine(RED + "[Error] type_map<"+T+">: instanceMapping<\""+theMapping.instanceKey+"\"> failed"); -+ traceLine(RED + " for mapping at " + placeHolder#parent.location + "." + DEFAULT_COLOR); -+ return false; -+ } -+ -+ // Update actual rtype. -+ local rtypeName = rtxRTypeName(actual_rtype); -+ local field_rtype; -+ if (rtxTypingLookup_TypeField(actual_rtype, identifiers#front, placeHolder#root, source_tree, field_rtype) == false) -+ { -+ traceLine(RED + "[Error] Could not resolve type field '" -+ + identifiers#front + "' for type " + rtypeName + DEFAULT_COLOR); -+ return false; -+ } -+ -+ setall prev_expr = theMapping.body.expr; -+ setall actual_rtype = field_rtype; -+ clearVariable(actual_resVals); -+ rtxNodeArgs(actual_resVals); -+ rtxNodeArgs_AppendArg(actual_resVals, "self", actual_rtype, prev_expr); -+ removeFirstElement(identifiers); -+ } - } -- else -+ -+ // Now, resolve as a "self" - { - local self; - local val; -- if (rtxNodeArgs_GetArgByName(resolverValues, "self", self) == false) -+ if (rtxNodeArgs_GetArgByName(actual_resVals, "self", self) == false) - { - error(RED + "Could not get value..." + DEFAULT_COLOR); - } diff -r 3523e795bdf9 -r b83b0432a45b FixScalarRefCasts --- a/FixScalarRefCasts Mon Apr 01 00:56:28 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -# HG changeset patch -# User David Pineau -# Parent 2a7d28a3e2d86d36ddfc77ad8ce73c22eadcc718 -Add .ref and .scalar to rathaxes types - -diff --git a/rathaxes/compiler/node/rtxNodeBack.inc.cws b/rathaxes/compiler/node/rtxNodeBack.inc.cws ---- a/rathaxes/compiler/node/rtxNodeBack.inc.cws -+++ b/rathaxes/compiler/node/rtxNodeBack.inc.cws -@@ -19,7 +19,7 @@ - declare function rtxNodePlaceHolder(local_node : node); - declare function rtxNodeCall(local_node : node, theVars : node, theChunk : node, out_ref_params : reference); - declare function rtxNodeSequenceCall(local_node : node, name : node, args : node); --declare function rtxNodeCast(local_node : node, varName : value, typeId : node); -+declare function rtxNodeCast(local_node : node, varName : value, typeId : node, sQualifier : value); - // Tool functions for the resolution/generation - declare function rtxNodeResVal_GetField(resolver_values : node, idList : node, out_ref : reference); - declare function rtxNodeResVal(local_node : node); -@@ -233,7 +233,7 @@ - return true; - } - --function rtxNodeCast(local_node : node, varName : value, typeId : node) -+function rtxNodeCast(local_node : node, varName : value, typeId : node, sQualifier : value) - { - rtxNode(local_node); - local_node.type = "__rtx_tpl_cast__"; -@@ -244,6 +244,8 @@ - local dummy; - if (rtxNodeRType(local_node.rtype, typeId, dummy) == false) - return false; -+ if (rtxNodeRType_SetQualifier(local_node.rtype, sQualifier) == false) -+ return false; - - return true; - } -diff --git a/rathaxes/compiler/passes/back/rtxMeta.inc.cws b/rathaxes/compiler/passes/back/rtxMeta.inc.cws ---- a/rathaxes/compiler/passes/back/rtxMeta.inc.cws -+++ b/rathaxes/compiler/passes/back/rtxMeta.inc.cws -@@ -292,15 +292,20 @@ - - // Here, we allow casting a local C variable into a rathaxes type. This casts lasts for the current chunk's scope. - tpl_cast(theCast : node) ::= -+/**/ => local sQualifier = "scalar"; - "cast" -+ #continue(sError, "A cast can only be applied to a local variable (\"local.\" is expected).") - => local typeId; -- #continue(sError, "A cast can only be applied to a local variable (\"local.\" is expected).") - "local" '.' rootidentifier:varName - #continue(sError, "Expected 'as' token for a rathaxes cast.") - "as" - #continue(sError, "Expected Type name for casting type.") - rtx_scoped_identifier(typeId, false) -- #check(rtxNodeCast(theCast, varName, typeId)) -+ [ -+ "." -+ tpl_type_qualifier:sQualifier -+ ]? -+ #check(rtxNodeCast(theCast, varName, typeId, sQualifier)) - ; - - tpl_type_qualifier ::= diff -r 3523e795bdf9 -r b83b0432a45b FixScalarRefPlaceholders --- a/FixScalarRefPlaceholders Mon Apr 01 00:56:28 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -# HG changeset patch -# User David Pineau -# Parent 6f20fad6add410a6a8ba42ec60ffdf81cdbaa4e8 -Fix Scalar/Ref placeholders annotations by adding a 'copy' that does not alter the current state - -diff --git a/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws b/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws ---- a/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws -+++ b/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws -@@ -194,12 +194,13 @@ - // in unstrict mode - if (existVariable(ctype_ref.unknown) && $getArraySize(ctype_ref.unknown) > 0$) - { -- ctype_ref.identifier = ctype_ref.unknown#back; -- removeVariable(ctype_ref.unknown); -+ ctype_ref.identifier = ctype_ref.unknown#back; -+ removeVariable(ctype_ref.unknown); - } - // name of a type - if (existVariable(ctype_ref.identifier) && rtxPH_havePlaceHolder(ctype_ref.identifier)) - { rtxPH_mapPlaceHolder(ctype_ref.identifier, compile, node_idx, "target_decl"); } -+ - // composed - if (existVariable(ctype_ref.list)) - { -@@ -266,7 +267,7 @@ - // So do not bother with subtypes and check them all and then recurse. - function rtxPH_compile<"__expr__">(local_node : node, compile : node, node_idx : value) - { -- if (!existVariable(this.phtype)) insert this.phtype = "scalar";///// -+ if (!existVariable(this.phtype)) insert this.phtype = "copy";//// set to default - // left for bin operator - if (existVariable(local_node.left)) - { -@@ -275,7 +276,7 @@ - // all post expr case [] or (), are pointer - if (local_node.expr_type == "__postexpr__") { insert this.phtype = "pointer";}//// - rtxPH_compile(local_node.left, compile, node_idx); -- insert this.phtype = "scalar";//// -+ insert this.phtype = "copy";//// set to default - } - // right for bin operator - if (existVariable(local_node.right)) -@@ -283,7 +284,7 @@ - // the unary * - if (local_node.operator == "*" && local_node.expr_type == "__unary__") {insert this.phtype = "pointer";}//// - rtxPH_compile(local_node.right, compile, node_idx); -- insert this.phtype = "scalar";//// -+ insert this.phtype = "copy";//// set to default - } - // if,while - if (existVariable(local_node.condition)) -diff --git a/rathaxes/compiler/passes/common/rtxResolve.inc.cws b/rathaxes/compiler/passes/common/rtxResolve.inc.cws ---- a/rathaxes/compiler/passes/common/rtxResolve.inc.cws -+++ b/rathaxes/compiler/passes/common/rtxResolve.inc.cws -@@ -177,6 +177,10 @@ - if (out_type == "ref") - out_type = "pointer"; - -+ // Then, check if we need any changes or not for the out_type -+ if (out_type == "copy") // Copy means that we keep the current state, whether pointer or scalar. -+ return true; -+ - // make sure in and out types are either scalar or ref - if ((in_type != "scalar" && in_type != "pointer") - || (out_type != "scalar" && out_type != "pointer")) -@@ -593,7 +597,7 @@ - // We want to set the mangled typedef name into the ctype's identifier: - // (equivalent of: theDecl.ctype.identifier = COMPUTED_NAME;) - local_node#parent.ref_placeholder.identifier = rtxResolve_MangleTypeName(theRtype, theRtype.qualifier != "scalar"); -- -+ - return true; - } - -@@ -756,7 +760,6 @@ - { error(RED + "[Error] Cannot transcribe an expression from " + in_type + " to " + out_type + DEFAULT_COLOR); } - setall local_node#parent.ref_placeholder = mapping; - } -- - } - else if (isBuiltinVariable(varName)) // Mapping for a builtin type - { diff -r 3523e795bdf9 -r b83b0432a45b FixScalarRefUnstrictBug --- a/FixScalarRefUnstrictBug Mon Apr 01 00:56:28 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -# HG changeset patch -# User David Pineau -# Parent e1ea51d560d0e95cb29d42c30dbfe2dff5597e8b -Work around an unstrict cnorm bug issue concerning the function declarations. - -diff --git a/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws b/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws ---- a/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws -+++ b/rathaxes/compiler/passes/back/rtxPlaceHolders.inc.cws -@@ -213,9 +213,65 @@ - { rtxPH_compile(item, compile, node_idx); } - } - } -- // recurse param list -+ // recurse param list + Resolve unknown before going down. - if (existVariable(ctype_ref.param)) -- { rtxPH_compile(ctype_ref.param, compile, node_idx);} -+ { -+ // XXX FIXME -+ // This is a workaround for a bug involving the unstrict cnorm. -+ // We patch-up the function's arg's types and names before checking further. -+ local argnames; -+ foreach param in ctype_ref.param.block -+ { -+ localref theType = param; -+ localref param_ctype = theType.ctype; -+ -+ //First setup the iterator over the right param to retrieve name. -+ local name_it; -+ local it_idx = 0; -+ createIterator(name_it, ctype_ref.param.map); -+ while (it_idx != index(param)) -+ { -+ next(name_it); -+ increment(it_idx); -+ } -+ local theName = key(name_it); -+ -+ if (existVariable(param_ctype.unknown)) -+ { -+ local placeholder_key = false; -+ foreach token in param_ctype.unknown -+ { -+ local theKey = key(token); -+ if (rtxPH_havePlaceHolder(theKey)) -+ { -+ placeholder_key = theKey; -+ break ; -+ } -+ } -+ if (placeholder_key == false) // no token found -+ { -+ param_ctype.identifier = param_ctype.unknown#back; -+ removeVariable(param_ctype.unknown); -+ } -+ else // placeholder found -> Set as type, use other var as name. -+ { -+ param_ctype.identifier = placeholder_key; -+ removeVariable(param_ctype.unknown[placeholder_key]); -+ local last_it; -+ createReverseIterator(last_it, param_ctype.unknown); -+ theName = key(last_it); -+ removeVariable(param_ctype.unknown); -+ insert param.name = theName; -+ } -+ } -+ insert argnames[theName] = index(param); -+ } -+ setall ctype_ref.param.map = argnames; -+ -+ rtxPH_compile(ctype_ref.param, compile, node_idx); -+ } -+ -+ - // if type is enum - if (existVariable(ctype_ref.enum)) - { diff -r 3523e795bdf9 -r b83b0432a45b maintainers_fix_indentation_in_use_rathaxes.patch --- a/maintainers_fix_indentation_in_use_rathaxes.patch Mon Apr 01 00:56:28 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -# HG changeset patch -# User Louis Opter -# Parent 5686b8073a21eb9c4accbfdb7ad837d971d4cc43 -maintainers: fix identation in UseRathaxes.cmake - -diff --git a/maintainers/CMakeScripts/UseRathaxes.cmake b/maintainers/CMakeScripts/UseRathaxes.cmake ---- a/maintainers/CMakeScripts/UseRathaxes.cmake -+++ b/maintainers/CMakeScripts/UseRathaxes.cmake -@@ -221,9 +221,9 @@ - - ADD_CUSTOM_TARGET("${NAME}" ALL DEPENDS "${KERNEL_OBJECT_NAME}") - --ELSE (${SYSTEM} MATCHES "Linux") -- MESSAGE(STATUS "Don't know how to build kernel modules for ${SYSTEM} (yet)") --ENDIF (${SYSTEM} MATCHES "Linux") -+ ELSE (${SYSTEM} MATCHES "Linux") -+ MESSAGE(STATUS "Don't know how to build kernel modules for ${SYSTEM} (yet)") -+ ENDIF (${SYSTEM} MATCHES "Linux") - ENDFUNCTION(ADD_RATHAXES_LKM NAME RATHAXES_SOURCE) - - # Like FIND_PACKAGE but also search in the Rathaxes directories. Usage: diff -r 3523e795bdf9 -r b83b0432a45b rathaxes_change_the_abstract_type_notation_in_the_e1000_sample.patch --- a/rathaxes_change_the_abstract_type_notation_in_the_e1000_sample.patch Mon Apr 01 00:56:28 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,717 +0,0 @@ -# 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 - } - -+ 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 - } - -- 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 diff -r 3523e795bdf9 -r b83b0432a45b rathaxes_e1000_move_the_interrupt_init_and_cleanup_into_ethernet.patch --- a/rathaxes_e1000_move_the_interrupt_init_and_cleanup_into_ethernet.patch Mon Apr 01 00:56:28 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,310 +0,0 @@ -# HG changeset patch -# Parent 7be52c02870a053b3a12e75423226c252e256c6b -Move the interrupt handler init/cleanup out of e1000.blt - -This is not device dependant and can be done from the Ethernet subsystem -right now, (plus the interrupt handler itself was already in the -Ethernet subsytem). - -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 -@@ -247,7 +247,6 @@ - { - int bars; - unsigned char /* __iomem */ *ioaddr; -- int irq; - - ${e1000::RxRing} rx_ring; - ${e1000::TxRing} tx_ring; -@@ -265,14 +264,12 @@ - - chunk Ethernet::adapter_init_context(Ethernet::Device rtx_ether_ctx, - Builtin::number bars, -- Builtin::symbol ioaddr, -- Builtin::number irq) -+ Builtin::symbol ioaddr) - { - { - ${e1000::Context.ref} hw_ctx = &${rtx_ether_ctx}->hw_ctx; - hw_ctx->bars = ${bars}; - hw_ctx->ioaddr = ${ioaddr}; -- hw_ctx->irq = ${irq}; - } - } - -@@ -605,68 +602,6 @@ - } - } - -- template sequence e1000::setup_interrupt_handler(Ethernet::Device rtx_ether_ctx) -- { -- chunk LKM::includes() -- { -- #include -- } -- -- chunk LKM::prototypes() -- { -- static int e1000_setup_interrupt_handler(${Ethernet::Device} *); -- } -- -- chunk LKM::code() -- { -- static int e1000_setup_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx) -- { -- int error; -- -- error = request_irq(rtx_ether_ctx->hw_ctx.irq, -- rtx_ethernet_interrupt_handler, -- IRQF_SHARED, -- ${config.name}, -- rtx_ether_ctx); -- -- if (error) -- ${Log::info("cannot register the interrupt handler")}; -- -- return error; -- } -- } -- -- chunk ::CALL() -- { -- int error = e1000_setup_interrupt_handler(${rtx_ether_ctx}); -- if (error) -- { -- return error; -- } -- } -- } -- -- template sequence free_interrupt_handler(Ethernet::Device rtx_ether_ctx) -- { -- chunk prototypes() -- { -- static void e1000_free_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx); -- } -- -- chunk code() -- { -- static void e1000_free_interrupt_handler(${Ethernet::Device} *rtx_ether_ctx) -- { -- free_irq(rtx_ether_ctx->hw_ctx.irq, rtx_ether_ctx); -- } -- } -- -- chunk ::CALL() -- { -- e1000_free_interrupt_handler(${rtx_ether_ctx}); -- } -- } -- - template sequence activate_device_interruption(Ethernet::Device rtx_ether_ctx) - { - chunk ::CALL() -diff --git a/rathaxes/samples/e1000/e1000.rti b/rathaxes/samples/e1000/e1000.rti ---- a/rathaxes/samples/e1000/e1000.rti -+++ b/rathaxes/samples/e1000/e1000.rti -@@ -13,8 +13,7 @@ - /* Callbacks/Hooks which should probably be in the front-end: */ - chunk Ethernet::adapter_init_context(Ethernet::Device, - Builtin::number, -- Builtin::symbol, -- Builtin::number); -+ Builtin::symbol); - chunk Ethernet::adapter_reset(Ethernet::Device); - chunk Ethernet::adapter_load_mac_address(Ethernet::Device); - } -@@ -85,21 +84,6 @@ - provided chunk ::CALL(); - } - -- provided sequence setup_interrupt_handler(Ethernet::Device) -- { -- provided chunk LKM::includes(); // works without this one -- provided chunk LKM::prototypes(); -- provided chunk LKM::code(); -- provided chunk ::CALL(); -- } -- -- provided sequence free_interrupt_handler(Ethernet::Device) -- { -- provided chunk LKM::prototypes(); -- provided chunk LKM::code(); -- provided chunk ::CALL(); -- } -- - provided sequence activate_device_interruption(Ethernet::Device) - { - provided chunk ::CALL(); -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 -@@ -1,4 +1,4 @@ --with Ethernet, PCI, LKM, Log -+with Ethernet, PCI, LKM, Log, Builtin - { - template type Ethernet::ProtocolId() - { -@@ -61,7 +61,9 @@ - - map - { -- netdev: ${self}->ndev; -+ netdev: ${self}->ndev; -+ /* This could be another init method for Ethernet::Device: */ -+ rtx_ether_ctx: netdev_priv(&${self}->ndev); - } - } - -@@ -106,11 +108,17 @@ - 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; - } - } - - template sequence Ethernet::open(Ethernet::Device dev) - { -+ chunk LKM::includes() -+ { -+ #include -+ } -+ - chunk LKM::prototypes() - { - static int rtx_ethernet_open(struct net_device *); -@@ -122,6 +130,20 @@ - { - ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(dev); - -+ int error; -+ { -+ ${Log::info("installing the interrupt handler")}; -+ } -+ error = request_irq(${local.rtx_ether_ctx.irq}, -+ rtx_ethernet_interrupt_handler, -+ IRQF_SHARED, -+ ${config.name}, -+ dev); -+ if (error) -+ { -+ ${Log::info("Cannot register the interrupt handler")}; -+ return error; -+ } - ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; - - return 0; -@@ -161,7 +183,15 @@ - { - ${Ethernet::Device.ref} rtx_ether_ctx = netdev_priv(dev); - -- ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; -+ /* TODO: change this pointcut into a pointcut/adapter/callback: */ -+ { -+ ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; -+ } -+ -+ free_irq(${local.rtx_ether_ctx.irq}, dev); -+ { -+ ${Log::info("interrupt handler free'ed")}; -+ } - - return 0; - } -@@ -183,7 +213,9 @@ - { - static enum irqreturn rtx_ethernet_interrupt_handler(int irq, void *dev_id) - { -- ${Ethernet::Device.ref} rtx_ether_ctx = dev_id; -+ ${Ethernet::AbstractDevice.ref} rtx_net_dev = dev_id; -+ ${Ethernet::Device.ref} rtx_ether_ctx; -+ rtx_ether_ctx = ${local.rtx_net_dev.rtx_ether_ctx}; - - ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)}; - -@@ -260,13 +292,10 @@ - */ - int bars = ${rtx_pci_dev.bars}; - unsigned char /* __iomem */ *ioaddr = ${rtx_pci_dev.ioaddr}; -- int irq = ${rtx_pci_dev.irq}; - ${cast local.bars as Builtin::number}; -- ${cast local.irq as Builtin::number}; - ${pointcut Ethernet::adapter_init_context(local.rtx_ether_ctx, - local.bars, -- local.ioaddr, -- local.irq)}; -+ local.ioaddr)}; - ${pointcut Ethernet::adapter_reset(local.rtx_ether_ctx)}; - ${pointcut Ethernet::adapter_load_mac_address(local.rtx_ether_ctx)}; - memcpy(${local.rtx_ether_ctx.perm_addr}, -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 -@@ -18,6 +18,11 @@ - chunk LKM::includes(); - decl data_types(); - attribute Builtin::symbol.scalar netdev; -+ /* -+ * XXX: should be a Ethernet::Device, but that causes a circular -+ * dependency: -+ */ -+ attribute Builtin::symbol.scalar rtx_ether_ctx; - } - - provided type Device -@@ -34,12 +39,14 @@ - * I'd like to use better names here, but I'd like to understand the - * difference between the two first: - */ -- attribute Builtin::symbol.ref perm_addr; -- attribute Builtin::symbol.ref dev_addr; -+ attribute Builtin::symbol.ref perm_addr; -+ attribute Builtin::symbol.ref dev_addr; -+ attribute Builtin::symbol.scalar irq; - } - - required sequence open(Ethernet::Device) - { -+ provided chunk LKM::includes(); - provided chunk LKM::prototypes(); - provided chunk LKM::code(); - } -@@ -69,8 +76,7 @@ - - provided pointcut Ethernet::adapter_init_context(Ethernet::Device, - Builtin::number, -- Builtin::symbol, -- Builtin::number); -+ Builtin::symbol); - provided pointcut Ethernet::adapter_reset(Ethernet::Device); - provided pointcut Ethernet::adapter_load_mac_address(Ethernet::Device); - } -diff --git a/rathaxes/samples/e1000/lkm.rtx b/rathaxes/samples/e1000/lkm.rtx ---- a/rathaxes/samples/e1000/lkm.rtx -+++ b/rathaxes/samples/e1000/lkm.rtx -@@ -4,13 +4,6 @@ - { - Log::info("opening the device"); - -- /* -- * Maybe e1000::create_device should be called from here, to be -- * more coherent. -- */ -- -- e1000::setup_interrupt_handler(dev); -- Log::info("interrupt handler installed"); - - e1000::set_up_device(dev); - Log::info("device activated"); -@@ -32,9 +25,6 @@ - */ - e1000::free_rx_tx(dev); - Log::info("free'ed up rx/tx resources"); -- -- e1000::free_interrupt_handler(dev); -- Log::info("interrupt handler free'ed"); - } - - Ethernet::interrupt_handler(Ethernet::Device dev) diff -r 3523e795bdf9 -r b83b0432a45b series --- a/series Mon Apr 01 00:56:28 2013 -0700 +++ b/series Tue Jul 02 22:19:28 2013 -0700 @@ -1,8 +0,0 @@ -maintainers_fix_indentation_in_use_rathaxes.patch -FixScalarRefCasts -FixScalarRefPlaceholders -FixScalarRefUnstrictBug -FixRecursiveTypeFieldResolution -E1000_UpdateToScalarRef -rathaxes_e1000_move_the_interrupt_init_and_cleanup_into_ethernet.patch -rathaxes_change_the_abstract_type_notation_in_the_e1000_sample.patch