| 1 | #pragma once |
| 2 | |
| 3 | #include <uacpi/status.h> |
| 4 | #include <uacpi/types.h> |
| 5 | #include <uacpi/namespace.h> |
| 6 | |
| 7 | #ifdef __cplusplus |
| 8 | extern "C" { |
| 9 | #endif |
| 10 | |
| 11 | #ifndef UACPI_BAREBONES_MODE |
| 12 | |
| 13 | /** |
| 14 | * Checks whether the device at 'node' matches any of the PNP ids provided in |
| 15 | * 'list' (terminated by a UACPI_NULL). This is done by first attempting to |
| 16 | * match the value returned from _HID and then the value(s) from _CID. |
| 17 | * |
| 18 | * Note that the presence of the device (_STA) is not verified here. |
| 19 | */ |
| 20 | uacpi_bool uacpi_device_matches_pnp_id( |
| 21 | uacpi_namespace_node *node, |
| 22 | const uacpi_char *const *list |
| 23 | ); |
| 24 | |
| 25 | /** |
| 26 | * Find all the devices in the namespace starting at 'parent' matching the |
| 27 | * specified 'hids' (terminated by a UACPI_NULL) against any value from _HID or |
| 28 | * _CID. Only devices reported as present via _STA are checked. Any matching |
| 29 | * devices are then passed to the 'cb'. |
| 30 | */ |
| 31 | uacpi_status uacpi_find_devices_at( |
| 32 | uacpi_namespace_node *parent, |
| 33 | const uacpi_char *const *hids, |
| 34 | uacpi_iteration_callback cb, |
| 35 | void *user |
| 36 | ); |
| 37 | |
| 38 | /** |
| 39 | * Same as uacpi_find_devices_at, except this starts at the root and only |
| 40 | * matches one hid. |
| 41 | */ |
| 42 | uacpi_status uacpi_find_devices( |
| 43 | const uacpi_char *hid, |
| 44 | uacpi_iteration_callback cb, |
| 45 | void *user |
| 46 | ); |
| 47 | |
| 48 | typedef enum uacpi_interrupt_model { |
| 49 | UACPI_INTERRUPT_MODEL_PIC = 0, |
| 50 | UACPI_INTERRUPT_MODEL_IOAPIC, |
| 51 | UACPI_INTERRUPT_MODEL_IOSAPIC, |
| 52 | UACPI_INTERRUPT_MODEL_PLATFORM_SPECIFIC, |
| 53 | UACPI_INTERRUPT_MODEL_GIC, |
| 54 | UACPI_INTERRUPT_MODEL_LPIC, |
| 55 | UACPI_INTERRUPT_MODEL_RINTC, |
| 56 | } uacpi_interrupt_model; |
| 57 | |
| 58 | uacpi_status uacpi_set_interrupt_model(uacpi_interrupt_model); |
| 59 | |
| 60 | typedef struct uacpi_pci_routing_table_entry { |
| 61 | uacpi_u32 address; |
| 62 | uacpi_u32 index; |
| 63 | uacpi_namespace_node *source; |
| 64 | uacpi_u8 pin; |
| 65 | } uacpi_pci_routing_table_entry; |
| 66 | |
| 67 | typedef struct uacpi_pci_routing_table { |
| 68 | uacpi_size num_entries; |
| 69 | uacpi_pci_routing_table_entry entries[]; |
| 70 | } uacpi_pci_routing_table; |
| 71 | void uacpi_free_pci_routing_table(uacpi_pci_routing_table*); |
| 72 | |
| 73 | uacpi_status uacpi_get_pci_routing_table( |
| 74 | uacpi_namespace_node *parent, uacpi_pci_routing_table **out_table |
| 75 | ); |
| 76 | |
| 77 | typedef struct uacpi_id_string { |
| 78 | // size of the string including the null byte |
| 79 | uacpi_u32 size; |
| 80 | uacpi_char *value; |
| 81 | } uacpi_id_string; |
| 82 | void uacpi_free_id_string(uacpi_id_string *id); |
| 83 | |
| 84 | /** |
| 85 | * Evaluate a device's _HID method and get its value. |
| 86 | * The returned struture must be freed using uacpi_free_id_string. |
| 87 | */ |
| 88 | uacpi_status uacpi_eval_hid(uacpi_namespace_node*, uacpi_id_string **out_id); |
| 89 | |
| 90 | typedef struct uacpi_pnp_id_list { |
| 91 | // number of 'ids' in the list |
| 92 | uacpi_u32 num_ids; |
| 93 | |
| 94 | // size of the 'ids' list including the string lengths |
| 95 | uacpi_u32 size; |
| 96 | |
| 97 | // list of PNP ids |
| 98 | uacpi_id_string ids[]; |
| 99 | } uacpi_pnp_id_list; |
| 100 | void uacpi_free_pnp_id_list(uacpi_pnp_id_list *list); |
| 101 | |
| 102 | /** |
| 103 | * Evaluate a device's _CID method and get its value. |
| 104 | * The returned structure must be freed using uacpi_free_pnp_id_list. |
| 105 | */ |
| 106 | uacpi_status uacpi_eval_cid(uacpi_namespace_node*, uacpi_pnp_id_list **out_list); |
| 107 | |
| 108 | /** |
| 109 | * Evaluate a device's _STA method and get its value. |
| 110 | * If this method is not found, the value of 'flags' is set to all ones. |
| 111 | */ |
| 112 | uacpi_status uacpi_eval_sta(uacpi_namespace_node*, uacpi_u32 *flags); |
| 113 | |
| 114 | /** |
| 115 | * Evaluate a device's _ADR method and get its value. |
| 116 | */ |
| 117 | uacpi_status uacpi_eval_adr(uacpi_namespace_node*, uacpi_u64 *out); |
| 118 | |
| 119 | /** |
| 120 | * Evaluate a device's _CLS method and get its value. |
| 121 | * The format of returned string is BBSSPP where: |
| 122 | * BB => Base Class (e.g. 01 => Mass Storage) |
| 123 | * SS => Sub-Class (e.g. 06 => SATA) |
| 124 | * PP => Programming Interface (e.g. 01 => AHCI) |
| 125 | * The returned struture must be freed using uacpi_free_id_string. |
| 126 | */ |
| 127 | uacpi_status uacpi_eval_cls(uacpi_namespace_node*, uacpi_id_string **out_id); |
| 128 | |
| 129 | /** |
| 130 | * Evaluate a device's _UID method and get its value. |
| 131 | * The returned struture must be freed using uacpi_free_id_string. |
| 132 | */ |
| 133 | uacpi_status uacpi_eval_uid(uacpi_namespace_node*, uacpi_id_string **out_uid); |
| 134 | |
| 135 | |
| 136 | // uacpi_namespace_node_info->flags |
| 137 | #define UACPI_NS_NODE_INFO_HAS_ADR (1 << 0) |
| 138 | #define UACPI_NS_NODE_INFO_HAS_HID (1 << 1) |
| 139 | #define UACPI_NS_NODE_INFO_HAS_UID (1 << 2) |
| 140 | #define UACPI_NS_NODE_INFO_HAS_CID (1 << 3) |
| 141 | #define UACPI_NS_NODE_INFO_HAS_CLS (1 << 4) |
| 142 | #define UACPI_NS_NODE_INFO_HAS_SXD (1 << 5) |
| 143 | #define UACPI_NS_NODE_INFO_HAS_SXW (1 << 6) |
| 144 | |
| 145 | typedef struct uacpi_namespace_node_info { |
| 146 | // Size of the entire structure |
| 147 | uacpi_u32 size; |
| 148 | |
| 149 | // Object information |
| 150 | uacpi_object_name name; |
| 151 | uacpi_object_type type; |
| 152 | uacpi_u8 num_params; |
| 153 | |
| 154 | // UACPI_NS_NODE_INFO_HAS_* |
| 155 | uacpi_u8 flags; |
| 156 | |
| 157 | /** |
| 158 | * A mapping of [S1..S4] to the shallowest D state supported by the device |
| 159 | * in that S state. |
| 160 | */ |
| 161 | uacpi_u8 sxd[4]; |
| 162 | |
| 163 | /** |
| 164 | * A mapping of [S0..S4] to the deepest D state supported by the device |
| 165 | * in that S state to be able to wake itself. |
| 166 | */ |
| 167 | uacpi_u8 sxw[5]; |
| 168 | |
| 169 | uacpi_u64 adr; |
| 170 | uacpi_id_string hid; |
| 171 | uacpi_id_string uid; |
| 172 | uacpi_id_string cls; |
| 173 | uacpi_pnp_id_list cid; |
| 174 | } uacpi_namespace_node_info; |
| 175 | void uacpi_free_namespace_node_info(uacpi_namespace_node_info*); |
| 176 | |
| 177 | /** |
| 178 | * Retrieve information about a namespace node. This includes the attached |
| 179 | * object's type, name, number of parameters (if it's a method), the result of |
| 180 | * evaluating _ADR, _UID, _CLS, _HID, _CID, as well as _SxD and _SxW. |
| 181 | * |
| 182 | * The returned structure must be freed with uacpi_free_namespace_node_info. |
| 183 | */ |
| 184 | uacpi_status uacpi_get_namespace_node_info( |
| 185 | uacpi_namespace_node *node, uacpi_namespace_node_info **out_info |
| 186 | ); |
| 187 | |
| 188 | #endif // !UACPI_BAREBONES_MODE |
| 189 | |
| 190 | #ifdef __cplusplus |
| 191 | } |
| 192 | #endif |
| 193 | |