qualcomm/qbox
Loading...
Searching...
No Matches
qemu_hexagon_qtimer.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * Author: GreenSocs 2021
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _LIBQBOX_COMPONENTS_TIMER_HEXAGON_QTIMER_H
10#define _LIBQBOX_COMPONENTS_TIMER_HEXAGON_QTIMER_H
11
12#include <string>
13#include <cassert>
14#include <memory>
15#include <vector>
16
17#include <device.h>
18#include <ports/target.h>
19#include <ports/qemu-target-signal-socket.h>
20#include <ports/qemu-initiator-signal-socket.h>
21#include <module_factory_registery.h>
22
23class qemu_hexagon_qtimer : public QemuDevice
24{
25protected:
26 cci::cci_param<unsigned int> p_nr_frames;
27 cci::cci_param<unsigned int> p_nr_views;
28 cci::cci_param<unsigned int> p_frame_stride;
29 cci::cci_param<uint32_t> p_freq_hz;
30 cci::cci_param<uint32_t> p_freq_scale;
31 /* One cnttid register covers 8 frames (4 bits/nibble per frame in a 32-bit register).
32 * Number of cnttid registers = ceil(nr_frames / 8). */
33 std::vector<std::unique_ptr<cci::cci_param<unsigned int>>> p_cnttid;
34
35public:
36 QemuTargetSocket<> socket;
37
38 /*
39 * FIXME:
40 * the irq is not really declared as a gpio in qemu, so we cannot
41 * import it
42 *QemuInitiatorSignalSocket irq;
43 */
44
45 /* timers mem/irq */
46 QemuTargetSocket<> view_socket;
47 sc_core::sc_vector<QemuInitiatorSignalSocket> irq;
48
49public:
50 qemu_hexagon_qtimer(const sc_core::sc_module_name& name, sc_core::sc_object* o)
51 : qemu_hexagon_qtimer(name, *(dynamic_cast<QemuInstance*>(o)))
52 {
53 }
54 qemu_hexagon_qtimer(sc_core::sc_module_name nm, QemuInstance& inst)
55 : QemuDevice(nm, inst, "qct-qtimer")
56 , p_nr_frames("nr_frames", 2, "Number of frames")
57 , p_nr_views("nr_views", 1, "Number of views")
58 , p_frame_stride("frame_stride", 0x1000, "Frame stride in bytes")
59 , p_freq_hz("freq_hz", 19200000, "freq of the timer in hz")
60 , p_freq_scale("freq_scale", 100, "scale down factor of the timer freq")
61 , socket("mem", inst)
62 , view_socket("mem_view", inst)
63 , irq("irq", p_nr_frames.get_value(), [](const char* n, size_t i) { return new QemuInitiatorSignalSocket(n); })
64 {
65 /* 4 bits (one nibble) per frame in a 32-bit cnttid register -> 8 frames per register */
66 unsigned int nr_cnttid = (p_nr_frames.get_value() + 7) / 8;
67 for (unsigned int i = 0; i < nr_cnttid; ++i) {
68 p_cnttid.push_back(std::make_unique<cci::cci_param<unsigned int>>(
69 std::string("cnttid_") + std::to_string(i), (i == 0) ? 0x11u : 0x0u,
70 std::string("Value of cnttid_") + std::to_string(i)));
71 }
72 }
73
74 void before_end_of_elaboration() override
75 {
76 QemuDevice::before_end_of_elaboration();
77
78 m_dev.set_prop_int("nr_frames", p_nr_frames);
79 m_dev.set_prop_int("nr_views", p_nr_views);
80 m_dev.set_prop_int("frame_stride", p_frame_stride);
81 m_dev.set_prop_int("freq", p_freq_hz.get_value());
82 m_dev.set_prop_int("freq-scale", p_freq_scale.get_value());
83 for (unsigned int i = 0; i < p_cnttid.size(); ++i) {
84 m_dev.set_prop_int((std::string("cnttid_") + std::to_string(i)).c_str(), *p_cnttid[i]);
85 }
86 }
87
88 void end_of_elaboration() override
89 {
90 QemuDevice::set_sysbus_as_parent_bus();
91 QemuDevice::end_of_elaboration();
92
93 qemu::SysBusDevice sbd(m_dev);
94 socket.init(sbd, 0);
95 view_socket.init(sbd, 1);
96
97 for (uint32_t i = 0; i < p_nr_frames.get_value(); ++i) {
98 irq[i].init_sbd(sbd, i);
99 }
100 }
101};
102
103extern "C" void module_register();
104#endif
QemuDevice(const sc_core::sc_module_name &name, QemuInstance &inst, const char *qom_type)
Construct a QEMU device.
Definition device.h:86
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
Definition target.h:194
Definition libqemu-cxx.h:699