gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Andreas Sandberg
38  */
39 
40 #ifndef __DEV_VIRTIO_FS9P_HH__
41 #define __DEV_VIRTIO_FS9P_HH__
42 
43 #include <map>
44 #include <memory>
45 #include <string>
46 
47 #include "base/pollevent.hh"
48 #include "dev/virtio/base.hh"
49 
50 struct VirtIO9PBaseParams;
51 
52 typedef uint8_t P9MsgType;
53 typedef uint16_t P9Tag;
54 
55 struct P9MsgHeader {
57  uint32_t len;
63 
65 template <typename T> inline T
66 p9toh(T v) { return letoh(v); }
67 
69 template <typename T> inline T
70 htop9(T v) { return htole(v); }
71 
72 template <> inline P9MsgHeader
74 {
75  v.len = p9toh(v.len);
76  v.type = p9toh(v.type);
77  v.tag = p9toh(v.tag);
78  return v;
79 }
80 
81 template <> inline P9MsgHeader
83 {
84  v.len = htop9(v.len);
85  v.type = htop9(v.type);
86  v.tag = htop9(v.tag);
87  return v;
88 }
89 
110 {
111  public:
112  typedef VirtIO9PBaseParams Params;
113  VirtIO9PBase(Params *params);
114  virtual ~VirtIO9PBase();
115 
116  void readConfig(PacketPtr pkt, Addr cfgOffset);
117 
118  protected:
125  struct Config {
126  uint16_t len;
127  char tag[];
128  } M5_ATTR_PACKED;
129 
131  std::unique_ptr<Config> config;
132 
134  static const DeviceId ID_9P = 0x09;
135 
140  static const FeatureBits F_MOUNT_TAG = 0x01;
143  protected:
147  class FSQueue : public VirtQueue
148  {
149  public:
151  uint16_t size, VirtIO9PBase &_parent)
152  : VirtQueue(proxy, bo, size), parent(_parent) {}
153  virtual ~FSQueue() {}
154 
155  void onNotifyDescriptor(VirtDescriptor *desc);
156 
157  std::string name() const { return parent.name() + ".queue"; }
158 
159  protected:
161  };
162 
164 
165  protected:
173  virtual void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size) = 0;
181  void sendRMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);
182 
190  void dumpMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);
191 
192  private:
202  std::map<P9Tag, VirtDescriptor *> pendingTransactions;
203 };
204 
205 struct VirtIO9PProxyParams;
206 
214 {
215  public:
216  typedef VirtIO9PProxyParams Params;
217  VirtIO9PProxy(Params *params);
218  virtual ~VirtIO9PProxy();
219 
220  void serialize(CheckpointOut &cp) const override;
221  void unserialize(CheckpointIn &cp) override;
222 
223  protected:
224  void recvTMsg(const P9MsgHeader &header, const uint8_t *data,
225  size_t size) override;
226 
228  void serverDataReady();
229 
239  virtual ssize_t read(uint8_t *data, size_t len) = 0;
249  virtual ssize_t write(const uint8_t *data, size_t len) = 0;
250 
261  void readAll(uint8_t *data, size_t len);
272  void writeAll(const uint8_t *data, size_t len);
273 
284 };
285 
286 struct VirtIO9PDiodParams;
287 
293 {
294  public:
295  typedef VirtIO9PDiodParams Params;
296  VirtIO9PDiod(Params *params);
297  virtual ~VirtIO9PDiod();
298 
299  void startup();
300 
301  protected:
305  void startDiod();
306 
307  ssize_t read(uint8_t *data, size_t len);
308  ssize_t write(const uint8_t *data, size_t len);
310  void terminateDiod();
311 
312  private:
313  class DiodDataEvent : public PollEvent
314  {
315  public:
316  DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
317  : PollEvent(fd, event), parent(_parent) {}
318 
319  virtual ~DiodDataEvent() {};
320 
321  void process(int revent);
322 
323  private:
325  };
326 
331 
332  std::unique_ptr<DiodDataEvent> dataEvent;
333 
335  int diod_pid;
336 };
337 
338 struct VirtIO9PSocketParams;
339 
345 {
346  public:
347  typedef VirtIO9PSocketParams Params;
348  VirtIO9PSocket(Params *params);
349  virtual ~VirtIO9PSocket();
350 
351  void startup();
352 
353  protected:
357  void connectSocket();
358 
360  void socketDisconnect();
361 
362  ssize_t read(uint8_t *data, size_t len);
363  ssize_t write(const uint8_t *data, size_t len);
364 
365  private:
366  class SocketDataEvent : public PollEvent
367  {
368  public:
370  : PollEvent(fd, event), parent(_parent) {}
371 
372  virtual ~SocketDataEvent() {};
373 
374  void process(int revent);
375 
376  private:
378  };
379 
381  int fdSocket;
382 
383  std::unique_ptr<SocketDataEvent> dataEvent;
384 };
385 
386 #endif // __DEV_VIRTIO_FS9P_HH__
This class implements a VirtIO transport layer for the 9p network file system.
Definition: fs9p.hh:109
Base class for all VirtIO-based devices.
Definition: base.hh:560
output header
Definition: nop.cc:39
VirtIO9PSocket & parent
Definition: fs9p.hh:377
VirtIO 9p proxy that communicates with a 9p server over tcp sockets.
Definition: fs9p.hh:344
Bitfield< 28 > v
uint16_t P9Tag
Definition: fs9p.hh:53
struct P9MsgHeader M5_ATTR_PACKED
std::unique_ptr< DiodDataEvent > dataEvent
Definition: fs9p.hh:332
VirtIO9PSocketParams Params
Definition: fs9p.hh:347
uint8_t P9MsgType
Definition: fs9p.hh:50
std::map< P9Tag, VirtDescriptor * > pendingTransactions
Map between 9p transaction tags and descriptors where they appeared.
Definition: fs9p.hh:202
T letoh(T value)
Definition: byteswap.hh:145
Definition: cprintf.cc:42
T p9toh(T v)
Convert p9 byte order (LE) to host byte order.
Definition: fs9p.hh:66
int fd_to_diod
fd for data pipe going to diod (write end)
Definition: fs9p.hh:328
VirtIO9PProxyParams Params
Definition: fs9p.hh:216
int fd_from_diod
fd for data pipe coming from diod (read end)
Definition: fs9p.hh:330
virtual ~FSQueue()
Definition: fs9p.hh:153
std::unique_ptr< SocketDataEvent > dataEvent
Definition: fs9p.hh:383
VirtIO9PBase & parent
Definition: fs9p.hh:160
T htole(T value)
Definition: byteswap.hh:144
P9Tag tag
Message tag.
Definition: fs9p.hh:61
uint32_t len
Length including header.
Definition: fs9p.hh:57
ByteOrder
Definition: types.hh:247
bool deviceUsed
Bool to track if the device has been used or not.
Definition: fs9p.hh:283
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
std::string name() const
Definition: fs9p.hh:157
VirtIO descriptor (chain) wrapper.
Definition: base.hh:108
FSQueue queue
Definition: fs9p.hh:163
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
VirtIO9PDiod & parent
Definition: fs9p.hh:324
Bitfield< 10, 5 > event
VirtIO9PBaseParams Params
Definition: fs9p.hh:112
uint16_t len
Definition: fs9p.hh:126
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:82
Bitfield< 25, 21 > bo
Definition: types.hh:64
uint16_t DeviceId
Device Type (sometimes known as subsystem ID)
Definition: base.hh:572
VirtIO9PDiodParams Params
Definition: fs9p.hh:295
T htop9(T v)
Convert host byte order to p9 byte order (LE)
Definition: fs9p.hh:70
std::ostream CheckpointOut
Definition: serialize.hh:68
VirtIO 9p configuration structure.
Definition: fs9p.hh:125
int diod_pid
PID of diod process.
Definition: fs9p.hh:335
FSQueue(PortProxy &proxy, ByteOrder bo, uint16_t size, VirtIO9PBase &_parent)
Definition: fs9p.hh:150
SocketDataEvent(VirtIO9PSocket &_parent, int fd, int event)
Definition: fs9p.hh:369
void unserialize(ThreadContext &tc, CheckpointIn &cp)
Base wrapper around a virtqueue.
Definition: base.hh:293
VirtIO 9p proxy that communicates with the diod 9p server using pipes.
Definition: fs9p.hh:292
DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
Definition: fs9p.hh:316
Bitfield< 14, 12 > fd
Definition: types.hh:160
Virtqueue for 9p requests.
Definition: fs9p.hh:147
std::unique_ptr< Config > config
Currently active configuration (host byte order)
Definition: fs9p.hh:131
P9MsgType type
Message type.
Definition: fs9p.hh:59
const char data[]
int fdSocket
Socket connected to the 9p server.
Definition: fs9p.hh:381
virtual ~DiodDataEvent()
Definition: fs9p.hh:319
uint32_t FeatureBits
Definition: base.hh:564
VirtIO 9p proxy base class.
Definition: fs9p.hh:213

Generated on Fri Feb 28 2020 16:27:01 for gem5 by doxygen 1.8.13