Mercurial > archived > louis > epitech > mq > rathaxes
view rathaxes_e1000_move_the_interrupt_init_and_cleanup_into_ethernet.patch @ 104:c4c33ac02b93
First try at splitting the type nightmare and the refactoring
author | Louis Opter <louis@lse.epita.fr> |
---|---|
date | Fri, 22 Mar 2013 00:06:00 -0700 |
parents | |
children | fb20f01ea997 |
line wrap: on
line source
# HG changeset patch # Parent 68c4f142af579e558314cdeebd091fc5abd62014 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() { @@ -111,6 +111,11 @@ 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 +128,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}, + ${local.rtx_net_dev.k_net_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 +189,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}, ${local.rtx_net_dev.k_net_dev}); + { + ${Log::info("interrupt handler free'ed")}; + } return 0; } @@ -267,14 +300,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 @@ -40,6 +40,7 @@ required sequence open(Ethernet::Device) { + provided chunk LKM::includes(); provided chunk LKM::prototypes(); provided chunk LKM::code(); } @@ -69,8 +70,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)