Merge tag 'pci-v6.16-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci
[linux-block.git] / include / linux / device.h
CommitLineData
989d42e8 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/*
3 * device.h - generic, centralized driver model
4 *
5 * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
b4028437
GKH
6 * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de>
7 * Copyright (c) 2008-2009 Novell Inc.
1da177e4 8 *
fe34c89d 9 * See Documentation/driver-api/driver-model/ for more information.
1da177e4
LT
10 */
11
12#ifndef _DEVICE_H_
13#define _DEVICE_H_
14
af628aae 15#include <linux/dev_printk.h>
1bc138c6 16#include <linux/energy_model.h>
1da177e4
LT
17#include <linux/ioport.h>
18#include <linux/kobject.h>
465c7a3a 19#include <linux/klist.h>
1da177e4 20#include <linux/list.h>
d2a3b914 21#include <linux/lockdep.h>
4a7fb636 22#include <linux/compiler.h>
1da177e4 23#include <linux/types.h>
de477254 24#include <linux/mutex.h>
1da177e4 25#include <linux/pm.h>
60063497 26#include <linux/atomic.h>
3c2670e6 27#include <linux/uidgid.h>
64c862a8 28#include <linux/gfp.h>
5aee2bf2 29#include <linux/device/bus.h>
a8ae6085 30#include <linux/device/class.h>
a21cad93 31#include <linux/device/devres.h>
4c002c97 32#include <linux/device/driver.h>
54da6a09 33#include <linux/cleanup.h>
c6dbaef2 34#include <asm/device.h>
1da177e4 35
1da177e4 36struct device;
fb069a5d 37struct device_private;
1da177e4 38struct device_driver;
e5dd1278 39struct driver_private;
de477254 40struct module;
1da177e4 41struct class;
6b6e39a6 42struct subsys_private;
d706c1b0 43struct device_node;
ce793486 44struct fwnode_handle;
74416e1e 45struct iommu_group;
23c35f48 46struct dev_pin_info;
045a7042 47struct dev_iommu;
013bd8e5 48struct msi_device_data;
b8c5cec2 49
ca22e56d
KS
50/**
51 * struct subsys_interface - interfaces to device functions
2eda013f 52 * @name: name of the device function
5dd5f934 53 * @subsys: subsystem of the devices to attach to
2eda013f
RD
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
ca22e56d
KS
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;
32f78abe 65 const struct bus_type *subsys;
ca22e56d
KS
66 struct list_head node;
67 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
71db87ba 68 void (*remove_dev)(struct device *dev, struct subsys_interface *sif);
ca22e56d
KS
69};
70
71int subsys_interface_register(struct subsys_interface *sif);
72void subsys_interface_unregister(struct subsys_interface *sif);
73
32f78abe 74int subsys_system_register(const struct bus_type *subsys,
ca22e56d 75 const struct attribute_group **groups);
32f78abe 76int subsys_virtual_register(const struct bus_type *subsys,
d73ce004 77 const struct attribute_group **groups);
ca22e56d 78
414264f9
KS
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 */
f9f852df 88struct device_type {
414264f9 89 const char *name;
a4dbd674 90 const struct attribute_group **groups;
162736b0 91 int (*uevent)(const struct device *dev, struct kobj_uevent_env *env);
a9b12f8b 92 char *(*devnode)(const struct device *dev, umode_t *mode,
4e4098a3 93 kuid_t *uid, kgid_t *gid);
f9f852df 94 void (*release)(struct device *dev);
1eede070 95
8150f32b 96 const struct dev_pm_ops *pm;
f9f852df
KS
97};
98
cd00bc2c
JS
99/**
100 * struct device_attribute - Interface for exporting device attributes.
101 * @attr: sysfs attribute definition.
102 * @show: Show handler.
103 * @store: Store handler.
104 */
a7fd6706
KS
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
cd00bc2c
JS
113/**
114 * struct dev_ext_attribute - Exported device attribute with extra context.
115 * @attr: Exported device attribute.
116 * @var: Pointer to context.
117 */
ca22e56d
KS
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);
91872392
BP
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);
3cc50d07
LW
135ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
136 char *buf);
a7fd6706 137
cd00bc2c
JS
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 */
d462943a 157#define DEVICE_ATTR(_name, _mode, _show, _store) \
ca22e56d 158 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
cd00bc2c
JS
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 */
7fda9100
CL
169#define DEVICE_ATTR_PREALLOC(_name, _mode, _show, _store) \
170 struct device_attribute dev_attr_##_name = \
171 __ATTR_PREALLOC(_name, _mode, _show, _store)
cd00bc2c
JS
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 */
ced321bf
GKH
180#define DEVICE_ATTR_RW(_name) \
181 struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
cd00bc2c
JS
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 */
3022c6a1
DW
189#define DEVICE_ATTR_ADMIN_RW(_name) \
190 struct device_attribute dev_attr_##_name = __ATTR_RW_MODE(_name, 0600)
cd00bc2c
JS
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 */
ced321bf
GKH
198#define DEVICE_ATTR_RO(_name) \
199 struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
cd00bc2c
JS
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 */
3022c6a1
DW
207#define DEVICE_ATTR_ADMIN_RO(_name) \
208 struct device_attribute dev_attr_##_name = __ATTR_RO_MODE(_name, 0400)
cd00bc2c
JS
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 */
1130c55c
GKH
216#define DEVICE_ATTR_WO(_name) \
217 struct device_attribute dev_attr_##_name = __ATTR_WO(_name)
cd00bc2c
JS
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 */
ca22e56d
KS
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) }
cd00bc2c
JS
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 */
ca22e56d
KS
240#define DEVICE_INT_ATTR(_name, _mode, _var) \
241 struct dev_ext_attribute dev_attr_##_name = \
94758185 242 { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) }
cd00bc2c
JS
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 */
91872392
BP
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) }
cd00bc2c 255
3cc50d07
LW
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
356c05d5
AS
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)
a7fd6706 272
67dd0772
BG
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,
66ecb92b 280 const struct bin_attribute *attr);
67dd0772
BG
281void device_remove_bin_file(struct device *dev,
282 const struct bin_attribute *attr);
9ac7849e 283
ff86aae3
MB
284/**
285 * devm_alloc_percpu - Resource-managed alloc_percpu
286 * @dev: Device to allocate per-cpu memory for
287 * @type: Type to allocate per-cpu memory for
288 *
289 * Managed alloc_percpu. Per-cpu memory allocated with this function is
290 * automatically freed on driver detach.
291 *
292 * RETURNS:
293 * Pointer to allocated memory on success, NULL on failure.
294 */
295#define devm_alloc_percpu(dev, type) \
296 ((typeof(type) __percpu *)__devm_alloc_percpu((dev), sizeof(type), \
297 __alignof__(type)))
298
299void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
300 size_t align);
301void devm_free_percpu(struct device *dev, void __percpu *pdata);
302
6b7b6510
FT
303struct device_dma_parameters {
304 /*
305 * a low level driver may set these to teach IOMMU code about
306 * sg limitations.
307 */
308 unsigned int max_segment_size;
36950f2d 309 unsigned int min_align_mask;
6b7b6510
FT
310 unsigned long segment_boundary_mask;
311};
312
9ed98953
RW
313/**
314 * enum device_link_state - Device link states.
315 * @DL_STATE_NONE: The presence of the drivers is not being tracked.
316 * @DL_STATE_DORMANT: None of the supplier/consumer drivers is present.
317 * @DL_STATE_AVAILABLE: The supplier driver is present, but the consumer is not.
318 * @DL_STATE_CONSUMER_PROBE: The consumer is probing (supplier driver present).
319 * @DL_STATE_ACTIVE: Both the supplier and consumer drivers are present.
320 * @DL_STATE_SUPPLIER_UNBIND: The supplier driver is unbinding.
321 */
322enum device_link_state {
323 DL_STATE_NONE = -1,
324 DL_STATE_DORMANT = 0,
325 DL_STATE_AVAILABLE,
326 DL_STATE_CONSUMER_PROBE,
327 DL_STATE_ACTIVE,
328 DL_STATE_SUPPLIER_UNBIND,
329};
330
331/*
332 * Device link flags.
333 *
515db266 334 * STATELESS: The core will not remove this link automatically.
e88728f4 335 * AUTOREMOVE_CONSUMER: Remove the link automatically on consumer driver unbind.
21d5c57b
RW
336 * PM_RUNTIME: If set, the runtime PM framework will use this link.
337 * RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link creation.
1689cac5 338 * AUTOREMOVE_SUPPLIER: Remove the link automatically on supplier driver unbind.
e7dd4010 339 * AUTOPROBE_CONSUMER: Probe consumer driver automatically after supplier binds.
515db266 340 * MANAGED: The core tracks presence of supplier/consumer drivers (internal).
05ef983e 341 * SYNC_STATE_ONLY: Link only affects sync_state() behavior.
4b9bbb29 342 * INFERRED: Inferred from data (eg: firmware) and not from driver actions.
9ed98953 343 */
e88728f4
VG
344#define DL_FLAG_STATELESS BIT(0)
345#define DL_FLAG_AUTOREMOVE_CONSUMER BIT(1)
346#define DL_FLAG_PM_RUNTIME BIT(2)
347#define DL_FLAG_RPM_ACTIVE BIT(3)
1689cac5 348#define DL_FLAG_AUTOREMOVE_SUPPLIER BIT(4)
e7dd4010 349#define DL_FLAG_AUTOPROBE_CONSUMER BIT(5)
515db266 350#define DL_FLAG_MANAGED BIT(6)
05ef983e 351#define DL_FLAG_SYNC_STATE_ONLY BIT(7)
4b9bbb29 352#define DL_FLAG_INFERRED BIT(8)
67cad5c6 353#define DL_FLAG_CYCLE BIT(9)
9ed98953 354
9ed98953
RW
355/**
356 * enum dl_dev_state - Device driver presence tracking information.
357 * @DL_DEV_NO_DRIVER: There is no driver attached to the device.
358 * @DL_DEV_PROBING: A driver is probing.
359 * @DL_DEV_DRIVER_BOUND: The driver has been bound to the device.
360 * @DL_DEV_UNBINDING: The driver is unbinding from the device.
361 */
362enum dl_dev_state {
363 DL_DEV_NO_DRIVER = 0,
364 DL_DEV_PROBING,
365 DL_DEV_DRIVER_BOUND,
366 DL_DEV_UNBINDING,
367};
368
70f400d4
RJ
369/**
370 * enum device_removable - Whether the device is removable. The criteria for a
371 * device to be classified as removable is determined by its subsystem or bus.
372 * @DEVICE_REMOVABLE_NOT_SUPPORTED: This attribute is not supported for this
373 * device (default).
374 * @DEVICE_REMOVABLE_UNKNOWN: Device location is Unknown.
375 * @DEVICE_FIXED: Device is not removable by the user.
376 * @DEVICE_REMOVABLE: Device is removable by the user.
377 */
378enum device_removable {
379 DEVICE_REMOVABLE_NOT_SUPPORTED = 0, /* must be 0 */
380 DEVICE_REMOVABLE_UNKNOWN,
381 DEVICE_FIXED,
382 DEVICE_REMOVABLE,
383};
384
9ed98953
RW
385/**
386 * struct dev_links_info - Device data related to device links.
387 * @suppliers: List of links to supplier devices.
388 * @consumers: List of links to consumer devices.
3b052a3e 389 * @defer_sync: Hook to global list of devices that have deferred sync_state.
9ed98953
RW
390 * @status: Driver status information.
391 */
392struct dev_links_info {
393 struct list_head suppliers;
394 struct list_head consumers;
3b052a3e 395 struct list_head defer_sync;
9ed98953
RW
396 enum dl_dev_state status;
397};
398
34fff628
TG
399/**
400 * struct dev_msi_info - Device data related to MSI
401 * @domain: The MSI interrupt domain associated to the device
013bd8e5 402 * @data: Pointer to MSI device data
34fff628
TG
403 */
404struct dev_msi_info {
013bd8e5 405#ifdef CONFIG_GENERIC_MSI_IRQ
13e7accb 406 struct irq_domain *domain;
013bd8e5
TG
407 struct msi_device_data *data;
408#endif
34fff628
TG
409};
410
6423d295
WC
411/**
412 * enum device_physical_location_panel - Describes which panel surface of the
413 * system's housing the device connection point resides on.
414 * @DEVICE_PANEL_TOP: Device connection point is on the top panel.
415 * @DEVICE_PANEL_BOTTOM: Device connection point is on the bottom panel.
416 * @DEVICE_PANEL_LEFT: Device connection point is on the left panel.
417 * @DEVICE_PANEL_RIGHT: Device connection point is on the right panel.
418 * @DEVICE_PANEL_FRONT: Device connection point is on the front panel.
419 * @DEVICE_PANEL_BACK: Device connection point is on the back panel.
420 * @DEVICE_PANEL_UNKNOWN: The panel with device connection point is unknown.
421 */
422enum device_physical_location_panel {
423 DEVICE_PANEL_TOP,
424 DEVICE_PANEL_BOTTOM,
425 DEVICE_PANEL_LEFT,
426 DEVICE_PANEL_RIGHT,
427 DEVICE_PANEL_FRONT,
428 DEVICE_PANEL_BACK,
429 DEVICE_PANEL_UNKNOWN,
430};
431
432/**
433 * enum device_physical_location_vertical_position - Describes vertical
434 * position of the device connection point on the panel surface.
435 * @DEVICE_VERT_POS_UPPER: Device connection point is at upper part of panel.
436 * @DEVICE_VERT_POS_CENTER: Device connection point is at center part of panel.
437 * @DEVICE_VERT_POS_LOWER: Device connection point is at lower part of panel.
438 */
439enum device_physical_location_vertical_position {
440 DEVICE_VERT_POS_UPPER,
441 DEVICE_VERT_POS_CENTER,
442 DEVICE_VERT_POS_LOWER,
443};
444
445/**
446 * enum device_physical_location_horizontal_position - Describes horizontal
447 * position of the device connection point on the panel surface.
448 * @DEVICE_HORI_POS_LEFT: Device connection point is at left part of panel.
449 * @DEVICE_HORI_POS_CENTER: Device connection point is at center part of panel.
450 * @DEVICE_HORI_POS_RIGHT: Device connection point is at right part of panel.
451 */
452enum device_physical_location_horizontal_position {
453 DEVICE_HORI_POS_LEFT,
454 DEVICE_HORI_POS_CENTER,
455 DEVICE_HORI_POS_RIGHT,
456};
457
458/**
459 * struct device_physical_location - Device data related to physical location
460 * of the device connection point.
461 * @panel: Panel surface of the system's housing that the device connection
462 * point resides on.
463 * @vertical_position: Vertical position of the device connection point within
464 * the panel.
465 * @horizontal_position: Horizontal position of the device connection point
466 * within the panel.
467 * @dock: Set if the device connection point resides in a docking station or
468 * port replicator.
469 * @lid: Set if this device connection point resides on the lid of laptop
470 * system.
471 */
472struct device_physical_location {
473 enum device_physical_location_panel panel;
474 enum device_physical_location_vertical_position vertical_position;
475 enum device_physical_location_horizontal_position horizontal_position;
476 bool dock;
477 bool lid;
478};
479
880ffb5c
WG
480/**
481 * struct device - The basic device structure
482 * @parent: The device's "parent" device, the device to which it is attached.
483 * In most cases, a parent device is some sort of bus or host
484 * controller. If parent is NULL, the device, is a top-level device,
485 * which is not usually what you want.
486 * @p: Holds the private data of the driver core portions of the device.
487 * See the comment of the struct device_private for detail.
488 * @kobj: A top-level, abstract class from which other classes are derived.
489 * @init_name: Initial name of the device.
490 * @type: The type of device.
491 * This identifies the device type and carries type-specific
492 * information.
493 * @mutex: Mutex to synchronize calls to its driver.
494 * @bus: Type of bus device is on.
495 * @driver: Which driver has allocated this
496 * @platform_data: Platform data specific to the device.
497 * Example: For devices on custom boards, as typical of embedded
498 * and SOC based hardware, Linux often uses platform_data to point
499 * to board-specific structures describing devices and how they
500 * are wired. That can include what ports are available, chip
501 * variants, which GPIO pins act in what additional roles, and so
502 * on. This shrinks the "Board Support Packages" (BSPs) and
503 * minimizes board-specific #ifdefs in drivers.
1bb6c08a 504 * @driver_data: Private pointer for driver specific info.
64df1148 505 * @links: Links to suppliers and consumers of this device.
880ffb5c 506 * @power: For device power management.
74378c5c 507 * See Documentation/driver-api/pm/devices.rst for details.
564b905a 508 * @pm_domain: Provide callbacks that are executed during system suspend,
880ffb5c
WG
509 * hibernation, system resume and during runtime PM transitions
510 * along with subsystem-level and driver-level callbacks.
95035eac 511 * @em_pd: device's energy model performance domain
ab78029e 512 * @pins: For device pin management.
4b0c9948 513 * See Documentation/driver-api/pin-control.rst for details.
34fff628 514 * @msi: MSI related data
880ffb5c 515 * @numa_node: NUMA node this device is close to.
6a7a8176 516 * @dma_ops: DMA mapping operations for this device.
880ffb5c
WG
517 * @dma_mask: Dma mask (if dma'ble device).
518 * @coherent_dma_mask: Like dma_mask, but for alloc_coherent mapping as not all
519 * hardware supports 64-bit addresses for consistent allocations
520 * such descriptors.
a7ba70f1
NSJ
521 * @bus_dma_limit: Limit of an upstream bridge or bus which imposes a smaller
522 * DMA limit than the device itself supports.
e0d07278 523 * @dma_range_map: map for DMA memory ranges relative to that of RAM
880ffb5c
WG
524 * @dma_parms: A low level driver may set these to teach IOMMU code about
525 * segment limitations.
526 * @dma_pools: Dma pools (if dma'ble device).
527 * @dma_mem: Internal for coherent mem override.
bfd63cd2 528 * @cma_area: Contiguous memory area for dma allocations
158dbe9c 529 * @dma_io_tlb_mem: Software IO TLB allocator. Not for driver use.
79636caa
PT
530 * @dma_io_tlb_pools: List of transient swiotlb memory pools.
531 * @dma_io_tlb_lock: Protects changes to the list of active pools.
1395706a 532 * @dma_uses_io_tlb: %true if device has used the software IO TLB.
880ffb5c
WG
533 * @archdata: For arch-specific additions.
534 * @of_node: Associated device tree node.
ce793486 535 * @fwnode: Associated device node supplied by platform firmware.
880ffb5c 536 * @devt: For creating the sysfs "dev".
2eda013f 537 * @id: device instance
880ffb5c
WG
538 * @devres_lock: Spinlock to protect the resource of the device.
539 * @devres_head: The resources list of the device.
880ffb5c
WG
540 * @class: The class of the device.
541 * @groups: Optional attribute groups.
542 * @release: Callback to free the device after all references have
543 * gone away. This should be set by the allocator of the
544 * device (i.e. the bus driver that discovered the device).
bfd63cd2 545 * @iommu_group: IOMMU group the device belongs to.
045a7042 546 * @iommu: Per device generic IOMMU runtime data
6423d295
WC
547 * @physical_location: Describes physical location of the device connection
548 * point in the system housing.
70f400d4
RJ
549 * @removable: Whether the device can be removed from the system. This
550 * should be set by the subsystem / bus driver that discovered
551 * the device.
880ffb5c 552 *
4f3549d7
RW
553 * @offline_disabled: If set, the device is permanently online.
554 * @offline: Set after successful invocation of bus type's .offline().
4e75e1d7
JH
555 * @of_node_reused: Set if the device-tree node is shared with an ancestor
556 * device.
fc5a251d
SK
557 * @state_synced: The hardware state of this device has been synced to match
558 * the software state of this device by calling the driver/bus
559 * sync_state() callback.
f2db85b6
SK
560 * @can_match: The device has matched with a driver at least once or it is in
561 * a bus (like AMBA) which can't check for matching drivers until
562 * other devices probe successfully.
f3ecc0ff
CH
563 * @dma_coherent: this particular device is dma coherent, even if the
564 * architecture supports non-coherent devices.
d35834c6
CH
565 * @dma_ops_bypass: If set to %true then the dma_ops are bypassed for the
566 * streaming DMA operations (->map_* / ->unmap_* / ->sync_*),
567 * and optionall (if the coherent mask is large enough) also
568 * for dma allocations. This flag is managed by the dma ops
569 * instance from ->dma_supported.
a6016aac 570 * @dma_skip_sync: DMA sync operations can be skipped for coherent buffers.
b5c58b2f
LR
571 * @dma_iommu: Device is using default IOMMU implementation for DMA and
572 * doesn't rely on dma_ops structure.
880ffb5c
WG
573 *
574 * At the lowest level, every device in a Linux system is represented by an
575 * instance of struct device. The device structure contains the information
576 * that the device model core needs to model the system. Most subsystems,
577 * however, track additional information about the devices they host. As a
578 * result, it is rare for devices to be represented by bare device structures;
579 * instead, that structure, like kobject structures, is usually embedded within
580 * a higher-level representation of the device.
581 */
1da177e4 582struct device {
159ef31e 583 struct kobject kobj;
49a4ec18 584 struct device *parent;
1da177e4 585
fb069a5d
GKH
586 struct device_private *p;
587
c906a48a 588 const char *init_name; /* initial name of the device */
aed65af1 589 const struct device_type *type;
1da177e4 590
d492cc25 591 const struct bus_type *bus; /* type of bus device is on */
1da177e4
LT
592 struct device_driver *driver; /* which driver has allocated this
593 device */
e67c8562
GKH
594 void *platform_data; /* Platform specific data, device
595 core doesn't touch it */
1bb6c08a 596 void *driver_data; /* Driver data, set and get with
2c6f4fc8 597 dev_set_drvdata/dev_get_drvdata */
159ef31e
GKH
598 struct mutex mutex; /* mutex to synchronize calls to
599 * its driver.
600 */
601
9ed98953 602 struct dev_links_info links;
1da177e4 603 struct dev_pm_info power;
564b905a 604 struct dev_pm_domain *pm_domain;
1da177e4 605
1bc138c6
LL
606#ifdef CONFIG_ENERGY_MODEL
607 struct em_perf_domain *em_pd;
608#endif
609
ab78029e
LW
610#ifdef CONFIG_PINCTRL
611 struct dev_pin_info *pins;
612#endif
34fff628 613 struct dev_msi_info msi;
de6c85bf 614#ifdef CONFIG_ARCH_HAS_DMA_OPS
5657933d 615 const struct dma_map_ops *dma_ops;
2f9237d4 616#endif
1da177e4
LT
617 u64 *dma_mask; /* dma mask (if dma'able device) */
618 u64 coherent_dma_mask;/* Like dma_mask, but for
619 alloc_coherent mappings as
620 not all hardware supports
621 64 bit addresses for consistent
622 allocations such descriptors. */
a7ba70f1 623 u64 bus_dma_limit; /* upstream dma constraint */
e0d07278 624 const struct bus_dma_region *dma_range_map;
1da177e4 625
6b7b6510
FT
626 struct device_dma_parameters *dma_parms;
627
1da177e4
LT
628 struct list_head dma_pools; /* dma pools (if dma'ble) */
629
ff4c25f2 630#ifdef CONFIG_DMA_DECLARE_COHERENT
1da177e4
LT
631 struct dma_coherent_mem *dma_mem; /* internal for coherent mem
632 override */
2b281296 633#endif
a2547380 634#ifdef CONFIG_DMA_CMA
c64be2bb
MS
635 struct cma *cma_area; /* contiguous memory area for dma
636 allocations */
69031f50
CC
637#endif
638#ifdef CONFIG_SWIOTLB
639 struct io_tlb_mem *dma_io_tlb_mem;
79636caa
PT
640#endif
641#ifdef CONFIG_SWIOTLB_DYNAMIC
642 struct list_head dma_io_tlb_pools;
643 spinlock_t dma_io_tlb_lock;
1395706a 644 bool dma_uses_io_tlb;
c64be2bb 645#endif
c6dbaef2
BH
646 /* arch specific additions */
647 struct dev_archdata archdata;
c9e358df
GL
648
649 struct device_node *of_node; /* associated device tree node */
ce793486 650 struct fwnode_handle *fwnode; /* firmware device node */
1da177e4 651
159ef31e
GKH
652#ifdef CONFIG_NUMA
653 int numa_node; /* NUMA node this device is close to */
654#endif
929d2fa5 655 dev_t devt; /* dev_t, creates the sysfs "dev" */
ca22e56d 656 u32 id; /* device instance */
929d2fa5 657
9ac7849e
TH
658 spinlock_t devres_lock;
659 struct list_head devres_head;
660
9fa120fb 661 const struct class *class;
a4dbd674 662 const struct attribute_group **groups; /* optional groups */
23681e47 663
d462943a 664 void (*release)(struct device *dev);
74416e1e 665 struct iommu_group *iommu_group;
045a7042 666 struct dev_iommu *iommu;
4f3549d7 667
6423d295
WC
668 struct device_physical_location *physical_location;
669
70f400d4
RJ
670 enum device_removable removable;
671
4f3549d7
RW
672 bool offline_disabled:1;
673 bool offline:1;
4e75e1d7 674 bool of_node_reused:1;
fc5a251d 675 bool state_synced:1;
f2db85b6 676 bool can_match:1;
f3ecc0ff
CH
677#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
678 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
679 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
680 bool dma_coherent:1;
681#endif
d35834c6
CH
682#ifdef CONFIG_DMA_OPS_BYPASS
683 bool dma_ops_bypass : 1;
684#endif
f406c8e4 685#ifdef CONFIG_DMA_NEED_SYNC
a6016aac 686 bool dma_skip_sync:1;
f406c8e4 687#endif
b5c58b2f
LR
688#ifdef CONFIG_IOMMU_DMA
689 bool dma_iommu:1;
690#endif
1da177e4
LT
691};
692
287905e6
SK
693/**
694 * struct device_link - Device link representation.
695 * @supplier: The device on the supplier end of the link.
696 * @s_node: Hook to the supplier device's list of links to consumers.
697 * @consumer: The device on the consumer end of the link.
698 * @c_node: Hook to the consumer device's list of links to suppliers.
699 * @link_dev: device used to expose link details in sysfs
700 * @status: The state of the link (with respect to the presence of drivers).
701 * @flags: Link flags.
702 * @rpm_active: Whether or not the consumer device is runtime-PM-active.
703 * @kref: Count repeated addition of the same link.
80dd33cf 704 * @rm_work: Work structure used for removing the link.
287905e6
SK
705 * @supplier_preactivated: Supplier has been made active before consumer probe.
706 */
707struct device_link {
708 struct device *supplier;
709 struct list_head s_node;
710 struct device *consumer;
711 struct list_head c_node;
712 struct device link_dev;
713 enum device_link_state status;
714 u32 flags;
715 refcount_t rpm_active;
716 struct kref kref;
80dd33cf 717 struct work_struct rm_work;
287905e6
SK
718 bool supplier_preactivated; /* Owned by consumer probe. */
719};
720
6149f83b 721#define kobj_to_dev(__kobj) container_of_const(__kobj, struct device, kobj)
a4232963 722
dbba197e
JR
723/**
724 * device_iommu_mapped - Returns true when the device DMA is translated
725 * by an IOMMU
726 * @dev: Device to perform the check on
727 */
728static inline bool device_iommu_mapped(struct device *dev)
729{
730 return (dev->iommu_group != NULL);
731}
732
9a3df1f7
AS
733/* Get the wakeup routines, which depend on struct device */
734#include <linux/pm_wakeup.h>
735
cd00bc2c
JS
736/**
737 * dev_name - Return a device's name.
738 * @dev: Device with name to get.
739 * Return: The kobject name of the device, or its initial name if unavailable.
740 */
bf9ca69f 741static inline const char *dev_name(const struct device *dev)
06916639 742{
a636ee7f
PM
743 /* Use the init name until the kobject becomes available */
744 if (dev->init_name)
745 return dev->init_name;
746
1fa5ae85 747 return kobject_name(&dev->kobj);
06916639
KS
748}
749
e020ff61
SK
750/**
751 * dev_bus_name - Return a device's bus/class name, if at all possible
752 * @dev: struct device to get the bus/class name of
753 *
754 * Will return the name of the bus/class the device is attached to. If it is
755 * not attached to a bus/class, an empty string will be returned.
756 */
757static inline const char *dev_bus_name(const struct device *dev)
758{
759 return dev->bus ? dev->bus->name : (dev->class ? dev->class->name : "");
760}
761
67dd0772 762__printf(2, 3) int dev_set_name(struct device *dev, const char *name, ...);
413c239f 763
87348136
CH
764#ifdef CONFIG_NUMA
765static inline int dev_to_node(struct device *dev)
766{
767 return dev->numa_node;
768}
769static inline void set_dev_node(struct device *dev, int node)
770{
771 dev->numa_node = node;
772}
773#else
774static inline int dev_to_node(struct device *dev)
775{
98fa15f3 776 return NUMA_NO_NODE;
87348136
CH
777}
778static inline void set_dev_node(struct device *dev, int node)
779{
780}
781#endif
782
f1421db8
MZ
783static inline struct irq_domain *dev_get_msi_domain(const struct device *dev)
784{
13e7accb 785#ifdef CONFIG_GENERIC_MSI_IRQ
34fff628 786 return dev->msi.domain;
f1421db8
MZ
787#else
788 return NULL;
789#endif
790}
791
792static inline void dev_set_msi_domain(struct device *dev, struct irq_domain *d)
793{
13e7accb 794#ifdef CONFIG_GENERIC_MSI_IRQ
34fff628 795 dev->msi.domain = d;
f1421db8
MZ
796#endif
797}
798
a996d010
JD
799static inline void *dev_get_drvdata(const struct device *dev)
800{
801 return dev->driver_data;
802}
803
804static inline void dev_set_drvdata(struct device *dev, void *data)
805{
806 dev->driver_data = data;
807}
808
5c095a0e
RW
809static inline struct pm_subsys_data *dev_to_psd(struct device *dev)
810{
811 return dev ? dev->power.subsys_data : NULL;
812}
813
f67f129e
ML
814static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
815{
816 return dev->kobj.uevent_suppress;
817}
818
819static inline void dev_set_uevent_suppress(struct device *dev, int val)
820{
821 dev->kobj.uevent_suppress = val;
822}
823
d305ef5d
DR
824static inline int device_is_registered(struct device *dev)
825{
3f62e570 826 return dev->kobj.state_in_sysfs;
d305ef5d
DR
827}
828
5af84b82
RW
829static inline void device_enable_async_suspend(struct device *dev)
830{
f76b168b 831 if (!dev->power.is_prepared)
5af84b82
RW
832 dev->power.async_suspend = true;
833}
834
5a2eb858
RW
835static inline void device_disable_async_suspend(struct device *dev)
836{
f76b168b 837 if (!dev->power.is_prepared)
5a2eb858
RW
838 dev->power.async_suspend = false;
839}
840
841static inline bool device_async_suspend_enabled(struct device *dev)
842{
843 return !!dev->power.async_suspend;
844}
845
85945c28
SH
846static inline bool device_pm_not_required(struct device *dev)
847{
848 return dev->power.no_pm;
849}
850
851static inline void device_set_pm_not_required(struct device *dev)
852{
853 dev->power.no_pm = true;
854}
855
feb70af0
RW
856static inline void dev_pm_syscore_device(struct device *dev, bool val)
857{
858#ifdef CONFIG_PM_SLEEP
859 dev->power.syscore = val;
860#endif
861}
862
08810a41
RW
863static inline void dev_pm_set_driver_flags(struct device *dev, u32 flags)
864{
865 dev->power.driver_flags = flags;
866}
867
868static inline bool dev_pm_test_driver_flags(struct device *dev, u32 flags)
869{
870 return !!(dev->power.driver_flags & flags);
871}
872
bca84a7b
RW
873static inline bool dev_pm_smart_suspend(struct device *dev)
874{
875#ifdef CONFIG_PM_SLEEP
876 return dev->power.smart_suspend;
877#else
878 return false;
879#endif
880}
881
8e9394ce
GKH
882static inline void device_lock(struct device *dev)
883{
3142788b 884 mutex_lock(&dev->mutex);
8e9394ce
GKH
885}
886
7dd9cba5
ON
887static inline int device_lock_interruptible(struct device *dev)
888{
889 return mutex_lock_interruptible(&dev->mutex);
890}
891
8e9394ce
GKH
892static inline int device_trylock(struct device *dev)
893{
3142788b 894 return mutex_trylock(&dev->mutex);
8e9394ce
GKH
895}
896
897static inline void device_unlock(struct device *dev)
898{
3142788b 899 mutex_unlock(&dev->mutex);
8e9394ce 900}
134c6eaa
DW
901
902DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T))
8e9394ce 903
ac801022
KRW
904static inline void device_lock_assert(struct device *dev)
905{
906 lockdep_assert_held(&dev->mutex);
907}
908
ac338acf
SK
909static inline bool dev_has_sync_state(struct device *dev)
910{
911 if (!dev)
912 return false;
913 if (dev->driver && dev->driver->sync_state)
914 return true;
915 if (dev->bus && dev->bus->sync_state)
916 return true;
917 return false;
918}
919
70f400d4
RJ
920static inline void dev_set_removable(struct device *dev,
921 enum device_removable removable)
922{
923 dev->removable = removable;
924}
925
926static inline bool dev_is_removable(struct device *dev)
927{
928 return dev->removable == DEVICE_REMOVABLE;
929}
930
931static inline bool dev_removable_is_valid(struct device *dev)
932{
933 return dev->removable != DEVICE_REMOVABLE_NOT_SUPPORTED;
934}
935
1da177e4
LT
936/*
937 * High level routines for use by the bus drivers
938 */
67dd0772
BG
939int __must_check device_register(struct device *dev);
940void device_unregister(struct device *dev);
941void device_initialize(struct device *dev);
942int __must_check device_add(struct device *dev);
943void device_del(struct device *dev);
54da6a09
PZ
944
945DEFINE_FREE(device_del, struct device *, if (_T) device_del(_T))
946
ab017a15 947int device_for_each_child(struct device *parent, void *data,
767b74e0 948 device_iter_t fn);
ab017a15 949int device_for_each_child_reverse(struct device *parent, void *data,
767b74e0 950 device_iter_t fn);
101c268b 951int device_for_each_child_reverse_from(struct device *parent,
523c6b3e 952 struct device *from, void *data,
767b74e0 953 device_iter_t fn);
ab017a15 954struct device *device_find_child(struct device *parent, const void *data,
f1e8bf56 955 device_match_t match);
51796f5e
ZH
956/**
957 * device_find_child_by_name - device iterator for locating a child device.
958 * @parent: parent struct device
959 * @name: name of the child device
960 *
961 * This is similar to the device_find_child() function above, but it
962 * returns a reference to a device that has the name @name.
963 *
964 * NOTE: you will need to drop the reference with put_device() after use.
965 */
966static inline struct device *device_find_child_by_name(struct device *parent,
967 const char *name)
968{
969 return device_find_child(parent, name, device_match_name);
970}
971
972/**
973 * device_find_any_child - device iterator for locating a child device, if any.
974 * @parent: parent struct device
975 *
976 * This is similar to the device_find_child() function above, but it
977 * returns a reference to a child device, if any.
978 *
979 * NOTE: you will need to drop the reference with put_device() after use.
980 */
981static inline struct device *device_find_any_child(struct device *parent)
982{
983 return device_find_child(parent, NULL, device_match_any);
984}
82b070be 985
67dd0772
BG
986int device_rename(struct device *dev, const char *new_name);
987int device_move(struct device *dev, struct device *new_parent,
988 enum dpm_order dpm_order);
989int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid);
1da177e4 990
4f3549d7
RW
991static inline bool device_supports_offline(struct device *dev)
992{
993 return dev->bus && dev->bus->offline && dev->bus->online;
994}
995
d864b8ea
DW
996#define __device_lock_set_class(dev, name, key) \
997do { \
998 struct device *__d2 __maybe_unused = dev; \
999 lock_set_class(&__d2->mutex.dep_map, name, key, 0, _THIS_IP_); \
1000} while (0)
1001
1002/**
1003 * device_lock_set_class - Specify a temporary lock class while a device
1004 * is attached to a driver
1005 * @dev: device to modify
1006 * @key: lock class key data
1007 *
1008 * This must be called with the device_lock() already held, for example
1009 * from driver ->probe(). Take care to only override the default
1010 * lockdep_no_validate class.
1011 */
1012#ifdef CONFIG_LOCKDEP
1013#define device_lock_set_class(dev, key) \
1014do { \
1015 struct device *__d = dev; \
1016 dev_WARN_ONCE(__d, !lockdep_match_class(&__d->mutex, \
1017 &__lockdep_no_validate__), \
1018 "overriding existing custom lock class\n"); \
1019 __device_lock_set_class(__d, #key, key); \
1020} while (0)
1021#else
1022#define device_lock_set_class(dev, key) __device_lock_set_class(dev, #key, key)
1023#endif
1024
1025/**
1026 * device_lock_reset_class - Return a device to the default lockdep novalidate state
1027 * @dev: device to modify
1028 *
1029 * This must be called with the device_lock() already held, for example
1030 * from driver ->remove().
1031 */
1032#define device_lock_reset_class(dev) \
1033do { \
1034 struct device *__d __maybe_unused = dev; \
1035 lock_set_novalidate_class(&__d->mutex.dep_map, "&dev->mutex", \
1036 _THIS_IP_); \
1037} while (0)
1038
67dd0772
BG
1039void lock_device_hotplug(void);
1040void unlock_device_hotplug(void);
1041int lock_device_hotplug_sysfs(void);
1042int device_offline(struct device *dev);
1043int device_online(struct device *dev);
1968845d 1044
67dd0772
BG
1045void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
1046void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
43e76d46 1047void device_set_node(struct device *dev, struct fwnode_handle *fwnode);
3b62449d
HC
1048int device_add_of_node(struct device *dev, struct device_node *of_node);
1049void device_remove_of_node(struct device *dev);
1968845d
AS
1050void device_set_of_node_from_dev(struct device *dev, const struct device *dev2);
1051
1052static inline struct device_node *dev_of_node(struct device *dev)
1053{
1054 if (!IS_ENABLED(CONFIG_OF) || !dev)
1055 return NULL;
1056 return dev->of_node;
1057}
97badf87 1058
9af15c38
PS
1059static inline int dev_num_vf(struct device *dev)
1060{
1061 if (dev->bus && dev->bus->num_vf)
1062 return dev->bus->num_vf(dev);
1063 return 0;
1064}
1065
0aa0dc41
MM
1066/*
1067 * Root device objects for grouping under /sys/devices
1068 */
67dd0772 1069struct device *__root_device_register(const char *name, struct module *owner);
eb5589a8 1070
33ac1257 1071/* This is a macro to avoid include problems with THIS_MODULE */
eb5589a8
PG
1072#define root_device_register(name) \
1073 __root_device_register(name, THIS_MODULE)
1074
67dd0772 1075void root_device_unregister(struct device *root);
0aa0dc41 1076
a5b8b1ad
MB
1077static inline void *dev_get_platdata(const struct device *dev)
1078{
1079 return dev->platform_data;
1080}
1081
1da177e4
LT
1082/*
1083 * Manual binding of a device to driver. See drivers/base/bus.c
1084 * for information on use.
1085 */
269e974e 1086int __must_check device_driver_attach(const struct device_driver *drv,
0d9f837c 1087 struct device *dev);
67dd0772
BG
1088int __must_check device_bind_driver(struct device *dev);
1089void device_release_driver(struct device *dev);
1090int __must_check device_attach(struct device *dev);
269e974e 1091int __must_check driver_attach(const struct device_driver *drv);
67dd0772
BG
1092void device_initial_probe(struct device *dev);
1093int __must_check device_reprobe(struct device *dev);
1da177e4 1094
67dd0772 1095bool device_is_bound(struct device *dev);
6b9cb427 1096
23681e47
GKH
1097/*
1098 * Easy functions for dynamically creating devices on the fly
1099 */
67dd0772 1100__printf(5, 6) struct device *
2bd5c639 1101device_create(const struct class *cls, struct device *parent, dev_t devt,
67dd0772
BG
1102 void *drvdata, const char *fmt, ...);
1103__printf(6, 7) struct device *
2bd5c639 1104device_create_with_groups(const struct class *cls, struct device *parent, dev_t devt,
67dd0772
BG
1105 void *drvdata, const struct attribute_group **groups,
1106 const char *fmt, ...);
d2fff096 1107void device_destroy(const struct class *cls, dev_t devt);
67dd0772
BG
1108
1109int __must_check device_add_groups(struct device *dev,
1110 const struct attribute_group **groups);
1111void device_remove_groups(struct device *dev,
1112 const struct attribute_group **groups);
a7670d42 1113
e323b2dd
DT
1114static inline int __must_check device_add_group(struct device *dev,
1115 const struct attribute_group *grp)
1116{
1117 const struct attribute_group *groups[] = { grp, NULL };
1118
1119 return device_add_groups(dev, groups);
1120}
1121
1122static inline void device_remove_group(struct device *dev,
1123 const struct attribute_group *grp)
1124{
1125 const struct attribute_group *groups[] = { grp, NULL };
1126
a44073c2 1127 device_remove_groups(dev, groups);
e323b2dd
DT
1128}
1129
67dd0772
BG
1130int __must_check devm_device_add_group(struct device *dev,
1131 const struct attribute_group *grp);
57b8ff07 1132
880ffb5c 1133/*
1da177e4
LT
1134 * get_device - atomically increment the reference count for the device.
1135 *
1136 */
67dd0772
BG
1137struct device *get_device(struct device *dev);
1138void put_device(struct device *dev);
54da6a09
PZ
1139
1140DEFINE_FREE(put_device, struct device *, if (_T) put_device(_T))
1141
67dd0772 1142bool kill_device(struct device *dev);
1da177e4 1143
2b2af54a 1144#ifdef CONFIG_DEVTMPFS
67dd0772 1145int devtmpfs_mount(void);
2b2af54a 1146#else
5e787dbf 1147static inline int devtmpfs_mount(void) { return 0; }
2b2af54a
KS
1148#endif
1149
116f232b 1150/* drivers/base/power/shutdown.c */
67dd0772 1151void device_shutdown(void);
1da177e4 1152
1da177e4 1153/* debugging and troubleshooting/diagnostic helpers. */
67dd0772 1154const char *dev_driver_string(const struct device *dev);
99bcf217 1155
9ed98953
RW
1156/* Device links interface. */
1157struct device_link *device_link_add(struct device *consumer,
1158 struct device *supplier, u32 flags);
1159void device_link_del(struct device_link *link);
d8842211 1160void device_link_remove(void *consumer, struct device *supplier);
fc5a251d
SK
1161void device_links_supplier_sync_state_pause(void);
1162void device_links_supplier_sync_state_resume(void);
0462c56c 1163void device_link_wait_removal(void);
99bcf217 1164
1da177e4
LT
1165/* Create alias, so I can be autoloaded. */
1166#define MODULE_ALIAS_CHARDEV(major,minor) \
1167 MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
1168#define MODULE_ALIAS_CHARDEV_MAJOR(major) \
1169 MODULE_ALIAS("char-major-" __stringify(major) "-*")
e52eec13 1170
1da177e4 1171#endif /* _DEVICE_H_ */