Remove reduntant qemu: from error functions
[qemu/ar7.git] / tests / libqos / rtas.c
blob0269803ce09c4b81102898d861eff5e68dd58d23
1 /*
2 * This work is licensed under the terms of the GNU GPL, version 2 or later.
3 * See the COPYING file in the top-level directory.
4 */
6 #include "qemu/osdep.h"
7 #include "libqtest.h"
8 #include "libqos/rtas.h"
10 static void qrtas_copy_args(uint64_t target_args, uint32_t nargs,
11 uint32_t *args)
13 int i;
15 for (i = 0; i < nargs; i++) {
16 writel(target_args + i * sizeof(uint32_t), args[i]);
20 static void qrtas_copy_ret(uint64_t target_ret, uint32_t nret, uint32_t *ret)
22 int i;
24 for (i = 0; i < nret; i++) {
25 ret[i] = readl(target_ret + i * sizeof(uint32_t));
29 static uint64_t qrtas_call(QGuestAllocator *alloc, const char *name,
30 uint32_t nargs, uint32_t *args,
31 uint32_t nret, uint32_t *ret)
33 uint64_t res;
34 uint64_t target_args, target_ret;
36 target_args = guest_alloc(alloc, nargs * sizeof(uint32_t));
37 target_ret = guest_alloc(alloc, nret * sizeof(uint32_t));
39 qrtas_copy_args(target_args, nargs, args);
40 res = qtest_rtas_call(global_qtest, name,
41 nargs, target_args, nret, target_ret);
42 qrtas_copy_ret(target_ret, nret, ret);
44 guest_free(alloc, target_ret);
45 guest_free(alloc, target_args);
47 return res;
50 int qrtas_get_time_of_day(QGuestAllocator *alloc, struct tm *tm, uint32_t *ns)
52 int res;
53 uint32_t ret[8];
55 res = qrtas_call(alloc, "get-time-of-day", 0, NULL, 8, ret);
56 if (res != 0) {
57 return res;
60 res = ret[0];
61 memset(tm, 0, sizeof(*tm));
62 tm->tm_year = ret[1] - 1900;
63 tm->tm_mon = ret[2] - 1;
64 tm->tm_mday = ret[3];
65 tm->tm_hour = ret[4];
66 tm->tm_min = ret[5];
67 tm->tm_sec = ret[6];
68 *ns = ret[7];
70 return res;
73 uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
74 uint32_t addr, uint32_t size)
76 int res;
77 uint32_t args[4], ret[2];
79 args[0] = addr;
80 args[1] = buid >> 32;
81 args[2] = buid & 0xffffffff;
82 args[3] = size;
83 res = qrtas_call(alloc, "ibm,read-pci-config", 4, args, 2, ret);
84 if (res != 0) {
85 return -1;
88 if (ret[0] != 0) {
89 return -1;
92 return ret[1];
95 int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid,
96 uint32_t addr, uint32_t size, uint32_t val)
98 int res;
99 uint32_t args[5], ret[1];
101 args[0] = addr;
102 args[1] = buid >> 32;
103 args[2] = buid & 0xffffffff;
104 args[3] = size;
105 args[4] = val;
106 res = qrtas_call(alloc, "ibm,write-pci-config", 5, args, 1, ret);
107 if (res != 0) {
108 return -1;
111 if (ret[0] != 0) {
112 return -1;
115 return 0;