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.

Dependency Surface

Detected Declarations

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, &regions_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

Implementation Notes