blob: 89ff88f28c95d79eab2197e1376c1bf62a15ee57 [file] [log] [blame]
Andreas Färber1d0cb672012-04-06 14:39:03 +02001/*
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
Markus Armbruster2e5b09f2019-07-09 17:20:52 +020023#include "hw/core/cpu.h"
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040024#include "qom/object.h"
Andreas Färber1d0cb672012-04-06 14:39:03 +020025
26#ifdef TARGET_PPC64
27#define TYPE_POWERPC_CPU "powerpc64-cpu"
Andreas Färber1d0cb672012-04-06 14:39:03 +020028#else
29#define TYPE_POWERPC_CPU "powerpc-cpu"
30#endif
31
Philippe Mathieu-Daudé9295b1a2022-02-14 17:08:40 +010032OBJECT_DECLARE_CPU_TYPE(PowerPCCPU, PowerPCCPUClass, POWERPC_CPU)
Andreas Färber1d0cb672012-04-06 14:39:03 +020033
Philippe Mathieu-Daudé1ea4a062022-02-07 13:35:58 +010034typedef struct CPUArchState CPUPPCState;
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010035typedef struct ppc_tb_t ppc_tb_t;
36typedef struct ppc_dcr_t ppc_dcr_t;
37
38/*****************************************************************************/
39/* MMU model */
40typedef enum powerpc_mmu_t powerpc_mmu_t;
41enum powerpc_mmu_t {
42 POWERPC_MMU_UNKNOWN = 0x00000000,
43 /* Standard 32 bits PowerPC MMU */
44 POWERPC_MMU_32B = 0x00000001,
45 /* PowerPC 6xx MMU with software TLB */
46 POWERPC_MMU_SOFT_6xx = 0x00000002,
Fabiano Rosasa09410e2021-12-17 17:57:16 +010047 /*
48 * PowerPC 74xx MMU with software TLB (this has been
49 * disabled, see git history for more information.
50 * keywords: tlbld tlbli TLBMISS PTEHI PTELO)
51 */
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010052 POWERPC_MMU_SOFT_74xx = 0x00000003,
53 /* PowerPC 4xx MMU with software TLB */
54 POWERPC_MMU_SOFT_4xx = 0x00000004,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010055 /* PowerPC MMU in real mode only */
56 POWERPC_MMU_REAL = 0x00000006,
57 /* Freescale MPC8xx MMU model */
58 POWERPC_MMU_MPC8xx = 0x00000007,
59 /* BookE MMU model */
60 POWERPC_MMU_BOOKE = 0x00000008,
61 /* BookE 2.06 MMU model */
62 POWERPC_MMU_BOOKE206 = 0x00000009,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010063#define POWERPC_MMU_64 0x00010000
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010064 /* 64 bits PowerPC MMU */
65 POWERPC_MMU_64B = POWERPC_MMU_64 | 0x00000001,
66 /* Architecture 2.03 and later (has LPCR) */
67 POWERPC_MMU_2_03 = POWERPC_MMU_64 | 0x00000002,
68 /* Architecture 2.06 variant */
David Gibson58969ee2018-03-23 14:11:07 +110069 POWERPC_MMU_2_06 = POWERPC_MMU_64 | 0x00000003,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010070 /* Architecture 2.07 variant */
David Gibson58969ee2018-03-23 14:11:07 +110071 POWERPC_MMU_2_07 = POWERPC_MMU_64 | 0x00000004,
Suraj Jitindar Singh86cf1e92017-02-10 16:25:51 +110072 /* Architecture 3.00 variant */
David Gibsonca79b3b2018-03-23 16:42:45 +110073 POWERPC_MMU_3_00 = POWERPC_MMU_64 | 0x00000005,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010074};
75
Greg Kurzd57d72a2020-12-09 18:35:36 +010076static inline bool mmu_is_64bit(powerpc_mmu_t mmu_model)
77{
78 return mmu_model & POWERPC_MMU_64;
79}
80
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010081/*****************************************************************************/
82/* Exception model */
83typedef enum powerpc_excp_t powerpc_excp_t;
84enum powerpc_excp_t {
85 POWERPC_EXCP_UNKNOWN = 0,
86 /* Standard PowerPC exception model */
87 POWERPC_EXCP_STD,
88 /* PowerPC 40x exception model */
89 POWERPC_EXCP_40x,
Fabiano Rosas93236502022-02-09 09:08:55 +010090 /* PowerPC 603/604/G2 exception model */
91 POWERPC_EXCP_6xx,
Fabiano Rosasfd7dc4b2022-02-09 09:08:56 +010092 /* PowerPC 7xx exception model */
93 POWERPC_EXCP_7xx,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010094 /* PowerPC 74xx exception model */
95 POWERPC_EXCP_74xx,
96 /* BookE exception model */
97 POWERPC_EXCP_BOOKE,
98 /* PowerPC 970 exception model */
99 POWERPC_EXCP_970,
100 /* POWER7 exception model */
101 POWERPC_EXCP_POWER7,
102 /* POWER8 exception model */
103 POWERPC_EXCP_POWER8,
Benjamin Herrenschmidta790e822019-02-15 17:16:44 +0100104 /* POWER9 exception model */
105 POWERPC_EXCP_POWER9,
Nicholas Piggin526cdce2021-05-01 17:24:35 +1000106 /* POWER10 exception model */
107 POWERPC_EXCP_POWER10,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +0100108};
109
110/*****************************************************************************/
Benjamin Herrenschmidt7778a572016-06-21 23:48:55 +0200111/* PM instructions */
112typedef enum {
113 PPC_PM_DOZE,
114 PPC_PM_NAP,
115 PPC_PM_SLEEP,
116 PPC_PM_RVWINKLE,
Benjamin Herrenschmidt21c0d662019-02-15 17:16:41 +0100117 PPC_PM_STOP,
Benjamin Herrenschmidt7778a572016-06-21 23:48:55 +0200118} powerpc_pm_insn_t;
119
120/*****************************************************************************/
Paolo Bonzini2d34fe32016-03-15 13:49:25 +0100121/* Input pins model */
122typedef enum powerpc_input_t powerpc_input_t;
123enum powerpc_input_t {
124 PPC_FLAGS_INPUT_UNKNOWN = 0,
125 /* PowerPC 6xx bus */
126 PPC_FLAGS_INPUT_6xx,
127 /* BookE bus */
128 PPC_FLAGS_INPUT_BookE,
129 /* PowerPC 405 bus */
130 PPC_FLAGS_INPUT_405,
131 /* PowerPC 970 bus */
132 PPC_FLAGS_INPUT_970,
133 /* PowerPC POWER7 bus */
134 PPC_FLAGS_INPUT_POWER7,
Benjamin Herrenschmidt67afe772019-02-15 17:16:47 +0100135 /* PowerPC POWER9 bus */
136 PPC_FLAGS_INPUT_POWER9,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +0100137 /* Freescale RCPU bus */
138 PPC_FLAGS_INPUT_RCPU,
139};
140
David Gibsonb07c59f2018-03-23 13:31:52 +1100141typedef struct PPCHash64Options PPCHash64Options;
Andreas Färberd0e39c52013-09-02 14:14:24 +0200142
Andreas Färber1d0cb672012-04-06 14:39:03 +0200143/**
144 * PowerPCCPUClass:
Andreas Färber4776ce62013-01-16 03:55:14 +0100145 * @parent_realize: The parent class' realize handler.
Andreas Färber1d0cb672012-04-06 14:39:03 +0200146 * @parent_reset: The parent class' reset handler.
147 *
148 * A PowerPC CPU model.
149 */
Eduardo Habkostdb1015e2020-09-03 16:43:22 -0400150struct PowerPCCPUClass {
Andreas Färber1d0cb672012-04-06 14:39:03 +0200151 /*< private >*/
152 CPUClass parent_class;
153 /*< public >*/
154
Andreas Färber4776ce62013-01-16 03:55:14 +0100155 DeviceRealize parent_realize;
Laurent Vivier7bbc1242016-10-20 13:26:04 +0200156 DeviceUnrealize parent_unrealize;
Peter Maydell781c67c2020-03-03 10:05:11 +0000157 DeviceReset parent_reset;
Igor Mammedovb8e99962017-10-09 21:50:59 +0200158 void (*parent_parse_features)(const char *type, char *str, Error **errp);
Andreas Färber2985b862013-01-06 08:31:30 +0000159
Andreas Färbercfe34f42013-02-17 23:16:41 +0000160 uint32_t pvr;
Nicholas Piggin21d3a782022-07-31 11:33:58 +1000161 /*
162 * If @best is false, match if pcc is in the family of pvr
163 * Else match only if pcc is the best match for pvr in this family.
164 */
165 bool (*pvr_match)(struct PowerPCCPUClass *pcc, uint32_t pvr, bool best);
Thomas Huth8cd2ce72016-06-07 17:39:37 +0200166 uint64_t pcr_mask; /* Available bits in PCR register */
167 uint64_t pcr_supported; /* Bits for supported PowerISA versions */
Andreas Färbercfe34f42013-02-17 23:16:41 +0000168 uint32_t svr;
169 uint64_t insns_flags;
170 uint64_t insns_flags2;
171 uint64_t msr_mask;
David Gibsone232ecc2020-01-06 16:35:10 +1100172 uint64_t lpcr_mask; /* Available bits in the LPCR */
Cédric Le Goater403aacd2017-11-23 18:05:24 +0100173 uint64_t lpcr_pm; /* Power-saving mode Exit Cause Enable bits */
Andreas Färbercfe34f42013-02-17 23:16:41 +0000174 powerpc_mmu_t mmu_model;
175 powerpc_excp_t excp_model;
176 powerpc_input_t bus_model;
177 uint32_t flags;
178 int bfd_mach;
David Gibson0cbad812013-04-07 19:08:19 +0000179 uint32_t l1_dcache_size, l1_icache_size;
Fabiano Rosas707c7c22019-02-06 14:51:33 -0200180#ifndef CONFIG_USER_ONLY
181 unsigned int gdb_num_sprs;
182 const char *gdb_spr_xml;
183#endif
David Gibsonb07c59f2018-03-23 13:31:52 +1100184 const PPCHash64Options *hash64_opts;
Sam Bobroffc64abd12017-03-20 10:46:43 +1100185 struct ppc_radix_page_info *radix_page_info;
Suraj Jitindar Singha8dafa52019-03-01 13:43:15 +1100186 uint32_t lrg_decr_bits;
Suraj Jitindar Singh289af4a2019-08-27 14:57:51 +1000187 int n_host_threads;
Andreas Färbercfe34f42013-02-17 23:16:41 +0000188 void (*init_proc)(CPUPPCState *env);
189 int (*check_pow)(CPUPPCState *env);
Eduardo Habkostdb1015e2020-09-03 16:43:22 -0400190};
Andreas Färber1d0cb672012-04-06 14:39:03 +0200191
Alexey Kardashevskiya90db152013-07-18 14:32:54 -0500192#ifndef CONFIG_USER_ONLY
Alexey Kardashevskiy98a8b522014-05-01 20:37:09 +1000193typedef struct PPCTimebase {
194 uint64_t guest_timebase;
195 int64_t time_of_the_day_ns;
Maxiwell S. Garciad14f3392019-07-11 16:47:02 -0300196 bool runstate_paused;
Alexey Kardashevskiy98a8b522014-05-01 20:37:09 +1000197} PPCTimebase;
198
Markus Armbruster8a9358c2019-08-12 07:23:44 +0200199extern const VMStateDescription vmstate_ppc_timebase;
Alexey Kardashevskiy98a8b522014-05-01 20:37:09 +1000200
201#define VMSTATE_PPC_TIMEBASE_V(_field, _state, _version) { \
202 .name = (stringify(_field)), \
203 .version_id = (_version), \
204 .size = sizeof(PPCTimebase), \
205 .vmsd = &vmstate_ppc_timebase, \
206 .flags = VMS_STRUCT, \
207 .offset = vmstate_offset_value(_state, _field, PPCTimebase), \
208}
Laurent Vivier42043e42017-01-27 13:24:58 +0100209
Philippe Mathieu-Daudé538f0492021-01-11 16:20:20 +0100210void cpu_ppc_clock_vm_state_change(void *opaque, bool running,
Laurent Vivier42043e42017-01-27 13:24:58 +0100211 RunState state);
Alexey Kardashevskiya90db152013-07-18 14:32:54 -0500212#endif
213
Andreas Färber1d0cb672012-04-06 14:39:03 +0200214#endif