shithub: riscv

Download patch

ref: aa0627162b3abdf2a9f8dd68e5b845a8461c75a4
parent: 63f1fc07eb77a5443d693b902dd2b74b56f95057
author: cinap_lenrek <[email protected]>
date: Sun Jan 13 05:23:31 EST 2013

remove non standard COM3 (eia2) serial port from i8250 uart.

access to non standard serial port COM3 at i/o port 0x200 causes
kernel panic on some machines (Toshiba Sattelite 1415-S115). also,
some machines have gameport at 0x200.

i readded uartisa to the pcf and pccpuf kernel configurations so
one can use plan9.ini to add non standard uarts like:

uart2=type=isa port=0x200 irq=5

--- a/sys/src/9/omap/devuart.c
+++ b/sys/src/9/omap/devuart.c
@@ -124,33 +124,6 @@
 	iunlock(&uartalloc);
 }
 
-void
-uartmouse(Uart* p, int (*putc)(Queue*, int), int setb1200)
-{
-	qlock(p);
-	if(p->opens++ == 0 && uartenable(p) == nil){
-		qunlock(p);
-		error(Enodev);
-	}
-	if(setb1200)
-		uartctl(p, "b1200");
-	p->putc = putc;
-	p->special = 1;
-	qunlock(p);
-}
-
-void
-uartsetmouseputc(Uart* p, int (*putc)(Queue*, int))
-{
-	qlock(p);
-	if(p->opens == 0 || p->special == 0){
-		qunlock(p);
-		error(Enodev);
-	}
-	p->putc = putc;
-	qunlock(p);
-}
-
 static void
 setlength(int i)
 {
--- a/sys/src/9/pc/fns.h
+++ b/sys/src/9/pc/fns.h
@@ -50,8 +50,6 @@
 void	i8042reset(void);
 void	i8250console(void);
 void*	i8250alloc(int, int, int);
-void	i8250mouse(char*, int (*)(Queue*, int), int);
-void	i8250setmouseputc(char*, int (*)(Queue*, int));
 void	i8253enable(void);
 void	i8253init(void);
 void	i8253reset(void);
--- a/sys/src/9/pc/mouse.c
+++ b/sys/src/9/pc/mouse.c
@@ -240,7 +240,7 @@
 		i8042auxcmd(0x50);
 		break;
 	case Mouseserial:
-		i8250setmouseputc(mouseport, m5mouseputc);
+		uartsetmouseputc(mouseport, m5mouseputc);
 		break;
 	}
 }
@@ -311,13 +311,13 @@
 
 		if(cb->nf > 2){
 			if(strcmp(cb->f[2], "M") == 0)
-				i8250mouse(cb->f[1], m3mouseputc, 0);
+				uartmouse(cb->f[1], m3mouseputc, 0);
 			else if(strcmp(cb->f[2], "MI") == 0)
-				i8250mouse(cb->f[1], m5mouseputc, 0);
+				uartmouse(cb->f[1], m5mouseputc, 0);
 			else
-				i8250mouse(cb->f[1], mouseputc, cb->nf == 1);
+				uartmouse(cb->f[1], mouseputc, cb->nf == 1);
 		} else
-			i8250mouse(cb->f[1], mouseputc, cb->nf == 1);
+			uartmouse(cb->f[1], mouseputc, cb->nf == 1);
 
 		mousetype = Mouseserial;
 		strncpy(mouseport, cb->f[1], sizeof(mouseport)-1);
--- a/sys/src/9/pc/pccpuf
+++ b/sys/src/9/pc/pccpuf
@@ -84,6 +84,7 @@
 	mtrr
 
 	uarti8250
+	uartisa
 	uartpci		pci
 
 	sdaoe
--- a/sys/src/9/pc/pcf
+++ b/sys/src/9/pc/pcf
@@ -95,6 +95,7 @@
 	sdloop
 
 	uarti8250
+	uartisa
 	uartpci		pci
 
 	vga3dfx		+cur
--- a/sys/src/9/pc/uarti8250.c
+++ b/sys/src/9/pc/uarti8250.c
@@ -14,8 +14,6 @@
 	Uart0IRQ	= 4,
 	Uart1		= 0x2F8,	/* COM2 */
 	Uart1IRQ	= 3,
-	Uart2		= 0x200, /* COM3 */
-	Uart2IRQ	= 5,
 
 	UartFREQ	= 1843200,
 };
@@ -123,7 +121,7 @@
 
 extern PhysUart i8250physuart;
 
-static Ctlr i8250ctlr[3] = {
+static Ctlr i8250ctlr[2] = {
 {	.io	= Uart0,
 	.irq	= Uart0IRQ,
 	.tbdf	= BUSUNKNOWN, },
@@ -131,13 +129,9 @@
 {	.io	= Uart1,
 	.irq	= Uart1IRQ,
 	.tbdf	= BUSUNKNOWN, },
-
-{	.io	= Uart2,
-	.irq	= Uart2IRQ,
-	.tbdf	= BUSUNKNOWN, },
 };
 
-static Uart i8250uart[3] = {
+static Uart i8250uart[2] = {
 {	.regs	= &i8250ctlr[0],
 	.name	= "COM1",
 	.freq	= UartFREQ,
@@ -150,13 +144,6 @@
 	.freq	= UartFREQ,
 	.phys	= &i8250physuart,
 	.special= 0,
-	.next	= &i8250uart[2], },
-
-{	.regs	= &i8250ctlr[2],
-	.name	= "COM3",
-	.freq	= UartFREQ,
-	.phys	= &i8250physuart,
-	.special= 0,
 	.next	= nil, },
 };
 
@@ -704,21 +691,9 @@
 	if((p = getconf("console")) == nil)
 		return;
 	n = strtoul(p, &cmd, 0);
-	if(p == cmd)
+	if(p == cmd || n < 0 || n >= nelem(i8250uart))
 		return;
-	switch(n){
-	default:
-		return;
-	case 0:
-		uart = &i8250uart[0];
-		break;
-	case 1:
-		uart = &i8250uart[1];
-		break;
-	case 2:
-		uart = &i8250uart[2];
-		break;
-	}
+	uart = &i8250uart[n];
 
 	(*uart->phys->enable)(uart, 0);
 	uartctl(uart, "b9600 l8 pn s1");
@@ -727,29 +702,4 @@
 
 	consuart = uart;
 	uart->console = 1;
-}
-
-void
-i8250mouse(char* which, int (*putc)(Queue*, int), int setb1200)
-{
-	char *p;
-	int port;
-
-	port = strtol(which, &p, 0);
-	if(p == which || port < 0 || port > 1)
-		error(Ebadarg);
-	uartmouse(&i8250uart[port], putc, setb1200);
-}
-
-void
-i8250setmouseputc(char* which, int (*putc)(Queue*, int))
-{
-	char *p;
-	int port;
-
-	port = strtol(which, &p, 0);
-	if(p == which || port < 0 || port > 1)
-		error(Ebadarg);
-	uartsetmouseputc(&i8250uart[port], putc);
-
 }
--- a/sys/src/9/port/devuart.c
+++ b/sys/src/9/port/devuart.c
@@ -121,9 +121,26 @@
 	iunlock(&uartalloc);
 }
 
+static Uart*
+uartport(char *which)
+{
+	int port;
+	char *p;
+
+	port = strtol(which, &p, 0);
+	if(p == which)
+		error(Ebadarg);
+	if(port < 0 || port >= uartnuart || uart[port] == nil)
+		error(Enodev);
+	return uart[port];
+}
+
 void
-uartmouse(Uart* p, int (*putc)(Queue*, int), int setb1200)
+uartmouse(char *which, int (*putc)(Queue*, int), int setb1200)
 {
+	Uart *p;
+
+	p = uartport(which);
 	qlock(p);
 	if(p->opens++ == 0 && uartenable(p) == nil){
 		qunlock(p);
@@ -137,8 +154,11 @@
 }
 
 void
-uartsetmouseputc(Uart* p, int (*putc)(Queue*, int))
+uartsetmouseputc(char *which, int (*putc)(Queue*, int))
 {
+	Uart *p;
+
+	p = uartport(which);
 	qlock(p);
 	if(p->opens == 0 || p->special == 0){
 		qunlock(p);
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -345,8 +345,8 @@
 int		uartctl(Uart*, char*);
 int		uartgetc(void);
 void		uartkick(void*);
-void		uartmouse(Uart*, int (*)(Queue*, int), int);
-void		uartsetmouseputc(Uart*, int (*)(Queue*, int));
+void		uartmouse(char*, int (*)(Queue*, int), int);
+void		uartsetmouseputc(char*, int (*)(Queue*, int));
 void		uartputc(int);
 void		uartputs(char*, int);
 void		uartrecv(Uart*, char);