diff mbox series

[v2,01/15] cxl: Modify address translation callback for generic use

Message ID 20250218132356.1809075-2-rrichter@amd.com
State New
Headers show
Series cxl: Address translation support, part 2: Generic support and AMD Zen5 platform enablement | expand

Commit Message

Robert Richter Feb. 18, 2025, 1:23 p.m. UTC
The root decoder address translation callback could be reused for
other decoders too. For generic use of the callback, change the
function interface to use a decoder argument instead of the root
decoder.

Note that a root decoder's HPA is equal to its SPA, but else it may be
different. Thus, change the name of the function type to
cxl_to_hpa_fn.

Signed-off-by: Robert Richter <rrichter@amd.com>
---
 drivers/cxl/acpi.c        | 4 ++--
 drivers/cxl/core/region.c | 7 +++++--
 drivers/cxl/cxl.h         | 5 ++---
 3 files changed, 9 insertions(+), 7 deletions(-)

Comments

Gregory Price Feb. 20, 2025, 4 p.m. UTC | #1
On Tue, Feb 18, 2025 at 02:23:42PM +0100, Robert Richter wrote:
> The root decoder address translation callback could be reused for
> other decoders too. For generic use of the callback, change the
> function interface to use a decoder argument instead of the root
> decoder.
> 
> Note that a root decoder's HPA is equal to its SPA, but else it may be

slighlty better wording:
"but it may different for non-root decoders"

> different. Thus, change the name of the function type to
> cxl_to_hpa_fn.
> 
> Signed-off-by: Robert Richter <rrichter@amd.com>

Reviewed-by: Gregory Price <gourry@gourry.net>
Dave Jiang Feb. 20, 2025, 9:03 p.m. UTC | #2
On 2/20/25 9:00 AM, Gregory Price wrote:
> On Tue, Feb 18, 2025 at 02:23:42PM +0100, Robert Richter wrote:
>> The root decoder address translation callback could be reused for
>> other decoders too. For generic use of the callback, change the
>> function interface to use a decoder argument instead of the root
>> decoder.
>>
>> Note that a root decoder's HPA is equal to its SPA, but else it may be
> 
> slighlty better wording:
> "but it may different for non-root decoders"

This change helped me understand what that sentence was trying to say.

> 
>> different. Thus, change the name of the function type to
>> cxl_to_hpa_fn.

I would also drop the "thus" so it's in imperative tone. 

>>
>> Signed-off-by: Robert Richter <rrichter@amd.com>
> 
> Reviewed-by: Gregory Price <gourry@gourry.net>
>
diff mbox series

Patch

diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
index 93c73b163c28..48ad90025d77 100644
--- a/drivers/cxl/acpi.c
+++ b/drivers/cxl/acpi.c
@@ -22,9 +22,9 @@  static const guid_t acpi_cxl_qtg_id_guid =
 	GUID_INIT(0xF365F9A6, 0xA7DE, 0x4071,
 		  0xA6, 0x6A, 0xB4, 0x0C, 0x0B, 0x4F, 0x8E, 0x52);
 
-
-static u64 cxl_xor_hpa_to_spa(struct cxl_root_decoder *cxlrd, u64 hpa)
+static u64 cxl_xor_hpa_to_spa(struct cxl_decoder *cxld, u64 hpa)
 {
+	struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(&cxld->dev);
 	struct cxl_cxims_data *cximsd = cxlrd->platform_data;
 	int hbiw = cxlrd->cxlsd.nr_targets;
 	u64 val;
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index a56b84e7103a..c118bda93e86 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -2936,9 +2936,12 @@  u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
 	/* Apply the hpa_offset to the region base address */
 	hpa = hpa_offset + p->res->start;
 
-	/* Root decoder translation overrides typical modulo decode */
+	/*
+	 * Root decoder translation overrides typical modulo decode.
+	 * Note that a root decoder's HPA is equal to its SPA.
+	 */
 	if (cxlrd->hpa_to_spa)
-		hpa = cxlrd->hpa_to_spa(cxlrd, hpa);
+		hpa = cxlrd->hpa_to_spa(&cxlrd->cxlsd.cxld, hpa);
 
 	if (hpa < p->res->start || hpa > p->res->end) {
 		dev_dbg(&cxlr->dev,
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index 50e7d878bb6f..b19ba47242c6 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -418,8 +418,7 @@  struct cxl_switch_decoder {
 	struct cxl_dport *target[];
 };
 
-struct cxl_root_decoder;
-typedef u64 (*cxl_hpa_to_spa_fn)(struct cxl_root_decoder *cxlrd, u64 hpa);
+typedef u64 (*cxl_to_hpa_fn)(struct cxl_decoder *cxld, u64 hpa);
 
 /**
  * struct cxl_root_decoder - Static platform CXL address decoder
@@ -434,7 +433,7 @@  typedef u64 (*cxl_hpa_to_spa_fn)(struct cxl_root_decoder *cxlrd, u64 hpa);
 struct cxl_root_decoder {
 	struct resource *res;
 	atomic_t region_id;
-	cxl_hpa_to_spa_fn hpa_to_spa;
+	cxl_to_hpa_fn hpa_to_spa;
 	void *platform_data;
 	struct mutex range_lock;
 	int qos_class;