0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _DEVICE_BUS_H_
0015 #define _DEVICE_BUS_H_
0016
0017 #include <linux/kobject.h>
0018 #include <linux/klist.h>
0019 #include <linux/pm.h>
0020
0021 struct device_driver;
0022 struct fwnode_handle;
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 struct bus_type {
0085 const char *name;
0086 const char *dev_name;
0087 struct device *dev_root;
0088 const struct attribute_group **bus_groups;
0089 const struct attribute_group **dev_groups;
0090 const struct attribute_group **drv_groups;
0091
0092 int (*match)(struct device *dev, struct device_driver *drv);
0093 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
0094 int (*probe)(struct device *dev);
0095 void (*sync_state)(struct device *dev);
0096 void (*remove)(struct device *dev);
0097 void (*shutdown)(struct device *dev);
0098
0099 int (*online)(struct device *dev);
0100 int (*offline)(struct device *dev);
0101
0102 int (*suspend)(struct device *dev, pm_message_t state);
0103 int (*resume)(struct device *dev);
0104
0105 int (*num_vf)(struct device *dev);
0106
0107 int (*dma_configure)(struct device *dev);
0108 void (*dma_cleanup)(struct device *dev);
0109
0110 const struct dev_pm_ops *pm;
0111
0112 const struct iommu_ops *iommu_ops;
0113
0114 struct subsys_private *p;
0115 struct lock_class_key lock_key;
0116
0117 bool need_parent_lock;
0118 };
0119
0120 extern int __must_check bus_register(struct bus_type *bus);
0121
0122 extern void bus_unregister(struct bus_type *bus);
0123
0124 extern int __must_check bus_rescan_devices(struct bus_type *bus);
0125
0126 struct bus_attribute {
0127 struct attribute attr;
0128 ssize_t (*show)(struct bus_type *bus, char *buf);
0129 ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
0130 };
0131
0132 #define BUS_ATTR_RW(_name) \
0133 struct bus_attribute bus_attr_##_name = __ATTR_RW(_name)
0134 #define BUS_ATTR_RO(_name) \
0135 struct bus_attribute bus_attr_##_name = __ATTR_RO(_name)
0136 #define BUS_ATTR_WO(_name) \
0137 struct bus_attribute bus_attr_##_name = __ATTR_WO(_name)
0138
0139 extern int __must_check bus_create_file(struct bus_type *,
0140 struct bus_attribute *);
0141 extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
0142
0143
0144 int device_match_name(struct device *dev, const void *name);
0145 int device_match_of_node(struct device *dev, const void *np);
0146 int device_match_fwnode(struct device *dev, const void *fwnode);
0147 int device_match_devt(struct device *dev, const void *pdevt);
0148 int device_match_acpi_dev(struct device *dev, const void *adev);
0149 int device_match_acpi_handle(struct device *dev, const void *handle);
0150 int device_match_any(struct device *dev, const void *unused);
0151
0152
0153 struct subsys_dev_iter {
0154 struct klist_iter ki;
0155 const struct device_type *type;
0156 };
0157 void subsys_dev_iter_init(struct subsys_dev_iter *iter,
0158 struct bus_type *subsys,
0159 struct device *start,
0160 const struct device_type *type);
0161 struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
0162 void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
0163
0164 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
0165 int (*fn)(struct device *dev, void *data));
0166 struct device *bus_find_device(struct bus_type *bus, struct device *start,
0167 const void *data,
0168 int (*match)(struct device *dev, const void *data));
0169
0170
0171
0172
0173
0174
0175
0176 static inline struct device *bus_find_device_by_name(struct bus_type *bus,
0177 struct device *start,
0178 const char *name)
0179 {
0180 return bus_find_device(bus, start, name, device_match_name);
0181 }
0182
0183
0184
0185
0186
0187
0188
0189 static inline struct device *
0190 bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
0191 {
0192 return bus_find_device(bus, NULL, np, device_match_of_node);
0193 }
0194
0195
0196
0197
0198
0199
0200
0201 static inline struct device *
0202 bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
0203 {
0204 return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
0205 }
0206
0207
0208
0209
0210
0211
0212
0213 static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
0214 dev_t devt)
0215 {
0216 return bus_find_device(bus, NULL, &devt, device_match_devt);
0217 }
0218
0219
0220
0221
0222
0223
0224
0225 static inline struct device *
0226 bus_find_next_device(struct bus_type *bus,struct device *cur)
0227 {
0228 return bus_find_device(bus, cur, NULL, device_match_any);
0229 }
0230
0231 #ifdef CONFIG_ACPI
0232 struct acpi_device;
0233
0234
0235
0236
0237
0238
0239
0240 static inline struct device *
0241 bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
0242 {
0243 return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
0244 }
0245 #else
0246 static inline struct device *
0247 bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
0248 {
0249 return NULL;
0250 }
0251 #endif
0252
0253 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
0254 struct device *hint);
0255 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
0256 void *data, int (*fn)(struct device_driver *, void *));
0257 void bus_sort_breadthfirst(struct bus_type *bus,
0258 int (*compare)(const struct device *a,
0259 const struct device *b));
0260
0261
0262
0263
0264
0265
0266 struct notifier_block;
0267
0268 extern int bus_register_notifier(struct bus_type *bus,
0269 struct notifier_block *nb);
0270 extern int bus_unregister_notifier(struct bus_type *bus,
0271 struct notifier_block *nb);
0272
0273
0274
0275
0276
0277 #define BUS_NOTIFY_ADD_DEVICE 0x00000001
0278 #define BUS_NOTIFY_DEL_DEVICE 0x00000002
0279 #define BUS_NOTIFY_REMOVED_DEVICE 0x00000003
0280 #define BUS_NOTIFY_BIND_DRIVER 0x00000004
0281
0282 #define BUS_NOTIFY_BOUND_DRIVER 0x00000005
0283 #define BUS_NOTIFY_UNBIND_DRIVER 0x00000006
0284
0285 #define BUS_NOTIFY_UNBOUND_DRIVER 0x00000007
0286
0287 #define BUS_NOTIFY_DRIVER_NOT_BOUND 0x00000008
0288
0289 extern struct kset *bus_get_kset(struct bus_type *bus);
0290 extern struct klist *bus_get_device_klist(struct bus_type *bus);
0291
0292 #endif