From 5bb5ac3a901a914b314290541f4690cb38ef559e Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Fri, 16 Aug 2024 09:59:29 +0300 Subject: [PATCH] foo --- kern/src/dev.c | 17 ++++++++++++++++- kern/src/dev.h | 2 ++ kern/src/ser.c | 23 ++++++++++------------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/kern/src/dev.c b/kern/src/dev.c index e0635cf..0648a36 100644 --- a/kern/src/dev.c +++ b/kern/src/dev.c @@ -1,6 +1,21 @@ #include "dev.h" +struct device devices[MAX_DEVICES]; + struct file *dev_open(int major, int minor, unsigned int flags) { - return 0; /* TODO */ + /* XXX temporary hack */ + struct inode fakenode; + static struct file file; + + fakenode.dev_major = major; + fakenode.dev_minor = minor; + + if(!devices[major].fop) { + return 0; + } + if(devices[major].fop->open(&file, &fakenode, flags) < 0) { + return 0; + } + return &file; } diff --git a/kern/src/dev.h b/kern/src/dev.h index 1f5a883..ec61fe5 100644 --- a/kern/src/dev.h +++ b/kern/src/dev.h @@ -12,6 +12,8 @@ struct device { #define DEV_VID 0 #define DEV_SER 1 +extern struct device devices[MAX_DEVICES]; + struct file *dev_open(int major, int minor, unsigned int flags); #endif /* DEV_H_ */ diff --git a/kern/src/ser.c b/kern/src/ser.c index 08fb397..db948e9 100644 --- a/kern/src/ser.c +++ b/kern/src/ser.c @@ -16,8 +16,6 @@ #define UART_MCTL 4 #define UART_LSTAT 5 -#define DIV_9600 (115200 / 9600) -#define DIV_38400 (115200 / 38400) #define LCTL_8N1 0x03 #define LCTL_DLAB 0x80 #define FIFO_ENABLE_CLEAR 0x07 @@ -34,20 +32,19 @@ static int ser_write(struct file *file, void *buf, int sz); static int ser_ioctl(struct file *file, int ioc, long val); static unsigned int uart_addr[2] = {UART1_BASE, UART2_BASE}; -static struct device serdev[2]; +static struct fileops fops; static unsigned int devopen; int ser_init(void) { - int i; - - for(i=0; i<2; i++) { - serdev[i].fop->open = ser_open; - serdev[i].fop->close = ser_close; - serdev[i].fop->read = ser_read; - serdev[i].fop->write = ser_write; - serdev[i].fop->ioctl = ser_ioctl; - } + fops.open = ser_open; + fops.close = ser_close; + fops.read = ser_read; + fops.write = ser_write; + fops.ioctl = ser_ioctl; + + devices[DEV_SER].fop = &fops; + devopen = 0; setuart(0, BAUD_9600); @@ -99,7 +96,7 @@ static int ser_open(struct file *file, struct inode *inode, unsigned int flags) memset(file, 0, sizeof *file); file->type = FILE_CDEV; file->inode = inode; - file->dev = serdev + port; + file->dev = devices + DEV_SER; devopen |= 1 << port; return 0; -- 1.7.10.4