1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (C) 2013 Imagination Technologies
4*4882a593Smuzhiyun * Author: Paul Burton <paul.burton@mips.com>
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun #ifndef __MIPS_ASM_MIPS_CPS_H__
8*4882a593Smuzhiyun # error Please include asm/mips-cps.h rather than asm/mips-cpc.h
9*4882a593Smuzhiyun #endif
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #ifndef __MIPS_ASM_MIPS_CPC_H__
12*4882a593Smuzhiyun #define __MIPS_ASM_MIPS_CPC_H__
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #include <linux/bitops.h>
15*4882a593Smuzhiyun #include <linux/errno.h>
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun /* The base address of the CPC registers */
18*4882a593Smuzhiyun extern void __iomem *mips_cpc_base;
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun /**
21*4882a593Smuzhiyun * mips_cpc_default_phys_base - retrieve the default physical base address of
22*4882a593Smuzhiyun * the CPC
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * Returns the default physical base address of the Cluster Power Controller
25*4882a593Smuzhiyun * memory mapped registers. This is platform dependant & must therefore be
26*4882a593Smuzhiyun * implemented per-platform.
27*4882a593Smuzhiyun */
28*4882a593Smuzhiyun extern phys_addr_t mips_cpc_default_phys_base(void);
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun /**
31*4882a593Smuzhiyun * mips_cpc_probe - probe for a Cluster Power Controller
32*4882a593Smuzhiyun *
33*4882a593Smuzhiyun * Attempt to detect the presence of a Cluster Power Controller. Returns 0 if
34*4882a593Smuzhiyun * a CPC is successfully detected, else -errno.
35*4882a593Smuzhiyun */
36*4882a593Smuzhiyun #ifdef CONFIG_MIPS_CPC
37*4882a593Smuzhiyun extern int mips_cpc_probe(void);
38*4882a593Smuzhiyun #else
mips_cpc_probe(void)39*4882a593Smuzhiyun static inline int mips_cpc_probe(void)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun return -ENODEV;
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun #endif
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun /**
46*4882a593Smuzhiyun * mips_cpc_present - determine whether a Cluster Power Controller is present
47*4882a593Smuzhiyun *
48*4882a593Smuzhiyun * Returns true if a CPC is present in the system, else false.
49*4882a593Smuzhiyun */
mips_cpc_present(void)50*4882a593Smuzhiyun static inline bool mips_cpc_present(void)
51*4882a593Smuzhiyun {
52*4882a593Smuzhiyun #ifdef CONFIG_MIPS_CPC
53*4882a593Smuzhiyun return mips_cpc_base != NULL;
54*4882a593Smuzhiyun #else
55*4882a593Smuzhiyun return false;
56*4882a593Smuzhiyun #endif
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /* Offsets from the CPC base address to various control blocks */
60*4882a593Smuzhiyun #define MIPS_CPC_GCB_OFS 0x0000
61*4882a593Smuzhiyun #define MIPS_CPC_CLCB_OFS 0x2000
62*4882a593Smuzhiyun #define MIPS_CPC_COCB_OFS 0x4000
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun #define CPC_ACCESSOR_RO(sz, off, name) \
65*4882a593Smuzhiyun CPS_ACCESSOR_RO(cpc, sz, MIPS_CPC_GCB_OFS + off, name) \
66*4882a593Smuzhiyun CPS_ACCESSOR_RO(cpc, sz, MIPS_CPC_COCB_OFS + off, redir_##name)
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #define CPC_ACCESSOR_RW(sz, off, name) \
69*4882a593Smuzhiyun CPS_ACCESSOR_RW(cpc, sz, MIPS_CPC_GCB_OFS + off, name) \
70*4882a593Smuzhiyun CPS_ACCESSOR_RW(cpc, sz, MIPS_CPC_COCB_OFS + off, redir_##name)
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun #define CPC_CX_ACCESSOR_RO(sz, off, name) \
73*4882a593Smuzhiyun CPS_ACCESSOR_RO(cpc, sz, MIPS_CPC_CLCB_OFS + off, cl_##name) \
74*4882a593Smuzhiyun CPS_ACCESSOR_RO(cpc, sz, MIPS_CPC_COCB_OFS + off, co_##name)
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun #define CPC_CX_ACCESSOR_RW(sz, off, name) \
77*4882a593Smuzhiyun CPS_ACCESSOR_RW(cpc, sz, MIPS_CPC_CLCB_OFS + off, cl_##name) \
78*4882a593Smuzhiyun CPS_ACCESSOR_RW(cpc, sz, MIPS_CPC_COCB_OFS + off, co_##name)
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /* CPC_ACCESS - Control core/IOCU access to CPC registers prior to CM 3 */
81*4882a593Smuzhiyun CPC_ACCESSOR_RW(32, 0x000, access)
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun /* CPC_SEQDEL - Configure delays between command sequencer steps */
84*4882a593Smuzhiyun CPC_ACCESSOR_RW(32, 0x008, seqdel)
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun /* CPC_RAIL - Configure the delay from rail power-up to stability */
87*4882a593Smuzhiyun CPC_ACCESSOR_RW(32, 0x010, rail)
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun /* CPC_RESETLEN - Configure the length of reset sequences */
90*4882a593Smuzhiyun CPC_ACCESSOR_RW(32, 0x018, resetlen)
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun /* CPC_REVISION - Indicates the revisison of the CPC */
93*4882a593Smuzhiyun CPC_ACCESSOR_RO(32, 0x020, revision)
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun /* CPC_PWRUP_CTL - Control power to the Coherence Manager (CM) */
96*4882a593Smuzhiyun CPC_ACCESSOR_RW(32, 0x030, pwrup_ctl)
97*4882a593Smuzhiyun #define CPC_PWRUP_CTL_CM_PWRUP BIT(0)
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /* CPC_CONFIG - Mirrors GCR_CONFIG */
100*4882a593Smuzhiyun CPC_ACCESSOR_RW(64, 0x138, config)
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /* CPC_SYS_CONFIG - Control cluster endianness */
103*4882a593Smuzhiyun CPC_ACCESSOR_RW(32, 0x140, sys_config)
104*4882a593Smuzhiyun #define CPC_SYS_CONFIG_BE_IMMEDIATE BIT(2)
105*4882a593Smuzhiyun #define CPC_SYS_CONFIG_BE_STATUS BIT(1)
106*4882a593Smuzhiyun #define CPC_SYS_CONFIG_BE BIT(0)
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun /* CPC_Cx_CMD - Instruct the CPC to take action on a core */
109*4882a593Smuzhiyun CPC_CX_ACCESSOR_RW(32, 0x000, cmd)
110*4882a593Smuzhiyun #define CPC_Cx_CMD GENMASK(3, 0)
111*4882a593Smuzhiyun #define CPC_Cx_CMD_CLOCKOFF 0x1
112*4882a593Smuzhiyun #define CPC_Cx_CMD_PWRDOWN 0x2
113*4882a593Smuzhiyun #define CPC_Cx_CMD_PWRUP 0x3
114*4882a593Smuzhiyun #define CPC_Cx_CMD_RESET 0x4
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /* CPC_Cx_STAT_CONF - Indicates core configuration & state */
117*4882a593Smuzhiyun CPC_CX_ACCESSOR_RW(32, 0x008, stat_conf)
118*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_PWRUPE BIT(23)
119*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE GENMASK(22, 19)
120*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_D0 0x0
121*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_U0 0x1
122*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_U1 0x2
123*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_U2 0x3
124*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_U3 0x4
125*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_U4 0x5
126*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_U5 0x6
127*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_U6 0x7
128*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_D1 0x8
129*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_D3 0x9
130*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_SEQSTATE_D2 0xa
131*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_CLKGAT_IMPL BIT(17)
132*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_PWRDN_IMPL BIT(16)
133*4882a593Smuzhiyun #define CPC_Cx_STAT_CONF_EJTAG_PROBE BIT(15)
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun /* CPC_Cx_OTHER - Configure the core-other register block prior to CM 3 */
136*4882a593Smuzhiyun CPC_CX_ACCESSOR_RW(32, 0x010, other)
137*4882a593Smuzhiyun #define CPC_Cx_OTHER_CORENUM GENMASK(23, 16)
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun /* CPC_Cx_VP_STOP - Stop Virtual Processors (VPs) within a core from running */
140*4882a593Smuzhiyun CPC_CX_ACCESSOR_RW(32, 0x020, vp_stop)
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun /* CPC_Cx_VP_START - Start Virtual Processors (VPs) within a core running */
143*4882a593Smuzhiyun CPC_CX_ACCESSOR_RW(32, 0x028, vp_run)
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun /* CPC_Cx_VP_RUNNING - Indicate which Virtual Processors (VPs) are running */
146*4882a593Smuzhiyun CPC_CX_ACCESSOR_RW(32, 0x030, vp_running)
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun /* CPC_Cx_CONFIG - Mirrors GCR_Cx_CONFIG */
149*4882a593Smuzhiyun CPC_CX_ACCESSOR_RW(32, 0x090, config)
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun #ifdef CONFIG_MIPS_CPC
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun /**
154*4882a593Smuzhiyun * mips_cpc_lock_other - lock access to another core
155*4882a593Smuzhiyun * core: the other core to be accessed
156*4882a593Smuzhiyun *
157*4882a593Smuzhiyun * Call before operating upon a core via the 'other' register region in
158*4882a593Smuzhiyun * order to prevent the region being moved during access. Must be called
159*4882a593Smuzhiyun * within the bounds of a mips_cm_{lock,unlock}_other pair, and followed
160*4882a593Smuzhiyun * by a call to mips_cpc_unlock_other.
161*4882a593Smuzhiyun */
162*4882a593Smuzhiyun extern void mips_cpc_lock_other(unsigned int core);
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun /**
165*4882a593Smuzhiyun * mips_cpc_unlock_other - unlock access to another core
166*4882a593Smuzhiyun *
167*4882a593Smuzhiyun * Call after operating upon another core via the 'other' register region.
168*4882a593Smuzhiyun * Must be called after mips_cpc_lock_other.
169*4882a593Smuzhiyun */
170*4882a593Smuzhiyun extern void mips_cpc_unlock_other(void);
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun #else /* !CONFIG_MIPS_CPC */
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun static inline void mips_cpc_lock_other(unsigned int core) { }
175*4882a593Smuzhiyun static inline void mips_cpc_unlock_other(void) { }
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun #endif /* !CONFIG_MIPS_CPC */
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun #endif /* __MIPS_ASM_MIPS_CPC_H__ */
180