blob: 118baf8d41f7583227b254bb0b30aafc6d42e421 [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
Eduardo Habkostc821774a2020-08-31 17:07:37 -040032OBJECT_DECLARE_TYPE(PowerPCCPU, PowerPCCPUClass,
Eduardo Habkost30b57072020-09-16 14:25:17 -040033 POWERPC_CPU)
Andreas Färber1d0cb672012-04-06 14:39:03 +020034
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010035typedef struct CPUPPCState CPUPPCState;
36typedef struct ppc_tb_t ppc_tb_t;
37typedef struct ppc_dcr_t ppc_dcr_t;
38
39/*****************************************************************************/
40/* MMU model */
41typedef enum powerpc_mmu_t powerpc_mmu_t;
42enum powerpc_mmu_t {
43 POWERPC_MMU_UNKNOWN = 0x00000000,
44 /* Standard 32 bits PowerPC MMU */
45 POWERPC_MMU_32B = 0x00000001,
46 /* PowerPC 6xx MMU with software TLB */
47 POWERPC_MMU_SOFT_6xx = 0x00000002,
48 /* PowerPC 74xx MMU with software TLB */
49 POWERPC_MMU_SOFT_74xx = 0x00000003,
50 /* PowerPC 4xx MMU with software TLB */
51 POWERPC_MMU_SOFT_4xx = 0x00000004,
52 /* PowerPC 4xx MMU with software TLB and zones protections */
53 POWERPC_MMU_SOFT_4xx_Z = 0x00000005,
54 /* PowerPC MMU in real mode only */
55 POWERPC_MMU_REAL = 0x00000006,
56 /* Freescale MPC8xx MMU model */
57 POWERPC_MMU_MPC8xx = 0x00000007,
58 /* BookE MMU model */
59 POWERPC_MMU_BOOKE = 0x00000008,
60 /* BookE 2.06 MMU model */
61 POWERPC_MMU_BOOKE206 = 0x00000009,
62 /* PowerPC 601 MMU model (specific BATs format) */
63 POWERPC_MMU_601 = 0x0000000A,
64#define POWERPC_MMU_64 0x00010000
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010065 /* 64 bits PowerPC MMU */
66 POWERPC_MMU_64B = POWERPC_MMU_64 | 0x00000001,
67 /* Architecture 2.03 and later (has LPCR) */
68 POWERPC_MMU_2_03 = POWERPC_MMU_64 | 0x00000002,
69 /* Architecture 2.06 variant */
David Gibson58969ee2018-03-23 14:11:07 +110070 POWERPC_MMU_2_06 = POWERPC_MMU_64 | 0x00000003,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010071 /* Architecture 2.07 variant */
David Gibson58969ee2018-03-23 14:11:07 +110072 POWERPC_MMU_2_07 = POWERPC_MMU_64 | 0x00000004,
Suraj Jitindar Singh86cf1e92017-02-10 16:25:51 +110073 /* Architecture 3.00 variant */
David Gibsonca79b3b2018-03-23 16:42:45 +110074 POWERPC_MMU_3_00 = POWERPC_MMU_64 | 0x00000005,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010075};
76
Greg Kurzd57d72a2020-12-09 18:35:36 +010077static inline bool mmu_is_64bit(powerpc_mmu_t mmu_model)
78{
79 return mmu_model & POWERPC_MMU_64;
80}
81
Paolo Bonzini2d34fe32016-03-15 13:49:25 +010082/*****************************************************************************/
83/* Exception model */
84typedef enum powerpc_excp_t powerpc_excp_t;
85enum powerpc_excp_t {
86 POWERPC_EXCP_UNKNOWN = 0,
87 /* Standard PowerPC exception model */
88 POWERPC_EXCP_STD,
89 /* PowerPC 40x exception model */
90 POWERPC_EXCP_40x,
91 /* PowerPC 601 exception model */
92 POWERPC_EXCP_601,
93 /* PowerPC 602 exception model */
94 POWERPC_EXCP_602,
95 /* PowerPC 603 exception model */
96 POWERPC_EXCP_603,
97 /* PowerPC 603e exception model */
98 POWERPC_EXCP_603E,
99 /* PowerPC G2 exception model */
100 POWERPC_EXCP_G2,
101 /* PowerPC 604 exception model */
102 POWERPC_EXCP_604,
103 /* PowerPC 7x0 exception model */
104 POWERPC_EXCP_7x0,
105 /* PowerPC 7x5 exception model */
106 POWERPC_EXCP_7x5,
107 /* PowerPC 74xx exception model */
108 POWERPC_EXCP_74xx,
109 /* BookE exception model */
110 POWERPC_EXCP_BOOKE,
111 /* PowerPC 970 exception model */
112 POWERPC_EXCP_970,
113 /* POWER7 exception model */
114 POWERPC_EXCP_POWER7,
115 /* POWER8 exception model */
116 POWERPC_EXCP_POWER8,
Benjamin Herrenschmidta790e822019-02-15 17:16:44 +0100117 /* POWER9 exception model */
118 POWERPC_EXCP_POWER9,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +0100119};
120
121/*****************************************************************************/
Benjamin Herrenschmidt7778a572016-06-21 23:48:55 +0200122/* PM instructions */
123typedef enum {
124 PPC_PM_DOZE,
125 PPC_PM_NAP,
126 PPC_PM_SLEEP,
127 PPC_PM_RVWINKLE,
Benjamin Herrenschmidt21c0d662019-02-15 17:16:41 +0100128 PPC_PM_STOP,
Benjamin Herrenschmidt7778a572016-06-21 23:48:55 +0200129} powerpc_pm_insn_t;
130
131/*****************************************************************************/
Paolo Bonzini2d34fe32016-03-15 13:49:25 +0100132/* Input pins model */
133typedef enum powerpc_input_t powerpc_input_t;
134enum powerpc_input_t {
135 PPC_FLAGS_INPUT_UNKNOWN = 0,
136 /* PowerPC 6xx bus */
137 PPC_FLAGS_INPUT_6xx,
138 /* BookE bus */
139 PPC_FLAGS_INPUT_BookE,
140 /* PowerPC 405 bus */
141 PPC_FLAGS_INPUT_405,
142 /* PowerPC 970 bus */
143 PPC_FLAGS_INPUT_970,
144 /* PowerPC POWER7 bus */
145 PPC_FLAGS_INPUT_POWER7,
Benjamin Herrenschmidt67afe772019-02-15 17:16:47 +0100146 /* PowerPC POWER9 bus */
147 PPC_FLAGS_INPUT_POWER9,
Paolo Bonzini2d34fe32016-03-15 13:49:25 +0100148 /* PowerPC 401 bus */
149 PPC_FLAGS_INPUT_401,
150 /* Freescale RCPU bus */
151 PPC_FLAGS_INPUT_RCPU,
152};
153
David Gibsonb07c59f2018-03-23 13:31:52 +1100154typedef struct PPCHash64Options PPCHash64Options;
Andreas Färberd0e39c52013-09-02 14:14:24 +0200155
Andreas Färber1d0cb672012-04-06 14:39:03 +0200156/**
157 * PowerPCCPUClass:
Andreas Färber4776ce62013-01-16 03:55:14 +0100158 * @parent_realize: The parent class' realize handler.
Andreas Färber1d0cb672012-04-06 14:39:03 +0200159 * @parent_reset: The parent class' reset handler.
160 *
161 * A PowerPC CPU model.
162 */
Eduardo Habkostdb1015e2020-09-03 16:43:22 -0400163struct PowerPCCPUClass {
Andreas Färber1d0cb672012-04-06 14:39:03 +0200164 /*< private >*/
165 CPUClass parent_class;
166 /*< public >*/
167
Andreas Färber4776ce62013-01-16 03:55:14 +0100168 DeviceRealize parent_realize;
Laurent Vivier7bbc1242016-10-20 13:26:04 +0200169 DeviceUnrealize parent_unrealize;
Peter Maydell781c67c2020-03-03 10:05:11 +0000170 DeviceReset parent_reset;
Igor Mammedovb8e99962017-10-09 21:50:59 +0200171 void (*parent_parse_features)(const char *type, char *str, Error **errp);
Andreas Färber2985b862013-01-06 08:31:30 +0000172
Andreas Färbercfe34f42013-02-17 23:16:41 +0000173 uint32_t pvr;
Alexey Kardashevskiy03ae4132014-07-04 00:48:55 +1000174 bool (*pvr_match)(struct PowerPCCPUClass *pcc, uint32_t pvr);
Thomas Huth8cd2ce72016-06-07 17:39:37 +0200175 uint64_t pcr_mask; /* Available bits in PCR register */
176 uint64_t pcr_supported; /* Bits for supported PowerISA versions */
Andreas Färbercfe34f42013-02-17 23:16:41 +0000177 uint32_t svr;
178 uint64_t insns_flags;
179 uint64_t insns_flags2;
180 uint64_t msr_mask;
David Gibsone232ecc2020-01-06 16:35:10 +1100181 uint64_t lpcr_mask; /* Available bits in the LPCR */
Cédric Le Goater403aacd2017-11-23 18:05:24 +0100182 uint64_t lpcr_pm; /* Power-saving mode Exit Cause Enable bits */
Andreas Färbercfe34f42013-02-17 23:16:41 +0000183 powerpc_mmu_t mmu_model;
184 powerpc_excp_t excp_model;
185 powerpc_input_t bus_model;
186 uint32_t flags;
187 int bfd_mach;
David Gibson0cbad812013-04-07 19:08:19 +0000188 uint32_t l1_dcache_size, l1_icache_size;
Fabiano Rosas707c7c22019-02-06 14:51:33 -0200189#ifndef CONFIG_USER_ONLY
190 unsigned int gdb_num_sprs;
191 const char *gdb_spr_xml;
192#endif
David Gibsonb07c59f2018-03-23 13:31:52 +1100193 const PPCHash64Options *hash64_opts;
Sam Bobroffc64abd12017-03-20 10:46:43 +1100194 struct ppc_radix_page_info *radix_page_info;
Suraj Jitindar Singha8dafa52019-03-01 13:43:15 +1100195 uint32_t lrg_decr_bits;
Suraj Jitindar Singh289af4a2019-08-27 14:57:51 +1000196 int n_host_threads;
Andreas Färbercfe34f42013-02-17 23:16:41 +0000197 void (*init_proc)(CPUPPCState *env);
198 int (*check_pow)(CPUPPCState *env);
Paolo Bonzinib2305602016-03-15 15:12:16 +0100199 int (*handle_mmu_fault)(PowerPCCPU *cpu, vaddr eaddr, int rwx, int mmu_idx);
Greg Kurz382d2db2014-05-19 19:59:05 +0200200 bool (*interrupts_big_endian)(PowerPCCPU *cpu);
Eduardo Habkostdb1015e2020-09-03 16:43:22 -0400201};
Andreas Färber1d0cb672012-04-06 14:39:03 +0200202
Alexey Kardashevskiya90db152013-07-18 14:32:54 -0500203#ifndef CONFIG_USER_ONLY
Alexey Kardashevskiy98a8b522014-05-01 20:37:09 +1000204typedef struct PPCTimebase {
205 uint64_t guest_timebase;
206 int64_t time_of_the_day_ns;
Maxiwell S. Garciad14f3392019-07-11 16:47:02 -0300207 bool runstate_paused;
Alexey Kardashevskiy98a8b522014-05-01 20:37:09 +1000208} PPCTimebase;
209
Markus Armbruster8a9358c2019-08-12 07:23:44 +0200210extern const VMStateDescription vmstate_ppc_timebase;
Alexey Kardashevskiy98a8b522014-05-01 20:37:09 +1000211
212#define VMSTATE_PPC_TIMEBASE_V(_field, _state, _version) { \
213 .name = (stringify(_field)), \
214 .version_id = (_version), \
215 .size = sizeof(PPCTimebase), \
216 .vmsd = &vmstate_ppc_timebase, \
217 .flags = VMS_STRUCT, \
218 .offset = vmstate_offset_value(_state, _field, PPCTimebase), \
219}
Laurent Vivier42043e42017-01-27 13:24:58 +0100220
Philippe Mathieu-Daudé538f0492021-01-11 16:20:20 +0100221void cpu_ppc_clock_vm_state_change(void *opaque, bool running,
Laurent Vivier42043e42017-01-27 13:24:58 +0100222 RunState state);
Alexey Kardashevskiya90db152013-07-18 14:32:54 -0500223#endif
224
Andreas Färber1d0cb672012-04-06 14:39:03 +0200225#endif