view rathaxes_e1000_move_the_interrupt_init_and_cleanup_into_ethernet.patch @ 106:976a4b87803f

Fix the resolution and the e1000 sample with the new scalar ref feature
author David Pineau <dav.pineau@gmail.com>
date Mon, 25 Mar 2013 01:17:56 +0100
parents fb20f01ea997
children f42751b8ca99
line wrap: on
line source

# HG changeset patch
# Parent db54879402d420664f53e83cb7f55204571a9a8e
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
@@ -249,7 +249,6 @@
         {
             int                         bars;
             unsigned char /* __iomem */ *ioaddr;
-            int                         irq;
 
             ${e1000::RxRing}    rx_ring;
             ${e1000::TxRing}    tx_ring;
@@ -267,14 +266,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} *hw_ctx = &${rtx_ether_ctx}->hw_ctx;
                 hw_ctx->bars = ${bars};
                 hw_ctx->ioaddr = ${ioaddr};
-                hw_ctx->irq = ${irq};
             }
         }
 
@@ -606,68 +603,6 @@
         }
     }
 
-    template sequence   e1000::setup_interrupt_handler(Ethernet::Device rtx_ether_ctx)
-    {
-        chunk   LKM::includes()
-        {
-            #include <linux/interrupt.h>
-        }
-
-        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()
     {
@@ -106,11 +106,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 <linux/interrupt.h>
+        }
+
         chunk LKM::prototypes()
         {
             static int  rtx_ethernet_open(struct net_device *);
@@ -123,9 +129,28 @@
                 ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(dev);
 
                 ${cast local.rtx_ether_ctx as Ethernet::Device};
+
+                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")};
+                    goto error;
+                }
+
                 ${pointcut ::IMPLEMENTATION(local.rtx_ether_ctx)};
 
                 return 0;
+
+            error:
+                return error;
             }
         }
     }
@@ -165,7 +190,16 @@
                 ${Ethernet::Device} *rtx_ether_ctx = netdev_priv(dev);
 
                 ${cast local.rtx_ether_ctx as Ethernet::Device};
-                ${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;
             }
@@ -267,14 +301,11 @@
              */
             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};
             ${cast local.rtx_ether_ctx as Ethernet::Device};
             ${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
@@ -36,10 +36,12 @@
          */
         attribute   Builtin::symbol.scalar      perm_addr;
         attribute   Builtin::symbol.scalar      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 +71,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)