summaryrefslogtreecommitdiffstats
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 @@
#include <QMap>
#include <QVector>
#include <QMetaType>
+#include <QAbstractItemModel>
#ifdef HAVE_HWSTUB
#include "hwstub.h"
#endif
-#include "soc_desc_v1.hpp"
+#include "soc_desc.hpp"
/* we don't want to import the entire soc_desc except for a few selected
* pieces */
-using namespace soc_desc_v1;
+using soc_desc::soc_word_t;
+using soc_desc::soc_addr_t;
+using soc_desc::soc_id_t;
class IoBackend : public QObject
{
@@ -47,35 +50,20 @@ public:
Write, Set, Clear, Toggle
};
- enum AccessType
- {
- ByName,
- ByAddress,
- };
-
- /** Register naming convention: name based access are of the form:
- * HW.dev.reg
- * where <dev> is the device name (including index like APPUART1)
- * and <reg> is the register name (including index like PRIORITY29) */
/* report whether backend is valid */
virtual bool IsValid() = 0;
- /* report whether backend supports register access type */
- virtual bool SupportAccess(AccessType type) = 0;
/* get SoC name */
virtual QString GetSocName() = 0;
- /* read a register by name or address */
- virtual bool ReadRegister(const QString& name, soc_word_t& value) = 0;
- virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value) = 0;
+ /* read a register */
+ virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value, unsigned width) = 0;
/* reload content (if it makes sense) */
virtual bool Reload() = 0;
/* check whether backend supports writing */
virtual bool IsReadOnly() = 0;
/* write a register by name or address
- * NOTE: even on a read-only backend, a write is allowed be successful as long
+ * NOTE: even on a read-only backend, a write is allowed to be successful as long
* as commit fails */
- virtual bool WriteRegister(const QString& name, soc_word_t value,
- WriteMode mode = Write) = 0;
- virtual bool WriteRegister(soc_addr_t addr, soc_word_t value,
+ virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, unsigned width,
WriteMode mode = Write) = 0;
/* check whether backend contains uncommitted (ie cached) writes */
virtual bool IsDirty() = 0;
@@ -87,23 +75,17 @@ class DummyIoBackend : public IoBackend
{
Q_OBJECT
public:
- DummyIoBackend() {}
-
- virtual bool IsValid() { return false; }
- virtual bool SupportAccess(AccessType type) { Q_UNUSED(type); return false; }
- virtual QString GetSocName() { return ""; }
- virtual bool ReadRegister(const QString& name, soc_word_t& value)
- { Q_UNUSED(name); Q_UNUSED(value); return false; }
- virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value)
- { Q_UNUSED(addr); Q_UNUSED(value); return false; }
- virtual bool Reload() { return false; }
- virtual bool IsReadOnly() { return true; }
- virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode)
- { Q_UNUSED(name); Q_UNUSED(value); Q_UNUSED(mode); return false; }
- virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, WriteMode mode)
- { Q_UNUSED(addr); Q_UNUSED(value); Q_UNUSED(mode); return false; }
- virtual bool IsDirty() { return false; }
- virtual bool Commit() { return false; }
+ DummyIoBackend();
+
+ virtual bool IsValid();
+ virtual QString GetSocName();
+ virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value, unsigned width);
+ virtual bool Reload();
+ virtual bool IsReadOnly();
+ virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, unsigned width,
+ WriteMode mode);
+ virtual bool IsDirty();
+ virtual bool Commit();
};
/** The RAM backend doesn't have any backend storage and stores all values in
@@ -114,26 +96,22 @@ class RamIoBackend : public IoBackend
public:
RamIoBackend(const QString& soc_name = "");
- virtual bool IsValid() { return m_soc != ""; }
- virtual bool SupportAccess(AccessType type) { return type == ByName; }
- virtual QString GetSocName() { return m_soc; }
- virtual void SetSocName(const QString& soc_name) { m_soc = soc_name; }
- virtual bool ReadRegister(const QString& name, soc_word_t& value);
- virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value)
- { Q_UNUSED(addr); Q_UNUSED(value); return false; }
- virtual bool Reload() { return false; }
- virtual bool IsReadOnly() { return false; }
- virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode);
- virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, WriteMode mode)
- { Q_UNUSED(addr); Q_UNUSED(value); Q_UNUSED(mode); return false; }
- virtual bool IsDirty() { return false; }
- virtual bool Commit() { return false; }
+ virtual bool IsValid();
+ virtual QString GetSocName();
+ virtual void SetSocName(const QString& soc_name);
+ virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value, unsigned width);
+ virtual bool Reload();
+ virtual bool IsReadOnly();
+ virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, unsigned width,
+ WriteMode mode);
+ virtual bool IsDirty();
+ virtual bool Commit();
/* clear all entries of the backend */
virtual void DeleteAll();
protected:
QString m_soc;
- QMap< QString, soc_word_t > m_map;
+ QMap< soc_addr_t, soc_word_t > m_map;
};
/** NOTE the File backend makes a difference between writes and commits:
@@ -144,14 +122,14 @@ class FileIoBackend : public RamIoBackend
public:
FileIoBackend(const QString& filename, const QString& soc_name = "");
- virtual bool IsValid() { return m_valid; }
- virtual bool SupportAccess(AccessType type) { return type == ByName; }
+ virtual bool IsValid();
virtual bool Reload();
- virtual bool IsReadOnly() { return m_readonly; }
- virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode);
- virtual bool IsDirty() { return m_dirty; }
+ virtual bool IsReadOnly();
+ virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, unsigned width,
+ WriteMode mode);
+ virtual bool IsDirty();
virtual bool Commit();
- QString GetFileName() { return m_filename; }
+ QString GetFileName();
protected:
QString m_filename;
@@ -204,20 +182,16 @@ public:
HWStubIoBackend(HWStubDevice *dev);
virtual ~HWStubIoBackend();
- virtual bool IsValid() { return m_dev->IsValid(); }
- virtual bool SupportAccess(AccessType type) { return type == ByAddress; }
+ virtual bool IsValid();
virtual QString GetSocName();
- virtual bool ReadRegister(const QString& name, soc_word_t& value)
- { Q_UNUSED(name); Q_UNUSED(value); return false; }
- virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value);
+ virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value, unsigned width);
virtual bool Reload();
- virtual bool IsReadOnly() { return false; }
- virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode)
- { Q_UNUSED(name); Q_UNUSED(value); Q_UNUSED(mode); return false; }
- virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, WriteMode mode);
- virtual bool IsDirty() { return false; }
- virtual bool Commit() { return true; }
- HWStubDevice *GetDevice() { return m_dev; }
+ virtual bool IsReadOnly();
+ virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, unsigned width,
+ WriteMode mode);
+ virtual bool IsDirty();
+ virtual bool Commit();
+ HWStubDevice *GetDevice();
protected:
QString m_soc;
@@ -251,8 +225,6 @@ protected:
};
#endif
-class SocRef;
-
class SocFile
{
public:
@@ -260,14 +232,14 @@ public:
SocFile(const QString& filename);
bool IsValid();
- SocRef GetSocRef();
+ soc_desc::soc_ref_t GetSocRef();
QString GetFilename();
- soc_t& GetSoc() { return m_soc; }
+ soc_desc::soc_t& GetSoc() { return m_soc; }
protected:
bool m_valid;
QString m_filename;
- soc_t m_soc;
+ soc_desc::soc_t m_soc;
};
class SocFileRef
@@ -283,56 +255,17 @@ protected:
Q_DECLARE_METATYPE(SocFileRef)
-class SocRef : public SocFileRef
-{
-public:
- SocRef() {}
- SocRef(SocFile *file):SocFileRef(file) {}
- soc_t& GetSoc() const { return GetSocFile()->GetSoc(); }
-};
-
-Q_DECLARE_METATYPE(SocRef)
+Q_DECLARE_METATYPE(soc_desc::instance_t::type_t)
+Q_DECLARE_METATYPE(soc_desc::range_t::type_t)
-class SocDevRef : public SocRef
-{
-public:
- SocDevRef() {}
- SocDevRef(const SocRef& soc, int dev_idx, int dev_addr_idx)
- :SocRef(soc), m_dev_idx(dev_idx), m_dev_addr_idx(dev_addr_idx) {}
- int GetDevIndex() const { return m_dev_idx; }
- soc_dev_t& GetDev() const { return GetSoc().dev[GetDevIndex()]; }
- int GetDevAddrIndex() const { return m_dev_addr_idx; }
- soc_dev_addr_t& GetDevAddr() const { return GetDev().addr[GetDevAddrIndex()]; }
-protected:
- int m_dev_idx, m_dev_addr_idx;
-};
-
-class SocRegRef : public SocDevRef
-{
-public:
- SocRegRef() {}
- SocRegRef(const SocDevRef& dev, int reg_idx, int reg_addr_idx)
- :SocDevRef(dev), m_reg_idx(reg_idx), m_reg_addr_idx(reg_addr_idx) {}
- int GetRegIndex() const { return m_reg_idx; }
- soc_reg_t& GetReg() const { return GetDev().reg[GetRegIndex()]; }
- int GetRegAddrIndex() const { return m_reg_addr_idx; }
- soc_reg_addr_t& GetRegAddr() const { return GetReg().addr[GetRegAddrIndex()]; }
-protected:
- int m_reg_idx, m_reg_addr_idx;
-};
-
-class SocFieldRef : public SocRegRef
-{
-public:
- SocFieldRef(){}
- SocFieldRef(const SocRegRef& reg, int field_idx)
- :SocRegRef(reg), m_field_idx(field_idx) {}
- int GetFieldIndex() const { return m_field_idx; }
- soc_reg_field_t& GetField() const { return GetReg().field[GetFieldIndex()]; }
-protected:
- int m_field_idx;
-};
+Q_DECLARE_METATYPE(soc_desc::soc_ref_t)
+Q_DECLARE_METATYPE(soc_desc::node_ref_t)
+Q_DECLARE_METATYPE(soc_desc::register_ref_t)
+Q_DECLARE_METATYPE(soc_desc::field_ref_t)
+Q_DECLARE_METATYPE(soc_desc::node_inst_t)
+/** NOTE the Backend stores soc descriptions in a way that pointers are never
+ * invalidated */
class Backend : public QObject
{
Q_OBJECT
@@ -340,7 +273,7 @@ public:
Backend();
QList< SocFileRef > GetSocFileList();
- QList< SocRef > GetSocList();
+ QList< soc_desc::soc_ref_t > GetSocList();
bool LoadSocDesc(const QString& filename);
IoBackend *CreateDummyIoBackend();
IoBackend *CreateFileIoBackend(const QString& filename);
@@ -349,33 +282,38 @@ public:
#endif
signals:
- void OnSocListChanged();
+ void OnSocAdded(const SocFileRef& ref);
+
private:
+ /* store them as a list so that pointers are never invalidated */
std::list< SocFile > m_socs;
};
class BackendHelper
{
public:
- BackendHelper(IoBackend *io_backend, const SocRef& soc);
- bool ReadRegister(const QString& dev, const QString& reg, soc_word_t& v);
- bool ReadRegisterField(const QString& dev, const QString& reg,
+ BackendHelper(IoBackend *io_backend, const soc_desc::soc_ref_t& soc);
+ QString GetPath(const soc_desc::node_inst_t& inst);
+ soc_desc::node_inst_t ParsePath(const QString& path);
+ bool ReadRegister(const soc_desc::node_inst_t& inst, soc_word_t& v);
+ bool ReadRegisterField(const soc_desc::node_inst_t& inst,
const QString& field, soc_word_t& v);
- bool WriteRegister(const QString& dev, const QString& reg, soc_word_t v,
+ bool WriteRegister(const soc_desc::node_inst_t& inst, soc_word_t v,
IoBackend::WriteMode mode = IoBackend::Write);
- bool GetDevRef(const QString& dev, SocDevRef& ref);
- bool GetRegRef(const SocDevRef& dev, const QString& reg, SocRegRef& ref);
- bool GetFieldRef(const SocRegRef& reg, const QString& field, SocFieldRef& ref);
- bool GetRegisterAddress(const QString& dev, const QString& reg, soc_addr_t& addr);
+ bool GetRegisterAddress(const soc_desc::node_inst_t& inst, soc_addr_t& addr);
/* NOTE: does not commit writes to the backend
* if ignore_errors is true, the dump will continue even on errors, and the
* function will return false if one or more errors occured */
bool DumpAllRegisters(IoBackend *backend, bool ignore_errors = true);
bool DumpAllRegisters(const QString& filename, bool ignore_errors = true);
+protected:
+ bool DumpAllRegisters(BackendHelper *bh, const soc_desc::node_inst_t& inst,
+ bool ignore_errors);
+
private:
IoBackend *m_io_backend;
- const SocRef& m_soc;
+ const soc_desc::soc_ref_t& m_soc;
};
#endif /* __BACKEND_H__ */