From e501929ad5d2d478647bdf8933a050cc9d9be355 Mon Sep 17 00:00:00 2001 From: Helge Skrivervik Date: Mon, 11 Jul 2022 14:44:21 +0200 Subject: [PATCH 1/3] [serial driver] Removed hardcoding of IRQs for S2, S3 --- elks/arch/i86/drivers/char/serial-8250.c | 29 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/elks/arch/i86/drivers/char/serial-8250.c b/elks/arch/i86/drivers/char/serial-8250.c index ce37f6e18..726e9eab2 100644 --- a/elks/arch/i86/drivers/char/serial-8250.c +++ b/elks/arch/i86/drivers/char/serial-8250.c @@ -27,7 +27,8 @@ struct serial_info { unsigned char mcr; unsigned int divisor; struct tty *tty; - int pad1, pad2, pad3; // round out to 16 bytes for faster addressing of ports[] + int index; + int pad1, pad2; // round out to 16 bytes for faster addressing of ports[] }; /* flags*/ @@ -58,11 +59,12 @@ struct serial_info { static struct serial_info ports[NR_SERIAL] = { {(char *)COM1_PORT, COM1_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 0,0,0}, - {(char *)COM2_PORT, COM2_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 0,0,0}, - {(char *)COM3_PORT, COM3_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 0,0,0}, - {(char *)COM4_PORT, COM4_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 0,0,0}, + {(char *)COM2_PORT, COM2_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 1,0,0}, + {(char *)COM3_PORT, COM3_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 2,0,0}, + {(char *)COM4_PORT, COM4_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 3,0,0}, }; +static char ttytab[16]; static unsigned int divisors[] = { 0, /* 0 = B0 */ 2304, /* 1 = B50 */ @@ -275,16 +277,24 @@ void fast_com2_irq(void) #if !defined(CONFIG_FAST_IRQ4) || !defined(CONFIG_FAST_IRQ3) - -static int irq_port[NR_SERIAL] = { 3, 1, 0, 2 }; //FIXME must change with ports.h - +#if 0 +static struct serial_info *get_line(int irq) { + int i; + for (i = 0; i < NR_SERIAL; i++ ) + if (ports[i].irq == irq) + return (&ports[i]); + /* Assuming this cannot possibly fail ... */ + return NULL; +} +#endif /* * Slower serial interrupt routine, called from _irq_com with passed irq # * Reads all FIFO data available per interrupt and can provide serial stats */ void rs_irq(int irq, struct pt_regs *regs) { - struct serial_info *sp = &ports[irq_port[irq - 2]]; + struct serial_info *sp = &ports[(int)ttytab[irq]]; + //struct serial_info *sp = get_line(irq); char *io = sp->io; struct ch_queue *q = &sp->tty->inq; @@ -441,6 +451,7 @@ static void rs_init(void) register struct tty *tty = ttys + NR_CONSOLES; do { + ttytab[sp->irq] = sp->index; if (!rs_probe(sp)) { switch(sp->irq) { #ifdef CONFIG_FAST_IRQ4 @@ -475,7 +486,7 @@ void rs_conout(dev_t dev, char Ch) } #ifdef CONFIG_BOOTOPTS -/* note: this function may be called prior to serial_init if serial console set*/ +/* note: this function may be called prior to serial_init if serial console set */ void INITPROC rs_setbaud(dev_t dev, unsigned long baud) { register struct serial_info *sp = &ports[MINOR(dev) - RS_MINOR_OFFSET]; From 8d321507d2e46631ab6926d48f8554738cca5e40 Mon Sep 17 00:00:00 2001 From: Helge Skrivervik Date: Mon, 11 Jul 2022 21:07:29 +0200 Subject: [PATCH 2/3] [serial] adjustments --- elks/arch/i86/drivers/char/serial-8250.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/elks/arch/i86/drivers/char/serial-8250.c b/elks/arch/i86/drivers/char/serial-8250.c index 726e9eab2..351b84e8b 100644 --- a/elks/arch/i86/drivers/char/serial-8250.c +++ b/elks/arch/i86/drivers/char/serial-8250.c @@ -64,7 +64,7 @@ static struct serial_info ports[NR_SERIAL] = { {(char *)COM4_PORT, COM4_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 3,0,0}, }; -static char ttytab[16]; +static char irq_to_port[16]; static unsigned int divisors[] = { 0, /* 0 = B0 */ 2304, /* 1 = B50 */ @@ -277,24 +277,14 @@ void fast_com2_irq(void) #if !defined(CONFIG_FAST_IRQ4) || !defined(CONFIG_FAST_IRQ3) -#if 0 -static struct serial_info *get_line(int irq) { - int i; - for (i = 0; i < NR_SERIAL; i++ ) - if (ports[i].irq == irq) - return (&ports[i]); - /* Assuming this cannot possibly fail ... */ - return NULL; -} -#endif + /* * Slower serial interrupt routine, called from _irq_com with passed irq # * Reads all FIFO data available per interrupt and can provide serial stats */ void rs_irq(int irq, struct pt_regs *regs) { - struct serial_info *sp = &ports[(int)ttytab[irq]]; - //struct serial_info *sp = get_line(irq); + struct serial_info *sp = &ports[(int)irq_to_port[irq]]; char *io = sp->io; struct ch_queue *q = &sp->tty->inq; @@ -451,7 +441,7 @@ static void rs_init(void) register struct tty *tty = ttys + NR_CONSOLES; do { - ttytab[sp->irq] = sp->index; + irq_to_port[sp->irq] = sp - ports; /* Map irq to tty # */ if (!rs_probe(sp)) { switch(sp->irq) { #ifdef CONFIG_FAST_IRQ4 From 8e0af879e52c0f89c2107e644aa6754f66f277ed Mon Sep 17 00:00:00 2001 From: Helge Skrivervik Date: Tue, 12 Jul 2022 09:21:27 +0200 Subject: [PATCH 3/3] [serial] More cleanup --- elks/arch/i86/drivers/char/serial-8250.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/elks/arch/i86/drivers/char/serial-8250.c b/elks/arch/i86/drivers/char/serial-8250.c index 351b84e8b..b29b545bc 100644 --- a/elks/arch/i86/drivers/char/serial-8250.c +++ b/elks/arch/i86/drivers/char/serial-8250.c @@ -27,8 +27,7 @@ struct serial_info { unsigned char mcr; unsigned int divisor; struct tty *tty; - int index; - int pad1, pad2; // round out to 16 bytes for faster addressing of ports[] + int pad1, pad2, pad3; // round out to 16 bytes for faster addressing of ports[] }; /* flags*/ @@ -59,9 +58,9 @@ struct serial_info { static struct serial_info ports[NR_SERIAL] = { {(char *)COM1_PORT, COM1_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 0,0,0}, - {(char *)COM2_PORT, COM2_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 1,0,0}, - {(char *)COM3_PORT, COM3_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 2,0,0}, - {(char *)COM4_PORT, COM4_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 3,0,0}, + {(char *)COM2_PORT, COM2_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 0,0,0}, + {(char *)COM3_PORT, COM3_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 0,0,0}, + {(char *)COM4_PORT, COM4_IRQ, 0, DEFAULT_LCR, DEFAULT_MCR, 0, NULL, 0,0,0}, }; static char irq_to_port[16];