# HG changeset patch
# Parent 47ae8b89654899f0d6e2c0d656ca52c996d53262
rathaxes: tidy up ethernet.{rti,blt} in the e1000 sample

- Remove typedefs;
- Rename Ethernet::SubContext in Ethernet::HardwareContext: I think this
  is more clear. This pointcut is here to allow the underlying real
  device to store its private data structure within the context of the
  Ethernet subsystem.

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
@@ -267,7 +267,7 @@
             };
         }
 
-        chunk   Ethernet::SubContext()
+        chunk   Ethernet::HardwareContext()
         {
             /*
              * Force the generation of the structure in the "headers" part, we
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
@@ -7,7 +7,7 @@
 
     provided type   Context
     {
-        chunk       Ethernet::SubContext();
+        chunk       Ethernet::HardwareContext();
         decl        data_types();
         method      init();
 
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
@@ -59,7 +59,7 @@
 
         decl  data_types()
         {
-            typedef struct net_device *net_devp;
+            struct net_device;
         }
 
         map
@@ -76,14 +76,7 @@
 
         decl  data_types()
         {
-            /*
-             * So, at first sight, it sucks to typedef it as pointer but (for
-             * now) it makes sense for two reasons:
-             * - This structure will always be used through a pointer;
-             * - This remove the ambiguity of pointer/not-pointer in the
-             * ::init() chunk.
-             */
-            typedef struct rtx_ethernet_dev
+            struct rtx_ethernet_dev
             {
                 /*
                  * I think it's useless to use the ${PCI::AbstractDevice} "abstraction"
@@ -96,8 +89,8 @@
                  * In the long-term, this may disappear for a new concept allowing
                  * to embbed a descriptor defined and manipulated by the front-end
                  */
-                ${pointcut Ethernet::SubContext()};
-            } *rtx_ethernet_dev_p;
+                ${pointcut Ethernet::HardwareContext()};
+            };
         }
 
         method init(Ethernet::AbstractDevice net_dev, PCI::AbstractDevice pci_dev)
@@ -105,7 +98,7 @@
             ${self} = netdev_priv(${net_dev});
             /*
              * We can use -> because we know that ${self} will be always a
-             * pointer ("thanks" to the typedef)
+             * pointer, but the ambiguity sucks.
              */
             ${self}->pci_dev = ${pci_dev};
             ${self}->net_dev = ${net_dev};
@@ -129,8 +122,9 @@
         {
             static int  rtx_ethernet_open(struct net_device *dev)
             {
-                ${Ethernet::Device} rtx_ether_dev = netdev_priv(dev);
+                ${Ethernet::Device} *rtx_ether_dev = netdev_priv(dev);
 
+                ${cast local.rtx_ether_dev as Ethernet::Device};
                 ${pointcut ::IMPLEMENTATION(local.rtx_ether_dev)};
 
                 return 0;
@@ -149,8 +143,10 @@
         {
             static int  rtx_ethernet_xmit(struct sk_buff* kernel_skb, struct net_device *net_dev)
             {
-                ${Ethernet::Device} rtx_ethernet_dev = netdev_priv(net_dev);
+                ${Ethernet::Device} *rtx_ethernet_dev = netdev_priv(net_dev);
                 ${cast local.kernel_skb as Socket::AbstractSKBuff};
+
+                ${cast local.rtx_ethernet_dev as Ethernet::Device};
                 ${pointcut ::IMPLEMENTATION(local.rtx_ethernet_dev, local.kernel_skb)};
             }
         }
@@ -167,8 +163,9 @@
         {
             static int  rtx_ethernet_close(struct net_device *dev)
             {
-                ${Ethernet::Device} rtx_ether_dev = netdev_priv(dev);
+                ${Ethernet::Device} *rtx_ether_dev = netdev_priv(dev);
 
+                ${cast local.rtx_ether_dev as Ethernet::Device};
                 ${pointcut ::IMPLEMENTATION(local.rtx_ether_dev)};
 
                 return 0;
@@ -191,8 +188,9 @@
         {
             static enum irqreturn   rtx_ethernet_interrupt_handler(int irq, void *dev_id)
             {
-                ${Ethernet::Device} rtx_ether_dev = dev_id;
+                ${Ethernet::Device} *rtx_ether_dev = dev_id;
 
+                ${cast local.rtx_ether_dev as Ethernet::Device};
                 ${pointcut ::IMPLEMENTATION(local.rtx_ether_dev)};
 
                 return IRQ_NONE;
@@ -222,8 +220,8 @@
          */
         chunk PCI::pci_probe_hook(PCI::Device rtx_pci_dev)
         {
-            ${Ethernet::Device} rtx_ether_ctx;
-            ${Ethernet::AbstractDevice} net_dev;
+            ${Ethernet::Device} *rtx_ether_ctx;
+            ${Ethernet::AbstractDevice} *net_dev;
 
             net_dev = alloc_etherdev(sizeof(*rtx_ether_ctx));
             if (!net_dev)
@@ -272,6 +270,7 @@
             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,
@@ -294,10 +293,11 @@
          */
         chunk   PCI::pci_remove_hook(PCI::Device rtx_pci_dev)
         {
-            ${Ethernet::Device} rtx_ether_ctx = ${rtx_pci_dev.context};
+            ${Ethernet::Device} *rtx_ether_ctx = ${rtx_pci_dev.context};
 
             BUG_ON(!rtx_ether_ctx);
 
+            ${cast local.rtx_ether_ctx as Ethernet::Device};
             unregister_netdev(${local.rtx_ether_ctx.net_device});
             free_netdev(${local.rtx_ether_ctx.net_device});
         }
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
@@ -22,7 +22,7 @@
         chunk       LKM::includes();
         decl        data_types();
         method      init(Ethernet::AbstractDevice, PCI::AbstractDevice);
-        pointcut    Ethernet::SubContext();
+        pointcut    Ethernet::HardwareContext();
 
         attribute   PCI::AbstractDevice         pci_device;
         attribute   Ethernet::AbstractDevice    net_device;
