gem5  v22.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 
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
#define DPRINTF(x,...)
Definition: trace.hh:186
const char data[]
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
virtual uint8_t readData()=0
Read a character from the device.
void regInterfaceCallback(const std::function< void()> &callback)
Register a data available callback into the host interface layer.
Definition: serial.cc:56
virtual bool dataAvailable() const =0
Check if there is pending data from the serial device.
VirtIO descriptor (chain) wrapper.
Definition: base.hh:118
size_t size() const
Retrieve the size of this descriptor.
Definition: base.hh:213
void chainRead(size_t offset, uint8_t *dst, size_t size) const
Read the contents of a descriptor chain.
Definition: base.cc:172
size_t chainSize() const
Retrieve the size of this descriptor chain.
Definition: base.cc:218
void trySend()
Try to send data pending data from the terminal.
Definition: console.cc:77
void onNotifyDescriptor(VirtDescriptor *desc)
Notify queue of pending incoming descriptor.
Definition: console.cc:101
VirtIOConsole(const Params &params)
Definition: console.cc:47
virtual ~VirtIOConsole()
Definition: console.cc:63
VirtIOConsoleParams Params
Definition: console.hh:71
TermRecvQueue qRecv
Receive queue for port 0.
Definition: console.hh:130
SerialDevice & device
Definition: console.hh:155
Config config
Currently active configuration (host byte order)
Definition: console.hh:91
void readConfig(PacketPtr pkt, Addr cfgOffset)
Read from the configuration space of a device.
Definition: console.cc:67
TermTransQueue qTrans
Transmit queue for port 0.
Definition: console.hh:152
Base class for all VirtIO-based devices.
Definition: base.hh:588
void kick()
Inform the guest of available buffers.
Definition: base.hh:638
ByteOrder byteOrder
The byte order of the queues, descriptors, etc.
Definition: base.hh:747
void readConfigBlob(PacketPtr pkt, Addr cfgOffset, const uint8_t *cfg)
Read configuration data from a device structure.
Definition: base.cc:434
void registerQueue(VirtQueue &queue)
Register a new VirtQueue with the device model.
Definition: base.cc:491
void produceDescriptor(VirtDescriptor *desc, uint32_t len)
Send a descriptor chain to the guest.
Definition: base.cc:304
VirtDescriptor * consumeDescriptor()
Get an incoming descriptor chain from the queue.
Definition: base.cc:285
uint16_t len
Definition: helpers.cc:62
ByteOrder byteOrder(const ThreadContext *tc)
Definition: utility.hh:357
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 9 > d
Definition: misc_types.hh:64
Bitfield< 15 > system
Definition: misc.hh:1004
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
T htog(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:187
Console configuration structure.
Definition: console.hh:85

Generated on Wed Dec 21 2022 10:22:35 for gem5 by doxygen 1.9.1