Module Name: src
Committed By: dyoung
Date: Fri Apr 17 21:07:59 UTC 2009
Modified Files:
src/sys/arch/amd64/amd64: mainbus.c
src/sys/arch/i386/i386: mainbus.c
src/sys/arch/x86/conf: files.x86
src/sys/arch/x86/include: mpacpi.h mpbiosvar.h mpconfig.h
src/sys/arch/x86/x86: mpacpi.c mpbios.c
Added Files:
src/sys/arch/x86/x86: mp.c
Log Message:
Introduce sys/arch/x86/x86/mp.c for common x86 MP configuration code.
mpacpi_scan_pci() and mpbios_scan_pci() are identical code, so replace
them with mp_pci_scan().
Introduce mp_pci_childdetached(), which helps us to detach root PCI
buses that were enumerated either by MP BIOS or by ACPI.
Let us detach and re-attach PCI buses from mainbus0 on i386. This is
necessarily a work-in-progress, because testing detach and re-attach
is very difficult: to detach and re-attach the entire PCI tree on most
x86 computers that I own is not possible because some essential device
attaches under the PCI subtree: the console, com0, NIC, or storage
controller always attaches in the PCI tree.
To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/amd64/amd64/mainbus.c
cvs rdiff -u -r1.83 -r1.84 src/sys/arch/i386/i386/mainbus.c
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/include/mpacpi.h
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x86/include/mpbiosvar.h
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/x86/include/mpconfig.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/x86/x86/mp.c
cvs rdiff -u -r1.75 -r1.76 src/sys/arch/x86/x86/mpacpi.c
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/x86/x86/mpbios.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/amd64/amd64/mainbus.c
diff -u src/sys/arch/amd64/amd64/mainbus.c:1.26 src/sys/arch/amd64/amd64/mainbus.c:1.27
--- src/sys/arch/amd64/amd64/mainbus.c:1.26 Mon Nov 10 14:36:59 2008
+++ src/sys/arch/amd64/amd64/mainbus.c Fri Apr 17 21:07:58 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.26 2008/11/10 14:36:59 cegger Exp $ */
+/* $NetBSD: mainbus.c,v 1.27 2009/04/17 21:07:58 dyoung Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.26 2008/11/10 14:36:59 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.27 2009/04/17 21:07:58 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -263,12 +263,12 @@
mba.mba_pba.pba_bridgetag = NULL;
#if NACPI > 0 && defined(ACPI_SCANPCI)
if (mpacpi_active)
- mpacpi_scan_pci(self, &mba.mba_pba, pcibusprint);
+ mp_pci_scan(self, &mba.mba_pba, pcibusprint);
else
#endif
#if defined(MPBIOS) && defined(MPBIOS_SCANPCI)
if (mpbios_scanned != 0)
- mpbios_scan_pci(self, &mba.mba_pba, pcibusprint);
+ mp_pci_scan(self, &mba.mba_pba, pcibusprint);
else
#endif
config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint);
Index: src/sys/arch/i386/i386/mainbus.c
diff -u src/sys/arch/i386/i386/mainbus.c:1.83 src/sys/arch/i386/i386/mainbus.c:1.84
--- src/sys/arch/i386/i386/mainbus.c:1.83 Wed Apr 8 17:08:02 2009
+++ src/sys/arch/i386/i386/mainbus.c Fri Apr 17 21:07:58 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.83 2009/04/08 17:08:02 dyoung Exp $ */
+/* $NetBSD: mainbus.c,v 1.84 2009/04/17 21:07:58 dyoung Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.83 2009/04/08 17:08:02 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.84 2009/04/17 21:07:58 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -104,9 +104,11 @@
device_t sc_acpi;
device_t sc_dev;
device_t sc_ipmi;
+ device_t sc_pci;
device_t sc_mca;
device_t sc_pnpbios;
bool sc_acpi_present;
+ bool sc_mpacpi_active;
};
CFATTACH_DECL2_NEW(mainbus, sizeof(struct mainbus_softc),
@@ -185,6 +187,10 @@
sc->sc_mca = NULL;
if (sc->sc_pnpbios == child)
sc->sc_pnpbios = NULL;
+ if (sc->sc_pci == child)
+ sc->sc_pci = NULL;
+
+ mp_pci_childdetached(self, child);
}
/*
@@ -211,7 +217,6 @@
#if defined(PCI_BUS_FIXUP)
int pci_maxbus = 0;
#endif
- int mpacpi_active = 0;
int numcpus = 0;
sc->sc_dev = self;
@@ -251,10 +256,10 @@
* be done later (via a callback).
*/
if (sc->sc_acpi_present)
- mpacpi_active = mpacpi_scan_apics(self, &numcpus);
+ sc->sc_mpacpi_active = mpacpi_scan_apics(self, &numcpus) != 0;
#endif
- if (!mpacpi_active) {
+ if (!sc->sc_mpacpi_active) {
#ifdef MPBIOS
if (mpbios_present)
mpbios_scan(self, &numcpus);
@@ -286,39 +291,7 @@
mainbus_rescan(self, "ipmibus", NULL);
- /*
- * XXX Note also that the presence of a PCI bus should
- * XXX _always_ be checked, and if present the bus should be
- * XXX 'found'. However, because of the structure of the code,
- * XXX that's not currently possible.
- */
-#if NPCI > 0
- if (pci_mode != 0) {
- mba.mba_pba.pba_iot = X86_BUS_SPACE_IO;
- mba.mba_pba.pba_memt = X86_BUS_SPACE_MEM;
- mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
- mba.mba_pba.pba_dmat64 = NULL;
- mba.mba_pba.pba_pc = NULL;
- mba.mba_pba.pba_flags = pci_bus_flags();
- mba.mba_pba.pba_bus = 0;
- mba.mba_pba.pba_bridgetag = NULL;
-#if NACPI > 0 && defined(ACPI_SCANPCI)
- if (mpacpi_active)
- mpacpi_scan_pci(self, &mba.mba_pba, pcibusprint);
- else
-#endif
-#if defined(MPBIOS) && defined(MPBIOS_SCANPCI)
- if (mpbios_scanned != 0)
- mpbios_scan_pci(self, &mba.mba_pba, pcibusprint);
- else
-#endif
- config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint);
-#if NACPI > 0
- if (mp_verbose)
- acpi_pci_link_state();
-#endif
- }
-#endif
+ mainbus_rescan(self, "pcibus", NULL);
mainbus_rescan(self, "mcabus", NULL);
@@ -361,7 +334,7 @@
mainbus_rescan(device_t self, const char *ifattr, const int *locators)
{
struct mainbus_softc *sc = device_private(self);
-#if NPNPBIOS > 0 || NACPI > 0 || NIPMI > 0 || NMCA > 0
+#if NACPI > 0 || NIPMI > 0 || NMCA > 0 || NPCI > 0 || NPNPBIOS > 0
union mainbus_attach_args mba;
#endif
@@ -415,6 +388,44 @@
#endif
}
+ /*
+ * XXX Note also that the presence of a PCI bus should
+ * XXX _always_ be checked, and if present the bus should be
+ * XXX 'found'. However, because of the structure of the code,
+ * XXX that's not currently possible.
+ */
+#if NPCI > 0
+ if (pci_mode != 0 && ifattr_match(ifattr, "pcibus")) {
+ mba.mba_pba.pba_iot = X86_BUS_SPACE_IO;
+ mba.mba_pba.pba_memt = X86_BUS_SPACE_MEM;
+ mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
+ mba.mba_pba.pba_dmat64 = NULL;
+ mba.mba_pba.pba_pc = NULL;
+ mba.mba_pba.pba_flags = pci_bus_flags();
+ mba.mba_pba.pba_bus = 0;
+ mba.mba_pba.pba_bridgetag = NULL;
+#if NACPI > 0 && defined(ACPI_SCANPCI)
+ if (sc->sc_mpacpi_active)
+ mp_pci_scan(self, &mba.mba_pba, pcibusprint);
+ else
+#endif
+#if defined(MPBIOS) && defined(MPBIOS_SCANPCI)
+ if (mpbios_scanned != 0)
+ mp_pci_scan(self, &mba.mba_pba, pcibusprint);
+ else
+#endif
+ if (sc->sc_pci == NULL) {
+ sc->sc_pci = config_found_ia(self, "pcibus",
+ &mba.mba_pba, pcibusprint);
+ }
+#if NACPI > 0
+ if (mp_verbose)
+ acpi_pci_link_state();
+#endif
+ }
+#endif
+
+
if (ifattr_match(ifattr, "mcabus") && sc->sc_mca == NULL) {
#if NMCA > 0
/* Note: MCA bus probe is done in i386/machdep.c */
Index: src/sys/arch/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.50 src/sys/arch/x86/conf/files.x86:1.51
--- src/sys/arch/x86/conf/files.x86:1.50 Thu Apr 16 15:34:23 2009
+++ src/sys/arch/x86/conf/files.x86 Fri Apr 17 21:07:58 2009
@@ -1,4 +1,4 @@
-# $NetBSD: files.x86,v 1.50 2009/04/16 15:34:23 rmind Exp $
+# $NetBSD: files.x86,v 1.51 2009/04/17 21:07:58 dyoung Exp $
# options for MP configuration through the MP spec
defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI
@@ -78,6 +78,9 @@
# MP configuration using Intel SMP specification 1.4
file arch/x86/x86/mpbios.c mpbios
+# MP configuration using either ACPI or Intel SMP specification 1.4
+file arch/x86/x86/mp.c acpi | mpbios
+
# MP configuration using ACPI
file arch/x86/x86/mpacpi.c acpi
Index: src/sys/arch/x86/include/mpacpi.h
diff -u src/sys/arch/x86/include/mpacpi.h:1.8 src/sys/arch/x86/include/mpacpi.h:1.9
--- src/sys/arch/x86/include/mpacpi.h:1.8 Sun Nov 9 15:34:14 2008
+++ src/sys/arch/x86/include/mpacpi.h Fri Apr 17 21:07:58 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: mpacpi.h,v 1.8 2008/11/09 15:34:14 cegger Exp $ */
+/* $NetBSD: mpacpi.h,v 1.9 2009/04/17 21:07:58 dyoung Exp $ */
#ifndef _X86_MPACPI_H_
#define _X86_MPACPI_H_
@@ -9,7 +9,6 @@
int mpacpi_find_interrupts(void *);
int mpacpi_pci_attach_hook(device_t, device_t,
struct pcibus_attach_args *);
-int mpacpi_scan_pci(device_t, struct pcibus_attach_args *, cfprint_t);
struct mp_intr_map;
int mpacpi_findintr_linkdev(struct mp_intr_map *);
Index: src/sys/arch/x86/include/mpbiosvar.h
diff -u src/sys/arch/x86/include/mpbiosvar.h:1.7 src/sys/arch/x86/include/mpbiosvar.h:1.8
--- src/sys/arch/x86/include/mpbiosvar.h:1.7 Sun Nov 9 15:34:14 2008
+++ src/sys/arch/x86/include/mpbiosvar.h Fri Apr 17 21:07:58 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: mpbiosvar.h,v 1.7 2008/11/09 15:34:14 cegger Exp $ */
+/* $NetBSD: mpbiosvar.h,v 1.8 2009/04/17 21:07:58 dyoung Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -49,8 +49,6 @@
int mpbios_probe(device_t);
int mpbios_pci_attach_hook(device_t, device_t,
struct pcibus_attach_args *);
-int mpbios_scan_pci(device_t, struct pcibus_attach_args *, cfprint_t);
-
extern int mpbios_scanned;
#endif
Index: src/sys/arch/x86/include/mpconfig.h
diff -u src/sys/arch/x86/include/mpconfig.h:1.10 src/sys/arch/x86/include/mpconfig.h:1.11
--- src/sys/arch/x86/include/mpconfig.h:1.10 Wed Apr 16 16:06:51 2008
+++ src/sys/arch/x86/include/mpconfig.h Fri Apr 17 21:07:58 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: mpconfig.h,v 1.10 2008/04/16 16:06:51 cegger Exp $ */
+/* $NetBSD: mpconfig.h,v 1.11 2009/04/17 21:07:58 dyoung Exp $ */
/*
* Definitions originally from the mpbios code, but now used for ACPI
@@ -43,7 +43,7 @@
void (*mb_intr_cfg)(const struct mpbios_int *, uint32_t *);
struct mp_intr_map *mb_intrs;
uint32_t mb_data; /* random bus-specific datum. */
- int mb_configured; /* has been autoconfigured */
+ device_t mb_dev; /* has been autoconfigured if mb_dev != NULL */
pcitag_t *mb_pci_bridge_tag;
pci_chipset_tag_t mb_pci_chipset_tag;
};
@@ -75,6 +75,8 @@
extern int mp_nintr;
extern int mp_isa_bus, mp_eisa_bus;
extern int mp_nbus;
+int mp_pci_scan(device_t, struct pcibus_attach_args *, cfprint_t);
+void mp_pci_childdetached(device_t, device_t);
#endif
#endif
Index: src/sys/arch/x86/x86/mpacpi.c
diff -u src/sys/arch/x86/x86/mpacpi.c:1.75 src/sys/arch/x86/x86/mpacpi.c:1.76
--- src/sys/arch/x86/x86/mpacpi.c:1.75 Wed Jan 14 19:31:25 2009
+++ src/sys/arch/x86/x86/mpacpi.c Fri Apr 17 21:07:58 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: mpacpi.c,v 1.75 2009/01/14 19:31:25 cegger Exp $ */
+/* $NetBSD: mpacpi.c,v 1.76 2009/04/17 21:07:58 dyoung Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpacpi.c,v 1.75 2009/01/14 19:31:25 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpacpi.c,v 1.76 2009/04/17 21:07:58 dyoung Exp $");
#include "acpi.h"
#include "opt_acpi.h"
@@ -1142,7 +1142,7 @@
*/
mpb->mb_name = "pci";
- mpb->mb_configured = 1;
+ mpb->mb_dev = self;
mpb->mb_pci_bridge_tag = pba->pba_bridgetag;
mpb->mb_pci_chipset_tag = pba->pba_pc;
@@ -1156,27 +1156,6 @@
return 0;
}
-
-int
-mpacpi_scan_pci(device_t self, struct pcibus_attach_args *pba,
- cfprint_t print)
-{
- int i;
- struct mp_bus *mpb;
- struct pci_attach_args;
-
- for (i = 0; i < mp_nbus; i++) {
- mpb = &mp_busses[i];
- if (mpb->mb_name == NULL)
- continue;
- if (!strcmp(mpb->mb_name, "pci") && mpb->mb_configured == 0) {
- pba->pba_bus = i;
- config_found_ia(self, "pcibus", pba, print);
- }
- }
- return 0;
-}
-
#endif
int
Index: src/sys/arch/x86/x86/mpbios.c
diff -u src/sys/arch/x86/x86/mpbios.c:1.53 src/sys/arch/x86/x86/mpbios.c:1.54
--- src/sys/arch/x86/x86/mpbios.c:1.53 Fri Feb 13 20:51:19 2009
+++ src/sys/arch/x86/x86/mpbios.c Fri Apr 17 21:07:59 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: mpbios.c,v 1.53 2009/02/13 20:51:19 bouyer Exp $ */
+/* $NetBSD: mpbios.c,v 1.54 2009/04/17 21:07:59 dyoung Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpbios.c,v 1.53 2009/02/13 20:51:19 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpbios.c,v 1.54 2009/04/17 21:07:59 dyoung Exp $");
#include "acpi.h"
#include "lapic.h"
@@ -1194,30 +1194,10 @@
printf("\n%s: added to list as bus %d", device_xname(parent),
pba->pba_bus);
- mpb->mb_configured = 1;
+ mpb->mb_dev = self;
mpb->mb_pci_bridge_tag = pba->pba_bridgetag;
mpb->mb_pci_chipset_tag = pba->pba_pc;
return 0;
}
-int
-mpbios_scan_pci(device_t self, struct pcibus_attach_args *pba,
- cfprint_t print)
-{
- int i;
- struct mp_bus *mpb;
- struct pci_attach_args;
-
- for (i = 0; i < mp_nbus; i++) {
- mpb = &mp_busses[i];
- if (mpb->mb_name == NULL)
- continue;
- if (!strcmp(mpb->mb_name, "pci") && mpb->mb_configured == 0) {
- pba->pba_bus = i;
- config_found_ia(self, "pcibus", pba, print);
- }
- }
- return 0;
-}
-
#endif
Added files:
Index: src/sys/arch/x86/x86/mp.c
diff -u /dev/null src/sys/arch/x86/x86/mp.c:1.1
--- /dev/null Fri Apr 17 21:07:59 2009
+++ src/sys/arch/x86/x86/mp.c Fri Apr 17 21:07:58 2009
@@ -0,0 +1,97 @@
+/* $NetBSD: mp.c,v 1.1 2009/04/17 21:07:58 dyoung Exp $ */
+
+/*
+ * Copyright (c) 2003 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: mp.c,v 1.1 2009/04/17 21:07:58 dyoung Exp $");
+
+#include "opt_multiprocessor.h"
+#include "pchb.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/kmem.h>
+#include <sys/queue.h>
+
+#include <machine/specialreg.h>
+#include <machine/cpuvar.h>
+#include <machine/bus.h>
+#include <machine/mpconfig.h>
+
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#include "pci.h"
+#include "locators.h"
+
+#if NPCI > 0
+int
+mp_pci_scan(device_t self, struct pcibus_attach_args *pba,
+ cfprint_t print)
+{
+ int i;
+ struct mp_bus *mpb;
+
+ for (i = 0; i < mp_nbus; i++) {
+ mpb = &mp_busses[i];
+ if (mpb->mb_name == NULL)
+ continue;
+ if (strcmp(mpb->mb_name, "pci") == 0 && mpb->mb_dev == NULL) {
+ pba->pba_bus = i;
+ mpb->mb_dev =
+ config_found_ia(self, "pcibus", pba, print);
+ }
+ }
+ return 0;
+}
+
+void
+mp_pci_childdetached(device_t self, device_t child)
+{
+ int i;
+ struct mp_bus *mpb;
+
+ for (i = 0; i < mp_nbus; i++) {
+ mpb = &mp_busses[i];
+ if (mpb->mb_name == NULL)
+ continue;
+ if (strcmp(mpb->mb_name, "pci") == 0 && mpb->mb_dev == child)
+ mpb->mb_dev = NULL;
+ }
+}
+#endif