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