1 // SPDX-License-Identifier: GPL-2.0-only
2 //Copyright(c) 2021 Intel Corporation. All rights reserved.
4 #include <linux/libnvdimm.h>
5 #include <linux/rculist.h>
6 #include <linux/device.h>
7 #include <linux/export.h>
8 #include <linux/acpi.h>
14 static LIST_HEAD(mock
);
16 void register_cxl_mock_ops(struct cxl_mock_ops
*ops
)
18 list_add_rcu(&ops
->list
, &mock
);
20 EXPORT_SYMBOL_GPL(register_cxl_mock_ops
);
22 DEFINE_STATIC_SRCU(cxl_mock_srcu
);
24 void unregister_cxl_mock_ops(struct cxl_mock_ops
*ops
)
26 list_del_rcu(&ops
->list
);
27 synchronize_srcu(&cxl_mock_srcu
);
29 EXPORT_SYMBOL_GPL(unregister_cxl_mock_ops
);
31 struct cxl_mock_ops
*get_cxl_mock_ops(int *index
)
33 *index
= srcu_read_lock(&cxl_mock_srcu
);
34 return list_first_or_null_rcu(&mock
, struct cxl_mock_ops
, list
);
36 EXPORT_SYMBOL_GPL(get_cxl_mock_ops
);
38 void put_cxl_mock_ops(int index
)
40 srcu_read_unlock(&cxl_mock_srcu
, index
);
42 EXPORT_SYMBOL_GPL(put_cxl_mock_ops
);
44 bool __wrap_is_acpi_device_node(const struct fwnode_handle
*fwnode
)
46 struct acpi_device
*adev
=
47 container_of(fwnode
, struct acpi_device
, fwnode
);
49 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
53 retval
= ops
->is_mock_adev(adev
);
56 retval
= is_acpi_device_node(fwnode
);
58 put_cxl_mock_ops(index
);
61 EXPORT_SYMBOL(__wrap_is_acpi_device_node
);
63 int __wrap_acpi_table_parse_cedt(enum acpi_cedt_type id
,
64 acpi_tbl_entry_handler_arg handler_arg
,
68 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
71 rc
= ops
->acpi_table_parse_cedt(id
, handler_arg
, arg
);
73 rc
= acpi_table_parse_cedt(id
, handler_arg
, arg
);
75 put_cxl_mock_ops(index
);
79 EXPORT_SYMBOL_NS_GPL(__wrap_acpi_table_parse_cedt
, "ACPI");
81 acpi_status
__wrap_acpi_evaluate_integer(acpi_handle handle
,
83 struct acpi_object_list
*arguments
,
84 unsigned long long *data
)
87 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
91 status
= ops
->acpi_evaluate_integer(handle
, pathname
, arguments
,
94 status
= acpi_evaluate_integer(handle
, pathname
, arguments
,
96 put_cxl_mock_ops(index
);
100 EXPORT_SYMBOL(__wrap_acpi_evaluate_integer
);
102 struct acpi_pci_root
*__wrap_acpi_pci_find_root(acpi_handle handle
)
105 struct acpi_pci_root
*root
;
106 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
109 root
= ops
->acpi_pci_find_root(handle
);
111 root
= acpi_pci_find_root(handle
);
113 put_cxl_mock_ops(index
);
117 EXPORT_SYMBOL_GPL(__wrap_acpi_pci_find_root
);
120 __wrap_nvdimm_bus_register(struct device
*dev
,
121 struct nvdimm_bus_descriptor
*nd_desc
)
124 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
126 if (ops
&& ops
->is_mock_dev(dev
->parent
->parent
))
127 nd_desc
->provider_name
= "cxl_test";
128 put_cxl_mock_ops(index
);
130 return nvdimm_bus_register(dev
, nd_desc
);
132 EXPORT_SYMBOL_GPL(__wrap_nvdimm_bus_register
);
134 struct cxl_hdm
*__wrap_devm_cxl_setup_hdm(struct cxl_port
*port
,
135 struct cxl_endpoint_dvsec_info
*info
)
139 struct cxl_hdm
*cxlhdm
;
140 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
142 if (ops
&& ops
->is_mock_port(port
->uport_dev
))
143 cxlhdm
= ops
->devm_cxl_setup_hdm(port
, info
);
145 cxlhdm
= devm_cxl_setup_hdm(port
, info
);
146 put_cxl_mock_ops(index
);
150 EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_setup_hdm
, "CXL");
152 int __wrap_devm_cxl_add_passthrough_decoder(struct cxl_port
*port
)
155 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
157 if (ops
&& ops
->is_mock_port(port
->uport_dev
))
158 rc
= ops
->devm_cxl_add_passthrough_decoder(port
);
160 rc
= devm_cxl_add_passthrough_decoder(port
);
161 put_cxl_mock_ops(index
);
165 EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_add_passthrough_decoder
, "CXL");
167 int __wrap_devm_cxl_enumerate_decoders(struct cxl_hdm
*cxlhdm
,
168 struct cxl_endpoint_dvsec_info
*info
)
171 struct cxl_port
*port
= cxlhdm
->port
;
172 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
174 if (ops
&& ops
->is_mock_port(port
->uport_dev
))
175 rc
= ops
->devm_cxl_enumerate_decoders(cxlhdm
, info
);
177 rc
= devm_cxl_enumerate_decoders(cxlhdm
, info
);
178 put_cxl_mock_ops(index
);
182 EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_enumerate_decoders
, "CXL");
184 int __wrap_devm_cxl_port_enumerate_dports(struct cxl_port
*port
)
187 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
189 if (ops
&& ops
->is_mock_port(port
->uport_dev
))
190 rc
= ops
->devm_cxl_port_enumerate_dports(port
);
192 rc
= devm_cxl_port_enumerate_dports(port
);
193 put_cxl_mock_ops(index
);
197 EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_port_enumerate_dports
, "CXL");
199 int __wrap_cxl_await_media_ready(struct cxl_dev_state
*cxlds
)
202 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
204 if (ops
&& ops
->is_mock_dev(cxlds
->dev
))
207 rc
= cxl_await_media_ready(cxlds
);
208 put_cxl_mock_ops(index
);
212 EXPORT_SYMBOL_NS_GPL(__wrap_cxl_await_media_ready
, "CXL");
214 int __wrap_cxl_hdm_decode_init(struct cxl_dev_state
*cxlds
,
215 struct cxl_hdm
*cxlhdm
,
216 struct cxl_endpoint_dvsec_info
*info
)
219 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
221 if (ops
&& ops
->is_mock_dev(cxlds
->dev
))
224 rc
= cxl_hdm_decode_init(cxlds
, cxlhdm
, info
);
225 put_cxl_mock_ops(index
);
229 EXPORT_SYMBOL_NS_GPL(__wrap_cxl_hdm_decode_init
, "CXL");
231 int __wrap_cxl_dvsec_rr_decode(struct device
*dev
, struct cxl_port
*port
,
232 struct cxl_endpoint_dvsec_info
*info
)
235 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
237 if (ops
&& ops
->is_mock_dev(dev
))
240 rc
= cxl_dvsec_rr_decode(dev
, port
, info
);
241 put_cxl_mock_ops(index
);
245 EXPORT_SYMBOL_NS_GPL(__wrap_cxl_dvsec_rr_decode
, "CXL");
247 struct cxl_dport
*__wrap_devm_cxl_add_rch_dport(struct cxl_port
*port
,
248 struct device
*dport_dev
,
250 resource_size_t rcrb
)
253 struct cxl_dport
*dport
;
254 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
256 if (ops
&& ops
->is_mock_port(dport_dev
)) {
257 dport
= devm_cxl_add_dport(port
, dport_dev
, port_id
,
259 if (!IS_ERR(dport
)) {
260 dport
->rcrb
.base
= rcrb
;
264 dport
= devm_cxl_add_rch_dport(port
, dport_dev
, port_id
, rcrb
);
265 put_cxl_mock_ops(index
);
269 EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_add_rch_dport
, "CXL");
271 resource_size_t
__wrap_cxl_rcd_component_reg_phys(struct device
*dev
,
272 struct cxl_dport
*dport
)
275 resource_size_t component_reg_phys
;
276 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
278 if (ops
&& ops
->is_mock_port(dev
))
279 component_reg_phys
= CXL_RESOURCE_NONE
;
281 component_reg_phys
= cxl_rcd_component_reg_phys(dev
, dport
);
282 put_cxl_mock_ops(index
);
284 return component_reg_phys
;
286 EXPORT_SYMBOL_NS_GPL(__wrap_cxl_rcd_component_reg_phys
, "CXL");
288 void __wrap_cxl_endpoint_parse_cdat(struct cxl_port
*port
)
291 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
292 struct cxl_memdev
*cxlmd
= to_cxl_memdev(port
->uport_dev
);
294 if (ops
&& ops
->is_mock_dev(cxlmd
->dev
.parent
))
295 ops
->cxl_endpoint_parse_cdat(port
);
297 cxl_endpoint_parse_cdat(port
);
298 put_cxl_mock_ops(index
);
300 EXPORT_SYMBOL_NS_GPL(__wrap_cxl_endpoint_parse_cdat
, "CXL");
302 void __wrap_cxl_dport_init_ras_reporting(struct cxl_dport
*dport
, struct device
*host
)
305 struct cxl_mock_ops
*ops
= get_cxl_mock_ops(&index
);
307 if (!ops
|| !ops
->is_mock_port(dport
->dport_dev
))
308 cxl_dport_init_ras_reporting(dport
, host
);
310 put_cxl_mock_ops(index
);
312 EXPORT_SYMBOL_NS_GPL(__wrap_cxl_dport_init_ras_reporting
, "CXL");
314 MODULE_LICENSE("GPL v2");
315 MODULE_IMPORT_NS("ACPI");
316 MODULE_IMPORT_NS("CXL");