2021-09-15 03:14:22 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
//Copyright(c) 2021 Intel Corporation. All rights reserved.
|
|
|
|
|
|
|
|
#include <linux/libnvdimm.h>
|
|
|
|
#include <linux/rculist.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/pci.h>
|
2022-02-01 10:10:04 +08:00
|
|
|
#include <cxlmem.h>
|
|
|
|
#include <cxlpci.h>
|
2021-09-15 03:14:22 +08:00
|
|
|
#include "mock.h"
|
|
|
|
|
|
|
|
static LIST_HEAD(mock);
|
|
|
|
|
|
|
|
void register_cxl_mock_ops(struct cxl_mock_ops *ops)
|
|
|
|
{
|
|
|
|
list_add_rcu(&ops->list, &mock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(register_cxl_mock_ops);
|
|
|
|
|
|
|
|
static DEFINE_SRCU(cxl_mock_srcu);
|
|
|
|
|
|
|
|
void unregister_cxl_mock_ops(struct cxl_mock_ops *ops)
|
|
|
|
{
|
|
|
|
list_del_rcu(&ops->list);
|
|
|
|
synchronize_srcu(&cxl_mock_srcu);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(unregister_cxl_mock_ops);
|
|
|
|
|
|
|
|
struct cxl_mock_ops *get_cxl_mock_ops(int *index)
|
|
|
|
{
|
|
|
|
*index = srcu_read_lock(&cxl_mock_srcu);
|
|
|
|
return list_first_or_null_rcu(&mock, struct cxl_mock_ops, list);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(get_cxl_mock_ops);
|
|
|
|
|
|
|
|
void put_cxl_mock_ops(int index)
|
|
|
|
{
|
|
|
|
srcu_read_unlock(&cxl_mock_srcu, index);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(put_cxl_mock_ops);
|
|
|
|
|
|
|
|
bool __wrap_is_acpi_device_node(const struct fwnode_handle *fwnode)
|
|
|
|
{
|
|
|
|
struct acpi_device *adev =
|
|
|
|
container_of(fwnode, struct acpi_device, fwnode);
|
|
|
|
int index;
|
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
bool retval = false;
|
|
|
|
|
|
|
|
if (ops)
|
|
|
|
retval = ops->is_mock_adev(adev);
|
|
|
|
|
|
|
|
if (!retval)
|
|
|
|
retval = is_acpi_device_node(fwnode);
|
|
|
|
|
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__wrap_is_acpi_device_node);
|
|
|
|
|
2021-10-30 03:51:53 +08:00
|
|
|
int __wrap_acpi_table_parse_cedt(enum acpi_cedt_type id,
|
|
|
|
acpi_tbl_entry_handler_arg handler_arg,
|
|
|
|
void *arg)
|
2021-09-15 03:14:22 +08:00
|
|
|
{
|
2021-10-30 03:51:53 +08:00
|
|
|
int index, rc;
|
2021-09-15 03:14:22 +08:00
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
|
|
|
|
if (ops)
|
2021-10-30 03:51:53 +08:00
|
|
|
rc = ops->acpi_table_parse_cedt(id, handler_arg, arg);
|
2021-09-15 03:14:22 +08:00
|
|
|
else
|
2021-10-30 03:51:53 +08:00
|
|
|
rc = acpi_table_parse_cedt(id, handler_arg, arg);
|
2021-09-15 03:14:22 +08:00
|
|
|
|
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
|
2021-10-30 03:51:53 +08:00
|
|
|
return rc;
|
2021-09-15 03:14:22 +08:00
|
|
|
}
|
2021-10-30 03:51:53 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(__wrap_acpi_table_parse_cedt, ACPI);
|
2021-09-15 03:14:22 +08:00
|
|
|
|
|
|
|
acpi_status __wrap_acpi_evaluate_integer(acpi_handle handle,
|
|
|
|
acpi_string pathname,
|
|
|
|
struct acpi_object_list *arguments,
|
|
|
|
unsigned long long *data)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
if (ops)
|
|
|
|
status = ops->acpi_evaluate_integer(handle, pathname, arguments,
|
|
|
|
data);
|
|
|
|
else
|
|
|
|
status = acpi_evaluate_integer(handle, pathname, arguments,
|
|
|
|
data);
|
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__wrap_acpi_evaluate_integer);
|
|
|
|
|
|
|
|
struct acpi_pci_root *__wrap_acpi_pci_find_root(acpi_handle handle)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
struct acpi_pci_root *root;
|
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
|
|
|
|
if (ops)
|
|
|
|
root = ops->acpi_pci_find_root(handle);
|
|
|
|
else
|
|
|
|
root = acpi_pci_find_root(handle);
|
|
|
|
|
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(__wrap_acpi_pci_find_root);
|
|
|
|
|
|
|
|
struct nvdimm_bus *
|
|
|
|
__wrap_nvdimm_bus_register(struct device *dev,
|
|
|
|
struct nvdimm_bus_descriptor *nd_desc)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
|
|
|
|
if (ops && ops->is_mock_dev(dev->parent->parent))
|
|
|
|
nd_desc->provider_name = "cxl_test";
|
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
|
|
|
|
return nvdimm_bus_register(dev, nd_desc);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(__wrap_nvdimm_bus_register);
|
|
|
|
|
2022-02-02 05:23:14 +08:00
|
|
|
struct cxl_hdm *__wrap_devm_cxl_setup_hdm(struct cxl_port *port)
|
2022-02-02 04:24:30 +08:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
struct cxl_hdm *cxlhdm;
|
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
|
|
|
|
if (ops && ops->is_mock_port(port->uport))
|
2022-02-02 05:23:14 +08:00
|
|
|
cxlhdm = ops->devm_cxl_setup_hdm(port);
|
2022-02-02 04:24:30 +08:00
|
|
|
else
|
2022-02-02 05:23:14 +08:00
|
|
|
cxlhdm = devm_cxl_setup_hdm(port);
|
2022-02-02 04:24:30 +08:00
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
|
|
|
|
return cxlhdm;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_setup_hdm, CXL);
|
|
|
|
|
2022-02-02 05:23:14 +08:00
|
|
|
int __wrap_devm_cxl_add_passthrough_decoder(struct cxl_port *port)
|
2022-02-02 04:24:30 +08:00
|
|
|
{
|
|
|
|
int rc, index;
|
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
|
|
|
|
if (ops && ops->is_mock_port(port->uport))
|
2022-02-02 05:23:14 +08:00
|
|
|
rc = ops->devm_cxl_add_passthrough_decoder(port);
|
2022-02-02 04:24:30 +08:00
|
|
|
else
|
2022-02-02 05:23:14 +08:00
|
|
|
rc = devm_cxl_add_passthrough_decoder(port);
|
2022-02-02 04:24:30 +08:00
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_add_passthrough_decoder, CXL);
|
|
|
|
|
2022-02-02 05:23:14 +08:00
|
|
|
int __wrap_devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm)
|
2022-02-02 04:24:30 +08:00
|
|
|
{
|
|
|
|
int rc, index;
|
|
|
|
struct cxl_port *port = cxlhdm->port;
|
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
|
|
|
|
if (ops && ops->is_mock_port(port->uport))
|
2022-02-02 05:23:14 +08:00
|
|
|
rc = ops->devm_cxl_enumerate_decoders(cxlhdm);
|
2022-02-02 04:24:30 +08:00
|
|
|
else
|
2022-02-02 05:23:14 +08:00
|
|
|
rc = devm_cxl_enumerate_decoders(cxlhdm);
|
2022-02-02 04:24:30 +08:00
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_enumerate_decoders, CXL);
|
|
|
|
|
2022-02-02 05:23:14 +08:00
|
|
|
int __wrap_devm_cxl_port_enumerate_dports(struct cxl_port *port)
|
2022-02-01 10:10:04 +08:00
|
|
|
{
|
|
|
|
int rc, index;
|
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
|
|
|
|
if (ops && ops->is_mock_port(port->uport))
|
2022-02-02 05:23:14 +08:00
|
|
|
rc = ops->devm_cxl_port_enumerate_dports(port);
|
2022-02-01 10:10:04 +08:00
|
|
|
else
|
2022-02-02 05:23:14 +08:00
|
|
|
rc = devm_cxl_port_enumerate_dports(port);
|
2022-02-01 10:10:04 +08:00
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_port_enumerate_dports, CXL);
|
|
|
|
|
2022-05-19 07:34:43 +08:00
|
|
|
int __wrap_cxl_await_media_ready(struct cxl_dev_state *cxlds)
|
|
|
|
{
|
|
|
|
int rc, index;
|
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
|
|
|
|
if (ops && ops->is_mock_dev(cxlds->dev))
|
|
|
|
rc = 0;
|
|
|
|
else
|
|
|
|
rc = cxl_await_media_ready(cxlds);
|
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_NS_GPL(__wrap_cxl_await_media_ready, CXL);
|
|
|
|
|
2022-06-22 16:00:45 +08:00
|
|
|
int __wrap_cxl_hdm_decode_init(struct cxl_dev_state *cxlds,
|
|
|
|
struct cxl_hdm *cxlhdm)
|
2022-05-19 07:34:48 +08:00
|
|
|
{
|
|
|
|
int rc = 0, index;
|
|
|
|
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
|
|
|
|
|
2022-06-22 16:00:45 +08:00
|
|
|
if (ops && ops->is_mock_dev(cxlds->dev))
|
|
|
|
rc = 0;
|
|
|
|
else
|
2022-05-19 07:35:17 +08:00
|
|
|
rc = cxl_hdm_decode_init(cxlds, cxlhdm);
|
2022-05-19 07:34:48 +08:00
|
|
|
put_cxl_mock_ops(index);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2022-05-19 07:35:00 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(__wrap_cxl_hdm_decode_init, CXL);
|
2022-05-19 07:34:48 +08:00
|
|
|
|
2021-09-15 03:14:22 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|
2021-10-30 03:51:53 +08:00
|
|
|
MODULE_IMPORT_NS(ACPI);
|
2022-02-01 10:10:04 +08:00
|
|
|
MODULE_IMPORT_NS(CXL);
|