acpi_bus.h 15 KB

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