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