quic/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
22#define DSP_REV(arch) \
23 { \
24#arch, arch##_rev \
25 }
26
28{
29 cci::cci_broker_handle m_broker;
30
31public:
32 static constexpr qemu::Target ARCH = qemu::Target::HEXAGON;
33
34 typedef enum {
35 v66_rev = 0xa666,
36 v68_rev = 0x8d68,
37 v69_rev = 0x8c69,
38 v73_rev = 0x8c73,
39 v79_rev = 0x8c79,
40 v81_rev = 0x8781,
41 } Rev_t;
42
43 const std::map<std::string, Rev_t> DSP_REVS = {
44 DSP_REV(v66), DSP_REV(v68), DSP_REV(v69), DSP_REV(v73), DSP_REV(v79), DSP_REV(v81)
45 };
46 sc_core::sc_vector<QemuTargetSignalSocket> irq_in;
47
48 qemu_cpu_hexagon(const sc_core::sc_module_name& name, sc_core::sc_object* o)
49 : qemu_cpu_hexagon(name, *(dynamic_cast<QemuInstance*>(o)))
50 {
51 }
52 qemu_cpu_hexagon(const sc_core::sc_module_name& name, QemuInstance& inst)
53 : QemuCpu(name, inst, "v67-hexagon")
54 , m_broker(cci::cci_get_broker())
55 , irq_in("irq_in", 8, [](const char* n, int i) { return new QemuTargetSignalSocket(n); })
56 , p_cfgbase("config_table_addr", 0xffffffffULL, "config table address")
57 , p_l2vic_base_addr("l2vic_base_addr", 0xffffffffULL, "l2vic base address")
58 , p_qtimer_base_addr("qtimer_base_addr", 0xffffffffULL, "qtimer base address")
59 , p_exec_start_addr("hexagon_start_addr", 0xffffffffULL, "execution start address")
60 , p_vp_mode("vp_mode", true, "override the vp_mode for testing")
61 , p_semihosting("enable_semihosting", false, "enable semihosting for debugging/testing")
62 , p_dsp_arch("dsp_arch", "v68", "DSP arch")
63 , p_start_powered_off("start_powered_off", false,
64 "Start and reset the CPU "
65 "in powered-off state")
66 , p_sched_limit("sched_limit", true, "use sched limit")
67 , p_paranoid("paranoid_commit_state", false, "enable per-packet checks")
68 , p_subsystem_id("subsystem_id", 0, "subsystem id")
69 , p_hexagon_num_threads("hexagon_num_threads", 8,
70 "number of hexagon threads") // THREADS_MAX in ./target/hexagon/cpu.h
71 , p_isdben_trusted("isdben_trusted", true, "isdben trusted")
72 , p_isdben_secure("isdben_secure", true, "isdben secure")
73 , p_coproc("coproc", "", "coproc")
74 , p_cmdline("cmdline", "", "cmdline")
75 , p_vtcm_base_addr("vtcm_base_addr", 0, "vtcm base address")
76 , p_vtcm_size_kb("vtcm_size_kb", 0, "vtcm size in kb")
77 , p_num_coproc_instance("num_coproc_instance", 0, "number of coproc instances")
78 , p_hvx_contexts("hvx_contexts", 0, "number of HVX contexts")
79 , p_num_tlbs("num_tlbs", 0, "number of Joint TLB entries")
80 , p_num_dma_tlbs("num_dma_tlbs", 0, "number of DMA TLB entries")
81 /*
82 * We have no choice but to attach-suspend here. This is fixable but
83 * non-trivial. It means that the SystemC kernel will never starve...
84 */
85 {
86 for (int i = 0; i < irq_in.size(); ++i) {
87 m_external_ev |= irq_in[i]->default_event();
88 }
89 }
90
91 void before_end_of_elaboration() override
92 {
93 const std::string dsp_arch = p_dsp_arch.get_value();
94 set_qom_type(dsp_arch + "-hexagon-cpu");
95 // set the parameter config-table-addr 195 hexagon_testboard
96 QemuCpu::before_end_of_elaboration();
97 qemu::CpuHexagon cpu(get_qemu_dev());
98
99 Rev_t dsp_rev;
100 auto rev = DSP_REVS.find(dsp_arch);
101 if (rev != DSP_REVS.end()) {
102 dsp_rev = rev->second;
103 } else {
104 SCP_FATAL(())("Unrecognized Architecture Revision: " + dsp_arch);
105 }
106 cpu.set_prop_int("config-table-addr", p_cfgbase);
107 cpu.set_prop_int("dsp-rev", dsp_rev);
108 cpu.set_prop_int("l2vic-base-addr", p_l2vic_base_addr);
109 cpu.set_prop_int("qtimer-base-addr", p_qtimer_base_addr);
110 cpu.set_prop_int("exec-start-addr", p_exec_start_addr);
111 cpu.set_prop_bool("start-powered-off", p_start_powered_off);
112 // in case of additional reset, this value will be loaded for PC
113 cpu.set_prop_int("start-evb", p_exec_start_addr);
114 cpu.set_prop_bool("sched-limit", p_sched_limit);
115 cpu.set_prop_bool("virtual-platform-mode", p_vp_mode);
116 cpu.set_prop_bool("enable-semihosting", p_semihosting);
117 cpu.set_prop_bool("paranoid-commit-state", p_paranoid);
118 cpu.set_prop_int("subsystem-id", p_subsystem_id);
119 cpu.set_prop_int("thread-count", p_hexagon_num_threads);
120 cpu.set_prop_bool("isdben-trusted", p_isdben_trusted);
121 cpu.set_prop_bool("isdben-secure", p_isdben_secure);
122 cpu.set_prop_str("coproc", p_coproc.get_value().data());
123 cpu.set_prop_str("cmdline", p_cmdline.get_value().data());
124 cpu.set_prop_int("vtcm-base-addr", p_vtcm_base_addr);
125 cpu.set_prop_int("vtcm-size-kb", p_vtcm_size_kb);
126 cpu.set_prop_int("num-coproc-instance", p_num_coproc_instance);
127 cpu.set_prop_int("hvx-contexts", p_hvx_contexts);
128 if (!p_num_tlbs.is_default_value()) {
129 cpu.set_prop_int("jtlb-entries", p_num_tlbs);
130 }
131 if (!p_num_dma_tlbs.is_default_value()) {
132 cpu.set_prop_int("dma-jtlb-entries", p_num_dma_tlbs);
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<uint32_t> p_l2vic_base_addr;
152 cci::cci_param<uint32_t> p_qtimer_base_addr;
153 cci::cci_param<uint32_t> p_exec_start_addr;
154 cci::cci_param<bool> p_vp_mode;
155 cci::cci_param<bool> p_semihosting;
156 cci::cci_param<bool> p_start_powered_off;
157 cci::cci_param<bool> p_sched_limit;
158 cci::cci_param<bool> p_paranoid;
159 cci::cci_param<std::string> p_dsp_arch;
160 cci::cci_param<uint32_t> p_subsystem_id;
161 cci::cci_param<uint32_t> p_hexagon_num_threads;
162 cci::cci_param<bool> p_isdben_trusted;
163 cci::cci_param<bool> p_isdben_secure;
164 cci::cci_param<std::string> p_coproc;
165 cci::cci_param<std::string> p_cmdline;
166 cci::cci_param<uint64_t> p_vtcm_base_addr;
167 cci::cci_param<uint32_t> p_vtcm_size_kb;
168 cci::cci_param<uint32_t> p_num_coproc_instance;
169 cci::cci_param<uint32_t> p_hvx_contexts;
170 cci::cci_param<uint32_t> p_num_tlbs;
171 cci::cci_param<uint32_t> p_num_dma_tlbs;
172};
173
174extern "C" void module_register();
Definition cpu.h:30
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 target.h:160
Definition hexagon.h:15
Definition hexagon.h:28