gem5  v20.1.0.0
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 
45  : VirtIODeviceBase(params, ID_CONSOLE, sizeof(Config), F_SIZE),
46  qRecv(params->system->physProxy, byteOrder, params->qRecvSize, *this),
47  qTrans(params->system->physProxy, byteOrder, params->qTransSize, *this),
48  device(*params->device)
49 {
52 
53  config.cols = 80;
54  config.rows = 24;
55 
56  device.regInterfaceCallback([this]() { qRecv.trySend(); });
57 }
58 
59 
61 {
62 }
63 void
65 {
66  Config cfg_out;
67  cfg_out.rows = htog(config.rows, byteOrder);
68  cfg_out.cols = htog(config.cols, byteOrder);
69 
70  readConfigBlob(pkt, cfgOffset, (uint8_t *)&cfg_out);
71 }
72 
73 void
75 {
76  DPRINTF(VIOConsole, "trySend\n");
77 
78  // Send data as long as the terminal has outgoing data and we can
79  // get free descriptors (i.e., there are buffers available to
80  // send) from the guest.
82  while (parent.device.dataAvailable() && (d = consumeDescriptor())) {
83  DPRINTF(VIOConsole, "Got descriptor (len: %i)\n", d->size());
84  size_t len(0);
85  while (parent.device.dataAvailable() && len < d->size()) {
86  uint8_t in(parent.device.readData());
87  d->chainWrite(len, &in, sizeof(uint8_t));
88  ++len;
89  }
90 
91  // Tell the guest that we are done with this descriptor.
93  parent.kick();
94  }
95 }
96 
97 void
99 {
100  DPRINTF(VIOConsole, "Got input data descriptor (len: %i)\n",
101  desc->size());
102 
103  // Copy the data from the guest and forward it to the
104  // terminal.
105  const size_t size(desc->chainSize());
106  uint8_t data[size];
107  desc->chainRead(0, data, size);
108  for (int i = 0; i < desc->size(); ++i)
109  parent.device.writeData(data[i]);
110 
111  // Tell the guest that we are done with this descriptor.
112  produceDescriptor(desc, 0);
113  parent.kick();
114 }
115 
117 VirtIOConsoleParams::create()
118 {
119  return new VirtIOConsole(this);
120 }
VirtDescriptor::size
size_t size() const
Retrieve the size of this descriptor.
Definition: base.hh:202
VirtIOConsole::device
SerialDevice & device
Definition: console.hh:150
VirtIOConsole::qTrans
TermTransQueue qTrans
Transmit queue for port 0.
Definition: console.hh:147
VirtQueue::produceDescriptor
void produceDescriptor(VirtDescriptor *desc, uint32_t len)
Send a descriptor chain to the guest.
Definition: base.cc:290
system.hh
data
const char data[]
Definition: circlebuf.test.cc:42
ArmISA::byteOrder
ByteOrder byteOrder(const ThreadContext *tc)
Definition: utility.hh:449
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
VirtIOConsole::readConfig
void readConfig(PacketPtr pkt, Addr cfgOffset)
Read from the configuration space of a device.
Definition: console.cc:64
VirtIOConsole::TermRecvQueue::parent
VirtIOConsole & parent
Definition: console.hh:122
VirtIODeviceBase::registerQueue
void registerQueue(VirtQueue &queue)
Register a new VirtQueue with the device model.
Definition: base.cc:477
console.hh
VirtIOConsole::~VirtIOConsole
virtual ~VirtIOConsole()
Definition: console.cc:60
VirtIODeviceBase
Base class for all VirtIO-based devices.
Definition: base.hh:558
VirtIOConsole::Params
VirtIOConsoleParams Params
Definition: console.hh:67
SerialDevice::regInterfaceCallback
void regInterfaceCallback(const std::function< void()> &callback)
Register a data available callback into the host interface layer.
Definition: serial.cc:53
X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:997
VirtIOConsole
VirtIO console.
Definition: console.hh:64
SerialDevice::dataAvailable
virtual bool dataAvailable() const =0
Check if there is pending data from the serial device.
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
ArmISA::d
Bitfield< 9 > d
Definition: miscregs_types.hh:60
htog
T htog(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:155
VirtIODeviceBase::readConfigBlob
void readConfigBlob(PacketPtr pkt, Addr cfgOffset, const uint8_t *cfg)
Read configuration data from a device structure.
Definition: base.cc:420
VirtDescriptor::chainSize
size_t chainSize() const
Retrieve the size of this descriptor chain.
Definition: base.cc:214
SerialDevice::readData
virtual uint8_t readData()=0
Read a character from the device.
VirtIOConsole::Config::cols
uint16_t cols
Definition: console.hh:81
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
VirtIOConsole::Config
Console configuration structure.
Definition: console.hh:80
VirtDescriptor::chainRead
void chainRead(size_t offset, uint8_t *dst, size_t size) const
Read the contents of a descriptor chain.
Definition: base.cc:168
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
VirtIOConsole::VirtIOConsole
VirtIOConsole(Params *params)
Definition: console.cc:44
VirtIOConsole::config
Config config
Currently active configuration (host byte order)
Definition: console.hh:86
VirtIOConsole::TermTransQueue::onNotifyDescriptor
void onNotifyDescriptor(VirtDescriptor *desc)
Notify queue of pending incoming descriptor.
Definition: console.cc:98
VirtQueue::consumeDescriptor
VirtDescriptor * consumeDescriptor()
Get an incoming descriptor chain from the queue.
Definition: base.cc:271
VirtIOConsole::qRecv
TermRecvQueue qRecv
Receive queue for port 0.
Definition: console.hh:125
VirtIOConsole::Config::rows
uint16_t rows
Definition: console.hh:82
VirtIODeviceBase::kick
void kick()
Inform the guest of available buffers.
Definition: base.hh:609
VirtIOConsole::TermRecvQueue::trySend
void trySend()
Try to send data pending data from the terminal.
Definition: console.cc:74
VirtIODeviceBase::byteOrder
ByteOrder byteOrder
The byte order of the queues, descriptors, etc.
Definition: base.hh:718
VirtDescriptor
VirtIO descriptor (chain) wrapper.
Definition: base.hh:106

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17