refactor: make pci device driver loading passive, pci bus scanner will not load them...
[lunaix-os.git] / lunaix-os / kernel / tty / lxconsole.c
index 0d7439be4542554b427ad998f9690d7c65fc9c85..fa20202807432f03c6a821dfd4960f9bb16b8ee0 100644 (file)
@@ -31,6 +31,9 @@ __tty_write(struct device* dev, void* buf, size_t offset, size_t len);
 int
 __tty_read(struct device* dev, void* buf, size_t offset, size_t len);
 
+void
+console_write(struct console* console, u8_t* data, size_t size);
+
 void
 console_flush();
 
@@ -143,25 +146,13 @@ __tty_read_pg(struct device* dev, void* buf, size_t offset)
     return __tty_read(dev, buf, offset, PG_SIZE);
 }
 
-void
-lxconsole_spawn_ttydev()
-{
-    struct device* tty_dev = device_addseq(NULL, &lx_console, "tty");
-    tty_dev->write = __tty_write;
-    tty_dev->write_page = __tty_write_pg;
-    tty_dev->read = __tty_read;
-    tty_dev->read_page = __tty_read_pg;
-    tty_dev->exec_cmd = __tty_exec_cmd;
-
-    waitq_init(&lx_reader);
-    input_add_listener(__lxconsole_listener);
-}
-
 int
 __tty_write(struct device* dev, void* buf, size_t offset, size_t len)
 {
     struct console* console = (struct console*)dev->underlay;
     console_write(console, buf, len);
+
+    return len;
 }
 
 int
@@ -204,6 +195,7 @@ __tty_read(struct device* dev, void* buf, size_t offset, size_t len)
             break;
         }
     }
+
     return count + fifo_read(&console->input, buf + count, len - count);
 }
 
@@ -285,15 +277,15 @@ console_flush()
 }
 
 void
-console_write(struct console* console, uint8_t* data, size_t size)
+console_write(struct console* console, u8_t* data, size_t size)
 {
     struct fifo_buf* fbuf = &console->output;
     mutex_lock(&console->output.lock);
     fifo_set_rdptr(fbuf, console->wnd_start);
 
-    uint8_t* buffer = fbuf->data;
-    uintptr_t ptr = fbuf->wr_pos;
-    uintptr_t rd_ptr = fbuf->rd_pos;
+    u8_t* buffer = fbuf->data;
+    ptr_t ptr = fbuf->wr_pos;
+    ptr_t rd_ptr = fbuf->rd_pos;
 
     char c;
     for (size_t i = 0; i < size; i++) {
@@ -331,13 +323,13 @@ console_write(struct console* console, uint8_t* data, size_t size)
 void
 console_write_str(char* str)
 {
-    console_write(&lx_console, str, strlen(str));
+    console_write(&lx_console, (u8_t*)str, strlen(str));
 }
 
 void
 console_write_char(char str)
 {
-    console_write(&lx_console, &str, 1);
+    console_write(&lx_console, (u8_t*)&str, 1);
 }
 
 void
@@ -346,4 +338,29 @@ console_start_flushing()
     struct lx_timer* timer =
       timer_run_ms(20, console_flush, NULL, TIMER_MODE_PERIODIC);
     lx_console.flush_timer = timer;
-}
\ No newline at end of file
+}
+
+static int
+lxconsole_spawn_ttydev(struct device_def* devdef)
+{
+    struct device* tty_dev = device_allocseq(NULL, &lx_console);
+    tty_dev->ops.write = __tty_write;
+    tty_dev->ops.write_page = __tty_write_pg;
+    tty_dev->ops.read = __tty_read;
+    tty_dev->ops.read_page = __tty_read_pg;
+    tty_dev->ops.exec_cmd = __tty_exec_cmd;
+
+    waitq_init(&lx_reader);
+    input_add_listener(__lxconsole_listener);
+
+    device_register(tty_dev, &devdef->class, "tty");
+
+    return 0;
+}
+
+static struct device_def lxconsole_def = {
+    .name = "Lunaix Virtual Console",
+    .class = DEVCLASSV(DEVIF_NON, DEVFN_TTY, DEV_BUILTIN, 12),
+    .init = lxconsole_spawn_ttydev
+};
+EXPORT_DEVICE(lxconsole, &lxconsole_def, load_onboot);
\ No newline at end of file