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(QTestState
*qts
, uint64_t target_args
,
11 uint32_t nargs
, uint32_t *args
)
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
)
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
,
32 uint32_t nargs
, uint32_t *args
,
33 uint32_t nret
, uint32_t *ret
)
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
);
51 int qrtas_get_time_of_day(QTestState
*qts
, QGuestAllocator
*alloc
,
52 struct tm
*tm
, uint32_t *ns
)
57 res
= qrtas_call(qts
, alloc
, "get-time-of-day", 0, NULL
, 8, ret
);
63 memset(tm
, 0, sizeof(*tm
));
64 tm
->tm_year
= ret
[1] - 1900;
65 tm
->tm_mon
= ret
[2] - 1;
75 uint32_t qrtas_ibm_read_pci_config(QTestState
*qts
, QGuestAllocator
*alloc
,
77 uint32_t addr
, uint32_t size
)
80 uint32_t args
[4], ret
[2];
84 args
[2] = buid
& 0xffffffff;
86 res
= qrtas_call(qts
, alloc
, "ibm,read-pci-config", 4, args
, 2, ret
);
98 int qrtas_ibm_write_pci_config(QTestState
*qts
, QGuestAllocator
*alloc
,
100 uint32_t addr
, uint32_t size
, uint32_t val
)
103 uint32_t args
[5], ret
[1];
106 args
[1] = buid
>> 32;
107 args
[2] = buid
& 0xffffffff;
110 res
= qrtas_call(qts
, alloc
, "ibm,write-pci-config", 5, args
, 1, ret
);