acpi.h 32 KB

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