Skip to content

Commit c0b584a

Browse files
Markos Chandrasralfbaechle
authored andcommitted
MIPS: mips-cm: Extend CM accessors for 64-bit CPUs
Previously, the CM accessors were only accessing CM registers as u32 types instead of using the native CM register with. However, newer CMs may actually be 64-bit on MIPS64 cores. Fortunately, current 64-bit CMs (CM3) hold all the useful configuration bits in the lower half of the 64-bit registers (at least most of them) so they can still be accessed using the current 32-bit accessors. Signed-off-by: Markos Chandras <markos.chandras@imgtec.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Jason Cooper <jason@lakedaemon.net> Cc: Andrew Bresticker <abrestic@chromium.org> Cc: Paul Burton <paul.burton@imgtec.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/10707/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent c014d16 commit c0b584a

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

arch/mips/include/asm/mips-cm.h

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ extern void __iomem *mips_cm_l2sync_base;
3333
*/
3434
extern phys_addr_t __mips_cm_phys_base(void);
3535

36+
/*
37+
* mips_cm_is64 - determine CM register width
38+
*
39+
* The CM register width is processor and CM specific. A 64-bit processor
40+
* usually has a 64-bit CM and a 32-bit one has a 32-bit CM but a 64-bit
41+
* processor could come with a 32-bit CM. Moreover, accesses on 64-bit CMs
42+
* can be done either using regular 64-bit load/store instructions, or 32-bit
43+
* load/store instruction on 32-bit register pairs. We opt for using 64-bit
44+
* accesses on 64-bit CMs and kernels and 32-bit in any other case.
45+
*
46+
* It's set to 0 for 32-bit accesses and 1 for 64-bit accesses.
47+
*/
48+
extern int mips_cm_is64;
49+
3650
/**
3751
* mips_cm_probe - probe for a Coherence Manager
3852
*
@@ -90,20 +104,46 @@ static inline bool mips_cm_has_l2sync(void)
90104

91105
/* Macros to ease the creation of register access functions */
92106
#define BUILD_CM_R_(name, off) \
93-
static inline u32 __iomem *addr_gcr_##name(void) \
107+
static inline unsigned long __iomem *addr_gcr_##name(void) \
94108
{ \
95-
return (u32 __iomem *)(mips_cm_base + (off)); \
109+
return (unsigned long __iomem *)(mips_cm_base + (off)); \
96110
} \
97111
\
98-
static inline u32 read_gcr_##name(void) \
112+
static inline u32 read32_gcr_##name(void) \
99113
{ \
100114
return __raw_readl(addr_gcr_##name()); \
115+
} \
116+
\
117+
static inline u64 read64_gcr_##name(void) \
118+
{ \
119+
return __raw_readq(addr_gcr_##name()); \
120+
} \
121+
\
122+
static inline unsigned long read_gcr_##name(void) \
123+
{ \
124+
if (mips_cm_is64) \
125+
return read64_gcr_##name(); \
126+
else \
127+
return read32_gcr_##name(); \
101128
}
102129

103130
#define BUILD_CM__W(name, off) \
104-
static inline void write_gcr_##name(u32 value) \
131+
static inline void write32_gcr_##name(u32 value) \
105132
{ \
106133
__raw_writel(value, addr_gcr_##name()); \
134+
} \
135+
\
136+
static inline void write64_gcr_##name(u64 value) \
137+
{ \
138+
__raw_writeq(value, addr_gcr_##name()); \
139+
} \
140+
\
141+
static inline void write_gcr_##name(unsigned long value) \
142+
{ \
143+
if (mips_cm_is64) \
144+
write64_gcr_##name(value); \
145+
else \
146+
write32_gcr_##name(value); \
107147
}
108148

109149
#define BUILD_CM_RW(name, off) \

arch/mips/kernel/mips-cm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
void __iomem *mips_cm_base;
1717
void __iomem *mips_cm_l2sync_base;
18+
int mips_cm_is64;
1819

1920
phys_addr_t __mips_cm_phys_base(void)
2021
{
@@ -124,5 +125,8 @@ int mips_cm_probe(void)
124125
/* probe for an L2-only sync region */
125126
mips_cm_probe_l2sync();
126127

128+
/* determine register width for this CM */
129+
mips_cm_is64 = config_enabled(CONFIG_64BIT) && (mips_cm_revision() >= CM_REV_CM3);
130+
127131
return 0;
128132
}

0 commit comments

Comments
 (0)