Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  acpi_bus.h - ACPI Bus Driver ($Revision: 22 $)
0004  *
0005  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
0006  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
0007  */
0008 
0009 #ifndef __ACPI_BUS_H__
0010 #define __ACPI_BUS_H__
0011 
0012 #include <linux/device.h>
0013 #include <linux/property.h>
0014 
0015 /* TBD: Make dynamic */
0016 #define ACPI_MAX_HANDLES    10
0017 struct acpi_handle_list {
0018     u32 count;
0019     acpi_handle handles[ACPI_MAX_HANDLES];
0020 };
0021 
0022 /* acpi_utils.h */
0023 acpi_status
0024 acpi_extract_package(union acpi_object *package,
0025              struct acpi_buffer *format, struct acpi_buffer *buffer);
0026 acpi_status
0027 acpi_evaluate_integer(acpi_handle handle,
0028               acpi_string pathname,
0029               struct acpi_object_list *arguments, unsigned long long *data);
0030 acpi_status
0031 acpi_evaluate_reference(acpi_handle handle,
0032             acpi_string pathname,
0033             struct acpi_object_list *arguments,
0034             struct acpi_handle_list *list);
0035 acpi_status
0036 acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
0037           struct acpi_buffer *status_buf);
0038 
0039 acpi_status
0040 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
0041 
0042 bool acpi_has_method(acpi_handle handle, char *name);
0043 acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
0044                        u64 arg);
0045 acpi_status acpi_evaluate_ej0(acpi_handle handle);
0046 acpi_status acpi_evaluate_lck(acpi_handle handle, int lock);
0047 acpi_status acpi_evaluate_reg(acpi_handle handle, u8 space_id, u32 function);
0048 bool acpi_ata_match(acpi_handle handle);
0049 bool acpi_bay_match(acpi_handle handle);
0050 bool acpi_dock_match(acpi_handle handle);
0051 
0052 bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs);
0053 union acpi_object *acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid,
0054             u64 rev, u64 func, union acpi_object *argv4);
0055 
0056 static inline union acpi_object *
0057 acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev,
0058             u64 func, union acpi_object *argv4,
0059             acpi_object_type type)
0060 {
0061     union acpi_object *obj;
0062 
0063     obj = acpi_evaluate_dsm(handle, guid, rev, func, argv4);
0064     if (obj && obj->type != type) {
0065         ACPI_FREE(obj);
0066         obj = NULL;
0067     }
0068 
0069     return obj;
0070 }
0071 
0072 #define ACPI_INIT_DSM_ARGV4(cnt, eles)          \
0073     {                       \
0074       .package.type = ACPI_TYPE_PACKAGE,        \
0075       .package.count = (cnt),           \
0076       .package.elements = (eles)            \
0077     }
0078 
0079 bool acpi_dev_found(const char *hid);
0080 bool acpi_dev_present(const char *hid, const char *uid, s64 hrv);
0081 bool acpi_reduced_hardware(void);
0082 
0083 #ifdef CONFIG_ACPI
0084 
0085 struct proc_dir_entry;
0086 
0087 #define ACPI_BUS_FILE_ROOT  "acpi"
0088 extern struct proc_dir_entry *acpi_root_dir;
0089 
0090 enum acpi_bus_device_type {
0091     ACPI_BUS_TYPE_DEVICE = 0,
0092     ACPI_BUS_TYPE_POWER,
0093     ACPI_BUS_TYPE_PROCESSOR,
0094     ACPI_BUS_TYPE_THERMAL,
0095     ACPI_BUS_TYPE_POWER_BUTTON,
0096     ACPI_BUS_TYPE_SLEEP_BUTTON,
0097     ACPI_BUS_TYPE_ECDT_EC,
0098     ACPI_BUS_DEVICE_TYPE_COUNT
0099 };
0100 
0101 struct acpi_driver;
0102 struct acpi_device;
0103 
0104 /*
0105  * ACPI Scan Handler
0106  * -----------------
0107  */
0108 
0109 struct acpi_hotplug_profile {
0110     struct kobject kobj;
0111     int (*scan_dependent)(struct acpi_device *adev);
0112     void (*notify_online)(struct acpi_device *adev);
0113     bool enabled:1;
0114     bool demand_offline:1;
0115 };
0116 
0117 static inline struct acpi_hotplug_profile *to_acpi_hotplug_profile(
0118                         struct kobject *kobj)
0119 {
0120     return container_of(kobj, struct acpi_hotplug_profile, kobj);
0121 }
0122 
0123 struct acpi_scan_handler {
0124     const struct acpi_device_id *ids;
0125     struct list_head list_node;
0126     bool (*match)(const char *idstr, const struct acpi_device_id **matchid);
0127     int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id);
0128     void (*detach)(struct acpi_device *dev);
0129     void (*bind)(struct device *phys_dev);
0130     void (*unbind)(struct device *phys_dev);
0131     struct acpi_hotplug_profile hotplug;
0132 };
0133 
0134 /*
0135  * ACPI Hotplug Context
0136  * --------------------
0137  */
0138 
0139 struct acpi_hotplug_context {
0140     struct acpi_device *self;
0141     int (*notify)(struct acpi_device *, u32);
0142     void (*uevent)(struct acpi_device *, u32);
0143     void (*fixup)(struct acpi_device *);
0144 };
0145 
0146 /*
0147  * ACPI Driver
0148  * -----------
0149  */
0150 
0151 typedef int (*acpi_op_add) (struct acpi_device * device);
0152 typedef int (*acpi_op_remove) (struct acpi_device * device);
0153 typedef void (*acpi_op_notify) (struct acpi_device * device, u32 event);
0154 
0155 struct acpi_device_ops {
0156     acpi_op_add add;
0157     acpi_op_remove remove;
0158     acpi_op_notify notify;
0159 };
0160 
0161 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS   0x1 /* system AND device events */
0162 
0163 struct acpi_driver {
0164     char name[80];
0165     char class[80];
0166     const struct acpi_device_id *ids; /* Supported Hardware IDs */
0167     unsigned int flags;
0168     struct acpi_device_ops ops;
0169     struct device_driver drv;
0170     struct module *owner;
0171 };
0172 
0173 /*
0174  * ACPI Device
0175  * -----------
0176  */
0177 
0178 /* Status (_STA) */
0179 
0180 struct acpi_device_status {
0181     u32 present:1;
0182     u32 enabled:1;
0183     u32 show_in_ui:1;
0184     u32 functional:1;
0185     u32 battery_present:1;
0186     u32 reserved:27;
0187 };
0188 
0189 /* Flags */
0190 
0191 struct acpi_device_flags {
0192     u32 dynamic_status:1;
0193     u32 removable:1;
0194     u32 ejectable:1;
0195     u32 power_manageable:1;
0196     u32 match_driver:1;
0197     u32 initialized:1;
0198     u32 visited:1;
0199     u32 hotplug_notify:1;
0200     u32 is_dock_station:1;
0201     u32 of_compatible_ok:1;
0202     u32 coherent_dma:1;
0203     u32 cca_seen:1;
0204     u32 enumeration_by_parent:1;
0205     u32 honor_deps:1;
0206     u32 reserved:18;
0207 };
0208 
0209 /* File System */
0210 
0211 struct acpi_device_dir {
0212     struct proc_dir_entry *entry;
0213 };
0214 
0215 #define acpi_device_dir(d)  ((d)->dir.entry)
0216 
0217 /* Plug and Play */
0218 
0219 typedef char acpi_bus_id[8];
0220 typedef u64 acpi_bus_address;
0221 typedef char acpi_device_name[40];
0222 typedef char acpi_device_class[20];
0223 
0224 struct acpi_hardware_id {
0225     struct list_head list;
0226     const char *id;
0227 };
0228 
0229 struct acpi_pnp_type {
0230     u32 hardware_id:1;
0231     u32 bus_address:1;
0232     u32 platform_id:1;
0233     u32 reserved:29;
0234 };
0235 
0236 struct acpi_device_pnp {
0237     acpi_bus_id bus_id;     /* Object name */
0238     int instance_no;        /* Instance number of this object */
0239     struct acpi_pnp_type type;  /* ID type */
0240     acpi_bus_address bus_address;   /* _ADR */
0241     char *unique_id;        /* _UID */
0242     struct list_head ids;       /* _HID and _CIDs */
0243     acpi_device_name device_name;   /* Driver-determined */
0244     acpi_device_class device_class; /*        "          */
0245     union acpi_object *str_obj; /* unicode string for _STR method */
0246 };
0247 
0248 #define acpi_device_bid(d)  ((d)->pnp.bus_id)
0249 #define acpi_device_adr(d)  ((d)->pnp.bus_address)
0250 const char *acpi_device_hid(struct acpi_device *device);
0251 #define acpi_device_uid(d)  ((d)->pnp.unique_id)
0252 #define acpi_device_name(d) ((d)->pnp.device_name)
0253 #define acpi_device_class(d)    ((d)->pnp.device_class)
0254 
0255 /* Power Management */
0256 
0257 struct acpi_device_power_flags {
0258     u32 explicit_get:1; /* _PSC present? */
0259     u32 power_resources:1;  /* Power resources */
0260     u32 inrush_current:1;   /* Serialize Dx->D0 */
0261     u32 power_removed:1;    /* Optimize Dx->D0 */
0262     u32 ignore_parent:1;    /* Power is independent of parent power state */
0263     u32 dsw_present:1;  /* _DSW present? */
0264     u32 reserved:26;
0265 };
0266 
0267 struct acpi_device_power_state {
0268     struct {
0269         u8 valid:1;
0270         u8 explicit_set:1;  /* _PSx present? */
0271         u8 reserved:6;
0272     } flags;
0273     int power;      /* % Power (compared to D0) */
0274     int latency;        /* Dx->D0 time (microseconds) */
0275     struct list_head resources; /* Power resources referenced */
0276 };
0277 
0278 struct acpi_device_power {
0279     int state;      /* Current state */
0280     struct acpi_device_power_flags flags;
0281     struct acpi_device_power_state states[ACPI_D_STATE_COUNT];  /* Power states (D0-D3Cold) */
0282     u8 state_for_enumeration; /* Deepest power state for enumeration */
0283 };
0284 
0285 struct acpi_dep_data {
0286     struct list_head node;
0287     acpi_handle supplier;
0288     acpi_handle consumer;
0289     bool honor_dep;
0290 };
0291 
0292 /* Performance Management */
0293 
0294 struct acpi_device_perf_flags {
0295     u8 reserved:8;
0296 };
0297 
0298 struct acpi_device_perf_state {
0299     struct {
0300         u8 valid:1;
0301         u8 reserved:7;
0302     } flags;
0303     u8 power;       /* % Power (compared to P0) */
0304     u8 performance;     /* % Performance (    "   ) */
0305     int latency;        /* Px->P0 time (microseconds) */
0306 };
0307 
0308 struct acpi_device_perf {
0309     int state;
0310     struct acpi_device_perf_flags flags;
0311     int state_count;
0312     struct acpi_device_perf_state *states;
0313 };
0314 
0315 /* Wakeup Management */
0316 struct acpi_device_wakeup_flags {
0317     u8 valid:1;     /* Can successfully enable wakeup? */
0318     u8 notifier_present:1;  /* Wake-up notify handler has been installed */
0319 };
0320 
0321 struct acpi_device_wakeup_context {
0322     void (*func)(struct acpi_device_wakeup_context *context);
0323     struct device *dev;
0324 };
0325 
0326 struct acpi_device_wakeup {
0327     acpi_handle gpe_device;
0328     u64 gpe_number;
0329     u64 sleep_state;
0330     struct list_head resources;
0331     struct acpi_device_wakeup_flags flags;
0332     struct acpi_device_wakeup_context context;
0333     struct wakeup_source *ws;
0334     int prepare_count;
0335     int enable_count;
0336 };
0337 
0338 struct acpi_device_physical_node {
0339     unsigned int node_id;
0340     struct list_head node;
0341     struct device *dev;
0342     bool put_online:1;
0343 };
0344 
0345 struct acpi_device_properties {
0346     const guid_t *guid;
0347     union acpi_object *properties;
0348     struct list_head list;
0349     void **bufs;
0350 };
0351 
0352 /* ACPI Device Specific Data (_DSD) */
0353 struct acpi_device_data {
0354     const union acpi_object *pointer;
0355     struct list_head properties;
0356     const union acpi_object *of_compatible;
0357     struct list_head subnodes;
0358 };
0359 
0360 struct acpi_gpio_mapping;
0361 
0362 /* Device */
0363 struct acpi_device {
0364     u32 pld_crc;
0365     int device_type;
0366     acpi_handle handle;     /* no handle for fixed hardware */
0367     struct fwnode_handle fwnode;
0368     struct acpi_device *parent;
0369     struct list_head wakeup_list;
0370     struct list_head del_list;
0371     struct acpi_device_status status;
0372     struct acpi_device_flags flags;
0373     struct acpi_device_pnp pnp;
0374     struct acpi_device_power power;
0375     struct acpi_device_wakeup wakeup;
0376     struct acpi_device_perf performance;
0377     struct acpi_device_dir dir;
0378     struct acpi_device_data data;
0379     struct acpi_scan_handler *handler;
0380     struct acpi_hotplug_context *hp;
0381     const struct acpi_gpio_mapping *driver_gpios;
0382     void *driver_data;
0383     struct device dev;
0384     unsigned int physical_node_count;
0385     unsigned int dep_unmet;
0386     struct list_head physical_node_list;
0387     struct mutex physical_node_lock;
0388     void (*remove)(struct acpi_device *);
0389 };
0390 
0391 /* Non-device subnode */
0392 struct acpi_data_node {
0393     const char *name;
0394     acpi_handle handle;
0395     struct fwnode_handle fwnode;
0396     struct fwnode_handle *parent;
0397     struct acpi_device_data data;
0398     struct list_head sibling;
0399     struct kobject kobj;
0400     struct completion kobj_done;
0401 };
0402 
0403 extern const struct fwnode_operations acpi_device_fwnode_ops;
0404 extern const struct fwnode_operations acpi_data_fwnode_ops;
0405 extern const struct fwnode_operations acpi_static_fwnode_ops;
0406 
0407 bool is_acpi_device_node(const struct fwnode_handle *fwnode);
0408 bool is_acpi_data_node(const struct fwnode_handle *fwnode);
0409 
0410 static inline bool is_acpi_node(const struct fwnode_handle *fwnode)
0411 {
0412     return (is_acpi_device_node(fwnode) || is_acpi_data_node(fwnode));
0413 }
0414 
0415 #define to_acpi_device_node(__fwnode)                   \
0416     ({                              \
0417         typeof(__fwnode) __to_acpi_device_node_fwnode = __fwnode; \
0418                                     \
0419         is_acpi_device_node(__to_acpi_device_node_fwnode) ? \
0420             container_of(__to_acpi_device_node_fwnode,  \
0421                      struct acpi_device, fwnode) :  \
0422             NULL;                       \
0423     })
0424 
0425 #define to_acpi_data_node(__fwnode)                 \
0426     ({                              \
0427         typeof(__fwnode) __to_acpi_data_node_fwnode = __fwnode; \
0428                                     \
0429         is_acpi_data_node(__to_acpi_data_node_fwnode) ?     \
0430             container_of(__to_acpi_data_node_fwnode,    \
0431                      struct acpi_data_node, fwnode) :   \
0432             NULL;                       \
0433     })
0434 
0435 static inline bool is_acpi_static_node(const struct fwnode_handle *fwnode)
0436 {
0437     return !IS_ERR_OR_NULL(fwnode) &&
0438         fwnode->ops == &acpi_static_fwnode_ops;
0439 }
0440 
0441 static inline bool acpi_data_node_match(const struct fwnode_handle *fwnode,
0442                     const char *name)
0443 {
0444     return is_acpi_data_node(fwnode) ?
0445         (!strcmp(to_acpi_data_node(fwnode)->name, name)) : false;
0446 }
0447 
0448 static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev)
0449 {
0450     return &adev->fwnode;
0451 }
0452 
0453 static inline void *acpi_driver_data(struct acpi_device *d)
0454 {
0455     return d->driver_data;
0456 }
0457 
0458 #define to_acpi_device(d)   container_of(d, struct acpi_device, dev)
0459 #define to_acpi_driver(d)   container_of(d, struct acpi_driver, drv)
0460 
0461 static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta)
0462 {
0463     *((u32 *)&adev->status) = sta;
0464 }
0465 
0466 static inline void acpi_set_hp_context(struct acpi_device *adev,
0467                        struct acpi_hotplug_context *hp)
0468 {
0469     hp->self = adev;
0470     adev->hp = hp;
0471 }
0472 
0473 void acpi_initialize_hp_context(struct acpi_device *adev,
0474                 struct acpi_hotplug_context *hp,
0475                 int (*notify)(struct acpi_device *, u32),
0476                 void (*uevent)(struct acpi_device *, u32));
0477 
0478 /* acpi_device.dev.bus == &acpi_bus_type */
0479 extern struct bus_type acpi_bus_type;
0480 
0481 int acpi_bus_for_each_dev(int (*fn)(struct device *, void *), void *data);
0482 int acpi_dev_for_each_child(struct acpi_device *adev,
0483                 int (*fn)(struct acpi_device *, void *), void *data);
0484 int acpi_dev_for_each_child_reverse(struct acpi_device *adev,
0485                     int (*fn)(struct acpi_device *, void *),
0486                     void *data);
0487 
0488 /*
0489  * Events
0490  * ------
0491  */
0492 
0493 struct acpi_bus_event {
0494     struct list_head node;
0495     acpi_device_class device_class;
0496     acpi_bus_id bus_id;
0497     u32 type;
0498     u32 data;
0499 };
0500 
0501 extern struct kobject *acpi_kobj;
0502 extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int);
0503 void acpi_bus_private_data_handler(acpi_handle, void *);
0504 int acpi_bus_get_private_data(acpi_handle, void **);
0505 int acpi_bus_attach_private_data(acpi_handle, void *);
0506 void acpi_bus_detach_private_data(acpi_handle);
0507 extern int acpi_notifier_call_chain(struct acpi_device *, u32, u32);
0508 extern int register_acpi_notifier(struct notifier_block *);
0509 extern int unregister_acpi_notifier(struct notifier_block *);
0510 
0511 /*
0512  * External Functions
0513  */
0514 
0515 struct acpi_device *acpi_fetch_acpi_dev(acpi_handle handle);
0516 acpi_status acpi_bus_get_status_handle(acpi_handle handle,
0517                        unsigned long long *sta);
0518 int acpi_bus_get_status(struct acpi_device *device);
0519 
0520 int acpi_bus_set_power(acpi_handle handle, int state);
0521 const char *acpi_power_state_string(int state);
0522 int acpi_device_set_power(struct acpi_device *device, int state);
0523 int acpi_bus_init_power(struct acpi_device *device);
0524 int acpi_device_fix_up_power(struct acpi_device *device);
0525 void acpi_device_fix_up_power_extended(struct acpi_device *adev);
0526 int acpi_bus_update_power(acpi_handle handle, int *state_p);
0527 int acpi_device_update_power(struct acpi_device *device, int *state_p);
0528 bool acpi_bus_power_manageable(acpi_handle handle);
0529 void acpi_dev_power_up_children_with_adr(struct acpi_device *adev);
0530 int acpi_device_power_add_dependent(struct acpi_device *adev,
0531                     struct device *dev);
0532 void acpi_device_power_remove_dependent(struct acpi_device *adev,
0533                     struct device *dev);
0534 
0535 #ifdef CONFIG_PM
0536 bool acpi_bus_can_wakeup(acpi_handle handle);
0537 #else
0538 static inline bool acpi_bus_can_wakeup(acpi_handle handle) { return false; }
0539 #endif
0540 
0541 void acpi_scan_lock_acquire(void);
0542 void acpi_scan_lock_release(void);
0543 void acpi_lock_hp_context(void);
0544 void acpi_unlock_hp_context(void);
0545 int acpi_scan_add_handler(struct acpi_scan_handler *handler);
0546 int acpi_bus_register_driver(struct acpi_driver *driver);
0547 void acpi_bus_unregister_driver(struct acpi_driver *driver);
0548 int acpi_bus_scan(acpi_handle handle);
0549 void acpi_bus_trim(struct acpi_device *start);
0550 acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
0551 int acpi_match_device_ids(struct acpi_device *device,
0552               const struct acpi_device_id *ids);
0553 void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
0554                char *modalias, size_t len);
0555 int acpi_create_dir(struct acpi_device *);
0556 void acpi_remove_dir(struct acpi_device *);
0557 
0558 static inline bool acpi_device_enumerated(struct acpi_device *adev)
0559 {
0560     return adev && adev->flags.initialized && adev->flags.visited;
0561 }
0562 
0563 /**
0564  * module_acpi_driver(acpi_driver) - Helper macro for registering an ACPI driver
0565  * @__acpi_driver: acpi_driver struct
0566  *
0567  * Helper macro for ACPI drivers which do not do anything special in module
0568  * init/exit. This eliminates a lot of boilerplate. Each module may only
0569  * use this macro once, and calling it replaces module_init() and module_exit()
0570  */
0571 #define module_acpi_driver(__acpi_driver) \
0572     module_driver(__acpi_driver, acpi_bus_register_driver, \
0573               acpi_bus_unregister_driver)
0574 
0575 /*
0576  * Bind physical devices with ACPI devices
0577  */
0578 struct acpi_bus_type {
0579     struct list_head list;
0580     const char *name;
0581     bool (*match)(struct device *dev);
0582     struct acpi_device * (*find_companion)(struct device *);
0583     void (*setup)(struct device *);
0584 };
0585 int register_acpi_bus_type(struct acpi_bus_type *);
0586 int unregister_acpi_bus_type(struct acpi_bus_type *);
0587 int acpi_bind_one(struct device *dev, struct acpi_device *adev);
0588 int acpi_unbind_one(struct device *dev);
0589 
0590 enum acpi_bridge_type {
0591     ACPI_BRIDGE_TYPE_PCIE = 1,
0592     ACPI_BRIDGE_TYPE_CXL,
0593 };
0594 
0595 struct acpi_pci_root {
0596     struct acpi_device * device;
0597     struct pci_bus *bus;
0598     u16 segment;
0599     int bridge_type;
0600     struct resource secondary;  /* downstream bus range */
0601 
0602     u32 osc_support_set;        /* _OSC state of support bits */
0603     u32 osc_control_set;        /* _OSC state of control bits */
0604     u32 osc_ext_support_set;    /* _OSC state of extended support bits */
0605     u32 osc_ext_control_set;    /* _OSC state of extended control bits */
0606     phys_addr_t mcfg_addr;
0607 };
0608 
0609 /* helper */
0610 
0611 bool acpi_dma_supported(const struct acpi_device *adev);
0612 enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev);
0613 int acpi_iommu_fwspec_init(struct device *dev, u32 id,
0614                struct fwnode_handle *fwnode,
0615                const struct iommu_ops *ops);
0616 int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
0617                u64 *size);
0618 int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
0619                const u32 *input_id);
0620 static inline int acpi_dma_configure(struct device *dev,
0621                      enum dev_dma_attr attr)
0622 {
0623     return acpi_dma_configure_id(dev, attr, NULL);
0624 }
0625 struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
0626                        u64 address, bool check_children);
0627 struct acpi_device *acpi_find_child_by_adr(struct acpi_device *adev,
0628                        acpi_bus_address adr);
0629 int acpi_is_root_bridge(acpi_handle);
0630 struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle);
0631 
0632 int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state);
0633 int acpi_disable_wakeup_device_power(struct acpi_device *dev);
0634 
0635 #ifdef CONFIG_X86
0636 bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status);
0637 bool acpi_quirk_skip_acpi_ac_and_battery(void);
0638 #else
0639 static inline bool acpi_device_override_status(struct acpi_device *adev,
0640                            unsigned long long *status)
0641 {
0642     return false;
0643 }
0644 static inline bool acpi_quirk_skip_acpi_ac_and_battery(void)
0645 {
0646     return false;
0647 }
0648 #endif
0649 
0650 #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
0651 bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev);
0652 int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip);
0653 #else
0654 static inline bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev)
0655 {
0656     return false;
0657 }
0658 static inline int
0659 acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
0660 {
0661     *skip = false;
0662     return 0;
0663 }
0664 #endif
0665 
0666 #ifdef CONFIG_PM
0667 void acpi_pm_wakeup_event(struct device *dev);
0668 acpi_status acpi_add_pm_notifier(struct acpi_device *adev, struct device *dev,
0669             void (*func)(struct acpi_device_wakeup_context *context));
0670 acpi_status acpi_remove_pm_notifier(struct acpi_device *adev);
0671 bool acpi_pm_device_can_wakeup(struct device *dev);
0672 int acpi_pm_device_sleep_state(struct device *, int *, int);
0673 int acpi_pm_set_device_wakeup(struct device *dev, bool enable);
0674 #else
0675 static inline void acpi_pm_wakeup_event(struct device *dev)
0676 {
0677 }
0678 static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
0679                            struct device *dev,
0680                            void (*func)(struct acpi_device_wakeup_context *context))
0681 {
0682     return AE_SUPPORT;
0683 }
0684 static inline acpi_status acpi_remove_pm_notifier(struct acpi_device *adev)
0685 {
0686     return AE_SUPPORT;
0687 }
0688 static inline bool acpi_pm_device_can_wakeup(struct device *dev)
0689 {
0690     return false;
0691 }
0692 static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
0693 {
0694     if (p)
0695         *p = ACPI_STATE_D0;
0696 
0697     return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3_COLD) ?
0698         m : ACPI_STATE_D0;
0699 }
0700 static inline int acpi_pm_set_device_wakeup(struct device *dev, bool enable)
0701 {
0702     return -ENODEV;
0703 }
0704 #endif
0705 
0706 #ifdef CONFIG_ACPI_SYSTEM_POWER_STATES_SUPPORT
0707 bool acpi_sleep_state_supported(u8 sleep_state);
0708 #else
0709 static inline bool acpi_sleep_state_supported(u8 sleep_state) { return false; }
0710 #endif
0711 
0712 #ifdef CONFIG_ACPI_SLEEP
0713 u32 acpi_target_system_state(void);
0714 #else
0715 static inline u32 acpi_target_system_state(void) { return ACPI_STATE_S0; }
0716 #endif
0717 
0718 static inline bool acpi_device_power_manageable(struct acpi_device *adev)
0719 {
0720     return adev->flags.power_manageable;
0721 }
0722 
0723 static inline bool acpi_device_can_wakeup(struct acpi_device *adev)
0724 {
0725     return adev->wakeup.flags.valid;
0726 }
0727 
0728 static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
0729 {
0730     return adev->power.states[ACPI_STATE_D3_COLD].flags.valid ||
0731         ((acpi_gbl_FADT.header.revision < 6) &&
0732         adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
0733 }
0734 
0735 bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
0736 
0737 void acpi_dev_clear_dependencies(struct acpi_device *supplier);
0738 bool acpi_dev_ready_for_enumeration(const struct acpi_device *device);
0739 struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier);
0740 struct acpi_device *
0741 acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
0742 struct acpi_device *
0743 acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
0744 
0745 /**
0746  * for_each_acpi_dev_match - iterate over ACPI devices that matching the criteria
0747  * @adev: pointer to the matching ACPI device, NULL at the end of the loop
0748  * @hid: Hardware ID of the device.
0749  * @uid: Unique ID of the device, pass NULL to not check _UID
0750  * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
0751  *
0752  * The caller is responsible for invoking acpi_dev_put() on the returned device.
0753  */
0754 #define for_each_acpi_dev_match(adev, hid, uid, hrv)            \
0755     for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv);    \
0756          adev;                          \
0757          adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv))
0758 
0759 static inline struct acpi_device *acpi_dev_get(struct acpi_device *adev)
0760 {
0761     return adev ? to_acpi_device(get_device(&adev->dev)) : NULL;
0762 }
0763 
0764 static inline void acpi_dev_put(struct acpi_device *adev)
0765 {
0766     if (adev)
0767         put_device(&adev->dev);
0768 }
0769 
0770 struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle);
0771 
0772 static inline void acpi_bus_put_acpi_device(struct acpi_device *adev)
0773 {
0774     acpi_dev_put(adev);
0775 }
0776 #else   /* CONFIG_ACPI */
0777 
0778 static inline int register_acpi_bus_type(void *bus) { return 0; }
0779 static inline int unregister_acpi_bus_type(void *bus) { return 0; }
0780 
0781 #endif              /* CONFIG_ACPI */
0782 
0783 #endif /*__ACPI_BUS_H__*/