STRUCT DEVICE(9)
π struct device(9) π
okay bestie, buckle up β this is struct device(9) from the Kernel API Manual, and it's literally the blueprint for every single device your kernel has ever met. main character energy, fr.
β¨ NAME β¨
struct device β the basic device structure π«Ά
π¦ SYNOPSIS π¦
struct device {
struct kobject kobj;
struct device *parent;
struct device_private *p;
const char *init_name;
const struct device_type *type;
const struct bus_type *bus;
struct device_driver *driver;
void *platform_data;
void *driver_data;
struct {
const char *name;
spinlock_t lock;
} driver_override;
struct mutex mutex;
struct dev_links_info links;
struct dev_pm_info power;
struct dev_pm_domain *pm_domain;
#ifdef CONFIG_ENERGY_MODEL;
struct em_perf_domain *em_pd;
#endif;
#ifdef CONFIG_PINCTRL;
struct dev_pin_info *pins;
#endif;
struct dev_msi_info msi;
#ifdef CONFIG_ARCH_HAS_DMA_OPS;
const struct dma_map_ops *dma_ops;
#endif;
u64 *dma_mask;
u64 coherent_dma_mask;
u64 bus_dma_limit;
const struct bus_dma_region *dma_range_map;
struct device_dma_parameters *dma_parms;
struct list_head dma_pools;
#ifdef CONFIG_DMA_DECLARE_COHERENT;
struct dma_coherent_mem *dma_mem;
#endif;
#ifdef CONFIG_DMA_CMA;
struct cma *cma_area;
#endif;
#ifdef CONFIG_SWIOTLB;
struct io_tlb_mem *dma_io_tlb_mem;
#endif;
#ifdef CONFIG_SWIOTLB_DYNAMIC;
struct list_head dma_io_tlb_pools;
spinlock_t dma_io_tlb_lock;
bool dma_uses_io_tlb;
#endif;
struct dev_archdata archdata;
struct device_node *of_node;
struct fwnode_handle *fwnode;
#ifdef CONFIG_NUMA;
int numa_node;
#endif;
dev_t devt;
u32 id;
spinlock_t devres_lock;
struct list_head devres_head;
const struct class *class;
const struct attribute_group **groups;
void (*release)(struct device *dev);
struct iommu_group *iommu_group;
struct dev_iommu *iommu;
struct device_physical_location *physical_location;
enum device_removable removable;
unsigned long flags[BITS_TO_LONGS( DEV_FLAG_COUNT)];
};
bestie it's a big struct, but every field is iconic in its own way. let's go π
πΈ Members πΈ
kobjβ a top-level, abstract class that other classes are derived from. the origin story, basically.parentβ the device's "parent" device, i.e. the device it's attached to. in most cases a parent device is some sort of bus or host controller. ifparentisNULL, the device is a top-level device β which is not usually what you want πpβ holds the private data of the driver core portions of the device. see the comment of thestruct device_privatefor detail.init_nameβ the initial name of the device.typeβ the type of device. it identifies the device type and carries type-specific information.busβ the type of bus the device is on.driverβ which driver has allocated this.platform_dataβ platform data specific to the device.driver_dataβ private pointer for driver specific info.driver_overrideβ driver name to force a match. do not touch directly; usedevice_set_driver_overrideinstead πmutexβ mutex to synchronize calls to its driver.linksβ links to suppliers and consumers of this device.powerβ for device power management. seeDocumentation/driver-api/pm/devices.rstfor details.pm_domainβ provides callbacks executed during system suspend, hibernation, system resume and during runtime PM transitions, along with subsystem-level and driver-level callbacks.em_pdβ the device's energy model performance domain. (lives behindCONFIG_ENERGY_MODELβ¨)pinsβ for device pin management. seeDocumentation/driver-api/pin-control.rstfor details. (behindCONFIG_PINCTRL)msiβ MSI related data.dma_opsβ DMA mapping operations for this device. (behindCONFIG_ARCH_HAS_DMA_OPS)dma_maskβ DMA mask (if it's a dma'ble device).coherent_dma_maskβ likedma_mask, but foralloc_coherentmapping, since not all hardware supports 64-bit addresses for consistent allocations of such descriptors.bus_dma_limitβ limit of an upstream bridge or bus which imposes a smaller DMA limit than the device itself supports.dma_range_mapβ map for DMA memory ranges relative to that of RAM.dma_parmsβ a low level driver may set these to teach IOMMU code about segment limitations.dma_poolsβ DMA pools (if it's a dma'ble device).dma_memβ internal for coherent mem override. (behindCONFIG_DMA_DECLARE_COHERENT)cma_areaβ contiguous memory area for DMA allocations. (behindCONFIG_DMA_CMA)dma_io_tlb_memβ software IO TLB allocator. not for driver use, bestie, hands off. (behindCONFIG_SWIOTLB)dma_io_tlb_poolsβ list of transient swiotlb memory pools. (behindCONFIG_SWIOTLB_DYNAMIC)dma_io_tlb_lockβ protects changes to the list of active pools. (behindCONFIG_SWIOTLB_DYNAMIC)dma_uses_io_tlbβtrueif the device has used the software IO TLB. (behindCONFIG_SWIOTLB_DYNAMIC)archdataβ for arch-specific additions.of_nodeβ associated device tree node.fwnodeβ associated device node supplied by platform firmware.numa_nodeβ the NUMA node this device is close to. (behindCONFIG_NUMA)devtβ for creating the sysfs "dev".idβ device instance.devres_lockβ spinlock to protect the resource of the device.devres_headβ the resources list of the device.classβ the class of the device.groupsβ optional attribute groups.releaseβ callback to free the device after all references have gone away. this should be set by the allocator of the device (i.e. the bus driver that discovered the device).iommu_groupβ the IOMMU group the device belongs to.iommuβ per device generic IOMMU runtime data.physical_locationβ describes the physical location of the device connection point in the system housing.removableβ whether the device can be removed from the system. this should be set by the subsystem / bus driver that discovered the device.flagsβDEV_FLAG_XXXflags. use atomic bitfield operations to modify them, no cap π«‘
π Example π
for devices on custom boards β the typical embedded and SOC based hardware situation β Linux often uses platform_data to point to board-specific structures describing devices and how they're wired. that can include which ports are available, chip variants, which GPIO pins act in what additional roles, and so on. it shrinks the "Board Support Packages" (BSPs) and minimizes board-specific #ifdefs in drivers. absolutely slaying the bloat π
π§ Description π§
at the lowest level, every device in a Linux system is represented by an instance of struct device. the device structure holds the information the device model core needs to model the system. most subsystems, however, track additional information about the devices they host. so yeah β it's rare for devices to be represented by bare device structures; instead that structure, like kobject structures, is usually embedded within a higher-level representation of the device. it's giving nesting dolls. it's giving "everything is a device inside a device" π
π SEE ALSO π
kernel file ./include/linux/device.h, plus all these besties:
struct subsys_interface(9)struct device_attribute(9)struct dev_ext_attribute(9)DEVICE_ATTR(9)DEVICE_ATTR_RW(9)DEVICE_ATTR_ADMIN_RW(9)DEVICE_ATTR_RW_NAMED(9)DEVICE_ATTR_RO(9)DEVICE_ATTR_ADMIN_RO(9)DEVICE_ATTR_RO_NAMED(9)DEVICE_ATTR_WO(9)DEVICE_ATTR_WO_NAMED(9)DEVICE_ULONG_ATTR(9)DEVICE_INT_ATTR(9)DEVICE_BOOL_ATTR(9)DEVICE_STRING_ATTR_RO(9)enum device_link_state(9)enum dl_dev_state(9)enum device_removable(9)struct dev_links_info(9)struct dev_msi_info(9)enum device_physical_location_panel(9)enum device_physical_location_vertical_position(9)enum device_physical_location_horizontal_position(9)struct device_physical_location(9)enum struct_device_flags(9)struct device_link(9)device_set_driver_override(9)device_has_driver_override(9)device_match_driver_override(9)device_iommu_mapped(9)dev_name(9)dev_bus_name(9)device_find_child_by_name(9)device_find_any_child(9)device_lock_set_class(9)device_lock_reset_class(9)
ngl bestie, if you made it this far you're officially a kernel dev now. go read device.h and hydrate π
this lil page came from ./include/linux, dated October 2026 β mwah, love u, bye πβ¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms