diff mbox series

[v1,12/29] cxl: Modify address translation callback for generic use

Message ID 20250107141015.3367194-13-rrichter@amd.com
State New
Headers show
Series cxl: Add address translation support and enable AMD Zen5 platforms | expand

Commit Message

Robert Richter Jan. 7, 2025, 2:09 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.

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

Comments

Gregory Price Jan. 7, 2025, 6:44 p.m. UTC | #1
On Tue, Jan 07, 2025 at 03:09:58PM +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.
> 
> Signed-off-by: Robert Richter <rrichter@amd.com>
> ---
>  drivers/cxl/acpi.c        | 4 ++--
>  drivers/cxl/core/region.c | 2 +-
>  drivers/cxl/cxl.h         | 5 ++---
>  3 files changed, 5 insertions(+), 6 deletions(-)
> 
... snip ...
> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> index b3989dc58ed1..be7685fe8a23 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -443,8 +443,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);
>  

changed from _to_spa to _to_hpa? Was the name wrong previously? Maybe at
least comment on this in the changelog.
Ben Cheatham Jan. 17, 2025, 9:31 p.m. UTC | #2
On 1/7/25 8:09 AM, 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.
> 
> Signed-off-by: Robert Richter <rrichter@amd.com>
> ---
>  drivers/cxl/acpi.c        | 4 ++--
>  drivers/cxl/core/region.c | 2 +-
>  drivers/cxl/cxl.h         | 5 ++---
>  3 files changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
> index cb14829bb9be..b42cffd6751f 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);

I think this needs to use cxl_find_root_decoder() instead of to_cxl_root_decoder() since the
cxld is no longer guaranteed to be a root decoder (as per commit message).
 
>  	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 6fcf56806606..9443507ed4e1 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -2925,7 +2925,7 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
>  
>  	/* Root decoder translation overrides typical modulo decode */
>  	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 b3989dc58ed1..be7685fe8a23 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -443,8 +443,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
> @@ -459,7 +458,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;
diff mbox series

Patch

diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
index cb14829bb9be..b42cffd6751f 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 6fcf56806606..9443507ed4e1 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -2925,7 +2925,7 @@  u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
 
 	/* Root decoder translation overrides typical modulo decode */
 	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 b3989dc58ed1..be7685fe8a23 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -443,8 +443,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
@@ -459,7 +458,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;