changeset 115:5a663f8f0e54

WIP, fix another small bug in rathaxes sequence calls
author Louis Opter <louis@lse.epita.fr>
date Mon, 22 Jul 2013 13:52:00 -0700
parents 8eac160e5f1c
children 2a7126613c70
files rathaxes_compiler_passes_look_for_locally_casted_variables_in_sequence_calls.patch rathaxes_samples_e1000_add_a_dma_abstraction.patch rathaxes_samples_e1000_use_the_dma_abstraction_in_socket.patch series
diffstat 4 files changed, 101 insertions(+), 120 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rathaxes_compiler_passes_look_for_locally_casted_variables_in_sequence_calls.patch	Mon Jul 22 13:52:00 2013 -0700
@@ -0,0 +1,20 @@
+# HG changeset patch
+# User David Pineau <dav.pineau@gmail.com>, Louis Opter <louis@lse.epita.fr>
+# Parent 163975605ce8e4b9049deb60207358acc904f14c
+rathaxes: correctly resolve locally casted variables during sequence calls
+
+C variables declared locally and casted into Rathaxes types weren't
+taken into account during sequence calls. This changeset fixes it.
+
+diff --git a/rathaxes/compiler/passes/back/rtxIntrospect.inc.cws b/rathaxes/compiler/passes/back/rtxIntrospect.inc.cws
+--- a/rathaxes/compiler/passes/back/rtxIntrospect.inc.cws
++++ b/rathaxes/compiler/passes/back/rtxIntrospect.inc.cws
+@@ -751,6 +751,8 @@
+             local theType;
+             if (findElement(theVar.name, theChunk.type_map))
+                 ref theType = theChunk.type_map[theVar.name];
++            else if (findElement(theVar.name, theChunk.variables))
++                ref theType = theChunk.variables[theVar.name].type_node;
+             insert param.rtype;
+             if (getArraySize(param.identifiers) > 2)
+             {
--- a/rathaxes_samples_e1000_add_a_dma_abstraction.patch	Mon Jul 22 00:35:20 2013 -0700
+++ b/rathaxes_samples_e1000_add_a_dma_abstraction.patch	Mon Jul 22 13:52:00 2013 -0700
@@ -1,5 +1,5 @@
 # HG changeset patch
-# Parent 0f12e80e810de1a9927db1f25dbea49acd73ae3c
+# Parent af7a1f8589d632497e2f2574570f5153cae59b91
 e1000: start a DMA allocation/mapping abstraction
 
 It currently matches a lot the Linux DMA API but it should be usable by
@@ -35,10 +35,10 @@
 new file mode 100644
 --- /dev/null
 +++ b/rathaxes/samples/e1000/dma.blt
-@@ -0,0 +1,81 @@
+@@ -0,0 +1,89 @@
 +with DMA, Builtin, LKM, Device
 +{
-+    template type   AbstractDMAHandle()
++    template type   DMA::AbstractDMAHandle()
 +    {
 +        chunk   LKM::includes()
 +        {
@@ -52,11 +52,11 @@
 +
 +        map
 +        {
-+            k_dma_handle: ((dma_addr_t *)${self});
++            k_dma_handle: ((dma_addr_t)${self});
 +        }
 +    }
 +
-+    template type   AbstractDMADirection()
++    template type   DMA::AbstractDMADirection()
 +    {
 +        decl    data_types()
 +        {
@@ -69,7 +69,7 @@
 +        }
 +    }
 +
-+    template type   DMADirection()
++    template type   DMA::DMADirection()
 +    {
 +        decl    data_types()
 +        {
@@ -80,20 +80,20 @@
 +
 +        map
 +        {
-+            /* XXX: we should use ${AbstractDMADirection} here: */
++            /* XXX: we should use ${DMA::AbstractDMADirection} here: */
 +            dma_direction: ((enum dma_data_direction)${self});
 +        }
 +    }
 +
-+    template sequence   map(Device::AbstractDevice dev, Builtin::symbol buf, Builtin::number size, DMADirection dir)
++    template sequence   map(Device::AbstractDevice dev, Builtin::symbol buf, Builtin::number size, DMA::DMADirection dir)
 +    {
 +        chunk  ::CALL()
 +        {
-+            dma_map_single(${dev.k_device}, ${buf}, ${size}, ${dir.dma_direction});
++            ((${DMA::DMA::AbstractDMAHandle})dma_map_single(${dev.k_device}, ${buf}, ${size}, ${dir.dma_direction}));
 +        }
 +    }
 +
-+    template sequence   unmap(Device::AbstractDevice dev, AbstractDMAHandle handle, Builtin::number size, DMADirection dir)
++    template sequence   unmap(Device::AbstractDevice dev, DMA::AbstractDMAHandle handle, Builtin::number size, DMA::DMADirection dir)
 +    {
 +        chunk  ::CALL()
 +        {
@@ -101,15 +101,23 @@
 +        }
 +    }
 +
-+    template sequence   alloc_coherent(Device::AbstractDevice dev, Builtin::number size, AbstractDMAHandle handle)
++    template sequence   mapping_error(Device::AbstractDevice dev, DMA::AbstractDMAHandle handle)
++    {
++        chunk ::CALL()
++        {
++            dma_mapping_error(${dev.k_device}, ${handle.k_dma_handle});
++        }
++    }
++
++    template sequence   alloc_coherent(Device::AbstractDevice dev, Builtin::number size, DMA::AbstractDMAHandle handle)
 +    {
 +        chunk  ::CALL()
 +        {
-+            dma_alloc_coherent(${dev.k_device}, ${size}, ${handle.k_dma_handle}, GFP_KERNEL);
++            dma_alloc_coherent(${dev.k_device}, ${size}, &${handle.k_dma_handle}, GFP_KERNEL);
 +        }
 +    }
 +
-+    template sequence   free_coherent(Device::AbstractDevice dev, Builtin::number size, Builtin::symbol addr, AbstractDMAHandle handle)
++    template sequence   free_coherent(Device::AbstractDevice dev, Builtin::number size, Builtin::symbol addr, DMA::AbstractDMAHandle handle)
 +    {
 +        chunk  ::CALL()
 +        {
@@ -121,7 +129,7 @@
 new file mode 100644
 --- /dev/null
 +++ b/rathaxes/samples/e1000/dma.rti
-@@ -0,0 +1,42 @@
+@@ -0,0 +1,48 @@
 +interface DMA : Builtin, LKM, Device
 +{
 +    provided type   AbstractDMAHandle
@@ -153,6 +161,12 @@
 +        provided chunk  ::CALL();
 +    }
 +
++    /* XXX: Until we have a real error handling mechanism: */
++    provided sequence   mapping_error(Device::AbstractDevice, AbstractDMAHandle)
++    {
++        provided chunk  ::CALL(); /* -> != 0 if the mapping failed */
++    }
++
 +    provided sequence   alloc_coherent(Device::AbstractDevice, Builtin::number, AbstractDMAHandle)
 +    {
 +        /* return the addr and the handle via the AbstractDMAHandle ptr: */
--- a/rathaxes_samples_e1000_use_the_dma_abstraction_in_socket.patch	Mon Jul 22 00:35:20 2013 -0700
+++ b/rathaxes_samples_e1000_use_the_dma_abstraction_in_socket.patch	Mon Jul 22 13:52:00 2013 -0700
@@ -1,98 +1,7 @@
 # HG changeset patch
-# Parent 5a53813ed1306484aa98dd95fe1d284ed24111ab
+# Parent 22cdd951a10d1b8b06daf6448da73e738f21d2e3
 Replace Linux specific code in Socket by DMA calls
 
-diff --git a/rathaxes/samples/e1000/dma.blt b/rathaxes/samples/e1000/dma.blt
---- a/rathaxes/samples/e1000/dma.blt
-+++ b/rathaxes/samples/e1000/dma.blt
-@@ -1,6 +1,6 @@
- with DMA, Builtin, LKM, Device
- {
--    template type   AbstractDMAHandle()
-+    template type   DMA::AbstractDMAHandle()
-     {
-         chunk   LKM::includes()
-         {
-@@ -14,11 +14,11 @@
- 
-         map
-         {
--            k_dma_handle: ((dma_addr_t *)${self});
-+            k_dma_handle: ((dma_addr_t)${self});
-         }
-     }
- 
--    template type   AbstractDMADirection()
-+    template type   DMA::AbstractDMADirection()
-     {
-         decl    data_types()
-         {
-@@ -42,7 +42,7 @@
- 
-         map
-         {
--            /* XXX: we should use ${AbstractDMADirection} here: */
-+            /* XXX: we should use ${DMA::AbstractDMADirection} here: */
-             dma_direction: ((enum dma_data_direction)${self});
-         }
-     }
-@@ -51,11 +51,11 @@
-     {
-         chunk  ::CALL()
-         {
--            dma_map_single(${dev.k_device}, ${buf}, ${size}, ${dir.dma_direction});
-+            ((${DMA::DMA::AbstractDMAHandle})dma_map_single(${dev.k_device}, ${buf}, ${size}, ${dir.dma_direction}));
-         }
-     }
- 
--    template sequence   unmap(Device::AbstractDevice dev, AbstractDMAHandle handle, Builtin::number size, DMADirection dir)
-+    template sequence   unmap(Device::AbstractDevice dev, DMA::AbstractDMAHandle handle, Builtin::number size, DMADirection dir)
-     {
-         chunk  ::CALL()
-         {
-@@ -63,15 +63,23 @@
-         }
-     }
- 
--    template sequence   alloc_coherent(Device::AbstractDevice dev, Builtin::number size, AbstractDMAHandle handle)
-+    template sequence   mapping_error(Device::AbstractDevice dev, DMA::AbstractDMAHandle handle)
-+    {
-+        chunk ::CALL()
-+        {
-+            dma_mapping_error(${dev.k_device}, ${handle.k_dma_handle});
-+        }
-+    }
-+
-+    template sequence   alloc_coherent(Device::AbstractDevice dev, Builtin::number size, DMA::AbstractDMAHandle handle)
-     {
-         chunk  ::CALL()
-         {
--            dma_alloc_coherent(${dev.k_device}, ${size}, ${handle.k_dma_handle}, GFP_KERNEL);
-+            dma_alloc_coherent(${dev.k_device}, ${size}, &${handle.k_dma_handle}, GFP_KERNEL);
-         }
-     }
- 
--    template sequence   free_coherent(Device::AbstractDevice dev, Builtin::number size, Builtin::symbol addr, AbstractDMAHandle handle)
-+    template sequence   free_coherent(Device::AbstractDevice dev, Builtin::number size, Builtin::symbol addr, DMA::AbstractDMAHandle handle)
-     {
-         chunk  ::CALL()
-         {
-diff --git a/rathaxes/samples/e1000/dma.rti b/rathaxes/samples/e1000/dma.rti
---- a/rathaxes/samples/e1000/dma.rti
-+++ b/rathaxes/samples/e1000/dma.rti
-@@ -29,6 +29,12 @@
-         provided chunk  ::CALL();
-     }
- 
-+    /* XXX: Until we have a real error handling mechanism: */
-+    provided sequence   mapping_error(Device::AbstractDevice, AbstractDMAHandle)
-+    {
-+        provided chunk  ::CALL(); /* -> != 0 if the mapping failed */
-+    }
-+
-     provided sequence   alloc_coherent(Device::AbstractDevice, Builtin::number, AbstractDMAHandle)
-     {
-         /* return the addr and the handle via the AbstractDMAHandle ptr: */
 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
@@ -102,7 +11,7 @@
  {
      template type Socket::AbstractSKBuff()
      {
-@@ -22,15 +22,15 @@
+@@ -22,35 +22,34 @@
      {
          decl  data_types()
          {
@@ -118,11 +27,47 @@
 -            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);
 +            static int  rtx_socket_skbuff_map(${Socket::SKBuff.ref}, ${Device::AbstractDevice.ref}, ${DMA::DMADirection.scalar});
-+            static void rtx_socket_skbuff_unmap_and_free(${Socket::SKBuff.ref}, struct device *, ${DMA::DMADirection.scalar});
++            static void rtx_socket_skbuff_unmap_and_free(${Socket::SKBuff.ref}, ${Device::AbstractDevice.ref}, ${DMA::DMADirection.scalar});
          }
  
          chunk   LKM::code()
-@@ -65,23 +65,21 @@
+         {
+             static void rtx_socket_skbuff_dump_infos(${Socket::SKBuff.ref} self)
+             {
+-                WARN_ON(!self->skbuff);
++                WARN_ON(!${local.self.k_sk_buff});
++
++                ${Ethernet::ProtocolId} ethernet_proto = { .id = be16_to_cpu(${local.self.k_sk_buff}->protocol) };
++                static const char * const ip_summed_values[] = {
++                    "none", "unnecessary", "complete", "partial"
++                };
++                struct skb_shared_info *shinfo = skb_shinfo(${local.self.k_sk_buff});
+ 
+                 /*
+                  * We should use a Rathaxes log abstraction instead of pr_info here,
+                  * but Rathaxes doesn't support functions with a variable number of
+                  * arguments yet.
+                  */
+-                ${Socket::AbstractSKBuff.ref} skb = self->skbuff;
+-                ${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.k_sk_buff});
+-
+                 pr_info(
+                         "\t protocol = %#-5x (%s) ip_summed = %d (%s)\n"
+                         "\t      len = %-5u data_len = %-5u head_len = %-5u\n"
+@@ -58,30 +57,26 @@
+                         "\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.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}),
++                        ${local.self.k_sk_buff}->ip_summed, ip_summed_values[${local.self.k_sk_buff}->ip_summed],
++                        ${local.self.k_sk_buff}->len, ${local.self.k_sk_buff}->data_len, skb_headlen(${local.self.k_sk_buff}),
+                         shinfo->nr_frags, shinfo->gso_size, shinfo->gso_segs, shinfo->gso_type
+                 );
              }
  
              static int rtx_socket_skbuff_map(${Socket::SKBuff.ref} self,
@@ -132,20 +77,21 @@
 +                                             ${DMA::DMADirection.scalar} direction)
              {
 -                ${Socket::AbstractSKBuff.ref}   skb = self->skbuff;
--
--                WARN_ON(!${local.skb.k_sk_buff});
--                WARN_ON(self->dma_handle);
 +                WARN_ON(!${local.self.k_sk_buff});
 +                WARN_ON(${local.self.k_dma_handle});
  
-                 self->dma_handle = dma_map_single(
+-                WARN_ON(!${local.skb.k_sk_buff});
+-                WARN_ON(self->dma_handle);
+-
+-                self->dma_handle = dma_map_single(
 -                        dev,
-+                        ${dev.k_device},
-                         ${local.skb.k_sk_buff},
-                         skb_headlen(${local.skb.k_sk_buff}),
+-                        ${local.skb.k_sk_buff},
+-                        skb_headlen(${local.skb.k_sk_buff}),
 -                        direction);
 -                int err = dma_mapping_error(dev, self->dma_handle);
-+                        ${local.direction.dma_direction});
++                unsigned int len = skb_headlen(${local.skb.k_sk_buff});
++                ${cast local.len as Builtin::number};
++                ${local.self.k_dma_handle} = ${DMA::map(local.dev, local.skb.k_sk_buff, local.len, local.direction)};
 +                int err = ${DMA::mapping_error(local.dev, local.self.k_dma_handle)};
                  if (err)
                  {
@@ -154,7 +100,7 @@
                      return err;
                  }
                  return 0;
-@@ -89,7 +87,7 @@
+@@ -89,7 +84,7 @@
  
              static void rtx_socket_skbuff_unmap_and_free(${Socket::SKBuff.ref} self,
                                                           struct device *dev,
@@ -163,7 +109,7 @@
              {
                  ${Socket::AbstractSKBuff.ref}   skb = self->skbuff;
  
-@@ -100,7 +98,7 @@
+@@ -100,7 +95,7 @@
                      dma_unmap_single(dev,
                              self->dma_handle,
                              skb_headlen(${local.skb.k_sk_buff}),
@@ -172,7 +118,7 @@
                      self->dma_handle = 0;
                  }
                  dev_kfree_skb_any(${local.skb.k_sk_buff});
-@@ -126,30 +124,32 @@
+@@ -126,30 +121,32 @@
  
          method   map_to(Device::AbstractDevice dev)
          {
--- a/series	Mon Jul 22 00:35:20 2013 -0700
+++ b/series	Mon Jul 22 13:52:00 2013 -0700
@@ -1,4 +1,5 @@
 rathaxes_compiler_passes_correctly_resolve_all_variables_subidentifiers.patch
+rathaxes_compiler_passes_look_for_locally_casted_variables_in_sequence_calls.patch
 rathaxes_compiler_passes_hack_injection_of_chunks_into_rvalues.patch
 rathaxes_samples_e1000_add_a_dma_abstraction.patch
 rathaxes_samples_e1000_use_the_dma_abstraction_in_socket.patch