1 /*
2 * Copyright (c) 2023 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include <zephyr/kernel.h>
9 #include <zephyr/acpi/acpi.h>
10
11 #define APCI_TEST_DEV ACPI_DT_HAS_HID(DT_ALIAS(acpi_dev))
12
13 #if APCI_TEST_DEV
14 #define DEV_HID ACPI_DT_HID(DT_ALIAS(acpi_dev))
15 #define DEV_UID ACPI_DT_UID(DT_ALIAS(acpi_dev))
16 #else
17 #define DEV_HID NULL
18 #define DEV_UID NULL
19 #endif
20
ZTEST(acpi,test_mcfg_table)21 ZTEST(acpi, test_mcfg_table)
22 {
23 struct acpi_mcfg *mcfg;
24
25 mcfg = acpi_table_get("MCFG", 0);
26
27 zassert_not_null(mcfg, "Failed to get MCFG table");
28 }
29
ZTEST(acpi,test_dev_enum)30 ZTEST(acpi, test_dev_enum)
31 {
32 struct acpi_dev *dev;
33 ACPI_RESOURCE *res_lst;
34 int ret;
35
36 Z_TEST_SKIP_IFNDEF(APCI_TEST_DEV);
37
38 dev = acpi_device_get(DEV_HID, DEV_UID);
39
40 zassert_not_null(dev, "Failed to get acpi device with given HID");
41
42 ret = acpi_current_resource_get(dev->path, &res_lst);
43
44 zassert_ok(ret, "Failed to get current resource setting");
45 }
46
ZTEST(acpi,test_resource_enum)47 ZTEST(acpi, test_resource_enum)
48 {
49 struct acpi_dev *dev;
50 struct acpi_irq_resource irq_res;
51 struct acpi_mmio_resource mmio_res;
52 uint16_t irqs[CONFIG_ACPI_IRQ_VECTOR_MAX];
53 struct acpi_reg_base reg_base[CONFIG_ACPI_MMIO_ENTRIES_MAX];
54 int ret;
55
56 Z_TEST_SKIP_IFNDEF(APCI_TEST_DEV);
57
58 dev = acpi_device_get(DEV_HID, DEV_UID);
59
60 zassert_not_null(dev, "Failed to get acpi device with given HID");
61
62 mmio_res.mmio_max = ARRAY_SIZE(reg_base);
63 mmio_res.reg_base = reg_base;
64 ret = acpi_device_mmio_get(dev, &mmio_res);
65
66 zassert_ok(ret, "Failed to get MMIO resources");
67
68 irq_res.irq_vector_max = ARRAY_SIZE(irqs);
69 irq_res.irqs = irqs;
70 ret = acpi_device_irq_get(dev, &irq_res);
71
72 zassert_ok(ret, "Failed to get IRQ resources");
73 }
74
75 ZTEST_SUITE(acpi, NULL, NULL, NULL, NULL, NULL);
76