rewrite the device subsystem interfaces (#48)
[lunaix-os.git] / lunaix-os / kernel / device / potentem.c
diff --git a/lunaix-os/kernel/device/potentem.c b/lunaix-os/kernel/device/potentem.c
new file mode 100644 (file)
index 0000000..b7de144
--- /dev/null
@@ -0,0 +1,33 @@
+#include <lunaix/device.h>
+#include <lunaix/mm/valloc.h>
+
+struct potens_meta*
+alloc_potens(int cap, unsigned int size) 
+{
+    struct potens_meta* cm = (struct potens_meta*)vzalloc(size);
+
+    cm->pot_type = cap;
+
+    return cm;
+}
+
+void
+device_grant_potens(struct device* dev, struct potens_meta* cap)
+{
+    llist_append(&dev->potentium, &cap->potentes);
+    cap->owner = dev;
+}
+
+struct potens_meta*
+device_get_potens(struct device* dev, unsigned int pot_type)
+{
+    struct potens_meta *pos, *n;
+
+    llist_for_each(pos, n, &dev->potentium, potentes) {
+        if (pos->pot_type == pot_type){
+            return pos;
+        }
+    }
+
+    return NULL;
+}
\ No newline at end of file