qualcomm/qbox
Loading...
Searching...
No Matches
hexagon.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * Author: GreenSocs 2021
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#pragma once
10
11#include <string>
12#include <functional>
13#include <optional>
14
15#include <libqemu-cxx/target/hexagon.h>
16
17#include <module_factory_registery.h>
18#include <libgssync.h>
19
20#include <cpu.h>
21#include <hexagon_globalreg.h>
22#include <hexagon-l2vic.h>
23#include <hexagon_tlb.h>
24
25class qemu_cpu_hexagon : public QemuCpu
26{
27 cci::cci_broker_handle m_broker;
28 hexagon_globalreg* p_hex_greg;
29 hexagon_l2vic* m_l2vic;
30 hexagon_tlb* m_hex_tlb;
31
32public:
33 static constexpr qemu::Target ARCH = qemu::Target::HEXAGON;
34 sc_core::sc_vector<QemuTargetSignalSocket> irq_in;
35
36 qemu_cpu_hexagon(const sc_core::sc_module_name& name, sc_core::sc_object* o1, sc_core::sc_object* o2)
37 : qemu_cpu_hexagon(name, *(dynamic_cast<QemuInstance*>(o1)), dynamic_cast<hexagon_globalreg*>(o2))
38 {
39 }
40 qemu_cpu_hexagon(const sc_core::sc_module_name& name, sc_core::sc_object* o1, sc_core::sc_object* o2,
41 sc_core::sc_object* o3)
42 : qemu_cpu_hexagon(name, *(dynamic_cast<QemuInstance*>(o1)), dynamic_cast<hexagon_globalreg*>(o2),
43 dynamic_cast<hexagon_l2vic*>(o3))
44 {
45 }
46 qemu_cpu_hexagon(const sc_core::sc_module_name& name, sc_core::sc_object* o1, sc_core::sc_object* o2,
47 sc_core::sc_object* o3, sc_core::sc_object* o4)
48 : qemu_cpu_hexagon(name, *(dynamic_cast<QemuInstance*>(o1)), dynamic_cast<hexagon_globalreg*>(o2),
49 dynamic_cast<hexagon_l2vic*>(o3), dynamic_cast<hexagon_tlb*>(o4))
50 {
51 }
52 qemu_cpu_hexagon(const sc_core::sc_module_name& name, QemuInstance& inst, hexagon_globalreg* hex_greg = nullptr,
53 hexagon_l2vic* l2vic = nullptr, hexagon_tlb* tlb = nullptr)
54 : QemuCpu(name, inst, "v67-hexagon")
55 , m_broker(cci::cci_get_broker())
56 , irq_in("irq_in", 8, [](const char* n, int i) { return new QemuTargetSignalSocket(n); })
57 , p_cfgbase("config_table_addr", 0xffffffffULL, "config table address")
58 , p_vp_mode("vp_mode", true, "override the vp_mode for testing")
59 , p_semihosting("enable_semihosting", false, "enable semihosting for debugging/testing")
60 , p_dsp_arch("dsp_arch", "v68", "DSP arch")
61 , p_start_powered_off("start_powered_off", false,
62 "Start and reset the CPU "
63 "in powered-off state")
64 , p_sched_limit("sched_limit", true, "use sched limit")
65 , p_paranoid("paranoid_commit_state", false, "enable per-packet checks")
66 , p_subsystem_id("subsystem_id", 0, "subsystem id")
67 , p_hexagon_num_threads("hexagon_num_threads", 8,
68 "number of hexagon threads") // THREADS_MAX in ./target/hexagon/cpu.h
69 , p_isdben_trusted("isdben_trusted", true, "isdben trusted")
70 , p_isdben_secure("isdben_secure", true, "isdben secure")
71 , p_cmdline("cmdline", "", "cmdline")
72 , p_vtcm_base_addr("vtcm_base_addr", 0, "vtcm base address")
73 , p_vtcm_size_kb("vtcm_size_kb", 0, "vtcm size in kb")
74 , p_coproc2_present("coproc2_present", false, "secondary coprocessor is present")
75 , p_hvx_contexts("hvx_contexts", 0, "number of HVX contexts")
76 , p_hex_greg(hex_greg)
77 , m_l2vic(l2vic)
78 , m_hex_tlb(tlb)
79 /*
80 * We have no choice but to attach-suspend here. This is fixable but
81 * non-trivial. It means that the SystemC kernel will never starve...
82 */
83 {
84 for (int i = 0; i < irq_in.size(); ++i) {
85 m_external_ev |= irq_in[i]->default_event();
86 }
87 }
88
89 void set_l2vic(hexagon_l2vic* l2vic) { m_l2vic = l2vic; }
90 void set_hex_tlb(hexagon_tlb* tlb) { m_hex_tlb = tlb; }
91
92 void before_end_of_elaboration() override
93 {
94 const std::string dsp_arch = p_dsp_arch.get_value();
95 set_qom_type(dsp_arch + "-hexagon-cpu");
96 // set the parameter config-table-addr 195 hexagon_testboard
97 QemuCpu::before_end_of_elaboration();
98 qemu::CpuHexagon cpu(get_qemu_dev());
99
100 qemu::CpuHexagon::Rev_t dsp_rev = qemu::CpuHexagon::parse_dsp_arch(dsp_arch);
101 if (dsp_rev == qemu::CpuHexagon::unknown_rev) {
102 SCP_FATAL(())("Unrecognized Architecture Revision: " + dsp_arch);
103 }
104 cpu.set_prop_bool("start-powered-off", p_start_powered_off);
105 cpu.set_prop_bool("sched-limit", p_sched_limit);
106 cpu.set_prop_bool("virtual-platform-mode", p_vp_mode);
107 cpu.set_prop_bool("enable-semihosting", p_semihosting);
108 cpu.set_prop_bool("paranoid-commit-state", p_paranoid);
109 cpu.set_prop_int("subsystem-id", p_subsystem_id);
110 cpu.set_prop_int("thread-count", p_hexagon_num_threads);
111 cpu.set_prop_str("cmdline", p_cmdline.get_value().data());
112 cpu.set_prop_int("vtcm-base-addr", p_vtcm_base_addr);
113 cpu.set_prop_int("vtcm-size-kb", p_vtcm_size_kb);
114 cpu.set_prop_bool("coproc2-present", p_coproc2_present);
115 cpu.set_prop_int("hvx-contexts", p_hvx_contexts);
116 if (p_hex_greg) {
117 p_hex_greg->before_end_of_elaboration();
118 qemu::Device hex_greg_dev = p_hex_greg->get_qemu_dev();
119 qemu::Device cpu_dev = get_qemu_dev();
120 cpu_dev.set_prop_link("global-regs", hex_greg_dev);
121 }
122
123 if (m_l2vic) {
124 m_l2vic->before_end_of_elaboration();
125 qemu::Device cpu_dev = get_qemu_dev();
126 cpu_dev.set_prop_link("l2vic", m_l2vic->get_qemu_dev());
127 }
128
129 if (m_hex_tlb) {
130 m_hex_tlb->before_end_of_elaboration();
131 qemu::Device cpu_dev = get_qemu_dev();
132 cpu_dev.set_prop_link("tlb", m_hex_tlb->get_qemu_dev());
133 }
134 }
135
136 qemu::CpuHexagon get_cpu_hexagon() const { return qemu::CpuHexagon(m_cpu); }
137
138 void end_of_elaboration() override
139 {
140 QemuCpu::end_of_elaboration();
141
142 get_cpu_hexagon().register_reset();
143
144 for (int i = 0; i < irq_in.size(); ++i) {
145 irq_in[i].init(m_dev, i);
146 }
147 }
148
149public:
150 cci::cci_param<uint64_t> p_cfgbase;
151 cci::cci_param<bool> p_vp_mode;
152 cci::cci_param<bool> p_semihosting;
153 cci::cci_param<bool> p_start_powered_off;
154 cci::cci_param<bool> p_sched_limit;
155 cci::cci_param<bool> p_paranoid;
156 cci::cci_param<std::string> p_dsp_arch;
157 cci::cci_param<uint32_t> p_subsystem_id;
158 cci::cci_param<uint32_t> p_hexagon_num_threads;
159 cci::cci_param<bool> p_isdben_trusted;
160 cci::cci_param<bool> p_isdben_secure;
161 cci::cci_param<std::string> p_cmdline;
162 cci::cci_param<uint64_t> p_vtcm_base_addr;
163 cci::cci_param<uint32_t> p_vtcm_size_kb;
164 cci::cci_param<bool> p_coproc2_present;
165 cci::cci_param<uint32_t> p_hvx_contexts;
166};
167
168extern "C" void module_register();
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
A QEMU input GPIO exposed as a TargetSignalSocket<bool>.
Definition qemu-target-signal-socket.h:29
Definition hexagon_globalreg.h:19
Definition hexagon-l2vic.h:23
Definition hexagon_tlb.h:15
Definition hexagon.h:20
Definition libqemu-cxx.h:675