2022-10-15 01:10:15 +03:00
|
|
|
/* $NetBSD: acpi_pci.c,v 1.37 2022/10/14 22:10:15 jmcneill Exp $ */
|
2009-12-04 00:04:29 +03:00
|
|
|
|
|
|
|
/*
|
2010-04-22 18:50:30 +04:00
|
|
|
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
|
2009-12-04 00:04:29 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2010-04-22 18:50:30 +04:00
|
|
|
* by Christoph Egger and Gregoire Sutre.
|
2009-12-04 00:04:29 +03:00
|
|
|
*
|
|
|
|
* 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. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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>
|
2022-10-15 01:10:15 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.37 2022/10/14 22:10:15 jmcneill Exp $");
|
2009-12-04 00:04:29 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/kmem.h>
|
2010-03-05 17:00:16 +03:00
|
|
|
#include <sys/systm.h>
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
#include <dev/pci/pcireg.h>
|
2010-12-31 13:23:44 +03:00
|
|
|
#include <dev/pci/pcivar.h>
|
2010-04-22 18:50:30 +04:00
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
#include <dev/pci/ppbreg.h>
|
|
|
|
|
2021-09-15 20:33:08 +03:00
|
|
|
#include <dev/pci/pci_calls.h>
|
|
|
|
|
2009-12-04 00:04:29 +03:00
|
|
|
#include <dev/acpi/acpireg.h>
|
|
|
|
#include <dev/acpi/acpivar.h>
|
|
|
|
#include <dev/acpi/acpi_pci.h>
|
|
|
|
|
2010-12-31 13:23:44 +03:00
|
|
|
#include "locators.h"
|
|
|
|
|
2010-04-22 19:14:24 +04:00
|
|
|
#define _COMPONENT ACPI_BUS_COMPONENT
|
|
|
|
ACPI_MODULE_NAME ("acpi_pci")
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-04-22 19:14:24 +04:00
|
|
|
#define ACPI_HILODWORD(x) ACPI_HIWORD(ACPI_LODWORD((x)))
|
|
|
|
#define ACPI_LOLODWORD(x) ACPI_LOWORD(ACPI_LODWORD((x)))
|
|
|
|
|
|
|
|
static ACPI_STATUS acpi_pcidev_pciroot_bus_callback(ACPI_RESOURCE *,
|
|
|
|
void *);
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
/*
|
2010-04-26 17:30:31 +04:00
|
|
|
* Regarding PCI Segment Groups (ACPI 4.0, p. 277):
|
2010-04-22 18:50:30 +04:00
|
|
|
*
|
|
|
|
* "The optional _SEG object is located under a PCI host bridge and
|
2010-04-26 17:30:31 +04:00
|
|
|
* evaluates to an integer that describes the PCI Segment Group (see PCI
|
|
|
|
* Firmware Specification v3.0)."
|
2010-04-22 18:50:30 +04:00
|
|
|
*
|
2010-04-26 17:30:31 +04:00
|
|
|
* "PCI Segment Group is purely a software concept managed by system
|
|
|
|
* firmware and used by OSPM. It is a logical collection of PCI buses
|
|
|
|
* (or bus segments). It is a way to logically group the PCI bus segments
|
|
|
|
* and PCI Express Hierarchies. _SEG is a level higher than _BBN."
|
2010-04-22 18:50:30 +04:00
|
|
|
*
|
2010-04-26 17:30:31 +04:00
|
|
|
* "PCI Segment Group supports more than 256 buses in a system by allowing
|
|
|
|
* the reuse of the PCI bus numbers. Within each PCI Segment Group, the bus
|
|
|
|
* numbers for the PCI buses must be unique. PCI buses in different PCI
|
|
|
|
* Segment Group are permitted to have the same bus number."
|
2010-04-22 18:50:30 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2010-04-26 17:30:31 +04:00
|
|
|
* Regarding PCI Base Bus Numbers (ACPI 4.0, p. 277):
|
2010-04-22 18:50:30 +04:00
|
|
|
*
|
|
|
|
* "For multi-root PCI platforms, the _BBN object evaluates to the PCI bus
|
2010-04-26 17:30:31 +04:00
|
|
|
* number that the BIOS assigns. This is needed to access a PCI_Config
|
|
|
|
* operation region for the specified bus. The _BBN object is located under
|
|
|
|
* a PCI host bridge and must be unique for every host bridge within a
|
|
|
|
* segment since it is the PCI bus number."
|
2010-04-22 18:50:30 +04:00
|
|
|
*
|
|
|
|
* Moreover, the ACPI FAQ (http://www.acpi.info/acpi_faq.htm) says:
|
|
|
|
*
|
|
|
|
* "For a multiple root bus machine, _BBN is required for each bus. _BBN
|
2010-04-26 17:30:31 +04:00
|
|
|
* should provide the bus number assigned to this bus by the BIOS at boot
|
|
|
|
* time."
|
2010-04-22 18:50:30 +04:00
|
|
|
*/
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
/*
|
|
|
|
* acpi_pcidev_pciroot_bus:
|
|
|
|
*
|
|
|
|
* Derive the PCI bus number of a PCI root bridge from its resources.
|
|
|
|
* If successful, return AE_OK and fill *busp. Otherwise, return an
|
|
|
|
* exception code and leave *busp unchanged.
|
|
|
|
*/
|
2020-05-08 17:42:38 +03:00
|
|
|
ACPI_STATUS
|
2010-04-22 18:50:30 +04:00
|
|
|
acpi_pcidev_pciroot_bus(ACPI_HANDLE handle, uint16_t *busp)
|
2009-12-04 00:04:29 +03:00
|
|
|
{
|
|
|
|
ACPI_STATUS rv;
|
2010-04-22 18:50:30 +04:00
|
|
|
int32_t bus;
|
|
|
|
|
|
|
|
bus = -1;
|
2010-04-26 17:30:31 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: Use the ACPI resource parsing functions (acpi_resource.c)
|
|
|
|
* once bus number ranges have been implemented there.
|
|
|
|
*/
|
|
|
|
rv = AcpiWalkResources(handle, "_CRS",
|
2010-04-22 18:50:30 +04:00
|
|
|
acpi_pcidev_pciroot_bus_callback, &bus);
|
|
|
|
|
2009-12-04 00:04:29 +03:00
|
|
|
if (ACPI_FAILURE(rv))
|
2010-04-22 18:50:30 +04:00
|
|
|
return rv;
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-09-24 11:48:59 +04:00
|
|
|
if (bus == -1)
|
2010-04-22 18:50:30 +04:00
|
|
|
return AE_NOT_EXIST;
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-09-24 11:48:59 +04:00
|
|
|
/* Here it holds that 0 <= bus <= 0xFFFF. */
|
2010-04-22 18:50:30 +04:00
|
|
|
*busp = (uint16_t)bus;
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ACPI_STATUS
|
|
|
|
acpi_pcidev_pciroot_bus_callback(ACPI_RESOURCE *res, void *context)
|
|
|
|
{
|
|
|
|
ACPI_RESOURCE_ADDRESS64 addr64;
|
2010-04-22 19:25:46 +04:00
|
|
|
int32_t *bus = context;
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-04-22 19:25:46 +04:00
|
|
|
/* Always continue the walk by returning AE_OK. */
|
2010-04-22 18:50:30 +04:00
|
|
|
if ((res->Type != ACPI_RESOURCE_TYPE_ADDRESS16) &&
|
|
|
|
(res->Type != ACPI_RESOURCE_TYPE_ADDRESS32) &&
|
|
|
|
(res->Type != ACPI_RESOURCE_TYPE_ADDRESS64))
|
2010-04-22 19:25:46 +04:00
|
|
|
return AE_OK;
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
if (ACPI_FAILURE(AcpiResourceToAddress64(res, &addr64)))
|
2010-04-22 19:25:46 +04:00
|
|
|
return AE_OK;
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
if (addr64.ResourceType != ACPI_BUS_NUMBER_RANGE)
|
2010-04-22 19:25:46 +04:00
|
|
|
return AE_OK;
|
2010-04-22 18:50:30 +04:00
|
|
|
|
|
|
|
if (*bus != -1)
|
|
|
|
return AE_ALREADY_EXISTS;
|
|
|
|
|
2015-04-13 21:32:50 +03:00
|
|
|
if (addr64.Address.Minimum > 0xFFFF)
|
2010-09-24 11:48:59 +04:00
|
|
|
return AE_BAD_DATA;
|
|
|
|
|
2015-04-13 21:32:50 +03:00
|
|
|
*bus = (int32_t)addr64.Address.Minimum;
|
2010-04-22 19:25:46 +04:00
|
|
|
|
|
|
|
return AE_OK;
|
2009-12-04 00:04:29 +03:00
|
|
|
}
|
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
/*
|
2010-04-23 01:58:08 +04:00
|
|
|
* acpi_pcidev_scan:
|
2010-04-22 18:50:30 +04:00
|
|
|
*
|
|
|
|
* Scan the ACPI device tree for PCI devices. A node is detected as a
|
|
|
|
* PCI device if it has an ancestor that is a PCI root bridge and such
|
|
|
|
* that all intermediate nodes are PCI-to-PCI bridges. Depth-first
|
|
|
|
* recursive implementation.
|
2010-10-27 02:27:44 +04:00
|
|
|
*
|
|
|
|
* PCI root bridges do not necessarily contain an _ADR, since they already
|
|
|
|
* contain an _HID (ACPI 4.0a, p. 197). However we require an _ADR for
|
|
|
|
* all non-root PCI devices.
|
2010-04-22 18:50:30 +04:00
|
|
|
*/
|
2010-04-23 01:58:08 +04:00
|
|
|
ACPI_STATUS
|
|
|
|
acpi_pcidev_scan(struct acpi_devnode *ad)
|
2009-12-04 00:04:29 +03:00
|
|
|
{
|
2010-04-22 18:50:30 +04:00
|
|
|
struct acpi_devnode *child;
|
|
|
|
struct acpi_pci_info *ap;
|
|
|
|
ACPI_INTEGER val;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
2010-08-08 20:26:47 +04:00
|
|
|
ad->ad_pciinfo = NULL;
|
|
|
|
|
2010-08-09 13:36:42 +04:00
|
|
|
/*
|
|
|
|
* We attach PCI information only to devices that are present,
|
|
|
|
* enabled, and functioning properly.
|
|
|
|
* Note: there is a possible race condition, because _STA may
|
|
|
|
* have changed since ad->ad_devinfo->CurrentStatus was set.
|
|
|
|
*/
|
2010-10-27 02:27:44 +04:00
|
|
|
if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE)
|
|
|
|
goto rec;
|
2010-08-09 13:36:42 +04:00
|
|
|
|
2018-05-05 20:16:23 +03:00
|
|
|
if (!acpi_device_present(ad->ad_handle))
|
|
|
|
goto rec;
|
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
if (ad->ad_devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) {
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
ap = kmem_zalloc(sizeof(*ap), KM_SLEEP);
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-26 17:30:31 +04:00
|
|
|
/*
|
|
|
|
* If no _SEG exist, all PCI bus segments are assumed
|
|
|
|
* to be in the PCI segment group 0 (ACPI 4.0, p. 277).
|
|
|
|
* The segment group number is conveyed in the lower
|
|
|
|
* 16 bits of _SEG (the other bits are all reserved).
|
|
|
|
*/
|
2010-04-22 19:25:46 +04:00
|
|
|
rv = acpi_eval_integer(ad->ad_handle, "_SEG", &val);
|
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
if (ACPI_SUCCESS(rv))
|
|
|
|
ap->ap_segment = ACPI_LOWORD(val);
|
|
|
|
|
2010-10-27 02:27:44 +04:00
|
|
|
/* Try to get downstream bus number using _CRS first. */
|
|
|
|
rv = acpi_pcidev_pciroot_bus(ad->ad_handle, &ap->ap_downbus);
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2010-04-22 19:25:46 +04:00
|
|
|
rv = acpi_eval_integer(ad->ad_handle, "_BBN", &val);
|
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
if (ACPI_SUCCESS(rv))
|
2010-10-27 02:27:44 +04:00
|
|
|
ap->ap_downbus = ACPI_LOWORD(val);
|
2010-04-22 18:50:30 +04:00
|
|
|
}
|
|
|
|
|
2010-10-27 02:27:44 +04:00
|
|
|
if (ap->ap_downbus > 255) {
|
2010-08-08 20:26:47 +04:00
|
|
|
aprint_error_dev(ad->ad_root,
|
2010-10-27 02:27:44 +04:00
|
|
|
"invalid PCI downstream bus for %s\n", ad->ad_name);
|
2010-08-08 20:26:47 +04:00
|
|
|
kmem_free(ap, sizeof(*ap));
|
|
|
|
goto rec;
|
|
|
|
}
|
|
|
|
|
2010-10-27 02:27:44 +04:00
|
|
|
ap->ap_flags |= ACPI_PCI_INFO_BRIDGE;
|
|
|
|
|
2020-01-17 20:06:32 +03:00
|
|
|
ap->ap_pc = acpi_get_pci_chipset_tag(acpi_softc, ap->ap_segment, ap->ap_downbus);
|
|
|
|
|
2010-10-27 02:27:44 +04:00
|
|
|
/*
|
|
|
|
* This ACPI node denotes a PCI root bridge, but it may also
|
|
|
|
* denote a PCI device on the bridge's downstream bus segment.
|
|
|
|
*/
|
|
|
|
if (ad->ad_devinfo->Valid & ACPI_VALID_ADR) {
|
|
|
|
ap->ap_bus = ap->ap_downbus;
|
|
|
|
ap->ap_device =
|
|
|
|
ACPI_HILODWORD(ad->ad_devinfo->Address);
|
|
|
|
ap->ap_function =
|
|
|
|
ACPI_LOLODWORD(ad->ad_devinfo->Address);
|
|
|
|
|
|
|
|
if (ap->ap_device > 31 ||
|
|
|
|
(ap->ap_function > 7 && ap->ap_function != 0xFFFF))
|
|
|
|
aprint_error_dev(ad->ad_root,
|
|
|
|
"invalid PCI address for %s\n", ad->ad_name);
|
|
|
|
else
|
|
|
|
ap->ap_flags |= ACPI_PCI_INFO_DEVICE;
|
|
|
|
}
|
2010-04-22 18:50:30 +04:00
|
|
|
|
|
|
|
ad->ad_pciinfo = ap;
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
goto rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ad->ad_parent != NULL) &&
|
|
|
|
(ad->ad_parent->ad_pciinfo != NULL) &&
|
2010-10-27 02:27:44 +04:00
|
|
|
(ad->ad_parent->ad_pciinfo->ap_flags & ACPI_PCI_INFO_BRIDGE) &&
|
|
|
|
(ad->ad_devinfo->Valid & ACPI_VALID_ADR)) {
|
2010-04-26 17:30:31 +04:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
/*
|
2010-04-26 17:30:31 +04:00
|
|
|
* Our parent is a PCI root bridge or a PCI-to-PCI
|
|
|
|
* bridge. We have the same PCI segment number, and
|
|
|
|
* our bus number is its downstream bus number.
|
2010-04-22 18:50:30 +04:00
|
|
|
*/
|
|
|
|
ap = kmem_zalloc(sizeof(*ap), KM_SLEEP);
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2020-01-17 20:06:32 +03:00
|
|
|
ap->ap_pc = ad->ad_parent->ad_pciinfo->ap_pc;
|
2010-04-22 18:50:30 +04:00
|
|
|
ap->ap_segment = ad->ad_parent->ad_pciinfo->ap_segment;
|
|
|
|
ap->ap_bus = ad->ad_parent->ad_pciinfo->ap_downbus;
|
2010-04-22 19:14:24 +04:00
|
|
|
|
|
|
|
ap->ap_device = ACPI_HILODWORD(ad->ad_devinfo->Address);
|
|
|
|
ap->ap_function = ACPI_LOLODWORD(ad->ad_devinfo->Address);
|
2010-04-22 18:50:30 +04:00
|
|
|
|
2010-09-24 11:48:59 +04:00
|
|
|
if (ap->ap_device > 31 ||
|
|
|
|
(ap->ap_function > 7 && ap->ap_function != 0xFFFF)) {
|
2010-08-08 20:26:47 +04:00
|
|
|
aprint_error_dev(ad->ad_root,
|
|
|
|
"invalid PCI address for %s\n", ad->ad_name);
|
|
|
|
kmem_free(ap, sizeof(*ap));
|
|
|
|
goto rec;
|
|
|
|
}
|
|
|
|
|
2010-10-27 02:27:44 +04:00
|
|
|
ap->ap_flags |= ACPI_PCI_INFO_DEVICE;
|
|
|
|
|
2010-09-24 11:48:59 +04:00
|
|
|
if (ap->ap_function == 0xFFFF) {
|
|
|
|
/*
|
|
|
|
* Assume that this device is not a PCI-to-PCI bridge.
|
|
|
|
* XXX: Do we need to be smarter?
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Check whether this device is a PCI-to-PCI
|
|
|
|
* bridge and get its secondary bus number.
|
|
|
|
*/
|
2020-01-17 20:06:32 +03:00
|
|
|
rv = acpi_pcidev_ppb_downbus(
|
|
|
|
ad->ad_parent->ad_pciinfo->ap_pc,
|
|
|
|
ap->ap_segment, ap->ap_bus, ap->ap_device,
|
|
|
|
ap->ap_function, &ap->ap_downbus);
|
2010-09-24 11:48:59 +04:00
|
|
|
|
2010-10-27 02:27:44 +04:00
|
|
|
if (ACPI_SUCCESS(rv))
|
|
|
|
ap->ap_flags |= ACPI_PCI_INFO_BRIDGE;
|
2010-09-24 11:48:59 +04:00
|
|
|
}
|
2010-04-22 18:50:30 +04:00
|
|
|
|
|
|
|
ad->ad_pciinfo = ap;
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
goto rec;
|
|
|
|
}
|
2010-04-23 01:58:08 +04:00
|
|
|
|
2010-04-22 19:25:46 +04:00
|
|
|
rec:
|
2010-04-22 18:50:30 +04:00
|
|
|
SIMPLEQ_FOREACH(child, &ad->ad_child_head, ad_child_list) {
|
2010-04-23 01:58:08 +04:00
|
|
|
rv = acpi_pcidev_scan(child);
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
if (ACPI_FAILURE(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AE_OK;
|
2009-12-04 00:04:29 +03:00
|
|
|
}
|
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
/*
|
|
|
|
* acpi_pcidev_ppb_downbus:
|
|
|
|
*
|
|
|
|
* Retrieve the secondary bus number of the PCI-to-PCI bridge having the
|
2010-08-08 20:26:47 +04:00
|
|
|
* given PCI id. If successful, return AE_OK and fill *downbus.
|
|
|
|
* Otherwise, return an exception code and leave *downbus unchanged.
|
2010-04-22 18:50:30 +04:00
|
|
|
*
|
|
|
|
* XXX Need to deal with PCI segment groups (see also acpica/OsdHardware.c).
|
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
2020-01-17 20:06:32 +03:00
|
|
|
acpi_pcidev_ppb_downbus(pci_chipset_tag_t pc, uint16_t segment, uint16_t bus,
|
|
|
|
uint16_t device, uint16_t function, uint16_t *downbus)
|
2009-12-04 00:04:29 +03:00
|
|
|
{
|
2010-04-22 18:50:30 +04:00
|
|
|
pcitag_t tag;
|
|
|
|
pcireg_t val;
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
if (bus > 255 || device > 31 || function > 7)
|
|
|
|
return AE_BAD_PARAMETER;
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
tag = pci_make_tag(pc, bus, device, function);
|
2010-03-09 21:15:21 +03:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
/* Check that this device exists. */
|
|
|
|
val = pci_conf_read(pc, tag, PCI_ID_REG);
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
if (PCI_VENDOR(val) == PCI_VENDOR_INVALID ||
|
|
|
|
PCI_VENDOR(val) == 0)
|
|
|
|
return AE_NOT_EXIST;
|
2010-03-09 21:15:21 +03:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
/* Check that this device is a PCI-to-PCI bridge. */
|
|
|
|
val = pci_conf_read(pc, tag, PCI_BHLC_REG);
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
if (PCI_HDRTYPE_TYPE(val) != PCI_HDRTYPE_PPB)
|
|
|
|
return AE_TYPE;
|
2010-03-09 21:15:21 +03:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
/* This is a PCI-to-PCI bridge. Get its secondary bus#. */
|
2019-03-01 12:25:59 +03:00
|
|
|
val = pci_conf_read(pc, tag, PCI_BRIDGE_BUS_REG);
|
|
|
|
*downbus = PCI_BRIDGE_BUS_NUM_SECONDARY(val);
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-22 18:50:30 +04:00
|
|
|
return AE_OK;
|
|
|
|
}
|
2009-12-04 00:04:29 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* acpi_pcidev_find:
|
|
|
|
*
|
|
|
|
* Finds a PCI device in the ACPI name space.
|
2010-04-23 19:46:59 +04:00
|
|
|
*
|
|
|
|
* Returns an ACPI device node on success and NULL on failure.
|
2009-12-04 00:04:29 +03:00
|
|
|
*/
|
2010-04-23 19:46:59 +04:00
|
|
|
struct acpi_devnode *
|
|
|
|
acpi_pcidev_find(uint16_t segment, uint16_t bus,
|
|
|
|
uint16_t device, uint16_t function)
|
2009-12-04 00:04:29 +03:00
|
|
|
{
|
2010-04-22 18:50:30 +04:00
|
|
|
struct acpi_softc *sc = acpi_softc;
|
|
|
|
struct acpi_devnode *ad;
|
|
|
|
|
|
|
|
if (sc == NULL)
|
2010-04-23 19:46:59 +04:00
|
|
|
return NULL;
|
2009-12-04 00:04:29 +03:00
|
|
|
|
2021-12-20 14:17:40 +03:00
|
|
|
SIMPLEQ_FOREACH(ad, &sc->sc_head, ad_list) {
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-23 19:46:59 +04:00
|
|
|
if (ad->ad_pciinfo != NULL &&
|
2010-10-27 02:27:44 +04:00
|
|
|
(ad->ad_pciinfo->ap_flags & ACPI_PCI_INFO_DEVICE) &&
|
2010-04-23 19:46:59 +04:00
|
|
|
ad->ad_pciinfo->ap_segment == segment &&
|
|
|
|
ad->ad_pciinfo->ap_bus == bus &&
|
|
|
|
ad->ad_pciinfo->ap_device == device &&
|
|
|
|
ad->ad_pciinfo->ap_function == function)
|
|
|
|
return ad;
|
2010-04-22 18:50:30 +04:00
|
|
|
}
|
2010-04-22 19:25:46 +04:00
|
|
|
|
2010-04-23 19:46:59 +04:00
|
|
|
return NULL;
|
2009-12-04 00:04:29 +03:00
|
|
|
}
|
2010-12-31 13:23:44 +03:00
|
|
|
|
2020-01-17 20:06:32 +03:00
|
|
|
/*
|
|
|
|
* acpi_pcidev_get_tag:
|
|
|
|
*
|
|
|
|
* Returns a PCI chipset tag for a PCI device in the ACPI name space.
|
|
|
|
*/
|
|
|
|
pci_chipset_tag_t
|
|
|
|
acpi_pcidev_get_tag(uint16_t segment, uint16_t bus,
|
|
|
|
uint16_t device, uint16_t function)
|
|
|
|
{
|
|
|
|
struct acpi_devnode *ad;
|
|
|
|
|
|
|
|
ad = acpi_pcidev_find(segment, bus, device, function);
|
|
|
|
if (ad == NULL || ad->ad_pciinfo == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return ad->ad_pciinfo->ap_pc;
|
|
|
|
}
|
|
|
|
|
2018-10-15 13:00:30 +03:00
|
|
|
/*
|
|
|
|
* acpi_pciroot_find:
|
|
|
|
*
|
|
|
|
* Finds a PCI root bridge in the ACPI name space.
|
|
|
|
*
|
|
|
|
* Returns an ACPI device node on success and NULL on failure.
|
|
|
|
*/
|
|
|
|
struct acpi_devnode *
|
|
|
|
acpi_pciroot_find(uint16_t segment, uint16_t bus)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc = acpi_softc;
|
|
|
|
struct acpi_devnode *ad;
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2021-12-20 14:17:40 +03:00
|
|
|
SIMPLEQ_FOREACH(ad, &sc->sc_head, ad_list) {
|
2018-10-15 13:00:30 +03:00
|
|
|
|
|
|
|
if (ad->ad_pciinfo != NULL &&
|
|
|
|
(ad->ad_pciinfo->ap_flags & ACPI_PCI_INFO_BRIDGE) &&
|
|
|
|
ad->ad_pciinfo->ap_segment == segment &&
|
|
|
|
ad->ad_pciinfo->ap_bus == bus)
|
|
|
|
return ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-12-31 13:23:44 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* acpi_pcidev_find_dev:
|
|
|
|
*
|
|
|
|
* Returns the device corresponding to the given PCI info, or NULL
|
|
|
|
* if it doesn't exist.
|
|
|
|
*/
|
|
|
|
device_t
|
2010-12-31 13:56:39 +03:00
|
|
|
acpi_pcidev_find_dev(struct acpi_devnode *ad)
|
2010-12-31 13:23:44 +03:00
|
|
|
{
|
2010-12-31 13:56:39 +03:00
|
|
|
struct acpi_pci_info *ap;
|
2010-12-31 13:23:44 +03:00
|
|
|
struct pci_softc *pci;
|
|
|
|
device_t dv, pr;
|
|
|
|
deviter_t di;
|
|
|
|
|
2010-12-31 13:56:39 +03:00
|
|
|
if (ad == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (ad->ad_pciinfo == NULL)
|
2010-12-31 13:23:44 +03:00
|
|
|
return NULL;
|
|
|
|
|
2010-12-31 13:56:39 +03:00
|
|
|
ap = ad->ad_pciinfo;
|
|
|
|
|
2010-12-31 13:23:44 +03:00
|
|
|
if (ap->ap_function == 0xFFFF)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
|
|
|
|
dv != NULL; dv = deviter_next(&di)) {
|
|
|
|
|
|
|
|
pr = device_parent(dv);
|
|
|
|
|
|
|
|
if (pr == NULL || device_is_a(pr, "pci") != true)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pci = device_private(pr);
|
|
|
|
|
|
|
|
if (pci->sc_bus == ap->ap_bus &&
|
|
|
|
device_locator(dv, PCICF_DEV) == ap->ap_device &&
|
|
|
|
device_locator(dv, PCICF_FUNCTION) == ap->ap_function)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
deviter_release(&di);
|
|
|
|
|
|
|
|
return dv;
|
|
|
|
}
|
2018-10-21 14:04:26 +03:00
|
|
|
|
2021-05-13 02:22:32 +03:00
|
|
|
/*
|
|
|
|
* acpi_pci_bus_get_child_devhandle:
|
|
|
|
*
|
|
|
|
* Implements the "pci-bus-get-child-devhandle" device call for
|
|
|
|
* ACPI device handles
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_pci_bus_get_child_devhandle(device_t dev, devhandle_t call_handle, void *v)
|
|
|
|
{
|
|
|
|
struct pci_bus_get_child_devhandle_args *args = v;
|
|
|
|
struct acpi_devnode *ad;
|
|
|
|
ACPI_HANDLE hdl;
|
|
|
|
int b, d, f;
|
|
|
|
u_int segment;
|
|
|
|
|
|
|
|
segment = pci_get_segment(args->pc);
|
|
|
|
|
|
|
|
pci_decompose_tag(args->pc, args->tag, &b, &d, &f);
|
|
|
|
|
|
|
|
ad = acpi_pcidev_find(segment, b, d, f);
|
|
|
|
|
|
|
|
if (ad != NULL && (hdl = ad->ad_handle) != NULL) {
|
|
|
|
/* Found it! */
|
2022-01-22 14:49:16 +03:00
|
|
|
args->devhandle = devhandle_from_acpi(call_handle, hdl);
|
2021-05-13 02:22:32 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ENODEV;
|
|
|
|
}
|
2021-09-15 20:33:08 +03:00
|
|
|
ACPI_DEVICE_CALL_REGISTER(PCI_BUS_GET_CHILD_DEVHANDLE_STR,
|
2021-05-13 02:22:32 +03:00
|
|
|
acpi_pci_bus_get_child_devhandle)
|