mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
cxl/test: Add mock version of devm_cxl_add_dport_by_dev()
devm_cxl_add_dport_by_dev() outside of cxl_test is done through PCI hierarchy. However with cxl_test, it needs to be done through the platform device hierarchy. Add the mock function for devm_cxl_add_dport_by_dev(). When cxl_core calls a cxl_core exported function and that function is mocked by cxl_test, the call chain causes a circular dependency issue. Dan provided a workaround to avoid this issue. Apply the method to changes from the late dport allocation changes in order to enable cxl-test. In cxl_core they are defined with "__" added in front of the function. A macro is used to define the original function names for when non-test version of the kernel is built. A bit of macros and typedefs are used to allow mocking of those functions in cxl_test. Co-developed-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Li Ming <ming.li@zohomail.com> Tested-by: Alison Schofield <alison.schofield@intel.com> Tested-by: Robert Richter <rrichter@amd.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
This commit is contained in:
@@ -944,10 +944,12 @@ static int mock_cxl_endpoint_decoders_setup(struct cxl_port *port)
|
||||
return __mock_cxl_decoders_setup(port);
|
||||
}
|
||||
|
||||
static int mock_cxl_port_enumerate_dports(struct cxl_port *port)
|
||||
static int get_port_array(struct cxl_port *port,
|
||||
struct platform_device ***port_array,
|
||||
int *port_array_size)
|
||||
{
|
||||
struct platform_device **array;
|
||||
int i, array_size;
|
||||
int array_size;
|
||||
|
||||
if (port->depth == 1) {
|
||||
if (is_multi_bridge(port->uport_dev)) {
|
||||
@@ -981,6 +983,22 @@ static int mock_cxl_port_enumerate_dports(struct cxl_port *port)
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
*port_array = array;
|
||||
*port_array_size = array_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mock_cxl_port_enumerate_dports(struct cxl_port *port)
|
||||
{
|
||||
struct platform_device **array;
|
||||
int i, array_size;
|
||||
int rc;
|
||||
|
||||
rc = get_port_array(port, &array, &array_size);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
for (i = 0; i < array_size; i++) {
|
||||
struct platform_device *pdev = array[i];
|
||||
struct cxl_dport *dport;
|
||||
@@ -1002,6 +1020,36 @@ static int mock_cxl_port_enumerate_dports(struct cxl_port *port)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct cxl_dport *mock_cxl_add_dport_by_dev(struct cxl_port *port,
|
||||
struct device *dport_dev)
|
||||
{
|
||||
struct platform_device **array;
|
||||
int rc, i, array_size;
|
||||
|
||||
rc = get_port_array(port, &array, &array_size);
|
||||
if (rc)
|
||||
return ERR_PTR(rc);
|
||||
|
||||
for (i = 0; i < array_size; i++) {
|
||||
struct platform_device *pdev = array[i];
|
||||
|
||||
if (pdev->dev.parent != port->uport_dev) {
|
||||
dev_dbg(&port->dev, "%s: mismatch parent %s\n",
|
||||
dev_name(port->uport_dev),
|
||||
dev_name(pdev->dev.parent));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (&pdev->dev != dport_dev)
|
||||
continue;
|
||||
|
||||
return devm_cxl_add_dport(port, &pdev->dev, pdev->id,
|
||||
CXL_RESOURCE_NONE);
|
||||
}
|
||||
|
||||
return ERR_PTR(-ENODEV);
|
||||
}
|
||||
|
||||
/*
|
||||
* Faking the cxl_dpa_perf for the memdev when appropriate.
|
||||
*/
|
||||
@@ -1062,6 +1110,7 @@ static struct cxl_mock_ops cxl_mock_ops = {
|
||||
.devm_cxl_endpoint_decoders_setup = mock_cxl_endpoint_decoders_setup,
|
||||
.devm_cxl_port_enumerate_dports = mock_cxl_port_enumerate_dports,
|
||||
.cxl_endpoint_parse_cdat = mock_cxl_endpoint_parse_cdat,
|
||||
.devm_cxl_add_dport_by_dev = mock_cxl_add_dport_by_dev,
|
||||
.list = LIST_HEAD_INIT(cxl_mock_ops.list),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user