diff mbox series

[V2,1/3] MIPS: Loongson: Add CFUCFG&CSR support

Message ID 1569073828-13019-1-git-send-email-chenhc@lemote.com (mailing list archive)
State Accepted
Headers show
Series [V2,1/3] MIPS: Loongson: Add CFUCFG&CSR support | expand

Commit Message

Huacai Chen Sept. 21, 2019, 1:50 p.m. UTC
Loongson-3A R4+ (Loongson-3A4000 and newer) has CPUCFG (CPU config) and
CSR (Control and Status Register) extensions. This patch add read/write
functionalities for them.

Signed-off-by: Huacai Chen <chenhc@lemote.com>
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 .../include/asm/mach-loongson64/loongson_regs.h    | 227 +++++++++++++++++++++
 1 file changed, 227 insertions(+)
 create mode 100644 arch/mips/include/asm/mach-loongson64/loongson_regs.h

Comments

Paul Burton Oct. 7, 2019, 5:51 p.m. UTC | #1
Hello,

Huacai Chen wrote:
> Loongson-3A R4+ (Loongson-3A4000 and newer) has CPUCFG (CPU config) and
> CSR (Control and Status Register) extensions. This patch add read/write
> functionalities for them.

Series applied to mips-next.

> MIPS: Loongson: Add CFUCFG&CSR support
>   commit 6a6f9b7dafd5
>   https://git.kernel.org/mips/c/6a6f9b7dafd5
>   
>   Signed-off-by: Huacai Chen <chenhc@lemote.com>
>   Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
>   Signed-off-by: Paul Burton <paul.burton@mips.com>
> 
> MIPS: Loongson: Add Loongson-3A R4 basic support
>   commit 7507445b1993
>   https://git.kernel.org/mips/c/7507445b1993
>   
>   Signed-off-by: Huacai Chen <chenhc@lemote.com>
>   Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
>   Signed-off-by: Paul Burton <paul.burton@mips.com>
> 
> MIPS: Loongson-3: Add CSR IPI support
>   commit ffe59ee36aaa
>   https://git.kernel.org/mips/c/ffe59ee36aaa
>   
>   Signed-off-by: Huacai Chen <chenhc@lemote.com>
>   Signed-off-by: Paul Burton <paul.burton@mips.com>

Thanks,
    Paul

[ This message was auto-generated; if you believe anything is incorrect
  then please email paul.burton@mips.com to report it. ]
Huacai Chen Oct. 8, 2019, 7:09 a.m. UTC | #2
Hi, Paul,

I found that there is a typo in the title, please change CFUCFG to
CPUCFG, thanks.

Huacai

On Tue, Oct 8, 2019 at 1:51 AM Paul Burton <paul.burton@mips.com> wrote:
>
> Hello,
>
> Huacai Chen wrote:
> > Loongson-3A R4+ (Loongson-3A4000 and newer) has CPUCFG (CPU config) and
> > CSR (Control and Status Register) extensions. This patch add read/write
> > functionalities for them.
>
> Series applied to mips-next.
>
> > MIPS: Loongson: Add CFUCFG&CSR support
> >   commit 6a6f9b7dafd5
> >   https://git.kernel.org/mips/c/6a6f9b7dafd5
> >
> >   Signed-off-by: Huacai Chen <chenhc@lemote.com>
> >   Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> >   Signed-off-by: Paul Burton <paul.burton@mips.com>
> >
> > MIPS: Loongson: Add Loongson-3A R4 basic support
> >   commit 7507445b1993
> >   https://git.kernel.org/mips/c/7507445b1993
> >
> >   Signed-off-by: Huacai Chen <chenhc@lemote.com>
> >   Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> >   Signed-off-by: Paul Burton <paul.burton@mips.com>
> >
> > MIPS: Loongson-3: Add CSR IPI support
> >   commit ffe59ee36aaa
> >   https://git.kernel.org/mips/c/ffe59ee36aaa
> >
> >   Signed-off-by: Huacai Chen <chenhc@lemote.com>
> >   Signed-off-by: Paul Burton <paul.burton@mips.com>
>
> Thanks,
>     Paul
>
> [ This message was auto-generated; if you believe anything is incorrect
>   then please email paul.burton@mips.com to report it. ]
Paul Burton Oct. 8, 2019, 6 p.m. UTC | #3
Hi Huacai,

[Quote munged to fix top posting]

On Tue, Oct 08, 2019 at 03:09:27PM +0800, Huacai Chen wrote:
> Hi, Paul,
> 
> On Tue, Oct 8, 2019 at 1:51 AM Paul Burton <paul.burton@mips.com> wrote:
> >
> > Hello,
> >
> > Huacai Chen wrote:
> > > Loongson-3A R4+ (Loongson-3A4000 and newer) has CPUCFG (CPU config) and
> > > CSR (Control and Status Register) extensions. This patch add read/write
> > > functionalities for them.
> >
> > Series applied to mips-next.
> >
> > > MIPS: Loongson: Add CFUCFG&CSR support
> > >   commit 6a6f9b7dafd5
> > >   https://git.kernel.org/mips/c/6a6f9b7dafd5
> > >
> > >   Signed-off-by: Huacai Chen <chenhc@lemote.com>
> > >   Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> > >   Signed-off-by: Paul Burton <paul.burton@mips.com>
> > >
> > > MIPS: Loongson: Add Loongson-3A R4 basic support
> > >   commit 7507445b1993
> > >   https://git.kernel.org/mips/c/7507445b1993
> > >
> > >   Signed-off-by: Huacai Chen <chenhc@lemote.com>
> > >   Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> > >   Signed-off-by: Paul Burton <paul.burton@mips.com>
> > >
> > > MIPS: Loongson-3: Add CSR IPI support
> > >   commit ffe59ee36aaa
> > >   https://git.kernel.org/mips/c/ffe59ee36aaa
> > >
> > >   Signed-off-by: Huacai Chen <chenhc@lemote.com>
> > >   Signed-off-by: Paul Burton <paul.burton@mips.com>
> >
> > Thanks,
> >     Paul
> >
> > [ This message was auto-generated; if you believe anything is incorrect
> >   then please email paul.burton@mips.com to report it. ]
> 
> I found that there is a typo in the title, please change CFUCFG to
> CPUCFG, thanks.
>
> Huacai

It's too late for that - the email you replied to was telling you that
the patches have already been applied to mips-next, and I'm not going to
rewrite the mips-next branch for something so minor.

Thanks,
    Paul
Jiaxun Yang Oct. 9, 2019, 1:10 a.m. UTC | #4
于 2019年10月9日 GMT+08:00 上午2:00:26, Paul Burton <paul.burton@mips.com> 写到:
>Hi Huacai,
>
>[Quote munged to fix top posting]
>
>On Tue, Oct 08, 2019 at 03:09:27PM +0800, Huacai Chen wrote:
>> Hi, Paul,
>> 
>> On Tue, Oct 8, 2019 at 1:51 AM Paul Burton <paul.burton@mips.com>
>wrote:
>> >
>> > Hello,
>> >
>> > Huacai Chen wrote:
>> > > Loongson-3A R4+ (Loongson-3A4000 and newer) has CPUCFG (CPU
>config) and
>> > > CSR (Control and Status Register) extensions. This patch add
>read/write
>> > > functionalities for them.
>> >
>> > Series applied to mips-next.
>> >
>> > > MIPS: Loongson: Add CFUCFG&CSR support
>> > >   commit 6a6f9b7dafd5
>> > >   https://git.kernel.org/mips/c/6a6f9b7dafd5
>> > >
>> > >   Signed-off-by: Huacai Chen <chenhc@lemote.com>
>> > >   Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
>> > >   Signed-off-by: Paul Burton <paul.burton@mips.com>
>> > >
>> > > MIPS: Loongson: Add Loongson-3A R4 basic support
>> > >   commit 7507445b1993
>> > >   https://git.kernel.org/mips/c/7507445b1993
>> > >
>> > >   Signed-off-by: Huacai Chen <chenhc@lemote.com>
>> > >   Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
>> > >   Signed-off-by: Paul Burton <paul.burton@mips.com>
>> > >
>> > > MIPS: Loongson-3: Add CSR IPI support
>> > >   commit ffe59ee36aaa
>> > >   https://git.kernel.org/mips/c/ffe59ee36aaa
>> > >
>> > >   Signed-off-by: Huacai Chen <chenhc@lemote.com>
>> > >   Signed-off-by: Paul Burton <paul.burton@mips.com>
>> >
>> > Thanks,
>> >     Paul
>> >
>> > [ This message was auto-generated; if you believe anything is
>incorrect
>> >   then please email paul.burton@mips.com to report it. ]
>> 
>> I found that there is a typo in the title, please change CFUCFG to
>> CPUCFG, thanks.
>>
>> Huacai
>
>It's too late for that - the email you replied to was telling you that
>the patches have already been applied to mips-next, and I'm not going
>to
>rewrite the mips-next branch for something so minor.
Hi Paul,

I think it is worthy to fix this by rewriting mips-next tree. As it haven't PR to upward next tree and this typo may lead to confusion in future when reviewing git log.
>
>Thanks,
>    Paul
Paul Burton Oct. 9, 2019, 1:37 a.m. UTC | #5
Hi Jiaxun,

On Wed, Oct 09, 2019 at 09:10:57AM +0800, Jiaxun Yang wrote:
> >> I found that there is a typo in the title, please change CFUCFG to
> >> CPUCFG, thanks.
> >>
> >> Huacai
> >
> >It's too late for that - the email you replied to was telling you that
> >the patches have already been applied to mips-next, and I'm not going
> >to
> >rewrite the mips-next branch for something so minor.
>
> Hi Paul,
> 
> I think it is worthy to fix this by rewriting mips-next tree. As it
> haven't PR to upward next tree and this typo may lead to confusion in
> future when reviewing git log.

I disagree.

It's fairly common good practice to not rewrite history that has been
shared. Quoting Documentation/process/7.AdvancedTopics.rst:

> Excessive use of this capability can lead to other problems, though,
> beyond a simple obsession for the creation of the perfect project
> history.  Rewriting history will rewrite the changes contained in that
> history, turning a tested (hopefully) kernel tree into an untested
> one.  But, beyond that, developers cannot easily collaborate if they
> do not have a shared view of the project history; if you rewrite
> history which other developers have pulled into their repositories,
> you will make life much more difficult for those developers.  So a
> simple rule of thumb applies here: history which has been exported to
> others should generally be seen as immutable thereafter.
> 
> So, once you push a set of changes to your publicly-available server,
> those changes should not be rewritten.  Git will attempt to enforce
> this rule if you try to push changes which do not result in a
> fast-forward merge (i.e. changes which do not share the same history).
> It is possible to override this check, and there may be times when it
> is necessary to rewrite an exported tree.  Moving changesets between
> trees to avoid conflicts in linux-next is one example.  But such
> actions should be rare.  This is one of the reasons why development
> should be done in private branches (which can be rewritten if
> necessary) and only moved into public branches when it's in a
> reasonably advanced state.

Rewriting history can complicate things for developers working atop
mips-next (which is something I want to encourage, not make difficult)
and it would mean commit references such as those included in the
"applied to mips-next" emails I send out would become incorrect.

So when commts to mips-next are pushed to kernel.org, I generally won't
change them unless there's something majorly wrong. A single character
typo in a commit message doesn't count as majorly wrong, so no - I won't
be rewriting history to fix it.

Thanks,
    Paul
diff mbox series

Patch

diff --git a/arch/mips/include/asm/mach-loongson64/loongson_regs.h b/arch/mips/include/asm/mach-loongson64/loongson_regs.h
new file mode 100644
index 00000000..6e3569a
--- /dev/null
+++ b/arch/mips/include/asm/mach-loongson64/loongson_regs.h
@@ -0,0 +1,227 @@ 
+/*
+ * Read/Write Loongson Extension Registers
+ */
+
+#ifndef _LOONGSON_REGS_H_
+#define _LOONGSON_REGS_H_
+
+#include <linux/types.h>
+#include <linux/bits.h>
+
+#include <asm/mipsregs.h>
+#include <asm/cpu.h>
+
+static inline bool cpu_has_cfg(void)
+{
+	return ((read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64G);
+}
+
+static inline u32 read_cpucfg(u32 reg)
+{
+	u32 __res;
+
+	__asm__ __volatile__(
+		"parse_r __res,%0\n\t"
+		"parse_r reg,%1\n\t"
+		".insn \n\t"
+		".word (0xc8080118 | (reg << 21) | (__res << 11))\n\t"
+		:"=r"(__res)
+		:"r"(reg)
+		:
+		);
+	return __res;
+}
+
+/* Bit Domains for CFG registers */
+#define LOONGSON_CFG0	0x0
+#define LOONGSON_CFG0_PRID GENMASK(31, 0)
+
+#define LOONGSON_CFG1 0x1
+#define LOONGSON_CFG1_FP	BIT(0)
+#define LOONGSON_CFG1_FPREV	GENMASK(3, 1)
+#define LOONGSON_CFG1_MMI	BIT(4)
+#define LOONGSON_CFG1_MSA1	BIT(5)
+#define LOONGSON_CFG1_MSA2	BIT(6)
+#define LOONGSON_CFG1_CGP	BIT(7)
+#define LOONGSON_CFG1_WRP	BIT(8)
+#define LOONGSON_CFG1_LSX1	BIT(9)
+#define LOONGSON_CFG1_LSX2	BIT(10)
+#define LOONGSON_CFG1_LASX	BIT(11)
+#define LOONGSON_CFG1_R6FXP	BIT(12)
+#define LOONGSON_CFG1_R6CRCP	BIT(13)
+#define LOONGSON_CFG1_R6FPP	BIT(14)
+#define LOONGSON_CFG1_CNT64	BIT(15)
+#define LOONGSON_CFG1_LSLDR0	BIT(16)
+#define LOONGSON_CFG1_LSPREF	BIT(17)
+#define LOONGSON_CFG1_LSPREFX	BIT(18)
+#define LOONGSON_CFG1_LSSYNCI	BIT(19)
+#define LOONGSON_CFG1_LSUCA	BIT(20)
+#define LOONGSON_CFG1_LLSYNC	BIT(21)
+#define LOONGSON_CFG1_TGTSYNC	BIT(22)
+#define LOONGSON_CFG1_LLEXC	BIT(23)
+#define LOONGSON_CFG1_SCRAND	BIT(24)
+#define LOONGSON_CFG1_MUALP	BIT(25)
+#define LOONGSON_CFG1_KMUALEN	BIT(26)
+#define LOONGSON_CFG1_ITLBT	BIT(27)
+#define LOONGSON_CFG1_LSUPERF	BIT(28)
+#define LOONGSON_CFG1_SFBP	BIT(29)
+#define LOONGSON_CFG1_CDMAP	BIT(30)
+
+#define LOONGSON_CFG2 0x2
+#define LOONGSON_CFG2_LEXT1	BIT(0)
+#define LOONGSON_CFG2_LEXT2	BIT(1)
+#define LOONGSON_CFG2_LEXT3	BIT(2)
+#define LOONGSON_CFG2_LSPW	BIT(3)
+#define LOONGSON_CFG2_LBT1	BIT(4)
+#define LOONGSON_CFG2_LBT2	BIT(5)
+#define LOONGSON_CFG2_LBT3	BIT(6)
+#define LOONGSON_CFG2_LBTMMU	BIT(7)
+#define LOONGSON_CFG2_LPMP	BIT(8)
+#define LOONGSON_CFG2_LPMPREV	GENMASK(11, 9)
+#define LOONGSON_CFG2_LAMO	BIT(12)
+#define LOONGSON_CFG2_LPIXU	BIT(13)
+#define LOONGSON_CFG2_LPIXUN	BIT(14)
+#define LOONGSON_CFG2_LZVP	BIT(15)
+#define LOONGSON_CFG2_LZVREV	GENMASK(18, 16)
+#define LOONGSON_CFG2_LGFTP	BIT(19)
+#define LOONGSON_CFG2_LGFTPREV	GENMASK(22, 20)
+#define LOONGSON_CFG2_LLFTP	BIT(23)
+#define LOONGSON_CFG2_LLFTPREV	GENMASK(24, 26)
+#define LOONGSON_CFG2_LCSRP	BIT(27)
+#define LOONGSON_CFG2_LDISBLIKELY	BIT(28)
+
+#define LOONGSON_CFG3 0x3
+#define LOONGSON_CFG3_LCAMP	BIT(0)
+#define LOONGSON_CFG3_LCAMREV	GENMASK(3, 1)
+#define LOONGSON_CFG3_LCAMNUM	GENMASK(11, 4)
+#define LOONGSON_CFG3_LCAMKW	GENMASK(19, 12)
+#define LOONGSON_CFG3_LCAMVW	GENMASK(27, 20)
+
+#define LOONGSON_CFG4 0x4
+#define LOONGSON_CFG4_CCFREQ	GENMASK(31, 0)
+
+#define LOONGSON_CFG5 0x5
+#define LOONGSON_CFG5_CFM	GENMASK(15, 0)
+#define LOONGSON_CFG5_CFD	GENMASK(31, 16)
+
+#define LOONGSON_CFG6 0x6
+
+#define LOONGSON_CFG7 0x7
+#define LOONGSON_CFG7_GCCAEQRP	BIT(0)
+#define LOONGSON_CFG7_UCAWINP	BIT(1)
+
+static inline bool cpu_has_csr(void)
+{
+	if (cpu_has_cfg())
+		return (read_cpucfg(LOONGSON_CFG2) & LOONGSON_CFG2_LCSRP);
+
+	return false;
+}
+
+static inline u32 csr_readl(u32 reg)
+{
+	u32 __res;
+
+	/* RDCSR reg, val */
+	__asm__ __volatile__(
+		"parse_r __res,%0\n\t"
+		"parse_r reg,%1\n\t"
+		".insn \n\t"
+		".word (0xc8000118 | (reg << 21) | (__res << 11))\n\t"
+		:"=r"(__res)
+		:"r"(reg)
+		:
+		);
+	return __res;
+}
+
+static inline u64 csr_readq(u32 reg)
+{
+	u64 __res;
+
+	/* DWRCSR reg, val */
+	__asm__ __volatile__(
+		"parse_r __res,%0\n\t"
+		"parse_r reg,%1\n\t"
+		".insn \n\t"
+		".word (0xc8020118 | (reg << 21) | (__res << 11))\n\t"
+		:"=r"(__res)
+		:"r"(reg)
+		:
+		);
+	return __res;
+}
+
+static inline void csr_writel(u32 val, u32 reg)
+{
+	/* WRCSR reg, val */
+	__asm__ __volatile__(
+		"parse_r reg,%0\n\t"
+		"parse_r val,%1\n\t"
+		".insn \n\t"
+		".word (0xc8010118 | (reg << 21) | (val << 11))\n\t"
+		:
+		:"r"(reg),"r"(val)
+		:
+		);
+}
+
+static inline void csr_writeq(u64 val, u32 reg)
+{
+	/* DWRCSR reg, val */
+	__asm__ __volatile__(
+		"parse_r reg,%0\n\t"
+		"parse_r val,%1\n\t"
+		".insn \n\t"
+		".word (0xc8030118 | (reg << 21) | (val << 11))\n\t"
+		:
+		:"r"(reg),"r"(val)
+		:
+		);
+}
+
+/* Public CSR Register can also be accessed with regular addresses */
+#define CSR_PUBLIC_MMIO_BASE 0x1fe00000
+
+#define MMIO_CSR(x)		(void *)TO_UNCAC(CSR_PUBLIC_MMIO_BASE + x)
+
+#define LOONGSON_CSR_FEATURES	0x8
+#define LOONGSON_CSRF_TEMP	BIT(0)
+#define LOONGSON_CSRF_NODECNT	BIT(1)
+#define LOONGSON_CSRF_MSI	BIT(2)
+#define LOONGSON_CSRF_EXTIOI	BIT(3)
+#define LOONGSON_CSRF_IPI	BIT(4)
+#define LOONGSON_CSRF_FREQ	BIT(5)
+
+#define LOONGSON_CSR_VENDOR	0x10 /* Vendor name string, should be "Loongson" */
+#define LOONGSON_CSR_CPUNAME	0x20 /* Processor name string */
+#define LOONGSON_CSR_NODECNT	0x408
+#define LOONGSON_CSR_CPUTEMP	0x428
+
+/* PerCore CSR, only accessable by local cores */
+#define LOONGSON_CSR_IPI_STATUS	0x1000
+#define LOONGSON_CSR_IPI_EN	0x1004
+#define LOONGSON_CSR_IPI_SET	0x1008
+#define LOONGSON_CSR_IPI_CLEAR	0x100c
+#define LOONGSON_CSR_IPI_SEND	0x1040
+#define CSR_IPI_SEND_IP_SHIFT	0
+#define CSR_IPI_SEND_CPU_SHIFT	16
+#define CSR_IPI_SEND_BLOCK	BIT(31)
+
+static inline u64 drdtime(void)
+{
+	int rID = 0;
+	u64 val = 0;
+
+	__asm__ __volatile__(
+		"parse_r rID,%0\n\t"
+		"parse_r val,%1\n\t"
+		".insn \n\t"
+		".word (0xc8090118 | (rID << 21) | (val << 11))\n\t"
+		:"=r"(rID),"=r"(val)
+		:
+		);
+	return val;
+}
+
+#endif