qualcomm/qbox
Loading...
Searching...
No Matches
arm.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * Author: GreenSocs 2020
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#pragma once
10
11#include "cpu.h"
12
13class QemuCpuArm : public QemuCpu
14{
15protected:
16 void init_secure_memory(bool has_el3)
17 {
18 if (p_has_secure_memory.get_value() && has_el3) {
19 secure_mem.init(m_dev, "secure-memory");
20 }
21 }
22
23public:
24 static constexpr qemu::Target ARCH = qemu::Target::AARCH64;
25
26 cci::cci_param<bool> p_has_secure_memory;
27 QemuInitiatorSocket<> secure_mem;
29
30 QemuCpuArm(const sc_core::sc_module_name& name, QemuInstance& inst, const std::string& type_name,
31 const char* cpu_type = nullptr)
32 : QemuCpu(name, inst, type_name, cpu_type)
33 , p_has_secure_memory("has_secure_memory", false, "Use a separate QEMU secure-memory address space")
34 , secure_mem("secure_mem", *this, inst)
35 , power_on("power_on")
36 {
37 auto poweroncb = std::bind(&QemuCpuArm::power_on_cb, this, std::placeholders::_1);
38 power_on.register_value_changed_cb(poweroncb);
39 }
40
45
46 void end_of_elaboration() override
47 {
48 QemuCpu::end_of_elaboration();
49
50 // This is needed for KVM otherwise the GIC won't reset properly when a system reset is requested
51 get_cpu_aarch64().register_reset();
52 }
53
54 void start_of_simulation() override
55 {
56 // According to qemu/hw/arm/virt.c:
57 // virt_cpu_post_init() must be called after the CPUs have been realized
58 // and the GIC has been created.
59 // I am not sure if this the right place where to call it. I wonder if a
60 // `before_start_of_simulation` stage would be a better place for this.
61 // It MUST be called before `QemuCpu::start_of_simulation()`.
62 get_cpu_aarch64().post_init();
63
64 QemuCpu::start_of_simulation();
65 }
66
67private:
68 void power_on_cb(const bool& val)
69 {
70 int ret;
71 auto arm_cpu = get_cpu_aarch64();
72
73 m_inst.get().lock_iothread();
74
75 if (val) {
76 SCP_INFO(()) << "Power ON request for CPU";
77 ret = arm_cpu.arm_set_cpu_on_and_reset();
78 } else {
79 SCP_INFO(()) << "Power OFF request for CPU";
80 ret = arm_cpu.arm_set_cpu_off();
81 }
82
83 m_inst.get().unlock_iothread();
84 m_qemu_kick_ev.async_notify();
85
86 switch (ret) {
87 case 0: // QEMU_ARM_POWERCTL_RET_SUCCESS
88 SCP_INFO(()) << "arm power control success: CPU Power " << (val ? "ON" : "OFF");
89 break;
90 case -2: // QEMU_ARM_POWERCTL_INVALID_PARAM
91 SCP_WARN(()) << "arm power control failed: Invalid Parameters (CPU not found)";
92 break;
93 case -3: // QEMU_ARM_POWERCTL_IS_OFF — arm_set_cpu_off only
94 SCP_WARN(()) << "arm_set_cpu_off failed: CPU Already OFF";
95 break;
96 case -4: // QEMU_ARM_POWERCTL_ALREADY_ON — arm_set_cpu_on_and_reset only
97 SCP_WARN(()) << "arm_set_cpu_on_and_reset failed: CPU Already ON";
98 break;
99 case -5: // QEMU_ARM_POWERCTL_ON_PENDING — arm_set_cpu_on_and_reset only
100 SCP_WARN(()) << "arm_set_cpu_on_and_reset failed: CPU Power ON is pending";
101 break;
102 default:
103 SCP_FATAL(()) << "arm power control: unexpected return code " << ret;
104 __builtin_unreachable();
105 }
106 }
107};
qemu::CpuAarch64 get_cpu_aarch64() const
Definition arm.h:44
TLM-2.0 initiator socket specialisation for QEMU AddressSpace mapping.
Definition initiator.h:63
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
Definition target-signal-socket.h:163
Definition aarch64.h:40