2023-10-27 22:11:44

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH v2 02/10] MIPS: spaces: Define a couple of handy macros

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 <[email protected]>
---
arch/mips/include/asm/addrspace.h | 5 +++++
arch/mips/include/asm/mach-generic/spaces.h | 5 +++--
2 files changed, 8 insertions(+), 2 deletions(-)

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.
*/
--
2.34.1


2023-12-21 15:45:22

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH v2 02/10] MIPS: spaces: Define a couple of handy macros

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.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]