Skip to content

Commit 6cce048

Browse files
jallen-amdbp3tk0v
authored andcommitted
RAS/AMD/ATL: Expand helpers for adding and removing base and hole
The ret_addr field in struct addr_ctx contains the intermediate value of the returned address as it passes through multiple steps in the translation process. Currently, adding the DRAM base and legacy hole is only done once, so it operates directly on the intermediate value. However, for DF 4.5 non-power-of-2 denormalization, adding and removing the DRAM base and legacy hole needs to be done for multiple temporary address values. During this process, the intermediate value should not be lost so the ret_addr value can't be reused. Update the existing 'add' helper to operate on an arbitrary address and introduce a new 'remove' helper to do the inverse operations. Signed-off-by: John Allen <john.allen@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Yazen Ghannam <yazen.ghannam@amd.com> Link: https://lore.kernel.org/r/20240606203313.51197-4-john.allen@amd.com
1 parent 1233aa3 commit 6cce048

2 files changed

Lines changed: 29 additions & 15 deletions

File tree

drivers/ras/amd/atl/core.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,26 @@ static bool legacy_hole_en(struct addr_ctx *ctx)
4949
return FIELD_GET(DF_LEGACY_MMIO_HOLE_EN, reg);
5050
}
5151

52-
static int add_legacy_hole(struct addr_ctx *ctx)
52+
static u64 add_legacy_hole(struct addr_ctx *ctx, u64 addr)
5353
{
5454
if (!legacy_hole_en(ctx))
55-
return 0;
55+
return addr;
5656

57-
if (ctx->ret_addr >= df_cfg.dram_hole_base)
58-
ctx->ret_addr += (BIT_ULL(32) - df_cfg.dram_hole_base);
57+
if (addr >= df_cfg.dram_hole_base)
58+
addr += (BIT_ULL(32) - df_cfg.dram_hole_base);
5959

60-
return 0;
60+
return addr;
61+
}
62+
63+
static u64 remove_legacy_hole(struct addr_ctx *ctx, u64 addr)
64+
{
65+
if (!legacy_hole_en(ctx))
66+
return addr;
67+
68+
if (addr >= df_cfg.dram_hole_base)
69+
addr -= (BIT_ULL(32) - df_cfg.dram_hole_base);
70+
71+
return addr;
6172
}
6273

6374
static u64 get_base_addr(struct addr_ctx *ctx)
@@ -72,14 +83,14 @@ static u64 get_base_addr(struct addr_ctx *ctx)
7283
return base_addr << DF_DRAM_BASE_LIMIT_LSB;
7384
}
7485

75-
static int add_base_and_hole(struct addr_ctx *ctx)
86+
u64 add_base_and_hole(struct addr_ctx *ctx, u64 addr)
7687
{
77-
ctx->ret_addr += get_base_addr(ctx);
78-
79-
if (add_legacy_hole(ctx))
80-
return -EINVAL;
88+
return add_legacy_hole(ctx, addr + get_base_addr(ctx));
89+
}
8190

82-
return 0;
91+
u64 remove_base_and_hole(struct addr_ctx *ctx, u64 addr)
92+
{
93+
return remove_legacy_hole(ctx, addr) - get_base_addr(ctx);
8394
}
8495

8596
static bool late_hole_remove(struct addr_ctx *ctx)
@@ -126,14 +137,14 @@ unsigned long norm_to_sys_addr(u8 socket_id, u8 die_id, u8 coh_st_inst_id, unsig
126137
if (denormalize_address(&ctx))
127138
return -EINVAL;
128139

129-
if (!late_hole_remove(&ctx) && add_base_and_hole(&ctx))
130-
return -EINVAL;
140+
if (!late_hole_remove(&ctx))
141+
ctx.ret_addr = add_base_and_hole(&ctx, ctx.ret_addr);
131142

132143
if (dehash_address(&ctx))
133144
return -EINVAL;
134145

135-
if (late_hole_remove(&ctx) && add_base_and_hole(&ctx))
136-
return -EINVAL;
146+
if (late_hole_remove(&ctx))
147+
ctx.ret_addr = add_base_and_hole(&ctx, ctx.ret_addr);
137148

138149
if (addr_over_limit(&ctx))
139150
return -EINVAL;

drivers/ras/amd/atl/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ int dehash_address(struct addr_ctx *ctx);
239239
unsigned long norm_to_sys_addr(u8 socket_id, u8 die_id, u8 coh_st_inst_id, unsigned long addr);
240240
unsigned long convert_umc_mca_addr_to_sys_addr(struct atl_err *err);
241241

242+
u64 add_base_and_hole(struct addr_ctx *ctx, u64 addr);
243+
u64 remove_base_and_hole(struct addr_ctx *ctx, u64 addr);
244+
242245
/*
243246
* Make a gap in @data that is @num_bits long starting at @bit_num.
244247
* e.g. data = 11111111'b

0 commit comments

Comments
 (0)