gem5  v20.1.0.0
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/pollevent.hh"
46 #include "dev/virtio/base.hh"
47 
48 struct VirtIO9PBaseParams;
49 
50 typedef uint8_t P9MsgType;
51 typedef uint16_t P9Tag;
52 
53 struct P9MsgHeader {
55  uint32_t len;
61 
63 template <typename T> inline T
64 p9toh(T v) { return letoh(v); }
65 
67 template <typename T> inline T
68 htop9(T v) { return htole(v); }
69 
70 template <> inline P9MsgHeader
72 {
73  v.len = p9toh(v.len);
74  v.type = p9toh(v.type);
75  v.tag = p9toh(v.tag);
76  return v;
77 }
78 
79 template <> inline P9MsgHeader
81 {
82  v.len = htop9(v.len);
83  v.type = htop9(v.type);
84  v.tag = htop9(v.tag);
85  return v;
86 }
87 
108 {
109  public:
110  typedef VirtIO9PBaseParams Params;
112  virtual ~VirtIO9PBase();
113 
114  void readConfig(PacketPtr pkt, Addr cfgOffset);
115 
116  protected:
123  struct Config {
124  uint16_t len;
125  char tag[];
126  } M5_ATTR_PACKED;
127 
129  std::unique_ptr<Config> config;
130 
132  static const DeviceId ID_9P = 0x09;
133 
138  static const FeatureBits F_MOUNT_TAG = 0x01;
141  protected:
145  class FSQueue : public VirtQueue
146  {
147  public:
148  FSQueue(PortProxy &proxy, ByteOrder bo,
149  uint16_t size, VirtIO9PBase &_parent)
150  : VirtQueue(proxy, bo, size), parent(_parent) {}
151  virtual ~FSQueue() {}
152 
154 
155  std::string name() const { return parent.name() + ".queue"; }
156 
157  protected:
159  };
160 
162 
163  protected:
171  virtual void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size) = 0;
179  void sendRMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);
180 
188  void dumpMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);
189 
190  private:
200  std::map<P9Tag, VirtDescriptor *> pendingTransactions;
201 };
202 
203 struct VirtIO9PProxyParams;
204 
212 {
213  public:
214  typedef VirtIO9PProxyParams Params;
216  virtual ~VirtIO9PProxy();
217 
218  void serialize(CheckpointOut &cp) const override;
219  void unserialize(CheckpointIn &cp) override;
220 
221  protected:
222  void recvTMsg(const P9MsgHeader &header, const uint8_t *data,
223  size_t size) override;
224 
226  void serverDataReady();
227 
237  virtual ssize_t read(uint8_t *data, size_t len) = 0;
247  virtual ssize_t write(const uint8_t *data, size_t len) = 0;
248 
259  void readAll(uint8_t *data, size_t len);
270  void writeAll(const uint8_t *data, size_t len);
271 
282 };
283 
284 struct VirtIO9PDiodParams;
285 
291 {
292  public:
293  typedef VirtIO9PDiodParams Params;
295  virtual ~VirtIO9PDiod();
296 
297  void startup();
298 
299  protected:
303  void startDiod();
304 
305  ssize_t read(uint8_t *data, size_t len);
306  ssize_t write(const uint8_t *data, size_t len);
308  void terminateDiod();
309 
310  private:
311  class DiodDataEvent : public PollEvent
312  {
313  public:
314  DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
315  : PollEvent(fd, event), parent(_parent) {}
316 
317  virtual ~DiodDataEvent() {};
318 
319  void process(int revent);
320 
321  private:
323  };
324 
329 
330  std::unique_ptr<DiodDataEvent> dataEvent;
331 
333  int diod_pid;
334 };
335 
336 struct VirtIO9PSocketParams;
337 
343 {
344  public:
345  typedef VirtIO9PSocketParams Params;
347  virtual ~VirtIO9PSocket();
348 
349  void startup();
350 
351  protected:
355  void connectSocket();
356 
358  void socketDisconnect();
359 
360  ssize_t read(uint8_t *data, size_t len);
361  ssize_t write(const uint8_t *data, size_t len);
362 
363  private:
364  class SocketDataEvent : public PollEvent
365  {
366  public:
368  : PollEvent(fd, event), parent(_parent) {}
369 
370  virtual ~SocketDataEvent() {};
371 
372  void process(int revent);
373 
374  private:
376  };
377 
379  int fdSocket;
380 
381  std::unique_ptr<SocketDataEvent> dataEvent;
382 };
383 
384 #endif // __DEV_VIRTIO_FS9P_HH__
P9Tag
uint16_t P9Tag
Definition: fs9p.hh:51
VirtIO9PProxy::write
virtual ssize_t write(const uint8_t *data, size_t len)=0
Write data to the server behind the proxy.
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:192
VirtIO9PProxy::deviceUsed
bool deviceUsed
Bool to track if the device has been used or not.
Definition: fs9p.hh:281
VirtIO9PDiod::Params
VirtIO9PDiodParams Params
Definition: fs9p.hh:293
VirtQueue
Base wrapper around a virtqueue.
Definition: base.hh:291
VirtIO9PSocket::dataEvent
std::unique_ptr< SocketDataEvent > dataEvent
Definition: fs9p.hh:381
VirtIO9PBase::VirtIO9PBase
VirtIO9PBase(Params *params)
Definition: fs9p.cc:115
VirtIO9PProxy::recvTMsg
void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size) override
Handle incoming 9p RPC message.
Definition: fs9p.cc:250
data
const char data[]
Definition: circlebuf.test.cc:42
VirtIO9PBase::readConfig
void readConfig(PacketPtr pkt, Addr cfgOffset)
Read from the configuration space of a device.
Definition: fs9p.cc:135
VirtIO9PProxy::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fs9p.cc:236
VirtIO9PSocket::read
ssize_t read(uint8_t *data, size_t len)
Read data from the server behind the proxy.
Definition: fs9p.cc:547
VirtIO9PProxy::serverDataReady
void serverDataReady()
Notification of pending data from server.
Definition: fs9p.cc:265
VirtIO9PSocket::SocketDataEvent::process
void process(int revent)
Definition: fs9p.cc:568
htole
T htole(T value)
Definition: byteswap.hh:140
ArmISA::fd
Bitfield< 14, 12 > fd
Definition: types.hh:159
VirtIO9PBase::FSQueue::~FSQueue
virtual ~FSQueue()
Definition: fs9p.hh:151
VirtIO9PSocket::Params
VirtIO9PSocketParams Params
Definition: fs9p.hh:345
VirtIODeviceBase
Base class for all VirtIO-based devices.
Definition: base.hh:558
VirtIO9PProxy::readAll
void readAll(uint8_t *data, size_t len)
Convenience function that reads exactly len bytes.
Definition: fs9p.cc:282
PowerISA::bo
Bitfield< 25, 21 > bo
Definition: types.hh:62
VirtIO9PBase::FSQueue::parent
VirtIO9PBase & parent
Definition: fs9p.hh:158
header
output header
Definition: nop.cc:36
VirtIO9PDiod::fd_to_diod
int fd_to_diod
fd for data pipe going to diod (write end)
Definition: fs9p.hh:326
VirtIO9PDiod::VirtIO9PDiod
VirtIO9PDiod(Params *params)
Definition: fs9p.cc:313
VirtIODeviceBase::DeviceId
uint16_t DeviceId
Device Type (sometimes known as subsystem ID)
Definition: base.hh:570
VirtIO9PDiod
VirtIO 9p proxy that communicates with the diod 9p server using pipes.
Definition: fs9p.hh:290
VirtIO9PDiod::fd_from_diod
int fd_from_diod
fd for data pipe coming from diod (read end)
Definition: fs9p.hh:328
VirtIO9PDiod::DiodDataEvent::process
void process(int revent)
Definition: fs9p.cc:432
base.hh
VirtIO9PBase::pendingTransactions
std::map< P9Tag, VirtDescriptor * > pendingTransactions
Map between 9p transaction tags and descriptors where they appeared.
Definition: fs9p.hh:200
VirtIO9PSocket::VirtIO9PSocket
VirtIO9PSocket(Params *params)
Definition: fs9p.cc:486
htop9
T htop9(T v)
Convert host byte order to p9 byte order (LE)
Definition: fs9p.hh:68
letoh
T letoh(T value)
Definition: byteswap.hh:141
VirtIO9PSocket::~VirtIO9PSocket
virtual ~VirtIO9PSocket()
Definition: fs9p.cc:491
VirtIO9PDiod::terminateDiod
void terminateDiod()
Kill the diod child process at the end of the simulation.
Definition: fs9p.cc:438
cp
Definition: cprintf.cc:40
VirtIO9PSocket::SocketDataEvent::SocketDataEvent
SocketDataEvent(VirtIO9PSocket &_parent, int fd, int event)
Definition: fs9p.hh:367
P9MsgHeader::type
P9MsgType type
Message type.
Definition: fs9p.hh:57
VirtIO9PBase::~VirtIO9PBase
virtual ~VirtIO9PBase()
Definition: fs9p.cc:130
VirtIO9PProxy::VirtIO9PProxy
VirtIO9PProxy(Params *params)
Definition: fs9p.cc:212
VirtIO9PDiod::dataEvent
std::unique_ptr< DiodDataEvent > dataEvent
Definition: fs9p.hh:330
VirtIO9PProxy::read
virtual ssize_t read(uint8_t *data, size_t len)=0
Read data from the server behind the proxy.
VirtIO9PDiod::startDiod
void startDiod()
Start diod and setup the communication pipes.
Definition: fs9p.cc:334
VirtIO9PSocket::write
ssize_t write(const uint8_t *data, size_t len)
Write data to the server behind the proxy.
Definition: fs9p.cc:560
VirtIO9PDiod::DiodDataEvent
Definition: fs9p.hh:311
VirtIO9PSocket::startup
void startup()
startup() is the final initialization call before simulation.
Definition: fs9p.cc:496
MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:297
pollevent.hh
VirtIO9PProxy::writeAll
void writeAll(const uint8_t *data, size_t len)
Convenience function that writes exactly len bytes.
Definition: fs9p.cc:297
VirtIO9PSocket::fdSocket
int fdSocket
Socket connected to the 9p server.
Definition: fs9p.hh:379
VirtIO9PBase::M5_ATTR_PACKED
struct VirtIO9PBase::Config M5_ATTR_PACKED
VirtIODeviceBase::FeatureBits
uint32_t FeatureBits
Definition: base.hh:562
VirtIO9PBase::Params
VirtIO9PBaseParams Params
Definition: fs9p.hh:110
VirtIO9PBase::queue
FSQueue queue
Definition: fs9p.hh:161
P9MsgHeader
Definition: fs9p.hh:53
VirtIO9PProxy::~VirtIO9PProxy
virtual ~VirtIO9PProxy()
Definition: fs9p.cc:217
VirtIO9PBase
This class implements a VirtIO transport layer for the 9p network file system.
Definition: fs9p.hh:107
VirtIO9PBase::FSQueue::name
std::string name() const
Definition: fs9p.hh:155
VirtIO9PBase::sendRMsg
void sendRMsg(const P9MsgHeader &header, const uint8_t *data, size_t size)
Send a 9p RPC message reply.
Definition: fs9p.cc:164
P9MsgHeader::tag
P9Tag tag
Message tag.
Definition: fs9p.hh:59
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
SimObject::params
const Params * params() const
Definition: sim_object.hh:119
p9toh
T p9toh(T v)
Convert p9 byte order (LE) to host byte order.
Definition: fs9p.hh:64
P9MsgHeader::len
uint32_t len
Length including header.
Definition: fs9p.hh:55
VirtIO9PBase::Config::tag
char tag[]
Definition: fs9p.hh:125
VirtIO9PSocket::SocketDataEvent::~SocketDataEvent
virtual ~SocketDataEvent()
Definition: fs9p.hh:370
VirtIO9PBase::FSQueue::FSQueue
FSQueue(PortProxy &proxy, ByteOrder bo, uint16_t size, VirtIO9PBase &_parent)
Definition: fs9p.hh:148
VirtIO9PBase::FSQueue::onNotifyDescriptor
void onNotifyDescriptor(VirtDescriptor *desc)
Notify queue of pending incoming descriptor.
Definition: fs9p.cc:141
VirtIO9PDiod::DiodDataEvent::parent
VirtIO9PDiod & parent
Definition: fs9p.hh:322
VirtIO9PBase::FSQueue
Virtqueue for 9p requests.
Definition: fs9p.hh:145
VirtIO9PProxy
VirtIO 9p proxy base class.
Definition: fs9p.hh:211
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
VirtIO9PSocket::socketDisconnect
void socketDisconnect()
9p server disconnect notification
Definition: fs9p.cc:541
PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:80
VirtIO9PDiod::DiodDataEvent::DiodDataEvent
DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
Definition: fs9p.hh:314
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
M5_ATTR_PACKED
struct P9MsgHeader M5_ATTR_PACKED
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
VirtIO9PDiod::DiodDataEvent::~DiodDataEvent
virtual ~DiodDataEvent()
Definition: fs9p.hh:317
VirtIO9PDiod::diod_pid
int diod_pid
PID of diod process.
Definition: fs9p.hh:333
VirtIO9PSocket
VirtIO 9p proxy that communicates with a 9p server over tcp sockets.
Definition: fs9p.hh:342
VirtIO9PBase::recvTMsg
virtual void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size)=0
Handle incoming 9p RPC message.
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
PollEvent
Definition: pollevent.hh:41
P9MsgType
uint8_t P9MsgType
Definition: fs9p.hh:48
VirtIO9PProxy::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fs9p.cc:223
VirtIO9PSocket::SocketDataEvent::parent
VirtIO9PSocket & parent
Definition: fs9p.hh:375
VirtIO9PDiod::write
ssize_t write(const uint8_t *data, size_t len)
Write data to the server behind the proxy.
Definition: fs9p.cc:424
VirtIO9PSocket::SocketDataEvent
Definition: fs9p.hh:364
CheckpointIn
Definition: serialize.hh:67
VirtIO9PDiod::startup
void startup()
startup() is the final initialization call before simulation.
Definition: fs9p.cc:326
VirtIO9PDiod::~VirtIO9PDiod
virtual ~VirtIO9PDiod()
Definition: fs9p.cc:321
VirtIO9PBase::Config
VirtIO 9p configuration structure.
Definition: fs9p.hh:123
VirtIO9PSocket::connectSocket
void connectSocket()
Try to resolve the server name and connect to the 9p server.
Definition: fs9p.cc:504
ArmISA::v
Bitfield< 28 > v
Definition: miscregs_types.hh:51
VirtIO9PBase::F_MOUNT_TAG
static const FeatureBits F_MOUNT_TAG
Device provides a name of the resource in its configuration.
Definition: fs9p.hh:138
VirtIO9PDiod::read
ssize_t read(uint8_t *data, size_t len)
Read data from the server behind the proxy.
Definition: fs9p.cc:416
VirtIO9PBase::config
std::unique_ptr< Config > config
Currently active configuration (host byte order)
Definition: fs9p.hh:129
VirtIO9PBase::Config::len
uint16_t len
Definition: fs9p.hh:124
VirtDescriptor
VirtIO descriptor (chain) wrapper.
Definition: base.hh:106
VirtIO9PProxy::Params
VirtIO9PProxyParams Params
Definition: fs9p.hh:214
VirtIO9PBase::ID_9P
static const DeviceId ID_9P
VirtIO device ID.
Definition: fs9p.hh:132

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