pci: designware: Update MSI mapping unconditionally
[qemu/ar7.git] / tests / libqos / rtas.c
blobd81ff4274da0a906e6e4bbb94d73f14e85ca636e
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(QTestState *qts, uint64_t target_args,
11 uint32_t nargs, uint32_t *args)
13 int i;
15 for (i = 0; i < nargs; i++) {
16 qtest_writel(qts, target_args + i * sizeof(uint32_t), args[i]);
20 static void qrtas_copy_ret(QTestState *qts, uint64_t target_ret,
21 uint32_t nret, uint32_t *ret)
23 int i;
25 for (i = 0; i < nret; i++) {
26 ret[i] = qtest_readl(qts, target_ret + i * sizeof(uint32_t));
30 static uint64_t qrtas_call(QTestState *qts, QGuestAllocator *alloc,
31 const char *name,
32 uint32_t nargs, uint32_t *args,
33 uint32_t nret, uint32_t *ret)
35 uint64_t res;
36 uint64_t target_args, target_ret;
38 target_args = guest_alloc(alloc, nargs * sizeof(uint32_t));
39 target_ret = guest_alloc(alloc, nret * sizeof(uint32_t));
41 qrtas_copy_args(qts, target_args, nargs, args);
42 res = qtest_rtas_call(qts, name, nargs, target_args, nret, target_ret);
43 qrtas_copy_ret(qts, target_ret, nret, ret);
45 guest_free(alloc, target_ret);
46 guest_free(alloc, target_args);
48 return res;
51 int qrtas_get_time_of_day(QTestState *qts, QGuestAllocator *alloc,
52 struct tm *tm, uint32_t *ns)
54 int res;
55 uint32_t ret[8];
57 res = qrtas_call(qts, alloc, "get-time-of-day", 0, NULL, 8, ret);
58 if (res != 0) {
59 return res;
62 res = ret[0];
63 memset(tm, 0, sizeof(*tm));
64 tm->tm_year = ret[1] - 1900;
65 tm->tm_mon = ret[2] - 1;
66 tm->tm_mday = ret[3];
67 tm->tm_hour = ret[4];
68 tm->tm_min = ret[5];
69 tm->tm_sec = ret[6];
70 *ns = ret[7];
72 return res;
75 uint32_t qrtas_ibm_read_pci_config(QTestState *qts, QGuestAllocator *alloc,
76 uint64_t buid,
77 uint32_t addr, uint32_t size)
79 int res;
80 uint32_t args[4], ret[2];
82 args[0] = addr;
83 args[1] = buid >> 32;
84 args[2] = buid & 0xffffffff;
85 args[3] = size;
86 res = qrtas_call(qts, alloc, "ibm,read-pci-config", 4, args, 2, ret);
87 if (res != 0) {
88 return -1;
91 if (ret[0] != 0) {
92 return -1;
95 return ret[1];
98 int qrtas_ibm_write_pci_config(QTestState *qts, QGuestAllocator *alloc,
99 uint64_t buid,
100 uint32_t addr, uint32_t size, uint32_t val)
102 int res;
103 uint32_t args[5], ret[1];
105 args[0] = addr;
106 args[1] = buid >> 32;
107 args[2] = buid & 0xffffffff;
108 args[3] = size;
109 args[4] = val;
110 res = qrtas_call(qts, alloc, "ibm,write-pci-config", 5, args, 1, ret);
111 if (res != 0) {
112 return -1;
115 if (ret[0] != 0) {
116 return -1;
119 return 0;