quic/qbox
Loading...
Searching...
No Matches
reset_gpio.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef _LIBQBOX_COMPONENTS_RESET_GPIO_INITIATOR_H
9#define _LIBQBOX_COMPONENTS_RESET_GPIO_INITIATOR_H
10
11#include <ports/qemu-initiator-signal-socket.h>
12#include <ports/qemu-target-signal-socket.h>
13#include <device.h>
14#include <qemu-instance.h>
15#include <module_factory_registery.h>
16#include <ports/multiinitiator-signal-socket.h>
17
18class reset_gpio : public QemuDevice
19{
20 SCP_LOGGER();
22 QemuTargetSignalSocket m_reset_t;
23
24 bool m_qemu_resetting = false;
25 bool m_systemc_resetting = false;
26 sc_core::sc_event m_reset_ev;
27
28public:
31
32 reset_gpio(const sc_core::sc_module_name& name, sc_core::sc_object* o)
33 : reset_gpio(name, *(dynamic_cast<QemuInstance*>(o)))
34 {
35 }
36 reset_gpio(const sc_core::sc_module_name& n, QemuInstance& inst)
37 : QemuDevice(n, inst, "reset_gpio")
38 , m_reset_i("_qemu_reset_i")
39 , m_reset_t("_qemu_reset_t")
40 , reset_out("reset_out")
41 , reset_in("reset_in")
42 {
43 SCP_TRACE(())("Init");
44 m_reset_i.bind(m_reset_t);
45
46 /* QEMU signalling reset*/
47 m_reset_t.register_value_changed_cb([&](bool value) {
48 sc_core::sc_suspendable(); // we should never be in a situation where the caller is waiting for us to
49 // complete, so we can remove the unsuspendable restriction
50 if (value) {
51 if (!m_systemc_resetting && !m_qemu_resetting) {
52 SCP_INFO(())("QEMU resetting");
53 m_qemu_resetting = true;
54
55 SCP_DEBUG(())("Starting SystemC reset");
56 m_systemc_resetting = true;
57 reset_out.async_write_vector({ 1, 0 }); // Async reset systemc
58 }
59 } else {
60 assert(m_qemu_resetting);
61 // QEMU has done it's reset.
62 SCP_INFO(())("QEMU done resetting");
63 m_qemu_resetting = false;
64 m_reset_ev.notify();
65 while (m_systemc_resetting) {
66 SCP_DEBUG(())("Waiting for SystemC to be done resetting");
67 wait(m_reset_ev);
68 }
69 SCP_DEBUG(())("Finished waiting for SystemC reset");
70 }
71 });
72
73 /* SystemC signalling reset*/
74 reset_in.register_value_changed_cb([&](bool value) {
75 if (value) {
76 if (!m_systemc_resetting && !m_qemu_resetting) {
77 SCP_INFO(())("SystemC resetting");
78 m_systemc_resetting = true;
79
80 SCP_DEBUG(())("Starting QEMU reset");
81 m_qemu_resetting = true;
82 m_inst.get().system_reset(); // Async reset qemu
83 }
84 } else {
85 assert(m_systemc_resetting);
86 SCP_INFO(())("SystemC done resetting");
87 m_systemc_resetting = false;
88 m_reset_ev.notify();
89 while (m_qemu_resetting) {
90 SCP_DEBUG(())("Waiting Qemu to be done resetting");
91 wait(m_reset_ev);
92 }
93 SCP_DEBUG(())("Finished waiting for QEMU reset");
94 }
95 });
96 }
97
98 virtual void end_of_elaboration() override
99 {
100 QemuDevice::end_of_elaboration();
101 m_reset_i.init_named(m_dev, "reset_out", 0);
102 }
103 virtual void start_of_simulation() override { m_dev.set_prop_bool("active", true); }
104};
105
106extern "C" void module_register();
107#endif //_LIBQBOX_COMPONENTS_RESET_GPIO_INITIATOR_H
QEMU device abstraction as a SystemC module.
Definition device.h:37
A QEMU output GPIO exposed as a InitiatorSignalSocket<bool>
Definition qemu-initiator-signal-socket.h:40
void init_named(qemu::Device dev, const char *gpio_name, int gpio_idx)
Initialize this socket with a device, a GPIO namespace, and a GPIO index.
Definition qemu-initiator-signal-socket.h:155
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
qemu::LibQemu & get()
Returns the underlying qemu::LibQemu instance.
Definition qemu-instance.h:448
A QEMU input GPIO exposed as a TargetSignalSocket<bool>
Definition qemu-target-signal-socket.h:29
Definition target.h:160
Definition reset_gpio.h:19