^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: evrgnini- ACPI address_space (op_region) init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "acevents.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "acnamesp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "acinterp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define _COMPONENT ACPI_EVENTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) ACPI_MODULE_NAME("evrgnini")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * FUNCTION: acpi_ev_system_memory_region_setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * PARAMETERS: handle - Region we are interested in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * function - Start or stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * handler_context - Address space handler context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * region_context - Region specific context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * DESCRIPTION: Setup a system_memory operation region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) acpi_ev_system_memory_region_setup(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u32 function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) void *handler_context, void **region_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) union acpi_operand_object *region_desc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) (union acpi_operand_object *)handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct acpi_mem_space_context *local_region_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct acpi_mem_mapping *mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ACPI_FUNCTION_TRACE(ev_system_memory_region_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (function == ACPI_REGION_DEACTIVATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (*region_context) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) local_region_context =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) (struct acpi_mem_space_context *)*region_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* Delete memory mappings if present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) while (local_region_context->first_mm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) mm = local_region_context->first_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) local_region_context->first_mm = mm->next_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) acpi_os_unmap_memory(mm->logical_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) mm->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ACPI_FREE(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ACPI_FREE(local_region_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *region_context = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* Create a new context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) local_region_context =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_mem_space_context));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (!(local_region_context)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* Save the region length and address for use in the handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) local_region_context->length = region_desc->region.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) local_region_context->address = region_desc->region.address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) *region_context = local_region_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^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) * FUNCTION: acpi_ev_io_space_region_setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * PARAMETERS: handle - Region we are interested in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * function - Start or stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * handler_context - Address space handler context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * region_context - Region specific context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * DESCRIPTION: Setup a IO operation region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) acpi_ev_io_space_region_setup(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u32 function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) void *handler_context, void **region_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ACPI_FUNCTION_TRACE(ev_io_space_region_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (function == ACPI_REGION_DEACTIVATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *region_context = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *region_context = handler_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return_ACPI_STATUS(AE_OK);
^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) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * FUNCTION: acpi_ev_pci_config_region_setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * PARAMETERS: handle - Region we are interested in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * function - Start or stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * handler_context - Address space handler context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * region_context - Region specific context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * DESCRIPTION: Setup a PCI_Config operation region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * MUTEX: Assumes namespace is not locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) acpi_ev_pci_config_region_setup(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) u32 function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) void *handler_context, void **region_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) u64 pci_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct acpi_pci_id *pci_id = *region_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) union acpi_operand_object *handler_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct acpi_namespace_node *parent_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct acpi_namespace_node *pci_root_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct acpi_namespace_node *pci_device_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) union acpi_operand_object *region_obj =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) (union acpi_operand_object *)handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ACPI_FUNCTION_TRACE(ev_pci_config_region_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) handler_obj = region_obj->region.handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (!handler_obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * No installed handler. This shouldn't happen because the dispatch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * routine checks before we get here, but we check again just in case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) "Attempting to init a region %p, with no handler\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) region_obj));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return_ACPI_STATUS(AE_NOT_EXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *region_context = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (function == ACPI_REGION_DEACTIVATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (pci_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ACPI_FREE(pci_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) parent_node = region_obj->region.node->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Get the _SEG and _BBN values from the device upon which the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * is installed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * This is the device the handler has been registered to handle.
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * If the address_space.Node is still pointing to the root, we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * to scan upward for a PCI Root bridge and re-associate the op_region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * handlers with that device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (handler_obj->address_space.node == acpi_gbl_root_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* Start search from the parent object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) pci_root_node = parent_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) while (pci_root_node != acpi_gbl_root_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* Get the _HID/_CID in order to detect a root_bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (acpi_ev_is_pci_root_bridge(pci_root_node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* Install a handler for this PCI root bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) status = acpi_install_address_space_handler((acpi_handle)pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (status == AE_SAME_HANDLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * It is OK if the handler is already installed on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * root bridge. Still need to return a context object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * for the new PCI_Config operation region, however.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ACPI_EXCEPTION((AE_INFO, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) "Could not install PciConfig handler "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) "for Root Bridge %4.4s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) acpi_ut_get_node_name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) (pci_root_node)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) pci_root_node = pci_root_node->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* PCI root bridge not found, use namespace root node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) pci_root_node = handler_obj->address_space.node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^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) * If this region is now initialized, we are done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * (install_address_space_handler could have initialized it)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* Region is still not initialized. Create a new context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) pci_id = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pci_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (!pci_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return_ACPI_STATUS(AE_NO_MEMORY);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * For PCI_Config space access, we need the segment, bus, device and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * function numbers. Acquire them here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * Find the parent device object. (This allows the operation region to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * within a subscope under the device, such as a control method.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) pci_device_node = region_obj->region.node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) while (pci_device_node && (pci_device_node->type != ACPI_TYPE_DEVICE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) pci_device_node = pci_device_node->parent;
^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) if (!pci_device_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) ACPI_FREE(pci_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * Get the PCI device and function numbers from the _ADR object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * contained in the parent's scope.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) pci_device_node, &pci_value);
^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) * The default is zero, and since the allocation above zeroed the data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * just do nothing on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) pci_id->device = ACPI_HIWORD(ACPI_LODWORD(pci_value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) pci_id->function = ACPI_LOWORD(ACPI_LODWORD(pci_value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* The PCI segment number comes from the _SEG method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) status = acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) pci_root_node, &pci_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) pci_id->segment = ACPI_LOWORD(pci_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* The PCI bus number comes from the _BBN method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) status = acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) pci_root_node, &pci_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) pci_id->bus = ACPI_LOWORD(pci_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* Complete/update the PCI ID for this device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) acpi_hw_derive_pci_id(pci_id, pci_root_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) region_obj->region.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) ACPI_FREE(pci_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) *region_context = pci_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * FUNCTION: acpi_ev_is_pci_root_bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * PARAMETERS: node - Device node being examined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * examining the _HID and _CID for the device.
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct acpi_pnp_device_id *hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) struct acpi_pnp_device_id_list *cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) u8 match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* Get the _HID and check for a PCI Root Bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) status = acpi_ut_execute_HID(node, &hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return (FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) match = acpi_ut_is_pci_root_bridge(hid->string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) ACPI_FREE(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return (TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) status = acpi_ut_execute_CID(node, &cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return (FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* Check all _CIDs in the returned list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) for (i = 0; i < cid->count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (acpi_ut_is_pci_root_bridge(cid->ids[i].string)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) ACPI_FREE(cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return (TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ACPI_FREE(cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return (FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * FUNCTION: acpi_ev_pci_bar_region_setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * PARAMETERS: handle - Region we are interested in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * function - Start or stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * handler_context - Address space handler context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * region_context - Region specific context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * DESCRIPTION: Setup a pci_BAR operation region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * MUTEX: Assumes namespace is not locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) acpi_ev_pci_bar_region_setup(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) u32 function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) void *handler_context, void **region_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) ACPI_FUNCTION_TRACE(ev_pci_bar_region_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return_ACPI_STATUS(AE_OK);
^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) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * FUNCTION: acpi_ev_cmos_region_setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * PARAMETERS: handle - Region we are interested in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * function - Start or stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * handler_context - Address space handler context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) * region_context - Region specific context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * DESCRIPTION: Setup a CMOS operation region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * MUTEX: Assumes namespace is not locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) acpi_ev_cmos_region_setup(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) u32 function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) void *handler_context, void **region_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) ACPI_FUNCTION_TRACE(ev_cmos_region_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * FUNCTION: acpi_ev_default_region_setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * PARAMETERS: handle - Region we are interested in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * function - Start or stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * handler_context - Address space handler context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * region_context - Region specific context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * DESCRIPTION: Default region initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) acpi_ev_default_region_setup(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) u32 function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) void *handler_context, void **region_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) ACPI_FUNCTION_TRACE(ev_default_region_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (function == ACPI_REGION_DEACTIVATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) *region_context = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) *region_context = handler_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * FUNCTION: acpi_ev_initialize_region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * PARAMETERS: region_obj - Region we are initializing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * for execution at a later time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * Get the appropriate address space handler for a newly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * created region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * This also performs address space specific initialization. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * example, PCI regions must have an _ADR object that contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * a PCI address in the scope of the definition. This address is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * required to perform an access to PCI config space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * MUTEX: Interpreter should be unlocked, because we may run the _REG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * method for this region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * NOTE: Possible incompliance:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * There is a behavior conflict in automatic _REG execution:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) * 1. When the interpreter is evaluating a method, we can only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * automatically run _REG for the following case:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * operation_region (OPR1, 0x80, 0x1000010, 0x4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * 2. When the interpreter is loading a table, we can also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * automatically run _REG for the following case:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * operation_region (OPR1, 0x80, 0x1000010, 0x4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * Though this may not be compliant to the de-facto standard, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * logic is kept in order not to trigger regressions. And keeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * this logic should be taken care by the caller of this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) acpi_status acpi_ev_initialize_region(union acpi_operand_object *region_obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) union acpi_operand_object *handler_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) union acpi_operand_object *obj_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) acpi_adr_space_type space_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct acpi_namespace_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) ACPI_FUNCTION_TRACE(ev_initialize_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (!region_obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) region_obj->common.flags |= AOPOBJ_OBJECT_INITIALIZED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) node = region_obj->region.node->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) space_id = region_obj->region.space_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * The following loop depends upon the root Node having no parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * ie: acpi_gbl_root_node->Parent being set to NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) while (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) /* Check to see if a handler exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) handler_obj = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) obj_desc = acpi_ns_get_attached_object(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (obj_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) /* Can only be a handler if the object exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) switch (node->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) case ACPI_TYPE_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) case ACPI_TYPE_PROCESSOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) case ACPI_TYPE_THERMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) handler_obj = obj_desc->common_notify.handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* Ignore other objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) handler_obj =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) acpi_ev_find_region_handler(space_id, handler_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (handler_obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) /* Found correct handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) "Found handler %p for region %p in obj %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) handler_obj, region_obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) obj_desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) (void)acpi_ev_attach_region(handler_obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) region_obj, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * Tell all users that this region is usable by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * running the _REG method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) acpi_ex_exit_interpreter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) (void)acpi_ev_execute_reg_method(region_obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) ACPI_REG_CONNECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) acpi_ex_enter_interpreter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) /* This node does not have the handler we need; Pop up one level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) node = node->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * If we get here, there is no handler for this region. This is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) * fatal because many regions get created before a handler is installed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * for said region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) "No handler for RegionType %s(%X) (RegionObj %p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) acpi_ut_get_region_name(space_id), space_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) region_obj));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }