Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Get rid of all PCI_CONF_MODE #ifdef'age except for ...



details:   https://anonhg.NetBSD.org/src/rev/989e57bede8c
branches:  trunk
changeset: 752119:989e57bede8c
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Tue Feb 16 00:03:47 2010 +0000

description:
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.

diffstat:

 sys/arch/i386/pci/pcibios.c        |    6 +-
 sys/arch/x86/include/pci_machdep.h |    4 +-
 sys/arch/x86/pci/pci_machdep.c     |  195 +++++++++++++-----------------------
 3 files changed, 75 insertions(+), 130 deletions(-)

diffs (truncated from 327 to 300 lines):

diff -r 9147bd5c7992 -r 989e57bede8c sys/arch/i386/pci/pcibios.c
--- a/sys/arch/i386/pci/pcibios.c       Mon Feb 15 23:55:24 2010 +0000
+++ b/sys/arch/i386/pci/pcibios.c       Tue Feb 16 00:03:47 2010 +0000
@@ -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;
 
diff -r 9147bd5c7992 -r 989e57bede8c sys/arch/x86/include/pci_machdep.h
--- a/sys/arch/x86/include/pci_machdep.h        Mon Feb 15 23:55:24 2010 +0000
+++ b/sys/arch/x86/include/pci_machdep.h        Tue Feb 16 00:03:47 2010 +0000
@@ -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;
diff -r 9147bd5c7992 -r 989e57bede8c sys/arch/x86/pci/pci_machdep.c
--- a/sys/arch/x86/pci/pci_machdep.c    Mon Feb 15 23:55:24 2010 +0000
+++ b/sys/arch/x86/pci/pci_machdep.c    Tue Feb 16 00:03:47 2010 +0000
@@ -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);



Home | Main Index | Thread Index | Old Index