acpi_bus.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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 Scan Handler
  76. * -----------------
  77. */
  78. enum acpi_hotplug_mode {
  79. AHM_GENERIC = 0,
  80. AHM_CONTAINER,
  81. AHM_COUNT
  82. };
  83. struct acpi_hotplug_profile {
  84. struct kobject kobj;
  85. bool enabled:1;
  86. enum acpi_hotplug_mode mode;
  87. };
  88. static inline struct acpi_hotplug_profile *to_acpi_hotplug_profile(
  89. struct kobject *kobj)
  90. {
  91. return container_of(kobj, struct acpi_hotplug_profile, kobj);
  92. }
  93. struct acpi_scan_handler {
  94. const struct acpi_device_id *ids;
  95. struct list_head list_node;
  96. int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id);
  97. void (*detach)(struct acpi_device *dev);
  98. struct acpi_hotplug_profile hotplug;
  99. };
  100. /*
  101. * ACPI Driver
  102. * -----------
  103. */
  104. typedef int (*acpi_op_add) (struct acpi_device * device);
  105. typedef int (*acpi_op_remove) (struct acpi_device * device);
  106. typedef void (*acpi_op_notify) (struct acpi_device * device, u32 event);
  107. struct acpi_device_ops {
  108. acpi_op_add add;
  109. acpi_op_remove remove;
  110. acpi_op_notify notify;
  111. };
  112. #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
  113. struct acpi_driver {
  114. char name[80];
  115. char class[80];
  116. const struct acpi_device_id *ids; /* Supported Hardware IDs */
  117. unsigned int flags;
  118. struct acpi_device_ops ops;
  119. struct device_driver drv;
  120. struct module *owner;
  121. };
  122. /*
  123. * ACPI Device
  124. * -----------
  125. */
  126. /* Status (_STA) */
  127. struct acpi_device_status {
  128. u32 present:1;
  129. u32 enabled:1;
  130. u32 show_in_ui:1;
  131. u32 functional:1;
  132. u32 battery_present:1;
  133. u32 reserved:27;
  134. };
  135. /* Flags */
  136. struct acpi_device_flags {
  137. u32 dynamic_status:1;
  138. u32 removable:1;
  139. u32 ejectable:1;
  140. u32 suprise_removal_ok:1;
  141. u32 power_manageable:1;
  142. u32 performance_manageable:1;
  143. u32 eject_pending:1;
  144. u32 match_driver:1;
  145. u32 reserved:24;
  146. };
  147. /* File System */
  148. struct acpi_device_dir {
  149. struct proc_dir_entry *entry;
  150. };
  151. #define acpi_device_dir(d) ((d)->dir.entry)
  152. /* Plug and Play */
  153. typedef char acpi_bus_id[8];
  154. typedef unsigned long acpi_bus_address;
  155. typedef char acpi_device_name[40];
  156. typedef char acpi_device_class[20];
  157. struct acpi_hardware_id {
  158. struct list_head list;
  159. char *id;
  160. };
  161. struct acpi_pnp_type {
  162. u32 hardware_id:1;
  163. u32 bus_address:1;
  164. u32 reserved:30;
  165. };
  166. struct acpi_device_pnp {
  167. acpi_bus_id bus_id; /* Object name */
  168. struct acpi_pnp_type type; /* ID type */
  169. acpi_bus_address bus_address; /* _ADR */
  170. char *unique_id; /* _UID */
  171. struct list_head ids; /* _HID and _CIDs */
  172. acpi_device_name device_name; /* Driver-determined */
  173. acpi_device_class device_class; /* " */
  174. union acpi_object *str_obj; /* unicode string for _STR method */
  175. unsigned long sun; /* _SUN */
  176. };
  177. #define acpi_device_bid(d) ((d)->pnp.bus_id)
  178. #define acpi_device_adr(d) ((d)->pnp.bus_address)
  179. const char *acpi_device_hid(struct acpi_device *device);
  180. #define acpi_device_name(d) ((d)->pnp.device_name)
  181. #define acpi_device_class(d) ((d)->pnp.device_class)
  182. /* Power Management */
  183. struct acpi_device_power_flags {
  184. u32 explicit_get:1; /* _PSC present? */
  185. u32 power_resources:1; /* Power resources */
  186. u32 inrush_current:1; /* Serialize Dx->D0 */
  187. u32 power_removed:1; /* Optimize Dx->D0 */
  188. u32 reserved:28;
  189. };
  190. struct acpi_device_power_state {
  191. struct {
  192. u8 valid:1;
  193. u8 os_accessible: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 list_head 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 list_head resources;
  236. struct acpi_device_wakeup_flags flags;
  237. int prepare_count;
  238. };
  239. struct acpi_device_physical_node {
  240. u8 node_id;
  241. struct list_head node;
  242. struct device *dev;
  243. };
  244. /* set maximum of physical nodes to 32 for expansibility */
  245. #define ACPI_MAX_PHYSICAL_NODE 32
  246. /* Device */
  247. struct acpi_device {
  248. int device_type;
  249. acpi_handle handle; /* no handle for fixed hardware */
  250. struct acpi_device *parent;
  251. struct list_head children;
  252. struct list_head node;
  253. struct list_head wakeup_list;
  254. struct acpi_device_status status;
  255. struct acpi_device_flags flags;
  256. struct acpi_device_pnp pnp;
  257. struct acpi_device_power power;
  258. struct acpi_device_wakeup wakeup;
  259. struct acpi_device_perf performance;
  260. struct acpi_device_dir dir;
  261. struct acpi_scan_handler *handler;
  262. struct acpi_driver *driver;
  263. void *driver_data;
  264. struct device dev;
  265. enum acpi_bus_removal_type removal_type; /* indicate for different removal type */
  266. u8 physical_node_count;
  267. struct list_head physical_node_list;
  268. struct mutex physical_node_lock;
  269. DECLARE_BITMAP(physical_node_id_bitmap, ACPI_MAX_PHYSICAL_NODE);
  270. struct list_head power_dependent;
  271. void (*remove)(struct acpi_device *);
  272. };
  273. static inline void *acpi_driver_data(struct acpi_device *d)
  274. {
  275. return d->driver_data;
  276. }
  277. #define to_acpi_device(d) container_of(d, struct acpi_device, dev)
  278. #define to_acpi_driver(d) container_of(d, struct acpi_driver, drv)
  279. /* acpi_device.dev.bus == &acpi_bus_type */
  280. extern struct bus_type acpi_bus_type;
  281. /*
  282. * Events
  283. * ------
  284. */
  285. struct acpi_bus_event {
  286. struct list_head node;
  287. acpi_device_class device_class;
  288. acpi_bus_id bus_id;
  289. u32 type;
  290. u32 data;
  291. };
  292. struct acpi_eject_event {
  293. struct acpi_device *device;
  294. u32 event;
  295. };
  296. struct acpi_hp_work {
  297. struct work_struct work;
  298. acpi_handle handle;
  299. u32 type;
  300. void *context;
  301. };
  302. void alloc_acpi_hp_work(acpi_handle handle, u32 type, void *context,
  303. void (*func)(struct work_struct *work));
  304. extern struct kobject *acpi_kobj;
  305. extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int);
  306. void acpi_bus_private_data_handler(acpi_handle, void *);
  307. int acpi_bus_get_private_data(acpi_handle, void **);
  308. extern int acpi_notifier_call_chain(struct acpi_device *, u32, u32);
  309. extern int register_acpi_notifier(struct notifier_block *);
  310. extern int unregister_acpi_notifier(struct notifier_block *);
  311. extern int register_acpi_bus_notifier(struct notifier_block *nb);
  312. extern void unregister_acpi_bus_notifier(struct notifier_block *nb);
  313. /*
  314. * External Functions
  315. */
  316. int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device);
  317. void acpi_bus_data_handler(acpi_handle handle, void *context);
  318. acpi_status acpi_bus_get_status_handle(acpi_handle handle,
  319. unsigned long long *sta);
  320. int acpi_bus_get_status(struct acpi_device *device);
  321. #ifdef CONFIG_PM
  322. int acpi_bus_set_power(acpi_handle handle, int state);
  323. const char *acpi_power_state_string(int state);
  324. int acpi_device_get_power(struct acpi_device *device, int *state);
  325. int acpi_device_set_power(struct acpi_device *device, int state);
  326. int acpi_bus_init_power(struct acpi_device *device);
  327. int acpi_bus_update_power(acpi_handle handle, int *state_p);
  328. bool acpi_bus_power_manageable(acpi_handle handle);
  329. bool acpi_bus_can_wakeup(acpi_handle handle);
  330. #else /* !CONFIG_PM */
  331. static inline int acpi_bus_set_power(acpi_handle handle, int state)
  332. {
  333. return 0;
  334. }
  335. static inline const char *acpi_power_state_string(int state)
  336. {
  337. return "D0";
  338. }
  339. static inline int acpi_device_get_power(struct acpi_device *device, int *state)
  340. {
  341. return 0;
  342. }
  343. static inline int acpi_device_set_power(struct acpi_device *device, int state)
  344. {
  345. return 0;
  346. }
  347. static inline int acpi_bus_init_power(struct acpi_device *device)
  348. {
  349. return 0;
  350. }
  351. static inline int acpi_bus_update_power(acpi_handle handle, int *state_p)
  352. {
  353. return 0;
  354. }
  355. static inline bool acpi_bus_power_manageable(acpi_handle handle)
  356. {
  357. return false;
  358. }
  359. static inline bool acpi_bus_can_wakeup(acpi_handle handle)
  360. {
  361. return false;
  362. }
  363. #endif /* !CONFIG_PM */
  364. #ifdef CONFIG_ACPI_PROC_EVENT
  365. int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data);
  366. int acpi_bus_generate_proc_event4(const char *class, const char *bid, u8 type, int data);
  367. int acpi_bus_receive_event(struct acpi_bus_event *event);
  368. #else
  369. static inline int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
  370. { return 0; }
  371. #endif
  372. void acpi_scan_lock_acquire(void);
  373. void acpi_scan_lock_release(void);
  374. int acpi_scan_add_handler(struct acpi_scan_handler *handler);
  375. int acpi_bus_register_driver(struct acpi_driver *driver);
  376. void acpi_bus_unregister_driver(struct acpi_driver *driver);
  377. int acpi_bus_scan(acpi_handle handle);
  378. void acpi_bus_hot_remove_device(void *context);
  379. void acpi_bus_trim(struct acpi_device *start);
  380. acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
  381. int acpi_match_device_ids(struct acpi_device *device,
  382. const struct acpi_device_id *ids);
  383. int acpi_create_dir(struct acpi_device *);
  384. void acpi_remove_dir(struct acpi_device *);
  385. /**
  386. * module_acpi_driver(acpi_driver) - Helper macro for registering an ACPI driver
  387. * @__acpi_driver: acpi_driver struct
  388. *
  389. * Helper macro for ACPI drivers which do not do anything special in module
  390. * init/exit. This eliminates a lot of boilerplate. Each module may only
  391. * use this macro once, and calling it replaces module_init() and module_exit()
  392. */
  393. #define module_acpi_driver(__acpi_driver) \
  394. module_driver(__acpi_driver, acpi_bus_register_driver, \
  395. acpi_bus_unregister_driver)
  396. /*
  397. * Bind physical devices with ACPI devices
  398. */
  399. struct acpi_bus_type {
  400. struct list_head list;
  401. const char *name;
  402. bool (*match)(struct device *dev);
  403. int (*find_device) (struct device *, acpi_handle *);
  404. void (*setup)(struct device *);
  405. void (*cleanup)(struct device *);
  406. };
  407. int register_acpi_bus_type(struct acpi_bus_type *);
  408. int unregister_acpi_bus_type(struct acpi_bus_type *);
  409. struct acpi_pci_root {
  410. struct list_head node;
  411. struct acpi_device * device;
  412. struct pci_bus *bus;
  413. u16 segment;
  414. struct resource secondary; /* downstream bus range */
  415. u32 osc_support_set; /* _OSC state of support bits */
  416. u32 osc_control_set; /* _OSC state of control bits */
  417. phys_addr_t mcfg_addr;
  418. };
  419. /* helper */
  420. acpi_handle acpi_get_child(acpi_handle, u64);
  421. int acpi_is_root_bridge(acpi_handle);
  422. struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle);
  423. #define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)ACPI_HANDLE(dev))
  424. int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state);
  425. int acpi_disable_wakeup_device_power(struct acpi_device *dev);
  426. #ifdef CONFIG_PM
  427. acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
  428. acpi_notify_handler handler, void *context);
  429. acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
  430. acpi_notify_handler handler);
  431. int acpi_device_power_state(struct device *dev, struct acpi_device *adev,
  432. u32 target_state, int d_max_in, int *d_min_p);
  433. int acpi_pm_device_sleep_state(struct device *, int *, int);
  434. void acpi_dev_pm_add_dependent(acpi_handle handle, struct device *depdev);
  435. void acpi_dev_pm_remove_dependent(acpi_handle handle, struct device *depdev);
  436. #else
  437. static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
  438. acpi_notify_handler handler,
  439. void *context)
  440. {
  441. return AE_SUPPORT;
  442. }
  443. static inline acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
  444. acpi_notify_handler handler)
  445. {
  446. return AE_SUPPORT;
  447. }
  448. static inline int __acpi_device_power_state(int m, int *p)
  449. {
  450. if (p)
  451. *p = ACPI_STATE_D0;
  452. return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3) ? m : ACPI_STATE_D0;
  453. }
  454. static inline int acpi_device_power_state(struct device *dev,
  455. struct acpi_device *adev,
  456. u32 target_state, int d_max_in,
  457. int *d_min_p)
  458. {
  459. return __acpi_device_power_state(d_max_in, d_min_p);
  460. }
  461. static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
  462. {
  463. return __acpi_device_power_state(m, p);
  464. }
  465. static inline void acpi_dev_pm_add_dependent(acpi_handle handle,
  466. struct device *depdev) {}
  467. static inline void acpi_dev_pm_remove_dependent(acpi_handle handle,
  468. struct device *depdev) {}
  469. #endif
  470. #ifdef CONFIG_PM_RUNTIME
  471. int __acpi_device_run_wake(struct acpi_device *, bool);
  472. int acpi_pm_device_run_wake(struct device *, bool);
  473. #else
  474. static inline int __acpi_device_run_wake(struct acpi_device *adev, bool en)
  475. {
  476. return -ENODEV;
  477. }
  478. static inline int acpi_pm_device_run_wake(struct device *dev, bool enable)
  479. {
  480. return -ENODEV;
  481. }
  482. #endif
  483. #ifdef CONFIG_PM_SLEEP
  484. int __acpi_device_sleep_wake(struct acpi_device *, u32, bool);
  485. int acpi_pm_device_sleep_wake(struct device *, bool);
  486. #else
  487. static inline int __acpi_device_sleep_wake(struct acpi_device *adev,
  488. u32 target_state, bool enable)
  489. {
  490. return -ENODEV;
  491. }
  492. static inline int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
  493. {
  494. return -ENODEV;
  495. }
  496. #endif
  497. #ifdef CONFIG_ACPI_SLEEP
  498. u32 acpi_target_system_state(void);
  499. #else
  500. static inline u32 acpi_target_system_state(void) { return ACPI_STATE_S0; }
  501. #endif
  502. static inline bool acpi_device_power_manageable(struct acpi_device *adev)
  503. {
  504. return adev->flags.power_manageable;
  505. }
  506. static inline bool acpi_device_can_wakeup(struct acpi_device *adev)
  507. {
  508. return adev->wakeup.flags.valid;
  509. }
  510. static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
  511. {
  512. return adev->power.states[ACPI_STATE_D3_COLD].flags.os_accessible;
  513. }
  514. #else /* CONFIG_ACPI */
  515. static inline int register_acpi_bus_type(void *bus) { return 0; }
  516. static inline int unregister_acpi_bus_type(void *bus) { return 0; }
  517. #endif /* CONFIG_ACPI */
  518. #endif /*__ACPI_BUS_H__*/