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.
6 #include "qemu/osdep.h"
8 #include "libqos/rtas.h"
10 static void qrtas_copy_args(uint64_t target_args, uint32_t nargs,
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)
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)
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);
50 int qrtas_get_time_of_day(QGuestAllocator *alloc, struct tm *tm, uint32_t *ns)
55 res = qrtas_call(alloc, "get-time-of-day", 0, NULL, 8, ret);
61 memset(tm, 0, sizeof(*tm));
62 tm->tm_year = ret[1] - 1900;
63 tm->tm_mon = ret[2] - 1;
73 uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
74 uint32_t addr, uint32_t size)
77 uint32_t args[4], ret[2];
81 args[2] = buid & 0xffffffff;
83 res = qrtas_call(alloc, "ibm,read-pci-config", 4, args, 2, ret);
95 int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid,
96 uint32_t addr, uint32_t size, uint32_t val)
99 uint32_t args[5], ret[1];
102 args[1] = buid >> 32;
103 args[2] = buid & 0xffffffff;
106 res = qrtas_call(alloc, "ibm,write-pci-config", 5, args, 1, ret);