acpi_bus.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * acpi_bus.h - ACPI Bus Driver ($Revision: 22 $)
  4. *
  5. * Copyright (C) 2001, 2002 Andy Grover <[email protected]>
  6. * Copyright (C) 2001, 2002 Paul Diefenbaugh <[email protected]>
  7. */
  8. #ifndef __ACPI_BUS_H__
  9. #define __ACPI_BUS_H__
  10. #include <linux/device.h>
  11. #include <linux/property.h>
  12. /* TBD: Make dynamic */
  13. #define ACPI_MAX_HANDLES 10
  14. struct acpi_handle_list {
  15. u32 count;
  16. acpi_handle handles[ACPI_MAX_HANDLES];
  17. };
  18. /* acpi_utils.h */
  19. acpi_status
  20. acpi_extract_package(union acpi_object *package,
  21. struct acpi_buffer *format, struct acpi_buffer *buffer);
  22. acpi_status
  23. acpi_evaluate_integer(acpi_handle handle,
  24. acpi_string pathname,
  25. struct acpi_object_list *arguments, unsigned long long *data);
  26. acpi_status
  27. acpi_evaluate_reference(acpi_handle handle,
  28. acpi_string pathname,
  29. struct acpi_object_list *arguments,
  30. struct acpi_handle_list *list);
  31. acpi_status
  32. acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
  33. struct acpi_buffer *status_buf);
  34. acpi_status
  35. acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
  36. bool acpi_has_method(acpi_handle handle, char *name);
  37. acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
  38. u64 arg);
  39. acpi_status acpi_evaluate_ej0(acpi_handle handle);
  40. acpi_status acpi_evaluate_lck(acpi_handle handle, int lock);
  41. acpi_status acpi_evaluate_reg(acpi_handle handle, u8 space_id, u32 function);
  42. bool acpi_ata_match(acpi_handle handle);
  43. bool acpi_bay_match(acpi_handle handle);
  44. bool acpi_dock_match(acpi_handle handle);
  45. bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs);
  46. union acpi_object *acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid,
  47. u64 rev, u64 func, union acpi_object *argv4);
  48. static inline union acpi_object *
  49. acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev,
  50. u64 func, union acpi_object *argv4,
  51. acpi_object_type type)
  52. {
  53. union acpi_object *obj;
  54. obj = acpi_evaluate_dsm(handle, guid, rev, func, argv4);
  55. if (obj && obj->type != type) {
  56. ACPI_FREE(obj);
  57. obj = NULL;
  58. }
  59. return obj;
  60. }
  61. #define ACPI_INIT_DSM_ARGV4(cnt, eles) \
  62. { \
  63. .package.type = ACPI_TYPE_PACKAGE, \
  64. .package.count = (cnt), \
  65. .package.elements = (eles) \
  66. }
  67. bool acpi_dev_found(const char *hid);
  68. bool acpi_dev_present(const char *hid, const char *uid, s64 hrv);
  69. bool acpi_reduced_hardware(void);
  70. #ifdef CONFIG_ACPI
  71. struct proc_dir_entry;
  72. #define ACPI_BUS_FILE_ROOT "acpi"
  73. extern struct proc_dir_entry *acpi_root_dir;
  74. enum acpi_bus_device_type {
  75. ACPI_BUS_TYPE_DEVICE = 0,
  76. ACPI_BUS_TYPE_POWER,
  77. ACPI_BUS_TYPE_PROCESSOR,
  78. ACPI_BUS_TYPE_THERMAL,
  79. ACPI_BUS_TYPE_POWER_BUTTON,
  80. ACPI_BUS_TYPE_SLEEP_BUTTON,
  81. ACPI_BUS_TYPE_ECDT_EC,
  82. ACPI_BUS_DEVICE_TYPE_COUNT
  83. };
  84. struct acpi_driver;
  85. struct acpi_device;
  86. /*
  87. * ACPI Scan Handler
  88. * -----------------
  89. */
  90. struct acpi_hotplug_profile {
  91. struct kobject kobj;
  92. int (*scan_dependent)(struct acpi_device *adev);
  93. void (*notify_online)(struct acpi_device *adev);
  94. bool enabled:1;
  95. bool demand_offline:1;
  96. };
  97. static inline struct acpi_hotplug_profile *to_acpi_hotplug_profile(
  98. struct kobject *kobj)
  99. {
  100. return container_of(kobj, struct acpi_hotplug_profile, kobj);
  101. }
  102. struct acpi_scan_handler {
  103. const struct acpi_device_id *ids;
  104. struct list_head list_node;
  105. bool (*match)(const char *idstr, const struct acpi_device_id **matchid);
  106. int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id);
  107. void (*detach)(struct acpi_device *dev);
  108. void (*bind)(struct device *phys_dev);
  109. void (*unbind)(struct device *phys_dev);
  110. struct acpi_hotplug_profile hotplug;
  111. };
  112. /*
  113. * ACPI Hotplug Context
  114. * --------------------
  115. */
  116. struct acpi_hotplug_context {
  117. struct acpi_device *self;
  118. int (*notify)(struct acpi_device *, u32);
  119. void (*uevent)(struct acpi_device *, u32);
  120. void (*fixup)(struct acpi_device *);
  121. };
  122. /*
  123. * ACPI Driver
  124. * -----------
  125. */
  126. typedef int (*acpi_op_add) (struct acpi_device * device);
  127. typedef int (*acpi_op_remove) (struct acpi_device * device);
  128. typedef void (*acpi_op_notify) (struct acpi_device * device, u32 event);
  129. struct acpi_device_ops {
  130. acpi_op_add add;
  131. acpi_op_remove remove;
  132. acpi_op_notify notify;
  133. };
  134. #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
  135. struct acpi_driver {
  136. char name[80];
  137. char class[80];
  138. const struct acpi_device_id *ids; /* Supported Hardware IDs */
  139. unsigned int flags;
  140. struct acpi_device_ops ops;
  141. struct device_driver drv;
  142. struct module *owner;
  143. };
  144. /*
  145. * ACPI Device
  146. * -----------
  147. */
  148. /* Status (_STA) */
  149. struct acpi_device_status {
  150. u32 present:1;
  151. u32 enabled:1;
  152. u32 show_in_ui:1;
  153. u32 functional:1;
  154. u32 battery_present:1;
  155. u32 reserved:27;
  156. };
  157. /* Flags */
  158. struct acpi_device_flags {
  159. u32 dynamic_status:1;
  160. u32 removable:1;
  161. u32 ejectable:1;
  162. u32 power_manageable:1;
  163. u32 match_driver:1;
  164. u32 initialized:1;
  165. u32 visited:1;
  166. u32 hotplug_notify:1;
  167. u32 is_dock_station:1;
  168. u32 of_compatible_ok:1;
  169. u32 coherent_dma:1;
  170. u32 cca_seen:1;
  171. u32 enumeration_by_parent:1;
  172. u32 honor_deps:1;
  173. u32 reserved:18;
  174. };
  175. /* File System */
  176. struct acpi_device_dir {
  177. struct proc_dir_entry *entry;
  178. };
  179. #define acpi_device_dir(d) ((d)->dir.entry)
  180. /* Plug and Play */
  181. typedef char acpi_bus_id[8];
  182. typedef u64 acpi_bus_address;
  183. typedef char acpi_device_name[40];
  184. typedef char acpi_device_class[20];
  185. struct acpi_hardware_id {
  186. struct list_head list;
  187. const char *id;
  188. };
  189. struct acpi_pnp_type {
  190. u32 hardware_id:1;
  191. u32 bus_address:1;
  192. u32 platform_id:1;
  193. u32 backlight:1;
  194. u32 reserved:28;
  195. };
  196. struct acpi_device_pnp {
  197. acpi_bus_id bus_id; /* Object name */
  198. int instance_no; /* Instance number of this object */
  199. struct acpi_pnp_type type; /* ID type */
  200. acpi_bus_address bus_address; /* _ADR */
  201. char *unique_id; /* _UID */
  202. struct list_head ids; /* _HID and _CIDs */
  203. acpi_device_name device_name; /* Driver-determined */
  204. acpi_device_class device_class; /* " */
  205. union acpi_object *str_obj; /* unicode string for _STR method */
  206. };
  207. #define acpi_device_bid(d) ((d)->pnp.bus_id)
  208. #define acpi_device_adr(d) ((d)->pnp.bus_address)
  209. const char *acpi_device_hid(struct acpi_device *device);
  210. #define acpi_device_uid(d) ((d)->pnp.unique_id)
  211. #define acpi_device_name(d) ((d)->pnp.device_name)
  212. #define acpi_device_class(d) ((d)->pnp.device_class)
  213. /* Power Management */
  214. struct acpi_device_power_flags {
  215. u32 explicit_get:1; /* _PSC present? */
  216. u32 power_resources:1; /* Power resources */
  217. u32 inrush_current:1; /* Serialize Dx->D0 */
  218. u32 power_removed:1; /* Optimize Dx->D0 */
  219. u32 ignore_parent:1; /* Power is independent of parent power state */
  220. u32 dsw_present:1; /* _DSW present? */
  221. u32 reserved:26;
  222. };
  223. struct acpi_device_power_state {
  224. struct {
  225. u8 valid:1;
  226. u8 explicit_set:1; /* _PSx present? */
  227. u8 reserved:6;
  228. } flags;
  229. int power; /* % Power (compared to D0) */
  230. int latency; /* Dx->D0 time (microseconds) */
  231. struct list_head resources; /* Power resources referenced */
  232. };
  233. struct acpi_device_power {
  234. int state; /* Current state */
  235. struct acpi_device_power_flags flags;
  236. struct acpi_device_power_state states[ACPI_D_STATE_COUNT]; /* Power states (D0-D3Cold) */
  237. u8 state_for_enumeration; /* Deepest power state for enumeration */
  238. };
  239. struct acpi_dep_data {
  240. struct list_head node;
  241. acpi_handle supplier;
  242. acpi_handle consumer;
  243. bool honor_dep;
  244. };
  245. /* Performance Management */
  246. struct acpi_device_perf_flags {
  247. u8 reserved:8;
  248. };
  249. struct acpi_device_perf_state {
  250. struct {
  251. u8 valid:1;
  252. u8 reserved:7;
  253. } flags;
  254. u8 power; /* % Power (compared to P0) */
  255. u8 performance; /* % Performance ( " ) */
  256. int latency; /* Px->P0 time (microseconds) */
  257. };
  258. struct acpi_device_perf {
  259. int state;
  260. struct acpi_device_perf_flags flags;
  261. int state_count;
  262. struct acpi_device_perf_state *states;
  263. };
  264. /* Wakeup Management */
  265. struct acpi_device_wakeup_flags {
  266. u8 valid:1; /* Can successfully enable wakeup? */
  267. u8 notifier_present:1; /* Wake-up notify handler has been installed */
  268. };
  269. struct acpi_device_wakeup_context {
  270. void (*func)(struct acpi_device_wakeup_context *context);
  271. struct device *dev;
  272. };
  273. struct acpi_device_wakeup {
  274. acpi_handle gpe_device;
  275. u64 gpe_number;
  276. u64 sleep_state;
  277. struct list_head resources;
  278. struct acpi_device_wakeup_flags flags;
  279. struct acpi_device_wakeup_context context;
  280. struct wakeup_source *ws;
  281. int prepare_count;
  282. int enable_count;
  283. };
  284. struct acpi_device_physical_node {
  285. unsigned int node_id;
  286. struct list_head node;
  287. struct device *dev;
  288. bool put_online:1;
  289. };
  290. struct acpi_device_properties {
  291. const guid_t *guid;
  292. union acpi_object *properties;
  293. struct list_head list;
  294. void **bufs;
  295. };
  296. /* ACPI Device Specific Data (_DSD) */
  297. struct acpi_device_data {
  298. const union acpi_object *pointer;
  299. struct list_head properties;
  300. const union acpi_object *of_compatible;
  301. struct list_head subnodes;
  302. };
  303. struct acpi_gpio_mapping;
  304. /* Device */
  305. struct acpi_device {
  306. u32 pld_crc;
  307. int device_type;
  308. acpi_handle handle; /* no handle for fixed hardware */
  309. struct fwnode_handle fwnode;
  310. struct list_head wakeup_list;
  311. struct list_head del_list;
  312. struct acpi_device_status status;
  313. struct acpi_device_flags flags;
  314. struct acpi_device_pnp pnp;
  315. struct acpi_device_power power;
  316. struct acpi_device_wakeup wakeup;
  317. struct acpi_device_perf performance;
  318. struct acpi_device_dir dir;
  319. struct acpi_device_data data;
  320. struct acpi_scan_handler *handler;
  321. struct acpi_hotplug_context *hp;
  322. const struct acpi_gpio_mapping *driver_gpios;
  323. void *driver_data;
  324. struct device dev;
  325. unsigned int physical_node_count;
  326. unsigned int dep_unmet;
  327. struct list_head physical_node_list;
  328. struct mutex physical_node_lock;
  329. void (*remove)(struct acpi_device *);
  330. };
  331. /* Non-device subnode */
  332. struct acpi_data_node {
  333. const char *name;
  334. acpi_handle handle;
  335. struct fwnode_handle fwnode;
  336. struct fwnode_handle *parent;
  337. struct acpi_device_data data;
  338. struct list_head sibling;
  339. struct kobject kobj;
  340. struct completion kobj_done;
  341. };
  342. extern const struct fwnode_operations acpi_device_fwnode_ops;
  343. extern const struct fwnode_operations acpi_data_fwnode_ops;
  344. extern const struct fwnode_operations acpi_static_fwnode_ops;
  345. bool is_acpi_device_node(const struct fwnode_handle *fwnode);
  346. bool is_acpi_data_node(const struct fwnode_handle *fwnode);
  347. static inline bool is_acpi_node(const struct fwnode_handle *fwnode)
  348. {
  349. return (is_acpi_device_node(fwnode) || is_acpi_data_node(fwnode));
  350. }
  351. #define to_acpi_device_node(__fwnode) \
  352. ({ \
  353. typeof(__fwnode) __to_acpi_device_node_fwnode = __fwnode; \
  354. \
  355. is_acpi_device_node(__to_acpi_device_node_fwnode) ? \
  356. container_of(__to_acpi_device_node_fwnode, \
  357. struct acpi_device, fwnode) : \
  358. NULL; \
  359. })
  360. #define to_acpi_data_node(__fwnode) \
  361. ({ \
  362. typeof(__fwnode) __to_acpi_data_node_fwnode = __fwnode; \
  363. \
  364. is_acpi_data_node(__to_acpi_data_node_fwnode) ? \
  365. container_of(__to_acpi_data_node_fwnode, \
  366. struct acpi_data_node, fwnode) : \
  367. NULL; \
  368. })
  369. static inline bool is_acpi_static_node(const struct fwnode_handle *fwnode)
  370. {
  371. return !IS_ERR_OR_NULL(fwnode) &&
  372. fwnode->ops == &acpi_static_fwnode_ops;
  373. }
  374. static inline bool acpi_data_node_match(const struct fwnode_handle *fwnode,
  375. const char *name)
  376. {
  377. return is_acpi_data_node(fwnode) ?
  378. (!strcmp(to_acpi_data_node(fwnode)->name, name)) : false;
  379. }
  380. static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev)
  381. {
  382. return &adev->fwnode;
  383. }
  384. static inline void *acpi_driver_data(struct acpi_device *d)
  385. {
  386. return d->driver_data;
  387. }
  388. #define to_acpi_device(d) container_of(d, struct acpi_device, dev)
  389. #define to_acpi_driver(d) container_of(d, struct acpi_driver, drv)
  390. static inline struct acpi_device *acpi_dev_parent(struct acpi_device *adev)
  391. {
  392. if (adev->dev.parent)
  393. return to_acpi_device(adev->dev.parent);
  394. return NULL;
  395. }
  396. static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta)
  397. {
  398. *((u32 *)&adev->status) = sta;
  399. }
  400. static inline void acpi_set_hp_context(struct acpi_device *adev,
  401. struct acpi_hotplug_context *hp)
  402. {
  403. hp->self = adev;
  404. adev->hp = hp;
  405. }
  406. void acpi_initialize_hp_context(struct acpi_device *adev,
  407. struct acpi_hotplug_context *hp,
  408. int (*notify)(struct acpi_device *, u32),
  409. void (*uevent)(struct acpi_device *, u32));
  410. /* acpi_device.dev.bus == &acpi_bus_type */
  411. extern struct bus_type acpi_bus_type;
  412. int acpi_bus_for_each_dev(int (*fn)(struct device *, void *), void *data);
  413. int acpi_dev_for_each_child(struct acpi_device *adev,
  414. int (*fn)(struct acpi_device *, void *), void *data);
  415. int acpi_dev_for_each_child_reverse(struct acpi_device *adev,
  416. int (*fn)(struct acpi_device *, void *),
  417. void *data);
  418. /*
  419. * Events
  420. * ------
  421. */
  422. struct acpi_bus_event {
  423. struct list_head node;
  424. acpi_device_class device_class;
  425. acpi_bus_id bus_id;
  426. u32 type;
  427. u32 data;
  428. };
  429. extern struct kobject *acpi_kobj;
  430. extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int);
  431. void acpi_bus_private_data_handler(acpi_handle, void *);
  432. int acpi_bus_get_private_data(acpi_handle, void **);
  433. int acpi_bus_attach_private_data(acpi_handle, void *);
  434. void acpi_bus_detach_private_data(acpi_handle);
  435. extern int acpi_notifier_call_chain(struct acpi_device *, u32, u32);
  436. extern int register_acpi_notifier(struct notifier_block *);
  437. extern int unregister_acpi_notifier(struct notifier_block *);
  438. /*
  439. * External Functions
  440. */
  441. acpi_status acpi_bus_get_status_handle(acpi_handle handle,
  442. unsigned long long *sta);
  443. int acpi_bus_get_status(struct acpi_device *device);
  444. int acpi_bus_set_power(acpi_handle handle, int state);
  445. const char *acpi_power_state_string(int state);
  446. int acpi_device_set_power(struct acpi_device *device, int state);
  447. int acpi_bus_init_power(struct acpi_device *device);
  448. int acpi_device_fix_up_power(struct acpi_device *device);
  449. void acpi_device_fix_up_power_extended(struct acpi_device *adev);
  450. int acpi_bus_update_power(acpi_handle handle, int *state_p);
  451. int acpi_device_update_power(struct acpi_device *device, int *state_p);
  452. bool acpi_bus_power_manageable(acpi_handle handle);
  453. void acpi_dev_power_up_children_with_adr(struct acpi_device *adev);
  454. u8 acpi_dev_power_state_for_wake(struct acpi_device *adev);
  455. int acpi_device_power_add_dependent(struct acpi_device *adev,
  456. struct device *dev);
  457. void acpi_device_power_remove_dependent(struct acpi_device *adev,
  458. struct device *dev);
  459. #ifdef CONFIG_PM
  460. bool acpi_bus_can_wakeup(acpi_handle handle);
  461. #else
  462. static inline bool acpi_bus_can_wakeup(acpi_handle handle) { return false; }
  463. #endif
  464. void acpi_scan_lock_acquire(void);
  465. void acpi_scan_lock_release(void);
  466. void acpi_lock_hp_context(void);
  467. void acpi_unlock_hp_context(void);
  468. int acpi_scan_add_handler(struct acpi_scan_handler *handler);
  469. int acpi_bus_register_driver(struct acpi_driver *driver);
  470. void acpi_bus_unregister_driver(struct acpi_driver *driver);
  471. int acpi_bus_scan(acpi_handle handle);
  472. void acpi_bus_trim(struct acpi_device *start);
  473. acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
  474. int acpi_match_device_ids(struct acpi_device *device,
  475. const struct acpi_device_id *ids);
  476. void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
  477. char *modalias, size_t len);
  478. int acpi_create_dir(struct acpi_device *);
  479. void acpi_remove_dir(struct acpi_device *);
  480. static inline bool acpi_device_enumerated(struct acpi_device *adev)
  481. {
  482. return adev && adev->flags.initialized && adev->flags.visited;
  483. }
  484. /**
  485. * module_acpi_driver(acpi_driver) - Helper macro for registering an ACPI driver
  486. * @__acpi_driver: acpi_driver struct
  487. *
  488. * Helper macro for ACPI drivers which do not do anything special in module
  489. * init/exit. This eliminates a lot of boilerplate. Each module may only
  490. * use this macro once, and calling it replaces module_init() and module_exit()
  491. */
  492. #define module_acpi_driver(__acpi_driver) \
  493. module_driver(__acpi_driver, acpi_bus_register_driver, \
  494. acpi_bus_unregister_driver)
  495. /*
  496. * Bind physical devices with ACPI devices
  497. */
  498. struct acpi_bus_type {
  499. struct list_head list;
  500. const char *name;
  501. bool (*match)(struct device *dev);
  502. struct acpi_device * (*find_companion)(struct device *);
  503. void (*setup)(struct device *);
  504. };
  505. int register_acpi_bus_type(struct acpi_bus_type *);
  506. int unregister_acpi_bus_type(struct acpi_bus_type *);
  507. int acpi_bind_one(struct device *dev, struct acpi_device *adev);
  508. int acpi_unbind_one(struct device *dev);
  509. enum acpi_bridge_type {
  510. ACPI_BRIDGE_TYPE_PCIE = 1,
  511. ACPI_BRIDGE_TYPE_CXL,
  512. };
  513. struct acpi_pci_root {
  514. struct acpi_device * device;
  515. struct pci_bus *bus;
  516. u16 segment;
  517. int bridge_type;
  518. struct resource secondary; /* downstream bus range */
  519. u32 osc_support_set; /* _OSC state of support bits */
  520. u32 osc_control_set; /* _OSC state of control bits */
  521. u32 osc_ext_support_set; /* _OSC state of extended support bits */
  522. u32 osc_ext_control_set; /* _OSC state of extended control bits */
  523. phys_addr_t mcfg_addr;
  524. };
  525. /* helper */
  526. bool acpi_dma_supported(const struct acpi_device *adev);
  527. enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev);
  528. int acpi_iommu_fwspec_init(struct device *dev, u32 id,
  529. struct fwnode_handle *fwnode,
  530. const struct iommu_ops *ops);
  531. int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map);
  532. int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
  533. const u32 *input_id);
  534. static inline int acpi_dma_configure(struct device *dev,
  535. enum dev_dma_attr attr)
  536. {
  537. return acpi_dma_configure_id(dev, attr, NULL);
  538. }
  539. struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
  540. u64 address, bool check_children);
  541. struct acpi_device *acpi_find_child_by_adr(struct acpi_device *adev,
  542. acpi_bus_address adr);
  543. int acpi_is_root_bridge(acpi_handle);
  544. struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle);
  545. int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state);
  546. int acpi_disable_wakeup_device_power(struct acpi_device *dev);
  547. #ifdef CONFIG_X86
  548. bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status);
  549. bool acpi_quirk_skip_acpi_ac_and_battery(void);
  550. #else
  551. static inline bool acpi_device_override_status(struct acpi_device *adev,
  552. unsigned long long *status)
  553. {
  554. return false;
  555. }
  556. static inline bool acpi_quirk_skip_acpi_ac_and_battery(void)
  557. {
  558. return false;
  559. }
  560. #endif
  561. #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
  562. bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev);
  563. int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip);
  564. #else
  565. static inline bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev)
  566. {
  567. return false;
  568. }
  569. static inline int
  570. acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
  571. {
  572. *skip = false;
  573. return 0;
  574. }
  575. #endif
  576. #ifdef CONFIG_PM
  577. void acpi_pm_wakeup_event(struct device *dev);
  578. acpi_status acpi_add_pm_notifier(struct acpi_device *adev, struct device *dev,
  579. void (*func)(struct acpi_device_wakeup_context *context));
  580. acpi_status acpi_remove_pm_notifier(struct acpi_device *adev);
  581. bool acpi_pm_device_can_wakeup(struct device *dev);
  582. int acpi_pm_device_sleep_state(struct device *, int *, int);
  583. int acpi_pm_set_device_wakeup(struct device *dev, bool enable);
  584. #else
  585. static inline void acpi_pm_wakeup_event(struct device *dev)
  586. {
  587. }
  588. static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
  589. struct device *dev,
  590. void (*func)(struct acpi_device_wakeup_context *context))
  591. {
  592. return AE_SUPPORT;
  593. }
  594. static inline acpi_status acpi_remove_pm_notifier(struct acpi_device *adev)
  595. {
  596. return AE_SUPPORT;
  597. }
  598. static inline bool acpi_pm_device_can_wakeup(struct device *dev)
  599. {
  600. return false;
  601. }
  602. static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
  603. {
  604. if (p)
  605. *p = ACPI_STATE_D0;
  606. return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3_COLD) ?
  607. m : ACPI_STATE_D0;
  608. }
  609. static inline int acpi_pm_set_device_wakeup(struct device *dev, bool enable)
  610. {
  611. return -ENODEV;
  612. }
  613. #endif
  614. #ifdef CONFIG_ACPI_SYSTEM_POWER_STATES_SUPPORT
  615. bool acpi_sleep_state_supported(u8 sleep_state);
  616. #else
  617. static inline bool acpi_sleep_state_supported(u8 sleep_state) { return false; }
  618. #endif
  619. #ifdef CONFIG_ACPI_SLEEP
  620. u32 acpi_target_system_state(void);
  621. #else
  622. static inline u32 acpi_target_system_state(void) { return ACPI_STATE_S0; }
  623. #endif
  624. static inline bool acpi_device_power_manageable(struct acpi_device *adev)
  625. {
  626. return adev->flags.power_manageable;
  627. }
  628. static inline bool acpi_device_can_wakeup(struct acpi_device *adev)
  629. {
  630. return adev->wakeup.flags.valid;
  631. }
  632. static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
  633. {
  634. return adev->power.states[ACPI_STATE_D3_COLD].flags.valid ||
  635. ((acpi_gbl_FADT.header.revision < 6) &&
  636. adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
  637. }
  638. bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
  639. int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer);
  640. void acpi_dev_clear_dependencies(struct acpi_device *supplier);
  641. bool acpi_dev_ready_for_enumeration(const struct acpi_device *device);
  642. struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier,
  643. struct acpi_device *start);
  644. /**
  645. * for_each_acpi_consumer_dev - iterate over the consumer ACPI devices for a
  646. * given supplier
  647. * @supplier: Pointer to the supplier's ACPI device
  648. * @consumer: Pointer to &struct acpi_device to hold the consumer, initially NULL
  649. */
  650. #define for_each_acpi_consumer_dev(supplier, consumer) \
  651. for (consumer = acpi_dev_get_next_consumer_dev(supplier, NULL); \
  652. consumer; \
  653. consumer = acpi_dev_get_next_consumer_dev(supplier, consumer))
  654. struct acpi_device *
  655. acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
  656. struct acpi_device *
  657. acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
  658. /**
  659. * for_each_acpi_dev_match - iterate over ACPI devices that matching the criteria
  660. * @adev: pointer to the matching ACPI device, NULL at the end of the loop
  661. * @hid: Hardware ID of the device.
  662. * @uid: Unique ID of the device, pass NULL to not check _UID
  663. * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
  664. *
  665. * The caller is responsible for invoking acpi_dev_put() on the returned device.
  666. */
  667. #define for_each_acpi_dev_match(adev, hid, uid, hrv) \
  668. for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv); \
  669. adev; \
  670. adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv))
  671. static inline struct acpi_device *acpi_dev_get(struct acpi_device *adev)
  672. {
  673. return adev ? to_acpi_device(get_device(&adev->dev)) : NULL;
  674. }
  675. static inline void acpi_dev_put(struct acpi_device *adev)
  676. {
  677. if (adev)
  678. put_device(&adev->dev);
  679. }
  680. struct acpi_device *acpi_fetch_acpi_dev(acpi_handle handle);
  681. struct acpi_device *acpi_get_acpi_dev(acpi_handle handle);
  682. static inline void acpi_put_acpi_dev(struct acpi_device *adev)
  683. {
  684. acpi_dev_put(adev);
  685. }
  686. #else /* CONFIG_ACPI */
  687. static inline int register_acpi_bus_type(void *bus) { return 0; }
  688. static inline int unregister_acpi_bus_type(void *bus) { return 0; }
  689. #endif /* CONFIG_ACPI */
  690. #endif /*__ACPI_BUS_H__*/