Skip to content

Commit b83ee96

Browse files
AlisonSchofielddavejiang
authored andcommitted
cxl: Define a SPA->CXL HPA root decoder callback for XOR Math
When DPA->SPA translation was introduced, it included a helper that applied the XOR maps to do the CXL HPA -> SPA translation for XOR region interleaves. In preparation for adding SPA->DPA address translation, introduce the reverse callback. The root decoder callback is defined generically and not all usages may be self inverting like this XOR function. Add another root decoder callback that is the spa_to_hpa function. Update the existing cxl_xor_hpa_to_spa() with a name that reflects what it does without directionality: cxl_apply_xor_maps(), a generic parameter: addr replaces hpa, and code comments stating that the function supports the translation in either direction. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Link: https://patch.msgid.link/79d9d72230c599cae94d7221781ead6392ae6d3f.1754290144.git.alison.schofield@intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 524b2b7 commit b83ee96

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

drivers/cxl/acpi.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static const guid_t acpi_cxl_qtg_id_guid =
2020
GUID_INIT(0xF365F9A6, 0xA7DE, 0x4071,
2121
0xA6, 0x6A, 0xB4, 0x0C, 0x0B, 0x4F, 0x8E, 0x52);
2222

23-
static u64 cxl_xor_hpa_to_spa(struct cxl_root_decoder *cxlrd, u64 hpa)
23+
static u64 cxl_apply_xor_maps(struct cxl_root_decoder *cxlrd, u64 addr)
2424
{
2525
struct cxl_cxims_data *cximsd = cxlrd->platform_data;
2626
int hbiw = cxlrd->cxlsd.nr_targets;
@@ -29,19 +29,23 @@ static u64 cxl_xor_hpa_to_spa(struct cxl_root_decoder *cxlrd, u64 hpa)
2929

3030
/* No xormaps for host bridge interleave ways of 1 or 3 */
3131
if (hbiw == 1 || hbiw == 3)
32-
return hpa;
32+
return addr;
3333

3434
/*
35-
* For root decoders using xormaps (hbiw: 2,4,6,8,12,16) restore
36-
* the position bit to its value before the xormap was applied at
37-
* HPA->DPA translation.
35+
* In regions using XOR interleave arithmetic the CXL HPA may not
36+
* be the same as the SPA. This helper performs the SPA->CXL HPA
37+
* or the CXL HPA->SPA translation. Since XOR is self-inverting,
38+
* so is this function.
39+
*
40+
* For root decoders using xormaps (hbiw: 2,4,6,8,12,16) applying the
41+
* xormaps will toggle a position bit.
3842
*
3943
* pos is the lowest set bit in an XORMAP
40-
* val is the XORALLBITS(HPA & XORMAP)
44+
* val is the XORALLBITS(addr & XORMAP)
4145
*
4246
* XORALLBITS: The CXL spec (3.1 Table 9-22) defines XORALLBITS
4347
* as an operation that outputs a single bit by XORing all the
44-
* bits in the input (hpa & xormap). Implement XORALLBITS using
48+
* bits in the input (addr & xormap). Implement XORALLBITS using
4549
* hweight64(). If the hamming weight is even the XOR of those
4650
* bits results in val==0, if odd the XOR result is val==1.
4751
*/
@@ -50,11 +54,11 @@ static u64 cxl_xor_hpa_to_spa(struct cxl_root_decoder *cxlrd, u64 hpa)
5054
if (!cximsd->xormaps[i])
5155
continue;
5256
pos = __ffs(cximsd->xormaps[i]);
53-
val = (hweight64(hpa & cximsd->xormaps[i]) & 1);
54-
hpa = (hpa & ~(1ULL << pos)) | (val << pos);
57+
val = (hweight64(addr & cximsd->xormaps[i]) & 1);
58+
addr = (addr & ~(1ULL << pos)) | (val << pos);
5559
}
5660

57-
return hpa;
61+
return addr;
5862
}
5963

6064
struct cxl_cxims_context {
@@ -476,7 +480,8 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws,
476480
if (!cxlrd->ops)
477481
return -ENOMEM;
478482

479-
cxlrd->ops->hpa_to_spa = cxl_xor_hpa_to_spa;
483+
cxlrd->ops->hpa_to_spa = cxl_apply_xor_maps;
484+
cxlrd->ops->spa_to_hpa = cxl_apply_xor_maps;
480485
}
481486

482487
rc = cxl_decoder_add(cxld, target_map);

drivers/cxl/cxl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,11 @@ struct cxl_root_decoder;
422422
/**
423423
* struct cxl_rd_ops - CXL root decoder callback operations
424424
* @hpa_to_spa: Convert host physical address to system physical address
425+
* @spa_to_hpa: Convert system physical address to host physical address
425426
*/
426427
struct cxl_rd_ops {
427428
u64 (*hpa_to_spa)(struct cxl_root_decoder *cxlrd, u64 hpa);
429+
u64 (*spa_to_hpa)(struct cxl_root_decoder *cxlrd, u64 spa);
428430
};
429431

430432
/**

0 commit comments

Comments
 (0)