changeset 5:e94d4a9e6bd5

WIP on the PCI LKM
author Louis Opter <louis@lse.epitech.net>
date Thu, 05 Jan 2012 20:53:28 +0100
parents d102c9be499c
children 5b128dbd2c17
files rathaxes_start_to_implement_pci_stuff_in_the_lkm.patch
diffstat 1 files changed, 53 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/rathaxes_start_to_implement_pci_stuff_in_the_lkm.patch	Thu Jan 05 17:37:29 2012 +0100
+++ b/rathaxes_start_to_implement_pci_stuff_in_the_lkm.patch	Thu Jan 05 20:53:28 2012 +0100
@@ -1,5 +1,5 @@
 # HG changeset patch
-# Parent e6e856bbde57d16b41e73cec8026d485ed722ab4
+# Parent 23fc39d03d6679b631adc6c22f312e6cda9aa82f
 rathaxes: start to implement the PCI registration part in the LKM sample
 
 diff --git a/rathaxes/samples/lkm/CMakeLists.txt b/rathaxes/samples/lkm/CMakeLists.txt
@@ -14,18 +14,20 @@
 diff --git a/rathaxes/samples/lkm/lkm.blt b/rathaxes/samples/lkm/lkm.blt
 --- a/rathaxes/samples/lkm/lkm.blt
 +++ b/rathaxes/samples/lkm/lkm.blt
-@@ -1,8 +1,8 @@
+@@ -1,8 +1,10 @@
  with LKM
  {
++    /* Skel of the generated C file: */
      ${pointcut LKM::includes};
 -    ${pointcut LKM::init};
 -    ${pointcut LKM::exit};
++    ${pointcut LKM::prototypes};
 +    ${pointcut LKM::data};
 +    ${pointcut LKM::code};
  
      template sequence   LKM::init()
      {
-@@ -17,7 +17,7 @@
+@@ -17,7 +19,7 @@
              MODULE_LICENSE(${config.license});
          }
  
@@ -34,7 +36,7 @@
          {
              /*
               * Rathaxes doesn't yet support arbitrary "decorators" like __init
-@@ -34,7 +34,7 @@
+@@ -34,7 +36,7 @@
  
      template sequence   LKM::exit()
      {
@@ -46,18 +48,19 @@
 diff --git a/rathaxes/samples/lkm/lkm.rti b/rathaxes/samples/lkm/lkm.rti
 --- a/rathaxes/samples/lkm/lkm.rti
 +++ b/rathaxes/samples/lkm/lkm.rti
-@@ -1,8 +1,8 @@
+@@ -1,8 +1,9 @@
  interface LKM
  {
      provided pointcut   LKM::includes;
 -    provided pointcut   LKM::init;
 -    provided pointcut   LKM::exit;
++    provided pointcut   LKM::prototypes;
 +    provided pointcut   LKM::data;
 +    provided pointcut   LKM::code;
  
      required variable ::string  LKM::author;
      required variable ::string  LKM::description;
-@@ -11,11 +11,11 @@
+@@ -11,11 +12,11 @@
      required sequence   LKM::init()
      {
          provided chunk  LKM::includes;
@@ -91,7 +94,7 @@
      LKM::init()
      {
          Log::info("Hello this is LKM");
-@@ -12,6 +22,7 @@
+@@ -12,7 +22,11 @@
  
  configuration
  {
@@ -99,11 +102,15 @@
      LKM::author = "Rathaxes";
      LKM::description = "Hello World Loadable Kernel Module (LKM)";
      LKM::license = "BSD";
++
++    PCI::vendor_id = "0x8080";
++    PCI::product_id = "0x42";
+ }
 diff --git a/rathaxes/samples/lkm/pci.blt b/rathaxes/samples/lkm/pci.blt
 new file mode 100644
 --- /dev/null
 +++ b/rathaxes/samples/lkm/pci.blt
-@@ -0,0 +1,73 @@
+@@ -0,0 +1,103 @@
 +with PCI, LKM
 +{
 +    template type   PCI::Device()
@@ -137,6 +144,31 @@
 +
 +    template sequence   PCI::probe(PCI::Device dev)
 +    {
++        chunk LKM::prototypes()
++        {
++            static int /* __devinit */  rtx_pci_probe(struct pci_dev *,
++                                                      const struct pci_device_id *);
++        }
++
++        chunk LKM::data()
++        {
++            /*
++             * CNorm doesn't seem to like "dynamic" arrays (i.e: you always
++             * have to specify the exact size).
++             */
++            static struct pci_device_id	rtx_pci_device_table[2] = {
++                { ${config.vendor_id}, ${config.product_id}, 0, PCI_ANY_ID, PCI_ANY_ID },
++                { 0, }
++            };
++
++            static struct pci_driver rtx_pci_driver = {
++                .name = ${config.name},
++                .id_table = rtx_pci_device_table,
++                .probe = rtx_pci_probe,
++                .remove = rtx_pci_remove
++            };
++        }
++
 +        chunk LKM::code()
 +        {
 +            static int /* __devinit */  rtx_pci_probe(struct pci_dev *pdev,
@@ -146,7 +178,7 @@
 +                typedef int ${PCI::Device};
 +
 +                int             err;
-+                ${PCI::Device}  dev = NULL; /* Doesn't work with a pointer */
++                ${PCI::Device}  *dev = NULL; /* Doesn't work with a pointer */
 +
 +                err = pci_enable_device(pdev);
 +//              if (err < 0) /* `if' doesn't work */
@@ -166,6 +198,11 @@
 +
 +    template sequence   PCI::remove(PCI::Device dev)
 +    {
++        chunk LKM::prototypes()
++        {
++            static void rtx_pci_remove(struct pci_dev *);
++        }
++
 +        chunk LKM::code()
 +        {
 +            static void rtx_pci_remove(struct pci_dev *pdev)
@@ -181,11 +218,14 @@
 new file mode 100644
 --- /dev/null
 +++ b/rathaxes/samples/lkm/pci.rti
-@@ -0,0 +1,19 @@
+@@ -0,0 +1,25 @@
 +interface PCI : LKM
 +{
 +    provided type       PCI::Device;
 +
++    required variable ::number  PCI::vendor_id;
++    required variable ::number  PCI::product_id;
++
 +    provided sequence   PCI::register()
 +    {
 +        provided chunk  ::CALL;
@@ -193,11 +233,14 @@
 +
 +    required sequence   PCI::probe(PCI::Device)
 +    {
++        provided chunk  LKM::prototypes;
++        provided chunk  LKM::data;
 +        provided chunk  LKM::code;
 +    }
 +
 +    required sequence   PCI::remove(PCI::Device)
 +    {
++        provided chunk  LKM::prototypes;
 +        provided chunk  LKM::code;
 +    }
 +}