at v6.14 44 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * device.h - generic, centralized driver model 4 * 5 * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org> 6 * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de> 7 * Copyright (c) 2008-2009 Novell Inc. 8 * 9 * See Documentation/driver-api/driver-model/ for more information. 10 */ 11 12#ifndef _DEVICE_H_ 13#define _DEVICE_H_ 14 15#include <linux/dev_printk.h> 16#include <linux/energy_model.h> 17#include <linux/ioport.h> 18#include <linux/kobject.h> 19#include <linux/klist.h> 20#include <linux/list.h> 21#include <linux/lockdep.h> 22#include <linux/compiler.h> 23#include <linux/types.h> 24#include <linux/mutex.h> 25#include <linux/pm.h> 26#include <linux/atomic.h> 27#include <linux/uidgid.h> 28#include <linux/gfp.h> 29#include <linux/overflow.h> 30#include <linux/device/bus.h> 31#include <linux/device/class.h> 32#include <linux/device/driver.h> 33#include <linux/cleanup.h> 34#include <asm/device.h> 35 36struct device; 37struct device_private; 38struct device_driver; 39struct driver_private; 40struct module; 41struct class; 42struct subsys_private; 43struct device_node; 44struct fwnode_handle; 45struct iommu_group; 46struct dev_pin_info; 47struct dev_iommu; 48struct msi_device_data; 49 50/** 51 * struct subsys_interface - interfaces to device functions 52 * @name: name of the device function 53 * @subsys: subsystem of the devices to attach to 54 * @node: the list of functions registered at the subsystem 55 * @add_dev: device hookup to device function handler 56 * @remove_dev: device hookup to device function handler 57 * 58 * Simple interfaces attached to a subsystem. Multiple interfaces can 59 * attach to a subsystem and its devices. Unlike drivers, they do not 60 * exclusively claim or control devices. Interfaces usually represent 61 * a specific functionality of a subsystem/class of devices. 62 */ 63struct subsys_interface { 64 const char *name; 65 const struct bus_type *subsys; 66 struct list_head node; 67 int (*add_dev)(struct device *dev, struct subsys_interface *sif); 68 void (*remove_dev)(struct device *dev, struct subsys_interface *sif); 69}; 70 71int subsys_interface_register(struct subsys_interface *sif); 72void subsys_interface_unregister(struct subsys_interface *sif); 73 74int subsys_system_register(const struct bus_type *subsys, 75 const struct attribute_group **groups); 76int subsys_virtual_register(const struct bus_type *subsys, 77 const struct attribute_group **groups); 78 79/* 80 * The type of device, "struct device" is embedded in. A class 81 * or bus can contain devices of different types 82 * like "partitions" and "disks", "mouse" and "event". 83 * This identifies the device type and carries type-specific 84 * information, equivalent to the kobj_type of a kobject. 85 * If "name" is specified, the uevent will contain it in 86 * the DEVTYPE variable. 87 */ 88struct device_type { 89 const char *name; 90 const struct attribute_group **groups; 91 int (*uevent)(const struct device *dev, struct kobj_uevent_env *env); 92 char *(*devnode)(const struct device *dev, umode_t *mode, 93 kuid_t *uid, kgid_t *gid); 94 void (*release)(struct device *dev); 95 96 const struct dev_pm_ops *pm; 97}; 98 99/** 100 * struct device_attribute - Interface for exporting device attributes. 101 * @attr: sysfs attribute definition. 102 * @show: Show handler. 103 * @store: Store handler. 104 */ 105struct device_attribute { 106 struct attribute attr; 107 ssize_t (*show)(struct device *dev, struct device_attribute *attr, 108 char *buf); 109 ssize_t (*store)(struct device *dev, struct device_attribute *attr, 110 const char *buf, size_t count); 111}; 112 113/** 114 * struct dev_ext_attribute - Exported device attribute with extra context. 115 * @attr: Exported device attribute. 116 * @var: Pointer to context. 117 */ 118struct dev_ext_attribute { 119 struct device_attribute attr; 120 void *var; 121}; 122 123ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr, 124 char *buf); 125ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr, 126 const char *buf, size_t count); 127ssize_t device_show_int(struct device *dev, struct device_attribute *attr, 128 char *buf); 129ssize_t device_store_int(struct device *dev, struct device_attribute *attr, 130 const char *buf, size_t count); 131ssize_t device_show_bool(struct device *dev, struct device_attribute *attr, 132 char *buf); 133ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, 134 const char *buf, size_t count); 135ssize_t device_show_string(struct device *dev, struct device_attribute *attr, 136 char *buf); 137 138/** 139 * DEVICE_ATTR - Define a device attribute. 140 * @_name: Attribute name. 141 * @_mode: File mode. 142 * @_show: Show handler. Optional, but mandatory if attribute is readable. 143 * @_store: Store handler. Optional, but mandatory if attribute is writable. 144 * 145 * Convenience macro for defining a struct device_attribute. 146 * 147 * For example, ``DEVICE_ATTR(foo, 0644, foo_show, foo_store);`` expands to: 148 * 149 * .. code-block:: c 150 * 151 * struct device_attribute dev_attr_foo = { 152 * .attr = { .name = "foo", .mode = 0644 }, 153 * .show = foo_show, 154 * .store = foo_store, 155 * }; 156 */ 157#define DEVICE_ATTR(_name, _mode, _show, _store) \ 158 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) 159 160/** 161 * DEVICE_ATTR_PREALLOC - Define a preallocated device attribute. 162 * @_name: Attribute name. 163 * @_mode: File mode. 164 * @_show: Show handler. Optional, but mandatory if attribute is readable. 165 * @_store: Store handler. Optional, but mandatory if attribute is writable. 166 * 167 * Like DEVICE_ATTR(), but ``SYSFS_PREALLOC`` is set on @_mode. 168 */ 169#define DEVICE_ATTR_PREALLOC(_name, _mode, _show, _store) \ 170 struct device_attribute dev_attr_##_name = \ 171 __ATTR_PREALLOC(_name, _mode, _show, _store) 172 173/** 174 * DEVICE_ATTR_RW - Define a read-write device attribute. 175 * @_name: Attribute name. 176 * 177 * Like DEVICE_ATTR(), but @_mode is 0644, @_show is <_name>_show, 178 * and @_store is <_name>_store. 179 */ 180#define DEVICE_ATTR_RW(_name) \ 181 struct device_attribute dev_attr_##_name = __ATTR_RW(_name) 182 183/** 184 * DEVICE_ATTR_ADMIN_RW - Define an admin-only read-write device attribute. 185 * @_name: Attribute name. 186 * 187 * Like DEVICE_ATTR_RW(), but @_mode is 0600. 188 */ 189#define DEVICE_ATTR_ADMIN_RW(_name) \ 190 struct device_attribute dev_attr_##_name = __ATTR_RW_MODE(_name, 0600) 191 192/** 193 * DEVICE_ATTR_RO - Define a readable device attribute. 194 * @_name: Attribute name. 195 * 196 * Like DEVICE_ATTR(), but @_mode is 0444 and @_show is <_name>_show. 197 */ 198#define DEVICE_ATTR_RO(_name) \ 199 struct device_attribute dev_attr_##_name = __ATTR_RO(_name) 200 201/** 202 * DEVICE_ATTR_ADMIN_RO - Define an admin-only readable device attribute. 203 * @_name: Attribute name. 204 * 205 * Like DEVICE_ATTR_RO(), but @_mode is 0400. 206 */ 207#define DEVICE_ATTR_ADMIN_RO(_name) \ 208 struct device_attribute dev_attr_##_name = __ATTR_RO_MODE(_name, 0400) 209 210/** 211 * DEVICE_ATTR_WO - Define an admin-only writable device attribute. 212 * @_name: Attribute name. 213 * 214 * Like DEVICE_ATTR(), but @_mode is 0200 and @_store is <_name>_store. 215 */ 216#define DEVICE_ATTR_WO(_name) \ 217 struct device_attribute dev_attr_##_name = __ATTR_WO(_name) 218 219/** 220 * DEVICE_ULONG_ATTR - Define a device attribute backed by an unsigned long. 221 * @_name: Attribute name. 222 * @_mode: File mode. 223 * @_var: Identifier of unsigned long. 224 * 225 * Like DEVICE_ATTR(), but @_show and @_store are automatically provided 226 * such that reads and writes to the attribute from userspace affect @_var. 227 */ 228#define DEVICE_ULONG_ATTR(_name, _mode, _var) \ 229 struct dev_ext_attribute dev_attr_##_name = \ 230 { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) } 231 232/** 233 * DEVICE_INT_ATTR - Define a device attribute backed by an int. 234 * @_name: Attribute name. 235 * @_mode: File mode. 236 * @_var: Identifier of int. 237 * 238 * Like DEVICE_ULONG_ATTR(), but @_var is an int. 239 */ 240#define DEVICE_INT_ATTR(_name, _mode, _var) \ 241 struct dev_ext_attribute dev_attr_##_name = \ 242 { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) } 243 244/** 245 * DEVICE_BOOL_ATTR - Define a device attribute backed by a bool. 246 * @_name: Attribute name. 247 * @_mode: File mode. 248 * @_var: Identifier of bool. 249 * 250 * Like DEVICE_ULONG_ATTR(), but @_var is a bool. 251 */ 252#define DEVICE_BOOL_ATTR(_name, _mode, _var) \ 253 struct dev_ext_attribute dev_attr_##_name = \ 254 { __ATTR(_name, _mode, device_show_bool, device_store_bool), &(_var) } 255 256/** 257 * DEVICE_STRING_ATTR_RO - Define a device attribute backed by a r/o string. 258 * @_name: Attribute name. 259 * @_mode: File mode. 260 * @_var: Identifier of string. 261 * 262 * Like DEVICE_ULONG_ATTR(), but @_var is a string. Because the length of the 263 * string allocation is unknown, the attribute must be read-only. 264 */ 265#define DEVICE_STRING_ATTR_RO(_name, _mode, _var) \ 266 struct dev_ext_attribute dev_attr_##_name = \ 267 { __ATTR(_name, (_mode) & ~0222, device_show_string, NULL), (_var) } 268 269#define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \ 270 struct device_attribute dev_attr_##_name = \ 271 __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) 272 273int device_create_file(struct device *device, 274 const struct device_attribute *entry); 275void device_remove_file(struct device *dev, 276 const struct device_attribute *attr); 277bool device_remove_file_self(struct device *dev, 278 const struct device_attribute *attr); 279int __must_check device_create_bin_file(struct device *dev, 280 const struct bin_attribute *attr); 281void device_remove_bin_file(struct device *dev, 282 const struct bin_attribute *attr); 283 284/* device resource management */ 285typedef void (*dr_release_t)(struct device *dev, void *res); 286typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); 287 288void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, 289 int nid, const char *name) __malloc; 290#define devres_alloc(release, size, gfp) \ 291 __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release) 292#define devres_alloc_node(release, size, gfp, nid) \ 293 __devres_alloc_node(release, size, gfp, nid, #release) 294 295void devres_for_each_res(struct device *dev, dr_release_t release, 296 dr_match_t match, void *match_data, 297 void (*fn)(struct device *, void *, void *), 298 void *data); 299void devres_free(void *res); 300void devres_add(struct device *dev, void *res); 301void *devres_find(struct device *dev, dr_release_t release, 302 dr_match_t match, void *match_data); 303void *devres_get(struct device *dev, void *new_res, 304 dr_match_t match, void *match_data); 305void *devres_remove(struct device *dev, dr_release_t release, 306 dr_match_t match, void *match_data); 307int devres_destroy(struct device *dev, dr_release_t release, 308 dr_match_t match, void *match_data); 309int devres_release(struct device *dev, dr_release_t release, 310 dr_match_t match, void *match_data); 311 312/* devres group */ 313void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp); 314void devres_close_group(struct device *dev, void *id); 315void devres_remove_group(struct device *dev, void *id); 316int devres_release_group(struct device *dev, void *id); 317 318/* managed devm_k.alloc/kfree for device drivers */ 319void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __alloc_size(2); 320void *devm_krealloc(struct device *dev, void *ptr, size_t size, 321 gfp_t gfp) __must_check __realloc_size(3); 322__printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp, 323 const char *fmt, va_list ap) __malloc; 324__printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp, 325 const char *fmt, ...) __malloc; 326static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) 327{ 328 return devm_kmalloc(dev, size, gfp | __GFP_ZERO); 329} 330static inline void *devm_kmalloc_array(struct device *dev, 331 size_t n, size_t size, gfp_t flags) 332{ 333 size_t bytes; 334 335 if (unlikely(check_mul_overflow(n, size, &bytes))) 336 return NULL; 337 338 return devm_kmalloc(dev, bytes, flags); 339} 340static inline void *devm_kcalloc(struct device *dev, 341 size_t n, size_t size, gfp_t flags) 342{ 343 return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); 344} 345static inline __realloc_size(3, 4) void * __must_check 346devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags) 347{ 348 size_t bytes; 349 350 if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) 351 return NULL; 352 353 return devm_krealloc(dev, p, bytes, flags); 354} 355 356void devm_kfree(struct device *dev, const void *p); 357char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; 358const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); 359void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp) 360 __realloc_size(3); 361 362unsigned long devm_get_free_pages(struct device *dev, 363 gfp_t gfp_mask, unsigned int order); 364void devm_free_pages(struct device *dev, unsigned long addr); 365 366#ifdef CONFIG_HAS_IOMEM 367void __iomem *devm_ioremap_resource(struct device *dev, 368 const struct resource *res); 369void __iomem *devm_ioremap_resource_wc(struct device *dev, 370 const struct resource *res); 371 372void __iomem *devm_of_iomap(struct device *dev, 373 struct device_node *node, int index, 374 resource_size_t *size); 375#else 376 377static inline 378void __iomem *devm_ioremap_resource(struct device *dev, 379 const struct resource *res) 380{ 381 return ERR_PTR(-EINVAL); 382} 383 384static inline 385void __iomem *devm_ioremap_resource_wc(struct device *dev, 386 const struct resource *res) 387{ 388 return ERR_PTR(-EINVAL); 389} 390 391static inline 392void __iomem *devm_of_iomap(struct device *dev, 393 struct device_node *node, int index, 394 resource_size_t *size) 395{ 396 return ERR_PTR(-EINVAL); 397} 398 399#endif 400 401/* allows to add/remove a custom action to devres stack */ 402int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data); 403 404/** 405 * devm_remove_action() - removes previously added custom action 406 * @dev: Device that owns the action 407 * @action: Function implementing the action 408 * @data: Pointer to data passed to @action implementation 409 * 410 * Removes instance of @action previously added by devm_add_action(). 411 * Both action and data should match one of the existing entries. 412 */ 413static inline 414void devm_remove_action(struct device *dev, void (*action)(void *), void *data) 415{ 416 WARN_ON(devm_remove_action_nowarn(dev, action, data)); 417} 418 419void devm_release_action(struct device *dev, void (*action)(void *), void *data); 420 421int __devm_add_action(struct device *dev, void (*action)(void *), void *data, const char *name); 422#define devm_add_action(dev, action, data) \ 423 __devm_add_action(dev, action, data, #action) 424 425static inline int __devm_add_action_or_reset(struct device *dev, void (*action)(void *), 426 void *data, const char *name) 427{ 428 int ret; 429 430 ret = __devm_add_action(dev, action, data, name); 431 if (ret) 432 action(data); 433 434 return ret; 435} 436#define devm_add_action_or_reset(dev, action, data) \ 437 __devm_add_action_or_reset(dev, action, data, #action) 438 439/** 440 * devm_alloc_percpu - Resource-managed alloc_percpu 441 * @dev: Device to allocate per-cpu memory for 442 * @type: Type to allocate per-cpu memory for 443 * 444 * Managed alloc_percpu. Per-cpu memory allocated with this function is 445 * automatically freed on driver detach. 446 * 447 * RETURNS: 448 * Pointer to allocated memory on success, NULL on failure. 449 */ 450#define devm_alloc_percpu(dev, type) \ 451 ((typeof(type) __percpu *)__devm_alloc_percpu((dev), sizeof(type), \ 452 __alignof__(type))) 453 454void __percpu *__devm_alloc_percpu(struct device *dev, size_t size, 455 size_t align); 456void devm_free_percpu(struct device *dev, void __percpu *pdata); 457 458struct device_dma_parameters { 459 /* 460 * a low level driver may set these to teach IOMMU code about 461 * sg limitations. 462 */ 463 unsigned int max_segment_size; 464 unsigned int min_align_mask; 465 unsigned long segment_boundary_mask; 466}; 467 468/** 469 * enum device_link_state - Device link states. 470 * @DL_STATE_NONE: The presence of the drivers is not being tracked. 471 * @DL_STATE_DORMANT: None of the supplier/consumer drivers is present. 472 * @DL_STATE_AVAILABLE: The supplier driver is present, but the consumer is not. 473 * @DL_STATE_CONSUMER_PROBE: The consumer is probing (supplier driver present). 474 * @DL_STATE_ACTIVE: Both the supplier and consumer drivers are present. 475 * @DL_STATE_SUPPLIER_UNBIND: The supplier driver is unbinding. 476 */ 477enum device_link_state { 478 DL_STATE_NONE = -1, 479 DL_STATE_DORMANT = 0, 480 DL_STATE_AVAILABLE, 481 DL_STATE_CONSUMER_PROBE, 482 DL_STATE_ACTIVE, 483 DL_STATE_SUPPLIER_UNBIND, 484}; 485 486/* 487 * Device link flags. 488 * 489 * STATELESS: The core will not remove this link automatically. 490 * AUTOREMOVE_CONSUMER: Remove the link automatically on consumer driver unbind. 491 * PM_RUNTIME: If set, the runtime PM framework will use this link. 492 * RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link creation. 493 * AUTOREMOVE_SUPPLIER: Remove the link automatically on supplier driver unbind. 494 * AUTOPROBE_CONSUMER: Probe consumer driver automatically after supplier binds. 495 * MANAGED: The core tracks presence of supplier/consumer drivers (internal). 496 * SYNC_STATE_ONLY: Link only affects sync_state() behavior. 497 * INFERRED: Inferred from data (eg: firmware) and not from driver actions. 498 */ 499#define DL_FLAG_STATELESS BIT(0) 500#define DL_FLAG_AUTOREMOVE_CONSUMER BIT(1) 501#define DL_FLAG_PM_RUNTIME BIT(2) 502#define DL_FLAG_RPM_ACTIVE BIT(3) 503#define DL_FLAG_AUTOREMOVE_SUPPLIER BIT(4) 504#define DL_FLAG_AUTOPROBE_CONSUMER BIT(5) 505#define DL_FLAG_MANAGED BIT(6) 506#define DL_FLAG_SYNC_STATE_ONLY BIT(7) 507#define DL_FLAG_INFERRED BIT(8) 508#define DL_FLAG_CYCLE BIT(9) 509 510/** 511 * enum dl_dev_state - Device driver presence tracking information. 512 * @DL_DEV_NO_DRIVER: There is no driver attached to the device. 513 * @DL_DEV_PROBING: A driver is probing. 514 * @DL_DEV_DRIVER_BOUND: The driver has been bound to the device. 515 * @DL_DEV_UNBINDING: The driver is unbinding from the device. 516 */ 517enum dl_dev_state { 518 DL_DEV_NO_DRIVER = 0, 519 DL_DEV_PROBING, 520 DL_DEV_DRIVER_BOUND, 521 DL_DEV_UNBINDING, 522}; 523 524/** 525 * enum device_removable - Whether the device is removable. The criteria for a 526 * device to be classified as removable is determined by its subsystem or bus. 527 * @DEVICE_REMOVABLE_NOT_SUPPORTED: This attribute is not supported for this 528 * device (default). 529 * @DEVICE_REMOVABLE_UNKNOWN: Device location is Unknown. 530 * @DEVICE_FIXED: Device is not removable by the user. 531 * @DEVICE_REMOVABLE: Device is removable by the user. 532 */ 533enum device_removable { 534 DEVICE_REMOVABLE_NOT_SUPPORTED = 0, /* must be 0 */ 535 DEVICE_REMOVABLE_UNKNOWN, 536 DEVICE_FIXED, 537 DEVICE_REMOVABLE, 538}; 539 540/** 541 * struct dev_links_info - Device data related to device links. 542 * @suppliers: List of links to supplier devices. 543 * @consumers: List of links to consumer devices. 544 * @defer_sync: Hook to global list of devices that have deferred sync_state. 545 * @status: Driver status information. 546 */ 547struct dev_links_info { 548 struct list_head suppliers; 549 struct list_head consumers; 550 struct list_head defer_sync; 551 enum dl_dev_state status; 552}; 553 554/** 555 * struct dev_msi_info - Device data related to MSI 556 * @domain: The MSI interrupt domain associated to the device 557 * @data: Pointer to MSI device data 558 */ 559struct dev_msi_info { 560#ifdef CONFIG_GENERIC_MSI_IRQ 561 struct irq_domain *domain; 562 struct msi_device_data *data; 563#endif 564}; 565 566/** 567 * enum device_physical_location_panel - Describes which panel surface of the 568 * system's housing the device connection point resides on. 569 * @DEVICE_PANEL_TOP: Device connection point is on the top panel. 570 * @DEVICE_PANEL_BOTTOM: Device connection point is on the bottom panel. 571 * @DEVICE_PANEL_LEFT: Device connection point is on the left panel. 572 * @DEVICE_PANEL_RIGHT: Device connection point is on the right panel. 573 * @DEVICE_PANEL_FRONT: Device connection point is on the front panel. 574 * @DEVICE_PANEL_BACK: Device connection point is on the back panel. 575 * @DEVICE_PANEL_UNKNOWN: The panel with device connection point is unknown. 576 */ 577enum device_physical_location_panel { 578 DEVICE_PANEL_TOP, 579 DEVICE_PANEL_BOTTOM, 580 DEVICE_PANEL_LEFT, 581 DEVICE_PANEL_RIGHT, 582 DEVICE_PANEL_FRONT, 583 DEVICE_PANEL_BACK, 584 DEVICE_PANEL_UNKNOWN, 585}; 586 587/** 588 * enum device_physical_location_vertical_position - Describes vertical 589 * position of the device connection point on the panel surface. 590 * @DEVICE_VERT_POS_UPPER: Device connection point is at upper part of panel. 591 * @DEVICE_VERT_POS_CENTER: Device connection point is at center part of panel. 592 * @DEVICE_VERT_POS_LOWER: Device connection point is at lower part of panel. 593 */ 594enum device_physical_location_vertical_position { 595 DEVICE_VERT_POS_UPPER, 596 DEVICE_VERT_POS_CENTER, 597 DEVICE_VERT_POS_LOWER, 598}; 599 600/** 601 * enum device_physical_location_horizontal_position - Describes horizontal 602 * position of the device connection point on the panel surface. 603 * @DEVICE_HORI_POS_LEFT: Device connection point is at left part of panel. 604 * @DEVICE_HORI_POS_CENTER: Device connection point is at center part of panel. 605 * @DEVICE_HORI_POS_RIGHT: Device connection point is at right part of panel. 606 */ 607enum device_physical_location_horizontal_position { 608 DEVICE_HORI_POS_LEFT, 609 DEVICE_HORI_POS_CENTER, 610 DEVICE_HORI_POS_RIGHT, 611}; 612 613/** 614 * struct device_physical_location - Device data related to physical location 615 * of the device connection point. 616 * @panel: Panel surface of the system's housing that the device connection 617 * point resides on. 618 * @vertical_position: Vertical position of the device connection point within 619 * the panel. 620 * @horizontal_position: Horizontal position of the device connection point 621 * within the panel. 622 * @dock: Set if the device connection point resides in a docking station or 623 * port replicator. 624 * @lid: Set if this device connection point resides on the lid of laptop 625 * system. 626 */ 627struct device_physical_location { 628 enum device_physical_location_panel panel; 629 enum device_physical_location_vertical_position vertical_position; 630 enum device_physical_location_horizontal_position horizontal_position; 631 bool dock; 632 bool lid; 633}; 634 635/** 636 * struct device - The basic device structure 637 * @parent: The device's "parent" device, the device to which it is attached. 638 * In most cases, a parent device is some sort of bus or host 639 * controller. If parent is NULL, the device, is a top-level device, 640 * which is not usually what you want. 641 * @p: Holds the private data of the driver core portions of the device. 642 * See the comment of the struct device_private for detail. 643 * @kobj: A top-level, abstract class from which other classes are derived. 644 * @init_name: Initial name of the device. 645 * @type: The type of device. 646 * This identifies the device type and carries type-specific 647 * information. 648 * @mutex: Mutex to synchronize calls to its driver. 649 * @bus: Type of bus device is on. 650 * @driver: Which driver has allocated this 651 * @platform_data: Platform data specific to the device. 652 * Example: For devices on custom boards, as typical of embedded 653 * and SOC based hardware, Linux often uses platform_data to point 654 * to board-specific structures describing devices and how they 655 * are wired. That can include what ports are available, chip 656 * variants, which GPIO pins act in what additional roles, and so 657 * on. This shrinks the "Board Support Packages" (BSPs) and 658 * minimizes board-specific #ifdefs in drivers. 659 * @driver_data: Private pointer for driver specific info. 660 * @links: Links to suppliers and consumers of this device. 661 * @power: For device power management. 662 * See Documentation/driver-api/pm/devices.rst for details. 663 * @pm_domain: Provide callbacks that are executed during system suspend, 664 * hibernation, system resume and during runtime PM transitions 665 * along with subsystem-level and driver-level callbacks. 666 * @em_pd: device's energy model performance domain 667 * @pins: For device pin management. 668 * See Documentation/driver-api/pin-control.rst for details. 669 * @msi: MSI related data 670 * @numa_node: NUMA node this device is close to. 671 * @dma_ops: DMA mapping operations for this device. 672 * @dma_mask: Dma mask (if dma'ble device). 673 * @coherent_dma_mask: Like dma_mask, but for alloc_coherent mapping as not all 674 * hardware supports 64-bit addresses for consistent allocations 675 * such descriptors. 676 * @bus_dma_limit: Limit of an upstream bridge or bus which imposes a smaller 677 * DMA limit than the device itself supports. 678 * @dma_range_map: map for DMA memory ranges relative to that of RAM 679 * @dma_parms: A low level driver may set these to teach IOMMU code about 680 * segment limitations. 681 * @dma_pools: Dma pools (if dma'ble device). 682 * @dma_mem: Internal for coherent mem override. 683 * @cma_area: Contiguous memory area for dma allocations 684 * @dma_io_tlb_mem: Software IO TLB allocator. Not for driver use. 685 * @dma_io_tlb_pools: List of transient swiotlb memory pools. 686 * @dma_io_tlb_lock: Protects changes to the list of active pools. 687 * @dma_uses_io_tlb: %true if device has used the software IO TLB. 688 * @archdata: For arch-specific additions. 689 * @of_node: Associated device tree node. 690 * @fwnode: Associated device node supplied by platform firmware. 691 * @devt: For creating the sysfs "dev". 692 * @id: device instance 693 * @devres_lock: Spinlock to protect the resource of the device. 694 * @devres_head: The resources list of the device. 695 * @class: The class of the device. 696 * @groups: Optional attribute groups. 697 * @release: Callback to free the device after all references have 698 * gone away. This should be set by the allocator of the 699 * device (i.e. the bus driver that discovered the device). 700 * @iommu_group: IOMMU group the device belongs to. 701 * @iommu: Per device generic IOMMU runtime data 702 * @physical_location: Describes physical location of the device connection 703 * point in the system housing. 704 * @removable: Whether the device can be removed from the system. This 705 * should be set by the subsystem / bus driver that discovered 706 * the device. 707 * 708 * @offline_disabled: If set, the device is permanently online. 709 * @offline: Set after successful invocation of bus type's .offline(). 710 * @of_node_reused: Set if the device-tree node is shared with an ancestor 711 * device. 712 * @state_synced: The hardware state of this device has been synced to match 713 * the software state of this device by calling the driver/bus 714 * sync_state() callback. 715 * @can_match: The device has matched with a driver at least once or it is in 716 * a bus (like AMBA) which can't check for matching drivers until 717 * other devices probe successfully. 718 * @dma_coherent: this particular device is dma coherent, even if the 719 * architecture supports non-coherent devices. 720 * @dma_ops_bypass: If set to %true then the dma_ops are bypassed for the 721 * streaming DMA operations (->map_* / ->unmap_* / ->sync_*), 722 * and optionall (if the coherent mask is large enough) also 723 * for dma allocations. This flag is managed by the dma ops 724 * instance from ->dma_supported. 725 * @dma_skip_sync: DMA sync operations can be skipped for coherent buffers. 726 * @dma_iommu: Device is using default IOMMU implementation for DMA and 727 * doesn't rely on dma_ops structure. 728 * 729 * At the lowest level, every device in a Linux system is represented by an 730 * instance of struct device. The device structure contains the information 731 * that the device model core needs to model the system. Most subsystems, 732 * however, track additional information about the devices they host. As a 733 * result, it is rare for devices to be represented by bare device structures; 734 * instead, that structure, like kobject structures, is usually embedded within 735 * a higher-level representation of the device. 736 */ 737struct device { 738 struct kobject kobj; 739 struct device *parent; 740 741 struct device_private *p; 742 743 const char *init_name; /* initial name of the device */ 744 const struct device_type *type; 745 746 const struct bus_type *bus; /* type of bus device is on */ 747 struct device_driver *driver; /* which driver has allocated this 748 device */ 749 void *platform_data; /* Platform specific data, device 750 core doesn't touch it */ 751 void *driver_data; /* Driver data, set and get with 752 dev_set_drvdata/dev_get_drvdata */ 753 struct mutex mutex; /* mutex to synchronize calls to 754 * its driver. 755 */ 756 757 struct dev_links_info links; 758 struct dev_pm_info power; 759 struct dev_pm_domain *pm_domain; 760 761#ifdef CONFIG_ENERGY_MODEL 762 struct em_perf_domain *em_pd; 763#endif 764 765#ifdef CONFIG_PINCTRL 766 struct dev_pin_info *pins; 767#endif 768 struct dev_msi_info msi; 769#ifdef CONFIG_ARCH_HAS_DMA_OPS 770 const struct dma_map_ops *dma_ops; 771#endif 772 u64 *dma_mask; /* dma mask (if dma'able device) */ 773 u64 coherent_dma_mask;/* Like dma_mask, but for 774 alloc_coherent mappings as 775 not all hardware supports 776 64 bit addresses for consistent 777 allocations such descriptors. */ 778 u64 bus_dma_limit; /* upstream dma constraint */ 779 const struct bus_dma_region *dma_range_map; 780 781 struct device_dma_parameters *dma_parms; 782 783 struct list_head dma_pools; /* dma pools (if dma'ble) */ 784 785#ifdef CONFIG_DMA_DECLARE_COHERENT 786 struct dma_coherent_mem *dma_mem; /* internal for coherent mem 787 override */ 788#endif 789#ifdef CONFIG_DMA_CMA 790 struct cma *cma_area; /* contiguous memory area for dma 791 allocations */ 792#endif 793#ifdef CONFIG_SWIOTLB 794 struct io_tlb_mem *dma_io_tlb_mem; 795#endif 796#ifdef CONFIG_SWIOTLB_DYNAMIC 797 struct list_head dma_io_tlb_pools; 798 spinlock_t dma_io_tlb_lock; 799 bool dma_uses_io_tlb; 800#endif 801 /* arch specific additions */ 802 struct dev_archdata archdata; 803 804 struct device_node *of_node; /* associated device tree node */ 805 struct fwnode_handle *fwnode; /* firmware device node */ 806 807#ifdef CONFIG_NUMA 808 int numa_node; /* NUMA node this device is close to */ 809#endif 810 dev_t devt; /* dev_t, creates the sysfs "dev" */ 811 u32 id; /* device instance */ 812 813 spinlock_t devres_lock; 814 struct list_head devres_head; 815 816 const struct class *class; 817 const struct attribute_group **groups; /* optional groups */ 818 819 void (*release)(struct device *dev); 820 struct iommu_group *iommu_group; 821 struct dev_iommu *iommu; 822 823 struct device_physical_location *physical_location; 824 825 enum device_removable removable; 826 827 bool offline_disabled:1; 828 bool offline:1; 829 bool of_node_reused:1; 830 bool state_synced:1; 831 bool can_match:1; 832#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ 833 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ 834 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) 835 bool dma_coherent:1; 836#endif 837#ifdef CONFIG_DMA_OPS_BYPASS 838 bool dma_ops_bypass : 1; 839#endif 840#ifdef CONFIG_DMA_NEED_SYNC 841 bool dma_skip_sync:1; 842#endif 843#ifdef CONFIG_IOMMU_DMA 844 bool dma_iommu:1; 845#endif 846}; 847 848/** 849 * struct device_link - Device link representation. 850 * @supplier: The device on the supplier end of the link. 851 * @s_node: Hook to the supplier device's list of links to consumers. 852 * @consumer: The device on the consumer end of the link. 853 * @c_node: Hook to the consumer device's list of links to suppliers. 854 * @link_dev: device used to expose link details in sysfs 855 * @status: The state of the link (with respect to the presence of drivers). 856 * @flags: Link flags. 857 * @rpm_active: Whether or not the consumer device is runtime-PM-active. 858 * @kref: Count repeated addition of the same link. 859 * @rm_work: Work structure used for removing the link. 860 * @supplier_preactivated: Supplier has been made active before consumer probe. 861 */ 862struct device_link { 863 struct device *supplier; 864 struct list_head s_node; 865 struct device *consumer; 866 struct list_head c_node; 867 struct device link_dev; 868 enum device_link_state status; 869 u32 flags; 870 refcount_t rpm_active; 871 struct kref kref; 872 struct work_struct rm_work; 873 bool supplier_preactivated; /* Owned by consumer probe. */ 874}; 875 876#define kobj_to_dev(__kobj) container_of_const(__kobj, struct device, kobj) 877 878/** 879 * device_iommu_mapped - Returns true when the device DMA is translated 880 * by an IOMMU 881 * @dev: Device to perform the check on 882 */ 883static inline bool device_iommu_mapped(struct device *dev) 884{ 885 return (dev->iommu_group != NULL); 886} 887 888/* Get the wakeup routines, which depend on struct device */ 889#include <linux/pm_wakeup.h> 890 891/** 892 * dev_name - Return a device's name. 893 * @dev: Device with name to get. 894 * Return: The kobject name of the device, or its initial name if unavailable. 895 */ 896static inline const char *dev_name(const struct device *dev) 897{ 898 /* Use the init name until the kobject becomes available */ 899 if (dev->init_name) 900 return dev->init_name; 901 902 return kobject_name(&dev->kobj); 903} 904 905/** 906 * dev_bus_name - Return a device's bus/class name, if at all possible 907 * @dev: struct device to get the bus/class name of 908 * 909 * Will return the name of the bus/class the device is attached to. If it is 910 * not attached to a bus/class, an empty string will be returned. 911 */ 912static inline const char *dev_bus_name(const struct device *dev) 913{ 914 return dev->bus ? dev->bus->name : (dev->class ? dev->class->name : ""); 915} 916 917__printf(2, 3) int dev_set_name(struct device *dev, const char *name, ...); 918 919#ifdef CONFIG_NUMA 920static inline int dev_to_node(struct device *dev) 921{ 922 return dev->numa_node; 923} 924static inline void set_dev_node(struct device *dev, int node) 925{ 926 dev->numa_node = node; 927} 928#else 929static inline int dev_to_node(struct device *dev) 930{ 931 return NUMA_NO_NODE; 932} 933static inline void set_dev_node(struct device *dev, int node) 934{ 935} 936#endif 937 938static inline struct irq_domain *dev_get_msi_domain(const struct device *dev) 939{ 940#ifdef CONFIG_GENERIC_MSI_IRQ 941 return dev->msi.domain; 942#else 943 return NULL; 944#endif 945} 946 947static inline void dev_set_msi_domain(struct device *dev, struct irq_domain *d) 948{ 949#ifdef CONFIG_GENERIC_MSI_IRQ 950 dev->msi.domain = d; 951#endif 952} 953 954static inline void *dev_get_drvdata(const struct device *dev) 955{ 956 return dev->driver_data; 957} 958 959static inline void dev_set_drvdata(struct device *dev, void *data) 960{ 961 dev->driver_data = data; 962} 963 964static inline struct pm_subsys_data *dev_to_psd(struct device *dev) 965{ 966 return dev ? dev->power.subsys_data : NULL; 967} 968 969static inline unsigned int dev_get_uevent_suppress(const struct device *dev) 970{ 971 return dev->kobj.uevent_suppress; 972} 973 974static inline void dev_set_uevent_suppress(struct device *dev, int val) 975{ 976 dev->kobj.uevent_suppress = val; 977} 978 979static inline int device_is_registered(struct device *dev) 980{ 981 return dev->kobj.state_in_sysfs; 982} 983 984static inline void device_enable_async_suspend(struct device *dev) 985{ 986 if (!dev->power.is_prepared) 987 dev->power.async_suspend = true; 988} 989 990static inline void device_disable_async_suspend(struct device *dev) 991{ 992 if (!dev->power.is_prepared) 993 dev->power.async_suspend = false; 994} 995 996static inline bool device_async_suspend_enabled(struct device *dev) 997{ 998 return !!dev->power.async_suspend; 999} 1000 1001static inline bool device_pm_not_required(struct device *dev) 1002{ 1003 return dev->power.no_pm; 1004} 1005 1006static inline void device_set_pm_not_required(struct device *dev) 1007{ 1008 dev->power.no_pm = true; 1009} 1010 1011static inline void dev_pm_syscore_device(struct device *dev, bool val) 1012{ 1013#ifdef CONFIG_PM_SLEEP 1014 dev->power.syscore = val; 1015#endif 1016} 1017 1018static inline void dev_pm_set_driver_flags(struct device *dev, u32 flags) 1019{ 1020 dev->power.driver_flags = flags; 1021} 1022 1023static inline bool dev_pm_test_driver_flags(struct device *dev, u32 flags) 1024{ 1025 return !!(dev->power.driver_flags & flags); 1026} 1027 1028static inline void device_lock(struct device *dev) 1029{ 1030 mutex_lock(&dev->mutex); 1031} 1032 1033static inline int device_lock_interruptible(struct device *dev) 1034{ 1035 return mutex_lock_interruptible(&dev->mutex); 1036} 1037 1038static inline int device_trylock(struct device *dev) 1039{ 1040 return mutex_trylock(&dev->mutex); 1041} 1042 1043static inline void device_unlock(struct device *dev) 1044{ 1045 mutex_unlock(&dev->mutex); 1046} 1047 1048DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T)) 1049 1050static inline void device_lock_assert(struct device *dev) 1051{ 1052 lockdep_assert_held(&dev->mutex); 1053} 1054 1055static inline bool dev_has_sync_state(struct device *dev) 1056{ 1057 if (!dev) 1058 return false; 1059 if (dev->driver && dev->driver->sync_state) 1060 return true; 1061 if (dev->bus && dev->bus->sync_state) 1062 return true; 1063 return false; 1064} 1065 1066static inline void dev_set_removable(struct device *dev, 1067 enum device_removable removable) 1068{ 1069 dev->removable = removable; 1070} 1071 1072static inline bool dev_is_removable(struct device *dev) 1073{ 1074 return dev->removable == DEVICE_REMOVABLE; 1075} 1076 1077static inline bool dev_removable_is_valid(struct device *dev) 1078{ 1079 return dev->removable != DEVICE_REMOVABLE_NOT_SUPPORTED; 1080} 1081 1082/* 1083 * High level routines for use by the bus drivers 1084 */ 1085int __must_check device_register(struct device *dev); 1086void device_unregister(struct device *dev); 1087void device_initialize(struct device *dev); 1088int __must_check device_add(struct device *dev); 1089void device_del(struct device *dev); 1090 1091DEFINE_FREE(device_del, struct device *, if (_T) device_del(_T)) 1092 1093int device_for_each_child(struct device *parent, void *data, 1094 device_iter_t fn); 1095int device_for_each_child_reverse(struct device *parent, void *data, 1096 device_iter_t fn); 1097int device_for_each_child_reverse_from(struct device *parent, 1098 struct device *from, void *data, 1099 device_iter_t fn); 1100struct device *device_find_child(struct device *parent, const void *data, 1101 device_match_t match); 1102/** 1103 * device_find_child_by_name - device iterator for locating a child device. 1104 * @parent: parent struct device 1105 * @name: name of the child device 1106 * 1107 * This is similar to the device_find_child() function above, but it 1108 * returns a reference to a device that has the name @name. 1109 * 1110 * NOTE: you will need to drop the reference with put_device() after use. 1111 */ 1112static inline struct device *device_find_child_by_name(struct device *parent, 1113 const char *name) 1114{ 1115 return device_find_child(parent, name, device_match_name); 1116} 1117 1118/** 1119 * device_find_any_child - device iterator for locating a child device, if any. 1120 * @parent: parent struct device 1121 * 1122 * This is similar to the device_find_child() function above, but it 1123 * returns a reference to a child device, if any. 1124 * 1125 * NOTE: you will need to drop the reference with put_device() after use. 1126 */ 1127static inline struct device *device_find_any_child(struct device *parent) 1128{ 1129 return device_find_child(parent, NULL, device_match_any); 1130} 1131 1132int device_rename(struct device *dev, const char *new_name); 1133int device_move(struct device *dev, struct device *new_parent, 1134 enum dpm_order dpm_order); 1135int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid); 1136 1137static inline bool device_supports_offline(struct device *dev) 1138{ 1139 return dev->bus && dev->bus->offline && dev->bus->online; 1140} 1141 1142#define __device_lock_set_class(dev, name, key) \ 1143do { \ 1144 struct device *__d2 __maybe_unused = dev; \ 1145 lock_set_class(&__d2->mutex.dep_map, name, key, 0, _THIS_IP_); \ 1146} while (0) 1147 1148/** 1149 * device_lock_set_class - Specify a temporary lock class while a device 1150 * is attached to a driver 1151 * @dev: device to modify 1152 * @key: lock class key data 1153 * 1154 * This must be called with the device_lock() already held, for example 1155 * from driver ->probe(). Take care to only override the default 1156 * lockdep_no_validate class. 1157 */ 1158#ifdef CONFIG_LOCKDEP 1159#define device_lock_set_class(dev, key) \ 1160do { \ 1161 struct device *__d = dev; \ 1162 dev_WARN_ONCE(__d, !lockdep_match_class(&__d->mutex, \ 1163 &__lockdep_no_validate__), \ 1164 "overriding existing custom lock class\n"); \ 1165 __device_lock_set_class(__d, #key, key); \ 1166} while (0) 1167#else 1168#define device_lock_set_class(dev, key) __device_lock_set_class(dev, #key, key) 1169#endif 1170 1171/** 1172 * device_lock_reset_class - Return a device to the default lockdep novalidate state 1173 * @dev: device to modify 1174 * 1175 * This must be called with the device_lock() already held, for example 1176 * from driver ->remove(). 1177 */ 1178#define device_lock_reset_class(dev) \ 1179do { \ 1180 struct device *__d __maybe_unused = dev; \ 1181 lock_set_novalidate_class(&__d->mutex.dep_map, "&dev->mutex", \ 1182 _THIS_IP_); \ 1183} while (0) 1184 1185void lock_device_hotplug(void); 1186void unlock_device_hotplug(void); 1187int lock_device_hotplug_sysfs(void); 1188int device_offline(struct device *dev); 1189int device_online(struct device *dev); 1190 1191void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode); 1192void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode); 1193void device_set_node(struct device *dev, struct fwnode_handle *fwnode); 1194void device_set_of_node_from_dev(struct device *dev, const struct device *dev2); 1195 1196static inline struct device_node *dev_of_node(struct device *dev) 1197{ 1198 if (!IS_ENABLED(CONFIG_OF) || !dev) 1199 return NULL; 1200 return dev->of_node; 1201} 1202 1203static inline int dev_num_vf(struct device *dev) 1204{ 1205 if (dev->bus && dev->bus->num_vf) 1206 return dev->bus->num_vf(dev); 1207 return 0; 1208} 1209 1210/* 1211 * Root device objects for grouping under /sys/devices 1212 */ 1213struct device *__root_device_register(const char *name, struct module *owner); 1214 1215/* This is a macro to avoid include problems with THIS_MODULE */ 1216#define root_device_register(name) \ 1217 __root_device_register(name, THIS_MODULE) 1218 1219void root_device_unregister(struct device *root); 1220 1221static inline void *dev_get_platdata(const struct device *dev) 1222{ 1223 return dev->platform_data; 1224} 1225 1226/* 1227 * Manual binding of a device to driver. See drivers/base/bus.c 1228 * for information on use. 1229 */ 1230int __must_check device_driver_attach(const struct device_driver *drv, 1231 struct device *dev); 1232int __must_check device_bind_driver(struct device *dev); 1233void device_release_driver(struct device *dev); 1234int __must_check device_attach(struct device *dev); 1235int __must_check driver_attach(const struct device_driver *drv); 1236void device_initial_probe(struct device *dev); 1237int __must_check device_reprobe(struct device *dev); 1238 1239bool device_is_bound(struct device *dev); 1240 1241/* 1242 * Easy functions for dynamically creating devices on the fly 1243 */ 1244__printf(5, 6) struct device * 1245device_create(const struct class *cls, struct device *parent, dev_t devt, 1246 void *drvdata, const char *fmt, ...); 1247__printf(6, 7) struct device * 1248device_create_with_groups(const struct class *cls, struct device *parent, dev_t devt, 1249 void *drvdata, const struct attribute_group **groups, 1250 const char *fmt, ...); 1251void device_destroy(const struct class *cls, dev_t devt); 1252 1253int __must_check device_add_groups(struct device *dev, 1254 const struct attribute_group **groups); 1255void device_remove_groups(struct device *dev, 1256 const struct attribute_group **groups); 1257 1258static inline int __must_check device_add_group(struct device *dev, 1259 const struct attribute_group *grp) 1260{ 1261 const struct attribute_group *groups[] = { grp, NULL }; 1262 1263 return device_add_groups(dev, groups); 1264} 1265 1266static inline void device_remove_group(struct device *dev, 1267 const struct attribute_group *grp) 1268{ 1269 const struct attribute_group *groups[] = { grp, NULL }; 1270 1271 return device_remove_groups(dev, groups); 1272} 1273 1274int __must_check devm_device_add_group(struct device *dev, 1275 const struct attribute_group *grp); 1276 1277/* 1278 * get_device - atomically increment the reference count for the device. 1279 * 1280 */ 1281struct device *get_device(struct device *dev); 1282void put_device(struct device *dev); 1283 1284DEFINE_FREE(put_device, struct device *, if (_T) put_device(_T)) 1285 1286bool kill_device(struct device *dev); 1287 1288#ifdef CONFIG_DEVTMPFS 1289int devtmpfs_mount(void); 1290#else 1291static inline int devtmpfs_mount(void) { return 0; } 1292#endif 1293 1294/* drivers/base/power/shutdown.c */ 1295void device_shutdown(void); 1296 1297/* debugging and troubleshooting/diagnostic helpers. */ 1298const char *dev_driver_string(const struct device *dev); 1299 1300/* Device links interface. */ 1301struct device_link *device_link_add(struct device *consumer, 1302 struct device *supplier, u32 flags); 1303void device_link_del(struct device_link *link); 1304void device_link_remove(void *consumer, struct device *supplier); 1305void device_links_supplier_sync_state_pause(void); 1306void device_links_supplier_sync_state_resume(void); 1307void device_link_wait_removal(void); 1308 1309/* Create alias, so I can be autoloaded. */ 1310#define MODULE_ALIAS_CHARDEV(major,minor) \ 1311 MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor)) 1312#define MODULE_ALIAS_CHARDEV_MAJOR(major) \ 1313 MODULE_ALIAS("char-major-" __stringify(major) "-*") 1314 1315#endif /* _DEVICE_H_ */