Blame SOURCES/0203-cxl-list-Add-region-to-decoder-listings.patch

2eb93d
From dba61cf8bb9bb96cde8dcf2c9a2dcc663074698b Mon Sep 17 00:00:00 2001
2eb93d
From: Dan Williams <dan.j.williams@intel.com>
2eb93d
Date: Fri, 5 Aug 2022 13:38:08 -0700
2eb93d
Subject: [PATCH 203/217] cxl/list: Add region to decoder listings
2eb93d
2eb93d
While decoders can be matched with regions by physical address, or filtered
2eb93d
by region, it is also useful to get a plain listing of the association.
2eb93d
2eb93d
Link: https://lore.kernel.org/r/165973188860.1528532.17427805440366364536.stgit@dwillia2-xfh.jf.intel.com
2eb93d
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 Documentation/cxl/lib/libcxl.txt |  7 +++++++
2eb93d
 cxl/json.c                       |  8 ++++++++
2eb93d
 cxl/lib/libcxl.c                 | 34 ++++++++++++++++++++++++++++++++
2eb93d
 cxl/lib/libcxl.sym               |  1 +
2eb93d
 cxl/libcxl.h                     |  1 +
2eb93d
 5 files changed, 51 insertions(+)
2eb93d
2eb93d
diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
2eb93d
index 50b0c9c..6756d2f 100644
2eb93d
--- a/Documentation/cxl/lib/libcxl.txt
2eb93d
+++ b/Documentation/cxl/lib/libcxl.txt
2eb93d
@@ -398,6 +398,7 @@ int cxl_decoder_set_dpa_size(struct cxl_decoder *decoder, unsigned long long siz
2eb93d
 const char *cxl_decoder_get_devname(struct cxl_decoder *decoder);
2eb93d
 int cxl_decoder_get_id(struct cxl_decoder *decoder);
2eb93d
 int cxl_decoder_get_nr_targets(struct cxl_decoder *decoder);
2eb93d
+struct cxl_region *cxl_decoder_get_region(struct cxl_decoder *decoder);
2eb93d
 
2eb93d
 enum cxl_decoder_target_type {
2eb93d
        CXL_DECODER_TTYPE_UNKNOWN,
2eb93d
@@ -446,6 +447,12 @@ Platform firmware may setup the CXL decode hierarchy before the OS
2eb93d
 boots, and may additionally require that the OS not change the decode
2eb93d
 settings. This property is indicated by the cxl_decoder_is_locked() API.
2eb93d
 
2eb93d
+When a decoder is associated with a region cxl_decoder_get_region()
2eb93d
+returns that region object. Note that it is only applicable to switch
2eb93d
+and endpoint decoders as root decoders have a 1:N relationship with
2eb93d
+regions.  Use cxl_region_foreach() for the similar functionality for
2eb93d
+root decoders.
2eb93d
+
2eb93d
 ==== TARGETS
2eb93d
 A root or switch level decoder takes an SPA (system-physical-address) as
2eb93d
 input and routes it to a downstream port. Which downstream port depends
2eb93d
diff --git a/cxl/json.c b/cxl/json.c
2eb93d
index ada1dbe..c3d9299 100644
2eb93d
--- a/cxl/json.c
2eb93d
+++ b/cxl/json.c
2eb93d
@@ -442,6 +442,7 @@ struct json_object *util_cxl_decoder_to_json(struct cxl_decoder *decoder,
2eb93d
 	const char *devname = cxl_decoder_get_devname(decoder);
2eb93d
 	struct cxl_port *port = cxl_decoder_get_port(decoder);
2eb93d
 	struct json_object *jdecoder, *jobj;
2eb93d
+	struct cxl_region *region;
2eb93d
 	u64 val, size;
2eb93d
 
2eb93d
 	jdecoder = json_object_new_object();
2eb93d
@@ -486,6 +487,13 @@ struct json_object *util_cxl_decoder_to_json(struct cxl_decoder *decoder,
2eb93d
 		}
2eb93d
 	}
2eb93d
 
2eb93d
+	region = cxl_decoder_get_region(decoder);
2eb93d
+	if (region) {
2eb93d
+		jobj = json_object_new_string(cxl_region_get_devname(region));
2eb93d
+		if (jobj)
2eb93d
+			json_object_object_add(jdecoder, "region", jobj);
2eb93d
+	}
2eb93d
+
2eb93d
 	if (size == 0) {
2eb93d
 		jobj = json_object_new_string("disabled");
2eb93d
 		if (jobj)
2eb93d
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
2eb93d
index c7dc2b0..ff85b23 100644
2eb93d
--- a/cxl/lib/libcxl.c
2eb93d
+++ b/cxl/lib/libcxl.c
2eb93d
@@ -2124,6 +2124,40 @@ cxl_decoder_get_interleave_ways(struct cxl_decoder *decoder)
2eb93d
 	return decoder->interleave_ways;
2eb93d
 }
2eb93d
 
2eb93d
+CXL_EXPORT struct cxl_region *
2eb93d
+cxl_decoder_get_region(struct cxl_decoder *decoder)
2eb93d
+{
2eb93d
+	struct cxl_port *port = cxl_decoder_get_port(decoder);
2eb93d
+	struct cxl_ctx *ctx = cxl_decoder_get_ctx(decoder);
2eb93d
+	char *path = decoder->dev_buf;
2eb93d
+	char buf[SYSFS_ATTR_SIZE];
2eb93d
+	struct cxl_region *region;
2eb93d
+	struct cxl_decoder *iter;
2eb93d
+	int rc;
2eb93d
+
2eb93d
+	if (cxl_port_is_root(port))
2eb93d
+		return NULL;
2eb93d
+
2eb93d
+	sprintf(path, "%s/region", decoder->dev_path);
2eb93d
+	rc = sysfs_read_attr(ctx, path, buf);
2eb93d
+	if (rc < 0) {
2eb93d
+		err(ctx, "failed to read region name: %s\n", strerror(-rc));
2eb93d
+		return NULL;
2eb93d
+	}
2eb93d
+
2eb93d
+	if (strcmp(buf, "") == 0)
2eb93d
+		return NULL;
2eb93d
+
2eb93d
+	while (!cxl_port_is_root(port))
2eb93d
+		port = cxl_port_get_parent(port);
2eb93d
+
2eb93d
+	cxl_decoder_foreach(port, iter)
2eb93d
+		cxl_region_foreach(iter, region)
2eb93d
+			if (strcmp(cxl_region_get_devname(region), buf) == 0)
2eb93d
+				return region;
2eb93d
+	return NULL;
2eb93d
+}
2eb93d
+
2eb93d
 CXL_EXPORT struct cxl_region *
2eb93d
 cxl_decoder_create_pmem_region(struct cxl_decoder *decoder)
2eb93d
 {
2eb93d
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
2eb93d
index 549f88d..385a8f0 100644
2eb93d
--- a/cxl/lib/libcxl.sym
2eb93d
+++ b/cxl/lib/libcxl.sym
2eb93d
@@ -214,4 +214,5 @@ global:
2eb93d
 	cxl_decoder_get_interleave_granularity;
2eb93d
 	cxl_decoder_get_interleave_ways;
2eb93d
 	cxl_decoder_get_max_available_extent;
2eb93d
+	cxl_decoder_get_region;
2eb93d
 } LIBCXL_2;
2eb93d
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
2eb93d
index 61c7fc4..2498fa1 100644
2eb93d
--- a/cxl/libcxl.h
2eb93d
+++ b/cxl/libcxl.h
2eb93d
@@ -201,6 +201,7 @@ bool cxl_decoder_is_locked(struct cxl_decoder *decoder);
2eb93d
 unsigned int
2eb93d
 cxl_decoder_get_interleave_granularity(struct cxl_decoder *decoder);
2eb93d
 unsigned int cxl_decoder_get_interleave_ways(struct cxl_decoder *decoder);
2eb93d
+struct cxl_region *cxl_decoder_get_region(struct cxl_decoder *decoder);
2eb93d
 struct cxl_region *cxl_decoder_create_pmem_region(struct cxl_decoder *decoder);
2eb93d
 struct cxl_decoder *cxl_decoder_get_by_name(struct cxl_ctx *ctx,
2eb93d
 					    const char *ident);
2eb93d
-- 
2eb93d
2.27.0
2eb93d