gem5  v22.0.0.2
fs9p.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2017 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 #ifndef __DEV_VIRTIO_FS9P_HH__
39 #define __DEV_VIRTIO_FS9P_HH__
40 
41 #include <map>
42 #include <memory>
43 #include <string>
44 
45 #include "base/compiler.hh"
46 #include "base/pollevent.hh"
47 #include "dev/virtio/base.hh"
48 
49 namespace gem5
50 {
51 
52 struct VirtIO9PBaseParams;
53 
54 typedef uint8_t P9MsgType;
55 typedef uint16_t P9Tag;
56 
58 {
60  uint32_t len;
65 };
66 
68 template <typename T> inline T
69 p9toh(T v) { return letoh(v); }
70 
72 template <typename T> inline T
73 htop9(T v) { return htole(v); }
74 
75 template <> inline P9MsgHeader
77 {
78  v.len = p9toh(v.len);
79  v.type = p9toh(v.type);
80  v.tag = p9toh(v.tag);
81  return v;
82 }
83 
84 template <> inline P9MsgHeader
86 {
87  v.len = htop9(v.len);
88  v.type = htop9(v.type);
89  v.tag = htop9(v.tag);
90  return v;
91 }
92 
113 {
114  public:
115  typedef VirtIO9PBaseParams Params;
116  VirtIO9PBase(const Params &params);
117  virtual ~VirtIO9PBase();
118 
119  void readConfig(PacketPtr pkt, Addr cfgOffset);
120 
121  protected:
129  {
130  uint16_t len;
131  char tag[];
132  };
133 
135  std::unique_ptr<Config, void(*)(void *p)> config =
136  {nullptr, [](void *p){ operator delete(p); }};
137 
139  static const DeviceId ID_9P = 0x09;
140 
145  static const FeatureBits F_MOUNT_TAG = 0x01;
148  protected:
152  class FSQueue : public VirtQueue
153  {
154  public:
155  FSQueue(PortProxy &proxy, ByteOrder bo,
156  uint16_t size, VirtIO9PBase &_parent)
157  : VirtQueue(proxy, bo, size), parent(_parent) {}
158  virtual ~FSQueue() {}
159 
161 
162  std::string name() const { return parent.name() + ".queue"; }
163 
164  protected:
166  };
167 
169 
170  protected:
178  virtual void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size) = 0;
186  void sendRMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);
187 
195  void dumpMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);
196 
197  private:
207  std::map<P9Tag, VirtDescriptor *> pendingTransactions;
208 };
209 
210 struct VirtIO9PProxyParams;
211 
219 {
220  public:
221  typedef VirtIO9PProxyParams Params;
222  VirtIO9PProxy(const Params &params);
223  virtual ~VirtIO9PProxy();
224 
225  void serialize(CheckpointOut &cp) const override;
226  void unserialize(CheckpointIn &cp) override;
227 
228  protected:
229  void recvTMsg(const P9MsgHeader &header, const uint8_t *data,
230  size_t size) override;
231 
233  void serverDataReady();
234 
244  virtual ssize_t read(uint8_t *data, size_t len) = 0;
254  virtual ssize_t write(const uint8_t *data, size_t len) = 0;
255 
266  void readAll(uint8_t *data, size_t len);
277  void writeAll(const uint8_t *data, size_t len);
278 
289 };
290 
291 struct VirtIO9PDiodParams;
292 
298 {
299  public:
300  typedef VirtIO9PDiodParams Params;
301  VirtIO9PDiod(const Params &params);
302  virtual ~VirtIO9PDiod();
303 
304  void startup();
305 
306  protected:
310  void startDiod();
311 
312  ssize_t read(uint8_t *data, size_t len);
313  ssize_t write(const uint8_t *data, size_t len);
315  void terminateDiod();
316 
317  private:
318  class DiodDataEvent : public PollEvent
319  {
320  public:
321  DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
322  : PollEvent(fd, event), parent(_parent) {}
323 
324  virtual ~DiodDataEvent() {};
325 
326  void process(int revent);
327 
328  private:
330  };
331 
336 
337  std::unique_ptr<DiodDataEvent> dataEvent;
338 
340  int diod_pid;
341 };
342 
343 struct VirtIO9PSocketParams;
344 
350 {
351  public:
352  typedef VirtIO9PSocketParams Params;
353  VirtIO9PSocket(const Params &params);
354  virtual ~VirtIO9PSocket();
355 
356  void startup();
357 
358  protected:
362  void connectSocket();
363 
365  void socketDisconnect();
366 
367  ssize_t read(uint8_t *data, size_t len);
368  ssize_t write(const uint8_t *data, size_t len);
369 
370  private:
371  class SocketDataEvent : public PollEvent
372  {
373  public:
375  : PollEvent(fd, event), parent(_parent) {}
376 
377  virtual ~SocketDataEvent() {};
378 
379  void process(int revent);
380 
381  private:
383  };
384 
386  int fdSocket;
387 
388  std::unique_ptr<SocketDataEvent> dataEvent;
389 };
390 
391 } // namespace gem5
392 
393 #endif // __DEV_VIRTIO_FS9P_HH__
gem5::VirtIO9PBase
This class implements a VirtIO transport layer for the 9p network file system.
Definition: fs9p.hh:112
gem5::VirtIO9PSocket::SocketDataEvent::SocketDataEvent
SocketDataEvent(VirtIO9PSocket &_parent, int fd, int event)
Definition: fs9p.hh:374
gem5::VirtIO9PDiod::dataEvent
std::unique_ptr< DiodDataEvent > dataEvent
Definition: fs9p.hh:337
gem5::VirtIO9PBase::F_MOUNT_TAG
static const FeatureBits F_MOUNT_TAG
Device provides a name of the resource in its configuration.
Definition: fs9p.hh:145
gem5::VirtIO9PSocket::fdSocket
int fdSocket
Socket connected to the 9p server.
Definition: fs9p.hh:386
gem5::VirtIO9PDiod::read
ssize_t read(uint8_t *data, size_t len)
Read data from the server behind the proxy.
Definition: fs9p.cc:413
gem5::VirtIO9PBase::Params
VirtIO9PBaseParams Params
Definition: fs9p.hh:115
gem5::VirtIO9PBase::pendingTransactions
std::map< P9Tag, VirtDescriptor * > pendingTransactions
Map between 9p transaction tags and descriptors where they appeared.
Definition: fs9p.hh:207
gem5::GEM5_PACKED
PM4 packets.
Definition: pm4_defines.hh:77
gem5::VirtIO9PDiod::DiodDataEvent::DiodDataEvent
DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
Definition: fs9p.hh:321
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::VirtIO9PBase::queue
FSQueue queue
Definition: fs9p.hh:168
gem5::ArmISA::fd
Bitfield< 14, 12 > fd
Definition: types.hh:150
gem5::VirtIO9PProxy::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fs9p.cc:242
gem5::VirtIO9PProxy::writeAll
void writeAll(const uint8_t *data, size_t len)
Convenience function that writes exactly len bytes.
Definition: fs9p.cc:303
gem5::VirtIODeviceBase::DeviceId
uint16_t DeviceId
Device Type (sometimes known as subsystem ID)
Definition: base.hh:599
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::VirtIO9PSocket::SocketDataEvent::parent
VirtIO9PSocket & parent
Definition: fs9p.hh:382
gem5::MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:300
gem5::VirtIO9PProxy::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fs9p.cc:229
gem5::P9MsgType
uint8_t P9MsgType
Definition: fs9p.hh:52
gem5::VirtIO9PProxy::deviceUsed
bool deviceUsed
Bool to track if the device has been used or not.
Definition: fs9p.hh:288
header
output header
Definition: nop.cc:36
gem5::PollEvent
Definition: pollevent.hh:43
gem5::letoh
T letoh(T value)
Definition: byteswap.hh:173
base.hh
gem5::VirtIO9PSocket::socketDisconnect
void socketDisconnect()
9p server disconnect notification
Definition: fs9p.cc:530
gem5::VirtIO9PBase::recvTMsg
virtual void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size)=0
Handle incoming 9p RPC message.
gem5::VirtIO9PSocket::VirtIO9PSocket
VirtIO9PSocket(const Params &params)
Definition: fs9p.cc:475
gem5::VirtQueue
Base wrapper around a virtqueue.
Definition: base.hh:302
gem5::VirtIO9PSocket
VirtIO 9p proxy that communicates with a 9p server over tcp sockets.
Definition: fs9p.hh:349
gem5::VirtIO9PSocket::SocketDataEvent::~SocketDataEvent
virtual ~SocketDataEvent()
Definition: fs9p.hh:377
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::VirtIO9PBase::FSQueue::onNotifyDescriptor
void onNotifyDescriptor(VirtDescriptor *desc)
Notify queue of pending incoming descriptor.
Definition: fs9p.cc:147
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
gem5::VirtIO9PDiod::DiodDataEvent::~DiodDataEvent
virtual ~DiodDataEvent()
Definition: fs9p.hh:324
gem5::VirtIO9PDiod::fd_to_diod
int fd_to_diod
fd for data pipe going to diod (write end)
Definition: fs9p.hh:333
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:291
gem5::PowerISA::bo
Bitfield< 25, 21 > bo
Definition: types.hh:82
gem5::P9Tag
uint16_t P9Tag
Definition: fs9p.hh:55
pollevent.hh
gem5::VirtIO9PDiod::startup
void startup()
startup() is the final initialization call before simulation.
Definition: fs9p.cc:332
gem5::VirtIO9PProxy::readAll
void readAll(uint8_t *data, size_t len)
Convenience function that reads exactly len bytes.
Definition: fs9p.cc:288
gem5::VirtIO9PBase::FSQueue::~FSQueue
virtual ~FSQueue()
Definition: fs9p.hh:158
len
uint16_t len
Definition: helpers.cc:62
gem5::PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:86
gem5::VirtIO9PSocket::dataEvent
std::unique_ptr< SocketDataEvent > dataEvent
Definition: fs9p.hh:388
gem5::P9MsgHeader::len
uint32_t len
Length including header.
Definition: fs9p.hh:60
gem5::VirtIO9PBase::sendRMsg
void sendRMsg(const P9MsgHeader &header, const uint8_t *data, size_t size)
Send a 9p RPC message reply.
Definition: fs9p.cc:170
compiler.hh
gem5::VirtIODeviceBase
Base class for all VirtIO-based devices.
Definition: base.hh:587
gem5::VirtIO9PBase::VirtIO9PBase
VirtIO9PBase(const Params &params)
Definition: fs9p.cc:121
gem5::P9MsgHeader::type
P9MsgType type
Message type.
Definition: fs9p.hh:62
gem5::p9toh
T p9toh(T v)
Convert p9 byte order (LE) to host byte order.
Definition: fs9p.hh:69
gem5::VirtIO9PSocket::SocketDataEvent
Definition: fs9p.hh:371
gem5::VirtIO9PSocket::startup
void startup()
startup() is the final initialization call before simulation.
Definition: fs9p.cc:485
gem5::VirtIO9PDiod::Params
VirtIO9PDiodParams Params
Definition: fs9p.hh:300
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::VirtIO9PProxy::Params
VirtIO9PProxyParams Params
Definition: fs9p.hh:221
gem5::VirtIO9PDiod::~VirtIO9PDiod
virtual ~VirtIO9PDiod()
Definition: fs9p.cc:327
gem5::VirtIO9PDiod::fd_from_diod
int fd_from_diod
fd for data pipe coming from diod (read end)
Definition: fs9p.hh:335
gem5::VirtIO9PProxy::~VirtIO9PProxy
virtual ~VirtIO9PProxy()
Definition: fs9p.cc:223
gem5::VirtIO9PDiod::DiodDataEvent::parent
VirtIO9PDiod & parent
Definition: fs9p.hh:329
gem5::VirtIO9PDiod::DiodDataEvent::process
void process(int revent)
Definition: fs9p.cc:429
gem5::VirtIO9PDiod::terminateDiod
void terminateDiod()
Kill the diod child process at the end of the simulation.
Definition: fs9p.cc:435
gem5::VirtIODeviceBase::FeatureBits
uint32_t FeatureBits
Definition: base.hh:591
gem5::VirtIO9PBase::readConfig
void readConfig(PacketPtr pkt, Addr cfgOffset)
Read from the configuration space of a device.
Definition: fs9p.cc:141
gem5::VirtIO9PBase::Config::len
uint16_t len
Definition: fs9p.hh:130
gem5::htop9
T htop9(T v)
Convert host byte order to p9 byte order (LE)
Definition: fs9p.hh:73
gem5::VirtIO9PBase::FSQueue
Virtqueue for 9p requests.
Definition: fs9p.hh:152
gem5::VegaISA::v
Bitfield< 0 > v
Definition: pagetable.hh:65
gem5::VirtIO9PProxy::recvTMsg
void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size) override
Handle incoming 9p RPC message.
Definition: fs9p.cc:256
gem5::VirtIO9PBase::Config
VirtIO 9p configuration structure.
Definition: fs9p.hh:128
gem5::VirtIO9PSocket::read
ssize_t read(uint8_t *data, size_t len)
Read data from the server behind the proxy.
Definition: fs9p.cc:536
gem5::VirtIO9PDiod::VirtIO9PDiod
VirtIO9PDiod(const Params &params)
Definition: fs9p.cc:319
gem5::VirtDescriptor
VirtIO descriptor (chain) wrapper.
Definition: base.hh:117
gem5::VirtIO9PDiod
VirtIO 9p proxy that communicates with the diod 9p server using pipes.
Definition: fs9p.hh:297
gem5::VirtIO9PSocket::Params
VirtIO9PSocketParams Params
Definition: fs9p.hh:352
gem5::VirtIO9PDiod::write
ssize_t write(const uint8_t *data, size_t len)
Write data to the server behind the proxy.
Definition: fs9p.cc:421
gem5::htole
T htole(T value)
Definition: byteswap.hh:172
gem5::VirtIO9PBase::dumpMsg
void dumpMsg(const P9MsgHeader &header, const uint8_t *data, size_t size)
Dump a 9p RPC message on the debug output.
Definition: fs9p.cc:198
gem5::VirtIO9PSocket::connectSocket
void connectSocket()
Try to resolve the server name and connect to the 9p server.
Definition: fs9p.cc:493
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::VirtIO9PProxy::VirtIO9PProxy
VirtIO9PProxy(const Params &params)
Definition: fs9p.cc:218
gem5::VirtIO9PDiod::startDiod
void startDiod()
Start diod and setup the communication pipes.
Definition: fs9p.cc:340
gem5::VirtIO9PBase::FSQueue::name
std::string name() const
Definition: fs9p.hh:162
gem5::VirtIO9PProxy::write
virtual ssize_t write(const uint8_t *data, size_t len)=0
Write data to the server behind the proxy.
gem5::VirtIO9PSocket::SocketDataEvent::process
void process(int revent)
Definition: fs9p.cc:557
gem5::VirtIO9PSocket::write
ssize_t write(const uint8_t *data, size_t len)
Write data to the server behind the proxy.
Definition: fs9p.cc:549
gem5::VirtIO9PProxy
VirtIO 9p proxy base class.
Definition: fs9p.hh:218
gem5::VirtIO9PBase::FSQueue::parent
VirtIO9PBase & parent
Definition: fs9p.hh:165
gem5::VirtIO9PDiod::DiodDataEvent
Definition: fs9p.hh:318
gem5::VirtIO9PBase::config
std::unique_ptr< Config, void(*)(void *p)> config
Currently active configuration (host byte order)
Definition: fs9p.hh:135
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::VirtIO9PBase::ID_9P
static const DeviceId ID_9P
VirtIO device ID.
Definition: fs9p.hh:139
gem5::VirtIO9PProxy::serverDataReady
void serverDataReady()
Notification of pending data from server.
Definition: fs9p.cc:271
gem5::VirtIO9PDiod::diod_pid
int diod_pid
PID of diod process.
Definition: fs9p.hh:340
gem5::P9MsgHeader
Definition: fs9p.hh:57
gem5::VirtIO9PProxy::read
virtual ssize_t read(uint8_t *data, size_t len)=0
Read data from the server behind the proxy.
gem5::P9MsgHeader::tag
P9Tag tag
Message tag.
Definition: fs9p.hh:64
gem5::VirtIO9PBase::FSQueue::FSQueue
FSQueue(PortProxy &proxy, ByteOrder bo, uint16_t size, VirtIO9PBase &_parent)
Definition: fs9p.hh:155
gem5::VirtIO9PSocket::~VirtIO9PSocket
virtual ~VirtIO9PSocket()
Definition: fs9p.cc:480
gem5::VirtIO9PBase::~VirtIO9PBase
virtual ~VirtIO9PBase()
Definition: fs9p.cc:136

Generated on Thu Jul 28 2022 13:32:32 for gem5 by doxygen 1.8.17