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