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.
This commit is contained in:
dyoung 2009-04-17 21:07:58 +00:00
parent 64670508f7
commit c94ffba5d6
9 changed files with 167 additions and 98 deletions

View File

@ -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 @@ mainbus_attach(device_t parent, device_t self, void *aux)
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);

View File

@ -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 @@ struct mainbus_softc {
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 @@ mainbus_childdetached(device_t self, device_t child)
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 @@ mainbus_attach(device_t parent, device_t self, void *aux)
#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 @@ mainbus_attach(device_t parent, device_t self, void *aux)
* 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_attach(device_t parent, device_t self, void *aux)
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 @@ static int
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 @@ mainbus_rescan(device_t self, const char *ifattr, const int *locators)
#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 */

View File

@ -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 @@ file arch/x86/x86/ioapic.c ioapic needs-flag
# 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

View File

@ -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_scan_apics(device_t, int *);
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 *);

View File

@ -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 @@ void mpbios_scan(device_t, int *);
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

View File

@ -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 @@ struct mp_bus
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 struct mp_intr_map *mp_intrs;
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

97
sys/arch/x86/x86/mp.c Normal file
View File

@ -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

View File

@ -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 @@ mpacpi_pci_attach_hook(device_t parent, device_t self,
*/
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 @@ mpacpi_pci_attach_hook(device_t parent, device_t self,
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

View File

@ -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 @@ mpbios_pci_attach_hook(device_t parent, device_t self,
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