feat: better rtc framework which aims to remove single rtc restrictions.
[lunaix-os.git] / lunaix-os / includes / lunaix / device.h
index fd234f0d91a8880bdba11d2c0d582b1bef21b69a..2634d81dcd076b22f752c1a981decbbb76c35034 100644 (file)
@@ -4,9 +4,18 @@
 #define DEVICE_NAME_SIZE 32
 
 #include <lunaix/ds/hstr.h>
+#include <lunaix/ds/ldga.h>
 #include <lunaix/ds/llist.h>
+#include <lunaix/ds/semaphore.h>
 #include <lunaix/types.h>
 
+/**
+ * @brief Export pseudo device
+ *
+ */
+#define EXPORT_PSEUDODEV(id, init_fn)                                          \
+    export_ldga_el(pseudo_dev, id, ptr_t, init_fn)
+
 #define DEV_STRUCT_MAGIC 0x5645444c
 
 #define DEV_MSKIF 0x00000003
 #define DEV_IFVOL 0x0 // volumetric (block) device
 #define DEV_IFSEQ 0x1 // sequential (character) device
 #define DEV_IFCAT 0x2 // a device category (as device groupping)
+#define DEV_IFSYS 0x3 // a system device
 
 typedef unsigned int dev_t;
 
 struct device
 {
-    uint32_t magic;
+    u32_t magic;
     struct llist_header siblings;
     struct llist_header children;
     struct device* parent;
+    // TODO investigate event polling
+
     struct hstr name;
     dev_t dev_id;
     int dev_type;
     char name_val[DEVICE_NAME_SIZE];
     void* underlay;
-    int (*read)(struct device* dev, void* buf, size_t offset, size_t len);
-    int (*write)(struct device* dev, void* buf, size_t offset, size_t len);
-    int (*read_page)(struct device* dev, void* buf, size_t offset);
-    int (*write_page)(struct device* dev, void* buf, size_t offset);
-    int (*exec_cmd)(struct device* dev, uint32_t req, va_list args);
+
+    struct
+    {
+        int (*read)(struct device* dev, void* buf, size_t offset, size_t len);
+        int (*write)(struct device* dev, void* buf, size_t offset, size_t len);
+        int (*read_page)(struct device* dev, void* buf, size_t offset);
+        int (*write_page)(struct device* dev, void* buf, size_t offset);
+        int (*exec_cmd)(struct device* dev, u32_t req, va_list args);
+    } ops;
 };
 
 struct device*
 device_add(struct device* parent,
            void* underlay,
            char* name_fmt,
-           uint32_t type,
+           u32_t type,
            va_list args);
 
+struct device*
+device_addsys(struct device* parent, void* underlay, char* name_fmt, ...);
+
 struct device*
 device_addseq(struct device* parent, void* underlay, char* name_fmt, ...);
 
@@ -66,4 +85,7 @@ device_getbyname(struct device* root_dev, const char* name, size_t len);
 struct device*
 device_getbyoffset(struct device* root_dev, int pos);
 
+void
+device_install_pseudo();
+
 #endif /* __LUNAIX_DEVICE_H */