xref: /openbmc/qemu/target/ppc/cpu-qom.h (revision 370ed600)
1 /*
2  * QEMU PowerPC CPU
3  *
4  * Copyright (c) 2012 SUSE LINUX Products GmbH
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
18  * <http://www.gnu.org/licenses/lgpl-2.1.html>
19  */
20 #ifndef QEMU_PPC_CPU_QOM_H
21 #define QEMU_PPC_CPU_QOM_H
22 
23 #include "hw/core/cpu.h"
24 #include "qom/object.h"
25 
26 #ifdef TARGET_PPC64
27 #define TYPE_POWERPC_CPU "powerpc64-cpu"
28 #else
29 #define TYPE_POWERPC_CPU "powerpc-cpu"
30 #endif
31 
32 OBJECT_DECLARE_CPU_TYPE(PowerPCCPU, PowerPCCPUClass, POWERPC_CPU)
33 
34 ObjectClass *ppc_cpu_class_by_name(const char *name);
35 
36 typedef struct CPUArchState CPUPPCState;
37 typedef struct ppc_tb_t ppc_tb_t;
38 typedef struct ppc_dcr_t ppc_dcr_t;
39 
40 /*****************************************************************************/
41 /* MMU model                                                                 */
42 typedef enum powerpc_mmu_t powerpc_mmu_t;
43 enum powerpc_mmu_t {
44     POWERPC_MMU_UNKNOWN    = 0x00000000,
45     /* Standard 32 bits PowerPC MMU                            */
46     POWERPC_MMU_32B        = 0x00000001,
47     /* PowerPC 6xx MMU with software TLB                       */
48     POWERPC_MMU_SOFT_6xx   = 0x00000002,
49     /*
50      * PowerPC 74xx MMU with software TLB (this has been
51      * disabled, see git history for more information.
52      * keywords: tlbld tlbli TLBMISS PTEHI PTELO)
53      */
54     POWERPC_MMU_SOFT_74xx  = 0x00000003,
55     /* PowerPC 4xx MMU with software TLB                       */
56     POWERPC_MMU_SOFT_4xx   = 0x00000004,
57     /* PowerPC MMU in real mode only                           */
58     POWERPC_MMU_REAL       = 0x00000006,
59     /* Freescale MPC8xx MMU model                              */
60     POWERPC_MMU_MPC8xx     = 0x00000007,
61     /* BookE MMU model                                         */
62     POWERPC_MMU_BOOKE      = 0x00000008,
63     /* BookE 2.06 MMU model                                    */
64     POWERPC_MMU_BOOKE206   = 0x00000009,
65 #define POWERPC_MMU_64       0x00010000
66     /* 64 bits PowerPC MMU                                     */
67     POWERPC_MMU_64B        = POWERPC_MMU_64 | 0x00000001,
68     /* Architecture 2.03 and later (has LPCR) */
69     POWERPC_MMU_2_03       = POWERPC_MMU_64 | 0x00000002,
70     /* Architecture 2.06 variant                               */
71     POWERPC_MMU_2_06       = POWERPC_MMU_64 | 0x00000003,
72     /* Architecture 2.07 variant                               */
73     POWERPC_MMU_2_07       = POWERPC_MMU_64 | 0x00000004,
74     /* Architecture 3.00 variant                               */
75     POWERPC_MMU_3_00       = POWERPC_MMU_64 | 0x00000005,
76 };
77 
78 static inline bool mmu_is_64bit(powerpc_mmu_t mmu_model)
79 {
80     return mmu_model & POWERPC_MMU_64;
81 }
82 
83 /*****************************************************************************/
84 /* Exception model                                                           */
85 typedef enum powerpc_excp_t powerpc_excp_t;
86 enum powerpc_excp_t {
87     POWERPC_EXCP_UNKNOWN   = 0,
88     /* Standard PowerPC exception model */
89     POWERPC_EXCP_STD,
90     /* PowerPC 40x exception model      */
91     POWERPC_EXCP_40x,
92     /* PowerPC 603/604/G2 exception model */
93     POWERPC_EXCP_6xx,
94     /* PowerPC 7xx exception model      */
95     POWERPC_EXCP_7xx,
96     /* PowerPC 74xx exception model     */
97     POWERPC_EXCP_74xx,
98     /* BookE exception model            */
99     POWERPC_EXCP_BOOKE,
100     /* PowerPC 970 exception model      */
101     POWERPC_EXCP_970,
102     /* POWER7 exception model           */
103     POWERPC_EXCP_POWER7,
104     /* POWER8 exception model           */
105     POWERPC_EXCP_POWER8,
106     /* POWER9 exception model           */
107     POWERPC_EXCP_POWER9,
108     /* POWER10 exception model           */
109     POWERPC_EXCP_POWER10,
110 };
111 
112 /*****************************************************************************/
113 /* PM instructions */
114 typedef enum {
115     PPC_PM_DOZE,
116     PPC_PM_NAP,
117     PPC_PM_SLEEP,
118     PPC_PM_RVWINKLE,
119     PPC_PM_STOP,
120 } powerpc_pm_insn_t;
121 
122 /*****************************************************************************/
123 /* Input pins model                                                          */
124 typedef enum powerpc_input_t powerpc_input_t;
125 enum powerpc_input_t {
126     PPC_FLAGS_INPUT_UNKNOWN = 0,
127     /* PowerPC 6xx bus                  */
128     PPC_FLAGS_INPUT_6xx,
129     /* BookE bus                        */
130     PPC_FLAGS_INPUT_BookE,
131     /* PowerPC 405 bus                  */
132     PPC_FLAGS_INPUT_405,
133     /* PowerPC 970 bus                  */
134     PPC_FLAGS_INPUT_970,
135     /* PowerPC POWER7 bus               */
136     PPC_FLAGS_INPUT_POWER7,
137     /* PowerPC POWER9 bus               */
138     PPC_FLAGS_INPUT_POWER9,
139     /* Freescale RCPU bus               */
140     PPC_FLAGS_INPUT_RCPU,
141 };
142 
143 typedef struct PPCHash64Options PPCHash64Options;
144 
145 /**
146  * PowerPCCPUClass:
147  * @parent_realize: The parent class' realize handler.
148  * @parent_phases: The parent class' reset phase handlers.
149  *
150  * A PowerPC CPU model.
151  */
152 struct PowerPCCPUClass {
153     /*< private >*/
154     CPUClass parent_class;
155     /*< public >*/
156 
157     DeviceRealize parent_realize;
158     DeviceUnrealize parent_unrealize;
159     ResettablePhases parent_phases;
160     void (*parent_parse_features)(const char *type, char *str, Error **errp);
161 
162     uint32_t pvr;
163     /*
164      * If @best is false, match if pcc is in the family of pvr
165      * Else match only if pcc is the best match for pvr in this family.
166      */
167     bool (*pvr_match)(struct PowerPCCPUClass *pcc, uint32_t pvr, bool best);
168     uint64_t pcr_mask;          /* Available bits in PCR register */
169     uint64_t pcr_supported;     /* Bits for supported PowerISA versions */
170     uint32_t svr;
171     uint64_t insns_flags;
172     uint64_t insns_flags2;
173     uint64_t msr_mask;
174     uint64_t lpcr_mask;         /* Available bits in the LPCR */
175     uint64_t lpcr_pm;           /* Power-saving mode Exit Cause Enable bits */
176     powerpc_mmu_t   mmu_model;
177     powerpc_excp_t  excp_model;
178     powerpc_input_t bus_model;
179     uint32_t flags;
180     int bfd_mach;
181     uint32_t l1_dcache_size, l1_icache_size;
182 #ifndef CONFIG_USER_ONLY
183     unsigned int gdb_num_sprs;
184     const char *gdb_spr_xml;
185 #endif
186     const PPCHash64Options *hash64_opts;
187     struct ppc_radix_page_info *radix_page_info;
188     uint32_t lrg_decr_bits;
189     int n_host_threads;
190     void (*init_proc)(CPUPPCState *env);
191     int  (*check_pow)(CPUPPCState *env);
192 };
193 
194 #ifndef CONFIG_USER_ONLY
195 typedef struct PPCTimebase {
196     uint64_t guest_timebase;
197     int64_t time_of_the_day_ns;
198     bool runstate_paused;
199 } PPCTimebase;
200 
201 extern const VMStateDescription vmstate_ppc_timebase;
202 
203 #define VMSTATE_PPC_TIMEBASE_V(_field, _state, _version) {            \
204     .name       = (stringify(_field)),                                \
205     .version_id = (_version),                                         \
206     .size       = sizeof(PPCTimebase),                                \
207     .vmsd       = &vmstate_ppc_timebase,                              \
208     .flags      = VMS_STRUCT,                                         \
209     .offset     = vmstate_offset_value(_state, _field, PPCTimebase),  \
210 }
211 
212 void cpu_ppc_clock_vm_state_change(void *opaque, bool running,
213                                    RunState state);
214 #endif
215 
216 #endif
217