Module Name:    src
Committed By:   dyoung
Date:           Tue Feb 16 00:03:48 UTC 2010

Modified Files:
        src/sys/arch/i386/pci: pcibios.c
        src/sys/arch/x86/include: pci_machdep.h
        src/sys/arch/x86/pci: pci_machdep.c

Log Message:
Get rid of all PCI_CONF_MODE #ifdef'age except for the little bit
that initializes pci_mode, which I have moved to the top.

Make pci_mode private to pci_machdep.c.

Provide pci_mode_set() for pcibios.c to configure the PCI Configuration
Mechanism.  KASSERT() in pci_mode_set() that the mechanism is not
changing from anything but the "don't know" value, -1.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/i386/pci/pcibios.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/include/pci_machdep.h
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/x86/pci/pci_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/i386/pci/pcibios.c
diff -u src/sys/arch/i386/pci/pcibios.c:1.36 src/sys/arch/i386/pci/pcibios.c:1.37
--- src/sys/arch/i386/pci/pcibios.c:1.36	Mon Apr 28 20:23:25 2008
+++ src/sys/arch/i386/pci/pcibios.c	Tue Feb 16 00:03:47 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcibios.c,v 1.36 2008/04/28 20:23:25 martin Exp $	*/
+/*	$NetBSD: pcibios.c,v 1.37 2010/02/16 00:03:47 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcibios.c,v 1.36 2008/04/28 20:23:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcibios.c,v 1.37 2010/02/16 00:03:47 dyoung Exp $");
 
 #include "opt_pcibios.h"
 #include "opt_pcifixup.h"
@@ -180,7 +180,7 @@
 	 * The PCI BIOS tells us the config mechanism; fill it in now
 	 * so that pci_mode_detect() doesn't have to look for it.
 	 */
-	pci_mode = mech1 ? 1 : 2;
+	pci_mode_set(mech1 ? 1 : 2);
 
 	pcibios_present = 1;
 

Index: src/sys/arch/x86/include/pci_machdep.h
diff -u src/sys/arch/x86/include/pci_machdep.h:1.8 src/sys/arch/x86/include/pci_machdep.h:1.9
--- src/sys/arch/x86/include/pci_machdep.h:1.8	Fri May 30 09:49:07 2008
+++ src/sys/arch/x86/include/pci_machdep.h	Tue Feb 16 00:03:47 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_machdep.h,v 1.8 2008/05/30 09:49:07 joerg Exp $	*/
+/*	$NetBSD: pci_machdep.h,v 1.9 2010/02/16 00:03:47 dyoung Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -82,7 +82,7 @@
  * i386-specific PCI variables and functions.
  * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
  */
-extern int pci_mode;
+void		pci_mode_set(int);
 int		pci_mode_detect(void);
 int		pci_bus_flags(void);
 struct		pci_attach_args;

Index: src/sys/arch/x86/pci/pci_machdep.c
diff -u src/sys/arch/x86/pci/pci_machdep.c:1.37 src/sys/arch/x86/pci/pci_machdep.c:1.38
--- src/sys/arch/x86/pci/pci_machdep.c:1.37	Tue Aug 18 16:41:03 2009
+++ src/sys/arch/x86/pci/pci_machdep.c	Tue Feb 16 00:03:47 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_machdep.c,v 1.37 2009/08/18 16:41:03 jmcneill Exp $	*/
+/*	$NetBSD: pci_machdep.c,v 1.38 2010/02/16 00:03:47 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.37 2009/08/18 16:41:03 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.38 2010/02/16 00:03:47 dyoung Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -119,7 +119,15 @@
 #endif
 #endif
 
-int pci_mode = -1;
+#ifdef PCI_CONF_MODE
+#if (PCI_CONF_MODE == 1) || (PCI_CONF_MODE == 2)
+static int pci_mode = PCI_CONF_MODE;
+#else
+#error Invalid PCI configuration mode.
+#endif
+#else
+static int pci_mode = -1;
+#endif
 
 static void pci_bridge_hook(pci_chipset_tag_t, pcitag_t, void *);
 struct pci_bridge_hook_arg {
@@ -284,41 +292,25 @@
 {
 	pcitag_t tag;
 
-#ifndef PCI_CONF_MODE
 	switch (pci_mode) {
 	case 1:
-		goto mode1;
+		if (bus >= 256 || device >= 32 || function >= 8)
+			panic("pci_make_tag: bad request");
+
+		tag.mode1 = PCI_MODE1_ENABLE |
+			    (bus << 16) | (device << 11) | (function << 8);
+		return tag;
 	case 2:
-		goto mode2;
+		if (bus >= 256 || device >= 16 || function >= 8)
+			panic("pci_make_tag: bad request");
+
+		tag.mode2.port = 0xc000 | (device << 8);
+		tag.mode2.enable = 0xf0 | (function << 1);
+		tag.mode2.forward = bus;
+		return tag;
 	default:
 		panic("pci_make_tag: mode not configured");
 	}
-#endif
-
-#if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 1)
-#ifndef PCI_CONF_MODE
-mode1:
-#endif
-	if (bus >= 256 || device >= 32 || function >= 8)
-		panic("pci_make_tag: bad request");
-
-	tag.mode1 = PCI_MODE1_ENABLE |
-		    (bus << 16) | (device << 11) | (function << 8);
-	return tag;
-#endif
-
-#if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 2)
-#ifndef PCI_CONF_MODE
-mode2:
-#endif
-	if (bus >= 256 || device >= 16 || function >= 8)
-		panic("pci_make_tag: bad request");
-
-	tag.mode2.port = 0xc000 | (device << 8);
-	tag.mode2.enable = 0xf0 | (function << 1);
-	tag.mode2.forward = bus;
-	return tag;
-#endif
 }
 
 void
@@ -326,41 +318,26 @@
     int *bp, int *dp, int *fp)
 {
 
-#ifndef PCI_CONF_MODE
 	switch (pci_mode) {
 	case 1:
-		goto mode1;
+		if (bp != NULL)
+			*bp = (tag.mode1 >> 16) & 0xff;
+		if (dp != NULL)
+			*dp = (tag.mode1 >> 11) & 0x1f;
+		if (fp != NULL)
+			*fp = (tag.mode1 >> 8) & 0x7;
+		return;
 	case 2:
-		goto mode2;
+		if (bp != NULL)
+			*bp = tag.mode2.forward & 0xff;
+		if (dp != NULL)
+			*dp = (tag.mode2.port >> 8) & 0xf;
+		if (fp != NULL)
+			*fp = (tag.mode2.enable >> 1) & 0x7;
+		return;
 	default:
 		panic("pci_decompose_tag: mode not configured");
 	}
-#endif
-
-#if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 1)
-#ifndef PCI_CONF_MODE
-mode1:
-#endif
-	if (bp != NULL)
-		*bp = (tag.mode1 >> 16) & 0xff;
-	if (dp != NULL)
-		*dp = (tag.mode1 >> 11) & 0x1f;
-	if (fp != NULL)
-		*fp = (tag.mode1 >> 8) & 0x7;
-	return;
-#endif
-
-#if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 2)
-#ifndef PCI_CONF_MODE
-mode2:
-#endif
-	if (bp != NULL)
-		*bp = tag.mode2.forward & 0xff;
-	if (dp != NULL)
-		*dp = (tag.mode2.port >> 8) & 0xf;
-	if (fp != NULL)
-		*fp = (tag.mode2.enable >> 1) & 0x7;
-#endif
 }
 
 pcireg_t
@@ -380,41 +357,25 @@
 	}
 #endif
 
-#ifndef PCI_CONF_MODE
 	switch (pci_mode) {
 	case 1:
-		goto mode1;
+		PCI_CONF_LOCK(s);
+		outl(PCI_MODE1_ADDRESS_REG, tag.mode1 | reg);
+		data = inl(PCI_MODE1_DATA_REG);
+		outl(PCI_MODE1_ADDRESS_REG, 0);
+		PCI_CONF_UNLOCK(s);
+		return data;
 	case 2:
-		goto mode2;
+		PCI_CONF_LOCK(s);
+		outb(PCI_MODE2_ENABLE_REG, tag.mode2.enable);
+		outb(PCI_MODE2_FORWARD_REG, tag.mode2.forward);
+		data = inl(tag.mode2.port | reg);
+		outb(PCI_MODE2_ENABLE_REG, 0);
+		PCI_CONF_UNLOCK(s);
+		return data;
 	default:
 		panic("pci_conf_read: mode not configured");
 	}
-#endif
-
-#if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 1)
-#ifndef PCI_CONF_MODE
-mode1:
-#endif
-	PCI_CONF_LOCK(s);
-	outl(PCI_MODE1_ADDRESS_REG, tag.mode1 | reg);
-	data = inl(PCI_MODE1_DATA_REG);
-	outl(PCI_MODE1_ADDRESS_REG, 0);
-	PCI_CONF_UNLOCK(s);
-	return data;
-#endif
-
-#if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 2)
-#ifndef PCI_CONF_MODE
-mode2:
-#endif
-	PCI_CONF_LOCK(s);
-	outb(PCI_MODE2_ENABLE_REG, tag.mode2.enable);
-	outb(PCI_MODE2_FORWARD_REG, tag.mode2.forward);
-	data = inl(tag.mode2.port | reg);
-	outb(PCI_MODE2_ENABLE_REG, 0);
-	PCI_CONF_UNLOCK(s);
-	return data;
-#endif
 }
 
 void
@@ -433,53 +394,38 @@
 	}
 #endif
 
-#ifndef PCI_CONF_MODE
 	switch (pci_mode) {
 	case 1:
-		goto mode1;
+		PCI_CONF_LOCK(s);
+		outl(PCI_MODE1_ADDRESS_REG, tag.mode1 | reg);
+		outl(PCI_MODE1_DATA_REG, data);
+		outl(PCI_MODE1_ADDRESS_REG, 0);
+		PCI_CONF_UNLOCK(s);
+		return;
 	case 2:
-		goto mode2;
+		PCI_CONF_LOCK(s);
+		outb(PCI_MODE2_ENABLE_REG, tag.mode2.enable);
+		outb(PCI_MODE2_FORWARD_REG, tag.mode2.forward);
+		outl(tag.mode2.port | reg, data);
+		outb(PCI_MODE2_ENABLE_REG, 0);
+		PCI_CONF_UNLOCK(s);
+		return;
 	default:
 		panic("pci_conf_write: mode not configured");
 	}
-#endif
+}
 
-#if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 1)
-#ifndef PCI_CONF_MODE
-mode1:
-#endif
-	PCI_CONF_LOCK(s);
-	outl(PCI_MODE1_ADDRESS_REG, tag.mode1 | reg);
-	outl(PCI_MODE1_DATA_REG, data);
-	outl(PCI_MODE1_ADDRESS_REG, 0);
-	PCI_CONF_UNLOCK(s);
-	return;
-#endif
+void
+pci_mode_set(int mode)
+{
+	KASSERT(pci_mode == -1 || pci_mode == mode);
 
-#if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 2)
-#ifndef PCI_CONF_MODE
-mode2:
-#endif
-	PCI_CONF_LOCK(s);
-	outb(PCI_MODE2_ENABLE_REG, tag.mode2.enable);
-	outb(PCI_MODE2_FORWARD_REG, tag.mode2.forward);
-	outl(tag.mode2.port | reg, data);
-	outb(PCI_MODE2_ENABLE_REG, 0);
-	PCI_CONF_UNLOCK(s);
-#endif
+	pci_mode = mode;
 }
 
 int
 pci_mode_detect(void)
 {
-
-#ifdef PCI_CONF_MODE
-#if (PCI_CONF_MODE == 1) || (PCI_CONF_MODE == 2)
-	return (pci_mode = PCI_CONF_MODE);
-#else
-#error Invalid PCI configuration mode.
-#endif
-#else
 	uint32_t sav, val;
 	int i;
 	pcireg_t idreg;
@@ -553,7 +499,6 @@
 not2:
 
 	return (pci_mode = 0);
-#endif
 }
 
 /*

Reply via email to