diff mbox series

[v4,18/24] EDAC/amd64: Define function to insert CS ID into address

Message ID 20220127204115.384161-19-yazen.ghannam@amd.com (mailing list archive)
State New, archived
Headers show
Series AMD MCA Address Translation Updates | expand

Commit Message

Yazen Ghannam Jan. 27, 2022, 8:41 p.m. UTC
Move the code that inserts the CS ID into the address into a separate
helper function.

Save the function pointer in the context struct. It will be set based on
interleaving mode rather than Data Fabric version. This will be expanded
for new interleaving modes added in future Data Fabric versions.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
---
Link:
https://lore.kernel.org/r/20211028175728.121452-24-yazen.ghannam@amd.com

v3->v4:
* No change.

v2->v3:
* Was patch 24 in v2.

v1->v2:
* Moved from arch/x86 to EDAC.
* Added function pointer to ctx struct.

 drivers/edac/amd64_edac.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

Comments

Borislav Petkov Feb. 14, 2022, 1:09 p.m. UTC | #1
On Thu, Jan 27, 2022 at 08:41:09PM +0000, Yazen Ghannam wrote:
> @@ -1326,20 +1331,7 @@ static int denormalize_addr(struct addr_ctx *ctx)
>  		return -EINVAL;
>  	}
>  
> -	if (num_intlv_bits > 0) {
> -		u64 temp_addr_i;
> -
> -		/*
> -		 * The pre-interleaved address consists of XXXXXXIIIYYYYY
> -		 * where III is the ID for this CS, and XXXXXXYYYYY are the
> -		 * address bits from the post-interleaved address.
> -		 * "num_intlv_bits" has been calculated to tell us how many "I"
> -		 * bits there are. "intlv_addr_bit" tells us how many "Y" bits
> -		 * there are (where "I" starts).
> -		 */

That comment looks useful, why remove it?
Yazen Ghannam March 9, 2022, 10:31 p.m. UTC | #2
On Mon, Feb 14, 2022 at 02:09:07PM +0100, Borislav Petkov wrote:
> On Thu, Jan 27, 2022 at 08:41:09PM +0000, Yazen Ghannam wrote:
> > @@ -1326,20 +1331,7 @@ static int denormalize_addr(struct addr_ctx *ctx)
> >  		return -EINVAL;
> >  	}
> >  
> > -	if (num_intlv_bits > 0) {
> > -		u64 temp_addr_i;
> > -
> > -		/*
> > -		 * The pre-interleaved address consists of XXXXXXIIIYYYYY
> > -		 * where III is the ID for this CS, and XXXXXXYYYYY are the
> > -		 * address bits from the post-interleaved address.
> > -		 * "num_intlv_bits" has been calculated to tell us how many "I"
> > -		 * bits there are. "intlv_addr_bit" tells us how many "Y" bits
> > -		 * there are (where "I" starts).
> > -		 */
> 
> That comment looks useful, why remove it?
>

No firm reason. I just got the feeling it wasn't very useful. But I'll keep it
in case others find it helpful.

Thanks,
Yazen
diff mbox series

Patch

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index b2bcd8ea1a06..e3db4e98fe58 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -1083,6 +1083,7 @@  struct addr_ctx {
 	u8 cs_id;
 	int (*dehash_addr)(struct addr_ctx *ctx);
 	void (*make_space_for_cs_id)(struct addr_ctx *ctx);
+	void (*insert_cs_id)(struct addr_ctx *ctx);
 };
 
 struct data_fabric_ops {
@@ -1115,6 +1116,11 @@  static void make_space_for_cs_id_simple(struct addr_ctx *ctx)
 	expand_bits(ctx->intlv_addr_bit, num_intlv_bits, &ctx->ret_addr);
 }
 
+static void insert_cs_id_simple(struct addr_ctx *ctx)
+{
+	ctx->ret_addr |= (ctx->cs_id << ctx->intlv_addr_bit);
+}
+
 static u64 get_hi_addr_offset_df2(struct addr_ctx *ctx)
 {
 	return (ctx->reg_dram_offset & GENMASK_ULL(31, 20)) << 8;
@@ -1146,6 +1152,7 @@  static int get_intlv_mode_df2(struct addr_ctx *ctx)
 	}
 
 	ctx->make_space_for_cs_id = make_space_for_cs_id_simple;
+	ctx->insert_cs_id = insert_cs_id_simple;
 
 	if (ctx->intlv_mode != NONE &&
 	    ctx->intlv_mode != NOHASH_2CH &&
@@ -1306,8 +1313,6 @@  static int calculate_cs_id(struct addr_ctx *ctx)
 
 static int denormalize_addr(struct addr_ctx *ctx)
 {
-	u8 num_intlv_bits;
-
 	/* Return early if no interleaving. */
 	if (ctx->intlv_mode == NONE)
 		return 0;
@@ -1326,20 +1331,7 @@  static int denormalize_addr(struct addr_ctx *ctx)
 		return -EINVAL;
 	}
 
-	if (num_intlv_bits > 0) {
-		u64 temp_addr_i;
-
-		/*
-		 * The pre-interleaved address consists of XXXXXXIIIYYYYY
-		 * where III is the ID for this CS, and XXXXXXYYYYY are the
-		 * address bits from the post-interleaved address.
-		 * "num_intlv_bits" has been calculated to tell us how many "I"
-		 * bits there are. "intlv_addr_bit" tells us how many "Y" bits
-		 * there are (where "I" starts).
-		 */
-		temp_addr_i = (ctx->cs_id << ctx->intlv_addr_bit);
-		ctx->ret_addr |= temp_addr_i;
-	}
+	ctx->insert_cs_id(ctx);
 
 	return 0;
 }