Skip to content

Commit 7908159

Browse files
davejiangdjbw
authored andcommitted
cxl: Add support for _DSM Function for retrieving QTG ID
CXL spec v3.0 9.17.3 CXL Root Device Specific Methods (_DSM) Add support to retrieve QTG ID via ACPI _DSM call. The _DSM call requires an input of an ACPI package with 4 dwords (read latency, write latency, read bandwidth, write bandwidth). The call returns a package with 1 WORD that provides the max supported QTG ID and a package that may contain 0 or more WORDs as the recommended QTG IDs in the recommended order. Create a cxl_root container for the root cxl_port and provide a callback ->get_qos_class() in order to retrieve the QoS class. For the ACPI case, the _DSM helper is used to retrieve the QTG ID and returned. A devm_cxl_add_root() function is added for root port setup and registration of the cxl_root callback operation(s). Signed-off-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/170319621294.2212653.1649682083061569256.stgit@djiang5-mobl3 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 80aa780 commit 7908159

3 files changed

Lines changed: 193 additions & 13 deletions

File tree

drivers/cxl/acpi.c

Lines changed: 129 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/kernel.h>
77
#include <linux/acpi.h>
88
#include <linux/pci.h>
9+
#include <linux/node.h>
910
#include <asm/div64.h>
1011
#include "cxlpci.h"
1112
#include "cxl.h"
@@ -17,6 +18,10 @@ struct cxl_cxims_data {
1718
u64 xormaps[] __counted_by(nr_maps);
1819
};
1920

21+
static const guid_t acpi_cxl_qtg_id_guid =
22+
GUID_INIT(0xF365F9A6, 0xA7DE, 0x4071,
23+
0xA6, 0x6A, 0xB4, 0x0C, 0x0B, 0x4F, 0x8E, 0x52);
24+
2025
/*
2126
* Find a targets entry (n) in the host bridge interleave list.
2227
* CXL Specification 3.0 Table 9-22
@@ -194,6 +199,125 @@ struct cxl_cfmws_context {
194199
int id;
195200
};
196201

202+
/**
203+
* cxl_acpi_evaluate_qtg_dsm - Retrieve QTG ids via ACPI _DSM
204+
* @handle: ACPI handle
205+
* @coord: performance access coordinates
206+
* @entries: number of QTG IDs to return
207+
* @qos_class: int array provided by caller to return QTG IDs
208+
*
209+
* Return: number of QTG IDs returned, or -errno for errors
210+
*
211+
* Issue QTG _DSM with accompanied bandwidth and latency data in order to get
212+
* the QTG IDs that are suitable for the performance point in order of most
213+
* suitable to least suitable. Write back array of QTG IDs and return the
214+
* actual number of QTG IDs written back.
215+
*/
216+
static int
217+
cxl_acpi_evaluate_qtg_dsm(acpi_handle handle, struct access_coordinate *coord,
218+
int entries, int *qos_class)
219+
{
220+
union acpi_object *out_obj, *out_buf, *obj;
221+
union acpi_object in_array[4] = {
222+
[0].integer = { ACPI_TYPE_INTEGER, coord->read_latency },
223+
[1].integer = { ACPI_TYPE_INTEGER, coord->write_latency },
224+
[2].integer = { ACPI_TYPE_INTEGER, coord->read_bandwidth },
225+
[3].integer = { ACPI_TYPE_INTEGER, coord->write_bandwidth },
226+
};
227+
union acpi_object in_obj = {
228+
.package = {
229+
.type = ACPI_TYPE_PACKAGE,
230+
.count = 4,
231+
.elements = in_array,
232+
},
233+
};
234+
int count, pkg_entries, i;
235+
u16 max_qtg;
236+
int rc;
237+
238+
if (!entries)
239+
return -EINVAL;
240+
241+
out_obj = acpi_evaluate_dsm(handle, &acpi_cxl_qtg_id_guid, 1, 1, &in_obj);
242+
if (!out_obj)
243+
return -ENXIO;
244+
245+
if (out_obj->type != ACPI_TYPE_PACKAGE) {
246+
rc = -ENXIO;
247+
goto out;
248+
}
249+
250+
/* Check Max QTG ID */
251+
obj = &out_obj->package.elements[0];
252+
if (obj->type != ACPI_TYPE_INTEGER) {
253+
rc = -ENXIO;
254+
goto out;
255+
}
256+
257+
max_qtg = obj->integer.value;
258+
259+
/* It's legal to have 0 QTG entries */
260+
pkg_entries = out_obj->package.count;
261+
if (pkg_entries <= 1) {
262+
rc = 0;
263+
goto out;
264+
}
265+
266+
/* Retrieve QTG IDs package */
267+
obj = &out_obj->package.elements[1];
268+
if (obj->type != ACPI_TYPE_PACKAGE) {
269+
rc = -ENXIO;
270+
goto out;
271+
}
272+
273+
pkg_entries = obj->package.count;
274+
count = min(entries, pkg_entries);
275+
for (i = 0; i < count; i++) {
276+
u16 qtg_id;
277+
278+
out_buf = &obj->package.elements[i];
279+
if (out_buf->type != ACPI_TYPE_INTEGER) {
280+
rc = -ENXIO;
281+
goto out;
282+
}
283+
284+
qtg_id = out_buf->integer.value;
285+
if (qtg_id > max_qtg)
286+
pr_warn("QTG ID %u greater than MAX %u\n",
287+
qtg_id, max_qtg);
288+
289+
qos_class[i] = qtg_id;
290+
}
291+
rc = count;
292+
293+
out:
294+
ACPI_FREE(out_obj);
295+
return rc;
296+
}
297+
298+
static int cxl_acpi_qos_class(struct cxl_port *root_port,
299+
struct access_coordinate *coord, int entries,
300+
int *qos_class)
301+
{
302+
acpi_handle handle;
303+
struct device *dev;
304+
305+
dev = root_port->uport_dev;
306+
307+
if (!dev_is_platform(dev))
308+
return -ENODEV;
309+
310+
handle = ACPI_HANDLE(dev);
311+
if (!handle)
312+
return -ENODEV;
313+
314+
return cxl_acpi_evaluate_qtg_dsm(handle, coord, entries, qos_class);
315+
}
316+
317+
static const struct cxl_root_ops acpi_root_ops = {
318+
.qos_class = cxl_acpi_qos_class,
319+
};
320+
197321
static int cxl_parse_cfmws(union acpi_subtable_headers *header, void *arg,
198322
const unsigned long end)
199323
{
@@ -656,6 +780,7 @@ static int cxl_acpi_probe(struct platform_device *pdev)
656780
{
657781
int rc;
658782
struct resource *cxl_res;
783+
struct cxl_root *cxl_root;
659784
struct cxl_port *root_port;
660785
struct device *host = &pdev->dev;
661786
struct acpi_device *adev = ACPI_COMPANION(host);
@@ -675,9 +800,10 @@ static int cxl_acpi_probe(struct platform_device *pdev)
675800
cxl_res->end = -1;
676801
cxl_res->flags = IORESOURCE_MEM;
677802

678-
root_port = devm_cxl_add_port(host, host, CXL_RESOURCE_NONE, NULL);
679-
if (IS_ERR(root_port))
680-
return PTR_ERR(root_port);
803+
cxl_root = devm_cxl_add_root(host, &acpi_root_ops);
804+
if (IS_ERR(cxl_root))
805+
return PTR_ERR(cxl_root);
806+
root_port = &cxl_root->port;
681807

682808
rc = bus_for_each_dev(adev->dev.bus, NULL, root_port,
683809
add_host_bridge_dport);

drivers/cxl/core/port.c

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,10 @@ static void cxl_port_release(struct device *dev)
541541
xa_destroy(&port->dports);
542542
xa_destroy(&port->regions);
543543
ida_free(&cxl_port_ida, port->id);
544-
kfree(port);
544+
if (is_cxl_root(port))
545+
kfree(to_cxl_root(port));
546+
else
547+
kfree(port);
545548
}
546549

547550
static ssize_t decoders_committed_show(struct device *dev,
@@ -669,17 +672,31 @@ static struct lock_class_key cxl_port_key;
669672
static struct cxl_port *cxl_port_alloc(struct device *uport_dev,
670673
struct cxl_dport *parent_dport)
671674
{
672-
struct cxl_port *port;
675+
struct cxl_root *cxl_root __free(kfree) = NULL;
676+
struct cxl_port *port, *_port __free(kfree) = NULL;
673677
struct device *dev;
674678
int rc;
675679

676-
port = kzalloc(sizeof(*port), GFP_KERNEL);
677-
if (!port)
678-
return ERR_PTR(-ENOMEM);
680+
/* No parent_dport, root cxl_port */
681+
if (!parent_dport) {
682+
cxl_root = kzalloc(sizeof(*cxl_root), GFP_KERNEL);
683+
if (!cxl_root)
684+
return ERR_PTR(-ENOMEM);
685+
} else {
686+
_port = kzalloc(sizeof(*port), GFP_KERNEL);
687+
if (!_port)
688+
return ERR_PTR(-ENOMEM);
689+
}
679690

680691
rc = ida_alloc(&cxl_port_ida, GFP_KERNEL);
681692
if (rc < 0)
682-
goto err;
693+
return ERR_PTR(rc);
694+
695+
if (cxl_root)
696+
port = &no_free_ptr(cxl_root)->port;
697+
else
698+
port = no_free_ptr(_port);
699+
683700
port->id = rc;
684701
port->uport_dev = uport_dev;
685702

@@ -731,10 +748,6 @@ static struct cxl_port *cxl_port_alloc(struct device *uport_dev,
731748
dev->type = &cxl_port_type;
732749

733750
return port;
734-
735-
err:
736-
kfree(port);
737-
return ERR_PTR(rc);
738751
}
739752

740753
static int cxl_setup_comp_regs(struct device *host, struct cxl_register_map *map,
@@ -884,6 +897,22 @@ struct cxl_port *devm_cxl_add_port(struct device *host,
884897
}
885898
EXPORT_SYMBOL_NS_GPL(devm_cxl_add_port, CXL);
886899

900+
struct cxl_root *devm_cxl_add_root(struct device *host,
901+
const struct cxl_root_ops *ops)
902+
{
903+
struct cxl_root *cxl_root;
904+
struct cxl_port *port;
905+
906+
port = devm_cxl_add_port(host, host, CXL_RESOURCE_NONE, NULL);
907+
if (IS_ERR(port))
908+
return (struct cxl_root *)port;
909+
910+
cxl_root = to_cxl_root(port);
911+
cxl_root->ops = ops;
912+
return cxl_root;
913+
}
914+
EXPORT_SYMBOL_NS_GPL(devm_cxl_add_root, CXL);
915+
887916
struct pci_bus *cxl_port_to_pci_bus(struct cxl_port *port)
888917
{
889918
/* There is no pci_bus associated with a CXL platform-root port */

drivers/cxl/cxl.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,29 @@ struct cxl_port {
615615
bool cdat_available;
616616
};
617617

618+
struct cxl_root_ops {
619+
int (*qos_class)(struct cxl_port *root_port,
620+
struct access_coordinate *coord, int entries,
621+
int *qos_class);
622+
};
623+
624+
/**
625+
* struct cxl_root - logical collection of root cxl_port items
626+
*
627+
* @port: cxl_port member
628+
* @ops: cxl root operations
629+
*/
630+
struct cxl_root {
631+
struct cxl_port port;
632+
const struct cxl_root_ops *ops;
633+
};
634+
635+
static inline struct cxl_root *
636+
to_cxl_root(const struct cxl_port *port)
637+
{
638+
return container_of(port, struct cxl_root, port);
639+
}
640+
618641
static inline struct cxl_dport *
619642
cxl_find_dport_by_dev(struct cxl_port *port, const struct device *dport_dev)
620643
{
@@ -703,6 +726,8 @@ struct cxl_port *devm_cxl_add_port(struct device *host,
703726
struct device *uport_dev,
704727
resource_size_t component_reg_phys,
705728
struct cxl_dport *parent_dport);
729+
struct cxl_root *devm_cxl_add_root(struct device *host,
730+
const struct cxl_root_ops *ops);
706731
struct cxl_port *find_cxl_root(struct cxl_port *port);
707732
int devm_cxl_enumerate_ports(struct cxl_memdev *cxlmd);
708733
void cxl_bus_rescan(void);

0 commit comments

Comments
 (0)