Commit | Line | Data |
---|---|---|
c942fddf | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
1da177e4 LT |
2 | /* |
3 | * acpi_bus.h - ACPI Bus Driver ($Revision: 22 $) | |
4 | * | |
5 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | |
6 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | |
1da177e4 LT |
7 | */ |
8 | ||
9 | #ifndef __ACPI_BUS_H__ | |
10 | #define __ACPI_BUS_H__ | |
11 | ||
5b327265 | 12 | #include <linux/device.h> |
8a0662d9 | 13 | #include <linux/property.h> |
1da177e4 | 14 | |
1da177e4 | 15 | struct acpi_handle_list { |
4be44fcd | 16 | u32 count; |
4c660ffe | 17 | acpi_handle *handles; |
1da177e4 LT |
18 | }; |
19 | ||
1da177e4 LT |
20 | /* acpi_utils.h */ |
21 | acpi_status | |
4be44fcd LB |
22 | acpi_extract_package(union acpi_object *package, |
23 | struct acpi_buffer *format, struct acpi_buffer *buffer); | |
1da177e4 | 24 | acpi_status |
4be44fcd LB |
25 | acpi_evaluate_integer(acpi_handle handle, |
26 | acpi_string pathname, | |
27663c58 | 27 | struct acpi_object_list *arguments, unsigned long long *data); |
6909e0f3 RW |
28 | bool acpi_evaluate_reference(acpi_handle handle, acpi_string pathname, |
29 | struct acpi_object_list *arguments, | |
30 | struct acpi_handle_list *list); | |
2e57d10a RW |
31 | bool acpi_handle_list_equal(struct acpi_handle_list *list1, |
32 | struct acpi_handle_list *list2); | |
33 | void acpi_handle_list_replace(struct acpi_handle_list *dst, | |
34 | struct acpi_handle_list *src); | |
35 | void acpi_handle_list_free(struct acpi_handle_list *list); | |
d70d141b | 36 | bool acpi_device_dep(acpi_handle target, acpi_handle match); |
275c58d7 | 37 | acpi_status |
05730c19 JL |
38 | acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code, |
39 | struct acpi_buffer *status_buf); | |
1da177e4 | 40 | |
38ac0f1b | 41 | acpi_status |
8ede06ab | 42 | acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld); |
952c63e9 JL |
43 | |
44 | bool acpi_has_method(acpi_handle handle, char *name); | |
0db98202 JL |
45 | acpi_status acpi_execute_simple_method(acpi_handle handle, char *method, |
46 | u64 arg); | |
7d2421f8 JL |
47 | acpi_status acpi_evaluate_ej0(acpi_handle handle); |
48 | acpi_status acpi_evaluate_lck(acpi_handle handle, int lock); | |
132565d8 | 49 | acpi_status acpi_evaluate_reg(acpi_handle handle, u8 space_id, u32 function); |
ebf4df8d JL |
50 | bool acpi_ata_match(acpi_handle handle); |
51 | bool acpi_bay_match(acpi_handle handle); | |
52 | bool acpi_dock_match(acpi_handle handle); | |
952c63e9 | 53 | |
94116f81 AS |
54 | bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs); |
55 | union acpi_object *acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid, | |
c7e16e52 | 56 | u64 rev, u64 func, union acpi_object *argv4); |
2c5a06e5 | 57 | #ifdef CONFIG_ACPI |
a65ac520 | 58 | static inline union acpi_object * |
94116f81 AS |
59 | acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev, |
60 | u64 func, union acpi_object *argv4, | |
61 | acpi_object_type type) | |
a65ac520 JL |
62 | { |
63 | union acpi_object *obj; | |
64 | ||
94116f81 | 65 | obj = acpi_evaluate_dsm(handle, guid, rev, func, argv4); |
a65ac520 JL |
66 | if (obj && obj->type != type) { |
67 | ACPI_FREE(obj); | |
68 | obj = NULL; | |
69 | } | |
70 | ||
71 | return obj; | |
72 | } | |
2c5a06e5 | 73 | #endif |
a65ac520 JL |
74 | |
75 | #define ACPI_INIT_DSM_ARGV4(cnt, eles) \ | |
76 | { \ | |
77 | .package.type = ACPI_TYPE_PACKAGE, \ | |
78 | .package.count = (cnt), \ | |
79 | .package.elements = (eles) \ | |
80 | } | |
81 | ||
c68ae33e | 82 | bool acpi_dev_found(const char *hid); |
8661423e | 83 | bool acpi_dev_present(const char *hid, const char *uid, s64 hrv); |
8eb99e9a | 84 | bool acpi_reduced_hardware(void); |
2d12b6b3 | 85 | |
76f58584 | 86 | #ifdef CONFIG_ACPI |
1da177e4 | 87 | |
df23e2be | 88 | struct proc_dir_entry; |
1da177e4 LT |
89 | |
90 | #define ACPI_BUS_FILE_ROOT "acpi" | |
4be44fcd | 91 | extern struct proc_dir_entry *acpi_root_dir; |
1da177e4 | 92 | |
1da177e4 | 93 | enum acpi_bus_device_type { |
4be44fcd | 94 | ACPI_BUS_TYPE_DEVICE = 0, |
1da177e4 LT |
95 | ACPI_BUS_TYPE_POWER, |
96 | ACPI_BUS_TYPE_PROCESSOR, | |
97 | ACPI_BUS_TYPE_THERMAL, | |
1da177e4 LT |
98 | ACPI_BUS_TYPE_POWER_BUTTON, |
99 | ACPI_BUS_TYPE_SLEEP_BUTTON, | |
a64a62ce | 100 | ACPI_BUS_TYPE_ECDT_EC, |
1da177e4 LT |
101 | ACPI_BUS_DEVICE_TYPE_COUNT |
102 | }; | |
103 | ||
104 | struct acpi_driver; | |
105 | struct acpi_device; | |
106 | ||
ca589f94 RW |
107 | /* |
108 | * ACPI Scan Handler | |
109 | * ----------------- | |
110 | */ | |
111 | ||
a33ec399 | 112 | struct acpi_hotplug_profile { |
3f8055c3 | 113 | struct kobject kobj; |
3338db00 | 114 | int (*scan_dependent)(struct acpi_device *adev); |
8ab17fc9 | 115 | void (*notify_online)(struct acpi_device *adev); |
d22ddcbc RW |
116 | bool enabled:1; |
117 | bool demand_offline:1; | |
a33ec399 RW |
118 | }; |
119 | ||
3f8055c3 RW |
120 | static inline struct acpi_hotplug_profile *to_acpi_hotplug_profile( |
121 | struct kobject *kobj) | |
122 | { | |
123 | return container_of(kobj, struct acpi_hotplug_profile, kobj); | |
124 | } | |
125 | ||
ca589f94 RW |
126 | struct acpi_scan_handler { |
127 | const struct acpi_device_id *ids; | |
128 | struct list_head list_node; | |
636c19d3 | 129 | bool (*match)(const char *idstr, const struct acpi_device_id **matchid); |
ca589f94 RW |
130 | int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id); |
131 | void (*detach)(struct acpi_device *dev); | |
9cb32acf RW |
132 | void (*bind)(struct device *phys_dev); |
133 | void (*unbind)(struct device *phys_dev); | |
a33ec399 | 134 | struct acpi_hotplug_profile hotplug; |
ca589f94 RW |
135 | }; |
136 | ||
3c2cc7ff RW |
137 | /* |
138 | * ACPI Hotplug Context | |
139 | * -------------------- | |
140 | */ | |
141 | ||
142 | struct acpi_hotplug_context { | |
143 | struct acpi_device *self; | |
be27b3dc RW |
144 | int (*notify)(struct acpi_device *, u32); |
145 | void (*uevent)(struct acpi_device *, u32); | |
59b42fa0 | 146 | void (*fixup)(struct acpi_device *); |
3c2cc7ff RW |
147 | }; |
148 | ||
1da177e4 LT |
149 | /* |
150 | * ACPI Driver | |
151 | * ----------- | |
152 | */ | |
153 | ||
4be44fcd | 154 | typedef int (*acpi_op_add) (struct acpi_device * device); |
6c0eb5ba | 155 | typedef void (*acpi_op_remove) (struct acpi_device *device); |
46ec8598 | 156 | typedef void (*acpi_op_notify) (struct acpi_device * device, u32 event); |
1da177e4 LT |
157 | |
158 | struct acpi_device_ops { | |
4be44fcd LB |
159 | acpi_op_add add; |
160 | acpi_op_remove remove; | |
46ec8598 | 161 | acpi_op_notify notify; |
1da177e4 LT |
162 | }; |
163 | ||
6d278131 BH |
164 | #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */ |
165 | ||
1da177e4 | 166 | struct acpi_driver { |
4be44fcd LB |
167 | char name[80]; |
168 | char class[80]; | |
8c8eb78f | 169 | const struct acpi_device_id *ids; /* Supported Hardware IDs */ |
6d278131 | 170 | unsigned int flags; |
4be44fcd | 171 | struct acpi_device_ops ops; |
d43ec68e | 172 | struct device_driver drv; |
1da177e4 LT |
173 | }; |
174 | ||
175 | /* | |
176 | * ACPI Device | |
177 | * ----------- | |
178 | */ | |
179 | ||
180 | /* Status (_STA) */ | |
181 | ||
182 | struct acpi_device_status { | |
4be44fcd LB |
183 | u32 present:1; |
184 | u32 enabled:1; | |
185 | u32 show_in_ui:1; | |
186 | u32 functional:1; | |
187 | u32 battery_present:1; | |
188 | u32 reserved:27; | |
1da177e4 LT |
189 | }; |
190 | ||
1da177e4 LT |
191 | /* Flags */ |
192 | ||
193 | struct acpi_device_flags { | |
4be44fcd | 194 | u32 dynamic_status:1; |
4be44fcd LB |
195 | u32 removable:1; |
196 | u32 ejectable:1; | |
4be44fcd | 197 | u32 power_manageable:1; |
209d3b17 | 198 | u32 match_driver:1; |
202317a5 RW |
199 | u32 initialized:1; |
200 | u32 visited:1; | |
3c2cc7ff | 201 | u32 hotplug_notify:1; |
1e2380cd | 202 | u32 is_dock_station:1; |
5c53b262 | 203 | u32 of_compatible_ok:1; |
d0562674 SS |
204 | u32 coherent_dma:1; |
205 | u32 cca_seen:1; | |
d87fb091 | 206 | u32 enumeration_by_parent:1; |
9d9bcae4 HG |
207 | u32 honor_deps:1; |
208 | u32 reserved:18; | |
1da177e4 LT |
209 | }; |
210 | ||
1da177e4 LT |
211 | /* File System */ |
212 | ||
213 | struct acpi_device_dir { | |
4be44fcd | 214 | struct proc_dir_entry *entry; |
1da177e4 LT |
215 | }; |
216 | ||
217 | #define acpi_device_dir(d) ((d)->dir.entry) | |
218 | ||
1da177e4 LT |
219 | /* Plug and Play */ |
220 | ||
24c5c4c2 | 221 | typedef char acpi_bus_id[8]; |
ca6f998c | 222 | typedef u64 acpi_bus_address; |
4be44fcd LB |
223 | typedef char acpi_device_name[40]; |
224 | typedef char acpi_device_class[20]; | |
1da177e4 | 225 | |
7f47fa6c BH |
226 | struct acpi_hardware_id { |
227 | struct list_head list; | |
844142c3 | 228 | const char *id; |
7f47fa6c BH |
229 | }; |
230 | ||
d4e1a692 TK |
231 | struct acpi_pnp_type { |
232 | u32 hardware_id:1; | |
233 | u32 bus_address:1; | |
549e6845 | 234 | u32 platform_id:1; |
f64e4275 HG |
235 | u32 backlight:1; |
236 | u32 reserved:28; | |
d4e1a692 TK |
237 | }; |
238 | ||
1da177e4 | 239 | struct acpi_device_pnp { |
d4e1a692 | 240 | acpi_bus_id bus_id; /* Object name */ |
eb50aaf9 | 241 | int instance_no; /* Instance number of this object */ |
d4e1a692 | 242 | struct acpi_pnp_type type; /* ID type */ |
4be44fcd | 243 | acpi_bus_address bus_address; /* _ADR */ |
d4e1a692 | 244 | char *unique_id; /* _UID */ |
7f47fa6c | 245 | struct list_head ids; /* _HID and _CIDs */ |
4be44fcd LB |
246 | acpi_device_name device_name; /* Driver-determined */ |
247 | acpi_device_class device_class; /* " */ | |
d1efe3c3 | 248 | union acpi_object *str_obj; /* unicode string for _STR method */ |
1da177e4 LT |
249 | }; |
250 | ||
251 | #define acpi_device_bid(d) ((d)->pnp.bus_id) | |
252 | #define acpi_device_adr(d) ((d)->pnp.bus_address) | |
620e112c | 253 | const char *acpi_device_hid(struct acpi_device *device); |
359597cb | 254 | #define acpi_device_uid(d) ((d)->pnp.unique_id) |
1da177e4 LT |
255 | #define acpi_device_name(d) ((d)->pnp.device_name) |
256 | #define acpi_device_class(d) ((d)->pnp.device_class) | |
257 | ||
1da177e4 LT |
258 | /* Power Management */ |
259 | ||
260 | struct acpi_device_power_flags { | |
4be44fcd LB |
261 | u32 explicit_get:1; /* _PSC present? */ |
262 | u32 power_resources:1; /* Power resources */ | |
263 | u32 inrush_current:1; /* Serialize Dx->D0 */ | |
264 | u32 power_removed:1; /* Optimize Dx->D0 */ | |
644f17ad | 265 | u32 ignore_parent:1; /* Power is independent of parent power state */ |
f25c0ae2 RW |
266 | u32 dsw_present:1; /* _DSW present? */ |
267 | u32 reserved:26; | |
1da177e4 LT |
268 | }; |
269 | ||
270 | struct acpi_device_power_state { | |
271 | struct { | |
4be44fcd LB |
272 | u8 valid:1; |
273 | u8 explicit_set:1; /* _PSx present? */ | |
274 | u8 reserved:6; | |
275 | } flags; | |
276 | int power; /* % Power (compared to D0) */ | |
277 | int latency; /* Dx->D0 time (microseconds) */ | |
0b224527 | 278 | struct list_head resources; /* Power resources referenced */ |
1da177e4 LT |
279 | }; |
280 | ||
281 | struct acpi_device_power { | |
4be44fcd | 282 | int state; /* Current state */ |
1da177e4 | 283 | struct acpi_device_power_flags flags; |
b4a03b9a | 284 | struct acpi_device_power_state states[ACPI_D_STATE_COUNT]; /* Power states (D0-D3Cold) */ |
b340c7d6 | 285 | u8 state_for_enumeration; /* Deepest power state for enumeration */ |
1da177e4 LT |
286 | }; |
287 | ||
a9e10e58 DS |
288 | struct acpi_dep_data { |
289 | struct list_head node; | |
290 | acpi_handle supplier; | |
291 | acpi_handle consumer; | |
9d9bcae4 | 292 | bool honor_dep; |
3ba12d8d RW |
293 | bool met; |
294 | bool free_when_met; | |
a9e10e58 DS |
295 | }; |
296 | ||
1da177e4 LT |
297 | /* Performance Management */ |
298 | ||
299 | struct acpi_device_perf_flags { | |
4be44fcd | 300 | u8 reserved:8; |
1da177e4 LT |
301 | }; |
302 | ||
303 | struct acpi_device_perf_state { | |
304 | struct { | |
4be44fcd LB |
305 | u8 valid:1; |
306 | u8 reserved:7; | |
307 | } flags; | |
308 | u8 power; /* % Power (compared to P0) */ | |
309 | u8 performance; /* % Performance ( " ) */ | |
310 | int latency; /* Px->P0 time (microseconds) */ | |
1da177e4 LT |
311 | }; |
312 | ||
313 | struct acpi_device_perf { | |
4be44fcd | 314 | int state; |
1da177e4 | 315 | struct acpi_device_perf_flags flags; |
4be44fcd | 316 | int state_count; |
1da177e4 LT |
317 | struct acpi_device_perf_state *states; |
318 | }; | |
319 | ||
320 | /* Wakeup Management */ | |
321 | struct acpi_device_wakeup_flags { | |
4be44fcd | 322 | u8 valid:1; /* Can successfully enable wakeup? */ |
b67ea761 | 323 | u8 notifier_present:1; /* Wake-up notify handler has been installed */ |
1da177e4 LT |
324 | }; |
325 | ||
c072530f | 326 | struct acpi_device_wakeup_context { |
64fd1c70 | 327 | void (*func)(struct acpi_device_wakeup_context *context); |
c072530f RW |
328 | struct device *dev; |
329 | }; | |
330 | ||
1da177e4 | 331 | struct acpi_device_wakeup { |
4be44fcd | 332 | acpi_handle gpe_device; |
439913ff LM |
333 | u64 gpe_number; |
334 | u64 sleep_state; | |
993cbe59 | 335 | struct list_head resources; |
4be44fcd | 336 | struct acpi_device_wakeup_flags flags; |
c072530f RW |
337 | struct acpi_device_wakeup_context context; |
338 | struct wakeup_source *ws; | |
9b83ccd2 | 339 | int prepare_count; |
99d8845e | 340 | int enable_count; |
1da177e4 LT |
341 | }; |
342 | ||
1033f904 | 343 | struct acpi_device_physical_node { |
007ccfcf | 344 | unsigned int node_id; |
1033f904 LT |
345 | struct list_head node; |
346 | struct device *dev; | |
683058e3 | 347 | bool put_online:1; |
1033f904 | 348 | }; |
1da177e4 | 349 | |
5f5e4890 MW |
350 | struct acpi_device_properties { |
351 | const guid_t *guid; | |
103e10c6 | 352 | union acpi_object *properties; |
5f5e4890 | 353 | struct list_head list; |
103e10c6 | 354 | void **bufs; |
5f5e4890 MW |
355 | }; |
356 | ||
ffdcd955 MW |
357 | /* ACPI Device Specific Data (_DSD) */ |
358 | struct acpi_device_data { | |
359 | const union acpi_object *pointer; | |
5f5e4890 | 360 | struct list_head properties; |
733e6251 | 361 | const union acpi_object *of_compatible; |
445b0eb0 | 362 | struct list_head subnodes; |
ffdcd955 MW |
363 | }; |
364 | ||
f028d524 RW |
365 | struct acpi_gpio_mapping; |
366 | ||
a6cb0a61 RW |
367 | #define ACPI_DEVICE_SWNODE_ROOT 0 |
368 | ||
369 | /* | |
370 | * The maximum expected number of CSI-2 data lanes. | |
371 | * | |
372 | * This number is not expected to ever have to be equal to or greater than the | |
373 | * number of bits in an unsigned long variable, but if it needs to be increased | |
374 | * above that limit, code will need to be adjusted accordingly. | |
375 | */ | |
693c667b RW |
376 | #define ACPI_DEVICE_CSI2_DATA_LANES 8 |
377 | ||
378 | #define ACPI_DEVICE_SWNODE_PORT_NAME_LENGTH 8 | |
379 | ||
a6cb0a61 | 380 | enum acpi_device_swnode_dev_props { |
f533e43a | 381 | ACPI_DEVICE_SWNODE_DEV_ROTATION, |
4cd57d6d SA |
382 | ACPI_DEVICE_SWNODE_DEV_CLOCK_FREQUENCY, |
383 | ACPI_DEVICE_SWNODE_DEV_LED_MAX_MICROAMP, | |
384 | ACPI_DEVICE_SWNODE_DEV_FLASH_MAX_MICROAMP, | |
385 | ACPI_DEVICE_SWNODE_DEV_FLASH_MAX_TIMEOUT_US, | |
a6cb0a61 RW |
386 | ACPI_DEVICE_SWNODE_DEV_NUM_OF, |
387 | ACPI_DEVICE_SWNODE_DEV_NUM_ENTRIES | |
388 | }; | |
389 | ||
693c667b RW |
390 | enum acpi_device_swnode_port_props { |
391 | ACPI_DEVICE_SWNODE_PORT_REG, | |
392 | ACPI_DEVICE_SWNODE_PORT_NUM_OF, | |
393 | ACPI_DEVICE_SWNODE_PORT_NUM_ENTRIES | |
394 | }; | |
395 | ||
396 | enum acpi_device_swnode_ep_props { | |
397 | ACPI_DEVICE_SWNODE_EP_REMOTE_EP, | |
398 | ACPI_DEVICE_SWNODE_EP_BUS_TYPE, | |
399 | ACPI_DEVICE_SWNODE_EP_REG, | |
400 | ACPI_DEVICE_SWNODE_EP_CLOCK_LANES, | |
401 | ACPI_DEVICE_SWNODE_EP_DATA_LANES, | |
402 | ACPI_DEVICE_SWNODE_EP_LANE_POLARITIES, | |
403 | /* TX only */ | |
404 | ACPI_DEVICE_SWNODE_EP_LINK_FREQUENCIES, | |
405 | ACPI_DEVICE_SWNODE_EP_NUM_OF, | |
406 | ACPI_DEVICE_SWNODE_EP_NUM_ENTRIES | |
407 | }; | |
408 | ||
409 | /* | |
410 | * Each device has a root software node plus two times as many nodes as the | |
411 | * number of CSI-2 ports. | |
412 | */ | |
413 | #define ACPI_DEVICE_SWNODE_PORT(port) (2 * (port) + 1) | |
414 | #define ACPI_DEVICE_SWNODE_EP(endpoint) \ | |
415 | (ACPI_DEVICE_SWNODE_PORT(endpoint) + 1) | |
416 | ||
417 | /** | |
418 | * struct acpi_device_software_node_port - MIPI DisCo for Imaging CSI-2 port | |
419 | * @port_name: Port name. | |
420 | * @data_lanes: "data-lanes" property values. | |
421 | * @lane_polarities: "lane-polarities" property values. | |
422 | * @link_frequencies: "link_frequencies" property values. | |
423 | * @port_nr: Port number. | |
424 | * @crs_crs2_local: _CRS CSI2 record present (i.e. this is a transmitter one). | |
425 | * @port_props: Port properties. | |
426 | * @ep_props: Endpoint properties. | |
427 | * @remote_ep: Reference to the remote endpoint. | |
428 | */ | |
bd721b93 | 429 | struct acpi_device_software_node_port { |
693c667b RW |
430 | char port_name[ACPI_DEVICE_SWNODE_PORT_NAME_LENGTH + 1]; |
431 | u32 data_lanes[ACPI_DEVICE_CSI2_DATA_LANES]; | |
432 | u32 lane_polarities[ACPI_DEVICE_CSI2_DATA_LANES + 1 /* clock lane */]; | |
433 | u64 link_frequencies[ACPI_DEVICE_CSI2_DATA_LANES]; | |
bd721b93 | 434 | unsigned int port_nr; |
693c667b RW |
435 | bool crs_csi2_local; |
436 | ||
437 | struct property_entry port_props[ACPI_DEVICE_SWNODE_PORT_NUM_ENTRIES]; | |
438 | struct property_entry ep_props[ACPI_DEVICE_SWNODE_EP_NUM_ENTRIES]; | |
439 | ||
440 | struct software_node_ref_args remote_ep[1]; | |
bd721b93 RW |
441 | }; |
442 | ||
443 | /** | |
444 | * struct acpi_device_software_nodes - Software nodes for an ACPI device | |
a6cb0a61 | 445 | * @dev_props: Device properties. |
bd721b93 RW |
446 | * @nodes: Software nodes for root as well as ports and endpoints. |
447 | * @nodeprts: Array of software node pointers, for (un)registering them. | |
448 | * @ports: Information related to each port and endpoint within a port. | |
449 | * @num_ports: The number of ports. | |
450 | */ | |
451 | struct acpi_device_software_nodes { | |
a6cb0a61 | 452 | struct property_entry dev_props[ACPI_DEVICE_SWNODE_DEV_NUM_ENTRIES]; |
bd721b93 RW |
453 | struct software_node *nodes; |
454 | const struct software_node **nodeptrs; | |
455 | struct acpi_device_software_node_port *ports; | |
456 | unsigned int num_ports; | |
457 | }; | |
458 | ||
1033f904 | 459 | /* Device */ |
1da177e4 | 460 | struct acpi_device { |
882c982d | 461 | u32 pld_crc; |
caaa6efb BH |
462 | int device_type; |
463 | acpi_handle handle; /* no handle for fixed hardware */ | |
8a0662d9 | 464 | struct fwnode_handle fwnode; |
4be44fcd | 465 | struct list_head wakeup_list; |
d783156e | 466 | struct list_head del_list; |
1da177e4 LT |
467 | struct acpi_device_status status; |
468 | struct acpi_device_flags flags; | |
4be44fcd | 469 | struct acpi_device_pnp pnp; |
1da177e4 LT |
470 | struct acpi_device_power power; |
471 | struct acpi_device_wakeup wakeup; | |
4be44fcd LB |
472 | struct acpi_device_perf performance; |
473 | struct acpi_device_dir dir; | |
ffdcd955 | 474 | struct acpi_device_data data; |
ca589f94 | 475 | struct acpi_scan_handler *handler; |
3c2cc7ff | 476 | struct acpi_hotplug_context *hp; |
a6cb0a61 | 477 | struct acpi_device_software_nodes *swnodes; |
f028d524 | 478 | const struct acpi_gpio_mapping *driver_gpios; |
4be44fcd | 479 | void *driver_data; |
5b327265 | 480 | struct device dev; |
007ccfcf | 481 | unsigned int physical_node_count; |
40e7fcb1 | 482 | unsigned int dep_unmet; |
1033f904 LT |
483 | struct list_head physical_node_list; |
484 | struct mutex physical_node_lock; | |
b1c0f99b | 485 | void (*remove)(struct acpi_device *); |
1da177e4 LT |
486 | }; |
487 | ||
445b0eb0 RW |
488 | /* Non-device subnode */ |
489 | struct acpi_data_node { | |
490 | const char *name; | |
263b4c1a | 491 | acpi_handle handle; |
445b0eb0 | 492 | struct fwnode_handle fwnode; |
dfa672fb | 493 | struct fwnode_handle *parent; |
445b0eb0 RW |
494 | struct acpi_device_data data; |
495 | struct list_head sibling; | |
263b4c1a RW |
496 | struct kobject kobj; |
497 | struct completion kobj_done; | |
445b0eb0 RW |
498 | }; |
499 | ||
db3e50f3 SA |
500 | extern const struct fwnode_operations acpi_device_fwnode_ops; |
501 | extern const struct fwnode_operations acpi_data_fwnode_ops; | |
502 | extern const struct fwnode_operations acpi_static_fwnode_ops; | |
3a7a2ab8 | 503 | |
9e987b70 JH |
504 | bool is_acpi_device_node(const struct fwnode_handle *fwnode); |
505 | bool is_acpi_data_node(const struct fwnode_handle *fwnode); | |
8a0662d9 | 506 | |
9e987b70 | 507 | static inline bool is_acpi_node(const struct fwnode_handle *fwnode) |
8a0662d9 | 508 | { |
9e987b70 | 509 | return (is_acpi_device_node(fwnode) || is_acpi_data_node(fwnode)); |
8a0662d9 RW |
510 | } |
511 | ||
8b9d6802 SA |
512 | #define to_acpi_device_node(__fwnode) \ |
513 | ({ \ | |
514 | typeof(__fwnode) __to_acpi_device_node_fwnode = __fwnode; \ | |
515 | \ | |
516 | is_acpi_device_node(__to_acpi_device_node_fwnode) ? \ | |
517 | container_of(__to_acpi_device_node_fwnode, \ | |
518 | struct acpi_device, fwnode) : \ | |
519 | NULL; \ | |
520 | }) | |
521 | ||
8b9d6802 SA |
522 | #define to_acpi_data_node(__fwnode) \ |
523 | ({ \ | |
524 | typeof(__fwnode) __to_acpi_data_node_fwnode = __fwnode; \ | |
525 | \ | |
526 | is_acpi_data_node(__to_acpi_data_node_fwnode) ? \ | |
527 | container_of(__to_acpi_data_node_fwnode, \ | |
528 | struct acpi_data_node, fwnode) : \ | |
529 | NULL; \ | |
530 | }) | |
531 | ||
532 | static inline bool is_acpi_static_node(const struct fwnode_handle *fwnode) | |
3a7a2ab8 | 533 | { |
db3e50f3 SA |
534 | return !IS_ERR_OR_NULL(fwnode) && |
535 | fwnode->ops == &acpi_static_fwnode_ops; | |
3a7a2ab8 RW |
536 | } |
537 | ||
8b9d6802 | 538 | static inline bool acpi_data_node_match(const struct fwnode_handle *fwnode, |
613e9721 AT |
539 | const char *name) |
540 | { | |
541 | return is_acpi_data_node(fwnode) ? | |
542 | (!strcmp(to_acpi_data_node(fwnode)->name, name)) : false; | |
543 | } | |
544 | ||
8a0662d9 RW |
545 | static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev) |
546 | { | |
547 | return &adev->fwnode; | |
548 | } | |
549 | ||
db89b4f0 PM |
550 | static inline void *acpi_driver_data(struct acpi_device *d) |
551 | { | |
552 | return d->driver_data; | |
553 | } | |
554 | ||
d43ec68e PM |
555 | #define to_acpi_device(d) container_of(d, struct acpi_device, dev) |
556 | #define to_acpi_driver(d) container_of(d, struct acpi_driver, drv) | |
1da177e4 | 557 | |
62fcb99b RW |
558 | static inline struct acpi_device *acpi_dev_parent(struct acpi_device *adev) |
559 | { | |
560 | if (adev->dev.parent) | |
561 | return to_acpi_device(adev->dev.parent); | |
562 | ||
563 | return NULL; | |
564 | } | |
565 | ||
25db115b RW |
566 | static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta) |
567 | { | |
568 | *((u32 *)&adev->status) = sta; | |
569 | } | |
570 | ||
3c2cc7ff | 571 | static inline void acpi_set_hp_context(struct acpi_device *adev, |
ba574dc8 | 572 | struct acpi_hotplug_context *hp) |
3c2cc7ff RW |
573 | { |
574 | hp->self = adev; | |
3c2cc7ff RW |
575 | adev->hp = hp; |
576 | } | |
577 | ||
5d513205 RW |
578 | void acpi_initialize_hp_context(struct acpi_device *adev, |
579 | struct acpi_hotplug_context *hp, | |
580 | int (*notify)(struct acpi_device *, u32), | |
581 | void (*uevent)(struct acpi_device *, u32)); | |
582 | ||
55955aad | 583 | /* acpi_device.dev.bus == &acpi_bus_type */ |
592190b5 | 584 | extern const struct bus_type acpi_bus_type; |
55955aad | 585 | |
3c36fe93 | 586 | int acpi_bus_for_each_dev(int (*fn)(struct device *, void *), void *data); |
cf6ba075 | 587 | int acpi_dev_for_each_child(struct acpi_device *adev, |
10fa1b2c | 588 | int (*fn)(struct acpi_device *, void *), void *data); |
ff32e599 RW |
589 | int acpi_dev_for_each_child_reverse(struct acpi_device *adev, |
590 | int (*fn)(struct acpi_device *, void *), | |
591 | void *data); | |
3c36fe93 | 592 | |
1da177e4 LT |
593 | /* |
594 | * Events | |
595 | * ------ | |
596 | */ | |
597 | ||
598 | struct acpi_bus_event { | |
4be44fcd LB |
599 | struct list_head node; |
600 | acpi_device_class device_class; | |
601 | acpi_bus_id bus_id; | |
602 | u32 type; | |
603 | u32 data; | |
1da177e4 LT |
604 | }; |
605 | ||
99e0d2fc | 606 | extern struct kobject *acpi_kobj; |
962ce8ca | 607 | extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int); |
8e4319c4 | 608 | void acpi_bus_private_data_handler(acpi_handle, void *); |
20733939 | 609 | int acpi_bus_get_private_data(acpi_handle, void **); |
72013795 LT |
610 | int acpi_bus_attach_private_data(acpi_handle, void *); |
611 | void acpi_bus_detach_private_data(acpi_handle); | |
c542ce36 MW |
612 | int acpi_dev_install_notify_handler(struct acpi_device *adev, |
613 | u32 handler_type, | |
470508f6 | 614 | acpi_notify_handler handler, void *context); |
c542ce36 MW |
615 | void acpi_dev_remove_notify_handler(struct acpi_device *adev, |
616 | u32 handler_type, | |
617 | acpi_notify_handler handler); | |
9ee85241 ZR |
618 | extern int acpi_notifier_call_chain(struct acpi_device *, u32, u32); |
619 | extern int register_acpi_notifier(struct notifier_block *); | |
620 | extern int unregister_acpi_notifier(struct notifier_block *); | |
6bd00a61 | 621 | |
1da177e4 LT |
622 | /* |
623 | * External Functions | |
624 | */ | |
625 | ||
402ac536 BH |
626 | acpi_status acpi_bus_get_status_handle(acpi_handle handle, |
627 | unsigned long long *sta); | |
4be44fcd | 628 | int acpi_bus_get_status(struct acpi_device *device); |
9ce4e607 | 629 | |
4be44fcd | 630 | int acpi_bus_set_power(acpi_handle handle, int state); |
96bfd3ce | 631 | const char *acpi_power_state_string(int state); |
078eb126 | 632 | int acpi_device_set_power(struct acpi_device *device, int state); |
9ce4e607 | 633 | int acpi_bus_init_power(struct acpi_device *device); |
b9e95fc6 | 634 | int acpi_device_fix_up_power(struct acpi_device *device); |
a22f18bd | 635 | void acpi_device_fix_up_power_extended(struct acpi_device *adev); |
37ba91a8 | 636 | void acpi_device_fix_up_power_children(struct acpi_device *adev); |
25eed407 | 637 | int acpi_bus_update_power(acpi_handle handle, int *state_p); |
2bb3a2bf | 638 | int acpi_device_update_power(struct acpi_device *device, int *state_p); |
3737b2b1 | 639 | bool acpi_bus_power_manageable(acpi_handle handle); |
b7dd6298 | 640 | void acpi_dev_power_up_children_with_adr(struct acpi_device *adev); |
8133844a | 641 | u8 acpi_dev_power_state_for_wake(struct acpi_device *adev); |
4533771c MW |
642 | int acpi_device_power_add_dependent(struct acpi_device *adev, |
643 | struct device *dev); | |
644 | void acpi_device_power_remove_dependent(struct acpi_device *adev, | |
645 | struct device *dev); | |
ec4602a9 RW |
646 | |
647 | #ifdef CONFIG_PM | |
eb9d0fe4 | 648 | bool acpi_bus_can_wakeup(acpi_handle handle); |
ec4602a9 RW |
649 | #else |
650 | static inline bool acpi_bus_can_wakeup(acpi_handle handle) { return false; } | |
651 | #endif | |
9ce4e607 | 652 | |
3757b948 RW |
653 | void acpi_scan_lock_acquire(void); |
654 | void acpi_scan_lock_release(void); | |
e525506f RW |
655 | void acpi_lock_hp_context(void); |
656 | void acpi_unlock_hp_context(void); | |
ca589f94 | 657 | int acpi_scan_add_handler(struct acpi_scan_handler *handler); |
48b9c486 KK |
658 | /* |
659 | * use a macro to avoid include chaining to get THIS_MODULE | |
660 | */ | |
661 | #define acpi_bus_register_driver(drv) \ | |
662 | __acpi_bus_register_driver(drv, THIS_MODULE) | |
663 | int __acpi_bus_register_driver(struct acpi_driver *driver, struct module *owner); | |
06ea8e08 | 664 | void acpi_bus_unregister_driver(struct acpi_driver *driver); |
b8bd759a | 665 | int acpi_bus_scan(acpi_handle handle); |
bfee26db | 666 | void acpi_bus_trim(struct acpi_device *start); |
fd350943 | 667 | acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd); |
8c8eb78f TR |
668 | int acpi_match_device_ids(struct acpi_device *device, |
669 | const struct acpi_device_id *ids); | |
51ede5d9 DD |
670 | void acpi_set_modalias(struct acpi_device *adev, const char *default_id, |
671 | char *modalias, size_t len); | |
1da177e4 | 672 | |
202317a5 RW |
673 | static inline bool acpi_device_enumerated(struct acpi_device *adev) |
674 | { | |
675 | return adev && adev->flags.initialized && adev->flags.visited; | |
676 | } | |
677 | ||
0d2cf8f5 MW |
678 | /** |
679 | * module_acpi_driver(acpi_driver) - Helper macro for registering an ACPI driver | |
680 | * @__acpi_driver: acpi_driver struct | |
681 | * | |
682 | * Helper macro for ACPI drivers which do not do anything special in module | |
683 | * init/exit. This eliminates a lot of boilerplate. Each module may only | |
684 | * use this macro once, and calling it replaces module_init() and module_exit() | |
685 | */ | |
686 | #define module_acpi_driver(__acpi_driver) \ | |
687 | module_driver(__acpi_driver, acpi_bus_register_driver, \ | |
688 | acpi_bus_unregister_driver) | |
689 | ||
4e10d12a DSL |
690 | /* |
691 | * Bind physical devices with ACPI devices | |
692 | */ | |
4e10d12a | 693 | struct acpi_bus_type { |
4be44fcd | 694 | struct list_head list; |
53540098 RW |
695 | const char *name; |
696 | bool (*match)(struct device *dev); | |
e3f02c52 | 697 | struct acpi_device * (*find_companion)(struct device *); |
11909ca1 | 698 | void (*setup)(struct device *); |
4e10d12a DSL |
699 | }; |
700 | int register_acpi_bus_type(struct acpi_bus_type *); | |
701 | int unregister_acpi_bus_type(struct acpi_bus_type *); | |
f1b1dc84 ZR |
702 | int acpi_bind_one(struct device *dev, struct acpi_device *adev); |
703 | int acpi_unbind_one(struct device *dev); | |
22c13f9d | 704 | |
241d26bc DW |
705 | enum acpi_bridge_type { |
706 | ACPI_BRIDGE_TYPE_PCIE = 1, | |
707 | ACPI_BRIDGE_TYPE_CXL, | |
708 | }; | |
709 | ||
76d56de5 | 710 | struct acpi_pci_root { |
76d56de5 | 711 | struct acpi_device * device; |
76d56de5 AC |
712 | struct pci_bus *bus; |
713 | u16 segment; | |
241d26bc | 714 | int bridge_type; |
6ad95513 | 715 | struct resource secondary; /* downstream bus range */ |
76d56de5 | 716 | |
56368029 VV |
717 | u32 osc_support_set; /* _OSC state of support bits */ |
718 | u32 osc_control_set; /* _OSC state of control bits */ | |
719 | u32 osc_ext_support_set; /* _OSC state of extended support bits */ | |
720 | u32 osc_ext_control_set; /* _OSC state of extended control bits */ | |
f4b57a3b | 721 | phys_addr_t mcfg_addr; |
76d56de5 AC |
722 | }; |
723 | ||
4e10d12a | 724 | /* helper */ |
d9fef0c4 | 725 | |
17de3f5f RM |
726 | struct iommu_ops; |
727 | ||
3d7c821c | 728 | bool acpi_dma_supported(const struct acpi_device *adev); |
b84f196d | 729 | enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev); |
11a8c5e3 JPB |
730 | int acpi_iommu_fwspec_init(struct device *dev, u32 id, |
731 | struct fwnode_handle *fwnode, | |
732 | const struct iommu_ops *ops); | |
bf2ee8d0 | 733 | int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map); |
b8e069a2 LP |
734 | int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, |
735 | const u32 *input_id); | |
736 | static inline int acpi_dma_configure(struct device *dev, | |
737 | enum dev_dma_attr attr) | |
738 | { | |
739 | return acpi_dma_configure_id(dev, attr, NULL); | |
740 | } | |
d9fef0c4 RW |
741 | struct acpi_device *acpi_find_child_device(struct acpi_device *parent, |
742 | u64 address, bool check_children); | |
2f6fe93f RW |
743 | struct acpi_device *acpi_find_child_by_adr(struct acpi_device *adev, |
744 | acpi_bus_address adr); | |
27558203 | 745 | int acpi_is_root_bridge(acpi_handle); |
76d56de5 | 746 | struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle); |
4e10d12a | 747 | |
b67ea761 RW |
748 | int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state); |
749 | int acpi_disable_wakeup_device_power(struct acpi_device *dev); | |
750 | ||
b7ecf663 | 751 | #ifdef CONFIG_X86 |
1a68b346 | 752 | bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status); |
57a18322 | 753 | bool acpi_quirk_skip_acpi_ac_and_battery(void); |
596ca52a ZR |
754 | int acpi_install_cmos_rtc_space_handler(acpi_handle handle); |
755 | void acpi_remove_cmos_rtc_space_handler(acpi_handle handle); | |
7c86e174 | 756 | int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip); |
b7ecf663 | 757 | #else |
1a68b346 HG |
758 | static inline bool acpi_device_override_status(struct acpi_device *adev, |
759 | unsigned long long *status) | |
b7ecf663 HG |
760 | { |
761 | return false; | |
762 | } | |
57a18322 HG |
763 | static inline bool acpi_quirk_skip_acpi_ac_and_battery(void) |
764 | { | |
765 | return false; | |
766 | } | |
596ca52a ZR |
767 | static inline int acpi_install_cmos_rtc_space_handler(acpi_handle handle) |
768 | { | |
769 | return 1; | |
770 | } | |
771 | static inline void acpi_remove_cmos_rtc_space_handler(acpi_handle handle) | |
772 | { | |
773 | } | |
7c86e174 HG |
774 | static inline int |
775 | acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip) | |
776 | { | |
777 | *skip = false; | |
778 | return 0; | |
779 | } | |
b7ecf663 HG |
780 | #endif |
781 | ||
35f9e773 HG |
782 | #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS) |
783 | bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev); | |
5adc4093 | 784 | bool acpi_quirk_skip_gpio_event_handlers(void); |
35f9e773 HG |
785 | #else |
786 | static inline bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev) | |
787 | { | |
788 | return false; | |
789 | } | |
5adc4093 HG |
790 | static inline bool acpi_quirk_skip_gpio_event_handlers(void) |
791 | { | |
792 | return false; | |
793 | } | |
b7ecf663 HG |
794 | #endif |
795 | ||
aa338601 | 796 | #ifdef CONFIG_PM |
33e4f80e | 797 | void acpi_pm_wakeup_event(struct device *dev); |
c072530f | 798 | acpi_status acpi_add_pm_notifier(struct acpi_device *adev, struct device *dev, |
64fd1c70 | 799 | void (*func)(struct acpi_device_wakeup_context *context)); |
c072530f | 800 | acpi_status acpi_remove_pm_notifier(struct acpi_device *adev); |
8370c2dc | 801 | bool acpi_pm_device_can_wakeup(struct device *dev); |
ee85f543 | 802 | int acpi_pm_device_sleep_state(struct device *, int *, int); |
4d183d04 | 803 | int acpi_pm_set_device_wakeup(struct device *dev, bool enable); |
761afb86 | 804 | #else |
33e4f80e RW |
805 | static inline void acpi_pm_wakeup_event(struct device *dev) |
806 | { | |
807 | } | |
ec2cd81c | 808 | static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev, |
c072530f | 809 | struct device *dev, |
33e4f80e | 810 | void (*func)(struct acpi_device_wakeup_context *context)) |
ec2cd81c RW |
811 | { |
812 | return AE_SUPPORT; | |
813 | } | |
c072530f | 814 | static inline acpi_status acpi_remove_pm_notifier(struct acpi_device *adev) |
ec2cd81c RW |
815 | { |
816 | return AE_SUPPORT; | |
817 | } | |
8370c2dc RW |
818 | static inline bool acpi_pm_device_can_wakeup(struct device *dev) |
819 | { | |
820 | return false; | |
821 | } | |
b25c77ef | 822 | static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m) |
296699de RW |
823 | { |
824 | if (p) | |
825 | *p = ACPI_STATE_D0; | |
b25c77ef | 826 | |
8ad928d5 RW |
827 | return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3_COLD) ? |
828 | m : ACPI_STATE_D0; | |
296699de | 829 | } |
4d183d04 | 830 | static inline int acpi_pm_set_device_wakeup(struct device *dev, bool enable) |
f7a1b860 DH |
831 | { |
832 | return -ENODEV; | |
833 | } | |
761afb86 | 834 | #endif |
fd4aff1a | 835 | |
ad5a449b DC |
836 | #ifdef CONFIG_ACPI_SYSTEM_POWER_STATES_SUPPORT |
837 | bool acpi_sleep_state_supported(u8 sleep_state); | |
838 | #else | |
839 | static inline bool acpi_sleep_state_supported(u8 sleep_state) { return false; } | |
840 | #endif | |
841 | ||
99926a8c DR |
842 | #ifdef CONFIG_ACPI_SLEEP |
843 | u32 acpi_target_system_state(void); | |
844 | #else | |
845 | static inline u32 acpi_target_system_state(void) { return ACPI_STATE_S0; } | |
846 | #endif | |
847 | ||
078eb126 RW |
848 | static inline bool acpi_device_power_manageable(struct acpi_device *adev) |
849 | { | |
850 | return adev->flags.power_manageable; | |
851 | } | |
852 | ||
853 | static inline bool acpi_device_can_wakeup(struct acpi_device *adev) | |
854 | { | |
855 | return adev->wakeup.flags.valid; | |
856 | } | |
857 | ||
1399dfcd AL |
858 | static inline bool acpi_device_can_poweroff(struct acpi_device *adev) |
859 | { | |
cd7f84c0 KX |
860 | return adev->power.states[ACPI_STATE_D3_COLD].flags.valid || |
861 | ((acpi_gbl_FADT.header.revision < 6) && | |
862 | adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set); | |
1399dfcd AL |
863 | } |
864 | ||
5db72fdb | 865 | int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer); |
35009c80 | 866 | |
b2b32a17 RJ |
867 | static inline bool acpi_dev_hid_match(struct acpi_device *adev, const char *hid2) |
868 | { | |
869 | const char *hid1 = acpi_device_hid(adev); | |
870 | ||
871 | return hid1 && hid2 && !strcmp(hid1, hid2); | |
872 | } | |
873 | ||
57b8543c RJ |
874 | static inline bool acpi_str_uid_match(struct acpi_device *adev, const char *uid2) |
875 | { | |
876 | const char *uid1 = acpi_device_uid(adev); | |
877 | ||
878 | return uid1 && uid2 && !strcmp(uid1, uid2); | |
879 | } | |
880 | ||
881 | static inline bool acpi_int_uid_match(struct acpi_device *adev, u64 uid2) | |
882 | { | |
883 | u64 uid1; | |
884 | ||
885 | return !acpi_dev_uid_to_integer(adev, &uid1) && uid1 == uid2; | |
886 | } | |
887 | ||
888 | #define TYPE_ENTRY(type, x) \ | |
889 | const type: x, \ | |
890 | type: x | |
891 | ||
892 | #define ACPI_STR_TYPES(match) \ | |
893 | TYPE_ENTRY(unsigned char *, match), \ | |
894 | TYPE_ENTRY(signed char *, match), \ | |
895 | TYPE_ENTRY(char *, match), \ | |
896 | TYPE_ENTRY(void *, match) | |
897 | ||
898 | /** | |
899 | * acpi_dev_uid_match - Match device by supplied UID | |
900 | * @adev: ACPI device to match. | |
901 | * @uid2: Unique ID of the device. | |
902 | * | |
903 | * Matches UID in @adev with given @uid2. | |
904 | * | |
905 | * Returns: %true if matches, %false otherwise. | |
906 | */ | |
907 | #define acpi_dev_uid_match(adev, uid2) \ | |
908 | _Generic(uid2, \ | |
909 | /* Treat @uid2 as a string for acpi string types */ \ | |
910 | ACPI_STR_TYPES(acpi_str_uid_match), \ | |
911 | /* Treat as an integer otherwise */ \ | |
912 | default: acpi_int_uid_match)(adev, uid2) | |
913 | ||
b2b32a17 RJ |
914 | /** |
915 | * acpi_dev_hid_uid_match - Match device by supplied HID and UID | |
916 | * @adev: ACPI device to match. | |
917 | * @hid2: Hardware ID of the device. | |
aca1a528 | 918 | * @uid2: Unique ID of the device, pass NULL to not check _UID. |
b2b32a17 RJ |
919 | * |
920 | * Matches HID and UID in @adev with given @hid2 and @uid2. Absence of @uid2 | |
921 | * will be treated as a match. If user wants to validate @uid2, it should be | |
922 | * done before calling this function. | |
923 | * | |
aca1a528 | 924 | * Returns: %true if matches or @uid2 is NULL, %false otherwise. |
b2b32a17 RJ |
925 | */ |
926 | #define acpi_dev_hid_uid_match(adev, hid2, uid2) \ | |
927 | (acpi_dev_hid_match(adev, hid2) && \ | |
aca1a528 RJ |
928 | /* Distinguish integer 0 from NULL @uid2 */ \ |
929 | (_Generic(uid2, ACPI_STR_TYPES(!(uid2)), default: 0) || \ | |
930 | acpi_dev_uid_match(adev, uid2))) | |
b2b32a17 | 931 | |
a9e10e58 | 932 | void acpi_dev_clear_dependencies(struct acpi_device *supplier); |
9d9bcae4 | 933 | bool acpi_dev_ready_for_enumeration(const struct acpi_device *device); |
cca8a7ef DS |
934 | struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier, |
935 | struct acpi_device *start); | |
936 | ||
62c8bc0d DS |
937 | /** |
938 | * for_each_acpi_consumer_dev - iterate over the consumer ACPI devices for a | |
939 | * given supplier | |
940 | * @supplier: Pointer to the supplier's ACPI device | |
941 | * @consumer: Pointer to &struct acpi_device to hold the consumer, initially NULL | |
942 | */ | |
943 | #define for_each_acpi_consumer_dev(supplier, consumer) \ | |
944 | for (consumer = acpi_dev_get_next_consumer_dev(supplier, NULL); \ | |
945 | consumer; \ | |
946 | consumer = acpi_dev_get_next_consumer_dev(supplier, consumer)) | |
947 | ||
bf263f64 DS |
948 | struct acpi_device * |
949 | acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv); | |
a814dcc2 AS |
950 | struct acpi_device * |
951 | acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv); | |
952 | ||
81eeb2f5 AS |
953 | /** |
954 | * for_each_acpi_dev_match - iterate over ACPI devices that matching the criteria | |
955 | * @adev: pointer to the matching ACPI device, NULL at the end of the loop | |
956 | * @hid: Hardware ID of the device. | |
957 | * @uid: Unique ID of the device, pass NULL to not check _UID | |
958 | * @hrv: Hardware Revision of the device, pass -1 to not check _HRV | |
959 | * | |
960 | * The caller is responsible for invoking acpi_dev_put() on the returned device. | |
81eeb2f5 | 961 | */ |
bf263f64 DS |
962 | #define for_each_acpi_dev_match(adev, hid, uid, hrv) \ |
963 | for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv); \ | |
964 | adev; \ | |
965 | adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv)) | |
966 | ||
4cbaba4e AS |
967 | static inline struct acpi_device *acpi_dev_get(struct acpi_device *adev) |
968 | { | |
969 | return adev ? to_acpi_device(get_device(&adev->dev)) : NULL; | |
970 | } | |
971 | ||
fe066621 Y |
972 | static inline void acpi_dev_put(struct acpi_device *adev) |
973 | { | |
fc68f42a LT |
974 | if (adev) |
975 | put_device(&adev->dev); | |
fe066621 | 976 | } |
2d079514 | 977 | |
45e9aa1f RW |
978 | struct acpi_device *acpi_fetch_acpi_dev(acpi_handle handle); |
979 | struct acpi_device *acpi_get_acpi_dev(acpi_handle handle); | |
2d079514 | 980 | |
45e9aa1f | 981 | static inline void acpi_put_acpi_dev(struct acpi_device *adev) |
2d079514 RW |
982 | { |
983 | acpi_dev_put(adev); | |
984 | } | |
66886d6f MG |
985 | #else /* CONFIG_ACPI */ |
986 | ||
7ae30986 LB |
987 | static inline int register_acpi_bus_type(void *bus) { return 0; } |
988 | static inline int unregister_acpi_bus_type(void *bus) { return 0; } | |
66886d6f | 989 | |
fd350943 | 990 | #endif /* CONFIG_ACPI */ |
1da177e4 LT |
991 | |
992 | #endif /*__ACPI_BUS_H__*/ |