summaryrefslogtreecommitdiff
path: root/utils/regtools/qeditor/backend.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/regtools/qeditor/backend.h')
-rw-r--r--utils/regtools/qeditor/backend.h208
1 files changed, 73 insertions, 135 deletions
diff --git a/utils/regtools/qeditor/backend.h b/utils/regtools/qeditor/backend.h
index 934c1c359b..17eeb44533 100644
--- a/utils/regtools/qeditor/backend.h
+++ b/utils/regtools/qeditor/backend.h
@@ -26,14 +26,17 @@
26#include <QMap> 26#include <QMap>
27#include <QVector> 27#include <QVector>
28#include <QMetaType> 28#include <QMetaType>
29#include <QAbstractItemModel>
29#ifdef HAVE_HWSTUB 30#ifdef HAVE_HWSTUB
30#include "hwstub.h" 31#include "hwstub.h"
31#endif 32#endif
32#include "soc_desc_v1.hpp" 33#include "soc_desc.hpp"
33 34
34/* we don't want to import the entire soc_desc except for a few selected 35/* we don't want to import the entire soc_desc except for a few selected
35 * pieces */ 36 * pieces */
36using namespace soc_desc_v1; 37using soc_desc::soc_word_t;
38using soc_desc::soc_addr_t;
39using soc_desc::soc_id_t;
37 40
38class IoBackend : public QObject 41class IoBackend : public QObject
39{ 42{
@@ -47,35 +50,20 @@ public:
47 Write, Set, Clear, Toggle 50 Write, Set, Clear, Toggle
48 }; 51 };
49 52
50 enum AccessType
51 {
52 ByName,
53 ByAddress,
54 };
55
56 /** Register naming convention: name based access are of the form:
57 * HW.dev.reg
58 * where <dev> is the device name (including index like APPUART1)
59 * and <reg> is the register name (including index like PRIORITY29) */
60 /* report whether backend is valid */ 53 /* report whether backend is valid */
61 virtual bool IsValid() = 0; 54 virtual bool IsValid() = 0;
62 /* report whether backend supports register access type */
63 virtual bool SupportAccess(AccessType type) = 0;
64 /* get SoC name */ 55 /* get SoC name */
65 virtual QString GetSocName() = 0; 56 virtual QString GetSocName() = 0;
66 /* read a register by name or address */ 57 /* read a register */
67 virtual bool ReadRegister(const QString& name, soc_word_t& value) = 0; 58 virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value, unsigned width) = 0;
68 virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value) = 0;
69 /* reload content (if it makes sense) */ 59 /* reload content (if it makes sense) */
70 virtual bool Reload() = 0; 60 virtual bool Reload() = 0;
71 /* check whether backend supports writing */ 61 /* check whether backend supports writing */
72 virtual bool IsReadOnly() = 0; 62 virtual bool IsReadOnly() = 0;
73 /* write a register by name or address 63 /* write a register by name or address
74 * NOTE: even on a read-only backend, a write is allowed be successful as long 64 * NOTE: even on a read-only backend, a write is allowed to be successful as long
75 * as commit fails */ 65 * as commit fails */
76 virtual bool WriteRegister(const QString& name, soc_word_t value, 66 virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, unsigned width,
77 WriteMode mode = Write) = 0;
78 virtual bool WriteRegister(soc_addr_t addr, soc_word_t value,
79 WriteMode mode = Write) = 0; 67 WriteMode mode = Write) = 0;
80 /* check whether backend contains uncommitted (ie cached) writes */ 68 /* check whether backend contains uncommitted (ie cached) writes */
81 virtual bool IsDirty() = 0; 69 virtual bool IsDirty() = 0;
@@ -87,23 +75,17 @@ class DummyIoBackend : public IoBackend
87{ 75{
88 Q_OBJECT 76 Q_OBJECT
89public: 77public:
90 DummyIoBackend() {} 78 DummyIoBackend();
91 79
92 virtual bool IsValid() { return false; } 80 virtual bool IsValid();
93 virtual bool SupportAccess(AccessType type) { Q_UNUSED(type); return false; } 81 virtual QString GetSocName();
94 virtual QString GetSocName() { return ""; } 82 virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value, unsigned width);
95 virtual bool ReadRegister(const QString& name, soc_word_t& value) 83 virtual bool Reload();
96 { Q_UNUSED(name); Q_UNUSED(value); return false; } 84 virtual bool IsReadOnly();
97 virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value) 85 virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, unsigned width,
98 { Q_UNUSED(addr); Q_UNUSED(value); return false; } 86 WriteMode mode);
99 virtual bool Reload() { return false; } 87 virtual bool IsDirty();
100 virtual bool IsReadOnly() { return true; } 88 virtual bool Commit();
101 virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode)
102 { Q_UNUSED(name); Q_UNUSED(value); Q_UNUSED(mode); return false; }
103 virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, WriteMode mode)
104 { Q_UNUSED(addr); Q_UNUSED(value); Q_UNUSED(mode); return false; }
105 virtual bool IsDirty() { return false; }
106 virtual bool Commit() { return false; }
107}; 89};
108 90
109/** The RAM backend doesn't have any backend storage and stores all values in 91/** The RAM backend doesn't have any backend storage and stores all values in
@@ -114,26 +96,22 @@ class RamIoBackend : public IoBackend
114public: 96public:
115 RamIoBackend(const QString& soc_name = ""); 97 RamIoBackend(const QString& soc_name = "");
116 98
117 virtual bool IsValid() { return m_soc != ""; } 99 virtual bool IsValid();
118 virtual bool SupportAccess(AccessType type) { return type == ByName; } 100 virtual QString GetSocName();
119 virtual QString GetSocName() { return m_soc; } 101 virtual void SetSocName(const QString& soc_name);
120 virtual void SetSocName(const QString& soc_name) { m_soc = soc_name; } 102 virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value, unsigned width);
121 virtual bool ReadRegister(const QString& name, soc_word_t& value); 103 virtual bool Reload();
122 virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value) 104 virtual bool IsReadOnly();
123 { Q_UNUSED(addr); Q_UNUSED(value); return false; } 105 virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, unsigned width,
124 virtual bool Reload() { return false; } 106 WriteMode mode);
125 virtual bool IsReadOnly() { return false; } 107 virtual bool IsDirty();
126 virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode); 108 virtual bool Commit();
127 virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, WriteMode mode)
128 { Q_UNUSED(addr); Q_UNUSED(value); Q_UNUSED(mode); return false; }
129 virtual bool IsDirty() { return false; }
130 virtual bool Commit() { return false; }
131 /* clear all entries of the backend */ 109 /* clear all entries of the backend */
132 virtual void DeleteAll(); 110 virtual void DeleteAll();
133 111
134protected: 112protected:
135 QString m_soc; 113 QString m_soc;
136 QMap< QString, soc_word_t > m_map; 114 QMap< soc_addr_t, soc_word_t > m_map;
137}; 115};
138 116
139/** NOTE the File backend makes a difference between writes and commits: 117/** NOTE the File backend makes a difference between writes and commits:
@@ -144,14 +122,14 @@ class FileIoBackend : public RamIoBackend
144public: 122public:
145 FileIoBackend(const QString& filename, const QString& soc_name = ""); 123 FileIoBackend(const QString& filename, const QString& soc_name = "");
146 124
147 virtual bool IsValid() { return m_valid; } 125 virtual bool IsValid();
148 virtual bool SupportAccess(AccessType type) { return type == ByName; }
149 virtual bool Reload(); 126 virtual bool Reload();
150 virtual bool IsReadOnly() { return m_readonly; } 127 virtual bool IsReadOnly();
151 virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode); 128 virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, unsigned width,
152 virtual bool IsDirty() { return m_dirty; } 129 WriteMode mode);
130 virtual bool IsDirty();
153 virtual bool Commit(); 131 virtual bool Commit();
154 QString GetFileName() { return m_filename; } 132 QString GetFileName();
155 133
156protected: 134protected:
157 QString m_filename; 135 QString m_filename;
@@ -204,20 +182,16 @@ public:
204 HWStubIoBackend(HWStubDevice *dev); 182 HWStubIoBackend(HWStubDevice *dev);
205 virtual ~HWStubIoBackend(); 183 virtual ~HWStubIoBackend();
206 184
207 virtual bool IsValid() { return m_dev->IsValid(); } 185 virtual bool IsValid();
208 virtual bool SupportAccess(AccessType type) { return type == ByAddress; }
209 virtual QString GetSocName(); 186 virtual QString GetSocName();
210 virtual bool ReadRegister(const QString& name, soc_word_t& value) 187 virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value, unsigned width);
211 { Q_UNUSED(name); Q_UNUSED(value); return false; }
212 virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value);
213 virtual bool Reload(); 188 virtual bool Reload();
214 virtual bool IsReadOnly() { return false; } 189 virtual bool IsReadOnly();
215 virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode) 190 virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, unsigned width,
216 { Q_UNUSED(name); Q_UNUSED(value); Q_UNUSED(mode); return false; } 191 WriteMode mode);
217 virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, WriteMode mode); 192 virtual bool IsDirty();
218 virtual bool IsDirty() { return false; } 193 virtual bool Commit();
219 virtual bool Commit() { return true; } 194 HWStubDevice *GetDevice();
220 HWStubDevice *GetDevice() { return m_dev; }
221 195
222protected: 196protected:
223 QString m_soc; 197 QString m_soc;
@@ -251,8 +225,6 @@ protected:
251}; 225};
252#endif 226#endif
253 227
254class SocRef;
255
256class SocFile 228class SocFile
257{ 229{
258public: 230public:
@@ -260,14 +232,14 @@ public:
260 SocFile(const QString& filename); 232 SocFile(const QString& filename);
261 bool IsValid(); 233 bool IsValid();
262 234
263 SocRef GetSocRef(); 235 soc_desc::soc_ref_t GetSocRef();
264 QString GetFilename(); 236 QString GetFilename();
265 soc_t& GetSoc() { return m_soc; } 237 soc_desc::soc_t& GetSoc() { return m_soc; }
266 238
267protected: 239protected:
268 bool m_valid; 240 bool m_valid;
269 QString m_filename; 241 QString m_filename;
270 soc_t m_soc; 242 soc_desc::soc_t m_soc;
271}; 243};
272 244
273class SocFileRef 245class SocFileRef
@@ -283,56 +255,17 @@ protected:
283 255
284Q_DECLARE_METATYPE(SocFileRef) 256Q_DECLARE_METATYPE(SocFileRef)
285 257
286class SocRef : public SocFileRef 258Q_DECLARE_METATYPE(soc_desc::instance_t::type_t)
287{ 259Q_DECLARE_METATYPE(soc_desc::range_t::type_t)
288public:
289 SocRef() {}
290 SocRef(SocFile *file):SocFileRef(file) {}
291 soc_t& GetSoc() const { return GetSocFile()->GetSoc(); }
292};
293
294Q_DECLARE_METATYPE(SocRef)
295 260
296class SocDevRef : public SocRef 261Q_DECLARE_METATYPE(soc_desc::soc_ref_t)
297{ 262Q_DECLARE_METATYPE(soc_desc::node_ref_t)
298public: 263Q_DECLARE_METATYPE(soc_desc::register_ref_t)
299 SocDevRef() {} 264Q_DECLARE_METATYPE(soc_desc::field_ref_t)
300 SocDevRef(const SocRef& soc, int dev_idx, int dev_addr_idx) 265Q_DECLARE_METATYPE(soc_desc::node_inst_t)
301 :SocRef(soc), m_dev_idx(dev_idx), m_dev_addr_idx(dev_addr_idx) {}
302 int GetDevIndex() const { return m_dev_idx; }
303 soc_dev_t& GetDev() const { return GetSoc().dev[GetDevIndex()]; }
304 int GetDevAddrIndex() const { return m_dev_addr_idx; }
305 soc_dev_addr_t& GetDevAddr() const { return GetDev().addr[GetDevAddrIndex()]; }
306protected:
307 int m_dev_idx, m_dev_addr_idx;
308};
309
310class SocRegRef : public SocDevRef
311{
312public:
313 SocRegRef() {}
314 SocRegRef(const SocDevRef& dev, int reg_idx, int reg_addr_idx)
315 :SocDevRef(dev), m_reg_idx(reg_idx), m_reg_addr_idx(reg_addr_idx) {}
316 int GetRegIndex() const { return m_reg_idx; }
317 soc_reg_t& GetReg() const { return GetDev().reg[GetRegIndex()]; }
318 int GetRegAddrIndex() const { return m_reg_addr_idx; }
319 soc_reg_addr_t& GetRegAddr() const { return GetReg().addr[GetRegAddrIndex()]; }
320protected:
321 int m_reg_idx, m_reg_addr_idx;
322};
323
324class SocFieldRef : public SocRegRef
325{
326public:
327 SocFieldRef(){}
328 SocFieldRef(const SocRegRef& reg, int field_idx)
329 :SocRegRef(reg), m_field_idx(field_idx) {}
330 int GetFieldIndex() const { return m_field_idx; }
331 soc_reg_field_t& GetField() const { return GetReg().field[GetFieldIndex()]; }
332protected:
333 int m_field_idx;
334};
335 266
267/** NOTE the Backend stores soc descriptions in a way that pointers are never
268 * invalidated */
336class Backend : public QObject 269class Backend : public QObject
337{ 270{
338 Q_OBJECT 271 Q_OBJECT
@@ -340,7 +273,7 @@ public:
340 Backend(); 273 Backend();
341 274
342 QList< SocFileRef > GetSocFileList(); 275 QList< SocFileRef > GetSocFileList();
343 QList< SocRef > GetSocList(); 276 QList< soc_desc::soc_ref_t > GetSocList();
344 bool LoadSocDesc(const QString& filename); 277 bool LoadSocDesc(const QString& filename);
345 IoBackend *CreateDummyIoBackend(); 278 IoBackend *CreateDummyIoBackend();
346 IoBackend *CreateFileIoBackend(const QString& filename); 279 IoBackend *CreateFileIoBackend(const QString& filename);
@@ -349,33 +282,38 @@ public:
349#endif 282#endif
350 283
351signals: 284signals:
352 void OnSocListChanged(); 285 void OnSocAdded(const SocFileRef& ref);
286
353private: 287private:
288 /* store them as a list so that pointers are never invalidated */
354 std::list< SocFile > m_socs; 289 std::list< SocFile > m_socs;
355}; 290};
356 291
357class BackendHelper 292class BackendHelper
358{ 293{
359public: 294public:
360 BackendHelper(IoBackend *io_backend, const SocRef& soc); 295 BackendHelper(IoBackend *io_backend, const soc_desc::soc_ref_t& soc);
361 bool ReadRegister(const QString& dev, const QString& reg, soc_word_t& v); 296 QString GetPath(const soc_desc::node_inst_t& inst);
362 bool ReadRegisterField(const QString& dev, const QString& reg, 297 soc_desc::node_inst_t ParsePath(const QString& path);
298 bool ReadRegister(const soc_desc::node_inst_t& inst, soc_word_t& v);
299 bool ReadRegisterField(const soc_desc::node_inst_t& inst,
363 const QString& field, soc_word_t& v); 300 const QString& field, soc_word_t& v);
364 bool WriteRegister(const QString& dev, const QString& reg, soc_word_t v, 301 bool WriteRegister(const soc_desc::node_inst_t& inst, soc_word_t v,
365 IoBackend::WriteMode mode = IoBackend::Write); 302 IoBackend::WriteMode mode = IoBackend::Write);
366 bool GetDevRef(const QString& dev, SocDevRef& ref); 303 bool GetRegisterAddress(const soc_desc::node_inst_t& inst, soc_addr_t& addr);
367 bool GetRegRef(const SocDevRef& dev, const QString& reg, SocRegRef& ref);
368 bool GetFieldRef(const SocRegRef& reg, const QString& field, SocFieldRef& ref);
369 bool GetRegisterAddress(const QString& dev, const QString& reg, soc_addr_t& addr);
370 /* NOTE: does not commit writes to the backend 304 /* NOTE: does not commit writes to the backend
371 * if ignore_errors is true, the dump will continue even on errors, and the 305 * if ignore_errors is true, the dump will continue even on errors, and the
372 * function will return false if one or more errors occured */ 306 * function will return false if one or more errors occured */
373 bool DumpAllRegisters(IoBackend *backend, bool ignore_errors = true); 307 bool DumpAllRegisters(IoBackend *backend, bool ignore_errors = true);
374 bool DumpAllRegisters(const QString& filename, bool ignore_errors = true); 308 bool DumpAllRegisters(const QString& filename, bool ignore_errors = true);
375 309
310protected:
311 bool DumpAllRegisters(BackendHelper *bh, const soc_desc::node_inst_t& inst,
312 bool ignore_errors);
313
376private: 314private:
377 IoBackend *m_io_backend; 315 IoBackend *m_io_backend;
378 const SocRef& m_soc; 316 const soc_desc::soc_ref_t& m_soc;
379}; 317};
380 318
381#endif /* __BACKEND_H__ */ 319#endif /* __BACKEND_H__ */