Skip to content

Commit

Permalink
lib: acpi: added acpi support using acpica lib
Browse files Browse the repository at this point in the history
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 <najumon.ba@intel.com>
  • Loading branch information
najumon1980 authored and jhedberg committed Jun 30, 2023
1 parent 9034758 commit f25dfcf
Show file tree
Hide file tree
Showing 8 changed files with 1,117 additions and 1 deletion.
1 change: 0 additions & 1 deletion drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@ source "drivers/watchdog/Kconfig"
source "drivers/wifi/Kconfig"
source "drivers/xen/Kconfig"
source "drivers/sip_svc/Kconfig"

endmenu
125 changes: 125 additions & 0 deletions include/zephyr/acpi/acpi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (c) 2023 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DRIVERS_ACPI_H_
#define ZEPHYR_INCLUDE_DRIVERS_ACPI_H_
#include <acpica/source/include/acpi.h>
#include <zephyr/drivers/pcie/pcie.h>

#define ACPI_RES_INVALID ACPI_RESOURCE_TYPE_MAX

struct acpi_dev {
ACPI_HANDLE handle;
char *path;
char hid[CONFIG_ACPI_HID_LEN_MAX];
ACPI_RESOURCE *res_lst;
int res_type;
ACPI_DEVICE_INFO *dev_info;
};

/**
* @brief retrieve legacy interrupt number for a PCI device.
*
* @param bdf the BDF of endpoint/PCI device
* @return return IRQ number or UINT_MAX if not fund
*/
uint32_t acpi_legacy_irq_get(pcie_bdf_t bdf);

/**
* @brief retrieve current resource setting of a device.
*
* @param dev_name the name of the device
* @param res the list of acpi resource list
* @return return 0 on success or error code
*/
int acpi_current_resource_get(char *dev_name, ACPI_RESOURCE **res);

/**
* @brief retrieve possible resource setting of a device.
*
* @param dev_name the name of the device
* @param res the list of acpi resource list
* @return return 0 on success or error code
*/
int acpi_possible_resource_get(char *dev_name, ACPI_RESOURCE **res);

/**
* @brief Free current resource list memory which is retrived by
* acpi_current_resource_get.
*
* @param res the list of acpi resource list
* @return return 0 on success or error code
*/
int acpi_current_resource_free(ACPI_RESOURCE *res);

/**
* @brief retrieve IRQ routing table of a bus.
*
* @param bus_name the name of the bus
* @param rt_table the IRQ routing table
* @param rt_size the the size of IRQ routing table
* @return return 0 on success or error code
*/
int acpi_get_irq_routing_table(char *bus_name,
ACPI_PCI_ROUTING_TABLE *rt_table, size_t rt_size);

/**
* @brief parse resource table for given resource type.
*
* @param res the list of acpi resource list
* @param res_type the acpi resource type
* @return resource list for the given type on success or NULL
*/
ACPI_RESOURCE *acpi_resource_parse(ACPI_RESOURCE *res, int res_type);

/**
* @brief retrieve acpi device info for given hardware id and unique id.
*
* @param hid the hardware id of the acpi child device
* @param inst the unique id of the acpi child device
* @return acpi child device info on success or NULL
*/
struct acpi_dev *acpi_device_get(char *hid, int inst);

/**
* @brief retrieve acpi device info form index.
*
* @param index the device index of an acpi child device
* @return acpi child device info on success or NULL
*/
struct acpi_dev *acpi_device_by_index_get(int index);

/**
* @brief parse resource table for irq info.
*
* @param res_lst the list of acpi resource list
* @return irq resource list on success or NULL
*/
static inline ACPI_RESOURCE_IRQ *acpi_irq_res_get(ACPI_RESOURCE *res_lst)
{
ACPI_RESOURCE *res = acpi_resource_parse(res_lst, ACPI_RESOURCE_TYPE_IRQ);

return res ? &res->Data.Irq : NULL;
}

/**
* @brief parse resource table for identify resource type.
*
* @param res the list of acpi resource list
* @return resource type on success or invalid resource type
*/
int acpi_device_type_get(ACPI_RESOURCE *res);

/**
* @brief retrieve acpi table for the given signature.
*
* @param signature pointer to the 4-character ACPI signature for the requested table
* @param inst instance number for the requested table
* @param acpi_table pointer to the acpi table
* @return return 0 on success or error code
*/
int acpi_table_get(char *signature, int inst, void **acpi_table);

#endif
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ add_subdirectory(hash)
add_subdirectory(os)
add_subdirectory_ifdef(CONFIG_SMF smf)
add_subdirectory_ifdef(CONFIG_OPENAMP open-amp)
add_subdirectory_ifdef(CONFIG_ACPI acpi)
1 change: 1 addition & 0 deletions lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ source "lib/open-amp/Kconfig"

source "lib/smf/Kconfig"

source "lib/acpi/Kconfig"
endmenu
6 changes: 6 additions & 0 deletions lib/acpi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_library()

zephyr_library_sources(acpi.c)
zephyr_library_sources_ifdef(CONFIG_ACPI_SHELL acpi_shell.c)
54 changes: 54 additions & 0 deletions lib/acpi/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ACPI configuration options

# Copyright (c) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

menuconfig ACPI
bool "ACPI support"
help
This option enables support for ACPI driver.

if ACPI

module = ACPI
module-str = acpi
source "subsys/logging/Kconfig.template.log_config"

config ACPI_MAX_PRT_ENTRY
int "Size of PRT buffer"
default 4096
help
Size of PRT table buffer.

config ACPI_SHELL
bool "ACPI command Shell"
default y
depends on SHELL
help
Enable commands for debugging ACPI using the built-in shell.

config ACPI_DEV_MAX
int "maximum child devices"
default 1000
help
maximum acpi child devices.

config ACPI_INIT_PRIORITY
int "acpi boot time init level"
default 42
help
boot time init level for acpi driver.

config ACPI_MAX_INIT_TABLES
int "acpi table size"
default 16
help
acpi table size.

endif # ACPI

config ACPI_HID_LEN_MAX
int "Size of HID name"
default 12
help
Size of HID string.
Loading

0 comments on commit f25dfcf

Please sign in to comment.