Source-Changes-HG archive

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

[src/trunk]: src/sys locate PCI buses and determine their bus numbers using t...



details:   https://anonhg.NetBSD.org/src/rev/e79813d9cab4
branches:  trunk
changeset: 781684:e79813d9cab4
user:      chs <chs%NetBSD.org@localhost>
date:      Sun Sep 23 00:31:05 2012 +0000

description:
locate PCI buses and determine their bus numbers using the info
previously extracted from ACPICA rather than trying to figure it out again.
allow PCI buses that don't have a _PRT method.

diffstat:

 sys/arch/ia64/acpi/acpi_machdep.c    |    6 +-
 sys/arch/ia64/include/acpi_machdep.h |    5 +-
 sys/arch/x86/acpi/acpi_machdep.c     |    8 +-
 sys/arch/x86/include/acpi_machdep.h  |    5 +-
 sys/arch/x86/x86/mpacpi.c            |  338 ++++++----------------------------
 sys/dev/acpi/acpi.c                  |   41 ++--
 6 files changed, 100 insertions(+), 303 deletions(-)

diffs (truncated from 593 to 300 lines):

diff -r 8c5c25e89fde -r e79813d9cab4 sys/arch/ia64/acpi/acpi_machdep.c
--- a/sys/arch/ia64/acpi/acpi_machdep.c Sun Sep 23 00:26:25 2012 +0000
+++ b/sys/arch/ia64/acpi/acpi_machdep.c Sun Sep 23 00:31:05 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_machdep.c,v 1.5 2011/06/12 11:31:30 jruoho Exp $  */
+/*     $NetBSD: acpi_machdep.c,v 1.6 2012/09/23 00:31:05 chs Exp $     */
 /*
  * Copyright (c) 2009 KIYOHARA Takashi
  * All rights reserved.
@@ -28,7 +28,7 @@
  * Machine-dependent routines for ACPICA.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.5 2011/06/12 11:31:30 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.6 2012/09/23 00:31:05 chs Exp $");
 
 #include <sys/param.h>
 
@@ -189,7 +189,7 @@
 }
 
 void
-acpi_md_callback(void)
+acpi_md_callback(struct acpi_softc *sc)
 {
        /* Nothing. */
 }
diff -r 8c5c25e89fde -r e79813d9cab4 sys/arch/ia64/include/acpi_machdep.h
--- a/sys/arch/ia64/include/acpi_machdep.h      Sun Sep 23 00:26:25 2012 +0000
+++ b/sys/arch/ia64/include/acpi_machdep.h      Sun Sep 23 00:31:05 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_machdep.h,v 1.5 2011/06/12 11:31:30 jruoho Exp $  */
+/*     $NetBSD: acpi_machdep.h,v 1.6 2012/09/23 00:31:05 chs Exp $     */
 
 ACPI_STATUS            acpi_md_OsInitialize(void);
 ACPI_PHYSICAL_ADDRESS  acpi_md_OsGetRootPointer(void);
@@ -28,4 +28,5 @@
 int            acpi_md_sleep(int);
 uint32_t       acpi_md_pdc(void);
 uint32_t       acpi_md_ncpus(void);
-void           acpi_md_callback(void);
+struct acpi_softc;
+void           acpi_md_callback(struct acpi_softc *);
diff -r 8c5c25e89fde -r e79813d9cab4 sys/arch/x86/acpi/acpi_machdep.c
--- a/sys/arch/x86/acpi/acpi_machdep.c  Sun Sep 23 00:26:25 2012 +0000
+++ b/sys/arch/x86/acpi/acpi_machdep.c  Sun Sep 23 00:31:05 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_machdep.c,v 1.3 2012/01/30 21:47:24 rmind Exp $ */
+/* $NetBSD: acpi_machdep.c,v 1.4 2012/09/23 00:31:05 chs Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.3 2012/01/30 21:47:24 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.4 2012/09/23 00:31:05 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -283,12 +283,12 @@
 }
 
 void
-acpi_md_callback(void)
+acpi_md_callback(struct acpi_softc *sc)
 {
 #ifdef MPBIOS
        if (!mpbios_scanned)
 #endif
-       mpacpi_find_interrupts(acpi_softc);
+       mpacpi_find_interrupts(sc);
 
 #ifndef XEN
        acpi_md_sleep_init();
diff -r 8c5c25e89fde -r e79813d9cab4 sys/arch/x86/include/acpi_machdep.h
--- a/sys/arch/x86/include/acpi_machdep.h       Sun Sep 23 00:26:25 2012 +0000
+++ b/sys/arch/x86/include/acpi_machdep.h       Sun Sep 23 00:31:05 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_machdep.h,v 1.10 2011/06/12 11:31:31 jruoho Exp $ */
+/*     $NetBSD: acpi_machdep.h,v 1.11 2012/09/23 00:31:05 chs Exp $    */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -75,6 +75,7 @@
 
 uint32_t       acpi_md_pdc(void);
 uint32_t       acpi_md_ncpus(void);
-void           acpi_md_callback(void);
+struct acpi_softc;
+void           acpi_md_callback(struct acpi_softc *);
 
 #endif /* !_X86_ACPI_MACHDEP_H_ */
diff -r 8c5c25e89fde -r e79813d9cab4 sys/arch/x86/x86/mpacpi.c
--- a/sys/arch/x86/x86/mpacpi.c Sun Sep 23 00:26:25 2012 +0000
+++ b/sys/arch/x86/x86/mpacpi.c Sun Sep 23 00:31:05 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mpacpi.c,v 1.94 2012/04/27 04:32:27 jruoho Exp $       */
+/*     $NetBSD: mpacpi.c,v 1.95 2012/09/23 00:31:05 chs Exp $  */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpacpi.c,v 1.94 2012/04/27 04:32:27 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpacpi.c,v 1.95 2012/09/23 00:31:05 chs Exp $");
 
 #include "acpica.h"
 #include "opt_acpi.h"
@@ -91,6 +91,7 @@
        TAILQ_ENTRY(mpacpi_pcibus) mpr_list;
        ACPI_HANDLE mpr_handle;         /* Same thing really, but.. */
        ACPI_BUFFER mpr_buf;            /* preserve _PRT */
+       int mpr_seg;                    /* PCI segment number */
        int mpr_bus;                    /* PCI bus number */
 };
 
@@ -108,10 +109,6 @@
 static ACPI_STATUS mpacpi_nonpci_intr(ACPI_SUBTABLE_HEADER *, void *);
 
 #if NPCI > 0
-/* Callbacks for the ACPI namespace walk */
-static ACPI_STATUS mpacpi_pcibus_cb(ACPI_HANDLE, uint32_t, void *, void **);
-static int mpacpi_derive_bus(ACPI_HANDLE, struct acpi_softc *);
-
 static int mpacpi_pcircount(struct mpacpi_pcibus *);
 static int mpacpi_pciroute(struct mpacpi_pcibus *);
 static int mpacpi_find_pcibusses(struct acpi_softc *);
@@ -484,286 +481,74 @@
 
 #if NPCI > 0
 
-/*
- * Find all PCI busses from ACPI namespace and construct mpacpi_pcibusses list.
- *
- * Note:
- * We cannot find all PCI busses in the system from ACPI namespace.
- * For example, a PCI-to-PCI bridge on an add-on PCI card is not
- * described in the ACPI namespace.
- * We search valid devices which have _PRT (PCI interrupt routing table)
- * method.
- * Such devices are either one of PCI root bridge or PCI-to-PCI bridge.
- */
-static int
-mpacpi_find_pcibusses(struct acpi_softc *acpi)
+static void
+mpacpi_pci_foundbus(struct acpi_devnode *ad)
 {
-       ACPI_HANDLE sbhandle;
-
-       if (AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SB_", &sbhandle) != AE_OK)
-               return ENOENT;
-       TAILQ_INIT(&mpacpi_pcibusses);
-       AcpiWalkNamespace(ACPI_TYPE_DEVICE, sbhandle, 100,
-           mpacpi_pcibus_cb, NULL, acpi, NULL);
-       return 0;
-}
-
-static const char * const pciroot_hid[] = {
-       "PNP0A03",                      /* PCI root bridge */
-       "PNP0A08",                      /* PCI-X root bridge */
-       NULL
-};
-
-/*
- * mpacpi_get_bbn:
- *
- * Get or guess the Base Bus Number and sanity check it.
- */
-static ACPI_STATUS
-mpacpi_get_bbn(struct acpi_softc *acpi, ACPI_HANDLE handle, int *bus)
-{
-       ACPI_STATUS rv;
-       ACPI_INTEGER val;
-#if NPCHB > 0
-       pcireg_t class, dvid;
-       pcitag_t tag;
-#endif
-
-       rv = acpi_eval_integer(handle, METHOD_NAME__BBN, &val);
-       if (ACPI_SUCCESS(rv))
-               *bus = ACPI_LOWORD(val);
-       else
-               *bus = 0;
-
-       /* If the _BBN is not 0, assume it is valid. */
-       if (*bus != 0)
-               return AE_OK;
-
-       rv = acpi_eval_integer(handle, METHOD_NAME__ADR, &val);
-       if (ACPI_FAILURE(rv) || val == 0xffffffff)
-               return AE_ERROR;
-
-       /* If the _ADR is also 0, assume the _BBN is valid. */
-       if (val == 0)
-               return AE_OK;
-
-#if NPCHB > 0
-       tag = pci_make_tag(acpi->sc_pc, 0,
-           ACPI_HIWORD(val), ACPI_LOWORD(val));
-
-       dvid = pci_conf_read(acpi->sc_pc, tag, PCI_ID_REG);
-       if (PCI_VENDOR(dvid) == PCI_VENDOR_INVALID || PCI_VENDOR(dvid) == 0)
-               return AE_ERROR;
+       struct mpacpi_pcibus *mpr;
+       ACPI_BUFFER buf;
+       int rv;
 
-       /* Check if this is a host bridge device. */
-       class = pci_conf_read(acpi->sc_pc, tag, PCI_CLASS_REG);
-       if (PCI_CLASS(class) != PCI_CLASS_BRIDGE ||
-           PCI_SUBCLASS(class) != PCI_SUBCLASS_BRIDGE_HOST)
-               return AE_ERROR;
-
-       *bus = pchb_get_bus_number(acpi->sc_pc, tag);
-       return *bus != -1 ? AE_OK : AE_ERROR;
-#else
-       return AE_ERROR;
-#endif
-}
-
-/*
- * mpacpi_derive_bus:
- *
- * Derive PCI bus number for the ACPI handle.
- *
- * If a device is not a PCI root bridge, it doesn't have _BBN method
- * and we have no direct method to know the bus number.
- * We have to walk up to search its root bridge and then walk down
- * to resolve the bus number.
- */
-static int
-mpacpi_derive_bus(ACPI_HANDLE handle, struct acpi_softc *acpi)
-{
-       ACPI_HANDLE parent, current;
-       ACPI_STATUS rv;
-       ACPI_INTEGER val;
-       ACPI_DEVICE_INFO *devinfo;
-       struct ac_dev {
-               TAILQ_ENTRY(ac_dev) list;
-               ACPI_HANDLE handle;
-       };
-       TAILQ_HEAD(, ac_dev) dev_list;
-       struct ac_dev *dev;
-       pcireg_t binf, class, dvid;
-       pcitag_t tag;
-       int bus;
+       /*
+        * set mpr_buf from _PRT (if it exists).
+        * set mpr_seg and mpr_bus from previously cached info.
+        */
 
-       TAILQ_INIT(&dev_list);
-
-       /* first, search parent root bus */
-       for (current = handle;; current = parent) {
-               rv = AcpiGetObjectInfo(current, &devinfo);
-               if (ACPI_FAILURE(rv))
-                       goto out;
-
-               /* add this device to the list only if it's active */
-               if ((devinfo->Valid & ACPI_VALID_STA) == 0 ||
-                   (devinfo->CurrentStatus & ACPI_STA_OK) == ACPI_STA_OK) {
-                       ACPI_FREE(devinfo);
-                       dev = kmem_zalloc(sizeof(struct ac_dev), KM_SLEEP);
-                       if (dev == NULL) {
-                               rv = AE_NO_MEMORY;
-                               goto out;
-                       }
-                       dev->handle = current;
-                       TAILQ_INSERT_HEAD(&dev_list, dev, list);
-               } else
-                       ACPI_FREE(devinfo);
-
-               rv = AcpiGetParent(current, &parent);
-               if (ACPI_FAILURE(rv))
-                       goto out;
-
-               rv = AcpiGetObjectInfo(parent, &devinfo);
-               if (ACPI_FAILURE(rv))
-                       goto out;
-
-               if (acpi_match_hid(devinfo, pciroot_hid)) {
-                       rv = mpacpi_get_bbn(acpi, parent, &bus);
-                       if (ACPI_FAILURE(rv))
-                               bus = 0;
-                       ACPI_FREE(devinfo);
-                       break;
-               }
-
-               ACPI_FREE(devinfo);
+       rv = acpi_get(ad->ad_handle, &buf, AcpiGetIrqRoutingTable);
+       if (ACPI_FAILURE(rv)) {
+               buf.Length = 0; 
+               buf.Pointer = NULL; 
        }
 



Home | Main Index | Thread Index | Old Index