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