xref: /openbmc/qemu/target/ppc/cpu-qom.h (revision 66453c0f)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth  * QEMU PowerPC CPU
3fcf5ef2aSThomas Huth  *
4fcf5ef2aSThomas Huth  * Copyright (c) 2012 SUSE LINUX Products GmbH
5fcf5ef2aSThomas Huth  *
6fcf5ef2aSThomas Huth  * This library is free software; you can redistribute it and/or
7fcf5ef2aSThomas Huth  * modify it under the terms of the GNU Lesser General Public
8fcf5ef2aSThomas Huth  * License as published by the Free Software Foundation; either
9fcf5ef2aSThomas Huth  * version 2.1 of the License, or (at your option) any later version.
10fcf5ef2aSThomas Huth  *
11fcf5ef2aSThomas Huth  * This library is distributed in the hope that it will be useful,
12fcf5ef2aSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13fcf5ef2aSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14fcf5ef2aSThomas Huth  * Lesser General Public License for more details.
15fcf5ef2aSThomas Huth  *
16fcf5ef2aSThomas Huth  * You should have received a copy of the GNU Lesser General Public
17fcf5ef2aSThomas Huth  * License along with this library; if not, see
18fcf5ef2aSThomas Huth  * <http://www.gnu.org/licenses/lgpl-2.1.html>
19fcf5ef2aSThomas Huth  */
20fcf5ef2aSThomas Huth #ifndef QEMU_PPC_CPU_QOM_H
21fcf5ef2aSThomas Huth #define QEMU_PPC_CPU_QOM_H
22fcf5ef2aSThomas Huth 
232e5b09fdSMarkus Armbruster #include "hw/core/cpu.h"
24db1015e9SEduardo Habkost #include "qom/object.h"
25fcf5ef2aSThomas Huth 
26fcf5ef2aSThomas Huth #ifdef TARGET_PPC64
27fcf5ef2aSThomas Huth #define TYPE_POWERPC_CPU "powerpc64-cpu"
28fcf5ef2aSThomas Huth #else
29fcf5ef2aSThomas Huth #define TYPE_POWERPC_CPU "powerpc-cpu"
30fcf5ef2aSThomas Huth #endif
31fcf5ef2aSThomas Huth 
329295b1aaSPhilippe Mathieu-Daudé OBJECT_DECLARE_CPU_TYPE(PowerPCCPU, PowerPCCPUClass, POWERPC_CPU)
33fcf5ef2aSThomas Huth 
34*66453c0fSPhilippe Mathieu-Daudé #define POWERPC_CPU_TYPE_SUFFIX "-" TYPE_POWERPC_CPU
35*66453c0fSPhilippe Mathieu-Daudé #define POWERPC_CPU_TYPE_NAME(model) model POWERPC_CPU_TYPE_SUFFIX
36*66453c0fSPhilippe Mathieu-Daudé #define CPU_RESOLVING_TYPE TYPE_POWERPC_CPU
37*66453c0fSPhilippe Mathieu-Daudé 
380f3fea21SPhilippe Mathieu-Daudé ObjectClass *ppc_cpu_class_by_name(const char *name);
390f3fea21SPhilippe Mathieu-Daudé 
401ea4a06aSPhilippe Mathieu-Daudé typedef struct CPUArchState CPUPPCState;
41fcf5ef2aSThomas Huth typedef struct ppc_tb_t ppc_tb_t;
42fcf5ef2aSThomas Huth typedef struct ppc_dcr_t ppc_dcr_t;
43fcf5ef2aSThomas Huth 
44fcf5ef2aSThomas Huth /*****************************************************************************/
45fcf5ef2aSThomas Huth /* MMU model                                                                 */
46fcf5ef2aSThomas Huth typedef enum powerpc_mmu_t powerpc_mmu_t;
47fcf5ef2aSThomas Huth enum powerpc_mmu_t {
48fcf5ef2aSThomas Huth     POWERPC_MMU_UNKNOWN    = 0x00000000,
49fcf5ef2aSThomas Huth     /* Standard 32 bits PowerPC MMU                            */
50fcf5ef2aSThomas Huth     POWERPC_MMU_32B        = 0x00000001,
51fcf5ef2aSThomas Huth     /* PowerPC 6xx MMU with software TLB                       */
52fcf5ef2aSThomas Huth     POWERPC_MMU_SOFT_6xx   = 0x00000002,
53a09410edSFabiano Rosas     /*
54a09410edSFabiano Rosas      * PowerPC 74xx MMU with software TLB (this has been
55a09410edSFabiano Rosas      * disabled, see git history for more information.
56a09410edSFabiano Rosas      * keywords: tlbld tlbli TLBMISS PTEHI PTELO)
57a09410edSFabiano Rosas      */
58fcf5ef2aSThomas Huth     POWERPC_MMU_SOFT_74xx  = 0x00000003,
59fcf5ef2aSThomas Huth     /* PowerPC 4xx MMU with software TLB                       */
60fcf5ef2aSThomas Huth     POWERPC_MMU_SOFT_4xx   = 0x00000004,
61fcf5ef2aSThomas Huth     /* PowerPC MMU in real mode only                           */
62fcf5ef2aSThomas Huth     POWERPC_MMU_REAL       = 0x00000006,
63fcf5ef2aSThomas Huth     /* Freescale MPC8xx MMU model                              */
64fcf5ef2aSThomas Huth     POWERPC_MMU_MPC8xx     = 0x00000007,
65fcf5ef2aSThomas Huth     /* BookE MMU model                                         */
66fcf5ef2aSThomas Huth     POWERPC_MMU_BOOKE      = 0x00000008,
67fcf5ef2aSThomas Huth     /* BookE 2.06 MMU model                                    */
68fcf5ef2aSThomas Huth     POWERPC_MMU_BOOKE206   = 0x00000009,
69fcf5ef2aSThomas Huth #define POWERPC_MMU_64       0x00010000
70fcf5ef2aSThomas Huth     /* 64 bits PowerPC MMU                                     */
71fcf5ef2aSThomas Huth     POWERPC_MMU_64B        = POWERPC_MMU_64 | 0x00000001,
72fcf5ef2aSThomas Huth     /* Architecture 2.03 and later (has LPCR) */
73fcf5ef2aSThomas Huth     POWERPC_MMU_2_03       = POWERPC_MMU_64 | 0x00000002,
74fcf5ef2aSThomas Huth     /* Architecture 2.06 variant                               */
7558969eeeSDavid Gibson     POWERPC_MMU_2_06       = POWERPC_MMU_64 | 0x00000003,
76fcf5ef2aSThomas Huth     /* Architecture 2.07 variant                               */
7758969eeeSDavid Gibson     POWERPC_MMU_2_07       = POWERPC_MMU_64 | 0x00000004,
7886cf1e9fSSuraj Jitindar Singh     /* Architecture 3.00 variant                               */
79ca79b3b7SDavid Gibson     POWERPC_MMU_3_00       = POWERPC_MMU_64 | 0x00000005,
80fcf5ef2aSThomas Huth };
81fcf5ef2aSThomas Huth 
82d57d72a8SGreg Kurz static inline bool mmu_is_64bit(powerpc_mmu_t mmu_model)
83d57d72a8SGreg Kurz {
84d57d72a8SGreg Kurz     return mmu_model & POWERPC_MMU_64;
85d57d72a8SGreg Kurz }
86d57d72a8SGreg Kurz 
87fcf5ef2aSThomas Huth /*****************************************************************************/
88fcf5ef2aSThomas Huth /* Exception model                                                           */
89fcf5ef2aSThomas Huth typedef enum powerpc_excp_t powerpc_excp_t;
90fcf5ef2aSThomas Huth enum powerpc_excp_t {
91fcf5ef2aSThomas Huth     POWERPC_EXCP_UNKNOWN   = 0,
92fcf5ef2aSThomas Huth     /* Standard PowerPC exception model */
93fcf5ef2aSThomas Huth     POWERPC_EXCP_STD,
94fcf5ef2aSThomas Huth     /* PowerPC 40x exception model      */
95fcf5ef2aSThomas Huth     POWERPC_EXCP_40x,
969323650fSFabiano Rosas     /* PowerPC 603/604/G2 exception model */
979323650fSFabiano Rosas     POWERPC_EXCP_6xx,
98fd7dc4bbSFabiano Rosas     /* PowerPC 7xx exception model      */
99fd7dc4bbSFabiano Rosas     POWERPC_EXCP_7xx,
100fcf5ef2aSThomas Huth     /* PowerPC 74xx exception model     */
101fcf5ef2aSThomas Huth     POWERPC_EXCP_74xx,
102fcf5ef2aSThomas Huth     /* BookE exception model            */
103fcf5ef2aSThomas Huth     POWERPC_EXCP_BOOKE,
104fcf5ef2aSThomas Huth     /* PowerPC 970 exception model      */
105fcf5ef2aSThomas Huth     POWERPC_EXCP_970,
106fcf5ef2aSThomas Huth     /* POWER7 exception model           */
107fcf5ef2aSThomas Huth     POWERPC_EXCP_POWER7,
108fcf5ef2aSThomas Huth     /* POWER8 exception model           */
109fcf5ef2aSThomas Huth     POWERPC_EXCP_POWER8,
110a790e82bSBenjamin Herrenschmidt     /* POWER9 exception model           */
111a790e82bSBenjamin Herrenschmidt     POWERPC_EXCP_POWER9,
112526cdce7SNicholas Piggin     /* POWER10 exception model           */
113526cdce7SNicholas Piggin     POWERPC_EXCP_POWER10,
114fcf5ef2aSThomas Huth };
115fcf5ef2aSThomas Huth 
116fcf5ef2aSThomas Huth /*****************************************************************************/
117fcf5ef2aSThomas Huth /* PM instructions */
118fcf5ef2aSThomas Huth typedef enum {
119fcf5ef2aSThomas Huth     PPC_PM_DOZE,
120fcf5ef2aSThomas Huth     PPC_PM_NAP,
121fcf5ef2aSThomas Huth     PPC_PM_SLEEP,
122fcf5ef2aSThomas Huth     PPC_PM_RVWINKLE,
12321c0d66aSBenjamin Herrenschmidt     PPC_PM_STOP,
124fcf5ef2aSThomas Huth } powerpc_pm_insn_t;
125fcf5ef2aSThomas Huth 
126fcf5ef2aSThomas Huth /*****************************************************************************/
127fcf5ef2aSThomas Huth /* Input pins model                                                          */
128fcf5ef2aSThomas Huth typedef enum powerpc_input_t powerpc_input_t;
129fcf5ef2aSThomas Huth enum powerpc_input_t {
130fcf5ef2aSThomas Huth     PPC_FLAGS_INPUT_UNKNOWN = 0,
131fcf5ef2aSThomas Huth     /* PowerPC 6xx bus                  */
132fcf5ef2aSThomas Huth     PPC_FLAGS_INPUT_6xx,
133fcf5ef2aSThomas Huth     /* BookE bus                        */
134fcf5ef2aSThomas Huth     PPC_FLAGS_INPUT_BookE,
135fcf5ef2aSThomas Huth     /* PowerPC 405 bus                  */
136fcf5ef2aSThomas Huth     PPC_FLAGS_INPUT_405,
137fcf5ef2aSThomas Huth     /* PowerPC 970 bus                  */
138fcf5ef2aSThomas Huth     PPC_FLAGS_INPUT_970,
139fcf5ef2aSThomas Huth     /* PowerPC POWER7 bus               */
140fcf5ef2aSThomas Huth     PPC_FLAGS_INPUT_POWER7,
14167afe775SBenjamin Herrenschmidt     /* PowerPC POWER9 bus               */
14267afe775SBenjamin Herrenschmidt     PPC_FLAGS_INPUT_POWER9,
143fcf5ef2aSThomas Huth     /* Freescale RCPU bus               */
144fcf5ef2aSThomas Huth     PPC_FLAGS_INPUT_RCPU,
145fcf5ef2aSThomas Huth };
146fcf5ef2aSThomas Huth 
147b07c59f7SDavid Gibson typedef struct PPCHash64Options PPCHash64Options;
148fcf5ef2aSThomas Huth 
149fcf5ef2aSThomas Huth /**
150fcf5ef2aSThomas Huth  * PowerPCCPUClass:
151fcf5ef2aSThomas Huth  * @parent_realize: The parent class' realize handler.
152a1c5d644SPeter Maydell  * @parent_phases: The parent class' reset phase handlers.
153fcf5ef2aSThomas Huth  *
154fcf5ef2aSThomas Huth  * A PowerPC CPU model.
155fcf5ef2aSThomas Huth  */
156db1015e9SEduardo Habkost struct PowerPCCPUClass {
157fcf5ef2aSThomas Huth     /*< private >*/
158fcf5ef2aSThomas Huth     CPUClass parent_class;
159fcf5ef2aSThomas Huth     /*< public >*/
160fcf5ef2aSThomas Huth 
161fcf5ef2aSThomas Huth     DeviceRealize parent_realize;
162fcf5ef2aSThomas Huth     DeviceUnrealize parent_unrealize;
163a1c5d644SPeter Maydell     ResettablePhases parent_phases;
164b8e99967SIgor Mammedov     void (*parent_parse_features)(const char *type, char *str, Error **errp);
165fcf5ef2aSThomas Huth 
166fcf5ef2aSThomas Huth     uint32_t pvr;
16721d3a78eSNicholas Piggin     /*
16821d3a78eSNicholas Piggin      * If @best is false, match if pcc is in the family of pvr
16921d3a78eSNicholas Piggin      * Else match only if pcc is the best match for pvr in this family.
17021d3a78eSNicholas Piggin      */
17121d3a78eSNicholas Piggin     bool (*pvr_match)(struct PowerPCCPUClass *pcc, uint32_t pvr, bool best);
172fcf5ef2aSThomas Huth     uint64_t pcr_mask;          /* Available bits in PCR register */
173fcf5ef2aSThomas Huth     uint64_t pcr_supported;     /* Bits for supported PowerISA versions */
174fcf5ef2aSThomas Huth     uint32_t svr;
175fcf5ef2aSThomas Huth     uint64_t insns_flags;
176fcf5ef2aSThomas Huth     uint64_t insns_flags2;
177fcf5ef2aSThomas Huth     uint64_t msr_mask;
178e232ecccSDavid Gibson     uint64_t lpcr_mask;         /* Available bits in the LPCR */
179403aacdbSCédric Le Goater     uint64_t lpcr_pm;           /* Power-saving mode Exit Cause Enable bits */
180fcf5ef2aSThomas Huth     powerpc_mmu_t   mmu_model;
181fcf5ef2aSThomas Huth     powerpc_excp_t  excp_model;
182fcf5ef2aSThomas Huth     powerpc_input_t bus_model;
183fcf5ef2aSThomas Huth     uint32_t flags;
184fcf5ef2aSThomas Huth     int bfd_mach;
185fcf5ef2aSThomas Huth     uint32_t l1_dcache_size, l1_icache_size;
186707c7c2eSFabiano Rosas #ifndef CONFIG_USER_ONLY
187707c7c2eSFabiano Rosas     unsigned int gdb_num_sprs;
188707c7c2eSFabiano Rosas     const char *gdb_spr_xml;
189707c7c2eSFabiano Rosas #endif
190b07c59f7SDavid Gibson     const PPCHash64Options *hash64_opts;
191c64abd1fSSam Bobroff     struct ppc_radix_page_info *radix_page_info;
192a8dafa52SSuraj Jitindar Singh     uint32_t lrg_decr_bits;
193289af4acSSuraj Jitindar Singh     int n_host_threads;
194fcf5ef2aSThomas Huth     void (*init_proc)(CPUPPCState *env);
195fcf5ef2aSThomas Huth     int  (*check_pow)(CPUPPCState *env);
196db1015e9SEduardo Habkost };
197fcf5ef2aSThomas Huth 
198fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
199fcf5ef2aSThomas Huth typedef struct PPCTimebase {
200fcf5ef2aSThomas Huth     uint64_t guest_timebase;
201fcf5ef2aSThomas Huth     int64_t time_of_the_day_ns;
202d14f3397SMaxiwell S. Garcia     bool runstate_paused;
203fcf5ef2aSThomas Huth } PPCTimebase;
204fcf5ef2aSThomas Huth 
2058a9358ccSMarkus Armbruster extern const VMStateDescription vmstate_ppc_timebase;
206fcf5ef2aSThomas Huth 
207fcf5ef2aSThomas Huth #define VMSTATE_PPC_TIMEBASE_V(_field, _state, _version) {            \
208fcf5ef2aSThomas Huth     .name       = (stringify(_field)),                                \
209fcf5ef2aSThomas Huth     .version_id = (_version),                                         \
210fcf5ef2aSThomas Huth     .size       = sizeof(PPCTimebase),                                \
211fcf5ef2aSThomas Huth     .vmsd       = &vmstate_ppc_timebase,                              \
212fcf5ef2aSThomas Huth     .flags      = VMS_STRUCT,                                         \
213fcf5ef2aSThomas Huth     .offset     = vmstate_offset_value(_state, _field, PPCTimebase),  \
214fcf5ef2aSThomas Huth }
21542043e4fSLaurent Vivier 
216538f0497SPhilippe Mathieu-Daudé void cpu_ppc_clock_vm_state_change(void *opaque, bool running,
21742043e4fSLaurent Vivier                                    RunState state);
218fcf5ef2aSThomas Huth #endif
219fcf5ef2aSThomas Huth 
220fcf5ef2aSThomas Huth #endif
221