4 * Copyright (c) 2013 Linaro Ltd
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see
18 * <http://www.gnu.org/licenses/gpl-2.0.html>
22 #include "qemu-common.h"
23 #if !defined(CONFIG_USER_ONLY)
24 #include "hw/loader.h"
26 #include "hw/arm/arm.h"
27 #include "sysemu/sysemu.h"
28 #include "sysemu/kvm.h"
30 static inline void set_feature(CPUARMState
*env
, int feature
)
32 env
->features
|= 1ULL << feature
;
35 #ifndef CONFIG_USER_ONLY
36 static uint64_t a57_l2ctlr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
38 /* Number of processors is in [25:24]; otherwise we RAZ */
39 return (smp_cpus
- 1) << 24;
43 static const ARMCPRegInfo cortexa57_cp_reginfo
[] = {
44 #ifndef CONFIG_USER_ONLY
45 { .name
= "L2CTLR_EL1", .state
= ARM_CP_STATE_AA64
,
46 .opc0
= 3, .opc1
= 1, .crn
= 11, .crm
= 0, .opc2
= 2,
47 .access
= PL1_RW
, .readfn
= a57_l2ctlr_read
,
48 .writefn
= arm_cp_write_ignore
},
50 .cp
= 15, .opc1
= 1, .crn
= 9, .crm
= 0, .opc2
= 2,
51 .access
= PL1_RW
, .readfn
= a57_l2ctlr_read
,
52 .writefn
= arm_cp_write_ignore
},
54 { .name
= "L2ECTLR_EL1", .state
= ARM_CP_STATE_AA64
,
55 .opc0
= 3, .opc1
= 1, .crn
= 11, .crm
= 0, .opc2
= 3,
56 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
58 .cp
= 15, .opc1
= 1, .crn
= 9, .crm
= 0, .opc2
= 3,
59 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
60 { .name
= "L2ACTLR", .state
= ARM_CP_STATE_BOTH
,
61 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 0, .opc2
= 0,
62 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
63 { .name
= "CPUACTLR_EL1", .state
= ARM_CP_STATE_AA64
,
64 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 2, .opc2
= 0,
65 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
67 .cp
= 15, .opc1
= 0, .crm
= 15,
68 .access
= PL1_RW
, .type
= ARM_CP_CONST
| ARM_CP_64BIT
, .resetvalue
= 0 },
69 { .name
= "CPUECTLR_EL1", .state
= ARM_CP_STATE_AA64
,
70 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 2, .opc2
= 1,
71 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
73 .cp
= 15, .opc1
= 1, .crm
= 15,
74 .access
= PL1_RW
, .type
= ARM_CP_CONST
| ARM_CP_64BIT
, .resetvalue
= 0 },
75 { .name
= "CPUMERRSR_EL1", .state
= ARM_CP_STATE_AA64
,
76 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 2, .opc2
= 2,
77 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
78 { .name
= "CPUMERRSR",
79 .cp
= 15, .opc1
= 2, .crm
= 15,
80 .access
= PL1_RW
, .type
= ARM_CP_CONST
| ARM_CP_64BIT
, .resetvalue
= 0 },
81 { .name
= "L2MERRSR_EL1", .state
= ARM_CP_STATE_AA64
,
82 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 2, .opc2
= 3,
83 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
85 .cp
= 15, .opc1
= 3, .crm
= 15,
86 .access
= PL1_RW
, .type
= ARM_CP_CONST
| ARM_CP_64BIT
, .resetvalue
= 0 },
90 static void aarch64_a57_initfn(Object
*obj
)
92 ARMCPU
*cpu
= ARM_CPU(obj
);
94 set_feature(&cpu
->env
, ARM_FEATURE_V8
);
95 set_feature(&cpu
->env
, ARM_FEATURE_VFP4
);
96 set_feature(&cpu
->env
, ARM_FEATURE_VFP_FP16
);
97 set_feature(&cpu
->env
, ARM_FEATURE_NEON
);
98 set_feature(&cpu
->env
, ARM_FEATURE_GENERIC_TIMER
);
99 set_feature(&cpu
->env
, ARM_FEATURE_AARCH64
);
100 set_feature(&cpu
->env
, ARM_FEATURE_CBAR_RO
);
101 cpu
->kvm_target
= QEMU_KVM_ARM_TARGET_CORTEX_A57
;
102 cpu
->midr
= 0x411fd070;
103 cpu
->reset_fpsid
= 0x41034070;
104 cpu
->mvfr0
= 0x10110222;
105 cpu
->mvfr1
= 0x12111111;
106 cpu
->mvfr2
= 0x00000043;
107 cpu
->ctr
= 0x8444c004;
108 cpu
->reset_sctlr
= 0x00c50838;
109 cpu
->id_pfr0
= 0x00000131;
110 cpu
->id_pfr1
= 0x00011011;
111 cpu
->id_dfr0
= 0x03010066;
112 cpu
->id_afr0
= 0x00000000;
113 cpu
->id_mmfr0
= 0x10101105;
114 cpu
->id_mmfr1
= 0x40000000;
115 cpu
->id_mmfr2
= 0x01260000;
116 cpu
->id_mmfr3
= 0x02102211;
117 cpu
->id_isar0
= 0x02101110;
118 cpu
->id_isar1
= 0x13112111;
119 cpu
->id_isar2
= 0x21232042;
120 cpu
->id_isar3
= 0x01112131;
121 cpu
->id_isar4
= 0x00011142;
122 cpu
->id_aa64pfr0
= 0x00002222;
123 cpu
->id_aa64dfr0
= 0x10305106;
124 cpu
->id_aa64isar0
= 0x00010000;
125 cpu
->id_aa64mmfr0
= 0x00001124;
126 cpu
->clidr
= 0x0a200023;
127 cpu
->ccsidr
[0] = 0x701fe00a; /* 32KB L1 dcache */
128 cpu
->ccsidr
[1] = 0x201fe012; /* 48KB L1 icache */
129 cpu
->ccsidr
[2] = 0x70ffe07a; /* 2048KB L2 cache */
130 cpu
->dcz_blocksize
= 4; /* 64 bytes */
133 #ifdef CONFIG_USER_ONLY
134 static void aarch64_any_initfn(Object
*obj
)
136 ARMCPU
*cpu
= ARM_CPU(obj
);
138 set_feature(&cpu
->env
, ARM_FEATURE_V8
);
139 set_feature(&cpu
->env
, ARM_FEATURE_VFP4
);
140 set_feature(&cpu
->env
, ARM_FEATURE_VFP_FP16
);
141 set_feature(&cpu
->env
, ARM_FEATURE_NEON
);
142 set_feature(&cpu
->env
, ARM_FEATURE_ARM_DIV
);
143 set_feature(&cpu
->env
, ARM_FEATURE_V7MP
);
144 set_feature(&cpu
->env
, ARM_FEATURE_AARCH64
);
145 cpu
->ctr
= 0x80030003; /* 32 byte I and D cacheline size, VIPT icache */
146 cpu
->dcz_blocksize
= 7; /* 512 bytes */
150 typedef struct ARMCPUInfo
{
152 void (*initfn
)(Object
*obj
);
153 void (*class_init
)(ObjectClass
*oc
, void *data
);
156 static const ARMCPUInfo aarch64_cpus
[] = {
157 { .name
= "cortex-a57", .initfn
= aarch64_a57_initfn
},
158 #ifdef CONFIG_USER_ONLY
159 { .name
= "any", .initfn
= aarch64_any_initfn
},
164 static void aarch64_cpu_initfn(Object
*obj
)
168 static void aarch64_cpu_finalizefn(Object
*obj
)
172 static void aarch64_cpu_set_pc(CPUState
*cs
, vaddr value
)
174 ARMCPU
*cpu
= ARM_CPU(cs
);
175 /* It's OK to look at env for the current mode here, because it's
176 * never possible for an AArch64 TB to chain to an AArch32 TB.
177 * (Otherwise we would need to use synchronize_from_tb instead.)
179 if (is_a64(&cpu
->env
)) {
182 cpu
->env
.regs
[15] = value
;
186 static void aarch64_cpu_class_init(ObjectClass
*oc
, void *data
)
188 CPUClass
*cc
= CPU_CLASS(oc
);
190 cc
->do_interrupt
= aarch64_cpu_do_interrupt
;
191 cc
->set_pc
= aarch64_cpu_set_pc
;
192 cc
->gdb_read_register
= aarch64_cpu_gdb_read_register
;
193 cc
->gdb_write_register
= aarch64_cpu_gdb_write_register
;
194 cc
->gdb_num_core_regs
= 34;
195 cc
->gdb_core_xml_file
= "aarch64-core.xml";
198 static void aarch64_cpu_register(const ARMCPUInfo
*info
)
200 TypeInfo type_info
= {
201 .parent
= TYPE_AARCH64_CPU
,
202 .instance_size
= sizeof(ARMCPU
),
203 .instance_init
= info
->initfn
,
204 .class_size
= sizeof(ARMCPUClass
),
205 .class_init
= info
->class_init
,
208 type_info
.name
= g_strdup_printf("%s-" TYPE_ARM_CPU
, info
->name
);
209 type_register(&type_info
);
210 g_free((void *)type_info
.name
);
213 static const TypeInfo aarch64_cpu_type_info
= {
214 .name
= TYPE_AARCH64_CPU
,
215 .parent
= TYPE_ARM_CPU
,
216 .instance_size
= sizeof(ARMCPU
),
217 .instance_init
= aarch64_cpu_initfn
,
218 .instance_finalize
= aarch64_cpu_finalizefn
,
220 .class_size
= sizeof(AArch64CPUClass
),
221 .class_init
= aarch64_cpu_class_init
,
224 static void aarch64_cpu_register_types(void)
226 const ARMCPUInfo
*info
= aarch64_cpus
;
228 type_register_static(&aarch64_cpu_type_info
);
231 aarch64_cpu_register(info
);
236 type_init(aarch64_cpu_register_types
)