gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fs9p.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015 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;
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:
150  FSQueue(PortProxy &proxy, uint16_t size, VirtIO9PBase &_parent)
151  : VirtQueue(proxy, size), parent(_parent) {}
152  virtual ~FSQueue() {}
153 
155 
156  std::string name() const { return parent.name() + ".queue"; }
157 
158  protected:
160  };
161 
163 
164  protected:
172  virtual void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size) = 0;
180  void sendRMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);
181 
189  void dumpMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);
190 
191  private:
201  std::map<P9Tag, VirtDescriptor *> pendingTransactions;
202 };
203 
204 struct VirtIO9PProxyParams;
205 
213 {
214  public:
215  typedef VirtIO9PProxyParams Params;
217  virtual ~VirtIO9PProxy();
218 
219  void serialize(CheckpointOut &cp) const override;
220  void unserialize(CheckpointIn &cp) override;
221 
222  protected:
223  void recvTMsg(const P9MsgHeader &header, const uint8_t *data,
224  size_t size) override;
225 
227  void serverDataReady();
228 
238  virtual ssize_t read(uint8_t *data, size_t len) = 0;
248  virtual ssize_t write(const uint8_t *data, size_t len) = 0;
249 
260  void readAll(uint8_t *data, size_t len);
271  void writeAll(const uint8_t *data, size_t len);
272 
283 };
284 
285 struct VirtIO9PDiodParams;
286 
292 {
293  public:
294  typedef VirtIO9PDiodParams Params;
296  virtual ~VirtIO9PDiod();
297 
298  void startup();
299 
300  protected:
304  void startDiod();
305 
306  ssize_t read(uint8_t *data, size_t len);
307  ssize_t write(const uint8_t *data, size_t len);
308 
309  private:
310  class DiodDataEvent : public PollEvent
311  {
312  public:
313  DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
314  : PollEvent(fd, event), parent(_parent) {}
315 
316  virtual ~DiodDataEvent() {};
317 
318  void process(int revent);
319 
320  private:
322  };
323 
328 
329  std::unique_ptr<DiodDataEvent> dataEvent;
330 
332  int diod_pid;
333 };
334 
335 struct VirtIO9PSocketParams;
336 
342 {
343  public:
344  typedef VirtIO9PSocketParams Params;
346  virtual ~VirtIO9PSocket();
347 
348  void startup();
349 
350  protected:
354  void connectSocket();
355 
357  void socketDisconnect();
358 
359  ssize_t read(uint8_t *data, size_t len);
360  ssize_t write(const uint8_t *data, size_t len);
361 
362  private:
363  class SocketDataEvent : public PollEvent
364  {
365  public:
367  : PollEvent(fd, event), parent(_parent) {}
368 
369  virtual ~SocketDataEvent() {};
370 
371  void process(int revent);
372 
373  private:
375  };
376 
378  int fdSocket;
379 
380  std::unique_ptr<SocketDataEvent> dataEvent;
381 };
382 
383 #endif // __DEV_VIRTIO_FS9P_HH__
void startup()
startup() is the final initialization call before simulation.
Definition: fs9p.cc:319
ssize_t read(uint8_t *data, size_t len)
Read data from the server behind the proxy.
Definition: fs9p.cc:375
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:570
ssize_t read(uint8_t *data, size_t len)
Read data from the server behind the proxy.
Definition: fs9p.cc:466
std::string name() const
Definition: fs9p.hh:156
VirtIO9PSocket & parent
Definition: fs9p.hh:374
VirtIO 9p proxy that communicates with a 9p server over tcp sockets.
Definition: fs9p.hh:341
Bitfield< 28 > v
Definition: miscregs.hh:1366
virtual ~VirtIO9PProxy()
Definition: fs9p.cc:212
uint16_t P9Tag
Definition: fs9p.hh:53
struct P9MsgHeader M5_ATTR_PACKED
FSQueue(PortProxy &proxy, uint16_t size, VirtIO9PBase &_parent)
Definition: fs9p.hh:150
void socketDisconnect()
9p server disconnect notification
Definition: fs9p.cc:460
std::unique_ptr< DiodDataEvent > dataEvent
Definition: fs9p.hh:329
virtual ssize_t read(uint8_t *data, size_t len)=0
Read data from the server behind the proxy.
void process(int revent)
Definition: fs9p.cc:487
VirtIO9PSocketParams Params
Definition: fs9p.hh:344
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fs9p.cc:218
const Params * params() const
Definition: sim_object.hh:111
uint8_t P9MsgType
Definition: fs9p.hh:50
static const DeviceId ID_9P
VirtIO device ID.
Definition: fs9p.hh:134
std::map< P9Tag, VirtDescriptor * > pendingTransactions
Map between 9p transaction tags and descriptors where they appeared.
Definition: fs9p.hh:201
T letoh(T value)
Definition: byteswap.hh:152
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:325
void readConfig(PacketPtr pkt, Addr cfgOffset)
Read from the configuration space of a device.
Definition: fs9p.cc:130
void sendRMsg(const P9MsgHeader &header, const uint8_t *data, size_t size)
Send a 9p RPC message reply.
Definition: fs9p.cc:159
VirtIO9PProxyParams Params
Definition: fs9p.hh:215
virtual void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size)=0
Handle incoming 9p RPC message.
virtual ssize_t write(const uint8_t *data, size_t len)=0
Write data to the server behind the proxy.
int fd_from_diod
fd for data pipe coming from diod (read end)
Definition: fs9p.hh:327
const char data[]
Definition: circlebuf.cc:43
virtual ~FSQueue()
Definition: fs9p.hh:152
void writeAll(const uint8_t *data, size_t len)
Convenience function that writes exactly len bytes.
Definition: fs9p.cc:292
std::unique_ptr< SocketDataEvent > dataEvent
Definition: fs9p.hh:380
VirtIO9PBase & parent
Definition: fs9p.hh:159
T htole(T value)
Definition: byteswap.hh:151
virtual ~VirtIO9PSocket()
Definition: fs9p.cc:410
P9Tag tag
Message tag.
Definition: fs9p.hh:61
void startup()
startup() is the final initialization call before simulation.
Definition: fs9p.cc:415
VirtIO9PDiod(Params *params)
Definition: fs9p.cc:308
void serverDataReady()
Notification of pending data from server.
Definition: fs9p.cc:260
VirtIO9PSocket(Params *params)
Definition: fs9p.cc:405
uint32_t len
Length including header.
Definition: fs9p.hh:57
static const FeatureBits F_MOUNT_TAG
Device provides a name of the resource in its configuration.
Definition: fs9p.hh:140
void process(int revent)
Definition: fs9p.cc:391
bool deviceUsed
Bool to track if the device has been used or not.
Definition: fs9p.hh:282
void onNotifyDescriptor(VirtDescriptor *desc)
Notify queue of pending incoming descriptor.
Definition: fs9p.cc:136
VirtIO descriptor (chain) wrapper.
Definition: base.hh:136
ssize_t write(const uint8_t *data, size_t len)
Write data to the server behind the proxy.
Definition: fs9p.cc:383
FSQueue queue
Definition: fs9p.hh:162
void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size) override
Handle incoming 9p RPC message.
Definition: fs9p.cc:245
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:245
VirtIO9PDiod & parent
Definition: fs9p.hh:321
Bitfield< 10, 5 > event
virtual ~VirtIO9PDiod()
Definition: fs9p.cc:314
VirtIO9PBaseParams Params
Definition: fs9p.hh:112
uint16_t len
Definition: fs9p.hh:126
void startDiod()
Start diod and setup the communication pipes.
Definition: fs9p.cc:327
This object is a proxy for a structural port, to be used for debug accesses.
Definition: port_proxy.hh:84
virtual ~VirtIO9PBase()
Definition: fs9p.cc:125
int size()
Definition: pagetable.hh:146
virtual const std::string name() const
Definition: sim_object.hh:117
uint16_t DeviceId
Device Type (sometimes known as subsystem ID)
Definition: base.hh:582
VirtIO9PDiodParams Params
Definition: fs9p.hh:294
void readAll(uint8_t *data, size_t len)
Convenience function that reads exactly len bytes.
Definition: fs9p.cc:277
T htop9(T v)
Convert host byte order to p9 byte order (LE)
Definition: fs9p.hh:70
std::ostream CheckpointOut
Definition: serialize.hh:67
VirtIO 9p configuration structure.
Definition: fs9p.hh:125
VirtIO9PBase(Params *params)
Definition: fs9p.cc:110
Bitfield< 18, 16 > len
Definition: miscregs.hh:1626
int diod_pid
PID of diod process.
Definition: fs9p.hh:332
SocketDataEvent(VirtIO9PSocket &_parent, int fd, int event)
Definition: fs9p.hh:366
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fs9p.cc:231
void connectSocket()
Try to resolve the server name and connect to the 9p server.
Definition: fs9p.cc:423
Base wrapper around a virtqueue.
Definition: base.hh:317
void dumpMsg(const P9MsgHeader &header, const uint8_t *data, size_t size)
Dump a 9p RPC message on the debug output.
Definition: fs9p.cc:187
VirtIO 9p proxy that communicates with the diod 9p server using pipes.
Definition: fs9p.hh:291
DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
Definition: fs9p.hh:313
Bitfield< 14, 12 > fd
Definition: types.hh:155
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
VirtIO9PProxy(Params *params)
Definition: fs9p.cc:207
int fdSocket
Socket connected to the 9p server.
Definition: fs9p.hh:378
virtual ~DiodDataEvent()
Definition: fs9p.hh:316
struct VirtIO9PBase::Config M5_ATTR_PACKED
uint32_t FeatureBits
Definition: base.hh:574
VirtIO 9p proxy base class.
Definition: fs9p.hh:212
ssize_t write(const uint8_t *data, size_t len)
Write data to the server behind the proxy.
Definition: fs9p.cc:479

Generated on Fri Jun 9 2017 13:03:47 for gem5 by doxygen 1.8.6