2016-09-13 15:52:45 +03:00
|
|
|
/*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "libqtest.h"
|
2020-08-04 21:00:40 +03:00
|
|
|
#include "rtas.h"
|
2016-09-13 15:52:45 +03:00
|
|
|
|
2017-09-11 20:19:58 +03:00
|
|
|
static void qrtas_copy_args(QTestState *qts, uint64_t target_args,
|
|
|
|
uint32_t nargs, uint32_t *args)
|
2016-09-13 15:52:45 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nargs; i++) {
|
2017-09-11 20:19:58 +03:00
|
|
|
qtest_writel(qts, target_args + i * sizeof(uint32_t), args[i]);
|
2016-09-13 15:52:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-11 20:19:58 +03:00
|
|
|
static void qrtas_copy_ret(QTestState *qts, uint64_t target_ret,
|
|
|
|
uint32_t nret, uint32_t *ret)
|
2016-09-13 15:52:45 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nret; i++) {
|
2017-09-11 20:19:58 +03:00
|
|
|
ret[i] = qtest_readl(qts, target_ret + i * sizeof(uint32_t));
|
2016-09-13 15:52:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-11 20:19:58 +03:00
|
|
|
static uint64_t qrtas_call(QTestState *qts, QGuestAllocator *alloc,
|
|
|
|
const char *name,
|
2016-09-13 15:52:45 +03:00
|
|
|
uint32_t nargs, uint32_t *args,
|
|
|
|
uint32_t nret, uint32_t *ret)
|
|
|
|
{
|
|
|
|
uint64_t res;
|
|
|
|
uint64_t target_args, target_ret;
|
|
|
|
|
|
|
|
target_args = guest_alloc(alloc, nargs * sizeof(uint32_t));
|
|
|
|
target_ret = guest_alloc(alloc, nret * sizeof(uint32_t));
|
|
|
|
|
2017-09-11 20:19:58 +03:00
|
|
|
qrtas_copy_args(qts, target_args, nargs, args);
|
|
|
|
res = qtest_rtas_call(qts, name, nargs, target_args, nret, target_ret);
|
|
|
|
qrtas_copy_ret(qts, target_ret, nret, ret);
|
2016-09-13 15:52:45 +03:00
|
|
|
|
|
|
|
guest_free(alloc, target_ret);
|
|
|
|
guest_free(alloc, target_args);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-09-11 20:19:58 +03:00
|
|
|
int qrtas_get_time_of_day(QTestState *qts, QGuestAllocator *alloc,
|
|
|
|
struct tm *tm, uint32_t *ns)
|
2016-09-13 15:52:45 +03:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
uint32_t ret[8];
|
|
|
|
|
2017-09-11 20:19:58 +03:00
|
|
|
res = qrtas_call(qts, alloc, "get-time-of-day", 0, NULL, 8, ret);
|
2016-09-13 15:52:45 +03:00
|
|
|
if (res != 0) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ret[0];
|
|
|
|
memset(tm, 0, sizeof(*tm));
|
|
|
|
tm->tm_year = ret[1] - 1900;
|
|
|
|
tm->tm_mon = ret[2] - 1;
|
|
|
|
tm->tm_mday = ret[3];
|
|
|
|
tm->tm_hour = ret[4];
|
|
|
|
tm->tm_min = ret[5];
|
|
|
|
tm->tm_sec = ret[6];
|
|
|
|
*ns = ret[7];
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2016-09-29 13:32:44 +03:00
|
|
|
|
2017-09-11 20:19:58 +03:00
|
|
|
uint32_t qrtas_ibm_read_pci_config(QTestState *qts, QGuestAllocator *alloc,
|
|
|
|
uint64_t buid,
|
2016-09-29 13:32:44 +03:00
|
|
|
uint32_t addr, uint32_t size)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
uint32_t args[4], ret[2];
|
|
|
|
|
|
|
|
args[0] = addr;
|
|
|
|
args[1] = buid >> 32;
|
|
|
|
args[2] = buid & 0xffffffff;
|
|
|
|
args[3] = size;
|
2017-09-11 20:19:58 +03:00
|
|
|
res = qrtas_call(qts, alloc, "ibm,read-pci-config", 4, args, 2, ret);
|
2016-09-29 13:32:44 +03:00
|
|
|
if (res != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret[0] != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret[1];
|
|
|
|
}
|
|
|
|
|
2017-09-11 20:19:58 +03:00
|
|
|
int qrtas_ibm_write_pci_config(QTestState *qts, QGuestAllocator *alloc,
|
|
|
|
uint64_t buid,
|
2016-09-29 13:32:44 +03:00
|
|
|
uint32_t addr, uint32_t size, uint32_t val)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
uint32_t args[5], ret[1];
|
|
|
|
|
|
|
|
args[0] = addr;
|
|
|
|
args[1] = buid >> 32;
|
|
|
|
args[2] = buid & 0xffffffff;
|
|
|
|
args[3] = size;
|
|
|
|
args[4] = val;
|
2017-09-11 20:19:58 +03:00
|
|
|
res = qrtas_call(qts, alloc, "ibm,write-pci-config", 5, args, 1, ret);
|
2016-09-29 13:32:44 +03:00
|
|
|
if (res != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret[0] != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|