acpi_bus.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. #ifdef CONFIG_ACPI
  49. #include <linux/proc_fs.h>
  50. #define ACPI_BUS_FILE_ROOT "acpi"
  51. extern struct proc_dir_entry *acpi_root_dir;
  52. enum acpi_bus_removal_type {
  53. ACPI_BUS_REMOVAL_NORMAL = 0,
  54. ACPI_BUS_REMOVAL_EJECT,
  55. ACPI_BUS_REMOVAL_SUPRISE,
  56. ACPI_BUS_REMOVAL_TYPE_COUNT
  57. };
  58. enum acpi_bus_device_type {
  59. ACPI_BUS_TYPE_DEVICE = 0,
  60. ACPI_BUS_TYPE_POWER,
  61. ACPI_BUS_TYPE_PROCESSOR,
  62. ACPI_BUS_TYPE_THERMAL,
  63. ACPI_BUS_TYPE_POWER_BUTTON,
  64. ACPI_BUS_TYPE_SLEEP_BUTTON,
  65. ACPI_BUS_DEVICE_TYPE_COUNT
  66. };
  67. struct acpi_driver;
  68. struct acpi_device;
  69. /*
  70. * ACPI Driver
  71. * -----------
  72. */
  73. typedef int (*acpi_op_add) (struct acpi_device * device);
  74. typedef int (*acpi_op_remove) (struct acpi_device * device, int type);
  75. typedef int (*acpi_op_start) (struct acpi_device * device);
  76. typedef int (*acpi_op_suspend) (struct acpi_device * device);
  77. typedef int (*acpi_op_resume) (struct acpi_device * device);
  78. typedef int (*acpi_op_bind) (struct acpi_device * device);
  79. typedef int (*acpi_op_unbind) (struct acpi_device * device);
  80. typedef void (*acpi_op_notify) (struct acpi_device * device, u32 event);
  81. struct acpi_bus_ops {
  82. u32 acpi_op_add:1;
  83. u32 acpi_op_start:1;
  84. };
  85. struct acpi_device_ops {
  86. acpi_op_add add;
  87. acpi_op_remove remove;
  88. acpi_op_start start;
  89. acpi_op_suspend suspend;
  90. acpi_op_resume resume;
  91. acpi_op_bind bind;
  92. acpi_op_unbind unbind;
  93. acpi_op_notify notify;
  94. };
  95. #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
  96. struct acpi_driver {
  97. char name[80];
  98. char class[80];
  99. const struct acpi_device_id *ids; /* Supported Hardware IDs */
  100. unsigned int flags;
  101. struct acpi_device_ops ops;
  102. struct device_driver drv;
  103. struct module *owner;
  104. };
  105. /*
  106. * ACPI Device
  107. * -----------
  108. */
  109. /* Status (_STA) */
  110. struct acpi_device_status {
  111. u32 present:1;
  112. u32 enabled:1;
  113. u32 show_in_ui:1;
  114. u32 functional:1;
  115. u32 battery_present:1;
  116. u32 reserved:27;
  117. };
  118. /* Flags */
  119. struct acpi_device_flags {
  120. u32 dynamic_status:1;
  121. u32 bus_address:1;
  122. u32 removable:1;
  123. u32 ejectable:1;
  124. u32 lockable:1;
  125. u32 suprise_removal_ok:1;
  126. u32 power_manageable:1;
  127. u32 performance_manageable:1;
  128. u32 reserved:24;
  129. };
  130. /* File System */
  131. struct acpi_device_dir {
  132. struct proc_dir_entry *entry;
  133. };
  134. #define acpi_device_dir(d) ((d)->dir.entry)
  135. /* Plug and Play */
  136. typedef char acpi_bus_id[8];
  137. typedef unsigned long acpi_bus_address;
  138. typedef char acpi_device_name[40];
  139. typedef char acpi_device_class[20];
  140. struct acpi_hardware_id {
  141. struct list_head list;
  142. char *id;
  143. };
  144. struct acpi_device_pnp {
  145. acpi_bus_id bus_id; /* Object name */
  146. acpi_bus_address bus_address; /* _ADR */
  147. char *unique_id; /* _UID */
  148. struct list_head ids; /* _HID and _CIDs */
  149. acpi_device_name device_name; /* Driver-determined */
  150. acpi_device_class device_class; /* " */
  151. };
  152. #define acpi_device_bid(d) ((d)->pnp.bus_id)
  153. #define acpi_device_adr(d) ((d)->pnp.bus_address)
  154. const char *acpi_device_hid(struct acpi_device *device);
  155. #define acpi_device_name(d) ((d)->pnp.device_name)
  156. #define acpi_device_class(d) ((d)->pnp.device_class)
  157. /* Power Management */
  158. struct acpi_device_power_flags {
  159. u32 explicit_get:1; /* _PSC present? */
  160. u32 power_resources:1; /* Power resources */
  161. u32 inrush_current:1; /* Serialize Dx->D0 */
  162. u32 power_removed:1; /* Optimize Dx->D0 */
  163. u32 reserved:28;
  164. };
  165. struct acpi_device_power_state {
  166. struct {
  167. u8 valid:1;
  168. u8 explicit_set:1; /* _PSx present? */
  169. u8 reserved:6;
  170. } flags;
  171. int power; /* % Power (compared to D0) */
  172. int latency; /* Dx->D0 time (microseconds) */
  173. struct acpi_handle_list resources; /* Power resources referenced */
  174. };
  175. struct acpi_device_power {
  176. int state; /* Current state */
  177. struct acpi_device_power_flags flags;
  178. struct acpi_device_power_state states[ACPI_D_STATE_COUNT]; /* Power states (D0-D3Cold) */
  179. };
  180. /* Performance Management */
  181. struct acpi_device_perf_flags {
  182. u8 reserved:8;
  183. };
  184. struct acpi_device_perf_state {
  185. struct {
  186. u8 valid:1;
  187. u8 reserved:7;
  188. } flags;
  189. u8 power; /* % Power (compared to P0) */
  190. u8 performance; /* % Performance ( " ) */
  191. int latency; /* Px->P0 time (microseconds) */
  192. };
  193. struct acpi_device_perf {
  194. int state;
  195. struct acpi_device_perf_flags flags;
  196. int state_count;
  197. struct acpi_device_perf_state *states;
  198. };
  199. /* Wakeup Management */
  200. struct acpi_device_wakeup_flags {
  201. u8 valid:1; /* Can successfully enable wakeup? */
  202. u8 run_wake:1; /* Run-Wake GPE devices */
  203. u8 notifier_present:1; /* Wake-up notify handler has been installed */
  204. };
  205. struct acpi_device_wakeup {
  206. acpi_handle gpe_device;
  207. u64 gpe_number;
  208. u64 sleep_state;
  209. struct acpi_handle_list resources;
  210. struct acpi_device_wakeup_flags flags;
  211. int prepare_count;
  212. };
  213. struct acpi_device_physical_node {
  214. u8 node_id;
  215. struct list_head node;
  216. struct device *dev;
  217. };
  218. /* set maximum of physical nodes to 32 for expansibility */
  219. #define ACPI_MAX_PHYSICAL_NODE 32
  220. /* Device */
  221. struct acpi_device {
  222. int device_type;
  223. acpi_handle handle; /* no handle for fixed hardware */
  224. struct acpi_device *parent;
  225. struct list_head children;
  226. struct list_head node;
  227. struct list_head wakeup_list;
  228. struct acpi_device_status status;
  229. struct acpi_device_flags flags;
  230. struct acpi_device_pnp pnp;
  231. struct acpi_device_power power;
  232. struct acpi_device_wakeup wakeup;
  233. struct acpi_device_perf performance;
  234. struct acpi_device_dir dir;
  235. struct acpi_device_ops ops;
  236. struct acpi_driver *driver;
  237. void *driver_data;
  238. struct device dev;
  239. struct acpi_bus_ops bus_ops; /* workaround for different code path for hotplug */
  240. enum acpi_bus_removal_type removal_type; /* indicate for different removal type */
  241. u8 physical_node_count;
  242. struct list_head physical_node_list;
  243. struct mutex physical_node_lock;
  244. DECLARE_BITMAP(physical_node_id_bitmap, ACPI_MAX_PHYSICAL_NODE);
  245. };
  246. static inline void *acpi_driver_data(struct acpi_device *d)
  247. {
  248. return d->driver_data;
  249. }
  250. #define to_acpi_device(d) container_of(d, struct acpi_device, dev)
  251. #define to_acpi_driver(d) container_of(d, struct acpi_driver, drv)
  252. /* acpi_device.dev.bus == &acpi_bus_type */
  253. extern struct bus_type acpi_bus_type;
  254. /*
  255. * Events
  256. * ------
  257. */
  258. struct acpi_bus_event {
  259. struct list_head node;
  260. acpi_device_class device_class;
  261. acpi_bus_id bus_id;
  262. u32 type;
  263. u32 data;
  264. };
  265. extern struct kobject *acpi_kobj;
  266. extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int);
  267. void acpi_bus_private_data_handler(acpi_handle, void *);
  268. int acpi_bus_get_private_data(acpi_handle, void **);
  269. extern int acpi_notifier_call_chain(struct acpi_device *, u32, u32);
  270. extern int register_acpi_notifier(struct notifier_block *);
  271. extern int unregister_acpi_notifier(struct notifier_block *);
  272. extern int register_acpi_bus_notifier(struct notifier_block *nb);
  273. extern void unregister_acpi_bus_notifier(struct notifier_block *nb);
  274. /*
  275. * External Functions
  276. */
  277. int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device);
  278. void acpi_bus_data_handler(acpi_handle handle, void *context);
  279. acpi_status acpi_bus_get_status_handle(acpi_handle handle,
  280. unsigned long long *sta);
  281. int acpi_bus_get_status(struct acpi_device *device);
  282. int acpi_bus_set_power(acpi_handle handle, int state);
  283. int acpi_bus_update_power(acpi_handle handle, int *state_p);
  284. bool acpi_bus_power_manageable(acpi_handle handle);
  285. bool acpi_bus_can_wakeup(acpi_handle handle);
  286. int acpi_power_resource_register_device(struct device *dev, acpi_handle handle);
  287. void acpi_power_resource_unregister_device(struct device *dev, acpi_handle handle);
  288. #ifdef CONFIG_ACPI_PROC_EVENT
  289. int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data);
  290. int acpi_bus_generate_proc_event4(const char *class, const char *bid, u8 type, int data);
  291. int acpi_bus_receive_event(struct acpi_bus_event *event);
  292. #else
  293. static inline int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
  294. { return 0; }
  295. #endif
  296. int acpi_bus_register_driver(struct acpi_driver *driver);
  297. void acpi_bus_unregister_driver(struct acpi_driver *driver);
  298. int acpi_bus_add(struct acpi_device **child, struct acpi_device *parent,
  299. acpi_handle handle, int type);
  300. int acpi_bus_trim(struct acpi_device *start, int rmdevice);
  301. int acpi_bus_start(struct acpi_device *device);
  302. acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
  303. int acpi_match_device_ids(struct acpi_device *device,
  304. const struct acpi_device_id *ids);
  305. int acpi_create_dir(struct acpi_device *);
  306. void acpi_remove_dir(struct acpi_device *);
  307. /*
  308. * Bind physical devices with ACPI devices
  309. */
  310. struct acpi_bus_type {
  311. struct list_head list;
  312. struct bus_type *bus;
  313. /* For general devices under the bus */
  314. int (*find_device) (struct device *, acpi_handle *);
  315. /* For bridges, such as PCI root bridge, IDE controller */
  316. int (*find_bridge) (struct device *, acpi_handle *);
  317. };
  318. int register_acpi_bus_type(struct acpi_bus_type *);
  319. int unregister_acpi_bus_type(struct acpi_bus_type *);
  320. struct acpi_pci_root {
  321. struct list_head node;
  322. struct acpi_device * device;
  323. struct acpi_pci_id id;
  324. struct pci_bus *bus;
  325. u16 segment;
  326. struct resource secondary; /* downstream bus range */
  327. u32 osc_support_set; /* _OSC state of support bits */
  328. u32 osc_control_set; /* _OSC state of control bits */
  329. };
  330. /* helper */
  331. acpi_handle acpi_get_child(acpi_handle, u64);
  332. int acpi_is_root_bridge(acpi_handle);
  333. acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
  334. struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle);
  335. #define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle))
  336. int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state);
  337. int acpi_disable_wakeup_device_power(struct acpi_device *dev);
  338. #ifdef CONFIG_PM
  339. int acpi_pm_device_sleep_state(struct device *, int *);
  340. #else
  341. static inline int acpi_pm_device_sleep_state(struct device *d, int *p)
  342. {
  343. if (p)
  344. *p = ACPI_STATE_D0;
  345. return ACPI_STATE_D3;
  346. }
  347. #endif
  348. #ifdef CONFIG_PM_SLEEP
  349. int acpi_pm_device_run_wake(struct device *, bool);
  350. int acpi_pm_device_sleep_wake(struct device *, bool);
  351. #else
  352. static inline int acpi_pm_device_run_wake(struct device *dev, bool enable)
  353. {
  354. return -ENODEV;
  355. }
  356. static inline int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
  357. {
  358. return -ENODEV;
  359. }
  360. #endif
  361. #endif /* CONFIG_ACPI */
  362. #endif /*__ACPI_BUS_H__*/