quic/qbox
Loading...
Searching...
No Matches
riscv-aclint-mtimer.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * Author: GreenSocs 2022
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#pragma once
10
11#include <vector>
12
13#include <cci_configuration>
14
15#include <libqemu-cxx/target/riscv.h>
16#include <module_factory_registery.h>
17
18#include <ports/target.h>
19#include <device.h>
20
22{
23public:
24 cci::cci_param<unsigned int> p_num_harts;
25 cci::cci_param<uint64_t> p_timecmp_base;
26 cci::cci_param<uint64_t> p_time_base;
27 cci::cci_param<uint64_t> p_aperture_size;
28 cci::cci_param<uint32_t> p_timebase_freq;
29 cci::cci_param<bool> p_provide_rdtime;
30
31 QemuTargetSocket<> socket;
32
33 riscv_aclint_mtimer(const sc_core::sc_module_name& name, sc_core::sc_object* o)
34 : riscv_aclint_mtimer(name, *(dynamic_cast<QemuInstance*>(o)))
35 {
36 }
37 riscv_aclint_mtimer(sc_core::sc_module_name nm, QemuInstance& inst)
38 : QemuDevice(nm, inst, "riscv.aclint.mtimer")
39 , p_num_harts("num_harts", 0, "Number of HARTS this CLINT is connected to")
40 , p_timecmp_base("timecmp_base", 0, "Base address for the TIMECMP registers")
41 , p_time_base("time_base", 0, "Base address for the TIME registers")
42 , p_aperture_size("aperture_size", 0, "Size of the whole CLINT address space")
43 , p_timebase_freq("timebase_freq", 10000000, "")
44 , p_provide_rdtime("provide_rdtime", false,
45 "If true, provide the CPU with "
46 "a rdtime register")
47 , socket("mem", inst)
48 {
49 }
50
51 void before_end_of_elaboration() override
52 {
53 QemuDevice::before_end_of_elaboration();
54
55 m_dev.set_prop_int("num-harts", p_num_harts);
56 m_dev.set_prop_int("timecmp-base", p_timecmp_base);
57 m_dev.set_prop_int("time-base", p_time_base);
58 m_dev.set_prop_int("aperture-size", p_aperture_size);
59 m_dev.set_prop_int("timebase-freq", p_timebase_freq);
60 m_dev.set_prop_bool("provide-rdtime", p_provide_rdtime);
61 }
62
63 void end_of_elaboration() override
64 {
65 QemuDevice::set_sysbus_as_parent_bus();
66 QemuDevice::end_of_elaboration();
67
68 qemu::SysBusDevice sbd(get_qemu_dev());
69 socket.init(qemu::SysBusDevice(m_dev), 0);
70 }
71};
72
73extern "C" void module_register();
QEMU device abstraction as a SystemC module.
Definition device.h:37
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
Definition target.h:160
Definition libqemu-cxx.h:638
Definition riscv-aclint-mtimer.h:22