acpi_bus.h 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * acpi_bus.h - ACPI Bus Driver ($Revision: 22 $)
  4. *
  5. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  6. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  7. */
  8. #ifndef __ACPI_BUS_H__
  9. #define __ACPI_BUS_H__
  10. #include <linux/completion.h>
  11. #include <linux/container_of.h>
  12. #include <linux/device.h>
  13. #include <linux/kobject.h>
  14. #include <linux/mutex.h>
  15. #include <linux/property.h>
  16. #include <linux/types.h>
  17. struct acpi_handle_list {
  18. u32 count;
  19. acpi_handle *handles;
  20. };
  21. /* acpi_utils.h */
  22. acpi_status
  23. acpi_extract_package(union acpi_object *package,
  24. struct acpi_buffer *format, struct acpi_buffer *buffer);
  25. acpi_status
  26. acpi_evaluate_integer(acpi_handle handle,
  27. acpi_string pathname,
  28. struct acpi_object_list *arguments, unsigned long long *data);
  29. bool acpi_evaluate_reference(acpi_handle handle, acpi_string pathname,
  30. struct acpi_object_list *arguments,
  31. struct acpi_handle_list *list);
  32. bool acpi_handle_list_equal(struct acpi_handle_list *list1,
  33. struct acpi_handle_list *list2);
  34. void acpi_handle_list_replace(struct acpi_handle_list *dst,
  35. struct acpi_handle_list *src);
  36. void acpi_handle_list_free(struct acpi_handle_list *list);
  37. bool acpi_device_dep(acpi_handle target, acpi_handle match);
  38. acpi_status
  39. acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
  40. struct acpi_buffer *status_buf);
  41. bool acpi_has_method(acpi_handle handle, char *name);
  42. acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
  43. u64 arg);
  44. acpi_status acpi_evaluate_ej0(acpi_handle handle);
  45. acpi_status acpi_evaluate_lck(acpi_handle handle, int lock);
  46. acpi_status acpi_evaluate_reg(acpi_handle handle, u8 space_id, u32 function);
  47. bool acpi_ata_match(acpi_handle handle);
  48. bool acpi_bay_match(acpi_handle handle);
  49. bool acpi_dock_match(acpi_handle handle);
  50. bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs);
  51. union acpi_object *acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid,
  52. u64 rev, u64 func, union acpi_object *argv4);
  53. #ifdef CONFIG_ACPI
  54. bool
  55. acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
  56. static inline union acpi_object *
  57. acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev,
  58. u64 func, union acpi_object *argv4,
  59. acpi_object_type type)
  60. {
  61. union acpi_object *obj;
  62. obj = acpi_evaluate_dsm(handle, guid, rev, func, argv4);
  63. if (obj && obj->type != type) {
  64. ACPI_FREE(obj);
  65. obj = NULL;
  66. }
  67. return obj;
  68. }
  69. #endif
  70. #define ACPI_INIT_DSM_ARGV4(cnt, eles) \
  71. { \
  72. .package.type = ACPI_TYPE_PACKAGE, \
  73. .package.count = (cnt), \
  74. .package.elements = (eles) \
  75. }
  76. bool acpi_dev_found(const char *hid);
  77. bool acpi_dev_present(const char *hid, const char *uid, s64 hrv);
  78. bool acpi_reduced_hardware(void);
  79. #ifdef CONFIG_ACPI
  80. struct proc_dir_entry;
  81. #define ACPI_BUS_FILE_ROOT "acpi"
  82. extern struct proc_dir_entry *acpi_root_dir;
  83. enum acpi_bus_device_type {
  84. ACPI_BUS_TYPE_DEVICE = 0,
  85. ACPI_BUS_TYPE_POWER,
  86. ACPI_BUS_TYPE_PROCESSOR,
  87. ACPI_BUS_TYPE_THERMAL,
  88. ACPI_BUS_TYPE_POWER_BUTTON,
  89. ACPI_BUS_TYPE_SLEEP_BUTTON,
  90. ACPI_BUS_TYPE_ECDT_EC,
  91. ACPI_BUS_DEVICE_TYPE_COUNT
  92. };
  93. struct acpi_driver;
  94. struct acpi_device;
  95. /*
  96. * ACPI Scan Handler
  97. * -----------------
  98. */
  99. struct acpi_hotplug_profile {
  100. struct kobject kobj;
  101. int (*scan_dependent)(struct acpi_device *adev);
  102. void (*notify_online)(struct acpi_device *adev);
  103. bool enabled:1;
  104. bool demand_offline:1;
  105. };
  106. static inline struct acpi_hotplug_profile *to_acpi_hotplug_profile(
  107. struct kobject *kobj)
  108. {
  109. return container_of(kobj, struct acpi_hotplug_profile, kobj);
  110. }
  111. struct acpi_scan_handler {
  112. struct list_head list_node;
  113. const struct acpi_device_id *ids;
  114. bool (*match)(const char *idstr, const struct acpi_device_id **matchid);
  115. int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id);
  116. void (*detach)(struct acpi_device *dev);
  117. void (*post_eject)(struct acpi_device *dev);
  118. void (*bind)(struct device *phys_dev);
  119. void (*unbind)(struct device *phys_dev);
  120. struct acpi_hotplug_profile hotplug;
  121. };
  122. /*
  123. * ACPI Hotplug Context
  124. * --------------------
  125. */
  126. typedef int (*acpi_hp_notify) (struct acpi_device *, u32);
  127. typedef void (*acpi_hp_uevent) (struct acpi_device *, u32);
  128. typedef void (*acpi_hp_fixup) (struct acpi_device *);
  129. struct acpi_hotplug_context {
  130. struct acpi_device *self;
  131. acpi_hp_notify notify;
  132. acpi_hp_uevent uevent;
  133. acpi_hp_fixup fixup;
  134. };
  135. /*
  136. * ACPI Driver
  137. * -----------
  138. */
  139. typedef int (*acpi_op_add) (struct acpi_device * device);
  140. typedef void (*acpi_op_remove) (struct acpi_device *device);
  141. typedef void (*acpi_op_notify) (struct acpi_device * device, u32 event);
  142. struct acpi_device_ops {
  143. acpi_op_add add;
  144. acpi_op_remove remove;
  145. acpi_op_notify notify;
  146. };
  147. #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
  148. struct acpi_driver {
  149. char name[80];
  150. char class[80];
  151. const struct acpi_device_id *ids; /* Supported Hardware IDs */
  152. unsigned int flags;
  153. struct acpi_device_ops ops;
  154. struct device_driver drv;
  155. };
  156. /*
  157. * ACPI Device
  158. * -----------
  159. */
  160. /* Status (_STA) */
  161. struct acpi_device_status {
  162. u32 present:1;
  163. u32 enabled:1;
  164. u32 show_in_ui:1;
  165. u32 functional:1;
  166. u32 battery_present:1;
  167. u32 reserved:27;
  168. };
  169. /* Flags */
  170. struct acpi_device_flags {
  171. u32 dynamic_status:1;
  172. u32 removable:1;
  173. u32 ejectable:1;
  174. u32 power_manageable:1;
  175. u32 match_driver:1;
  176. u32 initialized:1;
  177. u32 visited:1;
  178. u32 hotplug_notify:1;
  179. u32 is_dock_station:1;
  180. u32 of_compatible_ok:1;
  181. u32 coherent_dma:1;
  182. u32 cca_seen:1;
  183. u32 enumeration_by_parent:1;
  184. u32 honor_deps:1;
  185. u32 reserved:18;
  186. };
  187. /* File System */
  188. struct acpi_device_dir {
  189. struct proc_dir_entry *entry;
  190. };
  191. #define acpi_device_dir(d) ((d)->dir.entry)
  192. /* Plug and Play */
  193. #define MAX_ACPI_DEVICE_NAME_LEN 40
  194. #define MAX_ACPI_CLASS_NAME_LEN 20
  195. typedef char acpi_bus_id[8];
  196. typedef u64 acpi_bus_address;
  197. typedef char acpi_device_name[MAX_ACPI_DEVICE_NAME_LEN];
  198. typedef char acpi_device_class[MAX_ACPI_CLASS_NAME_LEN];
  199. struct acpi_hardware_id {
  200. struct list_head list;
  201. const char *id;
  202. };
  203. struct acpi_pnp_type {
  204. u32 hardware_id:1;
  205. u32 bus_address:1;
  206. u32 platform_id:1;
  207. u32 backlight:1;
  208. u32 reserved:28;
  209. };
  210. struct acpi_device_pnp {
  211. acpi_bus_id bus_id; /* Object name */
  212. int instance_no; /* Instance number of this object */
  213. struct acpi_pnp_type type; /* ID type */
  214. acpi_bus_address bus_address; /* _ADR */
  215. char *unique_id; /* _UID */
  216. struct list_head ids; /* _HID and _CIDs */
  217. acpi_device_name device_name; /* Driver-determined */
  218. acpi_device_class device_class; /* " */
  219. };
  220. #define acpi_device_bid(d) ((d)->pnp.bus_id)
  221. #define acpi_device_adr(d) ((d)->pnp.bus_address)
  222. const char *acpi_device_hid(struct acpi_device *device);
  223. #define acpi_device_uid(d) ((d)->pnp.unique_id)
  224. #define acpi_device_name(d) ((d)->pnp.device_name)
  225. #define acpi_device_class(d) ((d)->pnp.device_class)
  226. /* Power Management */
  227. struct acpi_device_power_flags {
  228. u32 explicit_get:1; /* _PSC present? */
  229. u32 power_resources:1; /* Power resources */
  230. u32 inrush_current:1; /* Serialize Dx->D0 */
  231. u32 power_removed:1; /* Optimize Dx->D0 */
  232. u32 ignore_parent:1; /* Power is independent of parent power state */
  233. u32 dsw_present:1; /* _DSW present? */
  234. u32 reserved:26;
  235. };
  236. struct acpi_device_power_state {
  237. struct list_head resources; /* Power resources referenced */
  238. struct {
  239. u8 valid:1;
  240. u8 explicit_set:1; /* _PSx present? */
  241. u8 reserved:6;
  242. } flags;
  243. int power; /* % Power (compared to D0) */
  244. int latency; /* Dx->D0 time (microseconds) */
  245. };
  246. struct acpi_device_power {
  247. int state; /* Current state */
  248. struct acpi_device_power_flags flags;
  249. struct acpi_device_power_state states[ACPI_D_STATE_COUNT]; /* Power states (D0-D3Cold) */
  250. u8 state_for_enumeration; /* Deepest power state for enumeration */
  251. };
  252. struct acpi_dep_data {
  253. struct list_head node;
  254. acpi_handle supplier;
  255. acpi_handle consumer;
  256. bool honor_dep;
  257. bool met;
  258. bool free_when_met;
  259. };
  260. /* Performance Management */
  261. struct acpi_device_perf_flags {
  262. u8 reserved:8;
  263. };
  264. struct acpi_device_perf_state {
  265. struct {
  266. u8 valid:1;
  267. u8 reserved:7;
  268. } flags;
  269. u8 power; /* % Power (compared to P0) */
  270. u8 performance; /* % Performance ( " ) */
  271. int latency; /* Px->P0 time (microseconds) */
  272. };
  273. struct acpi_device_perf {
  274. int state;
  275. struct acpi_device_perf_flags flags;
  276. int state_count;
  277. struct acpi_device_perf_state *states;
  278. };
  279. /* Wakeup Management */
  280. struct acpi_device_wakeup_flags {
  281. u8 valid:1; /* Can successfully enable wakeup? */
  282. u8 notifier_present:1; /* Wake-up notify handler has been installed */
  283. };
  284. struct acpi_device_wakeup_context {
  285. void (*func)(struct acpi_device_wakeup_context *context);
  286. struct device *dev;
  287. };
  288. struct acpi_device_wakeup {
  289. acpi_handle gpe_device;
  290. u64 gpe_number;
  291. u64 sleep_state;
  292. struct list_head resources;
  293. struct acpi_device_wakeup_flags flags;
  294. struct acpi_device_wakeup_context context;
  295. struct wakeup_source *ws;
  296. int prepare_count;
  297. int enable_count;
  298. };
  299. struct acpi_device_physical_node {
  300. struct list_head node;
  301. struct device *dev;
  302. unsigned int node_id;
  303. bool put_online:1;
  304. };
  305. struct acpi_device_properties {
  306. struct list_head list;
  307. const guid_t *guid;
  308. union acpi_object *properties;
  309. void **bufs;
  310. };
  311. /* ACPI Device Specific Data (_DSD) */
  312. struct acpi_device_data {
  313. const union acpi_object *pointer;
  314. struct list_head properties;
  315. const union acpi_object *of_compatible;
  316. struct list_head subnodes;
  317. };
  318. struct acpi_gpio_mapping;
  319. #define ACPI_DEVICE_SWNODE_ROOT 0
  320. /*
  321. * The maximum expected number of CSI-2 data lanes.
  322. *
  323. * This number is not expected to ever have to be equal to or greater than the
  324. * number of bits in an unsigned long variable, but if it needs to be increased
  325. * above that limit, code will need to be adjusted accordingly.
  326. */
  327. #define ACPI_DEVICE_CSI2_DATA_LANES 8
  328. #define ACPI_DEVICE_SWNODE_PORT_NAME_LENGTH 8
  329. enum acpi_device_swnode_dev_props {
  330. ACPI_DEVICE_SWNODE_DEV_ROTATION,
  331. ACPI_DEVICE_SWNODE_DEV_CLOCK_FREQUENCY,
  332. ACPI_DEVICE_SWNODE_DEV_LED_MAX_MICROAMP,
  333. ACPI_DEVICE_SWNODE_DEV_FLASH_MAX_MICROAMP,
  334. ACPI_DEVICE_SWNODE_DEV_FLASH_MAX_TIMEOUT_US,
  335. ACPI_DEVICE_SWNODE_DEV_NUM_OF,
  336. ACPI_DEVICE_SWNODE_DEV_NUM_ENTRIES
  337. };
  338. enum acpi_device_swnode_port_props {
  339. ACPI_DEVICE_SWNODE_PORT_REG,
  340. ACPI_DEVICE_SWNODE_PORT_NUM_OF,
  341. ACPI_DEVICE_SWNODE_PORT_NUM_ENTRIES
  342. };
  343. enum acpi_device_swnode_ep_props {
  344. ACPI_DEVICE_SWNODE_EP_REMOTE_EP,
  345. ACPI_DEVICE_SWNODE_EP_BUS_TYPE,
  346. ACPI_DEVICE_SWNODE_EP_REG,
  347. ACPI_DEVICE_SWNODE_EP_CLOCK_LANES,
  348. ACPI_DEVICE_SWNODE_EP_DATA_LANES,
  349. ACPI_DEVICE_SWNODE_EP_LANE_POLARITIES,
  350. /* TX only */
  351. ACPI_DEVICE_SWNODE_EP_LINK_FREQUENCIES,
  352. ACPI_DEVICE_SWNODE_EP_NUM_OF,
  353. ACPI_DEVICE_SWNODE_EP_NUM_ENTRIES
  354. };
  355. /*
  356. * Each device has a root software node plus two times as many nodes as the
  357. * number of CSI-2 ports.
  358. */
  359. #define ACPI_DEVICE_SWNODE_PORT(port) (2 * (port) + 1)
  360. #define ACPI_DEVICE_SWNODE_EP(endpoint) \
  361. (ACPI_DEVICE_SWNODE_PORT(endpoint) + 1)
  362. /**
  363. * struct acpi_device_software_node_port - MIPI DisCo for Imaging CSI-2 port
  364. * @port_name: Port name.
  365. * @data_lanes: "data-lanes" property values.
  366. * @lane_polarities: "lane-polarities" property values.
  367. * @link_frequencies: "link_frequencies" property values.
  368. * @port_nr: Port number.
  369. * @crs_crs2_local: _CRS CSI2 record present (i.e. this is a transmitter one).
  370. * @port_props: Port properties.
  371. * @ep_props: Endpoint properties.
  372. * @remote_ep: Reference to the remote endpoint.
  373. */
  374. struct acpi_device_software_node_port {
  375. char port_name[ACPI_DEVICE_SWNODE_PORT_NAME_LENGTH + 1];
  376. u32 data_lanes[ACPI_DEVICE_CSI2_DATA_LANES];
  377. u32 lane_polarities[ACPI_DEVICE_CSI2_DATA_LANES + 1 /* clock lane */];
  378. u64 link_frequencies[ACPI_DEVICE_CSI2_DATA_LANES];
  379. unsigned int port_nr;
  380. bool crs_csi2_local;
  381. struct property_entry port_props[ACPI_DEVICE_SWNODE_PORT_NUM_ENTRIES];
  382. struct property_entry ep_props[ACPI_DEVICE_SWNODE_EP_NUM_ENTRIES];
  383. struct software_node_ref_args remote_ep[1];
  384. };
  385. /**
  386. * struct acpi_device_software_nodes - Software nodes for an ACPI device
  387. * @dev_props: Device properties.
  388. * @nodes: Software nodes for root as well as ports and endpoints.
  389. * @nodeprts: Array of software node pointers, for (un)registering them.
  390. * @ports: Information related to each port and endpoint within a port.
  391. * @num_ports: The number of ports.
  392. */
  393. struct acpi_device_software_nodes {
  394. struct property_entry dev_props[ACPI_DEVICE_SWNODE_DEV_NUM_ENTRIES];
  395. struct software_node *nodes;
  396. const struct software_node **nodeptrs;
  397. struct acpi_device_software_node_port *ports;
  398. unsigned int num_ports;
  399. };
  400. /* Device */
  401. struct acpi_device {
  402. u32 pld_crc;
  403. int device_type;
  404. acpi_handle handle; /* no handle for fixed hardware */
  405. struct fwnode_handle fwnode;
  406. struct list_head wakeup_list;
  407. struct list_head del_list;
  408. struct acpi_device_status status;
  409. struct acpi_device_flags flags;
  410. struct acpi_device_pnp pnp;
  411. struct acpi_device_power power;
  412. struct acpi_device_wakeup wakeup;
  413. struct acpi_device_perf performance;
  414. struct acpi_device_dir dir;
  415. struct acpi_device_data data;
  416. struct acpi_scan_handler *handler;
  417. struct acpi_hotplug_context *hp;
  418. struct acpi_device_software_nodes *swnodes;
  419. const struct acpi_gpio_mapping *driver_gpios;
  420. void *driver_data;
  421. struct device dev;
  422. unsigned int physical_node_count;
  423. unsigned int dep_unmet;
  424. struct list_head physical_node_list;
  425. struct mutex physical_node_lock;
  426. void (*remove)(struct acpi_device *);
  427. };
  428. /* Non-device subnode */
  429. struct acpi_data_node {
  430. struct list_head sibling;
  431. const char *name;
  432. acpi_handle handle;
  433. struct fwnode_handle fwnode;
  434. struct fwnode_handle *parent;
  435. struct acpi_device_data data;
  436. struct kobject kobj;
  437. struct completion kobj_done;
  438. };
  439. extern const struct fwnode_operations acpi_device_fwnode_ops;
  440. extern const struct fwnode_operations acpi_data_fwnode_ops;
  441. extern const struct fwnode_operations acpi_static_fwnode_ops;
  442. bool is_acpi_device_node(const struct fwnode_handle *fwnode);
  443. bool is_acpi_data_node(const struct fwnode_handle *fwnode);
  444. static inline bool is_acpi_node(const struct fwnode_handle *fwnode)
  445. {
  446. return (is_acpi_device_node(fwnode) || is_acpi_data_node(fwnode));
  447. }
  448. #define to_acpi_device_node(__fwnode) \
  449. ({ \
  450. typeof(__fwnode) __to_acpi_device_node_fwnode = __fwnode; \
  451. \
  452. is_acpi_device_node(__to_acpi_device_node_fwnode) ? \
  453. container_of(__to_acpi_device_node_fwnode, \
  454. struct acpi_device, fwnode) : \
  455. NULL; \
  456. })
  457. #define to_acpi_data_node(__fwnode) \
  458. ({ \
  459. typeof(__fwnode) __to_acpi_data_node_fwnode = __fwnode; \
  460. \
  461. is_acpi_data_node(__to_acpi_data_node_fwnode) ? \
  462. container_of(__to_acpi_data_node_fwnode, \
  463. struct acpi_data_node, fwnode) : \
  464. NULL; \
  465. })
  466. static inline bool is_acpi_static_node(const struct fwnode_handle *fwnode)
  467. {
  468. return !IS_ERR_OR_NULL(fwnode) &&
  469. fwnode->ops == &acpi_static_fwnode_ops;
  470. }
  471. static inline bool acpi_data_node_match(const struct fwnode_handle *fwnode,
  472. const char *name)
  473. {
  474. return is_acpi_data_node(fwnode) ?
  475. (!strcmp(to_acpi_data_node(fwnode)->name, name)) : false;
  476. }
  477. static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev)
  478. {
  479. return &adev->fwnode;
  480. }
  481. static inline void *acpi_driver_data(struct acpi_device *d)
  482. {
  483. return d->driver_data;
  484. }
  485. #define to_acpi_device(d) container_of(d, struct acpi_device, dev)
  486. #define to_acpi_driver(d) container_of_const(d, struct acpi_driver, drv)
  487. static inline struct acpi_device *acpi_dev_parent(struct acpi_device *adev)
  488. {
  489. if (adev->dev.parent)
  490. return to_acpi_device(adev->dev.parent);
  491. return NULL;
  492. }
  493. static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta)
  494. {
  495. *((u32 *)&adev->status) = sta;
  496. }
  497. static inline void acpi_set_hp_context(struct acpi_device *adev,
  498. struct acpi_hotplug_context *hp)
  499. {
  500. hp->self = adev;
  501. adev->hp = hp;
  502. }
  503. void acpi_initialize_hp_context(struct acpi_device *adev,
  504. struct acpi_hotplug_context *hp,
  505. acpi_hp_notify notify, acpi_hp_uevent uevent);
  506. /* acpi_device.dev.bus == &acpi_bus_type */
  507. extern const struct bus_type acpi_bus_type;
  508. int acpi_bus_for_each_dev(int (*fn)(struct device *, void *), void *data);
  509. int acpi_dev_for_each_child(struct acpi_device *adev,
  510. int (*fn)(struct acpi_device *, void *), void *data);
  511. int acpi_dev_for_each_child_reverse(struct acpi_device *adev,
  512. int (*fn)(struct acpi_device *, void *),
  513. void *data);
  514. /*
  515. * Events
  516. * ------
  517. */
  518. struct acpi_bus_event {
  519. struct list_head node;
  520. acpi_device_class device_class;
  521. acpi_bus_id bus_id;
  522. u32 type;
  523. u32 data;
  524. };
  525. extern struct kobject *acpi_kobj;
  526. extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int);
  527. void acpi_bus_private_data_handler(acpi_handle, void *);
  528. int acpi_bus_get_private_data(acpi_handle, void **);
  529. int acpi_bus_attach_private_data(acpi_handle, void *);
  530. void acpi_bus_detach_private_data(acpi_handle);
  531. int acpi_dev_install_notify_handler(struct acpi_device *adev,
  532. u32 handler_type,
  533. acpi_notify_handler handler, void *context);
  534. void acpi_dev_remove_notify_handler(struct acpi_device *adev,
  535. u32 handler_type,
  536. acpi_notify_handler handler);
  537. extern int acpi_notifier_call_chain(struct acpi_device *, u32, u32);
  538. extern int register_acpi_notifier(struct notifier_block *);
  539. extern int unregister_acpi_notifier(struct notifier_block *);
  540. /*
  541. * External Functions
  542. */
  543. acpi_status acpi_bus_get_status_handle(acpi_handle handle,
  544. unsigned long long *sta);
  545. int acpi_bus_get_status(struct acpi_device *device);
  546. int acpi_bus_set_power(acpi_handle handle, int state);
  547. const char *acpi_power_state_string(int state);
  548. int acpi_device_set_power(struct acpi_device *device, int state);
  549. int acpi_bus_init_power(struct acpi_device *device);
  550. int acpi_device_fix_up_power(struct acpi_device *device);
  551. void acpi_device_fix_up_power_extended(struct acpi_device *adev);
  552. void acpi_device_fix_up_power_children(struct acpi_device *adev);
  553. int acpi_bus_update_power(acpi_handle handle, int *state_p);
  554. int acpi_device_update_power(struct acpi_device *device, int *state_p);
  555. bool acpi_bus_power_manageable(acpi_handle handle);
  556. void acpi_dev_power_up_children_with_adr(struct acpi_device *adev);
  557. u8 acpi_dev_power_state_for_wake(struct acpi_device *adev);
  558. int acpi_device_power_add_dependent(struct acpi_device *adev,
  559. struct device *dev);
  560. void acpi_device_power_remove_dependent(struct acpi_device *adev,
  561. struct device *dev);
  562. #ifdef CONFIG_PM
  563. bool acpi_bus_can_wakeup(acpi_handle handle);
  564. #else
  565. static inline bool acpi_bus_can_wakeup(acpi_handle handle) { return false; }
  566. #endif
  567. void acpi_scan_lock_acquire(void);
  568. void acpi_scan_lock_release(void);
  569. void acpi_lock_hp_context(void);
  570. void acpi_unlock_hp_context(void);
  571. int acpi_scan_add_handler(struct acpi_scan_handler *handler);
  572. /*
  573. * use a macro to avoid include chaining to get THIS_MODULE
  574. */
  575. #define acpi_bus_register_driver(drv) \
  576. __acpi_bus_register_driver(drv, THIS_MODULE)
  577. int __acpi_bus_register_driver(struct acpi_driver *driver, struct module *owner);
  578. void acpi_bus_unregister_driver(struct acpi_driver *driver);
  579. int acpi_bus_scan(acpi_handle handle);
  580. void acpi_bus_trim(struct acpi_device *start);
  581. acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
  582. int acpi_match_device_ids(struct acpi_device *device,
  583. const struct acpi_device_id *ids);
  584. void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
  585. char *modalias, size_t len);
  586. static inline bool acpi_device_enumerated(struct acpi_device *adev)
  587. {
  588. return adev && adev->flags.initialized && adev->flags.visited;
  589. }
  590. /**
  591. * module_acpi_driver(acpi_driver) - Helper macro for registering an ACPI driver
  592. * @__acpi_driver: acpi_driver struct
  593. *
  594. * Helper macro for ACPI drivers which do not do anything special in module
  595. * init/exit. This eliminates a lot of boilerplate. Each module may only
  596. * use this macro once, and calling it replaces module_init() and module_exit()
  597. */
  598. #define module_acpi_driver(__acpi_driver) \
  599. module_driver(__acpi_driver, acpi_bus_register_driver, \
  600. acpi_bus_unregister_driver)
  601. /*
  602. * Bind physical devices with ACPI devices
  603. */
  604. struct acpi_bus_type {
  605. struct list_head list;
  606. const char *name;
  607. bool (*match)(struct device *dev);
  608. struct acpi_device * (*find_companion)(struct device *);
  609. void (*setup)(struct device *);
  610. };
  611. int register_acpi_bus_type(struct acpi_bus_type *);
  612. int unregister_acpi_bus_type(struct acpi_bus_type *);
  613. int acpi_bind_one(struct device *dev, struct acpi_device *adev);
  614. int acpi_unbind_one(struct device *dev);
  615. enum acpi_bridge_type {
  616. ACPI_BRIDGE_TYPE_PCIE = 1,
  617. ACPI_BRIDGE_TYPE_CXL,
  618. };
  619. struct acpi_pci_root {
  620. struct acpi_device * device;
  621. struct pci_bus *bus;
  622. u16 segment;
  623. int bridge_type;
  624. struct resource secondary; /* downstream bus range */
  625. u32 osc_support_set; /* _OSC state of support bits */
  626. u32 osc_control_set; /* _OSC state of control bits */
  627. u32 osc_ext_support_set; /* _OSC state of extended support bits */
  628. u32 osc_ext_control_set; /* _OSC state of extended control bits */
  629. phys_addr_t mcfg_addr;
  630. };
  631. /* helper */
  632. struct iommu_ops;
  633. bool acpi_dma_supported(const struct acpi_device *adev);
  634. enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev);
  635. int acpi_iommu_fwspec_init(struct device *dev, u32 id,
  636. struct fwnode_handle *fwnode);
  637. int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map);
  638. int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
  639. const u32 *input_id);
  640. static inline int acpi_dma_configure(struct device *dev,
  641. enum dev_dma_attr attr)
  642. {
  643. return acpi_dma_configure_id(dev, attr, NULL);
  644. }
  645. struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
  646. u64 address, bool check_children);
  647. struct acpi_device *acpi_find_child_by_adr(struct acpi_device *adev,
  648. acpi_bus_address adr);
  649. int acpi_is_root_bridge(acpi_handle);
  650. struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle);
  651. int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state);
  652. int acpi_disable_wakeup_device_power(struct acpi_device *dev);
  653. #ifdef CONFIG_X86
  654. bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status);
  655. bool acpi_quirk_skip_acpi_ac_and_battery(void);
  656. int acpi_install_cmos_rtc_space_handler(acpi_handle handle);
  657. void acpi_remove_cmos_rtc_space_handler(acpi_handle handle);
  658. int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip);
  659. #else
  660. static inline bool acpi_device_override_status(struct acpi_device *adev,
  661. unsigned long long *status)
  662. {
  663. return false;
  664. }
  665. static inline bool acpi_quirk_skip_acpi_ac_and_battery(void)
  666. {
  667. return false;
  668. }
  669. static inline int acpi_install_cmos_rtc_space_handler(acpi_handle handle)
  670. {
  671. return 1;
  672. }
  673. static inline void acpi_remove_cmos_rtc_space_handler(acpi_handle handle)
  674. {
  675. }
  676. static inline int
  677. acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
  678. {
  679. *skip = false;
  680. return 0;
  681. }
  682. #endif
  683. #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
  684. bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev);
  685. bool acpi_quirk_skip_gpio_event_handlers(void);
  686. #else
  687. static inline bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev)
  688. {
  689. return false;
  690. }
  691. static inline bool acpi_quirk_skip_gpio_event_handlers(void)
  692. {
  693. return false;
  694. }
  695. #endif
  696. #ifdef CONFIG_PM
  697. void acpi_pm_wakeup_event(struct device *dev);
  698. acpi_status acpi_add_pm_notifier(struct acpi_device *adev, struct device *dev,
  699. void (*func)(struct acpi_device_wakeup_context *context));
  700. acpi_status acpi_remove_pm_notifier(struct acpi_device *adev);
  701. bool acpi_pm_device_can_wakeup(struct device *dev);
  702. int acpi_pm_device_sleep_state(struct device *, int *, int);
  703. int acpi_pm_set_device_wakeup(struct device *dev, bool enable);
  704. #else
  705. static inline void acpi_pm_wakeup_event(struct device *dev)
  706. {
  707. }
  708. static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
  709. struct device *dev,
  710. void (*func)(struct acpi_device_wakeup_context *context))
  711. {
  712. return AE_SUPPORT;
  713. }
  714. static inline acpi_status acpi_remove_pm_notifier(struct acpi_device *adev)
  715. {
  716. return AE_SUPPORT;
  717. }
  718. static inline bool acpi_pm_device_can_wakeup(struct device *dev)
  719. {
  720. return false;
  721. }
  722. static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
  723. {
  724. if (p)
  725. *p = ACPI_STATE_D0;
  726. return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3_COLD) ?
  727. m : ACPI_STATE_D0;
  728. }
  729. static inline int acpi_pm_set_device_wakeup(struct device *dev, bool enable)
  730. {
  731. return -ENODEV;
  732. }
  733. #endif
  734. #ifdef CONFIG_ACPI_SYSTEM_POWER_STATES_SUPPORT
  735. bool acpi_sleep_state_supported(u8 sleep_state);
  736. #else
  737. static inline bool acpi_sleep_state_supported(u8 sleep_state) { return false; }
  738. #endif
  739. #ifdef CONFIG_ACPI_SLEEP
  740. u32 acpi_target_system_state(void);
  741. #else
  742. static inline u32 acpi_target_system_state(void) { return ACPI_STATE_S0; }
  743. #endif
  744. static inline bool acpi_device_power_manageable(struct acpi_device *adev)
  745. {
  746. return adev->flags.power_manageable;
  747. }
  748. static inline bool acpi_device_can_wakeup(struct acpi_device *adev)
  749. {
  750. return adev->wakeup.flags.valid;
  751. }
  752. static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
  753. {
  754. return adev->power.states[ACPI_STATE_D3_COLD].flags.valid ||
  755. ((acpi_gbl_FADT.header.revision < 6) &&
  756. adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
  757. }
  758. int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer);
  759. static inline bool acpi_dev_hid_match(struct acpi_device *adev, const char *hid2)
  760. {
  761. const char *hid1 = acpi_device_hid(adev);
  762. return hid1 && hid2 && !strcmp(hid1, hid2);
  763. }
  764. static inline bool acpi_str_uid_match(struct acpi_device *adev, const char *uid2)
  765. {
  766. const char *uid1 = acpi_device_uid(adev);
  767. return uid1 && uid2 && !strcmp(uid1, uid2);
  768. }
  769. static inline bool acpi_int_uid_match(struct acpi_device *adev, u64 uid2)
  770. {
  771. u64 uid1;
  772. return !acpi_dev_uid_to_integer(adev, &uid1) && uid1 == uid2;
  773. }
  774. #define TYPE_ENTRY(type, x) \
  775. const type: x, \
  776. type: x
  777. #define ACPI_STR_TYPES(match) \
  778. TYPE_ENTRY(unsigned char *, match), \
  779. TYPE_ENTRY(signed char *, match), \
  780. TYPE_ENTRY(char *, match), \
  781. TYPE_ENTRY(void *, match)
  782. /**
  783. * acpi_dev_uid_match - Match device by supplied UID
  784. * @adev: ACPI device to match.
  785. * @uid2: Unique ID of the device.
  786. *
  787. * Matches UID in @adev with given @uid2.
  788. *
  789. * Returns: %true if matches, %false otherwise.
  790. */
  791. #define acpi_dev_uid_match(adev, uid2) \
  792. _Generic(uid2, \
  793. /* Treat @uid2 as a string for acpi string types */ \
  794. ACPI_STR_TYPES(acpi_str_uid_match), \
  795. /* Treat as an integer otherwise */ \
  796. default: acpi_int_uid_match)(adev, uid2)
  797. /**
  798. * acpi_dev_hid_uid_match - Match device by supplied HID and UID
  799. * @adev: ACPI device to match.
  800. * @hid2: Hardware ID of the device.
  801. * @uid2: Unique ID of the device, pass NULL to not check _UID.
  802. *
  803. * Matches HID and UID in @adev with given @hid2 and @uid2. Absence of @uid2
  804. * will be treated as a match. If user wants to validate @uid2, it should be
  805. * done before calling this function.
  806. *
  807. * Returns: %true if matches or @uid2 is NULL, %false otherwise.
  808. */
  809. #define acpi_dev_hid_uid_match(adev, hid2, uid2) \
  810. (acpi_dev_hid_match(adev, hid2) && \
  811. /* Distinguish integer 0 from NULL @uid2 */ \
  812. (_Generic(uid2, ACPI_STR_TYPES(!(uid2)), default: 0) || \
  813. acpi_dev_uid_match(adev, uid2)))
  814. void acpi_dev_clear_dependencies(struct acpi_device *supplier);
  815. bool acpi_dev_ready_for_enumeration(const struct acpi_device *device);
  816. struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier,
  817. struct acpi_device *start);
  818. /**
  819. * for_each_acpi_consumer_dev - iterate over the consumer ACPI devices for a
  820. * given supplier
  821. * @supplier: Pointer to the supplier's ACPI device
  822. * @consumer: Pointer to &struct acpi_device to hold the consumer, initially NULL
  823. */
  824. #define for_each_acpi_consumer_dev(supplier, consumer) \
  825. for (consumer = acpi_dev_get_next_consumer_dev(supplier, NULL); \
  826. consumer; \
  827. consumer = acpi_dev_get_next_consumer_dev(supplier, consumer))
  828. struct acpi_device *
  829. acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
  830. struct acpi_device *
  831. acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
  832. /**
  833. * for_each_acpi_dev_match - iterate over ACPI devices that matching the criteria
  834. * @adev: pointer to the matching ACPI device, NULL at the end of the loop
  835. * @hid: Hardware ID of the device.
  836. * @uid: Unique ID of the device, pass NULL to not check _UID
  837. * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
  838. *
  839. * The caller is responsible for invoking acpi_dev_put() on the returned device.
  840. */
  841. #define for_each_acpi_dev_match(adev, hid, uid, hrv) \
  842. for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv); \
  843. adev; \
  844. adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv))
  845. static inline struct acpi_device *acpi_dev_get(struct acpi_device *adev)
  846. {
  847. return adev ? to_acpi_device(get_device(&adev->dev)) : NULL;
  848. }
  849. static inline void acpi_dev_put(struct acpi_device *adev)
  850. {
  851. if (adev)
  852. put_device(&adev->dev);
  853. }
  854. struct acpi_device *acpi_fetch_acpi_dev(acpi_handle handle);
  855. struct acpi_device *acpi_get_acpi_dev(acpi_handle handle);
  856. static inline void acpi_put_acpi_dev(struct acpi_device *adev)
  857. {
  858. acpi_dev_put(adev);
  859. }
  860. int acpi_wait_for_acpi_ipmi(void);
  861. int acpi_scan_add_dep(acpi_handle handle, struct acpi_handle_list *dep_devices);
  862. u32 arch_acpi_add_auto_dep(acpi_handle handle);
  863. #else /* CONFIG_ACPI */
  864. static inline int register_acpi_bus_type(void *bus) { return 0; }
  865. static inline int unregister_acpi_bus_type(void *bus) { return 0; }
  866. static inline int acpi_wait_for_acpi_ipmi(void) { return 0; }
  867. static inline const char *acpi_device_hid(struct acpi_device *device)
  868. {
  869. return "";
  870. }
  871. static inline bool
  872. acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
  873. {
  874. return false;
  875. }
  876. #define for_each_acpi_consumer_dev(supplier, consumer) \
  877. for (consumer = NULL; false && (supplier);)
  878. #define for_each_acpi_dev_match(adev, hid, uid, hrv) \
  879. for (adev = NULL; false && (hid) && (uid) && (hrv); )
  880. #endif /* CONFIG_ACPI */
  881. #endif /*__ACPI_BUS_H__*/