Lines Matching +full:acpi +full:- +full:hid
4 * SPDX-License-Identifier: Apache-2.0
7 #include "acpi.h"
13 #include <zephyr/acpi/acpi.h>
15 LOG_MODULE_REGISTER(ACPI, CONFIG_ACPI_LOG_LEVEL);
25 } acpi = { variable
33 if (acpi.status == AE_NOT_CONFIGURED) { in check_init_status()
34 acpi.status = acpi_init(); in check_init_status()
37 if (ACPI_FAILURE(acpi.status)) { in check_init_status()
38 LOG_ERR("ACPI init was not success"); in check_init_status()
39 return -EIO; in check_init_status()
70 /* Initialize the ACPI subsystem */ in initialize_acpica()
73 ACPI_EXCEPTION((AE_INFO, status, "While initializing ACPI")); in initialize_acpica()
77 /* Initialize the ACPI Table Manager and get all ACPI tables */ in initialize_acpica()
78 if (!acpi.early_init) { in initialize_acpica()
86 /* Create the ACPI namespace from ACPI tables */ in initialize_acpica()
89 ACPI_EXCEPTION((AE_INFO, status, "While loading ACPI tables")); in initialize_acpica()
100 /* Initialize the ACPI hardware */ in initialize_acpica()
103 ACPI_EXCEPTION((AE_INFO, status, "While enabling ACPI")); in initialize_acpica()
107 /* Complete the ACPI namespace object initialization */ in initialize_acpica()
110 ACPI_EXCEPTION((AE_INFO, status, "While initializing ACPI objects")); in initialize_acpica()
152 LOG_ERR("No ACPI node with given name: %s", bus_name); in acpi_evaluate_method()
156 if (handle->Type != ACPI_TYPE_DEVICE) { in acpi_evaluate_method()
157 LOG_ERR("No ACPI node foud with given name: %s", bus_name); in acpi_evaluate_method()
166 LOG_ERR("No entry for the ACPI node with given name: %s", bus_name); in acpi_evaluate_method()
208 /* get device info such as HID, Class ID etc. */ in dev_resource_enum_callback()
215 if (acpi.num_dev >= CONFIG_ACPI_DEV_MAX) { in dev_resource_enum_callback()
219 if (!(dev_info->Valid & ACPI_VALID_HID)) { in dev_resource_enum_callback()
223 child_dev = (struct acpi_dev *)&acpi.child_dev[acpi.num_dev++]; in dev_resource_enum_callback()
224 child_dev->handle = obj_handle; in dev_resource_enum_callback()
225 child_dev->dev_info = dev_info; in dev_resource_enum_callback()
233 child_dev->path = path_name; in dev_resource_enum_callback()
243 child_dev->res_lst = rt_buffer.Pointer; in dev_resource_enum_callback()
267 if (acpi.early_init) { in acpi_early_init()
268 LOG_DBG("acpi early init already done"); in acpi_early_init()
274 LOG_ERR("Error in acpi table init:%d", status); in acpi_early_init()
275 return -EIO; in acpi_early_init()
278 acpi.early_init = true; in acpi_early_init()
293 return -EAGAIN; in acpi_current_resource_get()
299 return -ENOTSUP; in acpi_current_resource_get()
308 return -ENOTSUP; in acpi_current_resource_get()
326 return -EAGAIN; in acpi_possible_resource_get()
332 return -ENOTSUP; in acpi_possible_resource_get()
367 if (((acpi.pci_prt_table[i].Address >> 16) & 0xffff) == slot && in acpi_legacy_irq_get()
368 acpi.pci_prt_table[i].Pin + 1 == pin) { in acpi_legacy_irq_get()
370 acpi.pci_prt_table[i].SourceIndex); in acpi_legacy_irq_get()
371 return acpi.pci_prt_table[i].SourceIndex; in acpi_legacy_irq_get()
378 int acpi_legacy_irq_init(const char *hid, const char *uid) in acpi_legacy_irq_init() argument
380 struct acpi_dev *child_dev = acpi_device_get(hid, uid); in acpi_legacy_irq_init()
381 ACPI_PCI_ROUTING_TABLE *rt_table = acpi.pci_prt_table; in acpi_legacy_irq_init()
387 LOG_ERR("no such PCI bus device %s %s", hid, uid); in acpi_legacy_irq_init()
388 return -ENODEV; in acpi_legacy_irq_init()
391 node = acpi_evaluate_method(child_dev->path, METHOD_NAME__PRT); in acpi_legacy_irq_init()
393 LOG_ERR("Evaluation failed for given device: %s", child_dev->path); in acpi_legacy_irq_init()
394 return -ENODEV; in acpi_legacy_irq_init()
398 rt_buffer.Length = ARRAY_SIZE(acpi.pci_prt_table) * sizeof(ACPI_PCI_ROUTING_TABLE); in acpi_legacy_irq_init()
402 LOG_ERR("unable to retrieve IRQ Routing Table: %s", child_dev->path); in acpi_legacy_irq_init()
403 return -EIO; in acpi_legacy_irq_init()
406 if (rt_table->Source[0]) { in acpi_legacy_irq_init()
414 return -ENOENT; in acpi_legacy_irq_init()
417 for (size_t i = 0; i < ARRAY_SIZE(acpi.pci_prt_table); i++) { in acpi_legacy_irq_init()
418 if (!acpi.pci_prt_table[i].SourceIndex) { in acpi_legacy_irq_init()
423 arch_irq_set_used(acpi.pci_prt_table[i].SourceIndex); in acpi_legacy_irq_init()
434 if (!res->Length) { in acpi_resource_parse()
437 } else if (res->Type == res_type) { in acpi_resource_parse()
441 } while (res->Type != ACPI_RESOURCE_TYPE_END_TAG); in acpi_resource_parse()
443 if (res->Type == ACPI_RESOURCE_TYPE_END_TAG) { in acpi_resource_parse()
452 ACPI_RESOURCE *res = acpi_resource_parse(child_dev->res_lst, ACPI_RESOURCE_TYPE_IRQ); in acpi_device_irq_get()
455 res = acpi_resource_parse(child_dev->res_lst, ACPI_RESOURCE_TYPE_EXTENDED_IRQ); in acpi_device_irq_get()
457 return -ENODEV; in acpi_device_irq_get()
460 if (res->Data.ExtendedIrq.InterruptCount > irq_res->irq_vector_max) { in acpi_device_irq_get()
461 return -ENOMEM; in acpi_device_irq_get()
464 irq_res->irq_vector_max = res->Data.ExtendedIrq.InterruptCount; in acpi_device_irq_get()
465 for (int i = 0; i < irq_res->irq_vector_max; i++) { in acpi_device_irq_get()
466 irq_res->irqs[i] = (uint16_t)res->Data.ExtendedIrq.Interrupts[i]; in acpi_device_irq_get()
469 irq_res->flags = arch_acpi_encode_irq_flags(res->Data.ExtendedIrq.Polarity, in acpi_device_irq_get()
470 res->Data.ExtendedIrq.Triggering); in acpi_device_irq_get()
472 if (res->Data.Irq.InterruptCount > irq_res->irq_vector_max) { in acpi_device_irq_get()
473 return -ENOMEM; in acpi_device_irq_get()
476 irq_res->irq_vector_max = res->Data.Irq.InterruptCount; in acpi_device_irq_get()
477 for (int i = 0; i < irq_res->irq_vector_max; i++) { in acpi_device_irq_get()
478 irq_res->irqs[i] = (uint16_t)res->Data.Irq.Interrupts[i]; in acpi_device_irq_get()
481 irq_res->flags = arch_acpi_encode_irq_flags(res->Data.ExtendedIrq.Polarity, in acpi_device_irq_get()
482 res->Data.ExtendedIrq.Triggering); in acpi_device_irq_get()
490 ACPI_RESOURCE *res = child_dev->res_lst; in acpi_device_mmio_get()
491 struct acpi_reg_base *reg_base = mmio_res->reg_base; in acpi_device_mmio_get()
495 if (!res->Length) { in acpi_device_mmio_get()
496 LOG_DBG("Found Acpi resource with zero length!"); in acpi_device_mmio_get()
500 switch (res->Type) { in acpi_device_mmio_get()
503 reg_base[mmio_cnt].port = (uint32_t)res->Data.Io.Minimum; in acpi_device_mmio_get()
504 reg_base[mmio_cnt++].length = res->Data.Io.AddressLength; in acpi_device_mmio_get()
509 reg_base[mmio_cnt].port = (uint32_t)res->Data.FixedIo.Address; in acpi_device_mmio_get()
510 reg_base[mmio_cnt++].length = res->Data.FixedIo.AddressLength; in acpi_device_mmio_get()
515 reg_base[mmio_cnt].mmio = (uintptr_t)res->Data.Memory24.Minimum; in acpi_device_mmio_get()
516 reg_base[mmio_cnt++].length = res->Data.Memory24.AddressLength; in acpi_device_mmio_get()
521 reg_base[mmio_cnt].mmio = (uintptr_t)res->Data.Memory32.Minimum; in acpi_device_mmio_get()
522 reg_base[mmio_cnt++].length = res->Data.Memory32.AddressLength; in acpi_device_mmio_get()
527 reg_base[mmio_cnt].mmio = (uintptr_t)res->Data.FixedMemory32.Address; in acpi_device_mmio_get()
528 reg_base[mmio_cnt++].length = res->Data.FixedMemory32.AddressLength; in acpi_device_mmio_get()
533 if (mmio_cnt >= mmio_res->mmio_max && in acpi_device_mmio_get()
534 res->Type != ACPI_RESOURCE_TYPE_END_TAG) { in acpi_device_mmio_get()
535 return -ENOMEM; in acpi_device_mmio_get()
537 } while (res->Type != ACPI_RESOURCE_TYPE_END_TAG); in acpi_device_mmio_get()
540 return -ENODEV; in acpi_device_mmio_get()
543 mmio_res->mmio_max = mmio_cnt; in acpi_device_mmio_get()
552 switch (res->Type) { in acpi_res_type()
592 if (!res->Length) { in acpi_device_type_get()
601 } while (res->Type != ACPI_RESOURCE_TYPE_END_TAG); in acpi_device_type_get()
606 struct acpi_dev *acpi_device_get(const char *hid, const char *uid) in acpi_device_get() argument
618 child_dev = &acpi.child_dev[i]; in acpi_device_get()
619 if (!child_dev->path) { in acpi_device_get()
624 if (!child_dev->res_lst || !child_dev->dev_info || in acpi_device_get()
625 !child_dev->dev_info->HardwareId.Length) { in acpi_device_get()
629 if (!strcmp(hid, child_dev->dev_info->HardwareId.String)) { in acpi_device_get()
630 if (uid && child_dev->dev_info->UniqueId.Length) { in acpi_device_get()
631 if (!strcmp(child_dev->dev_info->UniqueId.String, uid)) { in acpi_device_get()
638 } while (i++ < acpi.num_dev); in acpi_device_get()
645 return index < acpi.num_dev ? &acpi.child_dev[index] : NULL; in acpi_device_by_index_get()
653 if (!acpi.early_init) { in acpi_table_get()
656 LOG_ERR("ACPI early init failed"); in acpi_table_get()
663 LOG_ERR("ACPI get table failed: %d", status); in acpi_table_get()
676 if (type == subtable->Type) { in acpi_get_subtable_entry_num()
679 offset += subtable->Length; in acpi_get_subtable_entry_num()
682 if (!subtable->Length) { in acpi_get_subtable_entry_num()
698 return -EIO; in acpi_madt_entry_get()
702 while (offset < madt->Length) { in acpi_madt_entry_get()
704 if (type == subtable->Type) { in acpi_madt_entry_get()
707 madt->Length); in acpi_madt_entry_get()
711 offset += subtable->Length; in acpi_madt_entry_get()
715 return -ENODEV; in acpi_madt_entry_get()
727 return -EIO; in acpi_dmar_entry_get()
731 while (offset < dmar->Header.Length) { in acpi_dmar_entry_get()
732 if (type == subtable->Type) { in acpi_dmar_entry_get()
736 offset += subtable->Length; in acpi_dmar_entry_get()
740 return -ENODEV; in acpi_dmar_entry_get()
746 uint16_t length = dmar->Header.Length; in acpi_dmar_foreach_subtable()
754 __ASSERT_NO_MSG(subtable->Length >= sizeof(*subtable)); in acpi_dmar_foreach_subtable()
755 __ASSERT_NO_MSG(subtable->Length <= length - offset); in acpi_dmar_foreach_subtable()
759 offset += subtable->Length; in acpi_dmar_foreach_subtable()
766 uint16_t length = hu->Header.Length; in acpi_dmar_foreach_devscope()
775 __ASSERT_NO_MSG(devscope->Length >= sizeof(*devscope)); in acpi_dmar_foreach_devscope()
776 __ASSERT_NO_MSG(devscope->Length <= length - offset); in acpi_dmar_foreach_devscope()
780 offset += devscope->Length; in acpi_dmar_foreach_devscope()
791 if (devscope->EntryType == ACPI_DMAR_SCOPE_TYPE_IOAPIC) { in devscope_handler()
798 pci_path.bits.bus = devscope->Bus; in devscope_handler()
799 pci_path.bits.device = dev_path->Device; in devscope_handler()
800 pci_path.bits.function = dev_path->Function; in devscope_handler()
810 if (subtable->Type == ACPI_DMAR_TYPE_HARDWARE_UNIT) { in subtable_handler()
824 return -ENODEV; in acpi_dmar_ioapic_get()
833 return -ENOENT; in acpi_dmar_ioapic_get()
855 scope_size = drdh->Length - sizeof(ACPI_DMAR_HARDWARE_UNIT); in acpi_drhd_get()
864 if (!subtable->Length) { in acpi_drhd_get()
868 if (scope == subtable->EntryType) { in acpi_drhd_get()
869 num_path = (subtable->Length - 6u) / 2u; in acpi_drhd_get()
873 while (num_path--) { in acpi_drhd_get()
876 return -ENOBUFS; in acpi_drhd_get()
878 dmar_id[i].bits.bus = subtable->Bus; in acpi_drhd_get()
886 offset += subtable->Length; in acpi_drhd_get()
888 if (scope_size < subtable->Length) { in acpi_drhd_get()
891 scope_size -= subtable->Length; in acpi_drhd_get()
897 return -ENODEV; in acpi_drhd_get()
927 cpu_num--; in acpi_local_apic_get()
945 return -EIO; in acpi_invoke_method()
962 LOG_ERR("Error in ACPI init:%d", status); in acpi_init()
969 LOG_WRN("Error in enable pic mode acpi method:%d", status); in acpi_init()