@@ -860,6 +860,38 @@ static void get_intlv_num_sockets(struct addr_ctx *ctx)
ctx->intlv_num_sockets = (ctx->reg_limit_addr >> 8) & 0x1;
}
+static void expand_bits(u8 start_bit, u8 num_bits, u64 *value)
+{
+ u64 temp1, temp2;
+
+ if (start_bit == 0) {
+ *value <<= num_bits;
+ return;
+ }
+
+ temp1 = *value & GENMASK_ULL(start_bit - 1, 0);
+ temp2 = (*value & GENMASK_ULL(63, start_bit)) << num_bits;
+ *value = temp1 | temp2;
+}
+
+static void make_space_for_cs_id(struct addr_ctx *ctx)
+{
+ u8 num_intlv_bits;
+
+ switch (ctx->intlv_mode) {
+ case NOHASH_2CH:
+ case DF2_HASH_2CH:
+ num_intlv_bits = ctx->intlv_num_chan;
+ num_intlv_bits += ctx->intlv_num_dies;
+ num_intlv_bits += ctx->intlv_num_sockets;
+ expand_bits(ctx->intlv_addr_bit, num_intlv_bits, &ctx->ret_addr);
+ break;
+ default:
+ /* Valid interleaving modes where checked earlier. */
+ break;
+ }
+}
+
static int denormalize_addr(struct addr_ctx *ctx)
{
u32 tmp;
@@ -878,13 +910,11 @@ static int denormalize_addr(struct addr_ctx *ctx)
get_intlv_num_dies(ctx);
get_intlv_num_sockets(ctx);
- num_intlv_bits = ctx->intlv_num_chan;
- num_intlv_bits += ctx->intlv_num_dies;
- num_intlv_bits += ctx->intlv_num_sockets;
+ make_space_for_cs_id(ctx);
if (num_intlv_bits > 0) {
- u64 temp_addr_x, temp_addr_i, temp_addr_y;
u8 die_id_bit, sock_id_bit, cs_fabric_id;
+ u64 temp_addr_i;
/*
* Read FabricBlockInstanceInformation3_CS[BlockFabricID].
@@ -939,11 +969,8 @@ static int denormalize_addr(struct addr_ctx *ctx)
* bits there are. "intlv_addr_bit" tells us how many "Y" bits
* there are (where "I" starts).
*/
- temp_addr_y = ctx->ret_addr & GENMASK_ULL(ctx->intlv_addr_bit - 1, 0);
temp_addr_i = (ctx->cs_id << ctx->intlv_addr_bit);
- temp_addr_x = (ctx->ret_addr & GENMASK_ULL(63, ctx->intlv_addr_bit))
- << num_intlv_bits;
- ctx->ret_addr = temp_addr_x | temp_addr_i | temp_addr_y;
+ ctx->ret_addr |= temp_addr_i;
}
return 0;