acpi_bus.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /*
  2. * acpi_bus.h - ACPI Bus Driver ($Revision: 22 $)
  3. *
  4. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  5. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or (at
  12. * your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. */
  25. #ifndef __ACPI_BUS_H__
  26. #define __ACPI_BUS_H__
  27. #include <linux/device.h>
  28. /* TBD: Make dynamic */
  29. #define ACPI_MAX_HANDLES 10
  30. struct acpi_handle_list {
  31. u32 count;
  32. acpi_handle handles[ACPI_MAX_HANDLES];
  33. };
  34. /* acpi_utils.h */
  35. acpi_status
  36. acpi_extract_package(union acpi_object *package,
  37. struct acpi_buffer *format, struct acpi_buffer *buffer);
  38. acpi_status
  39. acpi_evaluate_integer(acpi_handle handle,
  40. acpi_string pathname,
  41. struct acpi_object_list *arguments, unsigned long long *data);
  42. acpi_status
  43. acpi_evaluate_reference(acpi_handle handle,
  44. acpi_string pathname,
  45. struct acpi_object_list *arguments,
  46. struct acpi_handle_list *list);
  47. acpi_status
  48. acpi_evaluate_hotplug_ost(acpi_handle handle, u32 source_event,
  49. u32 status_code, struct acpi_buffer *status_buf);
  50. acpi_status
  51. acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
  52. bool acpi_has_method(acpi_handle handle, char *name);
  53. acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
  54. u64 arg);
  55. acpi_status acpi_evaluate_ej0(acpi_handle handle);
  56. acpi_status acpi_evaluate_lck(acpi_handle handle, int lock);
  57. bool acpi_ata_match(acpi_handle handle);
  58. bool acpi_bay_match(acpi_handle handle);
  59. bool acpi_dock_match(acpi_handle handle);
  60. bool acpi_check_dsm(acpi_handle handle, const u8 *uuid, int rev, u64 funcs);
  61. union acpi_object *acpi_evaluate_dsm(acpi_handle handle, const u8 *uuid,
  62. int rev, int func, union acpi_object *argv4);
  63. static inline union acpi_object *
  64. acpi_evaluate_dsm_typed(acpi_handle handle, const u8 *uuid, int rev, int func,
  65. union acpi_object *argv4, acpi_object_type type)
  66. {
  67. union acpi_object *obj;
  68. obj = acpi_evaluate_dsm(handle, uuid, rev, func, argv4);
  69. if (obj && obj->type != type) {
  70. ACPI_FREE(obj);
  71. obj = NULL;
  72. }
  73. return obj;
  74. }
  75. #define ACPI_INIT_DSM_ARGV4(cnt, eles) \
  76. { \
  77. .package.type = ACPI_TYPE_PACKAGE, \
  78. .package.count = (cnt), \
  79. .package.elements = (eles) \
  80. }
  81. #ifdef CONFIG_ACPI
  82. #include <linux/proc_fs.h>
  83. #define ACPI_BUS_FILE_ROOT "acpi"
  84. extern struct proc_dir_entry *acpi_root_dir;
  85. enum acpi_bus_device_type {
  86. ACPI_BUS_TYPE_DEVICE = 0,
  87. ACPI_BUS_TYPE_POWER,
  88. ACPI_BUS_TYPE_PROCESSOR,
  89. ACPI_BUS_TYPE_THERMAL,
  90. ACPI_BUS_TYPE_POWER_BUTTON,
  91. ACPI_BUS_TYPE_SLEEP_BUTTON,
  92. ACPI_BUS_DEVICE_TYPE_COUNT
  93. };
  94. struct acpi_driver;
  95. struct acpi_device;
  96. /*
  97. * ACPI Scan Handler
  98. * -----------------
  99. */
  100. struct acpi_hotplug_profile {
  101. struct kobject kobj;
  102. int (*scan_dependent)(struct acpi_device *adev);
  103. bool enabled:1;
  104. bool demand_offline:1;
  105. };
  106. static inline struct acpi_hotplug_profile *to_acpi_hotplug_profile(
  107. struct kobject *kobj)
  108. {
  109. return container_of(kobj, struct acpi_hotplug_profile, kobj);
  110. }
  111. struct acpi_scan_handler {
  112. const struct acpi_device_id *ids;
  113. struct list_head list_node;
  114. int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id);
  115. void (*detach)(struct acpi_device *dev);
  116. struct acpi_hotplug_profile hotplug;
  117. };
  118. /*
  119. * ACPI Driver
  120. * -----------
  121. */
  122. typedef int (*acpi_op_add) (struct acpi_device * device);
  123. typedef int (*acpi_op_remove) (struct acpi_device * device);
  124. typedef void (*acpi_op_notify) (struct acpi_device * device, u32 event);
  125. struct acpi_device_ops {
  126. acpi_op_add add;
  127. acpi_op_remove remove;
  128. acpi_op_notify notify;
  129. };
  130. #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
  131. struct acpi_driver {
  132. char name[80];
  133. char class[80];
  134. const struct acpi_device_id *ids; /* Supported Hardware IDs */
  135. unsigned int flags;
  136. struct acpi_device_ops ops;
  137. struct device_driver drv;
  138. struct module *owner;
  139. };
  140. /*
  141. * ACPI Device
  142. * -----------
  143. */
  144. /* Status (_STA) */
  145. struct acpi_device_status {
  146. u32 present:1;
  147. u32 enabled:1;
  148. u32 show_in_ui:1;
  149. u32 functional:1;
  150. u32 battery_present:1;
  151. u32 reserved:27;
  152. };
  153. /* Flags */
  154. struct acpi_device_flags {
  155. u32 dynamic_status:1;
  156. u32 removable:1;
  157. u32 ejectable:1;
  158. u32 power_manageable:1;
  159. u32 match_driver:1;
  160. u32 initialized:1;
  161. u32 visited:1;
  162. u32 no_hotplug:1;
  163. u32 reserved:24;
  164. };
  165. /* File System */
  166. struct acpi_device_dir {
  167. struct proc_dir_entry *entry;
  168. };
  169. #define acpi_device_dir(d) ((d)->dir.entry)
  170. /* Plug and Play */
  171. typedef char acpi_bus_id[8];
  172. typedef unsigned long acpi_bus_address;
  173. typedef char acpi_device_name[40];
  174. typedef char acpi_device_class[20];
  175. struct acpi_hardware_id {
  176. struct list_head list;
  177. char *id;
  178. };
  179. struct acpi_pnp_type {
  180. u32 hardware_id:1;
  181. u32 bus_address:1;
  182. u32 reserved:30;
  183. };
  184. struct acpi_device_pnp {
  185. acpi_bus_id bus_id; /* Object name */
  186. struct acpi_pnp_type type; /* ID type */
  187. acpi_bus_address bus_address; /* _ADR */
  188. char *unique_id; /* _UID */
  189. struct list_head ids; /* _HID and _CIDs */
  190. acpi_device_name device_name; /* Driver-determined */
  191. acpi_device_class device_class; /* " */
  192. union acpi_object *str_obj; /* unicode string for _STR method */
  193. unsigned long sun; /* _SUN */
  194. };
  195. #define acpi_device_bid(d) ((d)->pnp.bus_id)
  196. #define acpi_device_adr(d) ((d)->pnp.bus_address)
  197. const char *acpi_device_hid(struct acpi_device *device);
  198. #define acpi_device_name(d) ((d)->pnp.device_name)
  199. #define acpi_device_class(d) ((d)->pnp.device_class)
  200. /* Power Management */
  201. struct acpi_device_power_flags {
  202. u32 explicit_get:1; /* _PSC present? */
  203. u32 power_resources:1; /* Power resources */
  204. u32 inrush_current:1; /* Serialize Dx->D0 */
  205. u32 power_removed:1; /* Optimize Dx->D0 */
  206. u32 ignore_parent:1; /* Power is independent of parent power state */
  207. u32 reserved:27;
  208. };
  209. struct acpi_device_power_state {
  210. struct {
  211. u8 valid:1;
  212. u8 os_accessible:1;
  213. u8 explicit_set:1; /* _PSx present? */
  214. u8 reserved:6;
  215. } flags;
  216. int power; /* % Power (compared to D0) */
  217. int latency; /* Dx->D0 time (microseconds) */
  218. struct list_head resources; /* Power resources referenced */
  219. };
  220. struct acpi_device_power {
  221. int state; /* Current state */
  222. struct acpi_device_power_flags flags;
  223. struct acpi_device_power_state states[ACPI_D_STATE_COUNT]; /* Power states (D0-D3Cold) */
  224. };
  225. /* Performance Management */
  226. struct acpi_device_perf_flags {
  227. u8 reserved:8;
  228. };
  229. struct acpi_device_perf_state {
  230. struct {
  231. u8 valid:1;
  232. u8 reserved:7;
  233. } flags;
  234. u8 power; /* % Power (compared to P0) */
  235. u8 performance; /* % Performance ( " ) */
  236. int latency; /* Px->P0 time (microseconds) */
  237. };
  238. struct acpi_device_perf {
  239. int state;
  240. struct acpi_device_perf_flags flags;
  241. int state_count;
  242. struct acpi_device_perf_state *states;
  243. };
  244. /* Wakeup Management */
  245. struct acpi_device_wakeup_flags {
  246. u8 valid:1; /* Can successfully enable wakeup? */
  247. u8 run_wake:1; /* Run-Wake GPE devices */
  248. u8 notifier_present:1; /* Wake-up notify handler has been installed */
  249. };
  250. struct acpi_device_wakeup {
  251. acpi_handle gpe_device;
  252. u64 gpe_number;
  253. u64 sleep_state;
  254. struct list_head resources;
  255. struct acpi_device_wakeup_flags flags;
  256. int prepare_count;
  257. };
  258. struct acpi_device_physical_node {
  259. unsigned int node_id;
  260. struct list_head node;
  261. struct device *dev;
  262. bool put_online:1;
  263. };
  264. /* Device */
  265. struct acpi_device {
  266. int device_type;
  267. acpi_handle handle; /* no handle for fixed hardware */
  268. struct acpi_device *parent;
  269. struct list_head children;
  270. struct list_head node;
  271. struct list_head wakeup_list;
  272. struct list_head del_list;
  273. struct acpi_device_status status;
  274. struct acpi_device_flags flags;
  275. struct acpi_device_pnp pnp;
  276. struct acpi_device_power power;
  277. struct acpi_device_wakeup wakeup;
  278. struct acpi_device_perf performance;
  279. struct acpi_device_dir dir;
  280. struct acpi_scan_handler *handler;
  281. struct acpi_driver *driver;
  282. void *driver_data;
  283. struct device dev;
  284. unsigned int physical_node_count;
  285. struct list_head physical_node_list;
  286. struct mutex physical_node_lock;
  287. void (*remove)(struct acpi_device *);
  288. };
  289. static inline void *acpi_driver_data(struct acpi_device *d)
  290. {
  291. return d->driver_data;
  292. }
  293. #define to_acpi_device(d) container_of(d, struct acpi_device, dev)
  294. #define to_acpi_driver(d) container_of(d, struct acpi_driver, drv)
  295. static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta)
  296. {
  297. *((u32 *)&adev->status) = sta;
  298. }
  299. /* acpi_device.dev.bus == &acpi_bus_type */
  300. extern struct bus_type acpi_bus_type;
  301. /*
  302. * Events
  303. * ------
  304. */
  305. struct acpi_bus_event {
  306. struct list_head node;
  307. acpi_device_class device_class;
  308. acpi_bus_id bus_id;
  309. u32 type;
  310. u32 data;
  311. };
  312. extern struct kobject *acpi_kobj;
  313. extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int);
  314. void acpi_bus_private_data_handler(acpi_handle, void *);
  315. int acpi_bus_get_private_data(acpi_handle, void **);
  316. void acpi_bus_no_hotplug(acpi_handle handle);
  317. extern int acpi_notifier_call_chain(struct acpi_device *, u32, u32);
  318. extern int register_acpi_notifier(struct notifier_block *);
  319. extern int unregister_acpi_notifier(struct notifier_block *);
  320. /*
  321. * External Functions
  322. */
  323. int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device);
  324. acpi_status acpi_bus_get_status_handle(acpi_handle handle,
  325. unsigned long long *sta);
  326. int acpi_bus_get_status(struct acpi_device *device);
  327. int acpi_bus_set_power(acpi_handle handle, int state);
  328. const char *acpi_power_state_string(int state);
  329. int acpi_device_get_power(struct acpi_device *device, int *state);
  330. int acpi_device_set_power(struct acpi_device *device, int state);
  331. int acpi_bus_init_power(struct acpi_device *device);
  332. int acpi_device_fix_up_power(struct acpi_device *device);
  333. int acpi_bus_update_power(acpi_handle handle, int *state_p);
  334. bool acpi_bus_power_manageable(acpi_handle handle);
  335. #ifdef CONFIG_PM
  336. bool acpi_bus_can_wakeup(acpi_handle handle);
  337. #else
  338. static inline bool acpi_bus_can_wakeup(acpi_handle handle) { return false; }
  339. #endif
  340. void acpi_scan_lock_acquire(void);
  341. void acpi_scan_lock_release(void);
  342. int acpi_scan_add_handler(struct acpi_scan_handler *handler);
  343. int acpi_bus_register_driver(struct acpi_driver *driver);
  344. void acpi_bus_unregister_driver(struct acpi_driver *driver);
  345. int acpi_bus_scan(acpi_handle handle);
  346. void acpi_bus_trim(struct acpi_device *start);
  347. acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
  348. int acpi_match_device_ids(struct acpi_device *device,
  349. const struct acpi_device_id *ids);
  350. int acpi_create_dir(struct acpi_device *);
  351. void acpi_remove_dir(struct acpi_device *);
  352. static inline bool acpi_device_enumerated(struct acpi_device *adev)
  353. {
  354. return adev && adev->flags.initialized && adev->flags.visited;
  355. }
  356. typedef void (*acpi_hp_callback)(void *data, u32 src);
  357. acpi_status acpi_hotplug_execute(acpi_hp_callback func, void *data, u32 src);
  358. /**
  359. * module_acpi_driver(acpi_driver) - Helper macro for registering an ACPI driver
  360. * @__acpi_driver: acpi_driver struct
  361. *
  362. * Helper macro for ACPI drivers which do not do anything special in module
  363. * init/exit. This eliminates a lot of boilerplate. Each module may only
  364. * use this macro once, and calling it replaces module_init() and module_exit()
  365. */
  366. #define module_acpi_driver(__acpi_driver) \
  367. module_driver(__acpi_driver, acpi_bus_register_driver, \
  368. acpi_bus_unregister_driver)
  369. /*
  370. * Bind physical devices with ACPI devices
  371. */
  372. struct acpi_bus_type {
  373. struct list_head list;
  374. const char *name;
  375. bool (*match)(struct device *dev);
  376. struct acpi_device * (*find_companion)(struct device *);
  377. void (*setup)(struct device *);
  378. void (*cleanup)(struct device *);
  379. };
  380. int register_acpi_bus_type(struct acpi_bus_type *);
  381. int unregister_acpi_bus_type(struct acpi_bus_type *);
  382. struct acpi_pci_root {
  383. struct acpi_device * device;
  384. struct pci_bus *bus;
  385. u16 segment;
  386. struct resource secondary; /* downstream bus range */
  387. u32 osc_support_set; /* _OSC state of support bits */
  388. u32 osc_control_set; /* _OSC state of control bits */
  389. phys_addr_t mcfg_addr;
  390. };
  391. /* helper */
  392. struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
  393. u64 address, bool check_children);
  394. int acpi_is_root_bridge(acpi_handle);
  395. struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle);
  396. int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state);
  397. int acpi_disable_wakeup_device_power(struct acpi_device *dev);
  398. #ifdef CONFIG_PM
  399. acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
  400. acpi_notify_handler handler, void *context);
  401. acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
  402. acpi_notify_handler handler);
  403. int acpi_pm_device_sleep_state(struct device *, int *, int);
  404. #else
  405. static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
  406. acpi_notify_handler handler,
  407. void *context)
  408. {
  409. return AE_SUPPORT;
  410. }
  411. static inline acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
  412. acpi_notify_handler handler)
  413. {
  414. return AE_SUPPORT;
  415. }
  416. static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
  417. {
  418. if (p)
  419. *p = ACPI_STATE_D0;
  420. return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3_COLD) ?
  421. m : ACPI_STATE_D0;
  422. }
  423. #endif
  424. #ifdef CONFIG_PM_RUNTIME
  425. int __acpi_device_run_wake(struct acpi_device *, bool);
  426. int acpi_pm_device_run_wake(struct device *, bool);
  427. #else
  428. static inline int __acpi_device_run_wake(struct acpi_device *adev, bool en)
  429. {
  430. return -ENODEV;
  431. }
  432. static inline int acpi_pm_device_run_wake(struct device *dev, bool enable)
  433. {
  434. return -ENODEV;
  435. }
  436. #endif
  437. #ifdef CONFIG_PM_SLEEP
  438. int __acpi_device_sleep_wake(struct acpi_device *, u32, bool);
  439. int acpi_pm_device_sleep_wake(struct device *, bool);
  440. #else
  441. static inline int __acpi_device_sleep_wake(struct acpi_device *adev,
  442. u32 target_state, bool enable)
  443. {
  444. return -ENODEV;
  445. }
  446. static inline int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
  447. {
  448. return -ENODEV;
  449. }
  450. #endif
  451. #ifdef CONFIG_ACPI_SLEEP
  452. u32 acpi_target_system_state(void);
  453. #else
  454. static inline u32 acpi_target_system_state(void) { return ACPI_STATE_S0; }
  455. #endif
  456. static inline bool acpi_device_power_manageable(struct acpi_device *adev)
  457. {
  458. return adev->flags.power_manageable;
  459. }
  460. static inline bool acpi_device_can_wakeup(struct acpi_device *adev)
  461. {
  462. return adev->wakeup.flags.valid;
  463. }
  464. static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
  465. {
  466. return adev->power.states[ACPI_STATE_D3_COLD].flags.os_accessible;
  467. }
  468. #else /* CONFIG_ACPI */
  469. static inline int register_acpi_bus_type(void *bus) { return 0; }
  470. static inline int unregister_acpi_bus_type(void *bus) { return 0; }
  471. #endif /* CONFIG_ACPI */
  472. #endif /*__ACPI_BUS_H__*/