1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * acpi.h - ACPI Interface 4 * 5 * Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> 6 */ 7 8 #ifndef _LINUX_ACPI_H 9 #define _LINUX_ACPI_H 10 11 #include <linux/cleanup.h> 12 #include <linux/errno.h> 13 #include <linux/ioport.h> /* for struct resource */ 14 #include <linux/resource_ext.h> 15 #include <linux/device.h> 16 #include <linux/device-id/acpi.h> 17 #include <linux/property.h> 18 #include <linux/uuid.h> 19 #include <linux/node.h> 20 21 struct irq_domain; 22 struct irq_domain_ops; 23 24 #ifndef _LINUX 25 #define _LINUX 26 #endif 27 #include <acpi/acpi.h> 28 #include <acpi/acpi_bus.h> 29 #include <acpi/acpi_numa.h> 30 31 #ifdef CONFIG_ACPI 32 33 DEFINE_FREE(acpi_object_free, union acpi_object *, if (_T) ACPI_FREE(_T)); 34 35 #include <linux/list.h> 36 #include <linux/dynamic_debug.h> 37 #include <linux/module.h> 38 #include <linux/mutex.h> 39 #include <linux/fw_table.h> 40 41 #include <acpi/acpi_drivers.h> 42 #include <acpi/acpi_io.h> 43 #include <asm/acpi.h> 44 45 #ifdef CONFIG_ACPI_TABLE_LIB 46 #define EXPORT_SYMBOL_ACPI_LIB(x) EXPORT_SYMBOL_NS_GPL(x, "ACPI") 47 #define __init_or_acpilib 48 #define __initdata_or_acpilib 49 #else 50 #define EXPORT_SYMBOL_ACPI_LIB(x) 51 #define __init_or_acpilib __init 52 #define __initdata_or_acpilib __initdata 53 #endif 54 55 static inline acpi_handle acpi_device_handle(struct acpi_device *adev) 56 { 57 return adev ? adev->handle : NULL; 58 } 59 60 #define ACPI_COMPANION(dev) to_acpi_device_node((dev)->fwnode) 61 #define ACPI_COMPANION_SET(dev, adev) set_primary_fwnode(dev, (adev) ? \ 62 acpi_fwnode_handle(adev) : NULL) 63 #define ACPI_HANDLE(dev) acpi_device_handle(ACPI_COMPANION(dev)) 64 #define ACPI_HANDLE_FWNODE(fwnode) \ 65 acpi_device_handle(to_acpi_device_node(fwnode)) 66 67 static inline struct fwnode_handle *acpi_alloc_fwnode_static(void) 68 { 69 struct fwnode_handle *fwnode; 70 71 fwnode = kzalloc_obj(struct fwnode_handle); 72 if (!fwnode) 73 return NULL; 74 75 fwnode_init(fwnode, &acpi_static_fwnode_ops); 76 77 return fwnode; 78 } 79 80 static inline void acpi_free_fwnode_static(struct fwnode_handle *fwnode) 81 { 82 if (WARN_ON(!is_acpi_static_node(fwnode))) 83 return; 84 85 kfree(fwnode); 86 } 87 88 static inline bool has_acpi_companion(struct device *dev) 89 { 90 return is_acpi_device_node(dev->fwnode); 91 } 92 93 static inline void acpi_preset_companion(struct device *dev, 94 struct acpi_device *parent, u64 addr) 95 { 96 ACPI_COMPANION_SET(dev, acpi_find_child_device(parent, addr, false)); 97 } 98 99 static inline void acpi_device_clear_deps(struct device *dev) 100 { 101 if (has_acpi_companion(dev)) 102 acpi_dev_clear_dependencies(ACPI_COMPANION(dev)); 103 } 104 105 static inline const char *acpi_dev_name(struct acpi_device *adev) 106 { 107 return dev_name(&adev->dev); 108 } 109 110 enum acpi_irq_model_id { 111 ACPI_IRQ_MODEL_PIC = 0, 112 ACPI_IRQ_MODEL_IOAPIC, 113 ACPI_IRQ_MODEL_IOSAPIC, 114 ACPI_IRQ_MODEL_PLATFORM, 115 ACPI_IRQ_MODEL_GIC, 116 ACPI_IRQ_MODEL_GIC_V5, 117 ACPI_IRQ_MODEL_LPIC, 118 ACPI_IRQ_MODEL_RINTC, 119 ACPI_IRQ_MODEL_COUNT 120 }; 121 122 extern enum acpi_irq_model_id acpi_irq_model; 123 124 enum acpi_interrupt_id { 125 ACPI_INTERRUPT_PMI = 1, 126 ACPI_INTERRUPT_INIT, 127 ACPI_INTERRUPT_CPEI, 128 ACPI_INTERRUPT_COUNT 129 }; 130 131 #define ACPI_SPACE_MEM 0 132 133 enum acpi_address_range_id { 134 ACPI_ADDRESS_RANGE_MEMORY = 1, 135 ACPI_ADDRESS_RANGE_RESERVED = 2, 136 ACPI_ADDRESS_RANGE_ACPI = 3, 137 ACPI_ADDRESS_RANGE_NVS = 4, 138 ACPI_ADDRESS_RANGE_COUNT 139 }; 140 141 142 /* Table Handlers */ 143 typedef int (*acpi_tbl_table_handler)(struct acpi_table_header *table); 144 145 /* Debugger support */ 146 147 struct acpi_debugger_ops { 148 int (*create_thread)(acpi_osd_exec_callback function, void *context); 149 ssize_t (*write_log)(const char *msg); 150 ssize_t (*read_cmd)(char *buffer, size_t length); 151 int (*wait_command_ready)(bool single_step, char *buffer, size_t length); 152 int (*notify_command_complete)(void); 153 }; 154 155 struct acpi_debugger { 156 const struct acpi_debugger_ops *ops; 157 struct module *owner; 158 struct mutex lock; 159 }; 160 161 #ifdef CONFIG_ACPI_DEBUGGER 162 int __init acpi_debugger_init(void); 163 int acpi_register_debugger(struct module *owner, 164 const struct acpi_debugger_ops *ops); 165 void acpi_unregister_debugger(const struct acpi_debugger_ops *ops); 166 int acpi_debugger_create_thread(acpi_osd_exec_callback function, void *context); 167 ssize_t acpi_debugger_write_log(const char *msg); 168 ssize_t acpi_debugger_read_cmd(char *buffer, size_t buffer_length); 169 int acpi_debugger_wait_command_ready(void); 170 int acpi_debugger_notify_command_complete(void); 171 #else 172 static inline int acpi_debugger_init(void) 173 { 174 return -ENODEV; 175 } 176 177 static inline int acpi_register_debugger(struct module *owner, 178 const struct acpi_debugger_ops *ops) 179 { 180 return -ENODEV; 181 } 182 183 static inline void acpi_unregister_debugger(const struct acpi_debugger_ops *ops) 184 { 185 } 186 187 static inline int acpi_debugger_create_thread(acpi_osd_exec_callback function, 188 void *context) 189 { 190 return -ENODEV; 191 } 192 193 static inline int acpi_debugger_write_log(const char *msg) 194 { 195 return -ENODEV; 196 } 197 198 static inline int acpi_debugger_read_cmd(char *buffer, u32 buffer_length) 199 { 200 return -ENODEV; 201 } 202 203 static inline int acpi_debugger_wait_command_ready(void) 204 { 205 return -ENODEV; 206 } 207 208 static inline int acpi_debugger_notify_command_complete(void) 209 { 210 return -ENODEV; 211 } 212 #endif 213 214 #define BAD_MADT_ENTRY(entry, end) ( \ 215 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \ 216 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry)) 217 218 void __iomem *__acpi_map_table(unsigned long phys, unsigned long size); 219 void __acpi_unmap_table(void __iomem *map, unsigned long size); 220 int early_acpi_boot_init(void); 221 int acpi_boot_init (void); 222 void acpi_boot_table_prepare (void); 223 void acpi_boot_table_init (void); 224 int acpi_mps_check (void); 225 int acpi_numa_init (void); 226 227 int acpi_locate_initial_tables (void); 228 void acpi_reserve_initial_tables (void); 229 void acpi_table_init_complete (void); 230 int acpi_table_init (void); 231 232 static inline struct acpi_table_header *acpi_get_table_pointer(char *signature, u32 instance) 233 { 234 struct acpi_table_header *table; 235 int status = acpi_get_table(signature, instance, &table); 236 237 if (ACPI_FAILURE(status)) 238 return ERR_PTR(-ENOENT); 239 return table; 240 } 241 DEFINE_FREE(acpi_put_table, struct acpi_table_header *, if (!IS_ERR_OR_NULL(_T)) acpi_put_table(_T)) 242 243 int acpi_table_parse(char *id, acpi_tbl_table_handler handler); 244 int __init_or_acpilib acpi_table_parse_entries(char *id, 245 unsigned long table_size, int entry_id, 246 acpi_tbl_entry_handler handler, unsigned int max_entries); 247 int __init_or_acpilib acpi_table_parse_entries_array(char *id, 248 unsigned long table_size, struct acpi_subtable_proc *proc, 249 int proc_num, unsigned int max_entries); 250 int acpi_table_parse_madt(enum acpi_madt_type id, 251 acpi_tbl_entry_handler handler, 252 unsigned int max_entries); 253 int __init_or_acpilib 254 acpi_table_parse_cedt(enum acpi_cedt_type id, 255 acpi_tbl_entry_handler_arg handler_arg, void *arg); 256 257 int acpi_parse_mcfg (struct acpi_table_header *header); 258 void acpi_table_print_madt_entry (struct acpi_subtable_header *madt); 259 260 #if defined(CONFIG_X86) || defined(CONFIG_LOONGARCH) 261 void acpi_numa_processor_affinity_init (struct acpi_srat_cpu_affinity *pa); 262 #else 263 static inline void 264 acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) { } 265 #endif 266 267 void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa); 268 269 #if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH) 270 void acpi_arch_dma_setup(struct device *dev); 271 #else 272 static inline void acpi_arch_dma_setup(struct device *dev) { } 273 #endif 274 275 #ifdef CONFIG_ARM64 276 void acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa); 277 #else 278 static inline void 279 acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { } 280 #endif 281 282 #ifdef CONFIG_RISCV 283 void acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa); 284 #else 285 static inline void acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa) { } 286 #endif 287 288 #ifndef PHYS_CPUID_INVALID 289 typedef u32 phys_cpuid_t; 290 #define PHYS_CPUID_INVALID (phys_cpuid_t)(-1) 291 #endif 292 293 static inline bool invalid_logical_cpuid(u32 cpuid) 294 { 295 return (int)cpuid < 0; 296 } 297 298 static inline bool invalid_phys_cpuid(phys_cpuid_t phys_id) 299 { 300 return phys_id == PHYS_CPUID_INVALID; 301 } 302 303 304 int __init acpi_get_madt_revision(void); 305 306 /* Validate the processor object's proc_id */ 307 bool acpi_duplicate_processor_id(int proc_id); 308 /* Processor _CTS control */ 309 struct acpi_processor_power; 310 311 #ifdef CONFIG_ACPI_PROCESSOR_CSTATE 312 bool acpi_processor_claim_cst_control(void); 313 int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, 314 struct acpi_processor_power *info); 315 #else 316 static inline bool acpi_processor_claim_cst_control(void) { return false; } 317 static inline int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, 318 struct acpi_processor_power *info) 319 { 320 return -ENODEV; 321 } 322 #endif 323 324 #ifdef CONFIG_ACPI_PROCESSOR_IDLE 325 int acpi_processor_extract_lpi_info(acpi_handle pr_handle, 326 struct acpi_processor_power *pr_power, 327 bool strict); 328 #else 329 static inline int acpi_processor_extract_lpi_info(acpi_handle pr_handle, 330 struct acpi_processor_power *pr_power, 331 bool strict) 332 { 333 return -ENODEV; 334 } 335 #endif 336 337 #ifdef CONFIG_ACPI_HOTPLUG_CPU 338 /* Arch dependent functions for cpu hotplug support */ 339 int acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, u32 acpi_id, 340 int *pcpu); 341 int acpi_unmap_cpu(int cpu); 342 #endif /* CONFIG_ACPI_HOTPLUG_CPU */ 343 344 acpi_handle acpi_get_processor_handle(int cpu); 345 346 /** 347 * acpi_get_cpu_uid() - Get ACPI Processor UID of from MADT table 348 * @cpu: Logical CPU number (0-based) 349 * @uid: Pointer to store ACPI Processor UID 350 * 351 * Return: 0 on success (ACPI Processor ID stored in *uid); 352 * -EINVAL if CPU number is invalid or out of range; 353 * -ENODEV if ACPI Processor UID for the CPU is not found. 354 */ 355 int acpi_get_cpu_uid(unsigned int cpu, u32 *uid); 356 357 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC 358 int acpi_get_ioapic_id(acpi_handle handle, u32 gsi_base, u64 *phys_addr); 359 #endif 360 361 int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base); 362 int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base); 363 int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base); 364 void acpi_irq_stats_init(void); 365 extern u32 acpi_irq_handled; 366 extern u32 acpi_irq_not_handled; 367 extern unsigned int acpi_sci_irq; 368 extern bool acpi_no_s5; 369 #define INVALID_ACPI_IRQ ((unsigned)-1) 370 static inline bool acpi_sci_irq_valid(void) 371 { 372 return acpi_sci_irq != INVALID_ACPI_IRQ; 373 } 374 375 extern int sbf_port; 376 377 int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity); 378 int acpi_gsi_to_irq (u32 gsi, unsigned int *irq); 379 int acpi_isa_irq_to_gsi (unsigned isa_irq, u32 *gsi); 380 381 typedef struct fwnode_handle *(*acpi_gsi_domain_disp_fn)(u32); 382 typedef acpi_handle (*acpi_gsi_handle_disp_fn)(u32); 383 384 void acpi_set_irq_model(enum acpi_irq_model_id model, 385 acpi_gsi_domain_disp_fn fn, acpi_gsi_handle_disp_fn gsi_dep_fn); 386 acpi_gsi_domain_disp_fn acpi_get_gsi_dispatcher(void); 387 void acpi_set_gsi_to_irq_fallback(u32 (*)(u32)); 388 389 struct irq_domain *acpi_irq_create_hierarchy(unsigned int flags, 390 unsigned int size, 391 struct fwnode_handle *fwnode, 392 const struct irq_domain_ops *ops, 393 void *host_data); 394 395 u32 acpi_irq_add_auto_dep(acpi_handle handle); 396 397 #ifdef CONFIG_X86_IO_APIC 398 extern int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity); 399 #else 400 static inline int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity) 401 { 402 return -1; 403 } 404 #endif 405 /* 406 * This function undoes the effect of one call to acpi_register_gsi(). 407 * If this matches the last registration, any IRQ resources for gsi 408 * are freed. 409 */ 410 void acpi_unregister_gsi (u32 gsi); 411 412 struct pci_dev; 413 414 struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin); 415 int acpi_pci_irq_enable (struct pci_dev *dev); 416 void acpi_penalize_isa_irq(int irq, int active); 417 bool acpi_isa_irq_available(int irq); 418 #ifdef CONFIG_PCI 419 void acpi_penalize_sci_irq(int irq, int trigger, int polarity); 420 #else 421 static inline void acpi_penalize_sci_irq(int irq, int trigger, 422 int polarity) 423 { 424 } 425 #endif 426 void acpi_pci_irq_disable (struct pci_dev *dev); 427 428 extern int ec_read(u8 addr, u8 *val); 429 extern int ec_write(u8 addr, u8 val); 430 extern int ec_transaction(u8 command, 431 const u8 *wdata, unsigned wdata_len, 432 u8 *rdata, unsigned rdata_len); 433 extern acpi_handle ec_get_handle(void); 434 435 extern bool acpi_is_pnp_device(struct acpi_device *); 436 437 #if IS_ENABLED(CONFIG_ACPI_WMI) 438 439 typedef void (*wmi_notify_handler) (union acpi_object *data, void *context); 440 441 int wmi_instance_count(const char *guid); 442 443 extern acpi_status wmi_evaluate_method(const char *guid, u8 instance, 444 u32 method_id, 445 const struct acpi_buffer *in, 446 struct acpi_buffer *out); 447 extern acpi_status wmi_query_block(const char *guid, u8 instance, 448 struct acpi_buffer *out); 449 extern acpi_status wmi_set_block(const char *guid, u8 instance, 450 const struct acpi_buffer *in); 451 extern acpi_status wmi_install_notify_handler(const char *guid, 452 wmi_notify_handler handler, void *data); 453 extern acpi_status wmi_remove_notify_handler(const char *guid); 454 extern bool wmi_has_guid(const char *guid); 455 extern char *wmi_get_acpi_device_uid(const char *guid); 456 457 #endif /* CONFIG_ACPI_WMI */ 458 459 #define ACPI_VIDEO_OUTPUT_SWITCHING 0x0001 460 #define ACPI_VIDEO_DEVICE_POSTING 0x0002 461 #define ACPI_VIDEO_ROM_AVAILABLE 0x0004 462 #define ACPI_VIDEO_BACKLIGHT 0x0008 463 #define ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR 0x0010 464 #define ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO 0x0020 465 #define ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VENDOR 0x0040 466 #define ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VIDEO 0x0080 467 #define ACPI_VIDEO_BACKLIGHT_DMI_VENDOR 0x0100 468 #define ACPI_VIDEO_BACKLIGHT_DMI_VIDEO 0x0200 469 #define ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VENDOR 0x0400 470 #define ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VIDEO 0x0800 471 472 extern char acpi_video_backlight_string[]; 473 extern bool acpi_dev_is_video_device(struct acpi_device *adev); 474 extern long acpi_is_video_device(acpi_handle handle); 475 476 extern void acpi_osi_setup(char *str); 477 extern bool acpi_osi_is_win8(void); 478 479 #ifdef CONFIG_ACPI_THERMAL_LIB 480 int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp); 481 int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp); 482 int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp); 483 int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp); 484 #endif 485 486 #ifdef CONFIG_ACPI_HMAT 487 int acpi_get_genport_coordinates(u32 uid, struct access_coordinate *coord); 488 #else 489 static inline int acpi_get_genport_coordinates(u32 uid, 490 struct access_coordinate *coord) 491 { 492 return -EOPNOTSUPP; 493 } 494 #endif 495 496 #ifdef CONFIG_ACPI_NUMA 497 int acpi_map_pxm_to_node(int pxm); 498 int acpi_get_node(acpi_handle handle); 499 500 /** 501 * pxm_to_online_node - Map proximity ID to online node 502 * @pxm: ACPI proximity ID 503 * 504 * This is similar to pxm_to_node(), but always returns an online 505 * node. When the mapped node from a given proximity ID is offline, it 506 * looks up the node distance table and returns the nearest online node. 507 * 508 * ACPI device drivers, which are called after the NUMA initialization has 509 * completed in the kernel, can call this interface to obtain their device 510 * NUMA topology from ACPI tables. Such drivers do not have to deal with 511 * offline nodes. A node may be offline when SRAT memory entry does not exist, 512 * or NUMA is disabled, ex. "numa=off" on x86. 513 */ 514 static inline int pxm_to_online_node(int pxm) 515 { 516 int node = pxm_to_node(pxm); 517 518 return numa_map_to_online_node(node); 519 } 520 #else 521 static inline int pxm_to_online_node(int pxm) 522 { 523 return 0; 524 } 525 static inline int acpi_map_pxm_to_node(int pxm) 526 { 527 return 0; 528 } 529 static inline int acpi_get_node(acpi_handle handle) 530 { 531 return 0; 532 } 533 #endif 534 extern int pnpacpi_disabled; 535 536 #define PXM_INVAL (-1) 537 538 bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res); 539 bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res); 540 bool acpi_dev_resource_address_space(struct acpi_resource *ares, 541 struct resource_win *win); 542 bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares, 543 struct resource_win *win); 544 unsigned long acpi_dev_irq_flags(u8 triggering, u8 polarity, u8 shareable, u8 wake_capable); 545 unsigned int acpi_dev_get_irq_type(int triggering, int polarity); 546 bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index, 547 struct resource *res); 548 549 void acpi_dev_free_resource_list(struct list_head *list); 550 int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list, 551 int (*preproc)(struct acpi_resource *, void *), 552 void *preproc_data); 553 int acpi_dev_get_dma_resources(struct acpi_device *adev, 554 struct list_head *list); 555 int acpi_dev_get_memory_resources(struct acpi_device *adev, struct list_head *list); 556 int acpi_dev_filter_resource_type(struct acpi_resource *ares, 557 unsigned long types); 558 559 static inline int acpi_dev_filter_resource_type_cb(struct acpi_resource *ares, 560 void *arg) 561 { 562 return acpi_dev_filter_resource_type(ares, (unsigned long)arg); 563 } 564 565 struct acpi_device *acpi_resource_consumer(struct resource *res); 566 567 int acpi_check_resource_conflict(const struct resource *res); 568 569 int acpi_check_region(resource_size_t start, resource_size_t n, 570 const char *name); 571 572 int acpi_resources_are_enforced(void); 573 574 #ifdef CONFIG_HIBERNATION 575 extern int acpi_check_s4_hw_signature; 576 #endif 577 578 #ifdef CONFIG_PM_SLEEP 579 void __init acpi_old_suspend_ordering(void); 580 void __init acpi_nvs_nosave(void); 581 void __init acpi_nvs_nosave_s3(void); 582 void __init acpi_sleep_no_blacklist(void); 583 #endif /* CONFIG_PM_SLEEP */ 584 585 int acpi_register_wakeup_handler( 586 int wake_irq, bool (*wakeup)(void *context), void *context); 587 void acpi_unregister_wakeup_handler( 588 bool (*wakeup)(void *context), void *context); 589 590 struct acpi_osc_context { 591 char *uuid_str; /* UUID string */ 592 int rev; 593 struct acpi_buffer cap; /* list of DWORD capabilities */ 594 struct acpi_buffer ret; /* free by caller if success */ 595 }; 596 597 acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context); 598 599 /* Number of _OSC capability DWORDS depends on bridge type */ 600 #define OSC_PCI_CAPABILITY_DWORDS 3 601 #define OSC_CXL_CAPABILITY_DWORDS 5 602 603 /* Indexes into _OSC Capabilities Buffer (DWORDs 2 to 5 are device-specific) */ 604 #define OSC_QUERY_DWORD 0 /* DWORD 1 */ 605 #define OSC_SUPPORT_DWORD 1 /* DWORD 2 */ 606 #define OSC_CONTROL_DWORD 2 /* DWORD 3 */ 607 #define OSC_EXT_SUPPORT_DWORD 3 /* DWORD 4 */ 608 #define OSC_EXT_CONTROL_DWORD 4 /* DWORD 5 */ 609 610 /* _OSC Capabilities DWORD 1: Query/Control and Error Returns (generic) */ 611 #define OSC_QUERY_ENABLE 0x00000001 /* input */ 612 #define OSC_REQUEST_ERROR 0x00000002 /* return */ 613 #define OSC_INVALID_UUID_ERROR 0x00000004 /* return */ 614 #define OSC_INVALID_REVISION_ERROR 0x00000008 /* return */ 615 #define OSC_CAPABILITIES_MASK_ERROR 0x00000010 /* return */ 616 617 /* Platform-Wide Capabilities _OSC: Capabilities DWORD 2: Support Field */ 618 #define OSC_SB_PAD_SUPPORT 0x00000001 619 #define OSC_SB_PPC_OST_SUPPORT 0x00000002 620 #define OSC_SB_PR3_SUPPORT 0x00000004 621 #define OSC_SB_HOTPLUG_OST_SUPPORT 0x00000008 622 #define OSC_SB_APEI_SUPPORT 0x00000010 623 #define OSC_SB_CPC_SUPPORT 0x00000020 624 #define OSC_SB_CPCV2_SUPPORT 0x00000040 625 #define OSC_SB_PCLPI_SUPPORT 0x00000080 626 #define OSC_SB_OSLPI_SUPPORT 0x00000100 627 #define OSC_SB_FAST_THERMAL_SAMPLING_SUPPORT 0x00000200 628 #define OSC_SB_OVER_16_PSTATES_SUPPORT 0x00000400 629 #define OSC_SB_GED_SUPPORT 0x00000800 630 #define OSC_SB_CPC_DIVERSE_HIGH_SUPPORT 0x00001000 631 #define OSC_SB_IRQ_RESOURCE_SOURCE_SUPPORT 0x00002000 632 #define OSC_SB_CPC_FLEXIBLE_ADR_SPACE 0x00004000 633 #define OSC_SB_GENERIC_INITIATOR_SUPPORT 0x00020000 634 #define OSC_SB_NATIVE_USB4_SUPPORT 0x00040000 635 #define OSC_SB_BATTERY_CHARGE_LIMITING_SUPPORT 0x00080000 636 #define OSC_SB_PRM_SUPPORT 0x00200000 637 #define OSC_SB_FFH_OPR_SUPPORT 0x00400000 638 639 extern bool osc_sb_apei_support_acked; 640 extern bool osc_pc_lpi_support_confirmed; 641 extern bool osc_sb_native_usb4_support_confirmed; 642 extern bool osc_sb_cppc2_support_acked; 643 extern bool osc_cpc_flexible_adr_space_confirmed; 644 645 /* USB4 Capabilities */ 646 #define OSC_USB_USB3_TUNNELING 0x00000001 647 #define OSC_USB_DP_TUNNELING 0x00000002 648 #define OSC_USB_PCIE_TUNNELING 0x00000004 649 #define OSC_USB_XDOMAIN 0x00000008 650 651 extern u32 osc_sb_native_usb4_control; 652 653 /* PCI Host Bridge _OSC: Capabilities DWORD 2: Support Field */ 654 #define OSC_PCI_EXT_CONFIG_SUPPORT 0x00000001 655 #define OSC_PCI_ASPM_SUPPORT 0x00000002 656 #define OSC_PCI_CLOCK_PM_SUPPORT 0x00000004 657 #define OSC_PCI_SEGMENT_GROUPS_SUPPORT 0x00000008 658 #define OSC_PCI_MSI_SUPPORT 0x00000010 659 #define OSC_PCI_EDR_SUPPORT 0x00000080 660 #define OSC_PCI_HPX_TYPE_3_SUPPORT 0x00000100 661 662 /* PCI Host Bridge _OSC: Capabilities DWORD 3: Control Field */ 663 #define OSC_PCI_EXPRESS_NATIVE_HP_CONTROL 0x00000001 664 #define OSC_PCI_SHPC_NATIVE_HP_CONTROL 0x00000002 665 #define OSC_PCI_EXPRESS_PME_CONTROL 0x00000004 666 #define OSC_PCI_EXPRESS_AER_CONTROL 0x00000008 667 #define OSC_PCI_EXPRESS_CAPABILITY_CONTROL 0x00000010 668 #define OSC_PCI_EXPRESS_LTR_CONTROL 0x00000020 669 #define OSC_PCI_EXPRESS_DPC_CONTROL 0x00000080 670 671 /* CXL _OSC: Capabilities DWORD 4: Support Field */ 672 #define OSC_CXL_1_1_PORT_REG_ACCESS_SUPPORT 0x00000001 673 #define OSC_CXL_2_0_PORT_DEV_REG_ACCESS_SUPPORT 0x00000002 674 #define OSC_CXL_PROTOCOL_ERR_REPORTING_SUPPORT 0x00000004 675 #define OSC_CXL_NATIVE_HP_SUPPORT 0x00000008 676 677 /* CXL _OSC: Capabilities DWORD 5: Control Field */ 678 #define OSC_CXL_ERROR_REPORTING_CONTROL 0x00000001 679 680 static inline u32 acpi_osc_ctx_get_pci_control(struct acpi_osc_context *context) 681 { 682 u32 *ret = context->ret.pointer; 683 684 return ret[OSC_CONTROL_DWORD]; 685 } 686 687 static inline u32 acpi_osc_ctx_get_cxl_control(struct acpi_osc_context *context) 688 { 689 u32 *ret = context->ret.pointer; 690 691 return ret[OSC_EXT_CONTROL_DWORD]; 692 } 693 694 #define ACPI_GSB_ACCESS_ATTRIB_QUICK 0x00000002 695 #define ACPI_GSB_ACCESS_ATTRIB_SEND_RCV 0x00000004 696 #define ACPI_GSB_ACCESS_ATTRIB_BYTE 0x00000006 697 #define ACPI_GSB_ACCESS_ATTRIB_WORD 0x00000008 698 #define ACPI_GSB_ACCESS_ATTRIB_BLOCK 0x0000000A 699 #define ACPI_GSB_ACCESS_ATTRIB_MULTIBYTE 0x0000000B 700 #define ACPI_GSB_ACCESS_ATTRIB_WORD_CALL 0x0000000C 701 #define ACPI_GSB_ACCESS_ATTRIB_BLOCK_CALL 0x0000000D 702 #define ACPI_GSB_ACCESS_ATTRIB_RAW_BYTES 0x0000000E 703 #define ACPI_GSB_ACCESS_ATTRIB_RAW_PROCESS 0x0000000F 704 705 /* Enable _OST when all relevant hotplug operations are enabled */ 706 #if defined(CONFIG_ACPI_HOTPLUG_CPU) && \ 707 defined(CONFIG_ACPI_HOTPLUG_MEMORY) && \ 708 defined(CONFIG_ACPI_CONTAINER) 709 #define ACPI_HOTPLUG_OST 710 #endif 711 712 /* _OST Source Event Code (OSPM Action) */ 713 #define ACPI_OST_EC_OSPM_SHUTDOWN 0x100 714 #define ACPI_OST_EC_OSPM_EJECT 0x103 715 #define ACPI_OST_EC_OSPM_INSERTION 0x200 716 717 /* _OST General Processing Status Code */ 718 #define ACPI_OST_SC_SUCCESS 0x0 719 #define ACPI_OST_SC_NON_SPECIFIC_FAILURE 0x1 720 #define ACPI_OST_SC_UNRECOGNIZED_NOTIFY 0x2 721 722 /* _OST OS Shutdown Processing (0x100) Status Code */ 723 #define ACPI_OST_SC_OS_SHUTDOWN_DENIED 0x80 724 #define ACPI_OST_SC_OS_SHUTDOWN_IN_PROGRESS 0x81 725 #define ACPI_OST_SC_OS_SHUTDOWN_COMPLETED 0x82 726 #define ACPI_OST_SC_OS_SHUTDOWN_NOT_SUPPORTED 0x83 727 728 /* _OST Ejection Request (0x3, 0x103) Status Code */ 729 #define ACPI_OST_SC_EJECT_NOT_SUPPORTED 0x80 730 #define ACPI_OST_SC_DEVICE_IN_USE 0x81 731 #define ACPI_OST_SC_DEVICE_BUSY 0x82 732 #define ACPI_OST_SC_EJECT_DEPENDENCY_BUSY 0x83 733 #define ACPI_OST_SC_EJECT_IN_PROGRESS 0x84 734 735 /* _OST Insertion Request (0x200) Status Code */ 736 #define ACPI_OST_SC_INSERT_IN_PROGRESS 0x80 737 #define ACPI_OST_SC_DRIVER_LOAD_FAILURE 0x81 738 #define ACPI_OST_SC_INSERT_NOT_SUPPORTED 0x82 739 740 enum acpi_predicate { 741 all_versions, 742 less_than_or_equal, 743 equal, 744 greater_than_or_equal, 745 }; 746 747 /* Table must be terminted by a NULL entry */ 748 struct acpi_platform_list { 749 char oem_id[ACPI_OEM_ID_SIZE+1]; 750 char oem_table_id[ACPI_OEM_TABLE_ID_SIZE+1]; 751 u32 oem_revision; 752 char *table; 753 enum acpi_predicate pred; 754 char *reason; 755 u32 data; 756 }; 757 int acpi_match_platform_list(const struct acpi_platform_list *plat); 758 759 extern void acpi_early_init(void); 760 extern void acpi_subsystem_init(void); 761 762 extern int acpi_nvs_register(__u64 start, __u64 size); 763 764 extern int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *), 765 void *data); 766 767 const struct acpi_device_id *acpi_match_acpi_device(const struct acpi_device_id *ids, 768 const struct acpi_device *adev); 769 770 const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids, 771 const struct device *dev); 772 773 const void *acpi_device_get_match_data(const struct device *dev); 774 extern bool acpi_driver_match_device(struct device *dev, 775 const struct device_driver *drv); 776 int acpi_device_uevent_modalias(const struct device *, struct kobj_uevent_env *); 777 int acpi_device_modalias(struct device *, char *, int); 778 779 struct platform_device *acpi_create_platform_device(struct acpi_device *, 780 const struct property_entry *); 781 #define ACPI_PTR(_ptr) (_ptr) 782 783 static inline void acpi_device_set_enumerated(struct acpi_device *adev) 784 { 785 adev->flags.visited = true; 786 } 787 788 static inline void acpi_device_clear_enumerated(struct acpi_device *adev) 789 { 790 adev->flags.visited = false; 791 } 792 793 enum acpi_reconfig_event { 794 ACPI_RECONFIG_DEVICE_ADD = 0, 795 ACPI_RECONFIG_DEVICE_REMOVE, 796 }; 797 798 int acpi_reconfig_notifier_register(struct notifier_block *nb); 799 int acpi_reconfig_notifier_unregister(struct notifier_block *nb); 800 801 #ifdef CONFIG_ACPI_GTDT 802 int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count); 803 int acpi_gtdt_map_ppi(int type); 804 bool acpi_gtdt_c3stop(int type); 805 #endif 806 807 #ifndef ACPI_HAVE_ARCH_SET_ROOT_POINTER 808 static __always_inline void acpi_arch_set_root_pointer(u64 addr) 809 { 810 } 811 #endif 812 813 #ifndef ACPI_HAVE_ARCH_GET_ROOT_POINTER 814 static __always_inline u64 acpi_arch_get_root_pointer(void) 815 { 816 return 0; 817 } 818 #endif 819 820 int acpi_get_local_u64_address(acpi_handle handle, u64 *addr); 821 int acpi_get_local_address(acpi_handle handle, u32 *addr); 822 const char *acpi_get_subsystem_id(acpi_handle handle); 823 824 struct device *acpi_bus_find_device_by_name(const char *name); 825 826 #ifdef CONFIG_ACPI_MRRM 827 int acpi_mrrm_max_mem_region(void); 828 #endif 829 830 #define ACPI_CMOS_RTC_IDS \ 831 { "PNP0B00", }, \ 832 { "PNP0B01", }, \ 833 { "PNP0B02", }, \ 834 { "", } 835 836 extern bool cmos_rtc_platform_device_present; 837 838 #else /* !CONFIG_ACPI */ 839 840 #define acpi_disabled 1 841 842 #define ACPI_COMPANION(dev) (NULL) 843 #define ACPI_COMPANION_SET(dev, adev) do { } while (0) 844 #define ACPI_HANDLE(dev) (NULL) 845 #define ACPI_HANDLE_FWNODE(fwnode) (NULL) 846 847 /* Get rid of the -Wunused-variable for adev */ 848 #define acpi_dev_uid_match(adev, uid2) (adev && false) 849 #define acpi_dev_hid_uid_match(adev, hid2, uid2) (adev && false) 850 851 struct fwnode_handle; 852 853 static inline bool acpi_dev_found(const char *hid) 854 { 855 return false; 856 } 857 858 static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) 859 { 860 return false; 861 } 862 863 struct acpi_device; 864 865 static inline int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer) 866 { 867 return -ENODEV; 868 } 869 870 static inline struct acpi_device * 871 acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv) 872 { 873 return NULL; 874 } 875 876 static inline bool acpi_reduced_hardware(void) 877 { 878 return false; 879 } 880 881 static inline void acpi_dev_put(struct acpi_device *adev) {} 882 883 static inline bool is_acpi_node(const struct fwnode_handle *fwnode) 884 { 885 return false; 886 } 887 888 static inline bool is_acpi_device_node(const struct fwnode_handle *fwnode) 889 { 890 return false; 891 } 892 893 static inline struct acpi_device *to_acpi_device_node(const struct fwnode_handle *fwnode) 894 { 895 return NULL; 896 } 897 898 static inline bool is_acpi_data_node(const struct fwnode_handle *fwnode) 899 { 900 return false; 901 } 902 903 static inline struct acpi_data_node *to_acpi_data_node(const struct fwnode_handle *fwnode) 904 { 905 return NULL; 906 } 907 908 static inline bool acpi_data_node_match(const struct fwnode_handle *fwnode, 909 const char *name) 910 { 911 return false; 912 } 913 914 static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev) 915 { 916 return NULL; 917 } 918 919 static inline acpi_handle acpi_device_handle(struct acpi_device *adev) 920 { 921 return NULL; 922 } 923 924 static inline bool has_acpi_companion(struct device *dev) 925 { 926 return false; 927 } 928 929 static inline void acpi_preset_companion(struct device *dev, 930 struct acpi_device *parent, u64 addr) 931 { 932 } 933 934 static inline void acpi_device_clear_deps(struct device *dev) {} 935 936 static inline const char *acpi_dev_name(struct acpi_device *adev) 937 { 938 return NULL; 939 } 940 941 static inline void acpi_early_init(void) { } 942 static inline void acpi_subsystem_init(void) { } 943 944 static inline int early_acpi_boot_init(void) 945 { 946 return 0; 947 } 948 static inline int acpi_boot_init(void) 949 { 950 return 0; 951 } 952 953 static inline void acpi_boot_table_prepare(void) 954 { 955 } 956 957 static inline void acpi_boot_table_init(void) 958 { 959 } 960 961 static inline int acpi_mps_check(void) 962 { 963 return 0; 964 } 965 966 static inline int acpi_check_resource_conflict(struct resource *res) 967 { 968 return 0; 969 } 970 971 static inline int acpi_check_region(resource_size_t start, resource_size_t n, 972 const char *name) 973 { 974 return 0; 975 } 976 977 struct acpi_table_header; 978 static inline int acpi_table_parse(char *id, 979 int (*handler)(struct acpi_table_header *)) 980 { 981 return -ENODEV; 982 } 983 984 static inline int acpi_get_cpu_uid(unsigned int cpu, u32 *uid) 985 { 986 *uid = cpu; 987 return 0; 988 } 989 990 static inline int acpi_nvs_register(__u64 start, __u64 size) 991 { 992 return 0; 993 } 994 995 static inline int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *), 996 void *data) 997 { 998 return 0; 999 } 1000 1001 struct acpi_device_id; 1002 1003 static inline const struct acpi_device_id *acpi_match_acpi_device( 1004 const struct acpi_device_id *ids, const struct acpi_device *adev) 1005 { 1006 return NULL; 1007 } 1008 1009 static inline const struct acpi_device_id *acpi_match_device( 1010 const struct acpi_device_id *ids, const struct device *dev) 1011 { 1012 return NULL; 1013 } 1014 1015 static inline const void *acpi_device_get_match_data(const struct device *dev) 1016 { 1017 return NULL; 1018 } 1019 1020 static inline bool acpi_driver_match_device(struct device *dev, 1021 const struct device_driver *drv) 1022 { 1023 return false; 1024 } 1025 1026 static inline bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, 1027 u64 rev, u64 funcs) 1028 { 1029 return false; 1030 } 1031 1032 static inline union acpi_object *acpi_evaluate_dsm(acpi_handle handle, 1033 const guid_t *guid, 1034 u64 rev, u64 func, 1035 union acpi_object *argv4) 1036 { 1037 return NULL; 1038 } 1039 1040 static inline union acpi_object *acpi_evaluate_dsm_typed(acpi_handle handle, 1041 const guid_t *guid, 1042 u64 rev, u64 func, 1043 union acpi_object *argv4, 1044 acpi_object_type type) 1045 { 1046 return NULL; 1047 } 1048 1049 static inline int acpi_device_uevent_modalias(const struct device *dev, 1050 struct kobj_uevent_env *env) 1051 { 1052 return -ENODEV; 1053 } 1054 1055 static inline int acpi_device_modalias(struct device *dev, 1056 char *buf, int size) 1057 { 1058 return -ENODEV; 1059 } 1060 1061 static inline struct platform_device * 1062 acpi_create_platform_device(struct acpi_device *adev, 1063 const struct property_entry *properties) 1064 { 1065 return NULL; 1066 } 1067 1068 static inline bool acpi_dma_supported(const struct acpi_device *adev) 1069 { 1070 return false; 1071 } 1072 1073 static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev) 1074 { 1075 return DEV_DMA_NOT_SUPPORTED; 1076 } 1077 1078 static inline int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map) 1079 { 1080 return -ENODEV; 1081 } 1082 1083 static inline int acpi_dma_configure(struct device *dev, 1084 enum dev_dma_attr attr) 1085 { 1086 return 0; 1087 } 1088 1089 static inline int acpi_dma_configure_id(struct device *dev, 1090 enum dev_dma_attr attr, 1091 const u32 *input_id) 1092 { 1093 return 0; 1094 } 1095 1096 #define ACPI_PTR(_ptr) (NULL) 1097 1098 static inline void acpi_device_set_enumerated(struct acpi_device *adev) 1099 { 1100 } 1101 1102 static inline void acpi_device_clear_enumerated(struct acpi_device *adev) 1103 { 1104 } 1105 1106 static inline int acpi_reconfig_notifier_register(struct notifier_block *nb) 1107 { 1108 return -EINVAL; 1109 } 1110 1111 static inline int acpi_reconfig_notifier_unregister(struct notifier_block *nb) 1112 { 1113 return -EINVAL; 1114 } 1115 1116 static inline struct acpi_device *acpi_resource_consumer(struct resource *res) 1117 { 1118 return NULL; 1119 } 1120 1121 static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) 1122 { 1123 return -ENODEV; 1124 } 1125 1126 static inline const char *acpi_get_subsystem_id(acpi_handle handle) 1127 { 1128 return ERR_PTR(-ENODEV); 1129 } 1130 1131 static inline struct device *acpi_bus_find_device_by_name(const char *name) 1132 { 1133 return NULL; 1134 } 1135 1136 static inline int acpi_register_wakeup_handler(int wake_irq, 1137 bool (*wakeup)(void *context), void *context) 1138 { 1139 return -ENXIO; 1140 } 1141 1142 static inline void acpi_unregister_wakeup_handler( 1143 bool (*wakeup)(void *context), void *context) { } 1144 1145 struct acpi_osc_context; 1146 static inline u32 acpi_osc_ctx_get_pci_control(struct acpi_osc_context *context) 1147 { 1148 return 0; 1149 } 1150 1151 static inline u32 acpi_osc_ctx_get_cxl_control(struct acpi_osc_context *context) 1152 { 1153 return 0; 1154 } 1155 1156 static inline bool acpi_sleep_state_supported(u8 sleep_state) 1157 { 1158 return false; 1159 } 1160 1161 static inline acpi_handle acpi_get_processor_handle(int cpu) 1162 { 1163 return NULL; 1164 } 1165 1166 static inline int acpi_mrrm_max_mem_region(void) 1167 { 1168 return 1; 1169 } 1170 1171 #define cmos_rtc_platform_device_present false 1172 1173 #endif /* !CONFIG_ACPI */ 1174 1175 #ifdef CONFIG_ACPI_HMAT 1176 int hmat_get_extended_linear_cache_size(struct resource *backing_res, int nid, 1177 resource_size_t *size); 1178 #else 1179 static inline int hmat_get_extended_linear_cache_size(struct resource *backing_res, 1180 int nid, resource_size_t *size) 1181 { 1182 return -EOPNOTSUPP; 1183 } 1184 #endif 1185 1186 extern void arch_post_acpi_subsys_init(void); 1187 1188 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC 1189 int acpi_ioapic_add(acpi_handle root); 1190 #else 1191 static inline int acpi_ioapic_add(acpi_handle root) { return 0; } 1192 #endif 1193 1194 #ifdef CONFIG_ACPI 1195 void acpi_os_set_prepare_sleep(int (*func)(u8 sleep_state, 1196 u32 pm1a_ctrl, u32 pm1b_ctrl)); 1197 1198 acpi_status acpi_os_prepare_sleep(u8 sleep_state, 1199 u32 pm1a_control, u32 pm1b_control); 1200 1201 void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state, 1202 u32 val_a, u32 val_b)); 1203 1204 acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state, 1205 u32 val_a, u32 val_b); 1206 struct acpi_s2idle_dev_ops { 1207 struct list_head list_node; 1208 void (*prepare)(void); 1209 void (*check)(void); 1210 void (*restore)(void); 1211 }; 1212 #if defined(CONFIG_SUSPEND) && defined(CONFIG_X86) 1213 int acpi_register_lps0_dev(struct acpi_s2idle_dev_ops *arg); 1214 void acpi_unregister_lps0_dev(struct acpi_s2idle_dev_ops *arg); 1215 #else /* CONFIG_SUSPEND && CONFIG_X86 */ 1216 static inline int acpi_register_lps0_dev(struct acpi_s2idle_dev_ops *arg) 1217 { 1218 return -ENODEV; 1219 } 1220 static inline void acpi_unregister_lps0_dev(struct acpi_s2idle_dev_ops *arg) 1221 { 1222 } 1223 #endif /* CONFIG_SUSPEND && CONFIG_X86 */ 1224 void arch_reserve_mem_area(acpi_physical_address addr, size_t size); 1225 #else 1226 #define acpi_os_set_prepare_sleep(func, pm1a_ctrl, pm1b_ctrl) do { } while (0) 1227 #endif 1228 1229 #if defined(CONFIG_ACPI) && defined(CONFIG_PM) 1230 int acpi_dev_suspend(struct device *dev, bool wakeup); 1231 int acpi_dev_resume(struct device *dev); 1232 int acpi_subsys_runtime_suspend(struct device *dev); 1233 int acpi_subsys_runtime_resume(struct device *dev); 1234 int acpi_dev_pm_attach(struct device *dev, bool power_on); 1235 bool acpi_storage_d3(struct device *dev); 1236 bool acpi_dev_state_d0(struct device *dev); 1237 #else 1238 static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; } 1239 static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; } 1240 static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) 1241 { 1242 return 0; 1243 } 1244 static inline bool acpi_storage_d3(struct device *dev) 1245 { 1246 return false; 1247 } 1248 static inline bool acpi_dev_state_d0(struct device *dev) 1249 { 1250 return true; 1251 } 1252 #endif 1253 1254 #if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP) 1255 int acpi_subsys_prepare(struct device *dev); 1256 void acpi_subsys_complete(struct device *dev); 1257 int acpi_subsys_suspend_late(struct device *dev); 1258 int acpi_subsys_suspend_noirq(struct device *dev); 1259 int acpi_subsys_suspend(struct device *dev); 1260 int acpi_subsys_freeze(struct device *dev); 1261 int acpi_subsys_poweroff(struct device *dev); 1262 int acpi_subsys_restore_early(struct device *dev); 1263 #else 1264 static inline int acpi_subsys_prepare(struct device *dev) { return 0; } 1265 static inline void acpi_subsys_complete(struct device *dev) {} 1266 static inline int acpi_subsys_suspend_late(struct device *dev) { return 0; } 1267 static inline int acpi_subsys_suspend_noirq(struct device *dev) { return 0; } 1268 static inline int acpi_subsys_suspend(struct device *dev) { return 0; } 1269 static inline int acpi_subsys_freeze(struct device *dev) { return 0; } 1270 static inline int acpi_subsys_poweroff(struct device *dev) { return 0; } 1271 static inline int acpi_subsys_restore_early(struct device *dev) { return 0; } 1272 #endif 1273 1274 #if defined(CONFIG_ACPI_EC) && defined(CONFIG_PM_SLEEP) 1275 void acpi_ec_mark_gpe_for_wake(void); 1276 void acpi_ec_set_gpe_wake_mask(u8 action); 1277 #else 1278 static inline void acpi_ec_mark_gpe_for_wake(void) {} 1279 static inline void acpi_ec_set_gpe_wake_mask(u8 action) {} 1280 #endif 1281 1282 #ifdef CONFIG_ACPI 1283 char *acpi_handle_path(acpi_handle handle); 1284 __printf(3, 4) 1285 void acpi_handle_printk(const char *level, acpi_handle handle, 1286 const char *fmt, ...); 1287 void acpi_evaluation_failure_warn(acpi_handle handle, const char *name, 1288 acpi_status status); 1289 #else /* !CONFIG_ACPI */ 1290 static inline __printf(3, 4) void 1291 acpi_handle_printk(const char *level, void *handle, const char *fmt, ...) {} 1292 static inline void acpi_evaluation_failure_warn(acpi_handle handle, 1293 const char *name, 1294 acpi_status status) {} 1295 #endif /* !CONFIG_ACPI */ 1296 1297 #if defined(CONFIG_ACPI) && defined(CONFIG_DYNAMIC_DEBUG) 1298 __printf(3, 4) 1299 void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const char *fmt, ...); 1300 #endif 1301 1302 /* 1303 * acpi_handle_<level> - Print a message with ACPI prefix and object path 1304 * 1305 * In thread context, the global namespace mutex is acquired to obtain the 1306 * object path. In interrupt context, the object path is shown as <n/a>. 1307 */ 1308 #define acpi_handle_emerg(handle, fmt, ...) \ 1309 acpi_handle_printk(KERN_EMERG, handle, dev_fmt(fmt), ##__VA_ARGS__) 1310 #define acpi_handle_alert(handle, fmt, ...) \ 1311 acpi_handle_printk(KERN_ALERT, handle, dev_fmt(fmt), ##__VA_ARGS__) 1312 #define acpi_handle_crit(handle, fmt, ...) \ 1313 acpi_handle_printk(KERN_CRIT, handle, dev_fmt(fmt), ##__VA_ARGS__) 1314 #define acpi_handle_err(handle, fmt, ...) \ 1315 acpi_handle_printk(KERN_ERR, handle, dev_fmt(fmt), ##__VA_ARGS__) 1316 #define acpi_handle_warn(handle, fmt, ...) \ 1317 acpi_handle_printk(KERN_WARNING, handle, dev_fmt(fmt), ##__VA_ARGS__) 1318 #define acpi_handle_notice(handle, fmt, ...) \ 1319 acpi_handle_printk(KERN_NOTICE, handle, dev_fmt(fmt), ##__VA_ARGS__) 1320 #define acpi_handle_info(handle, fmt, ...) \ 1321 acpi_handle_printk(KERN_INFO, handle, dev_fmt(fmt), ##__VA_ARGS__) 1322 1323 #if defined(DEBUG) 1324 #define acpi_handle_debug(handle, fmt, ...) \ 1325 acpi_handle_printk(KERN_DEBUG, handle, dev_fmt(fmt), ##__VA_ARGS__) 1326 #else 1327 #if defined(CONFIG_DYNAMIC_DEBUG) 1328 #define acpi_handle_debug(handle, fmt, ...) \ 1329 _dynamic_func_call(fmt, __acpi_handle_debug, \ 1330 handle, dev_fmt(fmt), ##__VA_ARGS__) 1331 #else 1332 #define acpi_handle_debug(handle, fmt, ...) \ 1333 ({ \ 1334 if (0) \ 1335 acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__); \ 1336 0; \ 1337 }) 1338 #endif 1339 #endif 1340 1341 #if defined(CONFIG_ACPI) && defined(CONFIG_GPIOLIB) 1342 bool acpi_gpio_get_irq_resource(struct acpi_resource *ares, 1343 struct acpi_resource_gpio **agpio); 1344 bool acpi_gpio_get_io_resource(struct acpi_resource *ares, 1345 struct acpi_resource_gpio **agpio); 1346 int acpi_dev_gpio_irq_wake_get_by(struct acpi_device *adev, const char *con_id, int index, 1347 bool *wake_capable); 1348 #else 1349 static inline bool acpi_gpio_get_irq_resource(struct acpi_resource *ares, 1350 struct acpi_resource_gpio **agpio) 1351 { 1352 return false; 1353 } 1354 static inline bool acpi_gpio_get_io_resource(struct acpi_resource *ares, 1355 struct acpi_resource_gpio **agpio) 1356 { 1357 return false; 1358 } 1359 static inline int acpi_dev_gpio_irq_wake_get_by(struct acpi_device *adev, const char *con_id, 1360 int index, bool *wake_capable) 1361 { 1362 return -ENXIO; 1363 } 1364 #endif 1365 1366 static inline int acpi_dev_gpio_irq_wake_get(struct acpi_device *adev, int index, 1367 bool *wake_capable) 1368 { 1369 return acpi_dev_gpio_irq_wake_get_by(adev, NULL, index, wake_capable); 1370 } 1371 1372 static inline int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *con_id, 1373 int index) 1374 { 1375 return acpi_dev_gpio_irq_wake_get_by(adev, con_id, index, NULL); 1376 } 1377 1378 static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) 1379 { 1380 return acpi_dev_gpio_irq_wake_get_by(adev, NULL, index, NULL); 1381 } 1382 1383 /* Device properties */ 1384 1385 #ifdef CONFIG_ACPI 1386 int acpi_dev_get_property(const struct acpi_device *adev, const char *name, 1387 acpi_object_type type, const union acpi_object **obj); 1388 int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, 1389 const char *name, size_t index, size_t num_args, 1390 struct fwnode_reference_args *args); 1391 1392 static inline int acpi_node_get_property_reference( 1393 const struct fwnode_handle *fwnode, 1394 const char *name, size_t index, 1395 struct fwnode_reference_args *args) 1396 { 1397 return __acpi_node_get_property_reference(fwnode, name, index, 1398 NR_FWNODE_REFERENCE_ARGS, args); 1399 } 1400 1401 static inline bool acpi_dev_has_props(const struct acpi_device *adev) 1402 { 1403 return !list_empty(&adev->data.properties); 1404 } 1405 1406 struct acpi_device_properties * 1407 acpi_data_add_props(struct acpi_device_data *data, const guid_t *guid, 1408 union acpi_object *properties); 1409 1410 int acpi_node_prop_get(const struct fwnode_handle *fwnode, const char *propname, 1411 void **valptr); 1412 1413 struct acpi_probe_entry; 1414 typedef bool (*acpi_probe_entry_validate_subtbl)(struct acpi_subtable_header *, 1415 struct acpi_probe_entry *); 1416 1417 #define ACPI_TABLE_ID_LEN 5 1418 1419 /** 1420 * struct acpi_probe_entry - boot-time probing entry 1421 * @id: ACPI table name 1422 * @type: Optional subtable type to match 1423 * (if @id contains subtables) 1424 * @subtable_valid: Optional callback to check the validity of 1425 * the subtable 1426 * @probe_table: Callback to the driver being probed when table 1427 * match is successful 1428 * @probe_subtbl: Callback to the driver being probed when table and 1429 * subtable match (and optional callback is successful) 1430 * @driver_data: Sideband data provided back to the driver 1431 */ 1432 struct acpi_probe_entry { 1433 __u8 id[ACPI_TABLE_ID_LEN]; 1434 __u8 type; 1435 acpi_probe_entry_validate_subtbl subtable_valid; 1436 union { 1437 acpi_tbl_table_handler probe_table; 1438 acpi_tbl_entry_handler probe_subtbl; 1439 }; 1440 kernel_ulong_t driver_data; 1441 }; 1442 1443 void arch_sort_irqchip_probe(struct acpi_probe_entry *ap_head, int nr); 1444 1445 #define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, subtable, \ 1446 valid, data, fn) \ 1447 static const struct acpi_probe_entry __acpi_probe_##name \ 1448 __used __section("__" #table "_acpi_probe_table") = { \ 1449 .id = table_id, \ 1450 .type = subtable, \ 1451 .subtable_valid = valid, \ 1452 .probe_table = fn, \ 1453 .driver_data = data, \ 1454 } 1455 1456 #define ACPI_DECLARE_SUBTABLE_PROBE_ENTRY(table, name, table_id, \ 1457 subtable, valid, data, fn) \ 1458 static const struct acpi_probe_entry __acpi_probe_##name \ 1459 __used __section("__" #table "_acpi_probe_table") = { \ 1460 .id = table_id, \ 1461 .type = subtable, \ 1462 .subtable_valid = valid, \ 1463 .probe_subtbl = fn, \ 1464 .driver_data = data, \ 1465 } 1466 1467 #define ACPI_PROBE_TABLE(name) __##name##_acpi_probe_table 1468 #define ACPI_PROBE_TABLE_END(name) __##name##_acpi_probe_table_end 1469 1470 int __acpi_probe_device_table(struct acpi_probe_entry *start, int nr); 1471 1472 #define acpi_probe_device_table(t) \ 1473 ({ \ 1474 extern struct acpi_probe_entry ACPI_PROBE_TABLE(t), \ 1475 ACPI_PROBE_TABLE_END(t); \ 1476 __acpi_probe_device_table(&ACPI_PROBE_TABLE(t), \ 1477 (&ACPI_PROBE_TABLE_END(t) - \ 1478 &ACPI_PROBE_TABLE(t))); \ 1479 }) 1480 #else 1481 static inline int acpi_dev_get_property(struct acpi_device *adev, 1482 const char *name, acpi_object_type type, 1483 const union acpi_object **obj) 1484 { 1485 return -ENXIO; 1486 } 1487 1488 static inline int 1489 __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, 1490 const char *name, size_t index, size_t num_args, 1491 struct fwnode_reference_args *args) 1492 { 1493 return -ENXIO; 1494 } 1495 1496 static inline int 1497 acpi_node_get_property_reference(const struct fwnode_handle *fwnode, 1498 const char *name, size_t index, 1499 struct fwnode_reference_args *args) 1500 { 1501 return -ENXIO; 1502 } 1503 1504 static inline int acpi_node_prop_get(const struct fwnode_handle *fwnode, 1505 const char *propname, 1506 void **valptr) 1507 { 1508 return -ENXIO; 1509 } 1510 1511 static inline struct fwnode_handle * 1512 acpi_graph_get_next_endpoint(const struct fwnode_handle *fwnode, 1513 struct fwnode_handle *prev) 1514 { 1515 return ERR_PTR(-ENXIO); 1516 } 1517 1518 static inline int 1519 acpi_graph_get_remote_endpoint(const struct fwnode_handle *fwnode, 1520 struct fwnode_handle **remote, 1521 struct fwnode_handle **port, 1522 struct fwnode_handle **endpoint) 1523 { 1524 return -ENXIO; 1525 } 1526 1527 #define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, subtable, valid, data, fn) \ 1528 static const void * __acpi_table_##name[] \ 1529 __attribute__((unused)) \ 1530 = { (void *) table_id, \ 1531 (void *) subtable, \ 1532 (void *) valid, \ 1533 (void *) fn, \ 1534 (void *) data } 1535 1536 #define acpi_probe_device_table(t) ({ int __r = 0; __r;}) 1537 #endif 1538 1539 #ifdef CONFIG_ACPI_TABLE_UPGRADE 1540 void acpi_table_upgrade(void); 1541 #else 1542 static inline void acpi_table_upgrade(void) { } 1543 #endif 1544 1545 #if defined(CONFIG_ACPI) && defined(CONFIG_ACPI_WATCHDOG) 1546 extern bool acpi_has_watchdog(void); 1547 #else 1548 static inline bool acpi_has_watchdog(void) { return false; } 1549 #endif 1550 1551 #ifdef CONFIG_ACPI_SPCR_TABLE 1552 extern bool qdf2400_e44_present; 1553 int acpi_parse_spcr(bool enable_earlycon, bool enable_console); 1554 #else 1555 static inline int acpi_parse_spcr(bool enable_earlycon, bool enable_console) 1556 { 1557 return -ENODEV; 1558 } 1559 #endif 1560 1561 #if IS_ENABLED(CONFIG_ACPI_GENERIC_GSI) 1562 int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res); 1563 const struct cpumask *acpi_irq_get_affinity(acpi_handle handle, 1564 unsigned int index); 1565 #else 1566 static inline 1567 int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res) 1568 { 1569 return -EINVAL; 1570 } 1571 static inline const struct cpumask *acpi_irq_get_affinity(acpi_handle handle, 1572 unsigned int index) 1573 { 1574 return NULL; 1575 } 1576 #endif 1577 1578 #ifdef CONFIG_ACPI_LPIT 1579 int lpit_read_residency_count_address(u64 *address); 1580 #else 1581 static inline int lpit_read_residency_count_address(u64 *address) 1582 { 1583 return -EINVAL; 1584 } 1585 #endif 1586 1587 #ifdef CONFIG_ACPI_PROCESSOR_IDLE 1588 #ifndef arch_get_idle_state_flags 1589 static inline unsigned int arch_get_idle_state_flags(u32 arch_flags) 1590 { 1591 return 0; 1592 } 1593 #endif 1594 #endif /* CONFIG_ACPI_PROCESSOR_IDLE */ 1595 1596 #ifdef CONFIG_ACPI_PPTT 1597 int acpi_pptt_cpu_is_thread(unsigned int cpu); 1598 int find_acpi_cpu_topology(unsigned int cpu, int level); 1599 int find_acpi_cpu_topology_cluster(unsigned int cpu); 1600 int find_acpi_cpu_topology_package(unsigned int cpu); 1601 int find_acpi_cpu_topology_hetero_id(unsigned int cpu); 1602 void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id, cpumask_t *cpus); 1603 int find_acpi_cache_level_from_id(u32 cache_id); 1604 int acpi_pptt_get_cpumask_from_cache_id(u32 cache_id, cpumask_t *cpus); 1605 #else 1606 static inline int acpi_pptt_cpu_is_thread(unsigned int cpu) 1607 { 1608 return -EINVAL; 1609 } 1610 static inline int find_acpi_cpu_topology(unsigned int cpu, int level) 1611 { 1612 return -EINVAL; 1613 } 1614 static inline int find_acpi_cpu_topology_cluster(unsigned int cpu) 1615 { 1616 return -EINVAL; 1617 } 1618 static inline int find_acpi_cpu_topology_package(unsigned int cpu) 1619 { 1620 return -EINVAL; 1621 } 1622 static inline int find_acpi_cpu_topology_hetero_id(unsigned int cpu) 1623 { 1624 return -EINVAL; 1625 } 1626 static inline void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id, 1627 cpumask_t *cpus) { } 1628 static inline int find_acpi_cache_level_from_id(u32 cache_id) 1629 { 1630 return -ENOENT; 1631 } 1632 static inline int acpi_pptt_get_cpumask_from_cache_id(u32 cache_id, 1633 cpumask_t *cpus) 1634 { 1635 return -ENOENT; 1636 } 1637 #endif 1638 1639 void acpi_arch_init(void); 1640 1641 #ifdef CONFIG_ACPI_PCC 1642 void acpi_init_pcc(void); 1643 #else 1644 static inline void acpi_init_pcc(void) { } 1645 #endif 1646 1647 #ifdef CONFIG_ACPI_FFH 1648 void acpi_init_ffh(void); 1649 extern int acpi_ffh_address_space_arch_setup(void *handler_ctxt, 1650 void **region_ctxt); 1651 extern int acpi_ffh_address_space_arch_handler(acpi_integer *value, 1652 void *region_context); 1653 #else 1654 static inline void acpi_init_ffh(void) { } 1655 #endif 1656 1657 #ifdef CONFIG_ACPI 1658 extern void acpi_device_notify(struct device *dev); 1659 extern void acpi_device_notify_remove(struct device *dev); 1660 #else 1661 static inline void acpi_device_notify(struct device *dev) { } 1662 static inline void acpi_device_notify_remove(struct device *dev) { } 1663 #endif 1664 1665 static inline void acpi_use_parent_companion(struct device *dev) 1666 { 1667 ACPI_COMPANION_SET(dev, ACPI_COMPANION(dev->parent)); 1668 } 1669 1670 #ifdef CONFIG_ACPI_NUMA 1671 bool acpi_node_backed_by_real_pxm(int nid); 1672 #else 1673 static inline bool acpi_node_backed_by_real_pxm(int nid) 1674 { 1675 return false; 1676 } 1677 #endif 1678 1679 #endif /*_LINUX_ACPI_H*/ 1680