2013-08-21 18:16:26 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QDebug>
|
2014-02-09 01:16:43 +00:00
|
|
|
#include <QFileInfo>
|
2013-08-21 18:16:26 +00:00
|
|
|
#include "backend.h"
|
|
|
|
|
2014-04-07 09:28:04 +00:00
|
|
|
/**
|
|
|
|
* SocFile
|
|
|
|
*/
|
|
|
|
SocFile::SocFile()
|
|
|
|
:m_valid(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SocFile::SocFile(const QString& filename)
|
|
|
|
:m_filename(filename)
|
|
|
|
{
|
|
|
|
m_valid = soc_desc_parse_xml(filename.toStdString(), m_soc);
|
|
|
|
soc_desc_normalize(m_soc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SocFile::IsValid()
|
|
|
|
{
|
|
|
|
return m_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
SocRef SocFile::GetSocRef()
|
|
|
|
{
|
|
|
|
return SocRef(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SocFile::GetFilename()
|
|
|
|
{
|
|
|
|
return m_filename;
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
/**
|
|
|
|
* Backend
|
|
|
|
*/
|
|
|
|
|
2013-08-21 18:16:26 +00:00
|
|
|
Backend::Backend()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-07 09:28:04 +00:00
|
|
|
|
|
|
|
QList< SocFileRef > Backend::GetSocFileList()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-04-07 09:28:04 +00:00
|
|
|
QList< SocFileRef > list;
|
|
|
|
for(std::list< SocFile >::iterator it = m_socs.begin(); it != m_socs.end(); ++it)
|
|
|
|
list.append(SocFileRef(&(*it)));
|
|
|
|
return list;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 09:28:04 +00:00
|
|
|
QList< SocRef > Backend::GetSocList()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-04-07 09:28:04 +00:00
|
|
|
QList< SocRef > list;
|
|
|
|
for(std::list< SocFile >::iterator it = m_socs.begin(); it != m_socs.end(); ++it)
|
|
|
|
list.append(it->GetSocRef());
|
|
|
|
return list;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Backend::LoadSocDesc(const QString& filename)
|
|
|
|
{
|
2014-04-07 09:28:04 +00:00
|
|
|
SocFile f(filename);
|
|
|
|
if(!f.IsValid())
|
|
|
|
return false;
|
|
|
|
m_socs.push_back(f);
|
2013-08-21 18:16:26 +00:00
|
|
|
emit OnSocListChanged();
|
2014-04-07 09:28:04 +00:00
|
|
|
return true;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IoBackend *Backend::CreateFileIoBackend(const QString& filename)
|
|
|
|
{
|
|
|
|
return new FileIoBackend(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
IoBackend *Backend::CreateDummyIoBackend()
|
|
|
|
{
|
|
|
|
return new DummyIoBackend();
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
#ifdef HAVE_HWSTUB
|
|
|
|
IoBackend *Backend::CreateHWStubIoBackend(HWStubDevice *dev)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-02-03 23:18:51 +00:00
|
|
|
return new HWStubIoBackend(dev);
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FileIoBackend
|
|
|
|
*/
|
2013-08-21 18:16:26 +00:00
|
|
|
|
2014-05-11 17:51:55 +00:00
|
|
|
FileIoBackend::FileIoBackend(const QString& filename, const QString& soc_name)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
|
|
|
m_filename = filename;
|
2014-05-11 17:51:55 +00:00
|
|
|
m_soc = soc_name;
|
2013-08-21 18:16:26 +00:00
|
|
|
Reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FileIoBackend::GetSocName()
|
|
|
|
{
|
|
|
|
return m_soc;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileIoBackend::ReadRegister(const QString& name, soc_word_t& value)
|
|
|
|
{
|
|
|
|
if(m_map.find(name) == m_map.end())
|
|
|
|
return false;
|
|
|
|
value = m_map[name];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileIoBackend::Reload()
|
|
|
|
{
|
|
|
|
QFile file(m_filename);
|
|
|
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
|
|
return false;
|
|
|
|
m_map.clear();
|
|
|
|
|
|
|
|
QTextStream in(&file);
|
|
|
|
while(!in.atEnd())
|
|
|
|
{
|
|
|
|
QString line = in.readLine();
|
|
|
|
int idx = line.indexOf('=');
|
|
|
|
if(idx == -1)
|
|
|
|
continue;
|
|
|
|
QString key = line.left(idx).trimmed();
|
|
|
|
bool ok;
|
|
|
|
soc_word_t val = line.mid(idx + 1).trimmed().toULong(&ok, 0);
|
|
|
|
if(key == "HW")
|
|
|
|
m_soc = line.mid(idx + 1).trimmed();
|
|
|
|
else if(ok)
|
|
|
|
m_map[key] = val;
|
|
|
|
}
|
2014-02-09 01:16:43 +00:00
|
|
|
|
|
|
|
m_readonly = !QFileInfo(file).isWritable();
|
|
|
|
m_dirty = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-10 22:10:21 +00:00
|
|
|
bool FileIoBackend::WriteRegister(const QString& name, soc_word_t value, WriteMode mode)
|
2014-02-09 01:16:43 +00:00
|
|
|
{
|
|
|
|
m_dirty = true;
|
2014-02-10 22:10:21 +00:00
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case Write: m_map[name] = value; return true;
|
|
|
|
case Set: m_map[name] |= value; return true;
|
|
|
|
case Clear: m_map[name] &= ~value; return true;
|
|
|
|
case Toggle: m_map[name] ^= value; return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-09 01:16:43 +00:00
|
|
|
bool FileIoBackend::Commit()
|
|
|
|
{
|
|
|
|
if(!m_dirty)
|
|
|
|
return true;
|
|
|
|
QFile file(m_filename);
|
|
|
|
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
|
|
|
return false;
|
|
|
|
QTextStream out(&file);
|
|
|
|
out << "HW = " << m_soc << "\n";
|
|
|
|
QMapIterator< QString, soc_word_t > it(m_map);
|
|
|
|
while(it.hasNext())
|
|
|
|
{
|
|
|
|
it.next();
|
2014-05-11 17:51:55 +00:00
|
|
|
out << it.key() << " = " << hex << showbase << it.value() << "\n";
|
2014-02-09 01:16:43 +00:00
|
|
|
}
|
|
|
|
out.flush();
|
|
|
|
return file.flush();
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
#ifdef HAVE_HWSTUB
|
|
|
|
/**
|
|
|
|
* HWStubDevice
|
|
|
|
*/
|
|
|
|
HWStubDevice::HWStubDevice(struct libusb_device *dev)
|
2014-05-11 17:51:55 +00:00
|
|
|
{
|
|
|
|
Init(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWStubDevice::HWStubDevice(const HWStubDevice *dev)
|
|
|
|
{
|
|
|
|
Init(dev->m_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HWStubDevice::Init(struct libusb_device *dev)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-02-03 23:18:51 +00:00
|
|
|
libusb_ref_device(dev);
|
|
|
|
m_dev = dev;
|
|
|
|
m_handle = 0;
|
|
|
|
m_hwdev = 0;
|
|
|
|
m_valid = Probe();
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
HWStubDevice::~HWStubDevice()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-02-03 23:18:51 +00:00
|
|
|
Close();
|
|
|
|
libusb_unref_device(m_dev);
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
int HWStubDevice::GetBusNumber()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-02-03 23:18:51 +00:00
|
|
|
return libusb_get_bus_number(m_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int HWStubDevice::GetDevAddress()
|
|
|
|
{
|
|
|
|
return libusb_get_device_address(m_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HWStubDevice::Probe()
|
|
|
|
{
|
|
|
|
if(!Open())
|
|
|
|
return false;
|
|
|
|
// get target
|
2014-08-09 16:39:06 +00:00
|
|
|
int ret = hwstub_get_desc(m_hwdev, HWSTUB_DT_TARGET, &m_hwdev_target, sizeof(m_hwdev_target));
|
2014-02-03 23:18:51 +00:00
|
|
|
if(ret != sizeof(m_hwdev_target))
|
|
|
|
goto Lerr;
|
|
|
|
// get STMP information
|
|
|
|
if(m_hwdev_target.dID == HWSTUB_TARGET_STMP)
|
|
|
|
{
|
|
|
|
ret = hwstub_get_desc(m_hwdev, HWSTUB_DT_STMP, &m_hwdev_stmp, sizeof(m_hwdev_stmp));
|
|
|
|
if(ret != sizeof(m_hwdev_stmp))
|
|
|
|
goto Lerr;
|
|
|
|
}
|
2014-05-05 21:18:04 +00:00
|
|
|
else if(m_hwdev_target.dID == HWSTUB_TARGET_PP)
|
|
|
|
{
|
|
|
|
ret = hwstub_get_desc(m_hwdev, HWSTUB_DT_PP, &m_hwdev_pp, sizeof(m_hwdev_pp));
|
|
|
|
if(ret != sizeof(m_hwdev_pp))
|
|
|
|
goto Lerr;
|
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
Close();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Lerr:
|
|
|
|
Close();
|
2013-08-21 18:16:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
bool HWStubDevice::Open()
|
|
|
|
{
|
|
|
|
if(libusb_open(m_dev, &m_handle))
|
|
|
|
return false;
|
|
|
|
m_hwdev = hwstub_open(m_handle);
|
|
|
|
if(m_hwdev == 0)
|
|
|
|
{
|
|
|
|
libusb_close(m_handle);
|
2014-02-13 10:51:48 +00:00
|
|
|
m_handle = 0;
|
2014-02-03 23:18:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HWStubDevice::Close()
|
|
|
|
{
|
|
|
|
if(m_hwdev)
|
|
|
|
hwstub_release(m_hwdev);
|
|
|
|
m_hwdev = 0;
|
|
|
|
if(m_handle)
|
|
|
|
libusb_close(m_handle);
|
|
|
|
m_handle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HWStubDevice::ReadMem(soc_addr_t addr, size_t length, void *buffer)
|
|
|
|
{
|
|
|
|
if(!m_hwdev)
|
|
|
|
return false;
|
2014-11-18 22:27:26 +00:00
|
|
|
int ret = hwstub_rw_mem_atomic(m_hwdev, 1, addr, buffer, length);
|
2014-02-03 23:18:51 +00:00
|
|
|
return ret >= 0 && (size_t)ret == length;
|
|
|
|
}
|
|
|
|
|
2014-02-09 01:16:43 +00:00
|
|
|
bool HWStubDevice::WriteMem(soc_addr_t addr, size_t length, void *buffer)
|
|
|
|
{
|
|
|
|
if(!m_hwdev)
|
|
|
|
return false;
|
2014-11-18 22:27:26 +00:00
|
|
|
int ret = hwstub_rw_mem_atomic(m_hwdev, 0, addr, buffer, length);
|
2014-02-09 01:16:43 +00:00
|
|
|
return ret >= 0 && (size_t)ret == length;
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
bool HWStubDevice::IsValid()
|
|
|
|
{
|
|
|
|
return m_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HWStubIoBackend
|
|
|
|
*/
|
|
|
|
|
|
|
|
HWStubIoBackend::HWStubIoBackend(HWStubDevice *dev)
|
|
|
|
{
|
|
|
|
m_dev = dev;
|
|
|
|
m_dev->Open();
|
|
|
|
struct hwstub_target_desc_t target = m_dev->GetTargetInfo();
|
|
|
|
if(target.dID == HWSTUB_TARGET_STMP)
|
|
|
|
{
|
|
|
|
struct hwstub_stmp_desc_t stmp = m_dev->GetSTMPInfo();
|
|
|
|
if(stmp.wChipID == 0x3780)
|
|
|
|
m_soc = "imx233";
|
|
|
|
else if(stmp.wChipID >= 0x3700 && stmp.wChipID < 0x3780)
|
|
|
|
m_soc = "stmp3700";
|
|
|
|
else if(stmp.wChipID >= 0x3600 && stmp.wChipID < 0x3700)
|
|
|
|
m_soc = "stmp3600";
|
|
|
|
else
|
|
|
|
m_soc = QString("stmp%1").arg(stmp.wChipID, 4, 16, QChar('0'));
|
|
|
|
}
|
|
|
|
else if(target.dID == HWSTUB_TARGET_RK27)
|
|
|
|
m_soc = "rk27x";
|
2014-05-05 21:18:04 +00:00
|
|
|
else if(target.dID == HWSTUB_TARGET_PP)
|
|
|
|
{
|
|
|
|
struct hwstub_pp_desc_t pp = m_dev->GetPPInfo();
|
|
|
|
if(pp.wChipID == 0x6110 )
|
|
|
|
m_soc = "pp6110";
|
|
|
|
else
|
|
|
|
m_soc = QString("pp%1").arg(pp.wChipID, 4, 16, QChar('0'));
|
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
else
|
|
|
|
m_soc = target.bName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString HWStubIoBackend::GetSocName()
|
|
|
|
{
|
|
|
|
return m_soc;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWStubIoBackend::~HWStubIoBackend()
|
|
|
|
{
|
2014-05-11 17:51:55 +00:00
|
|
|
delete m_dev;
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HWStubIoBackend::ReadRegister(soc_addr_t addr, soc_word_t& value)
|
|
|
|
{
|
|
|
|
return m_dev->ReadMem(addr, sizeof(value), &value);
|
|
|
|
}
|
|
|
|
|
2014-02-10 22:10:21 +00:00
|
|
|
bool HWStubIoBackend::WriteRegister(soc_addr_t addr, soc_word_t value, WriteMode mode)
|
2014-02-09 01:16:43 +00:00
|
|
|
{
|
2014-02-10 22:10:21 +00:00
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case Set: addr += 4; break;
|
|
|
|
case Clear: addr += 8; break;
|
|
|
|
case Toggle: addr += 12; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2014-02-09 01:16:43 +00:00
|
|
|
return m_dev->WriteMem(addr, sizeof(value), &value);
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
bool HWStubIoBackend::Reload()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
/**
|
|
|
|
* HWStubBackendHelper
|
|
|
|
*/
|
|
|
|
HWStubBackendHelper::HWStubBackendHelper()
|
|
|
|
{
|
|
|
|
#ifdef LIBUSB_NO_HOTPLUG
|
|
|
|
m_hotplug = false;
|
|
|
|
#else
|
|
|
|
m_hotplug = libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG);
|
|
|
|
if(m_hotplug)
|
|
|
|
{
|
2014-08-09 16:39:06 +00:00
|
|
|
int evt = LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
|
|
|
|
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT;
|
2014-02-03 23:18:51 +00:00
|
|
|
m_hotplug = LIBUSB_SUCCESS == libusb_hotplug_register_callback(
|
2014-08-09 16:39:06 +00:00
|
|
|
NULL, (libusb_hotplug_event)evt, LIBUSB_HOTPLUG_ENUMERATE,
|
|
|
|
LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY,
|
|
|
|
&HWStubBackendHelper::HotPlugCallback, reinterpret_cast< void* >(this),
|
|
|
|
&m_hotplug_handle);
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
2014-09-18 17:00:56 +00:00
|
|
|
#endif /* LIBUSB_NO_HOTPLUG */
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HWStubBackendHelper::~HWStubBackendHelper()
|
|
|
|
{
|
|
|
|
#ifndef LIBUSB_NO_HOTPLUG
|
|
|
|
if(m_hotplug)
|
|
|
|
libusb_hotplug_deregister_callback(NULL, m_hotplug_handle);
|
2014-09-18 17:00:56 +00:00
|
|
|
#endif /* LIBUSB_NO_HOTPLUG */
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QList< HWStubDevice* > HWStubBackendHelper::GetDevList()
|
|
|
|
{
|
|
|
|
QList< HWStubDevice* > list;
|
|
|
|
libusb_device **dev_list;
|
2014-08-09 16:39:06 +00:00
|
|
|
ssize_t cnt = hwstub_get_device_list(NULL, &dev_list);
|
2014-02-03 23:18:51 +00:00
|
|
|
for(int i = 0; i < cnt; i++)
|
|
|
|
{
|
|
|
|
HWStubDevice *dev = new HWStubDevice(dev_list[i]);
|
|
|
|
/* filter out non-hwstub devices */
|
|
|
|
if(dev->IsValid())
|
|
|
|
list.push_back(dev);
|
|
|
|
else
|
|
|
|
delete dev;
|
|
|
|
}
|
|
|
|
libusb_free_device_list(dev_list, 1);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef LIBUSB_NO_HOTPLUG
|
|
|
|
void HWStubBackendHelper::OnHotPlug(bool arrived, struct libusb_device *dev)
|
|
|
|
{
|
|
|
|
/* signal it */
|
|
|
|
emit OnDevListChanged(arrived, dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int HWStubBackendHelper::HotPlugCallback(struct libusb_context *ctx, struct libusb_device *dev,
|
|
|
|
libusb_hotplug_event event, void *user_data)
|
|
|
|
{
|
2014-04-07 09:28:04 +00:00
|
|
|
Q_UNUSED(ctx);
|
2014-02-03 23:18:51 +00:00
|
|
|
HWStubBackendHelper *helper = reinterpret_cast< HWStubBackendHelper* >(user_data);
|
|
|
|
switch(event)
|
|
|
|
{
|
|
|
|
case LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED: helper->OnHotPlug(true, dev); break;
|
|
|
|
case LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT: helper->OnHotPlug(false, dev); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2014-09-18 17:00:56 +00:00
|
|
|
#endif /* LIBUSB_NO_HOTPLUG */
|
2014-02-03 23:18:51 +00:00
|
|
|
|
|
|
|
bool HWStubBackendHelper::HasHotPlugSupport()
|
|
|
|
{
|
|
|
|
return m_hotplug;
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:00:56 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class lib_usb_init
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lib_usb_init()
|
|
|
|
{
|
|
|
|
libusb_init(NULL);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
lib_usb_init __lib_usb_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_HWSTUB */
|
2014-02-03 23:18:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BackendHelper
|
|
|
|
*/
|
|
|
|
|
2014-02-09 01:13:53 +00:00
|
|
|
BackendHelper::BackendHelper(IoBackend *io_backend, const SocRef& soc)
|
2013-08-21 18:16:26 +00:00
|
|
|
:m_io_backend(io_backend), m_soc(soc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackendHelper::ReadRegister(const QString& dev, const QString& reg, soc_word_t& v)
|
|
|
|
{
|
2014-02-03 23:18:51 +00:00
|
|
|
if(m_io_backend->SupportAccess(IoBackend::ByName))
|
|
|
|
return m_io_backend->ReadRegister("HW." + dev + "." + reg, v);
|
|
|
|
if(m_io_backend->SupportAccess(IoBackend::ByAddress))
|
|
|
|
{
|
|
|
|
soc_addr_t addr;
|
|
|
|
if(GetRegisterAddress(dev, reg, addr))
|
|
|
|
return m_io_backend->ReadRegister(addr, v);
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 22:10:21 +00:00
|
|
|
bool BackendHelper::WriteRegister(const QString& dev, const QString& reg,
|
|
|
|
soc_word_t v, IoBackend::WriteMode mode)
|
|
|
|
{
|
|
|
|
if(m_io_backend->SupportAccess(IoBackend::ByName))
|
|
|
|
return m_io_backend->WriteRegister("HW." + dev + "." + reg, v, mode);
|
|
|
|
if(m_io_backend->SupportAccess(IoBackend::ByAddress))
|
|
|
|
{
|
|
|
|
soc_addr_t addr;
|
|
|
|
if(GetRegisterAddress(dev, reg, addr))
|
|
|
|
return m_io_backend->WriteRegister(addr, v, mode);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
|
2014-02-09 01:13:53 +00:00
|
|
|
bool BackendHelper::GetDevRef(const QString& sdev, SocDevRef& ref)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-02-09 01:13:53 +00:00
|
|
|
for(size_t i = 0; i < m_soc.GetSoc().dev.size(); i++)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-02-09 01:13:53 +00:00
|
|
|
const soc_dev_t& dev = m_soc.GetSoc().dev[i];
|
|
|
|
for(size_t j = 0; j < dev.addr.size(); j++)
|
|
|
|
if(dev.addr[j].name.c_str() == sdev)
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2014-02-09 01:13:53 +00:00
|
|
|
ref = SocDevRef(m_soc, i, j);
|
2014-02-03 23:18:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-09 01:13:53 +00:00
|
|
|
bool BackendHelper::GetRegRef(const SocDevRef& dev, const QString& sreg, SocRegRef& ref)
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2014-02-09 01:13:53 +00:00
|
|
|
const soc_dev_t& sdev = dev.GetDev();
|
|
|
|
for(size_t i = 0; i < sdev.reg.size(); i++)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-02-09 01:13:53 +00:00
|
|
|
const soc_reg_t& reg = sdev.reg[i];
|
|
|
|
for(size_t j = 0; j < reg.addr.size(); j++)
|
|
|
|
{
|
|
|
|
if(reg.addr[j].name.c_str() == sreg)
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2014-02-09 01:13:53 +00:00
|
|
|
ref = SocRegRef(dev, i, j);
|
2014-02-03 23:18:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-02-09 01:13:53 +00:00
|
|
|
}
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-09 01:13:53 +00:00
|
|
|
bool BackendHelper::GetFieldRef(const SocRegRef& reg, const QString& sfield, SocFieldRef& ref)
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2014-02-09 01:13:53 +00:00
|
|
|
for(size_t i = 0; i < reg.GetReg().field.size(); i++)
|
|
|
|
if(reg.GetReg().field[i].name.c_str() == sfield)
|
|
|
|
{
|
|
|
|
ref = SocFieldRef(reg, i);
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackendHelper::GetRegisterAddress(const QString& dev, const QString& reg,
|
|
|
|
soc_addr_t& addr)
|
|
|
|
{
|
2014-02-09 01:13:53 +00:00
|
|
|
SocDevRef dev_ref;
|
|
|
|
SocRegRef reg_ref;
|
|
|
|
if(!GetDevRef(dev, dev_ref) || !GetRegRef(dev_ref, reg, reg_ref))
|
2014-02-03 23:18:51 +00:00
|
|
|
return false;
|
2014-02-09 01:13:53 +00:00
|
|
|
addr = dev_ref.GetDevAddr().addr + reg_ref.GetRegAddr().addr;
|
2014-02-03 23:18:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackendHelper::ReadRegisterField(const QString& dev, const QString& reg,
|
|
|
|
const QString& field, soc_word_t& v)
|
|
|
|
{
|
2014-02-09 01:13:53 +00:00
|
|
|
SocDevRef dev_ref;
|
|
|
|
SocRegRef reg_ref;
|
|
|
|
SocFieldRef field_ref;
|
|
|
|
if(!GetDevRef(dev, dev_ref) || !GetRegRef(dev_ref, reg, reg_ref) ||
|
|
|
|
!GetFieldRef(reg_ref, field, field_ref))
|
2013-08-21 18:16:26 +00:00
|
|
|
return false;
|
|
|
|
if(!ReadRegister(dev, reg, v))
|
|
|
|
return false;
|
2014-02-09 01:13:53 +00:00
|
|
|
v = (v & field_ref.GetField().bitmask()) >> field_ref.GetField().first_bit;
|
2013-08-21 18:16:26 +00:00
|
|
|
return true;
|
2014-02-10 22:10:21 +00:00
|
|
|
}
|
2014-05-11 17:51:55 +00:00
|
|
|
|
|
|
|
bool BackendHelper::DumpAllRegisters(const QString& filename)
|
|
|
|
{
|
|
|
|
FileIoBackend b(filename, QString::fromStdString(m_soc.GetSoc().name));
|
|
|
|
BackendHelper bh(&b, m_soc);
|
|
|
|
for(size_t i = 0; i < m_soc.GetSoc().dev.size(); i++)
|
|
|
|
{
|
|
|
|
const soc_dev_t& dev = m_soc.GetSoc().dev[i];
|
|
|
|
for(size_t j = 0; j < dev.addr.size(); j++)
|
|
|
|
{
|
|
|
|
QString devname = QString::fromStdString(dev.addr[j].name);
|
|
|
|
for(size_t k = 0; k < dev.reg.size(); k++)
|
|
|
|
{
|
|
|
|
const soc_reg_t& reg = dev.reg[k];
|
|
|
|
for(size_t l = 0; l < reg.addr.size(); l++)
|
|
|
|
{
|
|
|
|
QString regname = QString::fromStdString(reg.addr[l].name);
|
|
|
|
soc_word_t val;
|
|
|
|
if(!ReadRegister(devname, regname, val))
|
|
|
|
return false;
|
|
|
|
if(!bh.WriteRegister(devname, regname, val))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return b.Commit();
|
|
|
|
}
|