svn commit: r297679 - in head/sys/dev: acpica xen/pci
John Baldwin
jhb at FreeBSD.org
Thu Apr 7 17:15:18 UTC 2016
Author: jhb
Date: Thu Apr 7 17:15:16 2016
New Revision: 297679
URL: https://svnweb.freebsd.org/changeset/base/297679
Log:
Associate device_t objects with ACPI handles via PCI_CHILD_ADDED().
Previously, the ACPI PCI bus driver did a single pass over the devices in
the namespace that were a child of a given PCI bus to associate the
PCI bus-enumerated device_t devices with the corresponding ACPI handles.
However, this meant that handles were only established at runtime for devices
found during the initial PCI bus scan.
PCI_IOV adds devices that show up after the initial PCI bus scan, and coming
changes to add a bus rescan can also add devices after the initial scan.
This change adds a pci_child_added() callback to the ACPI PCI bus that walks
the namespace to find the ACPI handle for each device that is added. Using
a callback means that the handle is correctly set for any device no matter
how it is added (initial scan, IOV, or a bus rescan).
Added:
head/sys/dev/acpica/acpi_pcivar.h (contents, props changed)
Modified:
head/sys/dev/acpica/acpi_pci.c
head/sys/dev/xen/pci/xen_acpi_pci.c
Modified: head/sys/dev/acpica/acpi_pci.c
==============================================================================
--- head/sys/dev/acpica/acpi_pci.c Thu Apr 7 16:12:38 2016 (r297678)
+++ head/sys/dev/acpica/acpi_pci.c Thu Apr 7 17:15:16 2016 (r297679)
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
#include <contrib/dev/acpica/include/accommon.h>
#include <dev/acpica/acpivar.h>
+#include <dev/acpica/acpi_pcivar.h>
#include <sys/pciio.h>
#include <dev/pci/pcireg.h>
@@ -104,6 +105,7 @@ static device_method_t acpi_pci_methods[
DEVMETHOD(bus_get_domain, acpi_get_domain),
/* PCI interface */
+ DEVMETHOD(pci_child_added, acpi_pci_child_added),
DEVMETHOD(pci_set_powerstate, acpi_pci_set_powerstate_method),
#ifdef PCI_IOV
DEVMETHOD(pci_create_iov_child, acpi_pci_create_iov_child),
@@ -271,31 +273,35 @@ acpi_pci_save_handle(ACPI_HANDLE handle,
void **status)
{
struct acpi_pci_devinfo *dinfo;
- device_t *devlist;
- int devcount, i, func, slot;
+ device_t child;
+ int func, slot;
UINT32 address;
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
+ child = context;
if (ACPI_FAILURE(acpi_GetInteger(handle, "_ADR", &address)))
return_ACPI_STATUS (AE_OK);
slot = ACPI_ADR_PCI_SLOT(address);
func = ACPI_ADR_PCI_FUNC(address);
- if (device_get_children((device_t)context, &devlist, &devcount) != 0)
- return_ACPI_STATUS (AE_OK);
- for (i = 0; i < devcount; i++) {
- dinfo = device_get_ivars(devlist[i]);
- if (dinfo->ap_dinfo.cfg.func == func &&
- dinfo->ap_dinfo.cfg.slot == slot) {
- dinfo->ap_handle = handle;
- acpi_pci_update_device(handle, devlist[i]);
- break;
- }
+ dinfo = device_get_ivars(child);
+ if (dinfo->ap_dinfo.cfg.func == func &&
+ dinfo->ap_dinfo.cfg.slot == slot) {
+ dinfo->ap_handle = handle;
+ acpi_pci_update_device(handle, child);
+ return_ACPI_STATUS (AE_CTRL_TERMINATE);
}
- free(devlist, M_TEMP);
return_ACPI_STATUS (AE_OK);
}
+void
+acpi_pci_child_added(device_t dev, device_t child)
+{
+
+ AcpiWalkNamespace(ACPI_TYPE_DEVICE, acpi_get_handle(dev), 1,
+ acpi_pci_save_handle, NULL, child, NULL);
+}
+
static int
acpi_pci_probe(device_t dev)
{
@@ -325,18 +331,18 @@ acpi_pci_attach(device_t dev)
busno = pcib_get_bus(dev);
/*
- * First, PCI devices are added as in the normal PCI bus driver.
- * Afterwards, the ACPI namespace under the bridge driver is
- * walked to save ACPI handles to all the devices that appear in
- * the ACPI namespace as immediate descendants of the bridge.
+ * PCI devices are added via the bus scan in the normal PCI
+ * bus driver. As each device is added, the
+ * acpi_pci_child_added() callback walks the ACPI namespace
+ * under the bridge driver to save ACPI handles to all the
+ * devices that appear in the ACPI namespace as immediate
+ * descendants of the bridge.
*
* XXX: Sometimes PCI devices show up in the ACPI namespace that
* pci_add_children() doesn't find. We currently just ignore
* these devices.
*/
pci_add_children(dev, domain, busno, sizeof(struct acpi_pci_devinfo));
- AcpiWalkNamespace(ACPI_TYPE_DEVICE, acpi_get_handle(dev), 1,
- acpi_pci_save_handle, NULL, dev, NULL);
return (bus_generic_attach(dev));
}
@@ -371,17 +377,9 @@ static device_t
acpi_pci_create_iov_child(device_t bus, device_t pf, uint16_t rid, uint16_t vid,
uint16_t did)
{
- struct acpi_pci_devinfo *dinfo;
- device_t vf;
- vf = pci_add_iov_child(bus, pf, sizeof(struct acpi_pci_devinfo), rid,
- vid, did);
- if (vf == NULL)
- return (NULL);
-
- dinfo = device_get_ivars(vf);
- dinfo->ap_handle = NULL;
- return (vf);
+ return (pci_add_iov_child(bus, pf, sizeof(struct acpi_pci_devinfo), rid,
+ vid, did));
}
#endif
Added: head/sys/dev/acpica/acpi_pcivar.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/sys/dev/acpica/acpi_pcivar.h Thu Apr 7 17:15:16 2016 (r297679)
@@ -0,0 +1,38 @@
+/*-
+ * Copyright (c) 2016 John Baldwin <jhb at FreeBSD.org>
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _ACPI_PCIVAR_H_
+#define _ACPI_PCIVAR_H_
+
+#ifdef _KERNEL
+
+void acpi_pci_child_added(device_t dev, device_t child);
+
+#endif
+
+#endif /* !_ACPI_PCIVAR_H_ */
Modified: head/sys/dev/xen/pci/xen_acpi_pci.c
==============================================================================
--- head/sys/dev/xen/pci/xen_acpi_pci.c Thu Apr 7 16:12:38 2016 (r297678)
+++ head/sys/dev/xen/pci/xen_acpi_pci.c Thu Apr 7 17:15:16 2016 (r297679)
@@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
#include <contrib/dev/acpica/include/accommon.h>
#include <dev/acpica/acpivar.h>
+#include <dev/acpica/acpi_pcivar.h>
#include <sys/pciio.h>
#include <dev/pci/pcireg.h>
@@ -65,6 +66,14 @@ xen_acpi_pci_probe(device_t dev)
return (BUS_PROBE_SPECIFIC);
}
+static void
+xen_acpi_pci_child_added(device_t dev, device_t child)
+{
+
+ acpi_pci_child_added(dev, child);
+ xen_pci_child_added_method(dev, child);
+}
+
static device_method_t xen_acpi_pci_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, xen_acpi_pci_probe),
@@ -72,7 +81,7 @@ static device_method_t xen_acpi_pci_meth
/* PCI interface overwrites */
DEVMETHOD(pci_enable_msi, xen_pci_enable_msi_method),
DEVMETHOD(pci_disable_msi, xen_pci_disable_msi_method),
- DEVMETHOD(pci_child_added, xen_pci_child_added_method),
+ DEVMETHOD(pci_child_added, xen_acpi_pci_child_added),
DEVMETHOD_END
};
More information about the svn-src-all
mailing list