Commit 7d3eb23c authored by Dan Williams's avatar Dan Williams
Browse files

tools/testing/cxl: Introduce a mock memory device + driver



Introduce an emulated device-set plus driver to register CXL memory
devices, 'struct cxl_memdev' instances, in the mock cxl_test topology.
This enables the development of HDM Decoder (Host-managed Device Memory
Decoder) programming flow (region provisioning) in an environment that
can be updated alongside the kernel as it gains more functionality.

Whereas the cxl_pci module looks for CXL memory expanders on the 'pci'
bus, the cxl_mock_mem module attaches to CXL expanders on the platform
bus emitted by cxl_test.

Acked-by: default avatarBen Widawsky <ben.widawsky@intel.com>
Reported-by: default avatarkernel test robot <lkp@intel.com>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/163116440099.2460985.10692549614409346604.stgit@dwillia2-desk3.amr.corp.intel.com


Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 49be6dd8
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -51,16 +51,16 @@ struct cxl_nvdimm_bridge *to_cxl_nvdimm_bridge(struct device *dev)
}
EXPORT_SYMBOL_GPL(to_cxl_nvdimm_bridge);

static int match_nvdimm_bridge(struct device *dev, const void *data)
__mock int match_nvdimm_bridge(struct device *dev, const void *data)
{
	return dev->type == &cxl_nvdimm_bridge_type;
}

struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(void)
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_nvdimm *cxl_nvd)
{
	struct device *dev;

	dev = bus_find_device(&cxl_bus_type, NULL, NULL, match_nvdimm_bridge);
	dev = bus_find_device(&cxl_bus_type, NULL, cxl_nvd, match_nvdimm_bridge);
	if (!dev)
		return NULL;
	return to_cxl_nvdimm_bridge(dev);
+1 −1
Original line number Diff line number Diff line
@@ -327,7 +327,7 @@ struct cxl_nvdimm_bridge *devm_cxl_add_nvdimm_bridge(struct device *host,
struct cxl_nvdimm *to_cxl_nvdimm(struct device *dev);
bool is_cxl_nvdimm(struct device *dev);
int devm_cxl_add_nvdimm(struct device *host, struct cxl_memdev *cxlmd);
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(void);
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_nvdimm *cxl_nvd);

/*
 * Unit test builds overrides this to __weak, find the 'strong' version
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ static int cxl_nvdimm_probe(struct device *dev)
	struct nvdimm *nvdimm;
	int rc;

	cxl_nvb = cxl_find_nvdimm_bridge();
	cxl_nvb = cxl_find_nvdimm_bridge(cxl_nvd);
	if (!cxl_nvb)
		return -ENXIO;

+2 −0
Original line number Diff line number Diff line
@@ -33,4 +33,6 @@ cxl_core-y += $(CXL_CORE_SRC)/memdev.o
cxl_core-y += $(CXL_CORE_SRC)/mbox.o
cxl_core-y += config_check.o

cxl_core-y += mock_pmem.o

obj-m += test/
+24 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright(c) 2021 Intel Corporation. All rights reserved. */
#include <cxl.h>
#include "test/mock.h"
#include <core/core.h>

int match_nvdimm_bridge(struct device *dev, const void *data)
{
	int index, rc = 0;
	struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
	const struct cxl_nvdimm *cxl_nvd = data;

	if (ops) {
		if (dev->type == &cxl_nvdimm_bridge_type &&
		    (ops->is_mock_dev(dev->parent->parent) ==
		     ops->is_mock_dev(cxl_nvd->dev.parent->parent)))
			rc = 1;
	} else
		rc = dev->type == &cxl_nvdimm_bridge_type;

	put_cxl_mock_ops(index);

	return rc;
}
Loading