1<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>struct device</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Linux Device Drivers"><link rel="up" href="devdrivers.html#id-1.4.2" title="The Basic Device Driver-Model Structures"><link rel="prev" href="API-struct-class.html" title="struct class"><link rel="next" href="API-module-driver.html" title="module_driver"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">struct device</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-struct-class.html">Prev</a> </td><th width="60%" align="center">The Basic Device Driver-Model Structures </th><td width="20%" align="right"> <a accesskey="n" href="API-module-driver.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-struct-device"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>struct device — 
2     The basic device structure
3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="programlisting">
4struct device {
5  struct device * parent;
6  struct device_private * p;
7  struct kobject kobj;
8  const char * init_name;
9  const struct device_type * type;
10  struct mutex mutex;
11  struct bus_type * bus;
12  struct device_driver * driver;
13  void * platform_data;
14  void * driver_data;
15  struct dev_pm_info power;
16  struct dev_pm_domain * pm_domain;
17#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
18  struct irq_domain * msi_domain;
19#endif
20#ifdef CONFIG_PINCTRL
21  struct dev_pin_info * pins;
22#endif
23#ifdef CONFIG_GENERIC_MSI_IRQ
24  struct list_head msi_list;
25#endif
26#ifdef CONFIG_NUMA
27  int numa_node;
28#endif
29  u64 * dma_mask;
30  u64 coherent_dma_mask;
31  unsigned long dma_pfn_offset;
32  struct device_dma_parameters * dma_parms;
33  struct list_head dma_pools;
34  struct dma_coherent_mem * dma_mem;
35#ifdef CONFIG_DMA_CMA
36  struct cma * cma_area;
37#endif
38  struct dev_archdata archdata;
39  struct device_node * of_node;
40  struct fwnode_handle * fwnode;
41  dev_t devt;
42  u32 id;
43  spinlock_t devres_lock;
44  struct list_head devres_head;
45  struct klist_node knode_class;
46  struct class * class;
47  const struct attribute_group ** groups;
48  void (* release) (struct device *dev);
49  struct iommu_group * iommu_group;
50  bool offline_disabled:1;
51  bool offline:1;
52};  </pre></div><div class="refsect1"><a name="id-1.4.2.7.5"></a><h2>Members</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term">parent</span></dt><dd><p>
53   The device's <span class="quote">“<span class="quote">parent</span>”</span> device, the device to which it is attached.
54   In most cases, a parent device is some sort of bus or host
55   controller. If parent is NULL, the device, is a top-level device,
56   which is not usually what you want.
57      </p></dd><dt><span class="term">p</span></dt><dd><p>
58   Holds the private data of the driver core portions of the device.
59   See the comment of the struct device_private for detail.
60      </p></dd><dt><span class="term">kobj</span></dt><dd><p>
61   A top-level, abstract class from which other classes are derived.
62      </p></dd><dt><span class="term">init_name</span></dt><dd><p>
63   Initial name of the device.
64      </p></dd><dt><span class="term">type</span></dt><dd><p>
65   The type of device.
66   This identifies the device type and carries type-specific
67   information.
68      </p></dd><dt><span class="term">mutex</span></dt><dd><p>
69   Mutex to synchronize calls to its driver.
70      </p></dd><dt><span class="term">bus</span></dt><dd><p>
71   Type of bus device is on.
72      </p></dd><dt><span class="term">driver</span></dt><dd><p>
73   Which driver has allocated this
74      </p></dd><dt><span class="term">platform_data</span></dt><dd><p>
75   Platform data specific to the device.
76      </p></dd><dt><span class="term">driver_data</span></dt><dd><p>
77   Private pointer for driver specific info.
78      </p></dd><dt><span class="term">power</span></dt><dd><p>
79   For device power management.
80   See Documentation/power/devices.txt for details.
81      </p></dd><dt><span class="term">pm_domain</span></dt><dd><p>
82   Provide callbacks that are executed during system suspend,
83   hibernation, system resume and during runtime PM transitions
84   along with subsystem-level and driver-level callbacks.
85      </p></dd><dt><span class="term">msi_domain</span></dt><dd><p>
86   The generic MSI domain this device is using.
87      </p></dd><dt><span class="term">pins</span></dt><dd><p>
88   For device pin management.
89   See Documentation/pinctrl.txt for details.
90      </p></dd><dt><span class="term">msi_list</span></dt><dd><p>
91   Hosts MSI descriptors
92      </p></dd><dt><span class="term">numa_node</span></dt><dd><p>
93   NUMA node this device is close to.
94      </p></dd><dt><span class="term">dma_mask</span></dt><dd><p>
95   Dma mask (if dma'ble device).
96      </p></dd><dt><span class="term">coherent_dma_mask</span></dt><dd><p>
97   Like dma_mask, but for alloc_coherent mapping as not all
98   hardware supports 64-bit addresses for consistent allocations
99   such descriptors.
100      </p></dd><dt><span class="term">dma_pfn_offset</span></dt><dd><p>
101   offset of DMA memory range relatively of RAM
102      </p></dd><dt><span class="term">dma_parms</span></dt><dd><p>
103   A low level driver may set these to teach IOMMU code about
104   segment limitations.
105      </p></dd><dt><span class="term">dma_pools</span></dt><dd><p>
106   Dma pools (if dma'ble device).
107      </p></dd><dt><span class="term">dma_mem</span></dt><dd><p>
108   Internal for coherent mem override.
109      </p></dd><dt><span class="term">cma_area</span></dt><dd><p>
110   Contiguous memory area for dma allocations
111      </p></dd><dt><span class="term">archdata</span></dt><dd><p>
112   For arch-specific additions.
113      </p></dd><dt><span class="term">of_node</span></dt><dd><p>
114   Associated device tree node.
115      </p></dd><dt><span class="term">fwnode</span></dt><dd><p>
116   Associated device node supplied by platform firmware.
117      </p></dd><dt><span class="term">devt</span></dt><dd><p>
118   For creating the sysfs <span class="quote">“<span class="quote">dev</span>”</span>.
119      </p></dd><dt><span class="term">id</span></dt><dd><p>
120   device instance
121      </p></dd><dt><span class="term">devres_lock</span></dt><dd><p>
122   Spinlock to protect the resource of the device.
123      </p></dd><dt><span class="term">devres_head</span></dt><dd><p>
124   The resources list of the device.
125      </p></dd><dt><span class="term">knode_class</span></dt><dd><p>
126   The node used to add the device to the class list.
127      </p></dd><dt><span class="term">class</span></dt><dd><p>
128   The class of the device.
129      </p></dd><dt><span class="term">groups</span></dt><dd><p>
130   Optional attribute groups.
131      </p></dd><dt><span class="term">release</span></dt><dd><p>
132   Callback to free the device after all references have
133   gone away. This should be set by the allocator of the
134   device (i.e. the bus driver that discovered the device).
135      </p></dd><dt><span class="term">iommu_group</span></dt><dd><p>
136   IOMMU group the device belongs to.
137      </p></dd><dt><span class="term">offline_disabled</span></dt><dd><p>
138   If set, the device is permanently online.
139      </p></dd><dt><span class="term">offline</span></dt><dd><p>
140   Set after successful invocation of bus type's .<code class="function">offline</code>.
141      </p></dd></dl></div></div><div class="refsect1"><a name="id-1.4.2.7.6"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
142   For devices on custom boards, as typical of embedded
143   		and SOC based hardware, Linux often uses platform_data to point
144   		to board-specific structures describing devices and how they
145   		are wired.  That can include what ports are available, chip
146   		variants, which GPIO pins act in what additional roles, and so
147   		on.  This shrinks the <span class="quote">“<span class="quote">Board Support Packages</span>”</span> (BSPs) and
148   		minimizes board-specific #ifdefs in drivers.
149</pre></div></div><div class="refsect1"><a name="id-1.4.2.7.7"></a><h2>Description</h2><p>
150   At the lowest level, every device in a Linux system is represented by an
151   instance of struct device. The device structure contains the information
152   that the device model core needs to model the system. Most subsystems,
153   however, track additional information about the devices they host. As a
154   result, it is rare for devices to be represented by bare device structures;
155   instead, that structure, like kobject structures, is usually embedded within
156   a higher-level representation of the device.
157</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-struct-class.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="devdrivers.html#id-1.4.2">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-module-driver.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">struct class</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">module_driver</span></td></tr></table></div></body></html>
158