0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef _DEVICE_H_
0013 #define _DEVICE_H_
0014
0015 #include <linux/dev_printk.h>
0016 #include <linux/energy_model.h>
0017 #include <linux/ioport.h>
0018 #include <linux/kobject.h>
0019 #include <linux/klist.h>
0020 #include <linux/list.h>
0021 #include <linux/lockdep.h>
0022 #include <linux/compiler.h>
0023 #include <linux/types.h>
0024 #include <linux/mutex.h>
0025 #include <linux/pm.h>
0026 #include <linux/atomic.h>
0027 #include <linux/uidgid.h>
0028 #include <linux/gfp.h>
0029 #include <linux/overflow.h>
0030 #include <linux/device/bus.h>
0031 #include <linux/device/class.h>
0032 #include <linux/device/driver.h>
0033 #include <asm/device.h>
0034
0035 struct device;
0036 struct device_private;
0037 struct device_driver;
0038 struct driver_private;
0039 struct module;
0040 struct class;
0041 struct subsys_private;
0042 struct device_node;
0043 struct fwnode_handle;
0044 struct iommu_ops;
0045 struct iommu_group;
0046 struct dev_pin_info;
0047 struct dev_iommu;
0048 struct msi_device_data;
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 struct subsys_interface {
0064 const char *name;
0065 struct bus_type *subsys;
0066 struct list_head node;
0067 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
0068 void (*remove_dev)(struct device *dev, struct subsys_interface *sif);
0069 };
0070
0071 int subsys_interface_register(struct subsys_interface *sif);
0072 void subsys_interface_unregister(struct subsys_interface *sif);
0073
0074 int subsys_system_register(struct bus_type *subsys,
0075 const struct attribute_group **groups);
0076 int subsys_virtual_register(struct bus_type *subsys,
0077 const struct attribute_group **groups);
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 struct device_type {
0089 const char *name;
0090 const struct attribute_group **groups;
0091 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
0092 char *(*devnode)(struct device *dev, umode_t *mode,
0093 kuid_t *uid, kgid_t *gid);
0094 void (*release)(struct device *dev);
0095
0096 const struct dev_pm_ops *pm;
0097 };
0098
0099
0100 struct device_attribute {
0101 struct attribute attr;
0102 ssize_t (*show)(struct device *dev, struct device_attribute *attr,
0103 char *buf);
0104 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
0105 const char *buf, size_t count);
0106 };
0107
0108 struct dev_ext_attribute {
0109 struct device_attribute attr;
0110 void *var;
0111 };
0112
0113 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
0114 char *buf);
0115 ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr,
0116 const char *buf, size_t count);
0117 ssize_t device_show_int(struct device *dev, struct device_attribute *attr,
0118 char *buf);
0119 ssize_t device_store_int(struct device *dev, struct device_attribute *attr,
0120 const char *buf, size_t count);
0121 ssize_t device_show_bool(struct device *dev, struct device_attribute *attr,
0122 char *buf);
0123 ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
0124 const char *buf, size_t count);
0125
0126 #define DEVICE_ATTR(_name, _mode, _show, _store) \
0127 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
0128 #define DEVICE_ATTR_PREALLOC(_name, _mode, _show, _store) \
0129 struct device_attribute dev_attr_##_name = \
0130 __ATTR_PREALLOC(_name, _mode, _show, _store)
0131 #define DEVICE_ATTR_RW(_name) \
0132 struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
0133 #define DEVICE_ATTR_ADMIN_RW(_name) \
0134 struct device_attribute dev_attr_##_name = __ATTR_RW_MODE(_name, 0600)
0135 #define DEVICE_ATTR_RO(_name) \
0136 struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
0137 #define DEVICE_ATTR_ADMIN_RO(_name) \
0138 struct device_attribute dev_attr_##_name = __ATTR_RO_MODE(_name, 0400)
0139 #define DEVICE_ATTR_WO(_name) \
0140 struct device_attribute dev_attr_##_name = __ATTR_WO(_name)
0141 #define DEVICE_ULONG_ATTR(_name, _mode, _var) \
0142 struct dev_ext_attribute dev_attr_##_name = \
0143 { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) }
0144 #define DEVICE_INT_ATTR(_name, _mode, _var) \
0145 struct dev_ext_attribute dev_attr_##_name = \
0146 { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) }
0147 #define DEVICE_BOOL_ATTR(_name, _mode, _var) \
0148 struct dev_ext_attribute dev_attr_##_name = \
0149 { __ATTR(_name, _mode, device_show_bool, device_store_bool), &(_var) }
0150 #define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
0151 struct device_attribute dev_attr_##_name = \
0152 __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
0153
0154 int device_create_file(struct device *device,
0155 const struct device_attribute *entry);
0156 void device_remove_file(struct device *dev,
0157 const struct device_attribute *attr);
0158 bool device_remove_file_self(struct device *dev,
0159 const struct device_attribute *attr);
0160 int __must_check device_create_bin_file(struct device *dev,
0161 const struct bin_attribute *attr);
0162 void device_remove_bin_file(struct device *dev,
0163 const struct bin_attribute *attr);
0164
0165
0166 typedef void (*dr_release_t)(struct device *dev, void *res);
0167 typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
0168
0169 void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp,
0170 int nid, const char *name) __malloc;
0171 #define devres_alloc(release, size, gfp) \
0172 __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release)
0173 #define devres_alloc_node(release, size, gfp, nid) \
0174 __devres_alloc_node(release, size, gfp, nid, #release)
0175
0176 void devres_for_each_res(struct device *dev, dr_release_t release,
0177 dr_match_t match, void *match_data,
0178 void (*fn)(struct device *, void *, void *),
0179 void *data);
0180 void devres_free(void *res);
0181 void devres_add(struct device *dev, void *res);
0182 void *devres_find(struct device *dev, dr_release_t release,
0183 dr_match_t match, void *match_data);
0184 void *devres_get(struct device *dev, void *new_res,
0185 dr_match_t match, void *match_data);
0186 void *devres_remove(struct device *dev, dr_release_t release,
0187 dr_match_t match, void *match_data);
0188 int devres_destroy(struct device *dev, dr_release_t release,
0189 dr_match_t match, void *match_data);
0190 int devres_release(struct device *dev, dr_release_t release,
0191 dr_match_t match, void *match_data);
0192
0193
0194 void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp);
0195 void devres_close_group(struct device *dev, void *id);
0196 void devres_remove_group(struct device *dev, void *id);
0197 int devres_release_group(struct device *dev, void *id);
0198
0199
0200 void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __malloc;
0201 void *devm_krealloc(struct device *dev, void *ptr, size_t size,
0202 gfp_t gfp) __must_check;
0203 __printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp,
0204 const char *fmt, va_list ap) __malloc;
0205 __printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp,
0206 const char *fmt, ...) __malloc;
0207 static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
0208 {
0209 return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
0210 }
0211 static inline void *devm_kmalloc_array(struct device *dev,
0212 size_t n, size_t size, gfp_t flags)
0213 {
0214 size_t bytes;
0215
0216 if (unlikely(check_mul_overflow(n, size, &bytes)))
0217 return NULL;
0218
0219 return devm_kmalloc(dev, bytes, flags);
0220 }
0221 static inline void *devm_kcalloc(struct device *dev,
0222 size_t n, size_t size, gfp_t flags)
0223 {
0224 return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
0225 }
0226 void devm_kfree(struct device *dev, const void *p);
0227 char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc;
0228 const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp);
0229 void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp);
0230
0231 unsigned long devm_get_free_pages(struct device *dev,
0232 gfp_t gfp_mask, unsigned int order);
0233 void devm_free_pages(struct device *dev, unsigned long addr);
0234
0235 void __iomem *devm_ioremap_resource(struct device *dev,
0236 const struct resource *res);
0237 void __iomem *devm_ioremap_resource_wc(struct device *dev,
0238 const struct resource *res);
0239
0240 void __iomem *devm_of_iomap(struct device *dev,
0241 struct device_node *node, int index,
0242 resource_size_t *size);
0243
0244
0245 int devm_add_action(struct device *dev, void (*action)(void *), void *data);
0246 void devm_remove_action(struct device *dev, void (*action)(void *), void *data);
0247 void devm_release_action(struct device *dev, void (*action)(void *), void *data);
0248
0249 static inline int devm_add_action_or_reset(struct device *dev,
0250 void (*action)(void *), void *data)
0251 {
0252 int ret;
0253
0254 ret = devm_add_action(dev, action, data);
0255 if (ret)
0256 action(data);
0257
0258 return ret;
0259 }
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272 #define devm_alloc_percpu(dev, type) \
0273 ((typeof(type) __percpu *)__devm_alloc_percpu((dev), sizeof(type), \
0274 __alignof__(type)))
0275
0276 void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
0277 size_t align);
0278 void devm_free_percpu(struct device *dev, void __percpu *pdata);
0279
0280 struct device_dma_parameters {
0281
0282
0283
0284
0285 unsigned int max_segment_size;
0286 unsigned int min_align_mask;
0287 unsigned long segment_boundary_mask;
0288 };
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299 enum device_link_state {
0300 DL_STATE_NONE = -1,
0301 DL_STATE_DORMANT = 0,
0302 DL_STATE_AVAILABLE,
0303 DL_STATE_CONSUMER_PROBE,
0304 DL_STATE_ACTIVE,
0305 DL_STATE_SUPPLIER_UNBIND,
0306 };
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321 #define DL_FLAG_STATELESS BIT(0)
0322 #define DL_FLAG_AUTOREMOVE_CONSUMER BIT(1)
0323 #define DL_FLAG_PM_RUNTIME BIT(2)
0324 #define DL_FLAG_RPM_ACTIVE BIT(3)
0325 #define DL_FLAG_AUTOREMOVE_SUPPLIER BIT(4)
0326 #define DL_FLAG_AUTOPROBE_CONSUMER BIT(5)
0327 #define DL_FLAG_MANAGED BIT(6)
0328 #define DL_FLAG_SYNC_STATE_ONLY BIT(7)
0329 #define DL_FLAG_INFERRED BIT(8)
0330
0331
0332
0333
0334
0335
0336
0337
0338 enum dl_dev_state {
0339 DL_DEV_NO_DRIVER = 0,
0340 DL_DEV_PROBING,
0341 DL_DEV_DRIVER_BOUND,
0342 DL_DEV_UNBINDING,
0343 };
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354 enum device_removable {
0355 DEVICE_REMOVABLE_NOT_SUPPORTED = 0,
0356 DEVICE_REMOVABLE_UNKNOWN,
0357 DEVICE_FIXED,
0358 DEVICE_REMOVABLE,
0359 };
0360
0361
0362
0363
0364
0365
0366
0367
0368 struct dev_links_info {
0369 struct list_head suppliers;
0370 struct list_head consumers;
0371 struct list_head defer_sync;
0372 enum dl_dev_state status;
0373 };
0374
0375
0376
0377
0378
0379
0380 struct dev_msi_info {
0381 #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
0382 struct irq_domain *domain;
0383 #endif
0384 #ifdef CONFIG_GENERIC_MSI_IRQ
0385 struct msi_device_data *data;
0386 #endif
0387 };
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400 enum device_physical_location_panel {
0401 DEVICE_PANEL_TOP,
0402 DEVICE_PANEL_BOTTOM,
0403 DEVICE_PANEL_LEFT,
0404 DEVICE_PANEL_RIGHT,
0405 DEVICE_PANEL_FRONT,
0406 DEVICE_PANEL_BACK,
0407 DEVICE_PANEL_UNKNOWN,
0408 };
0409
0410
0411
0412
0413
0414
0415
0416
0417 enum device_physical_location_vertical_position {
0418 DEVICE_VERT_POS_UPPER,
0419 DEVICE_VERT_POS_CENTER,
0420 DEVICE_VERT_POS_LOWER,
0421 };
0422
0423
0424
0425
0426
0427
0428
0429
0430 enum device_physical_location_horizontal_position {
0431 DEVICE_HORI_POS_LEFT,
0432 DEVICE_HORI_POS_CENTER,
0433 DEVICE_HORI_POS_RIGHT,
0434 };
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450 struct device_physical_location {
0451 enum device_physical_location_panel panel;
0452 enum device_physical_location_vertical_position vertical_position;
0453 enum device_physical_location_horizontal_position horizontal_position;
0454 bool dock;
0455 bool lid;
0456 };
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555 struct device {
0556 struct kobject kobj;
0557 struct device *parent;
0558
0559 struct device_private *p;
0560
0561 const char *init_name;
0562 const struct device_type *type;
0563
0564 struct bus_type *bus;
0565 struct device_driver *driver;
0566
0567 void *platform_data;
0568
0569 void *driver_data;
0570
0571 struct mutex mutex;
0572
0573
0574
0575 struct dev_links_info links;
0576 struct dev_pm_info power;
0577 struct dev_pm_domain *pm_domain;
0578
0579 #ifdef CONFIG_ENERGY_MODEL
0580 struct em_perf_domain *em_pd;
0581 #endif
0582
0583 #ifdef CONFIG_PINCTRL
0584 struct dev_pin_info *pins;
0585 #endif
0586 struct dev_msi_info msi;
0587 #ifdef CONFIG_DMA_OPS
0588 const struct dma_map_ops *dma_ops;
0589 #endif
0590 u64 *dma_mask;
0591 u64 coherent_dma_mask;
0592
0593
0594
0595
0596 u64 bus_dma_limit;
0597 const struct bus_dma_region *dma_range_map;
0598
0599 struct device_dma_parameters *dma_parms;
0600
0601 struct list_head dma_pools;
0602
0603 #ifdef CONFIG_DMA_DECLARE_COHERENT
0604 struct dma_coherent_mem *dma_mem;
0605
0606 #endif
0607 #ifdef CONFIG_DMA_CMA
0608 struct cma *cma_area;
0609
0610 #endif
0611 #ifdef CONFIG_SWIOTLB
0612 struct io_tlb_mem *dma_io_tlb_mem;
0613 #endif
0614
0615 struct dev_archdata archdata;
0616
0617 struct device_node *of_node;
0618 struct fwnode_handle *fwnode;
0619
0620 #ifdef CONFIG_NUMA
0621 int numa_node;
0622 #endif
0623 dev_t devt;
0624 u32 id;
0625
0626 spinlock_t devres_lock;
0627 struct list_head devres_head;
0628
0629 struct class *class;
0630 const struct attribute_group **groups;
0631
0632 void (*release)(struct device *dev);
0633 struct iommu_group *iommu_group;
0634 struct dev_iommu *iommu;
0635
0636 struct device_physical_location *physical_location;
0637
0638 enum device_removable removable;
0639
0640 bool offline_disabled:1;
0641 bool offline:1;
0642 bool of_node_reused:1;
0643 bool state_synced:1;
0644 bool can_match:1;
0645 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
0646 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
0647 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
0648 bool dma_coherent:1;
0649 #endif
0650 #ifdef CONFIG_DMA_OPS_BYPASS
0651 bool dma_ops_bypass : 1;
0652 #endif
0653 };
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663
0664
0665
0666
0667
0668
0669 struct device_link {
0670 struct device *supplier;
0671 struct list_head s_node;
0672 struct device *consumer;
0673 struct list_head c_node;
0674 struct device link_dev;
0675 enum device_link_state status;
0676 u32 flags;
0677 refcount_t rpm_active;
0678 struct kref kref;
0679 struct work_struct rm_work;
0680 bool supplier_preactivated;
0681 };
0682
0683 static inline struct device *kobj_to_dev(struct kobject *kobj)
0684 {
0685 return container_of(kobj, struct device, kobj);
0686 }
0687
0688
0689
0690
0691
0692
0693 static inline bool device_iommu_mapped(struct device *dev)
0694 {
0695 return (dev->iommu_group != NULL);
0696 }
0697
0698
0699 #include <linux/pm_wakeup.h>
0700
0701 static inline const char *dev_name(const struct device *dev)
0702 {
0703
0704 if (dev->init_name)
0705 return dev->init_name;
0706
0707 return kobject_name(&dev->kobj);
0708 }
0709
0710
0711
0712
0713
0714
0715
0716
0717 static inline const char *dev_bus_name(const struct device *dev)
0718 {
0719 return dev->bus ? dev->bus->name : (dev->class ? dev->class->name : "");
0720 }
0721
0722 __printf(2, 3) int dev_set_name(struct device *dev, const char *name, ...);
0723
0724 #ifdef CONFIG_NUMA
0725 static inline int dev_to_node(struct device *dev)
0726 {
0727 return dev->numa_node;
0728 }
0729 static inline void set_dev_node(struct device *dev, int node)
0730 {
0731 dev->numa_node = node;
0732 }
0733 #else
0734 static inline int dev_to_node(struct device *dev)
0735 {
0736 return NUMA_NO_NODE;
0737 }
0738 static inline void set_dev_node(struct device *dev, int node)
0739 {
0740 }
0741 #endif
0742
0743 static inline struct irq_domain *dev_get_msi_domain(const struct device *dev)
0744 {
0745 #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
0746 return dev->msi.domain;
0747 #else
0748 return NULL;
0749 #endif
0750 }
0751
0752 static inline void dev_set_msi_domain(struct device *dev, struct irq_domain *d)
0753 {
0754 #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
0755 dev->msi.domain = d;
0756 #endif
0757 }
0758
0759 static inline void *dev_get_drvdata(const struct device *dev)
0760 {
0761 return dev->driver_data;
0762 }
0763
0764 static inline void dev_set_drvdata(struct device *dev, void *data)
0765 {
0766 dev->driver_data = data;
0767 }
0768
0769 static inline struct pm_subsys_data *dev_to_psd(struct device *dev)
0770 {
0771 return dev ? dev->power.subsys_data : NULL;
0772 }
0773
0774 static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
0775 {
0776 return dev->kobj.uevent_suppress;
0777 }
0778
0779 static inline void dev_set_uevent_suppress(struct device *dev, int val)
0780 {
0781 dev->kobj.uevent_suppress = val;
0782 }
0783
0784 static inline int device_is_registered(struct device *dev)
0785 {
0786 return dev->kobj.state_in_sysfs;
0787 }
0788
0789 static inline void device_enable_async_suspend(struct device *dev)
0790 {
0791 if (!dev->power.is_prepared)
0792 dev->power.async_suspend = true;
0793 }
0794
0795 static inline void device_disable_async_suspend(struct device *dev)
0796 {
0797 if (!dev->power.is_prepared)
0798 dev->power.async_suspend = false;
0799 }
0800
0801 static inline bool device_async_suspend_enabled(struct device *dev)
0802 {
0803 return !!dev->power.async_suspend;
0804 }
0805
0806 static inline bool device_pm_not_required(struct device *dev)
0807 {
0808 return dev->power.no_pm;
0809 }
0810
0811 static inline void device_set_pm_not_required(struct device *dev)
0812 {
0813 dev->power.no_pm = true;
0814 }
0815
0816 static inline void dev_pm_syscore_device(struct device *dev, bool val)
0817 {
0818 #ifdef CONFIG_PM_SLEEP
0819 dev->power.syscore = val;
0820 #endif
0821 }
0822
0823 static inline void dev_pm_set_driver_flags(struct device *dev, u32 flags)
0824 {
0825 dev->power.driver_flags = flags;
0826 }
0827
0828 static inline bool dev_pm_test_driver_flags(struct device *dev, u32 flags)
0829 {
0830 return !!(dev->power.driver_flags & flags);
0831 }
0832
0833 static inline void device_lock(struct device *dev)
0834 {
0835 mutex_lock(&dev->mutex);
0836 }
0837
0838 static inline int device_lock_interruptible(struct device *dev)
0839 {
0840 return mutex_lock_interruptible(&dev->mutex);
0841 }
0842
0843 static inline int device_trylock(struct device *dev)
0844 {
0845 return mutex_trylock(&dev->mutex);
0846 }
0847
0848 static inline void device_unlock(struct device *dev)
0849 {
0850 mutex_unlock(&dev->mutex);
0851 }
0852
0853 static inline void device_lock_assert(struct device *dev)
0854 {
0855 lockdep_assert_held(&dev->mutex);
0856 }
0857
0858 static inline struct device_node *dev_of_node(struct device *dev)
0859 {
0860 if (!IS_ENABLED(CONFIG_OF) || !dev)
0861 return NULL;
0862 return dev->of_node;
0863 }
0864
0865 static inline bool dev_has_sync_state(struct device *dev)
0866 {
0867 if (!dev)
0868 return false;
0869 if (dev->driver && dev->driver->sync_state)
0870 return true;
0871 if (dev->bus && dev->bus->sync_state)
0872 return true;
0873 return false;
0874 }
0875
0876 static inline void dev_set_removable(struct device *dev,
0877 enum device_removable removable)
0878 {
0879 dev->removable = removable;
0880 }
0881
0882 static inline bool dev_is_removable(struct device *dev)
0883 {
0884 return dev->removable == DEVICE_REMOVABLE;
0885 }
0886
0887 static inline bool dev_removable_is_valid(struct device *dev)
0888 {
0889 return dev->removable != DEVICE_REMOVABLE_NOT_SUPPORTED;
0890 }
0891
0892
0893
0894
0895 int __must_check device_register(struct device *dev);
0896 void device_unregister(struct device *dev);
0897 void device_initialize(struct device *dev);
0898 int __must_check device_add(struct device *dev);
0899 void device_del(struct device *dev);
0900 int device_for_each_child(struct device *dev, void *data,
0901 int (*fn)(struct device *dev, void *data));
0902 int device_for_each_child_reverse(struct device *dev, void *data,
0903 int (*fn)(struct device *dev, void *data));
0904 struct device *device_find_child(struct device *dev, void *data,
0905 int (*match)(struct device *dev, void *data));
0906 struct device *device_find_child_by_name(struct device *parent,
0907 const char *name);
0908 struct device *device_find_any_child(struct device *parent);
0909
0910 int device_rename(struct device *dev, const char *new_name);
0911 int device_move(struct device *dev, struct device *new_parent,
0912 enum dpm_order dpm_order);
0913 int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid);
0914 const char *device_get_devnode(struct device *dev, umode_t *mode, kuid_t *uid,
0915 kgid_t *gid, const char **tmp);
0916 int device_is_dependent(struct device *dev, void *target);
0917
0918 static inline bool device_supports_offline(struct device *dev)
0919 {
0920 return dev->bus && dev->bus->offline && dev->bus->online;
0921 }
0922
0923 #define __device_lock_set_class(dev, name, key) \
0924 do { \
0925 struct device *__d2 __maybe_unused = dev; \
0926 lock_set_class(&__d2->mutex.dep_map, name, key, 0, _THIS_IP_); \
0927 } while (0)
0928
0929
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939 #ifdef CONFIG_LOCKDEP
0940 #define device_lock_set_class(dev, key) \
0941 do { \
0942 struct device *__d = dev; \
0943 dev_WARN_ONCE(__d, !lockdep_match_class(&__d->mutex, \
0944 &__lockdep_no_validate__), \
0945 "overriding existing custom lock class\n"); \
0946 __device_lock_set_class(__d, #key, key); \
0947 } while (0)
0948 #else
0949 #define device_lock_set_class(dev, key) __device_lock_set_class(dev, #key, key)
0950 #endif
0951
0952
0953
0954
0955
0956
0957
0958
0959 #define device_lock_reset_class(dev) \
0960 do { \
0961 struct device *__d __maybe_unused = dev; \
0962 lock_set_novalidate_class(&__d->mutex.dep_map, "&dev->mutex", \
0963 _THIS_IP_); \
0964 } while (0)
0965
0966 void lock_device_hotplug(void);
0967 void unlock_device_hotplug(void);
0968 int lock_device_hotplug_sysfs(void);
0969 int device_offline(struct device *dev);
0970 int device_online(struct device *dev);
0971 void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
0972 void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
0973 void device_set_of_node_from_dev(struct device *dev, const struct device *dev2);
0974 void device_set_node(struct device *dev, struct fwnode_handle *fwnode);
0975
0976 static inline int dev_num_vf(struct device *dev)
0977 {
0978 if (dev->bus && dev->bus->num_vf)
0979 return dev->bus->num_vf(dev);
0980 return 0;
0981 }
0982
0983
0984
0985
0986 struct device *__root_device_register(const char *name, struct module *owner);
0987
0988
0989 #define root_device_register(name) \
0990 __root_device_register(name, THIS_MODULE)
0991
0992 void root_device_unregister(struct device *root);
0993
0994 static inline void *dev_get_platdata(const struct device *dev)
0995 {
0996 return dev->platform_data;
0997 }
0998
0999
1000
1001
1002
1003 int __must_check device_driver_attach(struct device_driver *drv,
1004 struct device *dev);
1005 int __must_check device_bind_driver(struct device *dev);
1006 void device_release_driver(struct device *dev);
1007 int __must_check device_attach(struct device *dev);
1008 int __must_check driver_attach(struct device_driver *drv);
1009 void device_initial_probe(struct device *dev);
1010 int __must_check device_reprobe(struct device *dev);
1011
1012 bool device_is_bound(struct device *dev);
1013
1014
1015
1016
1017 __printf(5, 6) struct device *
1018 device_create(struct class *cls, struct device *parent, dev_t devt,
1019 void *drvdata, const char *fmt, ...);
1020 __printf(6, 7) struct device *
1021 device_create_with_groups(struct class *cls, struct device *parent, dev_t devt,
1022 void *drvdata, const struct attribute_group **groups,
1023 const char *fmt, ...);
1024 void device_destroy(struct class *cls, dev_t devt);
1025
1026 int __must_check device_add_groups(struct device *dev,
1027 const struct attribute_group **groups);
1028 void device_remove_groups(struct device *dev,
1029 const struct attribute_group **groups);
1030
1031 static inline int __must_check device_add_group(struct device *dev,
1032 const struct attribute_group *grp)
1033 {
1034 const struct attribute_group *groups[] = { grp, NULL };
1035
1036 return device_add_groups(dev, groups);
1037 }
1038
1039 static inline void device_remove_group(struct device *dev,
1040 const struct attribute_group *grp)
1041 {
1042 const struct attribute_group *groups[] = { grp, NULL };
1043
1044 return device_remove_groups(dev, groups);
1045 }
1046
1047 int __must_check devm_device_add_groups(struct device *dev,
1048 const struct attribute_group **groups);
1049 void devm_device_remove_groups(struct device *dev,
1050 const struct attribute_group **groups);
1051 int __must_check devm_device_add_group(struct device *dev,
1052 const struct attribute_group *grp);
1053 void devm_device_remove_group(struct device *dev,
1054 const struct attribute_group *grp);
1055
1056
1057
1058
1059
1060
1061
1062 extern int (*platform_notify)(struct device *dev);
1063
1064 extern int (*platform_notify_remove)(struct device *dev);
1065
1066
1067
1068
1069
1070
1071 struct device *get_device(struct device *dev);
1072 void put_device(struct device *dev);
1073 bool kill_device(struct device *dev);
1074
1075 #ifdef CONFIG_DEVTMPFS
1076 int devtmpfs_mount(void);
1077 #else
1078 static inline int devtmpfs_mount(void) { return 0; }
1079 #endif
1080
1081
1082 void device_shutdown(void);
1083
1084
1085 const char *dev_driver_string(const struct device *dev);
1086
1087
1088 struct device_link *device_link_add(struct device *consumer,
1089 struct device *supplier, u32 flags);
1090 void device_link_del(struct device_link *link);
1091 void device_link_remove(void *consumer, struct device *supplier);
1092 void device_links_supplier_sync_state_pause(void);
1093 void device_links_supplier_sync_state_resume(void);
1094
1095 extern __printf(3, 4)
1096 int dev_err_probe(const struct device *dev, int err, const char *fmt, ...);
1097
1098
1099 #define MODULE_ALIAS_CHARDEV(major,minor) \
1100 MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
1101 #define MODULE_ALIAS_CHARDEV_MAJOR(major) \
1102 MODULE_ALIAS("char-major-" __stringify(major) "-*")
1103
1104 #ifdef CONFIG_SYSFS_DEPRECATED
1105 extern long sysfs_deprecated;
1106 #else
1107 #define sysfs_deprecated 0
1108 #endif
1109
1110 #endif