[PATCH 0/2] AMD Address Translation Library

From: Yazen Ghannam
Date: Wed Aug 02 2023 - 14:55:51 EST

Hi all,

This set adds a new library to do AMD-specific address translation. The
first use case is for translating a Unified Memory Controller (UMC)
"Normalized" address to a system physical address. Another use case will
be to do a similar translation for certain CXL configurations. The only
user is EDAC at the moment. But this can be used in MCA and CXL
subsystems too. Patches coming soon...

Since this code is very much implementation-specific, I thought it'd be
appropriate to have it as a "platform driver". Having the option to
build as a module helps with development, but this will likely be
'built-in' to use for MCA and CXL in production.

Patch 1 adds the new code. This includes support for all current AMD
Zen-based systems with a couple of exceptions noted in the commit

The code is based on AMD reference code. Much of this is arbitrary bit
arithmetic. But I tried my best to make clarifying comments and to
restructure the code to be easier to follow.

Also, I purposefully avoided "over-optimizing" for the same reason, and
also to leverage compile-time checks for bitfields, etc. For example,
there are many uses of FIELD_GET(), and this requires a constant
expression as input.

The reference code underwent a major refactor. Therefore, this latest
set is fresh start. I figure it's best to match the latest reference
rather than submit another revision based on old code that will need to
be refactored anyway.

There are many code paths that are reused between various interleaving
modes and Data Fabric revisions. And these aren't easily decoupled. So
run time checks are used for code flow rather than function pointers,

All the code is added within a single patch. Mostly, this was done to
get the "whole picture" of how things fit together. But I can break this
up into separate patches for each Data Fabric revision, if needed. I
also want to avoid taking the old code and incrementally refactoring.
Since the old code no longer matches the reference, I think it's simpler
to just add the new and delete the old.

Patch 2 removes the old code and switches the AMD64 EDAC module to use
the new code.

Previous set:

Notable changes from previous set:
1) Move code out of EDAC.
2) Another major refactor based on refactored reference code.
3) Addition of DF4 and DF4.5 support.


Yazen Ghannam (2):
platform/x86/amd: Introduce AMD Address Translation Library
EDAC/amd64: Use new AMD Address Translation Library

drivers/edac/Kconfig | 1 +
drivers/edac/amd64_edac.c | 282 +--------
drivers/platform/x86/amd/Kconfig | 1 +
drivers/platform/x86/amd/Makefile | 1 +
drivers/platform/x86/amd/atl/Kconfig | 20 +
drivers/platform/x86/amd/atl/Makefile | 18 +
drivers/platform/x86/amd/atl/access.c | 107 ++++
drivers/platform/x86/amd/atl/core.c | 212 +++++++
drivers/platform/x86/amd/atl/dehash.c | 459 ++++++++++++++
drivers/platform/x86/amd/atl/denormalize.c | 644 ++++++++++++++++++++
drivers/platform/x86/amd/atl/internal.h | 307 ++++++++++
drivers/platform/x86/amd/atl/map.c | 659 +++++++++++++++++++++
drivers/platform/x86/amd/atl/reg_fields.h | 603 +++++++++++++++++++
drivers/platform/x86/amd/atl/system.c | 282 +++++++++
drivers/platform/x86/amd/atl/umc.c | 53 ++
include/linux/amd-atl.h | 18 +
17 files changed, 3398 insertions(+), 276 deletions(-)
create mode 100644 drivers/platform/x86/amd/atl/Kconfig
create mode 100644 drivers/platform/x86/amd/atl/Makefile
create mode 100644 drivers/platform/x86/amd/atl/access.c
create mode 100644 drivers/platform/x86/amd/atl/core.c
create mode 100644 drivers/platform/x86/amd/atl/dehash.c
create mode 100644 drivers/platform/x86/amd/atl/denormalize.c
create mode 100644 drivers/platform/x86/amd/atl/internal.h
create mode 100644 drivers/platform/x86/amd/atl/map.c
create mode 100644 drivers/platform/x86/amd/atl/reg_fields.h
create mode 100644 drivers/platform/x86/amd/atl/system.c
create mode 100644 drivers/platform/x86/amd/atl/umc.c
create mode 100644 include/linux/amd-atl.h