[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cdi-devel] [PATCH] Various cleanups and portability fixes



Hi,

This patch addresses several problems:
 * Added a few structures to cdi-osdep.h to clean up some tyndur-specific elements in some functions
 * Added extern "C" to header files where necessary in order to handle C++ linkage problems
 * This commit contains a draft for a solution (cdi-osdep.h) to get around the const error with CDI_DRIVER on some operating systems. This is merely an RFC change, and has not been propagated into actual driver code yet.
 
The idea of the CDI_DRIVER workaround is that both macros are implemented in drivers and the OS provides only one of the macros (whichever it supports best). There may well be a better solution; this is merely what I deem the most portable and simple solution.

Cheers,
Matt

Signed-off-by: Matthew Iselin <matthew@xxxxxxxxxxxxxx>
---
 include/cdi-osdep.h |   36 +++++++++++++++++++++++++++++++++++-
 include/cdi/dma.h   |    5 ++---
 include/cdi/misc.h  |    8 ++++++++
 include/cdi/net.h   |    8 ++++++++
 include/cdi/pci.h   |    3 +++
 5 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/include/cdi-osdep.h b/include/cdi-osdep.h
index 6227e91..08132c8 100644
--- a/include/cdi-osdep.h
+++ b/include/cdi-osdep.h
@@ -26,10 +26,44 @@
  * the driver with the CDI library.
  *
  * @param name Name of the driver
- * @param drv Pointer to a driver description (struct cdi_driver*)
+ * @param drv A driver description (struct cdi_driver)
  * @param deps List of names of other drivers on which this driver depends
  * \endenglish
  */
 #define CDI_DRIVER(name, drv, deps...) /* TODO */
 
+/**
+ * \english
+ * CDI_DRIVER_CONST shall be used exactly once for each CDI driver. It registers
+ * the driver with the CDI library. If CDI_DRIVER is defined, CDI_DRIVER_CONST
+ * must not be defined.
+ *
+ * @param name Name of the driver
+ * @param init Function to be called to initialise the driver
+ * @param destroy Function to be called to destroy the driver
+ * @param init_device Function to be called when initialising a device
+ * @param remove_device Function to be called when removing a device
+ * @param deps List of names of other drivers on which this driver depends
+ * \endenglish
+ */
+#define CDI_DRIVER_CONST(name, init, destroy, init_device, remove_device, deps...) /* TODO */
+
+/**
+ * \english
+ * OS-specific PCI metadata.
+ * \endenglish
+ */
+typedef struct
+{
+} os_pci_meta;
+
+/**
+ * \english
+ * OS-specific DMA metadata.
+ * \endenglish
+ */
+typedef struct
+{
+} os_dma_meta;
+
 #endif
diff --git a/include/cdi/dma.h b/include/cdi/dma.h
index 24f53a8..2ff19ec 100644
--- a/include/cdi/dma.h
+++ b/include/cdi/dma.h
@@ -20,9 +20,8 @@ struct cdi_dma_handle {
     size_t      length;
     uint8_t     mode;
     void*       buffer;
-
-    // LOST-Implementation...
-    FILE*       file;
+    
+    os_dma_meta meta;
 };
 
 // Geraet => Speicher
diff --git a/include/cdi/misc.h b/include/cdi/misc.h
index 2a130f6..2049c62 100644
--- a/include/cdi/misc.h
+++ b/include/cdi/misc.h
@@ -15,6 +15,10 @@
 
 #include "cdi.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * Registiert einen neuen IRQ-Handler.
  *
@@ -89,5 +93,9 @@ int cdi_ioports_free(uint16_t start, uint16_t count);
  */
 void cdi_sleep_ms(uint32_t ms);
 
+#ifdef __cplusplus
+}; // extern "C"
+#endif
+
 #endif
 
diff --git a/include/cdi/net.h b/include/cdi/net.h
index 89628bd..1fddab6 100644
--- a/include/cdi/net.h
+++ b/include/cdi/net.h
@@ -36,6 +36,10 @@ struct cdi_net_driver {
 };
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * Initialisiert die Datenstrukturen fuer einen Netzerktreiber
  * (erzeugt die devices-Liste)
@@ -60,6 +64,10 @@ void cdi_net_device_init(struct cdi_net_device* device);
 void cdi_net_receive(
     struct cdi_net_device* device, void* buffer, size_t size);
 
+#ifdef __cplusplus
+}; // extern "C"
+#endif
+
 #endif
 
 /*\@}*/
diff --git a/include/cdi/pci.h b/include/cdi/pci.h
index 8a9cc18..6a3be7a 100644
--- a/include/cdi/pci.h
+++ b/include/cdi/pci.h
@@ -14,6 +14,7 @@
 #include <stdint.h>
 
 #include "cdi.h"
+#include "cdi-osdep.h"
 #include "cdi/lists.h"
 
 struct cdi_pci_device {
@@ -33,6 +34,8 @@ struct cdi_pci_device {
     uint8_t     irq;
 
     cdi_list_t resources;
+    
+    os_pci_meta meta;
 };
 
 typedef enum {
-- 
1.6.0.4