acpi.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. /*
  2. * acpi.h - ACPI Interface
  3. *
  4. * Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  5. *
  6. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. */
  20. #ifndef _LINUX_ACPI_H
  21. #define _LINUX_ACPI_H
  22. #include <linux/errno.h>
  23. #include <linux/ioport.h> /* for struct resource */
  24. #include <linux/resource_ext.h>
  25. #include <linux/device.h>
  26. #include <linux/property.h>
  27. #ifndef _LINUX
  28. #define _LINUX
  29. #endif
  30. #include <acpi/acpi.h>
  31. #ifdef CONFIG_ACPI
  32. #include <linux/list.h>
  33. #include <linux/mod_devicetable.h>
  34. #include <linux/dynamic_debug.h>
  35. #include <acpi/acpi_bus.h>
  36. #include <acpi/acpi_drivers.h>
  37. #include <acpi/acpi_numa.h>
  38. #include <acpi/acpi_io.h>
  39. #include <asm/acpi.h>
  40. static inline acpi_handle acpi_device_handle(struct acpi_device *adev)
  41. {
  42. return adev ? adev->handle : NULL;
  43. }
  44. #define ACPI_COMPANION(dev) to_acpi_device_node((dev)->fwnode)
  45. #define ACPI_COMPANION_SET(dev, adev) set_primary_fwnode(dev, (adev) ? \
  46. acpi_fwnode_handle(adev) : NULL)
  47. #define ACPI_HANDLE(dev) acpi_device_handle(ACPI_COMPANION(dev))
  48. /**
  49. * ACPI_DEVICE_CLASS - macro used to describe an ACPI device with
  50. * the PCI-defined class-code information
  51. *
  52. * @_cls : the class, subclass, prog-if triple for this device
  53. * @_msk : the class mask for this device
  54. *
  55. * This macro is used to create a struct acpi_device_id that matches a
  56. * specific PCI class. The .id and .driver_data fields will be left
  57. * initialized with the default value.
  58. */
  59. #define ACPI_DEVICE_CLASS(_cls, _msk) .cls = (_cls), .cls_msk = (_msk),
  60. static inline bool has_acpi_companion(struct device *dev)
  61. {
  62. return is_acpi_device_node(dev->fwnode);
  63. }
  64. static inline void acpi_preset_companion(struct device *dev,
  65. struct acpi_device *parent, u64 addr)
  66. {
  67. ACPI_COMPANION_SET(dev, acpi_find_child_device(parent, addr, NULL));
  68. }
  69. static inline const char *acpi_dev_name(struct acpi_device *adev)
  70. {
  71. return dev_name(&adev->dev);
  72. }
  73. enum acpi_irq_model_id {
  74. ACPI_IRQ_MODEL_PIC = 0,
  75. ACPI_IRQ_MODEL_IOAPIC,
  76. ACPI_IRQ_MODEL_IOSAPIC,
  77. ACPI_IRQ_MODEL_PLATFORM,
  78. ACPI_IRQ_MODEL_GIC,
  79. ACPI_IRQ_MODEL_COUNT
  80. };
  81. extern enum acpi_irq_model_id acpi_irq_model;
  82. enum acpi_interrupt_id {
  83. ACPI_INTERRUPT_PMI = 1,
  84. ACPI_INTERRUPT_INIT,
  85. ACPI_INTERRUPT_CPEI,
  86. ACPI_INTERRUPT_COUNT
  87. };
  88. #define ACPI_SPACE_MEM 0
  89. enum acpi_address_range_id {
  90. ACPI_ADDRESS_RANGE_MEMORY = 1,
  91. ACPI_ADDRESS_RANGE_RESERVED = 2,
  92. ACPI_ADDRESS_RANGE_ACPI = 3,
  93. ACPI_ADDRESS_RANGE_NVS = 4,
  94. ACPI_ADDRESS_RANGE_COUNT
  95. };
  96. /* Table Handlers */
  97. typedef int (*acpi_tbl_table_handler)(struct acpi_table_header *table);
  98. typedef int (*acpi_tbl_entry_handler)(struct acpi_subtable_header *header,
  99. const unsigned long end);
  100. #ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
  101. void acpi_initrd_override(void *data, size_t size);
  102. #else
  103. static inline void acpi_initrd_override(void *data, size_t size)
  104. {
  105. }
  106. #endif
  107. #define BAD_MADT_ENTRY(entry, end) ( \
  108. (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
  109. ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
  110. struct acpi_subtable_proc {
  111. int id;
  112. acpi_tbl_entry_handler handler;
  113. int count;
  114. };
  115. char * __acpi_map_table (unsigned long phys_addr, unsigned long size);
  116. void __acpi_unmap_table(char *map, unsigned long size);
  117. int early_acpi_boot_init(void);
  118. int acpi_boot_init (void);
  119. void acpi_boot_table_init (void);
  120. int acpi_mps_check (void);
  121. int acpi_numa_init (void);
  122. int acpi_table_init (void);
  123. int acpi_table_parse(char *id, acpi_tbl_table_handler handler);
  124. int __init acpi_parse_entries(char *id, unsigned long table_size,
  125. acpi_tbl_entry_handler handler,
  126. struct acpi_table_header *table_header,
  127. int entry_id, unsigned int max_entries);
  128. int __init acpi_table_parse_entries(char *id, unsigned long table_size,
  129. int entry_id,
  130. acpi_tbl_entry_handler handler,
  131. unsigned int max_entries);
  132. int __init acpi_table_parse_entries(char *id, unsigned long table_size,
  133. int entry_id,
  134. acpi_tbl_entry_handler handler,
  135. unsigned int max_entries);
  136. int __init acpi_table_parse_entries_array(char *id, unsigned long table_size,
  137. struct acpi_subtable_proc *proc, int proc_num,
  138. unsigned int max_entries);
  139. int acpi_table_parse_madt(enum acpi_madt_type id,
  140. acpi_tbl_entry_handler handler,
  141. unsigned int max_entries);
  142. int acpi_parse_mcfg (struct acpi_table_header *header);
  143. void acpi_table_print_madt_entry (struct acpi_subtable_header *madt);
  144. /* the following four functions are architecture-dependent */
  145. void acpi_numa_slit_init (struct acpi_table_slit *slit);
  146. void acpi_numa_processor_affinity_init (struct acpi_srat_cpu_affinity *pa);
  147. void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
  148. int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
  149. void acpi_numa_arch_fixup(void);
  150. #ifndef PHYS_CPUID_INVALID
  151. typedef u32 phys_cpuid_t;
  152. #define PHYS_CPUID_INVALID (phys_cpuid_t)(-1)
  153. #endif
  154. static inline bool invalid_logical_cpuid(u32 cpuid)
  155. {
  156. return (int)cpuid < 0;
  157. }
  158. static inline bool invalid_phys_cpuid(phys_cpuid_t phys_id)
  159. {
  160. return phys_id == PHYS_CPUID_INVALID;
  161. }
  162. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  163. /* Arch dependent functions for cpu hotplug support */
  164. int acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, int *pcpu);
  165. int acpi_unmap_cpu(int cpu);
  166. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  167. #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
  168. int acpi_get_ioapic_id(acpi_handle handle, u32 gsi_base, u64 *phys_addr);
  169. #endif
  170. int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base);
  171. int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base);
  172. int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base);
  173. void acpi_irq_stats_init(void);
  174. extern u32 acpi_irq_handled;
  175. extern u32 acpi_irq_not_handled;
  176. extern unsigned int acpi_sci_irq;
  177. #define INVALID_ACPI_IRQ ((unsigned)-1)
  178. static inline bool acpi_sci_irq_valid(void)
  179. {
  180. return acpi_sci_irq != INVALID_ACPI_IRQ;
  181. }
  182. extern int sbf_port;
  183. extern unsigned long acpi_realmode_flags;
  184. int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity);
  185. int acpi_gsi_to_irq (u32 gsi, unsigned int *irq);
  186. int acpi_isa_irq_to_gsi (unsigned isa_irq, u32 *gsi);
  187. void acpi_set_irq_model(enum acpi_irq_model_id model,
  188. struct fwnode_handle *fwnode);
  189. #ifdef CONFIG_X86_IO_APIC
  190. extern int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity);
  191. #else
  192. #define acpi_get_override_irq(gsi, trigger, polarity) (-1)
  193. #endif
  194. /*
  195. * This function undoes the effect of one call to acpi_register_gsi().
  196. * If this matches the last registration, any IRQ resources for gsi
  197. * are freed.
  198. */
  199. void acpi_unregister_gsi (u32 gsi);
  200. struct pci_dev;
  201. int acpi_pci_irq_enable (struct pci_dev *dev);
  202. void acpi_penalize_isa_irq(int irq, int active);
  203. bool acpi_isa_irq_available(int irq);
  204. void acpi_penalize_sci_irq(int irq, int trigger, int polarity);
  205. void acpi_pci_irq_disable (struct pci_dev *dev);
  206. extern int ec_read(u8 addr, u8 *val);
  207. extern int ec_write(u8 addr, u8 val);
  208. extern int ec_transaction(u8 command,
  209. const u8 *wdata, unsigned wdata_len,
  210. u8 *rdata, unsigned rdata_len);
  211. extern acpi_handle ec_get_handle(void);
  212. extern bool acpi_is_pnp_device(struct acpi_device *);
  213. #if defined(CONFIG_ACPI_WMI) || defined(CONFIG_ACPI_WMI_MODULE)
  214. typedef void (*wmi_notify_handler) (u32 value, void *context);
  215. extern acpi_status wmi_evaluate_method(const char *guid, u8 instance,
  216. u32 method_id,
  217. const struct acpi_buffer *in,
  218. struct acpi_buffer *out);
  219. extern acpi_status wmi_query_block(const char *guid, u8 instance,
  220. struct acpi_buffer *out);
  221. extern acpi_status wmi_set_block(const char *guid, u8 instance,
  222. const struct acpi_buffer *in);
  223. extern acpi_status wmi_install_notify_handler(const char *guid,
  224. wmi_notify_handler handler, void *data);
  225. extern acpi_status wmi_remove_notify_handler(const char *guid);
  226. extern acpi_status wmi_get_event_data(u32 event, struct acpi_buffer *out);
  227. extern bool wmi_has_guid(const char *guid);
  228. #endif /* CONFIG_ACPI_WMI */
  229. #define ACPI_VIDEO_OUTPUT_SWITCHING 0x0001
  230. #define ACPI_VIDEO_DEVICE_POSTING 0x0002
  231. #define ACPI_VIDEO_ROM_AVAILABLE 0x0004
  232. #define ACPI_VIDEO_BACKLIGHT 0x0008
  233. #define ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR 0x0010
  234. #define ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO 0x0020
  235. #define ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VENDOR 0x0040
  236. #define ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VIDEO 0x0080
  237. #define ACPI_VIDEO_BACKLIGHT_DMI_VENDOR 0x0100
  238. #define ACPI_VIDEO_BACKLIGHT_DMI_VIDEO 0x0200
  239. #define ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VENDOR 0x0400
  240. #define ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VIDEO 0x0800
  241. extern char acpi_video_backlight_string[];
  242. extern long acpi_is_video_device(acpi_handle handle);
  243. extern int acpi_blacklisted(void);
  244. extern void acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d);
  245. extern void acpi_osi_setup(char *str);
  246. extern bool acpi_osi_is_win8(void);
  247. #ifdef CONFIG_ACPI_NUMA
  248. int acpi_map_pxm_to_online_node(int pxm);
  249. int acpi_get_node(acpi_handle handle);
  250. #else
  251. static inline int acpi_map_pxm_to_online_node(int pxm)
  252. {
  253. return 0;
  254. }
  255. static inline int acpi_get_node(acpi_handle handle)
  256. {
  257. return 0;
  258. }
  259. #endif
  260. extern int acpi_paddr_to_node(u64 start_addr, u64 size);
  261. extern int pnpacpi_disabled;
  262. #define PXM_INVAL (-1)
  263. bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res);
  264. bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res);
  265. bool acpi_dev_resource_address_space(struct acpi_resource *ares,
  266. struct resource_win *win);
  267. bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares,
  268. struct resource_win *win);
  269. unsigned long acpi_dev_irq_flags(u8 triggering, u8 polarity, u8 shareable);
  270. bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index,
  271. struct resource *res);
  272. void acpi_dev_free_resource_list(struct list_head *list);
  273. int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
  274. int (*preproc)(struct acpi_resource *, void *),
  275. void *preproc_data);
  276. int acpi_dev_filter_resource_type(struct acpi_resource *ares,
  277. unsigned long types);
  278. static inline int acpi_dev_filter_resource_type_cb(struct acpi_resource *ares,
  279. void *arg)
  280. {
  281. return acpi_dev_filter_resource_type(ares, (unsigned long)arg);
  282. }
  283. int acpi_check_resource_conflict(const struct resource *res);
  284. int acpi_check_region(resource_size_t start, resource_size_t n,
  285. const char *name);
  286. int acpi_resources_are_enforced(void);
  287. #ifdef CONFIG_HIBERNATION
  288. void __init acpi_no_s4_hw_signature(void);
  289. #endif
  290. #ifdef CONFIG_PM_SLEEP
  291. void __init acpi_old_suspend_ordering(void);
  292. void __init acpi_nvs_nosave(void);
  293. void __init acpi_nvs_nosave_s3(void);
  294. #endif /* CONFIG_PM_SLEEP */
  295. struct acpi_osc_context {
  296. char *uuid_str; /* UUID string */
  297. int rev;
  298. struct acpi_buffer cap; /* list of DWORD capabilities */
  299. struct acpi_buffer ret; /* free by caller if success */
  300. };
  301. acpi_status acpi_str_to_uuid(char *str, u8 *uuid);
  302. acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context);
  303. /* Indexes into _OSC Capabilities Buffer (DWORDs 2 & 3 are device-specific) */
  304. #define OSC_QUERY_DWORD 0 /* DWORD 1 */
  305. #define OSC_SUPPORT_DWORD 1 /* DWORD 2 */
  306. #define OSC_CONTROL_DWORD 2 /* DWORD 3 */
  307. /* _OSC Capabilities DWORD 1: Query/Control and Error Returns (generic) */
  308. #define OSC_QUERY_ENABLE 0x00000001 /* input */
  309. #define OSC_REQUEST_ERROR 0x00000002 /* return */
  310. #define OSC_INVALID_UUID_ERROR 0x00000004 /* return */
  311. #define OSC_INVALID_REVISION_ERROR 0x00000008 /* return */
  312. #define OSC_CAPABILITIES_MASK_ERROR 0x00000010 /* return */
  313. /* Platform-Wide Capabilities _OSC: Capabilities DWORD 2: Support Field */
  314. #define OSC_SB_PAD_SUPPORT 0x00000001
  315. #define OSC_SB_PPC_OST_SUPPORT 0x00000002
  316. #define OSC_SB_PR3_SUPPORT 0x00000004
  317. #define OSC_SB_HOTPLUG_OST_SUPPORT 0x00000008
  318. #define OSC_SB_APEI_SUPPORT 0x00000010
  319. #define OSC_SB_CPC_SUPPORT 0x00000020
  320. extern bool osc_sb_apei_support_acked;
  321. /* PCI Host Bridge _OSC: Capabilities DWORD 2: Support Field */
  322. #define OSC_PCI_EXT_CONFIG_SUPPORT 0x00000001
  323. #define OSC_PCI_ASPM_SUPPORT 0x00000002
  324. #define OSC_PCI_CLOCK_PM_SUPPORT 0x00000004
  325. #define OSC_PCI_SEGMENT_GROUPS_SUPPORT 0x00000008
  326. #define OSC_PCI_MSI_SUPPORT 0x00000010
  327. #define OSC_PCI_SUPPORT_MASKS 0x0000001f
  328. /* PCI Host Bridge _OSC: Capabilities DWORD 3: Control Field */
  329. #define OSC_PCI_EXPRESS_NATIVE_HP_CONTROL 0x00000001
  330. #define OSC_PCI_SHPC_NATIVE_HP_CONTROL 0x00000002
  331. #define OSC_PCI_EXPRESS_PME_CONTROL 0x00000004
  332. #define OSC_PCI_EXPRESS_AER_CONTROL 0x00000008
  333. #define OSC_PCI_EXPRESS_CAPABILITY_CONTROL 0x00000010
  334. #define OSC_PCI_CONTROL_MASKS 0x0000001f
  335. #define ACPI_GSB_ACCESS_ATTRIB_QUICK 0x00000002
  336. #define ACPI_GSB_ACCESS_ATTRIB_SEND_RCV 0x00000004
  337. #define ACPI_GSB_ACCESS_ATTRIB_BYTE 0x00000006
  338. #define ACPI_GSB_ACCESS_ATTRIB_WORD 0x00000008
  339. #define ACPI_GSB_ACCESS_ATTRIB_BLOCK 0x0000000A
  340. #define ACPI_GSB_ACCESS_ATTRIB_MULTIBYTE 0x0000000B
  341. #define ACPI_GSB_ACCESS_ATTRIB_WORD_CALL 0x0000000C
  342. #define ACPI_GSB_ACCESS_ATTRIB_BLOCK_CALL 0x0000000D
  343. #define ACPI_GSB_ACCESS_ATTRIB_RAW_BYTES 0x0000000E
  344. #define ACPI_GSB_ACCESS_ATTRIB_RAW_PROCESS 0x0000000F
  345. extern acpi_status acpi_pci_osc_control_set(acpi_handle handle,
  346. u32 *mask, u32 req);
  347. /* Enable _OST when all relevant hotplug operations are enabled */
  348. #if defined(CONFIG_ACPI_HOTPLUG_CPU) && \
  349. defined(CONFIG_ACPI_HOTPLUG_MEMORY) && \
  350. defined(CONFIG_ACPI_CONTAINER)
  351. #define ACPI_HOTPLUG_OST
  352. #endif
  353. /* _OST Source Event Code (OSPM Action) */
  354. #define ACPI_OST_EC_OSPM_SHUTDOWN 0x100
  355. #define ACPI_OST_EC_OSPM_EJECT 0x103
  356. #define ACPI_OST_EC_OSPM_INSERTION 0x200
  357. /* _OST General Processing Status Code */
  358. #define ACPI_OST_SC_SUCCESS 0x0
  359. #define ACPI_OST_SC_NON_SPECIFIC_FAILURE 0x1
  360. #define ACPI_OST_SC_UNRECOGNIZED_NOTIFY 0x2
  361. /* _OST OS Shutdown Processing (0x100) Status Code */
  362. #define ACPI_OST_SC_OS_SHUTDOWN_DENIED 0x80
  363. #define ACPI_OST_SC_OS_SHUTDOWN_IN_PROGRESS 0x81
  364. #define ACPI_OST_SC_OS_SHUTDOWN_COMPLETED 0x82
  365. #define ACPI_OST_SC_OS_SHUTDOWN_NOT_SUPPORTED 0x83
  366. /* _OST Ejection Request (0x3, 0x103) Status Code */
  367. #define ACPI_OST_SC_EJECT_NOT_SUPPORTED 0x80
  368. #define ACPI_OST_SC_DEVICE_IN_USE 0x81
  369. #define ACPI_OST_SC_DEVICE_BUSY 0x82
  370. #define ACPI_OST_SC_EJECT_DEPENDENCY_BUSY 0x83
  371. #define ACPI_OST_SC_EJECT_IN_PROGRESS 0x84
  372. /* _OST Insertion Request (0x200) Status Code */
  373. #define ACPI_OST_SC_INSERT_IN_PROGRESS 0x80
  374. #define ACPI_OST_SC_DRIVER_LOAD_FAILURE 0x81
  375. #define ACPI_OST_SC_INSERT_NOT_SUPPORTED 0x82
  376. extern void acpi_early_init(void);
  377. extern void acpi_subsystem_init(void);
  378. extern int acpi_nvs_register(__u64 start, __u64 size);
  379. extern int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *),
  380. void *data);
  381. const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
  382. const struct device *dev);
  383. extern bool acpi_driver_match_device(struct device *dev,
  384. const struct device_driver *drv);
  385. int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *);
  386. int acpi_device_modalias(struct device *, char *, int);
  387. void acpi_walk_dep_device_list(acpi_handle handle);
  388. struct platform_device *acpi_create_platform_device(struct acpi_device *);
  389. #define ACPI_PTR(_ptr) (_ptr)
  390. #else /* !CONFIG_ACPI */
  391. #define acpi_disabled 1
  392. #define ACPI_COMPANION(dev) (NULL)
  393. #define ACPI_COMPANION_SET(dev, adev) do { } while (0)
  394. #define ACPI_HANDLE(dev) (NULL)
  395. #define ACPI_DEVICE_CLASS(_cls, _msk) .cls = (0), .cls_msk = (0),
  396. struct fwnode_handle;
  397. static inline bool is_acpi_node(struct fwnode_handle *fwnode)
  398. {
  399. return false;
  400. }
  401. static inline bool is_acpi_device_node(struct fwnode_handle *fwnode)
  402. {
  403. return false;
  404. }
  405. static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode)
  406. {
  407. return NULL;
  408. }
  409. static inline bool is_acpi_data_node(struct fwnode_handle *fwnode)
  410. {
  411. return false;
  412. }
  413. static inline struct acpi_data_node *to_acpi_data_node(struct fwnode_handle *fwnode)
  414. {
  415. return NULL;
  416. }
  417. static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev)
  418. {
  419. return NULL;
  420. }
  421. static inline bool has_acpi_companion(struct device *dev)
  422. {
  423. return false;
  424. }
  425. static inline void acpi_preset_companion(struct device *dev,
  426. struct acpi_device *parent, u64 addr)
  427. {
  428. }
  429. static inline const char *acpi_dev_name(struct acpi_device *adev)
  430. {
  431. return NULL;
  432. }
  433. static inline void acpi_early_init(void) { }
  434. static inline void acpi_subsystem_init(void) { }
  435. static inline int early_acpi_boot_init(void)
  436. {
  437. return 0;
  438. }
  439. static inline int acpi_boot_init(void)
  440. {
  441. return 0;
  442. }
  443. static inline void acpi_boot_table_init(void)
  444. {
  445. return;
  446. }
  447. static inline int acpi_mps_check(void)
  448. {
  449. return 0;
  450. }
  451. static inline int acpi_check_resource_conflict(struct resource *res)
  452. {
  453. return 0;
  454. }
  455. static inline int acpi_check_region(resource_size_t start, resource_size_t n,
  456. const char *name)
  457. {
  458. return 0;
  459. }
  460. struct acpi_table_header;
  461. static inline int acpi_table_parse(char *id,
  462. int (*handler)(struct acpi_table_header *))
  463. {
  464. return -ENODEV;
  465. }
  466. static inline int acpi_nvs_register(__u64 start, __u64 size)
  467. {
  468. return 0;
  469. }
  470. static inline int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *),
  471. void *data)
  472. {
  473. return 0;
  474. }
  475. struct acpi_device_id;
  476. static inline const struct acpi_device_id *acpi_match_device(
  477. const struct acpi_device_id *ids, const struct device *dev)
  478. {
  479. return NULL;
  480. }
  481. static inline bool acpi_driver_match_device(struct device *dev,
  482. const struct device_driver *drv)
  483. {
  484. return false;
  485. }
  486. static inline int acpi_device_uevent_modalias(struct device *dev,
  487. struct kobj_uevent_env *env)
  488. {
  489. return -ENODEV;
  490. }
  491. static inline int acpi_device_modalias(struct device *dev,
  492. char *buf, int size)
  493. {
  494. return -ENODEV;
  495. }
  496. static inline bool acpi_dma_supported(struct acpi_device *adev)
  497. {
  498. return false;
  499. }
  500. static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
  501. {
  502. return DEV_DMA_NOT_SUPPORTED;
  503. }
  504. #define ACPI_PTR(_ptr) (NULL)
  505. #endif /* !CONFIG_ACPI */
  506. #ifdef CONFIG_ACPI
  507. void acpi_os_set_prepare_sleep(int (*func)(u8 sleep_state,
  508. u32 pm1a_ctrl, u32 pm1b_ctrl));
  509. acpi_status acpi_os_prepare_sleep(u8 sleep_state,
  510. u32 pm1a_control, u32 pm1b_control);
  511. void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state,
  512. u32 val_a, u32 val_b));
  513. acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state,
  514. u32 val_a, u32 val_b);
  515. #ifdef CONFIG_X86
  516. void arch_reserve_mem_area(acpi_physical_address addr, size_t size);
  517. #else
  518. static inline void arch_reserve_mem_area(acpi_physical_address addr,
  519. size_t size)
  520. {
  521. }
  522. #endif /* CONFIG_X86 */
  523. #else
  524. #define acpi_os_set_prepare_sleep(func, pm1a_ctrl, pm1b_ctrl) do { } while (0)
  525. #endif
  526. #if defined(CONFIG_ACPI) && defined(CONFIG_PM)
  527. int acpi_dev_runtime_suspend(struct device *dev);
  528. int acpi_dev_runtime_resume(struct device *dev);
  529. int acpi_subsys_runtime_suspend(struct device *dev);
  530. int acpi_subsys_runtime_resume(struct device *dev);
  531. struct acpi_device *acpi_dev_pm_get_node(struct device *dev);
  532. int acpi_dev_pm_attach(struct device *dev, bool power_on);
  533. #else
  534. static inline int acpi_dev_runtime_suspend(struct device *dev) { return 0; }
  535. static inline int acpi_dev_runtime_resume(struct device *dev) { return 0; }
  536. static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; }
  537. static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; }
  538. static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
  539. {
  540. return NULL;
  541. }
  542. static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
  543. {
  544. return -ENODEV;
  545. }
  546. #endif
  547. #if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP)
  548. int acpi_dev_suspend_late(struct device *dev);
  549. int acpi_dev_resume_early(struct device *dev);
  550. int acpi_subsys_prepare(struct device *dev);
  551. void acpi_subsys_complete(struct device *dev);
  552. int acpi_subsys_suspend_late(struct device *dev);
  553. int acpi_subsys_resume_early(struct device *dev);
  554. int acpi_subsys_suspend(struct device *dev);
  555. int acpi_subsys_freeze(struct device *dev);
  556. #else
  557. static inline int acpi_dev_suspend_late(struct device *dev) { return 0; }
  558. static inline int acpi_dev_resume_early(struct device *dev) { return 0; }
  559. static inline int acpi_subsys_prepare(struct device *dev) { return 0; }
  560. static inline void acpi_subsys_complete(struct device *dev) {}
  561. static inline int acpi_subsys_suspend_late(struct device *dev) { return 0; }
  562. static inline int acpi_subsys_resume_early(struct device *dev) { return 0; }
  563. static inline int acpi_subsys_suspend(struct device *dev) { return 0; }
  564. static inline int acpi_subsys_freeze(struct device *dev) { return 0; }
  565. #endif
  566. #ifdef CONFIG_ACPI
  567. __printf(3, 4)
  568. void acpi_handle_printk(const char *level, acpi_handle handle,
  569. const char *fmt, ...);
  570. #else /* !CONFIG_ACPI */
  571. static inline __printf(3, 4) void
  572. acpi_handle_printk(const char *level, void *handle, const char *fmt, ...) {}
  573. #endif /* !CONFIG_ACPI */
  574. #if defined(CONFIG_ACPI) && defined(CONFIG_DYNAMIC_DEBUG)
  575. __printf(3, 4)
  576. void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const char *fmt, ...);
  577. #else
  578. #define __acpi_handle_debug(descriptor, handle, fmt, ...) \
  579. acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__);
  580. #endif
  581. /*
  582. * acpi_handle_<level>: Print message with ACPI prefix and object path
  583. *
  584. * These interfaces acquire the global namespace mutex to obtain an object
  585. * path. In interrupt context, it shows the object path as <n/a>.
  586. */
  587. #define acpi_handle_emerg(handle, fmt, ...) \
  588. acpi_handle_printk(KERN_EMERG, handle, fmt, ##__VA_ARGS__)
  589. #define acpi_handle_alert(handle, fmt, ...) \
  590. acpi_handle_printk(KERN_ALERT, handle, fmt, ##__VA_ARGS__)
  591. #define acpi_handle_crit(handle, fmt, ...) \
  592. acpi_handle_printk(KERN_CRIT, handle, fmt, ##__VA_ARGS__)
  593. #define acpi_handle_err(handle, fmt, ...) \
  594. acpi_handle_printk(KERN_ERR, handle, fmt, ##__VA_ARGS__)
  595. #define acpi_handle_warn(handle, fmt, ...) \
  596. acpi_handle_printk(KERN_WARNING, handle, fmt, ##__VA_ARGS__)
  597. #define acpi_handle_notice(handle, fmt, ...) \
  598. acpi_handle_printk(KERN_NOTICE, handle, fmt, ##__VA_ARGS__)
  599. #define acpi_handle_info(handle, fmt, ...) \
  600. acpi_handle_printk(KERN_INFO, handle, fmt, ##__VA_ARGS__)
  601. #if defined(DEBUG)
  602. #define acpi_handle_debug(handle, fmt, ...) \
  603. acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__)
  604. #else
  605. #if defined(CONFIG_DYNAMIC_DEBUG)
  606. #define acpi_handle_debug(handle, fmt, ...) \
  607. do { \
  608. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
  609. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  610. __acpi_handle_debug(&descriptor, handle, pr_fmt(fmt), \
  611. ##__VA_ARGS__); \
  612. } while (0)
  613. #else
  614. #define acpi_handle_debug(handle, fmt, ...) \
  615. ({ \
  616. if (0) \
  617. acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__); \
  618. 0; \
  619. })
  620. #endif
  621. #endif
  622. struct acpi_gpio_params {
  623. unsigned int crs_entry_index;
  624. unsigned int line_index;
  625. bool active_low;
  626. };
  627. struct acpi_gpio_mapping {
  628. const char *name;
  629. const struct acpi_gpio_params *data;
  630. unsigned int size;
  631. };
  632. #if defined(CONFIG_ACPI) && defined(CONFIG_GPIOLIB)
  633. int acpi_dev_add_driver_gpios(struct acpi_device *adev,
  634. const struct acpi_gpio_mapping *gpios);
  635. static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev)
  636. {
  637. if (adev)
  638. adev->driver_gpios = NULL;
  639. }
  640. int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index);
  641. #else
  642. static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
  643. const struct acpi_gpio_mapping *gpios)
  644. {
  645. return -ENXIO;
  646. }
  647. static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
  648. static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
  649. {
  650. return -ENXIO;
  651. }
  652. #endif
  653. /* Device properties */
  654. #define MAX_ACPI_REFERENCE_ARGS 8
  655. struct acpi_reference_args {
  656. struct acpi_device *adev;
  657. size_t nargs;
  658. u64 args[MAX_ACPI_REFERENCE_ARGS];
  659. };
  660. #ifdef CONFIG_ACPI
  661. int acpi_dev_get_property(struct acpi_device *adev, const char *name,
  662. acpi_object_type type, const union acpi_object **obj);
  663. int acpi_node_get_property_reference(struct fwnode_handle *fwnode,
  664. const char *name, size_t index,
  665. struct acpi_reference_args *args);
  666. int acpi_node_prop_get(struct fwnode_handle *fwnode, const char *propname,
  667. void **valptr);
  668. int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname,
  669. enum dev_prop_type proptype, void *val);
  670. int acpi_node_prop_read(struct fwnode_handle *fwnode, const char *propname,
  671. enum dev_prop_type proptype, void *val, size_t nval);
  672. int acpi_dev_prop_read(struct acpi_device *adev, const char *propname,
  673. enum dev_prop_type proptype, void *val, size_t nval);
  674. struct fwnode_handle *acpi_get_next_subnode(struct device *dev,
  675. struct fwnode_handle *subnode);
  676. struct acpi_probe_entry;
  677. typedef bool (*acpi_probe_entry_validate_subtbl)(struct acpi_subtable_header *,
  678. struct acpi_probe_entry *);
  679. #define ACPI_TABLE_ID_LEN 5
  680. /**
  681. * struct acpi_probe_entry - boot-time probing entry
  682. * @id: ACPI table name
  683. * @type: Optional subtable type to match
  684. * (if @id contains subtables)
  685. * @subtable_valid: Optional callback to check the validity of
  686. * the subtable
  687. * @probe_table: Callback to the driver being probed when table
  688. * match is successful
  689. * @probe_subtbl: Callback to the driver being probed when table and
  690. * subtable match (and optional callback is successful)
  691. * @driver_data: Sideband data provided back to the driver
  692. */
  693. struct acpi_probe_entry {
  694. __u8 id[ACPI_TABLE_ID_LEN];
  695. __u8 type;
  696. acpi_probe_entry_validate_subtbl subtable_valid;
  697. union {
  698. acpi_tbl_table_handler probe_table;
  699. acpi_tbl_entry_handler probe_subtbl;
  700. };
  701. kernel_ulong_t driver_data;
  702. };
  703. #define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, subtable, valid, data, fn) \
  704. static const struct acpi_probe_entry __acpi_probe_##name \
  705. __used __section(__##table##_acpi_probe_table) \
  706. = { \
  707. .id = table_id, \
  708. .type = subtable, \
  709. .subtable_valid = valid, \
  710. .probe_table = (acpi_tbl_table_handler)fn, \
  711. .driver_data = data, \
  712. }
  713. #define ACPI_PROBE_TABLE(name) __##name##_acpi_probe_table
  714. #define ACPI_PROBE_TABLE_END(name) __##name##_acpi_probe_table_end
  715. int __acpi_probe_device_table(struct acpi_probe_entry *start, int nr);
  716. #define acpi_probe_device_table(t) \
  717. ({ \
  718. extern struct acpi_probe_entry ACPI_PROBE_TABLE(t), \
  719. ACPI_PROBE_TABLE_END(t); \
  720. __acpi_probe_device_table(&ACPI_PROBE_TABLE(t), \
  721. (&ACPI_PROBE_TABLE_END(t) - \
  722. &ACPI_PROBE_TABLE(t))); \
  723. })
  724. #else
  725. static inline int acpi_dev_get_property(struct acpi_device *adev,
  726. const char *name, acpi_object_type type,
  727. const union acpi_object **obj)
  728. {
  729. return -ENXIO;
  730. }
  731. static inline int acpi_node_get_property_reference(struct fwnode_handle *fwnode,
  732. const char *name, size_t index,
  733. struct acpi_reference_args *args)
  734. {
  735. return -ENXIO;
  736. }
  737. static inline int acpi_node_prop_get(struct fwnode_handle *fwnode,
  738. const char *propname,
  739. void **valptr)
  740. {
  741. return -ENXIO;
  742. }
  743. static inline int acpi_dev_prop_get(struct acpi_device *adev,
  744. const char *propname,
  745. void **valptr)
  746. {
  747. return -ENXIO;
  748. }
  749. static inline int acpi_dev_prop_read_single(struct acpi_device *adev,
  750. const char *propname,
  751. enum dev_prop_type proptype,
  752. void *val)
  753. {
  754. return -ENXIO;
  755. }
  756. static inline int acpi_node_prop_read(struct fwnode_handle *fwnode,
  757. const char *propname,
  758. enum dev_prop_type proptype,
  759. void *val, size_t nval)
  760. {
  761. return -ENXIO;
  762. }
  763. static inline int acpi_dev_prop_read(struct acpi_device *adev,
  764. const char *propname,
  765. enum dev_prop_type proptype,
  766. void *val, size_t nval)
  767. {
  768. return -ENXIO;
  769. }
  770. static inline struct fwnode_handle *acpi_get_next_subnode(struct device *dev,
  771. struct fwnode_handle *subnode)
  772. {
  773. return NULL;
  774. }
  775. #define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, subtable, valid, data, fn) \
  776. static const void * __acpi_table_##name[] \
  777. __attribute__((unused)) \
  778. = { (void *) table_id, \
  779. (void *) subtable, \
  780. (void *) valid, \
  781. (void *) fn, \
  782. (void *) data }
  783. #define acpi_probe_device_table(t) ({ int __r = 0; __r;})
  784. #endif
  785. #endif /*_LINUX_ACPI_H*/