acpi_bus.h 13 KB

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