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