xref: /openbmc/qemu/target/ppc/spr_common.h (revision 05caa062)
1 /*
2  *  PowerPC emulation for qemu: read/write callbacks for SPRs
3  *
4  *  Copyright (C) 2021 Instituto de Pesquisas Eldorado
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef SPR_COMMON_H
20 #define SPR_COMMON_H
21 
22 #define SPR_NOACCESS (&spr_noaccess)
23 
24 #ifdef CONFIG_TCG
25 # define USR_ARG(X)    X,
26 # ifdef CONFIG_USER_ONLY
27 #  define SYS_ARG(X)
28 # else
29 #  define SYS_ARG(X)   X,
30 # endif
31 #else
32 # define USR_ARG(X)
33 # define SYS_ARG(X)
34 #endif
35 #ifdef CONFIG_KVM
36 # define KVM_ARG(X)    X,
37 #else
38 # define KVM_ARG(X)
39 #endif
40 
41 typedef void spr_callback(DisasContext *, int, int);
42 
43 void _spr_register(CPUPPCState *env, int num, const char *name,
44                    USR_ARG(spr_callback *uea_read)
45                    USR_ARG(spr_callback *uea_write)
46                    SYS_ARG(spr_callback *oea_read)
47                    SYS_ARG(spr_callback *oea_write)
48                    SYS_ARG(spr_callback *hea_read)
49                    SYS_ARG(spr_callback *hea_write)
50                    KVM_ARG(uint64_t one_reg_id)
51                    target_ulong initial_value);
52 
53 /* spr_register_kvm_hv passes all required arguments. */
54 #define spr_register_kvm_hv(env, num, name, uea_read, uea_write,             \
55                             oea_read, oea_write, hea_read, hea_write,        \
56                             one_reg_id, initial_value)                       \
57     _spr_register(env, num, name,                                            \
58                   USR_ARG(uea_read) USR_ARG(uea_write)                       \
59                   SYS_ARG(oea_read) SYS_ARG(oea_write)                       \
60                   SYS_ARG(hea_read) SYS_ARG(hea_write)                       \
61                   KVM_ARG(one_reg_id) initial_value)
62 
63 /* spr_register_kvm duplicates the oea callbacks to the hea callbacks. */
64 #define spr_register_kvm(env, num, name, uea_read, uea_write,                \
65                          oea_read, oea_write, one_reg_id, ival)              \
66     spr_register_kvm_hv(env, num, name, uea_read, uea_write, oea_read,       \
67                         oea_write, oea_read, oea_write, one_reg_id, ival)
68 
69 /* spr_register_hv and spr_register are similar, except there is no kvm id. */
70 #define spr_register_hv(env, num, name, uea_read, uea_write,                 \
71                         oea_read, oea_write, hea_read, hea_write, ival)      \
72     spr_register_kvm_hv(env, num, name, uea_read, uea_write, oea_read,       \
73                         oea_write, hea_read, hea_write, 0, ival)
74 
75 #define spr_register(env, num, name, uea_read, uea_write,                    \
76                      oea_read, oea_write, ival)                              \
77     spr_register_kvm(env, num, name, uea_read, uea_write,                    \
78                      oea_read, oea_write, 0, ival)
79 
80 /* prototypes for readers and writers for SPRs */
81 void spr_noaccess(DisasContext *ctx, int gprn, int sprn);
82 void spr_read_generic(DisasContext *ctx, int gprn, int sprn);
83 void spr_write_generic(DisasContext *ctx, int sprn, int gprn);
84 void spr_write_generic32(DisasContext *ctx, int sprn, int gprn);
85 void spr_core_write_generic(DisasContext *ctx, int sprn, int gprn);
86 void spr_core_write_generic32(DisasContext *ctx, int sprn, int gprn);
87 void spr_core_lpar_write_generic(DisasContext *ctx, int sprn, int gprn);
88 void spr_write_MMCR0(DisasContext *ctx, int sprn, int gprn);
89 void spr_write_MMCR1(DisasContext *ctx, int sprn, int gprn);
90 void spr_write_MMCRA(DisasContext *ctx, int sprn, int gprn);
91 void spr_write_PMC(DisasContext *ctx, int sprn, int gprn);
92 void spr_write_CTRL(DisasContext *ctx, int sprn, int gprn);
93 void spr_read_xer(DisasContext *ctx, int gprn, int sprn);
94 void spr_write_xer(DisasContext *ctx, int sprn, int gprn);
95 void spr_read_lr(DisasContext *ctx, int gprn, int sprn);
96 void spr_write_lr(DisasContext *ctx, int sprn, int gprn);
97 void spr_read_ctr(DisasContext *ctx, int gprn, int sprn);
98 void spr_write_ctr(DisasContext *ctx, int sprn, int gprn);
99 void spr_read_ureg(DisasContext *ctx, int gprn, int sprn);
100 void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, int sprn);
101 void spr_read_MMCR2_ureg(DisasContext *ctx, int gprn, int sprn);
102 void spr_read_PMC(DisasContext *ctx, int gprn, int sprn);
103 void spr_read_PMC14_ureg(DisasContext *ctx, int gprn, int sprn);
104 void spr_read_PMC56_ureg(DisasContext *ctx, int gprn, int sprn);
105 void spr_read_tbl(DisasContext *ctx, int gprn, int sprn);
106 void spr_read_tbu(DisasContext *ctx, int gprn, int sprn);
107 void spr_read_atbl(DisasContext *ctx, int gprn, int sprn);
108 void spr_read_atbu(DisasContext *ctx, int gprn, int sprn);
109 void spr_read_spefscr(DisasContext *ctx, int gprn, int sprn);
110 void spr_write_spefscr(DisasContext *ctx, int sprn, int gprn);
111 void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn, int gprn);
112 void spr_write_MMCR2_ureg(DisasContext *ctx, int sprn, int gprn);
113 void spr_write_PMC14_ureg(DisasContext *ctx, int sprn, int gprn);
114 void spr_write_PMC56_ureg(DisasContext *ctx, int sprn, int gprn);
115 
116 #ifndef CONFIG_USER_ONLY
117 void spr_write_clear(DisasContext *ctx, int sprn, int gprn);
118 void spr_access_nop(DisasContext *ctx, int sprn, int gprn);
119 void spr_read_decr(DisasContext *ctx, int gprn, int sprn);
120 void spr_write_decr(DisasContext *ctx, int sprn, int gprn);
121 void spr_write_tbl(DisasContext *ctx, int sprn, int gprn);
122 void spr_write_tbu(DisasContext *ctx, int sprn, int gprn);
123 void spr_write_atbl(DisasContext *ctx, int sprn, int gprn);
124 void spr_write_atbu(DisasContext *ctx, int sprn, int gprn);
125 void spr_read_ibat(DisasContext *ctx, int gprn, int sprn);
126 void spr_read_ibat_h(DisasContext *ctx, int gprn, int sprn);
127 void spr_write_ibatu(DisasContext *ctx, int sprn, int gprn);
128 void spr_write_ibatu_h(DisasContext *ctx, int sprn, int gprn);
129 void spr_write_ibatl(DisasContext *ctx, int sprn, int gprn);
130 void spr_write_ibatl_h(DisasContext *ctx, int sprn, int gprn);
131 void spr_read_dbat(DisasContext *ctx, int gprn, int sprn);
132 void spr_read_dbat_h(DisasContext *ctx, int gprn, int sprn);
133 void spr_write_dbatu(DisasContext *ctx, int sprn, int gprn);
134 void spr_write_dbatu_h(DisasContext *ctx, int sprn, int gprn);
135 void spr_write_dbatl(DisasContext *ctx, int sprn, int gprn);
136 void spr_write_dbatl_h(DisasContext *ctx, int sprn, int gprn);
137 void spr_write_sdr1(DisasContext *ctx, int sprn, int gprn);
138 void spr_read_40x_pit(DisasContext *ctx, int gprn, int sprn);
139 void spr_write_40x_pit(DisasContext *ctx, int sprn, int gprn);
140 void spr_write_40x_dbcr0(DisasContext *ctx, int sprn, int gprn);
141 void spr_write_40x_sler(DisasContext *ctx, int sprn, int gprn);
142 void spr_write_40x_tcr(DisasContext *ctx, int sprn, int gprn);
143 void spr_write_40x_tsr(DisasContext *ctx, int sprn, int gprn);
144 void spr_write_40x_pid(DisasContext *ctx, int sprn, int gprn);
145 void spr_write_booke_tcr(DisasContext *ctx, int sprn, int gprn);
146 void spr_write_booke_tsr(DisasContext *ctx, int sprn, int gprn);
147 void spr_read_403_pbr(DisasContext *ctx, int gprn, int sprn);
148 void spr_write_403_pbr(DisasContext *ctx, int sprn, int gprn);
149 void spr_write_pir(DisasContext *ctx, int sprn, int gprn);
150 void spr_write_excp_prefix(DisasContext *ctx, int sprn, int gprn);
151 void spr_write_excp_vector(DisasContext *ctx, int sprn, int gprn);
152 void spr_read_thrm(DisasContext *ctx, int gprn, int sprn);
153 void spr_write_e500_l1csr0(DisasContext *ctx, int sprn, int gprn);
154 void spr_write_e500_l1csr1(DisasContext *ctx, int sprn, int gprn);
155 void spr_write_e500_l2csr0(DisasContext *ctx, int sprn, int gprn);
156 void spr_write_booke206_mmucsr0(DisasContext *ctx, int sprn, int gprn);
157 void spr_write_booke_pid(DisasContext *ctx, int sprn, int gprn);
158 void spr_write_eplc(DisasContext *ctx, int sprn, int gprn);
159 void spr_write_epsc(DisasContext *ctx, int sprn, int gprn);
160 void spr_write_mas73(DisasContext *ctx, int sprn, int gprn);
161 void spr_read_mas73(DisasContext *ctx, int gprn, int sprn);
162 #ifdef TARGET_PPC64
163 void spr_read_cfar(DisasContext *ctx, int gprn, int sprn);
164 void spr_write_cfar(DisasContext *ctx, int sprn, int gprn);
165 void spr_write_ciabr(DisasContext *ctx, int sprn, int gprn);
166 void spr_write_dawr0(DisasContext *ctx, int sprn, int gprn);
167 void spr_write_dawrx0(DisasContext *ctx, int sprn, int gprn);
168 void spr_write_ureg(DisasContext *ctx, int sprn, int gprn);
169 void spr_read_purr(DisasContext *ctx, int gprn, int sprn);
170 void spr_write_purr(DisasContext *ctx, int sprn, int gprn);
171 void spr_read_hdecr(DisasContext *ctx, int gprn, int sprn);
172 void spr_write_hdecr(DisasContext *ctx, int sprn, int gprn);
173 void spr_read_vtb(DisasContext *ctx, int gprn, int sprn);
174 void spr_write_vtb(DisasContext *ctx, int sprn, int gprn);
175 void spr_write_tbu40(DisasContext *ctx, int sprn, int gprn);
176 void spr_write_pidr(DisasContext *ctx, int sprn, int gprn);
177 void spr_write_lpidr(DisasContext *ctx, int sprn, int gprn);
178 void spr_read_hior(DisasContext *ctx, int gprn, int sprn);
179 void spr_write_hior(DisasContext *ctx, int sprn, int gprn);
180 void spr_write_ptcr(DisasContext *ctx, int sprn, int gprn);
181 void spr_write_pcr(DisasContext *ctx, int sprn, int gprn);
182 void spr_read_dpdes(DisasContext *ctx, int gprn, int sprn);
183 void spr_write_dpdes(DisasContext *ctx, int sprn, int gprn);
184 void spr_write_amr(DisasContext *ctx, int sprn, int gprn);
185 void spr_write_uamor(DisasContext *ctx, int sprn, int gprn);
186 void spr_write_iamr(DisasContext *ctx, int sprn, int gprn);
187 #endif
188 #endif
189 
190 #ifdef TARGET_PPC64
191 void spr_read_prev_upper32(DisasContext *ctx, int gprn, int sprn);
192 void spr_write_prev_upper32(DisasContext *ctx, int sprn, int gprn);
193 void spr_read_tar(DisasContext *ctx, int gprn, int sprn);
194 void spr_write_tar(DisasContext *ctx, int sprn, int gprn);
195 void spr_read_tm(DisasContext *ctx, int gprn, int sprn);
196 void spr_write_tm(DisasContext *ctx, int sprn, int gprn);
197 void spr_read_tm_upper32(DisasContext *ctx, int gprn, int sprn);
198 void spr_write_tm_upper32(DisasContext *ctx, int sprn, int gprn);
199 void spr_read_ebb(DisasContext *ctx, int gprn, int sprn);
200 void spr_write_ebb(DisasContext *ctx, int sprn, int gprn);
201 void spr_read_ebb_upper32(DisasContext *ctx, int gprn, int sprn);
202 void spr_write_ebb_upper32(DisasContext *ctx, int sprn, int gprn);
203 void spr_write_hmer(DisasContext *ctx, int sprn, int gprn);
204 void spr_read_tfmr(DisasContext *ctx, int gprn, int sprn);
205 void spr_write_tfmr(DisasContext *ctx, int sprn, int gprn);
206 void spr_write_lpcr(DisasContext *ctx, int sprn, int gprn);
207 void spr_read_dexcr_ureg(DisasContext *ctx, int gprn, int sprn);
208 void spr_read_ppr32(DisasContext *ctx, int sprn, int gprn);
209 void spr_write_ppr32(DisasContext *ctx, int sprn, int gprn);
210 void spr_write_sprc(DisasContext *ctx, int sprn, int gprn);
211 void spr_read_sprd(DisasContext *ctx, int sprn, int gprn);
212 void spr_write_sprd(DisasContext *ctx, int sprn, int gprn);
213 #endif
214 
215 void register_low_BATs(CPUPPCState *env);
216 void register_high_BATs(CPUPPCState *env);
217 void register_sdr1_sprs(CPUPPCState *env);
218 void register_thrm_sprs(CPUPPCState *env);
219 void register_usprgh_sprs(CPUPPCState *env);
220 void register_non_embedded_sprs(CPUPPCState *env);
221 void register_6xx_7xx_soft_tlb(CPUPPCState *env, int nb_tlbs, int nb_ways);
222 void register_generic_sprs(PowerPCCPU *cpu);
223 
224 #endif
225