drivers/dax/device.c
Source file repositories/reference/linux-study-clean/drivers/dax/device.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/dax/device.c- Extension
.c- Size
- 11799 bytes
- Lines
- 477
- Domain
- Driver Families
- Bucket
- drivers/dax
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/memremap.hlinux/pagemap.hlinux/module.hlinux/device.hlinux/cdev.hlinux/slab.hlinux/dax.hlinux/fs.hlinux/mm.hlinux/mman.hdax-private.hbus.h
Detected Declarations
function __check_vmafunction check_vmafunction dax_set_mappingfunction __dev_dax_pte_faultfunction __dev_dax_pmd_faultfunction __dev_dax_pud_faultfunction __dev_dax_pud_faultfunction dev_dax_huge_faultfunction dev_dax_faultfunction dev_dax_may_splitfunction dev_dax_pagesizefunction dax_mmap_preparefunction dax_get_unmapped_areafunction dax_openfunction dax_releasefunction dev_dax_cdev_delfunction dev_dax_killfunction dev_dax_probefunction dax_initfunction dax_exitmodule init dax_init
Annotated Snippet
static const struct file_operations dax_fops = {
.llseek = noop_llseek,
.owner = THIS_MODULE,
.open = dax_open,
.release = dax_release,
.get_unmapped_area = dax_get_unmapped_area,
.mmap_prepare = dax_mmap_prepare,
.fop_flags = FOP_MMAP_SYNC,
};
static void dev_dax_cdev_del(void *cdev)
{
cdev_del(cdev);
}
static void dev_dax_kill(void *dev_dax)
{
kill_dev_dax(dev_dax);
}
static int dev_dax_probe(struct dev_dax *dev_dax)
{
struct dax_device *dax_dev = dev_dax->dax_dev;
struct device *dev = &dev_dax->dev;
struct dev_pagemap *pgmap;
struct inode *inode;
struct cdev *cdev;
void *addr;
int rc, i;
if (static_dev_dax(dev_dax)) {
if (dev_dax->nr_range > 1) {
dev_warn(dev,
"static pgmap / multi-range device conflict\n");
return -EINVAL;
}
pgmap = dev_dax->pgmap;
} else {
if (dev_dax->pgmap) {
dev_warn(dev,
"dynamic-dax with pre-populated page map\n");
return -EINVAL;
}
pgmap = devm_kzalloc(dev,
struct_size(pgmap, ranges, dev_dax->nr_range - 1),
GFP_KERNEL);
if (!pgmap)
return -ENOMEM;
pgmap->nr_range = dev_dax->nr_range;
dev_dax->pgmap = pgmap;
for (i = 0; i < dev_dax->nr_range; i++) {
struct range *range = &dev_dax->ranges[i].range;
pgmap->ranges[i] = *range;
}
}
for (i = 0; i < dev_dax->nr_range; i++) {
struct range *range = &dev_dax->ranges[i].range;
if (!devm_request_mem_region(dev, range->start,
range_len(range), dev_name(dev))) {
dev_warn(dev, "mapping%d: %#llx-%#llx could not reserve range\n",
i, range->start, range->end);
return -EBUSY;
}
}
pgmap->type = MEMORY_DEVICE_GENERIC;
if (dev_dax->align > PAGE_SIZE)
pgmap->vmemmap_shift =
order_base_2(dev_dax->align >> PAGE_SHIFT);
addr = devm_memremap_pages(dev, pgmap);
if (IS_ERR(addr))
return PTR_ERR(addr);
inode = dax_inode(dax_dev);
cdev = inode->i_cdev;
cdev_init(cdev, &dax_fops);
cdev->owner = dev->driver->owner;
cdev_set_parent(cdev, &dev->kobj);
rc = cdev_add(cdev, dev->devt, 1);
if (rc)
return rc;
rc = devm_add_action_or_reset(dev, dev_dax_cdev_del, cdev);
if (rc)
Annotation
- Immediate include surface: `linux/memremap.h`, `linux/pagemap.h`, `linux/module.h`, `linux/device.h`, `linux/cdev.h`, `linux/slab.h`, `linux/dax.h`, `linux/fs.h`.
- Detected declarations: `function __check_vma`, `function check_vma`, `function dax_set_mapping`, `function __dev_dax_pte_fault`, `function __dev_dax_pmd_fault`, `function __dev_dax_pud_fault`, `function __dev_dax_pud_fault`, `function dev_dax_huge_fault`, `function dev_dax_fault`, `function dev_dax_may_split`.
- Atlas domain: Driver Families / drivers/dax.
- Implementation status: pattern implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.