diff mbox series

[v2,02/10] MIPS: spaces: Define a couple of handy macros

Message ID 20231027221106.405666-3-jiaxun.yang@flygoat.com (mailing list archive)
State Superseded
Headers show
Series MIPS: Fix kernel in XKPHYS | expand

Commit Message

Jiaxun Yang Oct. 27, 2023, 10:10 p.m. UTC
KSEGX_SIZE is defined to size of each KSEG segment.

TO_CAC and TO_UNCAC are brought to 32bit builds as well,
TO_PHYS remains to be 64bit only as we want people to
use __pa to avoid mixup compat address space.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 arch/mips/include/asm/addrspace.h           | 5 +++++
 arch/mips/include/asm/mach-generic/spaces.h | 5 +++--
 2 files changed, 8 insertions(+), 2 deletions(-)

Comments

Thomas Bogendoerfer Dec. 21, 2023, 3:42 p.m. UTC | #1
On Fri, Oct 27, 2023 at 11:10:58PM +0100, Jiaxun Yang wrote:
> KSEGX_SIZE is defined to size of each KSEG segment.
> 
> TO_CAC and TO_UNCAC are brought to 32bit builds as well,
> TO_PHYS remains to be 64bit only as we want people to
> use __pa to avoid mixup compat address space.

the problem here is, that in the 64bit case the macros work on every address
while in 32bit only the first 512MB address space is covered. So there
is a reason to not expose TO_CAC/TO_UNCAC for 32bit.

Which leaves the problem how to handle all the CKSEG[01]ADDR()
cases nicer for 64bit... I'd prefer an extra macro/inline function
which handles 32bit and 64bit accordingly. Not sure about the name
for it, but maybe something like

CKSEG[01]ADDR_OR_64BIT()

That would at least make clear (to me) this thing is special and might
return a XPHYS uncached address.

Thomas.
diff mbox series

Patch

diff --git a/arch/mips/include/asm/addrspace.h b/arch/mips/include/asm/addrspace.h
index 59a48c60a065..03a5e2c8b5dc 100644
--- a/arch/mips/include/asm/addrspace.h
+++ b/arch/mips/include/asm/addrspace.h
@@ -47,6 +47,11 @@ 
  */
 #define KSEGX(a)		((_ACAST32_(a)) & _ACAST32_(0xe0000000))
 
+/*
+ * Gives the size of each kernel segment
+ */
+#define KSEGX_SIZE		0x20000000
+
 /*
  * Returns the physical address of a CKSEGx / XKPHYS address
  */
diff --git a/arch/mips/include/asm/mach-generic/spaces.h b/arch/mips/include/asm/mach-generic/spaces.h
index b247575c5e69..05db19521e81 100644
--- a/arch/mips/include/asm/mach-generic/spaces.h
+++ b/arch/mips/include/asm/mach-generic/spaces.h
@@ -79,11 +79,12 @@ 
 #endif
 
 #define TO_PHYS(x)		(	      ((x) & TO_PHYS_MASK))
-#define TO_CAC(x)		(CAC_BASE   | ((x) & TO_PHYS_MASK))
-#define TO_UNCAC(x)		(UNCAC_BASE | ((x) & TO_PHYS_MASK))
 
 #endif /* CONFIG_64BIT */
 
+#define TO_CAC(x)		(CAC_BASE   | ((x) & TO_PHYS_MASK))
+#define TO_UNCAC(x)		(UNCAC_BASE | ((x) & TO_PHYS_MASK))
+
 /*
  * This handles the memory map.
  */