drivers/cxl/core/region.c
Source file repositories/reference/linux-study-clean/drivers/cxl/core/region.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cxl/core/region.c- Extension
.c- Size
- 111773 bytes
- Lines
- 4277
- Domain
- Driver Families
- Bucket
- drivers/cxl
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/memregion.hlinux/genalloc.hlinux/debugfs.hlinux/device.hlinux/module.hlinux/memory.hlinux/slab.hlinux/uuid.hlinux/sort.hlinux/idr.hlinux/memory-tiers.hlinux/string_choices.hcxlmem.hcxl.hcore.h
Detected Declarations
struct cxl_poison_contextstruct cxl_dpa_to_region_contextstruct dpa_resultfunction uuid_showfunction is_dupfunction uuid_storefunction cxl_region_invalidate_memregionfunction cxl_region_decode_resetfunction commit_decoderfunction cxl_region_decode_commitfunction queue_resetfunction __commitfunction commit_storefunction commit_showfunction interleave_ways_showfunction set_interleave_waysfunction interleave_ways_storefunction interleave_granularity_showfunction set_interleave_granularityfunction interleave_granularity_storefunction resource_showfunction mode_showfunction alloc_hpafunction cxl_region_iomem_releasefunction free_hpafunction size_storefunction size_showfunction extended_linear_cache_size_showfunction locked_showfunction cxl_region_visiblefunction show_targetNfunction check_commit_orderfunction match_free_decoderfunction spa_maps_hpafunction match_auto_decoderfunction cxl_port_pick_region_decoderfunction auto_order_okfunction alloc_region_reffunction xa_for_eachfunction cxl_rr_free_decoderfunction free_region_reffunction cxl_rr_ep_addfunction cxl_rr_assign_decoderfunction cxl_region_setup_flagsfunction cxl_port_attach_regionfunction xa_for_eachfunction cxl_port_detach_regionfunction xa_for_each
Annotated Snippet
rc = device_add(dev);
if (rc)
goto err;
rc = xa_insert(&cxlrd->regions, cxlr->id, cxlr, GFP_KERNEL);
if (rc) {
unregister_region(cxlr);
return ERR_PTR(rc);
}
dev_dbg(port->uport_dev, "%s: created %s\n",
dev_name(&cxlrd->cxlsd.cxld.dev), dev_name(dev));
return cxlr;
err:
put_device(dev);
return ERR_PTR(rc);
}
static ssize_t __create_region_show(struct cxl_root_decoder *cxlrd, char *buf)
{
return sysfs_emit(buf, "region%u\n", atomic_read(&cxlrd->region_id));
}
static ssize_t create_pmem_region_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return __create_region_show(to_cxl_root_decoder(dev), buf);
}
static ssize_t create_ram_region_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return __create_region_show(to_cxl_root_decoder(dev), buf);
}
static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
enum cxl_partition_mode mode, int id,
enum cxl_decoder_type target_type)
{
int rc;
if (cxlrd->dead)
return ERR_PTR(-ENXIO);
switch (mode) {
case CXL_PARTMODE_RAM:
case CXL_PARTMODE_PMEM:
break;
default:
dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %d\n", mode);
return ERR_PTR(-EINVAL);
}
rc = memregion_alloc(GFP_KERNEL);
if (rc < 0)
return ERR_PTR(rc);
if (atomic_cmpxchg(&cxlrd->region_id, id, rc) != id) {
memregion_free(rc);
return ERR_PTR(-EBUSY);
}
return devm_cxl_add_region(cxlrd, id, mode, target_type);
}
static ssize_t create_region_store(struct device *dev, const char *buf,
size_t len, enum cxl_partition_mode mode)
{
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev);
struct cxl_region *cxlr;
int rc, id;
rc = sscanf(buf, "region%d\n", &id);
if (rc != 1)
return -EINVAL;
ACQUIRE(mutex_intr, regions_lock)(&cxlrd->regions_lock);
if ((rc = ACQUIRE_ERR(mutex_intr, ®ions_lock)))
return rc;
cxlr = __create_region(cxlrd, mode, id, CXL_DECODER_HOSTONLYMEM);
if (IS_ERR(cxlr))
return PTR_ERR(cxlr);
return len;
}
static ssize_t create_pmem_region_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
Annotation
- Immediate include surface: `linux/memregion.h`, `linux/genalloc.h`, `linux/debugfs.h`, `linux/device.h`, `linux/module.h`, `linux/memory.h`, `linux/slab.h`, `linux/uuid.h`.
- Detected declarations: `struct cxl_poison_context`, `struct cxl_dpa_to_region_context`, `struct dpa_result`, `function uuid_show`, `function is_dup`, `function uuid_store`, `function cxl_region_invalidate_memregion`, `function cxl_region_decode_reset`, `function commit_decoder`, `function cxl_region_decode_commit`.
- Atlas domain: Driver Families / drivers/cxl.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.