Skip to content

Commit f25dfcf

Browse files
najumon1980jhedberg
authored andcommitted
lib: acpi: added acpi support using acpica lib
Add ACPI support for Zephyr using acpica open source project. ACPI subsystem use to discover and configure hardware components, perform power management (e.g. putting unused hardware components to sleep), auto configuration (e.g. Plug and Play and hot swapping) etc. Signed-off-by: Najumon Ba <[email protected]>
1 parent 9034758 commit f25dfcf

File tree

8 files changed

+1117
-1
lines changed

8 files changed

+1117
-1
lines changed

drivers/Kconfig

-1
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,4 @@ source "drivers/watchdog/Kconfig"
8282
source "drivers/wifi/Kconfig"
8383
source "drivers/xen/Kconfig"
8484
source "drivers/sip_svc/Kconfig"
85-
8685
endmenu

include/zephyr/acpi/acpi.h

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright (c) 2023 Intel Corporation.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_DRIVERS_ACPI_H_
7+
#define ZEPHYR_INCLUDE_DRIVERS_ACPI_H_
8+
#include <acpica/source/include/acpi.h>
9+
#include <zephyr/drivers/pcie/pcie.h>
10+
11+
#define ACPI_RES_INVALID ACPI_RESOURCE_TYPE_MAX
12+
13+
struct acpi_dev {
14+
ACPI_HANDLE handle;
15+
char *path;
16+
char hid[CONFIG_ACPI_HID_LEN_MAX];
17+
ACPI_RESOURCE *res_lst;
18+
int res_type;
19+
ACPI_DEVICE_INFO *dev_info;
20+
};
21+
22+
/**
23+
* @brief retrieve legacy interrupt number for a PCI device.
24+
*
25+
* @param bdf the BDF of endpoint/PCI device
26+
* @return return IRQ number or UINT_MAX if not fund
27+
*/
28+
uint32_t acpi_legacy_irq_get(pcie_bdf_t bdf);
29+
30+
/**
31+
* @brief retrieve current resource setting of a device.
32+
*
33+
* @param dev_name the name of the device
34+
* @param res the list of acpi resource list
35+
* @return return 0 on success or error code
36+
*/
37+
int acpi_current_resource_get(char *dev_name, ACPI_RESOURCE **res);
38+
39+
/**
40+
* @brief retrieve possible resource setting of a device.
41+
*
42+
* @param dev_name the name of the device
43+
* @param res the list of acpi resource list
44+
* @return return 0 on success or error code
45+
*/
46+
int acpi_possible_resource_get(char *dev_name, ACPI_RESOURCE **res);
47+
48+
/**
49+
* @brief Free current resource list memory which is retrived by
50+
* acpi_current_resource_get.
51+
*
52+
* @param res the list of acpi resource list
53+
* @return return 0 on success or error code
54+
*/
55+
int acpi_current_resource_free(ACPI_RESOURCE *res);
56+
57+
/**
58+
* @brief retrieve IRQ routing table of a bus.
59+
*
60+
* @param bus_name the name of the bus
61+
* @param rt_table the IRQ routing table
62+
* @param rt_size the the size of IRQ routing table
63+
* @return return 0 on success or error code
64+
*/
65+
int acpi_get_irq_routing_table(char *bus_name,
66+
ACPI_PCI_ROUTING_TABLE *rt_table, size_t rt_size);
67+
68+
/**
69+
* @brief parse resource table for given resource type.
70+
*
71+
* @param res the list of acpi resource list
72+
* @param res_type the acpi resource type
73+
* @return resource list for the given type on success or NULL
74+
*/
75+
ACPI_RESOURCE *acpi_resource_parse(ACPI_RESOURCE *res, int res_type);
76+
77+
/**
78+
* @brief retrieve acpi device info for given hardware id and unique id.
79+
*
80+
* @param hid the hardware id of the acpi child device
81+
* @param inst the unique id of the acpi child device
82+
* @return acpi child device info on success or NULL
83+
*/
84+
struct acpi_dev *acpi_device_get(char *hid, int inst);
85+
86+
/**
87+
* @brief retrieve acpi device info form index.
88+
*
89+
* @param index the device index of an acpi child device
90+
* @return acpi child device info on success or NULL
91+
*/
92+
struct acpi_dev *acpi_device_by_index_get(int index);
93+
94+
/**
95+
* @brief parse resource table for irq info.
96+
*
97+
* @param res_lst the list of acpi resource list
98+
* @return irq resource list on success or NULL
99+
*/
100+
static inline ACPI_RESOURCE_IRQ *acpi_irq_res_get(ACPI_RESOURCE *res_lst)
101+
{
102+
ACPI_RESOURCE *res = acpi_resource_parse(res_lst, ACPI_RESOURCE_TYPE_IRQ);
103+
104+
return res ? &res->Data.Irq : NULL;
105+
}
106+
107+
/**
108+
* @brief parse resource table for identify resource type.
109+
*
110+
* @param res the list of acpi resource list
111+
* @return resource type on success or invalid resource type
112+
*/
113+
int acpi_device_type_get(ACPI_RESOURCE *res);
114+
115+
/**
116+
* @brief retrieve acpi table for the given signature.
117+
*
118+
* @param signature pointer to the 4-character ACPI signature for the requested table
119+
* @param inst instance number for the requested table
120+
* @param acpi_table pointer to the acpi table
121+
* @return return 0 on success or error code
122+
*/
123+
int acpi_table_get(char *signature, int inst, void **acpi_table);
124+
125+
#endif

lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ add_subdirectory(hash)
99
add_subdirectory(os)
1010
add_subdirectory_ifdef(CONFIG_SMF smf)
1111
add_subdirectory_ifdef(CONFIG_OPENAMP open-amp)
12+
add_subdirectory_ifdef(CONFIG_ACPI acpi)

lib/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ source "lib/open-amp/Kconfig"
1717

1818
source "lib/smf/Kconfig"
1919

20+
source "lib/acpi/Kconfig"
2021
endmenu

lib/acpi/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
zephyr_library()
4+
5+
zephyr_library_sources(acpi.c)
6+
zephyr_library_sources_ifdef(CONFIG_ACPI_SHELL acpi_shell.c)

lib/acpi/Kconfig

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ACPI configuration options
2+
3+
# Copyright (c) 2023 Intel Corporation
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
menuconfig ACPI
7+
bool "ACPI support"
8+
help
9+
This option enables support for ACPI driver.
10+
11+
if ACPI
12+
13+
module = ACPI
14+
module-str = acpi
15+
source "subsys/logging/Kconfig.template.log_config"
16+
17+
config ACPI_MAX_PRT_ENTRY
18+
int "Size of PRT buffer"
19+
default 4096
20+
help
21+
Size of PRT table buffer.
22+
23+
config ACPI_SHELL
24+
bool "ACPI command Shell"
25+
default y
26+
depends on SHELL
27+
help
28+
Enable commands for debugging ACPI using the built-in shell.
29+
30+
config ACPI_DEV_MAX
31+
int "maximum child devices"
32+
default 1000
33+
help
34+
maximum acpi child devices.
35+
36+
config ACPI_INIT_PRIORITY
37+
int "acpi boot time init level"
38+
default 42
39+
help
40+
boot time init level for acpi driver.
41+
42+
config ACPI_MAX_INIT_TABLES
43+
int "acpi table size"
44+
default 16
45+
help
46+
acpi table size.
47+
48+
endif # ACPI
49+
50+
config ACPI_HID_LEN_MAX
51+
int "Size of HID name"
52+
default 12
53+
help
54+
Size of HID string.

0 commit comments

Comments
 (0)