drivers/cxl/mem.c

Source file repositories/reference/linux-study-clean/drivers/cxl/mem.c

File Facts

System
Linux kernel
Corpus path
drivers/cxl/mem.c
Extension
.c
Size
8718 bytes
Lines
316
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

if (rc) {
			if (rc == -ENODEV)
				dev_info(dev, "PMEM disabled by platform\n");
			return rc;
		}
	}

	if (dport->rch)
		endpoint_parent = parent_port->uport_dev;
	else
		endpoint_parent = &parent_port->dev;

	scoped_guard(device, endpoint_parent) {
		if (!endpoint_parent->driver) {
			dev_err(dev, "CXL port topology %s not enabled\n",
				dev_name(endpoint_parent));
			return -ENXIO;
		}

		rc = devm_cxl_add_endpoint(endpoint_parent, cxlmd, dport);
		if (rc)
			return rc;
	}

	if (cxlmd->attach) {
		rc = cxlmd->attach->probe(cxlmd);
		if (rc)
			return rc;
	}

	rc = devm_cxl_memdev_edac_register(cxlmd);
	if (rc)
		dev_dbg(dev, "CXL memdev EDAC registration failed rc=%d\n", rc);

	/*
	 * The kernel may be operating out of CXL memory on this device,
	 * there is no spec defined way to determine whether this device
	 * preserves contents over suspend, and there is no simple way
	 * to arrange for the suspend image to avoid CXL memory which
	 * would setup a circular dependency between PCI resume and save
	 * state restoration.
	 *
	 * TODO: support suspend when all the regions this device is
	 * hosting are locked and covered by the system address map,
	 * i.e. platform firmware owns restoring the HDM configuration
	 * that it locked.
	 */
	cxl_mem_active_inc();
	return devm_add_action_or_reset(dev, enable_suspend, NULL);
}

/**
 * devm_cxl_add_classdev - Add a CXL memory class-code device
 * @cxlds: CXL device state to associate with the memdev
 *
 * Upon return the device will have had a chance to attach to the
 * cxl_mem driver, but may fail to attach if the CXL topology is not ready
 * (hardware CXL link down, or software platform CXL root not attached).
 *
 * The parent of the resulting device and the devm context for allocations is
 * @cxlds->dev.
 */
struct cxl_memdev *devm_cxl_add_classdev(struct cxl_dev_state *cxlds)
{
	return __devm_cxl_add_memdev(cxlds, NULL);
}
EXPORT_SYMBOL_NS_GPL(devm_cxl_add_classdev, "CXL");

/**
 * devm_cxl_probe_mem - Add a CXL memory device and probe its region
 * @cxlds: CXL device state to associate with the memdev
 * @hpa_range: CXL.mem physical address range result
 *
 * Upon return the device will have had a chance to attach to the
 * cxl_mem driver, but may fail to attach if the CXL topology is not ready
 * (hardware CXL link down, or software platform CXL root not attached).
 *
 * Failure to probe the memdev and/or setup a region for the memdev
 * results in this function failing.
 *
 * The parent of the resulting device and the devm context for allocations is
 * @cxlds->dev.
 */
struct cxl_memdev *devm_cxl_probe_mem(struct cxl_dev_state *cxlds,
				      struct range *hpa_range)
{
	struct cxl_attach_region *attach =
		devm_kmalloc(cxlds->dev, sizeof(*attach), GFP_KERNEL);
	struct cxl_memdev *cxlmd;

Annotation

Implementation Notes