PCI 16x50 UART Controller, O2 Enablement (#39)
[lunaix-os.git] / lunaix-os / hal / char / serial.c
index d93ff398b81231019595c332bf8daaae1ad5e1a6..15a9c9ed098113e963c7af5c52af1284d9a45dd2 100644 (file)
@@ -1,13 +1,17 @@
 #include <lunaix/device.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/spike.h>
+#include <lunaix/owloysius.h>
 #include <lunaix/status.h>
+#include <lunaix/syslog.h>
 
-#include <sys/mm/mempart.h>
+#include <sys/mm/pagetable.h>
 
 #include <hal/serial.h>
 #include <hal/term.h>
 
+LOG_MODULE("serial")
+
 #define lock_sdev(sdev) device_lock((sdev)->dev)
 #define unlock_sdev(sdev) device_unlock((sdev)->dev)
 #define unlock_and_wait(sdev, wq)                                              \
@@ -20,6 +24,8 @@
 static DEFINE_LLIST(serial_devs);
 static int serial_idx = 0;
 
+static struct device_cat* serial_cat;
+
 #define serial_device(dev) ((struct serial_dev*)(dev)->underlay)
 
 int
@@ -159,7 +165,7 @@ __serial_read_async(struct device* dev, void* buf, off_t fpos, size_t len)
 static int
 __serial_read_page(struct device* dev, void* buf, off_t fpos)
 {
-    return serial_readbuf(serial_device(dev), (u8_t*)buf, MEM_PAGE);
+    return serial_readbuf(serial_device(dev), (u8_t*)buf, PAGE_SIZE);
 }
 
 static int
@@ -178,7 +184,7 @@ __serial_write_async(struct device* dev, void* buf, off_t fpos, size_t len)
 static int
 __serial_write_page(struct device* dev, void* buf, off_t fpos)
 {
-    return serial_writebuf(serial_device(dev), (u8_t*)buf, MEM_PAGE);
+    return serial_writebuf(serial_device(dev), (u8_t*)buf, PAGE_SIZE);
 }
 
 static int
@@ -239,7 +245,7 @@ struct serial_dev*
 serial_create(struct devclass* class, char* if_ident)
 {
     struct serial_dev* sdev = valloc(sizeof(struct serial_dev));
-    struct device* dev = device_allocseq(NULL, sdev);
+    struct device* dev = device_allocseq(dev_meta(serial_cat), sdev);
     dev->ops.read = __serial_read;
     dev->ops.read_page = __serial_read_page;
     dev->ops.read_async = __serial_read_async;
@@ -264,10 +270,13 @@ serial_create(struct devclass* class, char* if_ident)
     
     device_grant_capability(dev, cap_meta(tp_cap));
 
-    register_device(dev, class, "serial%d", class->variant);
+    register_device(dev, class, "%s%d", if_ident, class->variant);
 
     term_create(dev, if_ident);
 
+    INFO("interface: %s, %xh:%xh.%d", dev->name_val, 
+            class->fn_grp, class->device, class->variant);
+
     class->variant++;
     return sdev;
 }
@@ -284,4 +293,13 @@ serial_get_avilable()
     }
 
     return NULL;
-}
\ No newline at end of file
+}
+
+static void
+init_serial_dev()
+{
+    serial_cat = device_addcat(NULL, "serial");
+
+    assert(serial_cat);
+}
+owloysius_fetch_init(init_serial_dev, on_earlyboot)
\ No newline at end of file