gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
49namespace gem5
50{
51
52struct VirtIO9PBaseParams;
53
54typedef uint8_t P9MsgType;
55typedef uint16_t P9Tag;
56
66
68template <typename T> inline T
69p9toh(T v) { return letoh(v); }
70
72template <typename T> inline T
73htop9(T v) { return htole(v); }
74
75template <> 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
84template <> 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
210struct VirtIO9PProxyParams;
211
219{
220 public:
221 typedef VirtIO9PProxyParams 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
291struct 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:
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
341};
342
343struct VirtIO9PSocketParams;
344
350{
351 public:
352 typedef VirtIO9PSocketParams 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:
372 {
373 public:
375 : PollEvent(fd, event), parent(_parent) {}
376
377 virtual ~SocketDataEvent() {};
378
379 void process(int revent);
380
381 private:
383 };
384
387
388 std::unique_ptr<SocketDataEvent> dataEvent;
389};
390
391} // namespace gem5
392
393#endif // __DEV_VIRTIO_FS9P_HH__
const char data[]
virtual std::string name() const
Definition named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition port_proxy.hh:87
VirtIO descriptor (chain) wrapper.
Definition base.hh:118
Virtqueue for 9p requests.
Definition fs9p.hh:153
VirtIO9PBase & parent
Definition fs9p.hh:165
void onNotifyDescriptor(VirtDescriptor *desc)
Notify queue of pending incoming descriptor.
Definition fs9p.cc:147
std::string name() const
Definition fs9p.hh:162
FSQueue(PortProxy &proxy, ByteOrder bo, uint16_t size, VirtIO9PBase &_parent)
Definition fs9p.hh:155
This class implements a VirtIO transport layer for the 9p network file system.
Definition fs9p.hh:113
VirtIO9PBase(const Params &params)
Definition fs9p.cc:121
FSQueue queue
Definition fs9p.hh:168
void sendRMsg(const P9MsgHeader &header, const uint8_t *data, size_t size)
Send a 9p RPC message reply.
Definition fs9p.cc:170
virtual void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size)=0
Handle incoming 9p RPC message.
std::unique_ptr< Config, void(*)(void *p)> config
Currently active configuration (host byte order)
Definition fs9p.hh:135
virtual ~VirtIO9PBase()
Definition fs9p.cc:136
void readConfig(PacketPtr pkt, Addr cfgOffset)
Read from the configuration space of a device.
Definition fs9p.cc:141
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
std::map< P9Tag, VirtDescriptor * > pendingTransactions
Map between 9p transaction tags and descriptors where they appeared.
Definition fs9p.hh:207
static const DeviceId ID_9P
VirtIO device ID.
Definition fs9p.hh:139
VirtIO9PBaseParams Params
Definition fs9p.hh:115
static const FeatureBits F_MOUNT_TAG
Device provides a name of the resource in its configuration.
Definition fs9p.hh:145
DiodDataEvent(VirtIO9PDiod &_parent, int fd, int event)
Definition fs9p.hh:321
VirtIO 9p proxy that communicates with the diod 9p server using pipes.
Definition fs9p.hh:298
void startDiod()
Start diod and setup the communication pipes.
Definition fs9p.cc:340
void startup()
startup() is the final initialization call before simulation.
Definition fs9p.cc:332
int fd_from_diod
fd for data pipe coming from diod (read end)
Definition fs9p.hh:335
int diod_pid
PID of diod process.
Definition fs9p.hh:340
ssize_t read(uint8_t *data, size_t len)
Read data from the server behind the proxy.
Definition fs9p.cc:413
VirtIO9PDiod(const Params &params)
Definition fs9p.cc:319
virtual ~VirtIO9PDiod()
Definition fs9p.cc:327
ssize_t write(const uint8_t *data, size_t len)
Write data to the server behind the proxy.
Definition fs9p.cc:421
VirtIO9PDiodParams Params
Definition fs9p.hh:300
int fd_to_diod
fd for data pipe going to diod (write end)
Definition fs9p.hh:333
void terminateDiod()
Kill the diod child process at the end of the simulation.
Definition fs9p.cc:435
std::unique_ptr< DiodDataEvent > dataEvent
Definition fs9p.hh:337
VirtIO 9p proxy base class.
Definition fs9p.hh:219
virtual ssize_t read(uint8_t *data, size_t len)=0
Read data from the server behind the proxy.
virtual ssize_t write(const uint8_t *data, size_t len)=0
Write data to the server behind the proxy.
void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size) override
Handle incoming 9p RPC message.
Definition fs9p.cc:256
void writeAll(const uint8_t *data, size_t len)
Convenience function that writes exactly len bytes.
Definition fs9p.cc:303
void readAll(uint8_t *data, size_t len)
Convenience function that reads exactly len bytes.
Definition fs9p.cc:288
bool deviceUsed
Bool to track if the device has been used or not.
Definition fs9p.hh:288
VirtIO9PProxyParams Params
Definition fs9p.hh:221
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition fs9p.cc:242
VirtIO9PProxy(const Params &params)
Definition fs9p.cc:218
virtual ~VirtIO9PProxy()
Definition fs9p.cc:223
void serverDataReady()
Notification of pending data from server.
Definition fs9p.cc:271
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition fs9p.cc:229
SocketDataEvent(VirtIO9PSocket &_parent, int fd, int event)
Definition fs9p.hh:374
VirtIO 9p proxy that communicates with a 9p server over tcp sockets.
Definition fs9p.hh:350
virtual ~VirtIO9PSocket()
Definition fs9p.cc:480
std::unique_ptr< SocketDataEvent > dataEvent
Definition fs9p.hh:388
ssize_t read(uint8_t *data, size_t len)
Read data from the server behind the proxy.
Definition fs9p.cc:536
VirtIO9PSocketParams Params
Definition fs9p.hh:352
void startup()
startup() is the final initialization call before simulation.
Definition fs9p.cc:485
void socketDisconnect()
9p server disconnect notification
Definition fs9p.cc:530
int fdSocket
Socket connected to the 9p server.
Definition fs9p.hh:386
VirtIO9PSocket(const Params &params)
Definition fs9p.cc:475
ssize_t write(const uint8_t *data, size_t len)
Write data to the server behind the proxy.
Definition fs9p.cc:549
void connectSocket()
Try to resolve the server name and connect to the 9p server.
Definition fs9p.cc:493
Base class for all VirtIO-based devices.
Definition base.hh:588
uint32_t FeatureBits
Definition base.hh:591
uint16_t DeviceId
Device Type (sometimes known as subsystem ID)
Definition base.hh:599
Base wrapper around a virtqueue.
Definition base.hh:303
const Params & params() const
Bitfield< 28 > v
Definition misc_types.hh:54
Bitfield< 14, 12 > fd
Definition types.hh:150
Bitfield< 18, 16 > len
Bitfield< 10, 5 > event
Bitfield< 0 > p
Bitfield< 25, 21 > bo
Definition types.hh:82
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
T letoh(T value)
Definition byteswap.hh:173
uint16_t P9Tag
Definition fs9p.hh:55
T htop9(T v)
Convert host byte order to p9 byte order (LE)
Definition fs9p.hh:73
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint8_t P9MsgType
Definition fs9p.hh:54
T p9toh(T v)
Convert p9 byte order (LE) to host byte order.
Definition fs9p.hh:69
T htole(T value)
Definition byteswap.hh:172
output header
Definition nop.cc:36
PM4 packets.
P9Tag tag
Message tag.
Definition fs9p.hh:64
P9MsgType type
Message type.
Definition fs9p.hh:62
uint32_t len
Length including header.
Definition fs9p.hh:60
VirtIO 9p configuration structure.
Definition fs9p.hh:129

Generated on Tue Jun 18 2024 16:24:04 for gem5 by doxygen 1.11.0