|
| 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 |
0 commit comments