Skip to content

Commit 3e422ca

Browse files
Robert Richterdavejiang
authored andcommitted
cxl: Simplify cxl_root_ops allocation and handling
A root port's callback handlers are collected in struct cxl_root_ops. The structure is dynamically allocated, though it contains only a single pointer in it. This also requires to check two pointers to check for the existance of a callback. Simplify the allocation, release and handler check by embedding the ops statically in struct cxl_root. Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Signed-off-by: Robert Richter <rrichter@amd.com> Link: https://patch.msgid.link/20260114164837.1076338-5-rrichter@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 98ceb1a commit 3e422ca

4 files changed

Lines changed: 18 additions & 24 deletions

File tree

drivers/cxl/acpi.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,6 @@ static int cxl_acpi_qos_class(struct cxl_root *cxl_root,
318318
return cxl_acpi_evaluate_qtg_dsm(handle, coord, entries, qos_class);
319319
}
320320

321-
static const struct cxl_root_ops acpi_root_ops = {
322-
.qos_class = cxl_acpi_qos_class,
323-
};
324-
325321
static void del_cxl_resource(struct resource *res)
326322
{
327323
if (!res)
@@ -923,9 +919,10 @@ static int cxl_acpi_probe(struct platform_device *pdev)
923919
cxl_res->end = -1;
924920
cxl_res->flags = IORESOURCE_MEM;
925921

926-
cxl_root = devm_cxl_add_root(host, &acpi_root_ops);
922+
cxl_root = devm_cxl_add_root(host);
927923
if (IS_ERR(cxl_root))
928924
return PTR_ERR(cxl_root);
925+
cxl_root->ops.qos_class = cxl_acpi_qos_class;
929926
root_port = &cxl_root->port;
930927

931928
rc = bus_for_each_dev(adev->dev.bus, NULL, root_port,

drivers/cxl/core/cdat.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,17 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
213213
if (!cxl_root)
214214
return -ENODEV;
215215

216-
if (!cxl_root->ops || !cxl_root->ops->qos_class)
216+
if (!cxl_root->ops.qos_class)
217217
return -EOPNOTSUPP;
218218

219219
xa_for_each(dsmas_xa, index, dent) {
220220
int qos_class;
221221

222222
cxl_coordinates_combine(dent->coord, dent->cdat_coord, ep_c);
223223
dent->entries = 1;
224-
rc = cxl_root->ops->qos_class(cxl_root,
225-
&dent->coord[ACCESS_COORDINATE_CPU],
226-
1, &qos_class);
224+
rc = cxl_root->ops.qos_class(cxl_root,
225+
&dent->coord[ACCESS_COORDINATE_CPU],
226+
1, &qos_class);
227227
if (rc != 1)
228228
continue;
229229

drivers/cxl/core/port.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -954,19 +954,15 @@ struct cxl_port *devm_cxl_add_port(struct device *host,
954954
}
955955
EXPORT_SYMBOL_NS_GPL(devm_cxl_add_port, "CXL");
956956

957-
struct cxl_root *devm_cxl_add_root(struct device *host,
958-
const struct cxl_root_ops *ops)
957+
struct cxl_root *devm_cxl_add_root(struct device *host)
959958
{
960-
struct cxl_root *cxl_root;
961959
struct cxl_port *port;
962960

963961
port = devm_cxl_add_port(host, host, CXL_RESOURCE_NONE, NULL);
964962
if (IS_ERR(port))
965963
return ERR_CAST(port);
966964

967-
cxl_root = to_cxl_root(port);
968-
cxl_root->ops = ops;
969-
return cxl_root;
965+
return to_cxl_root(port);
970966
}
971967
EXPORT_SYMBOL_NS_GPL(devm_cxl_add_root, "CXL");
972968

drivers/cxl/cxl.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,14 @@ struct cxl_port {
646646
resource_size_t component_reg_phys;
647647
};
648648

649+
struct cxl_root;
650+
651+
struct cxl_root_ops {
652+
int (*qos_class)(struct cxl_root *cxl_root,
653+
struct access_coordinate *coord, int entries,
654+
int *qos_class);
655+
};
656+
649657
/**
650658
* struct cxl_root - logical collection of root cxl_port items
651659
*
@@ -654,7 +662,7 @@ struct cxl_port {
654662
*/
655663
struct cxl_root {
656664
struct cxl_port port;
657-
const struct cxl_root_ops *ops;
665+
struct cxl_root_ops ops;
658666
};
659667

660668
static inline struct cxl_root *
@@ -663,12 +671,6 @@ to_cxl_root(const struct cxl_port *port)
663671
return container_of(port, struct cxl_root, port);
664672
}
665673

666-
struct cxl_root_ops {
667-
int (*qos_class)(struct cxl_root *cxl_root,
668-
struct access_coordinate *coord, int entries,
669-
int *qos_class);
670-
};
671-
672674
static inline struct cxl_dport *
673675
cxl_find_dport_by_dev(struct cxl_port *port, const struct device *dport_dev)
674676
{
@@ -782,8 +784,7 @@ struct cxl_port *devm_cxl_add_port(struct device *host,
782784
struct device *uport_dev,
783785
resource_size_t component_reg_phys,
784786
struct cxl_dport *parent_dport);
785-
struct cxl_root *devm_cxl_add_root(struct device *host,
786-
const struct cxl_root_ops *ops);
787+
struct cxl_root *devm_cxl_add_root(struct device *host);
787788
struct cxl_root *find_cxl_root(struct cxl_port *port);
788789

789790
DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_device(&_T->port.dev))

0 commit comments

Comments
 (0)