From 0b7e14c69bedea234afc30902d1cb371b7e3274e Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Sun, 7 Oct 2012 10:28:33 -0400 Subject: [PATCH] serial: Allow more than one serial device to be registered --- drivers/serial.c | 15 ++++++++++----- include/drivers/serial.h | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/serial.c b/drivers/serial.c index 4431912..5b66ccd 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -21,16 +21,21 @@ #include #include -struct serial_dev *first_serial_dev; +struct dlist_node serial_dev_list; int serial_register_device(struct serial_dev *sdev) { - if (!first_serial_dev) - first_serial_dev = sdev; + if (!sdev) + return -1; + + insert_before(&serial_dev_list, &sdev->list); return 0; } struct serial_dev *serial_first_device() { - return first_serial_dev; + if (list_empty(&serial_dev_list)) + return 0; + + return container(serial_dev_list.next, struct serial_dev, list); } /* @@ -40,5 +45,5 @@ struct serial_dev *serial_first_device() { * initialized in earlyinitcalls. */ void serial_init() { - first_serial_dev = 0; + init_list(&serial_dev_list); } diff --git a/include/drivers/serial.h b/include/drivers/serial.h index 555a17a..80da521 100644 --- a/include/drivers/serial.h +++ b/include/drivers/serial.h @@ -18,9 +18,12 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + struct serial_dev { //TODO add more functions and attributes here int (*putc)(char); + struct dlist_node list; }; int serial_register_device(struct serial_dev *sdev);