MIPS: CM: Specify register size when generating accessors
Some CM registers are always 32 bits, or at least only use bits in the lower 32 bits of the register. For these registers it is wasteful for us to generate accessors which bother to check mips_cm_is64 & perform 64 bit accesses. This patch modifies the accessor generation to take into account the size of the register, and for 32 bit registers we generate accessors which only ever perform 32 bit accesses. For 64 bit registers we either perform a 64 bit access or two 32 bit accesses, depending upon the value of mips_cm_is64. Doing this saves us ~1.5KiB of code in a generic 64r6el kernel, and perhaps more importantly simplifies various code paths. This removes the read64_gcr_* accessors, so mips_cm_error_report() is modified to stop using them & instead use the regular read_gcr_* accessors which will return 64 bit values from the 64 bit registers. The new accessor macros are placed in asm/mips-cps.h such that they can be shared by CPC & GIC code in later patches. Signed-off-by: Paul Burton <paul.burton@imgtec.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/17000/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
This commit is contained in:

committed by
Ralf Baechle

parent
abe852ea3a
commit
b025d51873
87
arch/mips/include/asm/mips-cps.h
Normal file
87
arch/mips/include/asm/mips-cps.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Imagination Technologies
|
||||
* Author: Paul Burton <paul.burton@imgtec.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef __MIPS_ASM_MIPS_CPS_H__
|
||||
#define __MIPS_ASM_MIPS_CPS_H__
|
||||
|
||||
#include <linux/io.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
extern unsigned long __cps_access_bad_size(void)
|
||||
__compiletime_error("Bad size for CPS accessor");
|
||||
|
||||
#define CPS_ACCESSOR_A(unit, off, name) \
|
||||
static inline void *addr_##unit##_##name(void) \
|
||||
{ \
|
||||
return mips_##unit##_base + (off); \
|
||||
}
|
||||
|
||||
#define CPS_ACCESSOR_R(unit, sz, name) \
|
||||
static inline uint##sz##_t read_##unit##_##name(void) \
|
||||
{ \
|
||||
uint64_t val64; \
|
||||
\
|
||||
switch (sz) { \
|
||||
case 32: \
|
||||
return __raw_readl(addr_##unit##_##name()); \
|
||||
\
|
||||
case 64: \
|
||||
if (mips_cm_is64) \
|
||||
return __raw_readq(addr_##unit##_##name()); \
|
||||
\
|
||||
val64 = __raw_readl(addr_##unit##_##name() + 4); \
|
||||
val64 <<= 32; \
|
||||
val64 |= __raw_readl(addr_##unit##_##name()); \
|
||||
return val64; \
|
||||
\
|
||||
default: \
|
||||
return __cps_access_bad_size(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CPS_ACCESSOR_W(unit, sz, name) \
|
||||
static inline void write_##unit##_##name(uint##sz##_t val) \
|
||||
{ \
|
||||
switch (sz) { \
|
||||
case 32: \
|
||||
__raw_writel(val, addr_##unit##_##name()); \
|
||||
break; \
|
||||
\
|
||||
case 64: \
|
||||
if (mips_cm_is64) { \
|
||||
__raw_writeq(val, addr_##unit##_##name()); \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
__raw_writel((uint64_t)val >> 32, \
|
||||
addr_##unit##_##name() + 4); \
|
||||
__raw_writel(val, addr_##unit##_##name()); \
|
||||
break; \
|
||||
\
|
||||
default: \
|
||||
__cps_access_bad_size(); \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CPS_ACCESSOR_RO(unit, sz, off, name) \
|
||||
CPS_ACCESSOR_A(unit, off, name) \
|
||||
CPS_ACCESSOR_R(unit, sz, name)
|
||||
|
||||
#define CPS_ACCESSOR_WO(unit, sz, off, name) \
|
||||
CPS_ACCESSOR_A(unit, off, name) \
|
||||
CPS_ACCESSOR_W(unit, sz, name)
|
||||
|
||||
#define CPS_ACCESSOR_RW(unit, sz, off, name) \
|
||||
CPS_ACCESSOR_A(unit, off, name) \
|
||||
CPS_ACCESSOR_R(unit, sz, name) \
|
||||
CPS_ACCESSOR_W(unit, sz, name)
|
||||
|
||||
#endif /* __MIPS_ASM_MIPS_CPS_H__ */
|
Reference in New Issue
Block a user