Commit d96eb90d authored by Dave Jiang's avatar Dave Jiang
Browse files

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: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
Reviewed-by: default avatarJonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: default avatarLi Ming <ming.li@zohomail.com>
Tested-by: default avatarAlison Schofield <alison.schofield@intel.com>
Tested-by: default avatarRobert Richter <rrichter@amd.com>
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
parent 4f06d81e
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -146,8 +146,6 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,
int cxl_ras_init(void);
void cxl_ras_exit(void);
int cxl_gpf_port_setup(struct cxl_dport *dport);
struct cxl_dport *devm_cxl_add_dport_by_dev(struct cxl_port *port,
					    struct device *dport_dev);

struct cxl_hdm;
int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
+4 −3
Original line number Diff line number Diff line
@@ -41,13 +41,13 @@ static int pci_get_port_num(struct pci_dev *pdev)
}

/**
 * devm_cxl_add_dport_by_dev - allocate a dport by the dport device
 * __devm_cxl_add_dport_by_dev - allocate a dport by dport device
 * @port: cxl_port that hosts the dport
 * @dport_dev: 'struct device' of the dport
 *
 * Returns the allocated dport on success or ERR_PTR() of -errno on error
 */
struct cxl_dport *devm_cxl_add_dport_by_dev(struct cxl_port *port,
struct cxl_dport *__devm_cxl_add_dport_by_dev(struct cxl_port *port,
					      struct device *dport_dev)
{
	struct cxl_register_map map;
@@ -69,6 +69,7 @@ struct cxl_dport *devm_cxl_add_dport_by_dev(struct cxl_port *port,
	device_lock_assert(&port->dev);
	return devm_cxl_add_dport(port, dport_dev, port_num, map.resource);
}
EXPORT_SYMBOL_NS_GPL(__devm_cxl_add_dport_by_dev, "CXL");

struct cxl_walk_context {
	struct pci_bus *bus;
+20 −0
Original line number Diff line number Diff line
@@ -906,6 +906,10 @@ void cxl_coordinates_combine(struct access_coordinate *out,
			     struct access_coordinate *c2);

bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port);
struct cxl_dport *devm_cxl_add_dport_by_dev(struct cxl_port *port,
					    struct device *dport_dev);
struct cxl_dport *__devm_cxl_add_dport_by_dev(struct cxl_port *port,
					      struct device *dport_dev);

/*
 * Unit test builds overrides this to __weak, find the 'strong' version
@@ -916,4 +920,20 @@ bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port);
#endif

u16 cxl_gpf_get_dvsec(struct device *dev);

/*
 * Declaration for functions that are mocked by cxl_test that are called by
 * cxl_core. The respective functions are defined as __foo() and called by
 * cxl_core as foo(). The macros below ensures that those functions would
 * exist as foo(). See tools/testing/cxl/cxl_core_exports.c and
 * tools/testing/cxl/exports.h for setting up the mock functions. The dance
 * is done to avoid a circular dependency where cxl_core calls a function that
 * ends up being a mock function and goes to * cxl_test where it calls a
 * cxl_core function.
 */
#ifndef CXL_TEST_ENABLE
#define DECLARE_TESTABLE(x) __##x
#define devm_cxl_add_dport_by_dev DECLARE_TESTABLE(devm_cxl_add_dport_by_dev)
#endif

#endif /* __CXL_H__ */
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ CXL_SRC := $(DRIVERS)/cxl
CXL_CORE_SRC := $(DRIVERS)/cxl/core
ccflags-y := -I$(srctree)/drivers/cxl/
ccflags-y += -D__mock=__weak
ccflags-y += -DCXL_TEST_ENABLE=1
ccflags-y += -DTRACE_INCLUDE_PATH=$(CXL_CORE_SRC) -I$(srctree)/drivers/cxl/core/

obj-m += cxl_acpi.o
+12 −0
Original line number Diff line number Diff line
@@ -2,6 +2,18 @@
/* Copyright(c) 2022 Intel Corporation. All rights reserved. */

#include "cxl.h"
#include "exports.h"

/* Exporting of cxl_core symbols that are only used by cxl_test */
EXPORT_SYMBOL_NS_GPL(cxl_num_decoders_committed, "CXL");

cxl_add_dport_by_dev_fn _devm_cxl_add_dport_by_dev =
	__devm_cxl_add_dport_by_dev;
EXPORT_SYMBOL_NS_GPL(_devm_cxl_add_dport_by_dev, "CXL");

struct cxl_dport *devm_cxl_add_dport_by_dev(struct cxl_port *port,
					    struct device *dport_dev)
{
	return _devm_cxl_add_dport_by_dev(port, dport_dev);
}
EXPORT_SYMBOL_NS_GPL(devm_cxl_add_dport_by_dev, "CXL");
Loading