gem5  v21.1.0.2
console.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include "dev/virtio/console.hh"
39 
40 #include "debug/VIOConsole.hh"
41 #include "params/VirtIOConsole.hh"
42 #include "sim/system.hh"
43 
44 namespace gem5
45 {
46 
48  : VirtIODeviceBase(params, ID_CONSOLE, sizeof(Config), F_SIZE),
49  qRecv(params.system->physProxy, byteOrder, params.qRecvSize, *this),
50  qTrans(params.system->physProxy, byteOrder, params.qTransSize, *this),
51  device(*params.device)
52 {
55 
56  config.cols = 80;
57  config.rows = 24;
58 
59  device.regInterfaceCallback([this]() { qRecv.trySend(); });
60 }
61 
62 
64 {
65 }
66 void
68 {
69  Config cfg_out;
70  cfg_out.rows = htog(config.rows, byteOrder);
71  cfg_out.cols = htog(config.cols, byteOrder);
72 
73  readConfigBlob(pkt, cfgOffset, (uint8_t *)&cfg_out);
74 }
75 
76 void
78 {
79  DPRINTF(VIOConsole, "trySend\n");
80 
81  // Send data as long as the terminal has outgoing data and we can
82  // get free descriptors (i.e., there are buffers available to
83  // send) from the guest.
85  while (parent.device.dataAvailable() && (d = consumeDescriptor())) {
86  DPRINTF(VIOConsole, "Got descriptor (len: %i)\n", d->size());
87  size_t len(0);
88  while (parent.device.dataAvailable() && len < d->size()) {
89  uint8_t in(parent.device.readData());
90  d->chainWrite(len, &in, sizeof(uint8_t));
91  ++len;
92  }
93 
94  // Tell the guest that we are done with this descriptor.
96  parent.kick();
97  }
98 }
99 
100 void
102 {
103  DPRINTF(VIOConsole, "Got input data descriptor (len: %i)\n",
104  desc->size());
105 
106  // Copy the data from the guest and forward it to the
107  // terminal.
108  const size_t size(desc->chainSize());
109  uint8_t data[size];
110  desc->chainRead(0, data, size);
111  for (int i = 0; i < desc->size(); ++i)
112  parent.device.writeData(data[i]);
113 
114  // Tell the guest that we are done with this descriptor.
115  produceDescriptor(desc, 0);
116  parent.kick();
117 }
118 
119 } // namespace gem5
gem5::VirtIOConsole::qTrans
TermTransQueue qTrans
Transmit queue for port 0.
Definition: console.hh:152
gem5::VirtIOConsole::Config::cols
uint16_t cols
Definition: console.hh:86
gem5::ArmISA::len
Bitfield< 18, 16 > len
Definition: misc_types.hh:444
system.hh
data
const char data[]
Definition: circlebuf.test.cc:48
console.hh
gem5::VirtIOConsole::TermTransQueue::onNotifyDescriptor
void onNotifyDescriptor(VirtDescriptor *desc)
Notify queue of pending incoming descriptor.
Definition: console.cc:101
gem5::X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:1003
gem5::ArmISA::byteOrder
ByteOrder byteOrder(const ThreadContext *tc)
Definition: utility.hh:412
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::SerialDevice::dataAvailable
virtual bool dataAvailable() const =0
Check if there is pending data from the serial device.
gem5::VirtIODeviceBase::readConfigBlob
void readConfigBlob(PacketPtr pkt, Addr cfgOffset, const uint8_t *cfg)
Read configuration data from a device structure.
Definition: base.cc:434
gem5::VirtIOConsole::device
SerialDevice & device
Definition: console.hh:155
gem5::VirtIOConsole::readConfig
void readConfig(PacketPtr pkt, Addr cfgOffset)
Read from the configuration space of a device.
Definition: console.cc:67
gem5::VirtIOConsole::Config::rows
uint16_t rows
Definition: console.hh:87
gem5::VirtIOConsole::TermRecvQueue::parent
VirtIOConsole & parent
Definition: console.hh:127
gem5::VirtDescriptor::chainSize
size_t chainSize() const
Retrieve the size of this descriptor chain.
Definition: base.cc:218
gem5::VirtIOConsole::Params
VirtIOConsoleParams Params
Definition: console.hh:71
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::VirtIODeviceBase::registerQueue
void registerQueue(VirtQueue &queue)
Register a new VirtQueue with the device model.
Definition: base.cc:491
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::ArmISA::d
Bitfield< 9 > d
Definition: misc_types.hh:63
gem5::VirtIODeviceBase::kick
void kick()
Inform the guest of available buffers.
Definition: base.hh:638
gem5::VirtIOConsole::~VirtIOConsole
virtual ~VirtIOConsole()
Definition: console.cc:63
gem5::VirtDescriptor::size
size_t size() const
Retrieve the size of this descriptor.
Definition: base.hh:213
gem5::htog
T htog(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:187
gem5::VirtIODeviceBase
Base class for all VirtIO-based devices.
Definition: base.hh:587
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::SerialDevice::regInterfaceCallback
void regInterfaceCallback(const std::function< void()> &callback)
Register a data available callback into the host interface layer.
Definition: serial.cc:56
gem5::VirtIOConsole::config
Config config
Currently active configuration (host byte order)
Definition: console.hh:91
gem5::VirtIOConsole::TermRecvQueue::trySend
void trySend()
Try to send data pending data from the terminal.
Definition: console.cc:77
gem5::VirtIOConsole::VirtIOConsole
VirtIOConsole(const Params &params)
Definition: console.cc:47
gem5::VirtDescriptor
VirtIO descriptor (chain) wrapper.
Definition: base.hh:117
gem5::VirtIODeviceBase::byteOrder
ByteOrder byteOrder
The byte order of the queues, descriptors, etc.
Definition: base.hh:747
gem5::VirtQueue::produceDescriptor
void produceDescriptor(VirtDescriptor *desc, uint32_t len)
Send a descriptor chain to the guest.
Definition: base.cc:304
gem5::VirtDescriptor::chainRead
void chainRead(size_t offset, uint8_t *dst, size_t size) const
Read the contents of a descriptor chain.
Definition: base.cc:172
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::VirtQueue::consumeDescriptor
VirtDescriptor * consumeDescriptor()
Get an incoming descriptor chain from the queue.
Definition: base.cc:285
gem5::SerialDevice::readData
virtual uint8_t readData()=0
Read a character from the device.
gem5::VirtIOConsole::qRecv
TermRecvQueue qRecv
Receive queue for port 0.
Definition: console.hh:130
gem5::VirtIOConsole::Config
Console configuration structure.
Definition: console.hh:84

Generated on Tue Sep 21 2021 12:25:21 for gem5 by doxygen 1.8.17