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