acpi_bus.h 15 KB

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