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