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