^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: hwpci - Obtain PCI bus, device, and function numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define _COMPONENT ACPI_NAMESPACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) ACPI_MODULE_NAME("hwpci")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /* PCI configuration space values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define PCI_CFG_HEADER_TYPE_REG 0x0E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define PCI_CFG_PRIMARY_BUS_NUMBER_REG 0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define PCI_CFG_SECONDARY_BUS_NUMBER_REG 0x19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* PCI header values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define PCI_HEADER_TYPE_MASK 0x7F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define PCI_TYPE_BRIDGE 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define PCI_TYPE_CARDBUS_BRIDGE 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) typedef struct acpi_pci_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) acpi_handle device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct acpi_pci_device *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) } acpi_pci_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) acpi_hw_build_pci_list(acpi_handle root_pci_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) acpi_handle pci_region,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct acpi_pci_device **return_list_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) acpi_hw_process_pci_list(struct acpi_pci_id *pci_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct acpi_pci_device *list_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static void acpi_hw_delete_pci_list(struct acpi_pci_device *list_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) acpi_hw_get_pci_device_info(struct acpi_pci_id *pci_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) acpi_handle pci_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u16 *bus_number, u8 *is_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * FUNCTION: acpi_hw_derive_pci_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * PARAMETERS: pci_id - Initial values for the PCI ID. May be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * modified by this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * root_pci_device - A handle to a PCI device object. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * object must be a PCI Root Bridge having a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * _HID value of either PNP0A03 or PNP0A08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * pci_region - A handle to a PCI configuration space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Operation Region being initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * DESCRIPTION: This function derives a full PCI ID for a PCI device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * consisting of a Segment number, Bus number, Device number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * and function code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * The PCI hardware dynamically configures PCI bus numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * depending on the bus topology discovered during system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * initialization. This function is invoked during configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * of a PCI_Config Operation Region in order to (possibly) update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * the Bus/Device/Function numbers in the pci_id with the actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * values as determined by the hardware and operating system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * The pci_id parameter is initially populated during the Operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Region initialization. This function is then called, and is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * will make any necessary modifications to the Bus, Device, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * Function number PCI ID subfields as appropriate for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * current hardware and OS configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * NOTE: Created 08/2010. Replaces the previous OSL acpi_os_derive_pci_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * interface since this feature is OS-independent. This module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * specifically avoids any use of recursion by building a local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * temporary device list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) acpi_hw_derive_pci_id(struct acpi_pci_id *pci_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) acpi_handle root_pci_device, acpi_handle pci_region)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct acpi_pci_device *list_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ACPI_FUNCTION_TRACE(hw_derive_pci_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (!pci_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* Build a list of PCI devices, from pci_region up to root_pci_device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) acpi_hw_build_pci_list(root_pci_device, pci_region, &list_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* Walk the list, updating the PCI device/function/bus numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) status = acpi_hw_process_pci_list(pci_id, list_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* Delete the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) acpi_hw_delete_pci_list(list_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * FUNCTION: acpi_hw_build_pci_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * PARAMETERS: root_pci_device - A handle to a PCI device object. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * object is guaranteed to be a PCI Root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * Bridge having a _HID value of either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * PNP0A03 or PNP0A08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * pci_region - A handle to the PCI configuration space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * Operation Region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * return_list_head - Where the PCI device list is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * DESCRIPTION: Builds a list of devices from the input PCI region up to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * Root PCI device for this namespace subtree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) acpi_hw_build_pci_list(acpi_handle root_pci_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) acpi_handle pci_region,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct acpi_pci_device **return_list_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) acpi_handle current_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) acpi_handle parent_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct acpi_pci_device *list_element;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * Ascend namespace branch until the root_pci_device is reached, building
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * a list of device nodes. Loop will exit when either the PCI device is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * found, or the root of the namespace is reached.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) *return_list_head = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) current_device = pci_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) status = acpi_get_parent(current_device, &parent_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* Must delete the list before exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) acpi_hw_delete_pci_list(*return_list_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* Finished when we reach the PCI root device (PNP0A03 or PNP0A08) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (parent_device == root_pci_device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) list_element = ACPI_ALLOCATE(sizeof(struct acpi_pci_device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (!list_element) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* Must delete the list before exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) acpi_hw_delete_pci_list(*return_list_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return (AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* Put new element at the head of the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) list_element->next = *return_list_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) list_element->device = parent_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) *return_list_head = list_element;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) current_device = parent_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * FUNCTION: acpi_hw_process_pci_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * PARAMETERS: pci_id - Initial values for the PCI ID. May be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * modified by this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * list_head - Device list created by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * acpi_hw_build_pci_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * DESCRIPTION: Walk downward through the PCI device list, getting the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * info for each, via the PCI configuration space and updating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * the PCI ID as necessary. Deletes the list during traversal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) acpi_hw_process_pci_list(struct acpi_pci_id *pci_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct acpi_pci_device *list_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct acpi_pci_device *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u16 bus_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) u8 is_bridge = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) ACPI_FUNCTION_NAME(hw_process_pci_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) "Input PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) pci_id->segment, pci_id->bus, pci_id->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) pci_id->function));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) bus_number = pci_id->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * Descend down the namespace tree, collecting PCI device, function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * and bus numbers. bus_number is only important for PCI bridges.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * Algorithm: As we descend the tree, use the last valid PCI device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * function, and bus numbers that are discovered, and assign them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * to the PCI ID for the target device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) info = list_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) while (info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) status = acpi_hw_get_pci_device_info(pci_id, info->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) &bus_number, &is_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) info = info->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) "Output PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) "Status %X BusNumber %X IsBridge %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) pci_id->segment, pci_id->bus, pci_id->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) pci_id->function, status, bus_number, is_bridge));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * FUNCTION: acpi_hw_delete_pci_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * PARAMETERS: list_head - Device list created by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * acpi_hw_build_pci_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * DESCRIPTION: Free the entire PCI list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static void acpi_hw_delete_pci_list(struct acpi_pci_device *list_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct acpi_pci_device *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct acpi_pci_device *previous;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) next = list_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) while (next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) previous = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) next = previous->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ACPI_FREE(previous);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * FUNCTION: acpi_hw_get_pci_device_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * PARAMETERS: pci_id - Initial values for the PCI ID. May be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * modified by this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * pci_device - Handle for the PCI device object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * bus_number - Where a PCI bridge bus number is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * is_bridge - Return value, indicates if this PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * device is a PCI bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * DESCRIPTION: Get the device info for a single PCI device object. Get the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * _ADR (contains PCI device and function numbers), and for PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * bridge devices, get the bus number from PCI configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) acpi_hw_get_pci_device_info(struct acpi_pci_id *pci_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) acpi_handle pci_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) u16 *bus_number, u8 *is_bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) acpi_object_type object_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) u64 return_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) u64 pci_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* We only care about objects of type Device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) status = acpi_get_type(pci_device, &object_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (object_type != ACPI_TYPE_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /* We need an _ADR. Ignore device if not present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) pci_device, &return_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * From _ADR, get the PCI Device and Function and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * update the PCI ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) pci_id->device = ACPI_HIWORD(ACPI_LODWORD(return_value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) pci_id->function = ACPI_LOWORD(ACPI_LODWORD(return_value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * If the previous device was a bridge, use the previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * device bus number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (*is_bridge) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) pci_id->bus = *bus_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * Get the bus numbers from PCI Config space:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * First, get the PCI header_type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) *is_bridge = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) status = acpi_os_read_pci_configuration(pci_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) PCI_CFG_HEADER_TYPE_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) &pci_value, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /* We only care about bridges (1=pci_bridge, 2=card_bus_bridge) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) pci_value &= PCI_HEADER_TYPE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if ((pci_value != PCI_TYPE_BRIDGE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) (pci_value != PCI_TYPE_CARDBUS_BRIDGE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* Bridge: Get the Primary bus_number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) status = acpi_os_read_pci_configuration(pci_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) PCI_CFG_PRIMARY_BUS_NUMBER_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) &pci_value, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) *is_bridge = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) pci_id->bus = (u16)pci_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /* Bridge: Get the Secondary bus_number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) status = acpi_os_read_pci_configuration(pci_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) PCI_CFG_SECONDARY_BUS_NUMBER_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) &pci_value, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) *bus_number = (u16)pci_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }