gem5  v22.0.0.2
fw_cfg.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2022 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __DEV_QEMU_FW_CFG_HH__
29 #define __DEV_QEMU_FW_CFG_HH__
30 
31 #include <cstdint>
32 #include <map>
33 #include <string>
34 #include <type_traits>
35 #include <vector>
36 
38 #include "base/types.hh"
39 #include "dev/io_device.hh"
40 #include "params/QemuFwCfg.hh"
41 #include "params/QemuFwCfgIo.hh"
42 #include "params/QemuFwCfgItem.hh"
43 #include "params/QemuFwCfgItemBytes.hh"
44 #include "params/QemuFwCfgItemFile.hh"
45 #include "params/QemuFwCfgItemString.hh"
46 #include "params/QemuFwCfgMmio.hh"
47 
48 namespace gem5
49 {
50 
51 namespace qemu
52 {
53 
54 /*
55  * Items which can be reported by the firmware config device.
56  */
57 
58 class FwCfgItem
59 {
60  protected:
61  uint16_t _index;
62  const std::string _path;
64 
65  FwCfgItem(const std::string &new_path, bool arch_specific,
66  uint16_t new_index=0) :
67  _index(new_index), _path(new_path), _archSpecific(arch_specific)
68  {}
69 
70  public:
71  uint16_t index() const { return _index; }
72  void index(uint16_t new_index) { _index = new_index; }
73 
74  const std::string &path() const { return _path; }
75  bool archSpecific() const { return _archSpecific; }
76 
77  virtual uint64_t length() const = 0;
78 
79  virtual void read(void *buf, uint64_t offset, uint32_t to_read) = 0;
80 };
81 
82 // Read only items with precomputed data.
83 class FwCfgItemFixed : public FwCfgItem
84 {
85  protected:
86  virtual const void *bytes() const = 0;
87 
88  public:
90 
91  void read(void *buf, uint64_t offset, uint32_t to_read) override;
92 };
93 
94 // An item who's value comes from a file.
96 {
97  private:
99 
100  public:
101  FwCfgItemFile(const std::string &new_path, bool arch_specific,
102  const std::string path, uint16_t new_index=0) :
103  FwCfgItemFixed(new_path, arch_specific, new_index), data(path)
104  {}
105 
106  FwCfgItemFile(const QemuFwCfgItemFileParams &p) :
107  FwCfgItemFile(p.path, p.arch_specific, p.file, p.index)
108  {}
109 
110  const void *bytes() const override { return data.data(); }
111  uint64_t length() const override { return data.len(); }
112 };
113 
114 // An item who's value comes from a string.
116 {
117  private:
118  std::string str;
119 
120  public:
121  FwCfgItemString(const std::string &new_path, bool arch_specific,
122  const std::string _str, uint16_t new_index=0) :
123  FwCfgItemFixed(new_path, arch_specific, new_index), str(_str)
124  {}
125 
126  FwCfgItemString(const QemuFwCfgItemStringParams &p) :
127  FwCfgItemString(p.path, p.arch_specific, p.string, p.index)
128  {}
129 
130  const void *bytes() const override { return (void *)str.data(); }
131  uint64_t
132  length() const override
133  {
134  return sizeof(std::string::value_type) * str.length();
135  }
136 };
137 
138 // An item who's value comes from an array of bytes.
140 {
141  private:
143 
144  public:
145  FwCfgItemBytes(const std::string &new_path, bool arch_specific,
146  const std::vector<uint8_t> &_data, uint16_t new_index=0) :
147  FwCfgItemFixed(new_path, arch_specific, new_index), data(_data)
148  {}
149 
150  FwCfgItemBytes(const QemuFwCfgItemBytesParams &p) :
151  FwCfgItemBytes(p.path, p.arch_specific, p.data, p.index)
152  {}
153 
154  const void *bytes() const override { return (void *)data.data(); }
155  uint64_t length() const override { return data.size(); }
156 };
157 
158 /*
159  * Base and template classes for creating SimObject wrappers for item types.
160  */
161 
163 {
164  public:
165  PARAMS(QemuFwCfgItem);
167 
168  virtual FwCfgItem &item() = 0;
169 };
170 
171 template <class ItemType>
173 {
174  private:
175  ItemType _item;
176 
177  public:
178  template <class PType, class = typename std::enable_if_t<
179  std::is_base_of_v<SimObjectParams, PType>>>
181 
182  FwCfgItem &item() override { return _item; }
183 };
184 
185 /*
186  * The actual firmware config device itself.
187  */
188 
189 // The base class.
190 class FwCfg : public PioDevice
191 {
192  private:
193  std::map<std::string, uint16_t> names;
194  std::map<uint16_t, FwCfgItem *> numbers;
195 
196  uint32_t nextGenericIndex = 0x20;
197  static inline const uint32_t MaxGenericIndex = 0x3fff;
198 
199  uint32_t nextArchIndex = 0x8020;
200  static inline const uint32_t MaxArchIndex = 0xbfff;
201 
202  uint64_t offset = 0;
203  FwCfgItem *current = nullptr;
204 
205  class Directory : public FwCfgItemFixed
206  {
207  private:
209 
210  public:
211  Directory();
212 
213  void update(const std::map<std::string, uint16_t> &names,
214  const std::map<uint16_t, FwCfgItem *> &numbers);
215 
216  const void *bytes() const override { return (void *)data.data(); }
217  uint64_t length() const override { return data.size(); }
218  };
219 
223 
224  void addItem(FwCfgItem *item);
225 
226  protected:
228 
229  void select(uint16_t key);
230 
231  public:
232  PARAMS(QemuFwCfg);
233  FwCfg(const Params &p, const AddrRangeList &addr_ranges);
234 
235  AddrRangeList getAddrRanges() const override { return addrRanges; }
236 
237  void readItem(void *buf, uint32_t length);
238 };
239 
240 // A version which uses IO ports.
241 class FwCfgIo : public FwCfg
242 {
243  private:
245  const Addr dataAddr;
246 
247  public:
248  PARAMS(QemuFwCfgIo);
249  FwCfgIo(const Params &p);
250 
251  Tick read(PacketPtr pkt) override;
252  Tick write(PacketPtr pkt) override;
253 };
254 
255 // A version which uses memory mapped IO.
256 class FwCfgMmio : public FwCfg
257 {
258  private:
260  const Addr dataAddr;
261  const Addr dataSize;
262 
263  public:
264  PARAMS(QemuFwCfgMmio);
265  FwCfgMmio(const Params &p);
266 
267  Tick read(PacketPtr pkt) override;
268  Tick write(PacketPtr pkt) override;
269 };
270 
271 } // namespace qemu
272 } // namespace gem5
273 
274 #endif //__DEV_QEMU_FW_CFG_HH__
gem5::qemu::FwCfgItem::archSpecific
bool archSpecific() const
Definition: fw_cfg.hh:75
gem5::qemu::FwCfgItemFile::length
uint64_t length() const override
Definition: fw_cfg.hh:111
gem5::qemu::FwCfgItemString::FwCfgItemString
FwCfgItemString(const QemuFwCfgItemStringParams &p)
Definition: fw_cfg.hh:126
gem5::qemu::FwCfgItemString
Definition: fw_cfg.hh:115
gem5::qemu::FwCfgItem::FwCfgItem
FwCfgItem(const std::string &new_path, bool arch_specific, uint16_t new_index=0)
Definition: fw_cfg.hh:65
gem5::qemu::FwCfgIo::PARAMS
PARAMS(QemuFwCfgIo)
gem5::qemu::FwCfg::id
FwCfgItemString id
Definition: fw_cfg.hh:221
gem5::qemu::FwCfgIo::selectorAddr
const Addr selectorAddr
Definition: fw_cfg.hh:244
io_device.hh
gem5::qemu::FwCfg::directory
Directory directory
Definition: fw_cfg.hh:222
gem5::qemu::FwCfgMmio::read
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: fw_cfg.cc:297
gem5::qemu::FwCfgItem::_path
const std::string _path
Definition: fw_cfg.hh:62
gem5::qemu::FwCfgIo::dataAddr
const Addr dataAddr
Definition: fw_cfg.hh:245
gem5::PioDevice
This device is the base class which all devices senstive to an address range inherit from.
Definition: io_device.hh:102
gem5::qemu::FwCfg::select
void select(uint16_t key)
Definition: fw_cfg.cc:136
gem5::qemu::FwCfgItemBytes::FwCfgItemBytes
FwCfgItemBytes(const std::string &new_path, bool arch_specific, const std::vector< uint8_t > &_data, uint16_t new_index=0)
Definition: fw_cfg.hh:145
gem5::qemu::FwCfgItemFactory::FwCfgItemFactory
FwCfgItemFactory(const PType &p)
Definition: fw_cfg.hh:180
gem5::qemu::FwCfgItemBytes::length
uint64_t length() const override
Definition: fw_cfg.hh:155
gem5::qemu::FwCfg::MaxArchIndex
static const uint32_t MaxArchIndex
Definition: fw_cfg.hh:200
gem5::qemu::FwCfg::Directory::length
uint64_t length() const override
Definition: fw_cfg.hh:217
gem5::qemu::FwCfgMmio::PARAMS
PARAMS(QemuFwCfgMmio)
gem5::qemu::FwCfgItem::length
virtual uint64_t length() const =0
std::vector< uint8_t >
gem5::qemu::FwCfgItemBytes::data
std::vector< uint8_t > data
Definition: fw_cfg.hh:142
gem5::qemu::FwCfgItemFixed::bytes
virtual const void * bytes() const =0
gem5::qemu::FwCfgItemFactory::item
FwCfgItem & item() override
Definition: fw_cfg.hh:182
image_file_data.hh
gem5::qemu::FwCfgItemFactory
Definition: fw_cfg.hh:172
gem5::PioDevice::Params
PioDeviceParams Params
Definition: io_device.hh:134
gem5::qemu::FwCfg::readItem
void readItem(void *buf, uint32_t length)
Definition: fw_cfg.cc:160
gem5::qemu::FwCfgIo
Definition: fw_cfg.hh:241
gem5::SimObject::Params
SimObjectParams Params
Definition: sim_object.hh:170
gem5::qemu::FwCfgItemString::FwCfgItemString
FwCfgItemString(const std::string &new_path, bool arch_specific, const std::string _str, uint16_t new_index=0)
Definition: fw_cfg.hh:121
gem5::qemu::FwCfg::nextArchIndex
uint32_t nextArchIndex
Definition: fw_cfg.hh:199
gem5::qemu::FwCfgItemFactory::_item
ItemType _item
Definition: fw_cfg.hh:175
gem5::qemu::FwCfg::MaxGenericIndex
static const uint32_t MaxGenericIndex
Definition: fw_cfg.hh:197
gem5::qemu::FwCfgItemFactoryBase::PARAMS
PARAMS(QemuFwCfgItem)
gem5::qemu::FwCfgItem::_index
uint16_t _index
Definition: fw_cfg.hh:61
gem5::qemu::FwCfg::PARAMS
PARAMS(QemuFwCfg)
gem5::qemu::FwCfgMmio::write
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: fw_cfg.cc:324
gem5::qemu::FwCfg::FwCfg
FwCfg(const Params &p, const AddrRangeList &addr_ranges)
Definition: fw_cfg.cc:79
gem5::qemu::FwCfg::Directory::Directory
Directory()
Definition: fw_cfg.cc:183
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::qemu::FwCfgMmio
Definition: fw_cfg.hh:256
gem5::qemu::FwCfgItem::index
uint16_t index() const
Definition: fw_cfg.hh:71
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:291
gem5::loader::ImageFileData
Definition: image_file_data.hh:45
gem5::loader::ImageFileData::data
const uint8_t * data() const
Definition: image_file_data.hh:54
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::qemu::FwCfgItemString::bytes
const void * bytes() const override
Definition: fw_cfg.hh:130
gem5::qemu::FwCfgMmio::dataSize
const Addr dataSize
Definition: fw_cfg.hh:261
gem5::qemu::FwCfgMmio::FwCfgMmio
FwCfgMmio(const Params &p)
Definition: fw_cfg.cc:289
gem5::qemu::FwCfgIo::read
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: fw_cfg.cc:235
gem5::qemu::FwCfg::getAddrRanges
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
Definition: fw_cfg.hh:235
gem5::qemu::FwCfgItemFactoryBase::FwCfgItemFactoryBase
FwCfgItemFactoryBase(const Params &p)
Definition: fw_cfg.hh:166
gem5::qemu::FwCfg::names
std::map< std::string, uint16_t > names
Definition: fw_cfg.hh:193
gem5::qemu::FwCfgItemBytes::FwCfgItemBytes
FwCfgItemBytes(const QemuFwCfgItemBytesParams &p)
Definition: fw_cfg.hh:150
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::qemu::FwCfg::Directory::bytes
const void * bytes() const override
Definition: fw_cfg.hh:216
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::loader::ImageFileData::len
size_t len() const
Definition: image_file_data.hh:55
gem5::qemu::FwCfgIo::write
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: fw_cfg.cc:262
gem5::qemu::FwCfgItemString::str
std::string str
Definition: fw_cfg.hh:118
gem5::qemu::FwCfgItemFile::FwCfgItemFile
FwCfgItemFile(const QemuFwCfgItemFileParams &p)
Definition: fw_cfg.hh:106
gem5::qemu::FwCfgItemFile
Definition: fw_cfg.hh:95
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::qemu::FwCfgItemBytes::bytes
const void * bytes() const override
Definition: fw_cfg.hh:154
gem5::qemu::FwCfg::Directory
Definition: fw_cfg.hh:205
gem5::qemu::FwCfg::current
FwCfgItem * current
Definition: fw_cfg.hh:203
gem5::qemu::FwCfgItem::index
void index(uint16_t new_index)
Definition: fw_cfg.hh:72
gem5::qemu::FwCfg
Definition: fw_cfg.hh:190
gem5::qemu::FwCfgItemFile::bytes
const void * bytes() const override
Definition: fw_cfg.hh:110
gem5::qemu::FwCfg::addrRanges
const AddrRangeList addrRanges
Definition: fw_cfg.hh:227
gem5::qemu::FwCfgMmio::selectorAddr
const Addr selectorAddr
Definition: fw_cfg.hh:259
gem5::qemu::FwCfgMmio::dataAddr
const Addr dataAddr
Definition: fw_cfg.hh:260
gem5::qemu::FwCfgItem::path
const std::string & path() const
Definition: fw_cfg.hh:74
gem5::qemu::FwCfgItemFactoryBase::item
virtual FwCfgItem & item()=0
types.hh
gem5::qemu::FwCfgItemFile::FwCfgItemFile
FwCfgItemFile(const std::string &new_path, bool arch_specific, const std::string path, uint16_t new_index=0)
Definition: fw_cfg.hh:101
gem5::qemu::FwCfg::addItem
void addItem(FwCfgItem *item)
Definition: fw_cfg.cc:116
gem5::qemu::FwCfgItemFixed::read
void read(void *buf, uint64_t offset, uint32_t to_read) override
Definition: fw_cfg.cc:50
gem5::qemu::FwCfg::Directory::data
std::vector< uint8_t > data
Definition: fw_cfg.hh:208
gem5::qemu::FwCfg::offset
uint64_t offset
Definition: fw_cfg.hh:202
gem5::qemu::FwCfgItemFactoryBase
Definition: fw_cfg.hh:162
gem5::qemu::FwCfgItemFixed
Definition: fw_cfg.hh:83
gem5::qemu::FwCfgItem
Definition: fw_cfg.hh:58
gem5::qemu::FwCfg::signature
FwCfgItemString signature
Definition: fw_cfg.hh:220
std::list< AddrRange >
gem5::qemu::FwCfgItemString::length
uint64_t length() const override
Definition: fw_cfg.hh:132
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::qemu::FwCfgItem::_archSpecific
bool _archSpecific
Definition: fw_cfg.hh:63
gem5::qemu::FwCfg::nextGenericIndex
uint32_t nextGenericIndex
Definition: fw_cfg.hh:196
gem5::qemu::FwCfg::numbers
std::map< uint16_t, FwCfgItem * > numbers
Definition: fw_cfg.hh:194
gem5::qemu::FwCfgIo::FwCfgIo
FwCfgIo(const Params &p)
Definition: fw_cfg.cc:227
gem5::qemu::FwCfgItemFile::data
const gem5::loader::ImageFileData data
Definition: fw_cfg.hh:98
gem5::qemu::FwCfgItemBytes
Definition: fw_cfg.hh:139
gem5::qemu::FwCfg::Directory::update
void update(const std::map< std::string, uint16_t > &names, const std::map< uint16_t, FwCfgItem * > &numbers)
Definition: fw_cfg.cc:188
gem5::qemu::FwCfgItem::read
virtual void read(void *buf, uint64_t offset, uint32_t to_read)=0

Generated on Thu Jul 28 2022 13:32:32 for gem5 by doxygen 1.8.17