gem5  v21.1.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 
57 struct GEM5_PACKED P9MsgHeader
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:
128  struct GEM5_PACKED Config
129  {
130  uint16_t len;
131  char tag[];
132  };
133 
135  std::unique_ptr<Config> config;
136 
138  static const DeviceId ID_9P = 0x09;
139 
144  static const FeatureBits F_MOUNT_TAG = 0x01;
147  protected:
151  class FSQueue : public VirtQueue
152  {
153  public:
154  FSQueue(PortProxy &proxy, ByteOrder bo,
155  uint16_t size, VirtIO9PBase &_parent)
156  : VirtQueue(proxy, bo, size), parent(_parent) {}
157  virtual ~FSQueue() {}
158 
160 
161  std::string name() const { return parent.name() + ".queue"; }
162 
163  protected:
165  };
166 
168 
169  protected:
177  virtual void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size) = 0;
185  void sendRMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);
186 
194  void dumpMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);
195 
196  private:
206  std::map<P9Tag, VirtDescriptor *> pendingTransactions;
207 };
208 
209 struct VirtIO9PProxyParams;
210 
218 {
219  public:
220  typedef VirtIO9PProxyParams Params;
221  VirtIO9PProxy(const Params &params);
222  virtual ~VirtIO9PProxy();
223 
224  void serialize(CheckpointOut &cp) const override;
225  void unserialize(CheckpointIn &cp) override;
226 
227  protected:
228  void recvTMsg(const P9MsgHeader &header, const uint8_t *data,
229  size_t size) override;
230 
232  void serverDataReady();
233 
243  virtual ssize_t read(uint8_t *data, size_t len) = 0;
253  virtual ssize_t write(const uint8_t *data, size_t len) = 0;
254 
265  void readAll(uint8_t *data, size_t len);
276  void writeAll(const uint8_t *data, size_t len);
277 
288 };
289 
290 struct VirtIO9PDiodParams;
291 
297 {
298  public:
299  typedef VirtIO9PDiodParams Params;
300  VirtIO9PDiod(const Params &params);
301  virtual ~VirtIO9PDiod();
302 
303  void startup();
304 
305  protected:
309  void startDiod();
310 
311  ssize_t read(uint8_t *data, size_t len);
312  ssize_t write(const uint8_t *data, size_t len);
314  void terminateDiod();
315 
316  private:
317  class DiodDataEvent : public PollEvent
318  {
319  public:
320  DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
321  : PollEvent(fd, event), parent(_parent) {}
322 
323  virtual ~DiodDataEvent() {};
324 
325  void process(int revent);
326 
327  private:
329  };
330 
335 
336  std::unique_ptr<DiodDataEvent> dataEvent;
337 
339  int diod_pid;
340 };
341 
342 struct VirtIO9PSocketParams;
343 
349 {
350  public:
351  typedef VirtIO9PSocketParams Params;
352  VirtIO9PSocket(const Params &params);
353  virtual ~VirtIO9PSocket();
354 
355  void startup();
356 
357  protected:
361  void connectSocket();
362 
364  void socketDisconnect();
365 
366  ssize_t read(uint8_t *data, size_t len);
367  ssize_t write(const uint8_t *data, size_t len);
368 
369  private:
370  class SocketDataEvent : public PollEvent
371  {
372  public:
374  : PollEvent(fd, event), parent(_parent) {}
375 
376  virtual ~SocketDataEvent() {};
377 
378  void process(int revent);
379 
380  private:
382  };
383 
385  int fdSocket;
386 
387  std::unique_ptr<SocketDataEvent> dataEvent;
388 };
389 
390 } // namespace gem5
391 
392 #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:373
gem5::VirtIO9PDiod::dataEvent
std::unique_ptr< DiodDataEvent > dataEvent
Definition: fs9p.hh:336
gem5::VirtIO9PBase::F_MOUNT_TAG
static const FeatureBits F_MOUNT_TAG
Device provides a name of the resource in its configuration.
Definition: fs9p.hh:144
gem5::VirtIO9PSocket::fdSocket
int fdSocket
Socket connected to the 9p server.
Definition: fs9p.hh:385
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::ArmISA::len
Bitfield< 18, 16 > len
Definition: misc_types.hh:444
gem5::VirtIO9PBase::pendingTransactions
std::map< P9Tag, VirtDescriptor * > pendingTransactions
Map between 9p transaction tags and descriptors where they appeared.
Definition: fs9p.hh:206
gem5::VirtIO9PDiod::DiodDataEvent::DiodDataEvent
DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
Definition: fs9p.hh:320
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::VirtIO9PBase::queue
FSQueue queue
Definition: fs9p.hh:167
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:381
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:287
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:348
gem5::VirtIO9PSocket::SocketDataEvent::~SocketDataEvent
virtual ~SocketDataEvent()
Definition: fs9p.hh:376
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
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:323
gem5::VirtIO9PDiod::fd_to_diod
int fd_to_diod
fd for data pipe going to diod (write end)
Definition: fs9p.hh:332
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::PowerISA::bo
Bitfield< 25, 21 > bo
Definition: types.hh:82
gem5::P9Tag
uint16_t P9Tag
Definition: fs9p.hh:55
pollevent.hh
gem5::ArmISA::v
Bitfield< 28 > v
Definition: misc_types.hh:54
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:157
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:387
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:370
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:299
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:220
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:334
gem5::VirtIO9PProxy::~VirtIO9PProxy
virtual ~VirtIO9PProxy()
Definition: fs9p.cc:223
gem5::VirtIO9PDiod::DiodDataEvent::parent
VirtIO9PDiod & parent
Definition: fs9p.hh:328
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:151
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::VirtIO9PBase::config
std::unique_ptr< Config > config
Currently active configuration (host byte order)
Definition: fs9p.hh:135
gem5::VirtIO9PDiod
VirtIO 9p proxy that communicates with the diod 9p server using pipes.
Definition: fs9p.hh:296
gem5::VirtIO9PSocket::Params
VirtIO9PSocketParams Params
Definition: fs9p.hh:351
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:161
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:217
gem5::VirtIO9PBase::FSQueue::parent
VirtIO9PBase & parent
Definition: fs9p.hh:164
gem5::VirtIO9PDiod::DiodDataEvent
Definition: fs9p.hh:317
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::VirtIO9PBase::ID_9P
static const DeviceId ID_9P
VirtIO device ID.
Definition: fs9p.hh:138
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:339
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:154
gem5::VirtIO9PSocket::~VirtIO9PSocket
virtual ~VirtIO9PSocket()
Definition: fs9p.cc:480
gem5::VirtIO9PBase::~VirtIO9PBase
virtual ~VirtIO9PBase()
Definition: fs9p.cc:136

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