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