changeset 134:79226bb06e6a

Wip
author Louis Opter <kalessin@kalessin.fr>
date Sat, 11 Jan 2014 16:34:30 -0800
parents dbb4a3b383cb
children 9c6ae3a2e180
files rathaxes_sample_e1000_rewrite_device_dependent_code.patch
diffstat 1 files changed, 55 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/rathaxes_sample_e1000_rewrite_device_dependent_code.patch	Wed Jan 08 09:42:33 2014 -0800
+++ b/rathaxes_sample_e1000_rewrite_device_dependent_code.patch	Sat Jan 11 16:34:30 2014 -0800
@@ -55,7 +55,7 @@
      foreach placeHolder in local_node.body.compile
      {
 +        if (!placeHolder.node.body.type)
-+            traceLine(RED + "BUG: placeHolder.node.body.type is missing in rtxIntrospect_walk<\"__rtx_chunk__\">" + DEFAULT_COLOR);
++            traceLine(RED + "BUG: placeHolder.node.body.type is missing in rtxIntrospect_walk<\"__rtx_chunk__\">, placeHolder = " + toString(placeHolder) + DEFAULT_COLOR);
          if (rtxIntrospect_InferPlaceHolderTypes<placeHolder.node.body.type>(placeHolder.node.body, local_node) == false)
          {
              pushItem to_remove;
@@ -696,7 +696,7 @@
          {
              E1000_TXD_DTYP_D        = 0x00100000, /* Data Descriptor */
              E1000_TXD_DTYP_C        = 0x00000000, /* Context Descriptor */
-@@ -701,326 +140,656 @@
+@@ -701,326 +140,683 @@
          }
      }
  
@@ -780,12 +780,14 @@
 +    {
 +        decl data_types()
 +        {
-+            unsigned char   *io_addr; // XXX should be annoted with __iomem
++            ${Ethernet::Device.ref} net_dev;
++            // XXX should be annoted with __iomem:
++            unsigned char           *io_addr;
 +            // XXX Forced to hardcode the type because there is a circular
 +            // dependency between the rings and the context.
 +            // TODO: get the right generated types:
-+            int    tx_ring;
-+            int    rx_ring;
++            int                     tx_ring;
++            int                     rx_ring;
 +        }
 +
 +        chunk LKM::includes()
@@ -836,7 +838,7 @@
 +                                              ${e1000::Register} reg,
 +                                              unsigned int value)
 +            {
-+                return iowrite32(value, ${local.self.io_addr.io} + reg);
++                return iowrite32(value, ${local.self.io_addr} + reg);
 +            }
 +
 +            static void rtx_e1000_reg_set32(${e1000::Context} self,
@@ -845,7 +847,7 @@
 +            {
 +                return iowrite32(
 +                    rtx_e1000_reg_read32(${local.self}, reg) | value,
-+                    ${local.self.io_addr.io} + reg
++                    ${local.self.io_addr} + reg
 +                );
 +            }
 +
@@ -855,15 +857,16 @@
 +            {
 +                return iowrite32(rtx_e1000_reg_read32(
 +                    ${local.self}, reg) & ~value,
-+                    ${local.self.io_addr.io} + reg
++                    ${local.self.io_addr} + reg
 +                );
 +            }
          }
  
 -        chunk   ::CALL()
-+        method init(Builtin::symbol io_addr)
++        method init(Ethernet::Device rtx_ether_ctx, Builtin::symbol io_addr)
          {
 -            rtx_e1000_print_status(&${rtx_ether_ctx}->hw_ctx);
++            ${self.net_dev} = ${rtx_ether_ctx};
 +            ${self.io_addr} = ${io_addr};
 +        }
 +
@@ -896,7 +899,7 @@
 +        {
 +            {
 +                ${e1000::Context.ref} hw_ctx = &${local.rtx_ether_ctx}->hw_ctx;
-+                ${local.hw_ctx.init(local.io_addr)};
++                ${local.hw_ctx.init(local.rtx_ether_ctx, local.io_addr)};
 +                ${local.hw_ctx.rx_ring.init(local.hw_ctx.io, config.rx_ring_size)};
 +                ${local.hw_ctx.tx_ring.init(local.hw_ctx.io, config.tx_ring_size)};
 +            }
@@ -1014,7 +1017,7 @@
 +            }
 +        }
 +
-+        chunk Ethernet::disable_interrupts(Ethernet::Device rtx_ether_ctx)
++        chunk Ethernet::adapter_disable_interrupts(Ethernet::Device rtx_ether_ctx)
 +        {
 +            { ${Log::info("adapter_disable_interrupts: TBD...")}; }
 +        }
@@ -1057,7 +1060,7 @@
 +            { ${Log::info("adapter_disable_rx: TBD..")}; }
 +        }
 +
-+        chunk Ethernet::adpater_disable_tx(Ethernet::Device rtx_ether_ctx)
++        chunk Ethernet::adapter_disable_tx(Ethernet::Device rtx_ether_ctx)
 +        {
 +            { ${Log::info("adapter_disable_tx: TBD..")}; }
 +        }
@@ -1077,6 +1080,7 @@
 +            io_addr: ${self}->io;
 +            rx_ring: ${self}->rx_ring;
 +            tx_ring: ${self}->tx_ring;
++            net_dev: ${self}->net_dev;
          }
      }
  
@@ -1168,6 +1172,7 @@
 -            /* FIXME: See issue #54 */
 -            static void rtx_e1000_register_write32(/*const*/ ${e1000::Context.ref} ctx, unsigned int reg_offset, unsigned int value)
 +            static int rtx_e1000_rx_ring_alloc_resources(${e1000::RxRing.ref});
++            static void rtx_e1000_rx_ring_free_resources(${e1000::RxRing.ref});
 +            static void rtx_e1000_rx_ring_configure(${e1000::RxRing.ref});
 +        }
 +
@@ -1217,13 +1222,13 @@
 +
 +            err_skbuffs_alloc:
 +                while (i--) {
-+                    ${DMA::unmap(
-+                        local.self.hw_ctx.net_dev.device,
-+                        // XXX Leaking cast because of the array: (TODO: the data structure changed)
-+                        *((dma_addr_t *)&(self->buffs[i].dma_handle)),
-+                        ${config.rx_buffer_len},
-+                        RTX_DMA_FROM_DEVICE
-+                    )};
++// XXX              ${DMA::unmap(
++//                      local.self.hw_ctx.net_dev.device,
++//                      // XXX Leaking cast because of the array: (TODO: the data structure changed)
++//                      *((dma_addr_t *)&(self->buffs[i].dma_handle)),
++//                      config.rx_buffer_len,
++//                      RTX_DMA_FROM_DEVICE
++//                  )};
 +            err_skbuffs_map:
 +                    // XXX leaking cast: (TODO: the data structure changed)
 +                    dev_kfree_skb((struct sk_buff *)hw_ctx->rx_ring.skbuffs[i].skbuff);
@@ -1237,6 +1242,11 @@
 +                return -ENOMEM;
 +            }
 +
++            static void rtx_e1000_rx_ring_free_resources(${e1000::RxRing.ref} self)
++            {
++                ${Log::info("e1000_rx_ring_free_resources: TBD...")};
++            }
++
 +            static void rtx_e1000_rx_ring_configure(${e1000::RxRing.ref} self)
 +            {
 +                // XXX Reread & Fix everything down there (data structure changes and so on)
@@ -1333,6 +1343,11 @@
 +            rtx_e1000_rx_ring_alloc_resources(${self});
 +        }
 +
++        method free()
++        {
++            rtx_e1000_rx_ring_free_resources(${self});
++        }
++
 +        method configure()
 +        {
 +            rtx_e1000_rx_ring_configure(${self});
@@ -1367,6 +1382,7 @@
 -            /* FIXME: See issue #54 */
 -            static void rtx_e1000_register_set32(/*const*/ ${e1000::Context.ref} ctx, unsigned int reg_offset, unsigned int value)
 +            static int rtx_e1000_tx_ring_alloc_resources(${e1000::TxRing.ref});
++            static void rtx_e1000_tx_ring_free_resources(${e1000::TxRing.ref});
 +            static void rtx_e1000_tx_ring_configure(${e1000::TxRing.ref});
 +        }
 +
@@ -1375,9 +1391,15 @@
 +            static int rtx_e1000_tx_ring_alloc_resources(${e1000::TxRing.ref} self)
              {
 -                iowrite32(rtx_e1000_register_read32(ctx, reg_offset) | value, ctx->ioaddr + reg_offset);
++                ${Log::info("e1000_tx_ring_alloc_resources: TBD...")};
 +                return 0;
 +            }
 +
++            static void rtx_e1000_tx_ring_free_resources(${e1000::TxRing.ref} self)
++            {
++                ${Log::info("e1000_tx_ring_free_resources: TBD...")};
++            }
++
 +            static void rtx_e1000_tx_ring_configure(${e1000::TxRing.ref} self)
 +            {
 +                // return ; XXX wtf fails with:
@@ -1413,17 +1435,17 @@
          }
  
 -        chunk   ::CALL()
-+        method configure()
++        method free()
          {
 -            rtx_e1000_register_unset32(${ctx}, ${reg_offset}, ${value});
-+            rtx_e1000_tx_ring_configure(${self});
++            rtx_e1000_tx_ring_free_resources(${self});
          }
 -    }
  
 -    template sequence   activate_device_interruption(Ethernet::Device rtx_ether_ctx)
 -    {
 -        chunk  ::CALL()
-+        map
++        method configure()
          {
 -            rtx_e1000_register_write32(&${rtx_ether_ctx}->hw_ctx, E1000_IMS,
 -                                       E1000_INTR_TXDW |
@@ -1431,9 +1453,10 @@
 -                                       E1000_INTR_LSC  |
 -                                       E1000_INTR_RXO  |
 -                                       E1000_INTR_RXT0);
--        }
++            rtx_e1000_tx_ring_configure(${self});
+         }
 -    }
--
+ 
 -    /* TODO:
 -     *
 -     * Refactor into two methods (one in RxRing and one in TxRing) and make use
@@ -1442,7 +1465,8 @@
 -    template sequence   free_rx_tx(Ethernet::Device rtx_ether_ctx)
 -    {
 -        chunk   ::CALL()
--        {
++        map
+         {
 -            /*
 -             * XXX: Not generated if named "hw_ctx" (which is funny because
 -             * it's used and works in the template right above this one):
@@ -1612,7 +1636,7 @@
 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
-@@ -1,157 +1,122 @@
+@@ -1,157 +1,123 @@
 -interface e1000 : Socket, Ethernet, DMA, PCI, LKM, Builtin
 +interface e1000 : Socket, Ethernet, Device, DMA, PCI, LKM, Builtin
  {
@@ -1670,7 +1694,7 @@
 +        chunk       Ethernet::adapter_disable_tx(Ethernet::Device);
 +        chunk       Ethernet::adapter_free_rx_tx(Ethernet::Device);
 +
-+        method      init(Builtin::symbol);
++        method      init(Ethernet::Device net_dev, Builtin::symbol);
 +        method      print_status();
 +        method      reg_read32(Register);
 +        method      reg_write32(Register, Builtin::number);
@@ -1682,7 +1706,7 @@
 +        // us to hardcode generated types in the definition of the type:
 +        attribute   Builtin::symbol.scalar  rx_ring;
 +        attribute   Builtin::symbol.scalar  tx_ring;
-+
++        attribute   Builtin::symbol.scalar  io_addr;
 +        attribute   Ethernet::Device.ref    net_dev;
 +    }
 +
@@ -1693,12 +1717,11 @@
 +        chunk       LKM::prototypes();
 +        chunk       LKM::code();
 +
-+        method      init(e1000::Context, Builtin::number);
++        method      init(e1000::Context, Builtin::number, Builtin::number);
 +
 +        // Keep a backref to The context since it's going to be needed for of
 +        // operations involving the ethernet device, flags on the context, etc.
 +        attribute   Context.ref             hw_ctx;
-+
 +        attribute   DMA::DMAHandle.scalar   dma;
 +        attribute   Builtin::number.scalar  size;   // Total size in bytes
 +        attribute   Builtin::symbol.ref     descs;
@@ -1749,6 +1772,7 @@
 -        //attribute   TxRing.scalar   tx_ring;
 +        attribute   RxDescriptor.scalar     descs;
 +        attribute   Builtin::number.scalar  desc_size;
++        attribute   Buffer.ref              buffs;
      }
  
      provided type   TxRing
@@ -1864,6 +1888,7 @@
 +        attribute   Builtin::number.scalar  size;
 +        attribute   TxDescriptor.scalar     descs;
 +        attribute   Builtin::number.scalar  desc_size;
++        attribute   Buffer.ref              buffs;
      }
  }
 diff --git a/rathaxes/samples/e1000/ethernet.blt b/rathaxes/samples/e1000/ethernet.blt