acpi_bus.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. #define PREFIX "ACPI: "
  30. /* TBD: Make dynamic */
  31. #define ACPI_MAX_HANDLES 10
  32. struct acpi_handle_list {
  33. u32 count;
  34. acpi_handle handles[ACPI_MAX_HANDLES];
  35. };
  36. /* acpi_utils.h */
  37. acpi_status
  38. acpi_extract_package(union acpi_object *package,
  39. struct acpi_buffer *format, struct acpi_buffer *buffer);
  40. acpi_status
  41. acpi_evaluate_integer(acpi_handle handle,
  42. acpi_string pathname,
  43. struct acpi_object_list *arguments, unsigned long long *data);
  44. acpi_status
  45. acpi_evaluate_reference(acpi_handle handle,
  46. acpi_string pathname,
  47. struct acpi_object_list *arguments,
  48. struct acpi_handle_list *list);
  49. #ifdef CONFIG_ACPI
  50. #include <linux/proc_fs.h>
  51. #define ACPI_BUS_FILE_ROOT "acpi"
  52. extern struct proc_dir_entry *acpi_root_dir;
  53. enum acpi_bus_removal_type {
  54. ACPI_BUS_REMOVAL_NORMAL = 0,
  55. ACPI_BUS_REMOVAL_EJECT,
  56. ACPI_BUS_REMOVAL_SUPRISE,
  57. ACPI_BUS_REMOVAL_TYPE_COUNT
  58. };
  59. enum acpi_bus_device_type {
  60. ACPI_BUS_TYPE_DEVICE = 0,
  61. ACPI_BUS_TYPE_POWER,
  62. ACPI_BUS_TYPE_PROCESSOR,
  63. ACPI_BUS_TYPE_THERMAL,
  64. ACPI_BUS_TYPE_SYSTEM,
  65. ACPI_BUS_TYPE_POWER_BUTTON,
  66. ACPI_BUS_TYPE_SLEEP_BUTTON,
  67. ACPI_BUS_DEVICE_TYPE_COUNT
  68. };
  69. struct acpi_driver;
  70. struct acpi_device;
  71. /*
  72. * ACPI Driver
  73. * -----------
  74. */
  75. typedef int (*acpi_op_add) (struct acpi_device * device);
  76. typedef int (*acpi_op_remove) (struct acpi_device * device, int type);
  77. typedef int (*acpi_op_start) (struct acpi_device * device);
  78. typedef int (*acpi_op_stop) (struct acpi_device * device, int type);
  79. typedef int (*acpi_op_suspend) (struct acpi_device * device,
  80. pm_message_t state);
  81. typedef int (*acpi_op_resume) (struct acpi_device * device);
  82. typedef int (*acpi_op_bind) (struct acpi_device * device);
  83. typedef int (*acpi_op_unbind) (struct acpi_device * device);
  84. struct acpi_bus_ops {
  85. u32 acpi_op_add:1;
  86. u32 acpi_op_remove:1;
  87. u32 acpi_op_lock:1;
  88. u32 acpi_op_start:1;
  89. u32 acpi_op_stop:1;
  90. u32 acpi_op_suspend:1;
  91. u32 acpi_op_resume:1;
  92. u32 acpi_op_scan:1;
  93. u32 acpi_op_bind:1;
  94. u32 acpi_op_unbind:1;
  95. u32 acpi_op_shutdown:1;
  96. u32 reserved:21;
  97. };
  98. struct acpi_device_ops {
  99. acpi_op_add add;
  100. acpi_op_remove remove;
  101. acpi_op_start start;
  102. acpi_op_stop stop;
  103. acpi_op_suspend suspend;
  104. acpi_op_resume resume;
  105. acpi_op_bind bind;
  106. acpi_op_unbind unbind;
  107. };
  108. struct acpi_driver {
  109. char name[80];
  110. char class[80];
  111. const struct acpi_device_id *ids; /* Supported Hardware IDs */
  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 hardware_id:1;
  133. u32 compatible_ids:1;
  134. u32 bus_address:1;
  135. u32 unique_id:1;
  136. u32 removable:1;
  137. u32 ejectable:1;
  138. u32 lockable:1;
  139. u32 suprise_removal_ok:1;
  140. u32 power_manageable:1;
  141. u32 performance_manageable:1;
  142. u32 wake_capable:1; /* Wakeup(_PRW) supported? */
  143. u32 force_power_state:1;
  144. u32 reserved:19;
  145. };
  146. /* File System */
  147. struct acpi_device_dir {
  148. struct proc_dir_entry *entry;
  149. };
  150. #define acpi_device_dir(d) ((d)->dir.entry)
  151. /* Plug and Play */
  152. typedef char acpi_bus_id[5];
  153. typedef unsigned long acpi_bus_address;
  154. typedef char acpi_hardware_id[15];
  155. typedef char acpi_unique_id[9];
  156. typedef char acpi_device_name[40];
  157. typedef char acpi_device_class[20];
  158. struct acpi_device_pnp {
  159. acpi_bus_id bus_id; /* Object name */
  160. acpi_bus_address bus_address; /* _ADR */
  161. acpi_hardware_id hardware_id; /* _HID */
  162. struct acpi_compatible_id_list *cid_list; /* _CIDs */
  163. acpi_unique_id unique_id; /* _UID */
  164. acpi_device_name device_name; /* Driver-determined */
  165. acpi_device_class device_class; /* " */
  166. };
  167. #define acpi_device_bid(d) ((d)->pnp.bus_id)
  168. #define acpi_device_adr(d) ((d)->pnp.bus_address)
  169. #define acpi_device_hid(d) ((d)->pnp.hardware_id)
  170. #define acpi_device_uid(d) ((d)->pnp.unique_id)
  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 explicit_set:1; /* _PSx present? */
  185. u8 reserved:6;
  186. } flags;
  187. int power; /* % Power (compared to D0) */
  188. int latency; /* Dx->D0 time (microseconds) */
  189. struct acpi_handle_list resources; /* Power resources referenced */
  190. };
  191. struct acpi_device_power {
  192. int state; /* Current state */
  193. struct acpi_device_power_flags flags;
  194. struct acpi_device_power_state states[4]; /* Power states (D0-D3) */
  195. };
  196. /* Performance Management */
  197. struct acpi_device_perf_flags {
  198. u8 reserved:8;
  199. };
  200. struct acpi_device_perf_state {
  201. struct {
  202. u8 valid:1;
  203. u8 reserved:7;
  204. } flags;
  205. u8 power; /* % Power (compared to P0) */
  206. u8 performance; /* % Performance ( " ) */
  207. int latency; /* Px->P0 time (microseconds) */
  208. };
  209. struct acpi_device_perf {
  210. int state;
  211. struct acpi_device_perf_flags flags;
  212. int state_count;
  213. struct acpi_device_perf_state *states;
  214. };
  215. /* Wakeup Management */
  216. struct acpi_device_wakeup_flags {
  217. u8 valid:1; /* Can successfully enable wakeup? */
  218. u8 prepared:1; /* Has the wake-up capability been enabled? */
  219. u8 run_wake:1; /* Run-Wake GPE devices */
  220. };
  221. struct acpi_device_wakeup_state {
  222. u8 enabled:1;
  223. };
  224. struct acpi_device_wakeup {
  225. acpi_handle gpe_device;
  226. acpi_integer gpe_number;
  227. acpi_integer sleep_state;
  228. struct acpi_handle_list resources;
  229. struct acpi_device_wakeup_state state;
  230. struct acpi_device_wakeup_flags flags;
  231. };
  232. /* Device */
  233. struct acpi_device {
  234. acpi_handle handle;
  235. struct acpi_device *parent;
  236. struct list_head children;
  237. struct list_head node;
  238. struct list_head wakeup_list;
  239. struct list_head g_list;
  240. struct acpi_device_status status;
  241. struct acpi_device_flags flags;
  242. struct acpi_device_pnp pnp;
  243. struct acpi_device_power power;
  244. struct acpi_device_wakeup wakeup;
  245. struct acpi_device_perf performance;
  246. struct acpi_device_dir dir;
  247. struct acpi_device_ops ops;
  248. struct acpi_driver *driver;
  249. void *driver_data;
  250. struct device dev;
  251. struct acpi_bus_ops bus_ops; /* workaround for different code path for hotplug */
  252. enum acpi_bus_removal_type removal_type; /* indicate for different removal type */
  253. };
  254. static inline void *acpi_driver_data(struct acpi_device *d)
  255. {
  256. return d->driver_data;
  257. }
  258. #define to_acpi_device(d) container_of(d, struct acpi_device, dev)
  259. #define to_acpi_driver(d) container_of(d, struct acpi_driver, drv)
  260. /* acpi_device.dev.bus == &acpi_bus_type */
  261. extern struct bus_type acpi_bus_type;
  262. /*
  263. * Events
  264. * ------
  265. */
  266. struct acpi_bus_event {
  267. struct list_head node;
  268. acpi_device_class device_class;
  269. acpi_bus_id bus_id;
  270. u32 type;
  271. u32 data;
  272. };
  273. extern struct kobject *acpi_kobj;
  274. extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int);
  275. void acpi_bus_private_data_handler(acpi_handle, u32, void *);
  276. int acpi_bus_get_private_data(acpi_handle, void **);
  277. extern int acpi_notifier_call_chain(struct acpi_device *, u32, u32);
  278. extern int register_acpi_notifier(struct notifier_block *);
  279. extern int unregister_acpi_notifier(struct notifier_block *);
  280. extern int register_acpi_bus_notifier(struct notifier_block *nb);
  281. extern void unregister_acpi_bus_notifier(struct notifier_block *nb);
  282. /*
  283. * External Functions
  284. */
  285. int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device);
  286. void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context);
  287. int acpi_bus_get_status(struct acpi_device *device);
  288. int acpi_bus_get_power(acpi_handle handle, int *state);
  289. int acpi_bus_set_power(acpi_handle handle, int state);
  290. bool acpi_bus_power_manageable(acpi_handle handle);
  291. bool acpi_bus_can_wakeup(acpi_handle handle);
  292. #ifdef CONFIG_ACPI_PROC_EVENT
  293. int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data);
  294. int acpi_bus_generate_proc_event4(const char *class, const char *bid, u8 type, int data);
  295. int acpi_bus_receive_event(struct acpi_bus_event *event);
  296. #else
  297. static inline int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
  298. { return 0; }
  299. #endif
  300. int acpi_bus_register_driver(struct acpi_driver *driver);
  301. void acpi_bus_unregister_driver(struct acpi_driver *driver);
  302. int acpi_bus_add(struct acpi_device **child, struct acpi_device *parent,
  303. acpi_handle handle, int type);
  304. int acpi_bus_trim(struct acpi_device *start, int rmdevice);
  305. int acpi_bus_start(struct acpi_device *device);
  306. acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
  307. int acpi_match_device_ids(struct acpi_device *device,
  308. const struct acpi_device_id *ids);
  309. int acpi_create_dir(struct acpi_device *);
  310. void acpi_remove_dir(struct acpi_device *);
  311. /*
  312. * Bind physical devices with ACPI devices
  313. */
  314. #include <linux/device.h>
  315. struct acpi_bus_type {
  316. struct list_head list;
  317. struct bus_type *bus;
  318. /* For general devices under the bus */
  319. int (*find_device) (struct device *, acpi_handle *);
  320. /* For bridges, such as PCI root bridge, IDE controller */
  321. int (*find_bridge) (struct device *, acpi_handle *);
  322. };
  323. int register_acpi_bus_type(struct acpi_bus_type *);
  324. int unregister_acpi_bus_type(struct acpi_bus_type *);
  325. struct device *acpi_get_physical_device(acpi_handle);
  326. struct device *acpi_get_physical_pci_device(acpi_handle);
  327. /* helper */
  328. acpi_handle acpi_get_child(acpi_handle, acpi_integer);
  329. acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
  330. #define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle))
  331. #ifdef CONFIG_PM_SLEEP
  332. int acpi_pm_device_sleep_state(struct device *, int *);
  333. int acpi_pm_device_sleep_wake(struct device *, bool);
  334. #else /* !CONFIG_PM_SLEEP */
  335. static inline int acpi_pm_device_sleep_state(struct device *d, int *p)
  336. {
  337. if (p)
  338. *p = ACPI_STATE_D0;
  339. return ACPI_STATE_D3;
  340. }
  341. static inline int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
  342. {
  343. return -ENODEV;
  344. }
  345. #endif /* !CONFIG_PM_SLEEP */
  346. #endif /* CONFIG_ACPI */
  347. #endif /*__ACPI_BUS_H__*/