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