acpi_bus.h 12 KB

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