Subject: port-i386/3253: isapnp_map_readport should check for resource conflicts
To: None <gnats-bugs@gnats.netbsd.org>
From: Christoph Badura <bad@klicman.de>
List: netbsd-bugs
Date: 02/24/1997 22:49:48
>Number:         3253
>Category:       port-i386
>Synopsis:       isapnp_map_readport should check if other devices have
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 24 14:05:00 1997
>Last-Modified:
>Originator:     Christoph Badura
>Organization:
	
>Release:        1997-02-22
>Environment:
	
486 Saturn PCI board and a Gigabyte GA586HX (430HX) with NE2000 at 0x300.

System: NetBSD klic3.klicman.de 1.2C NetBSD 1.2C (KLIC) #28: Sat Feb 22 20:14:50 MET 1997 bad@klic3.klicman.de:/usr/src/sys/arch/i386/compile/KLIC i386

>Description:
	
With the addition of the isapnp code kernels with isapnp have been locking
up solid in two test machines.  One has PNP support the other doesn't.
Both machines have no PNP cards installed.  Both have a NE2000 at 0x300.
When locking up the machines would respond only to a hard reset.

I traced it down to isapnp_findcard setting the READ_PORT to 0x313 and 0x317.
Both addresses are claimed by the ed driver in my machines.

Since making the trivial changes to isapnp_map_readport to check if other
devices have claimed the to-be-mapped address already both machines boot
reliably again.

>How-To-Repeat:
	

Put a non-PNP NE2000 configured at io port 0x300 in a board with no PNP-Cards.
Try booting a GENERIC kernel.

>Fix:
	
Patch sys/arch/i386/isa/isapnp_machdep.c as follows.

Index: isapnp_machdep.c
===================================================================
RCS file: /u2/src.master/netbsd/src/sys/arch/i386/isa/isapnp_machdep.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 isapnp_machdep.c
--- isapnp_machdep.c	1997/02/06 19:21:31	1.1.1.1
+++ isapnp_machdep.c	1997/02/24 21:16:45
@@ -94,11 +94,17 @@
 isapnp_map_readport(sc)
 	struct isapnp_softc *sc;
 {
+	int error;
 
 	if (sc->sc_iot != I386_BUS_SPACE_IO)
 		panic("isapnp_map_readport: bogus bus space tag");
 
-	sc->sc_read_ioh = sc->sc_read_port;
+	/* Check if some other device has already claimed this port. */
+	if ((error = bus_space_map(sc->sc_iot,
+				  sc->sc_read_port,
+				  1, 0,
+				  &sc->sc_read_ioh)))
+		return (error);
 	return (0);
 }
 
@@ -110,5 +116,5 @@
 	struct isapnp_softc *sc;
 {
 
-	/* Do nothing. */
+	bus_space_unmap(sc->sc_iot, sc->sc_read_ioh, 1);
 }
>Audit-Trail:
>Unformatted:
already claimed the READ_PORT.