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 */ 5 6 #include "qemu/osdep.h" 7 #include "libqtest.h" 8 #include "libqos/rtas.h" 9 10 static void qrtas_copy_args(uint64_t target_args, uint32_t nargs, 11 uint32_t *args) 12 { 13 int i; 14 15 for (i = 0; i < nargs; i++) { 16 writel(target_args + i * sizeof(uint32_t), args[i]); 17 } 18 } 19 20 static void qrtas_copy_ret(uint64_t target_ret, uint32_t nret, uint32_t *ret) 21 { 22 int i; 23 24 for (i = 0; i < nret; i++) { 25 ret[i] = readl(target_ret + i * sizeof(uint32_t)); 26 } 27 } 28 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) 32 { 33 uint64_t res; 34 uint64_t target_args, target_ret; 35 36 target_args = guest_alloc(alloc, nargs * sizeof(uint32_t)); 37 target_ret = guest_alloc(alloc, nret * sizeof(uint32_t)); 38 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); 43 44 guest_free(alloc, target_ret); 45 guest_free(alloc, target_args); 46 47 return res; 48 } 49 50 int qrtas_get_time_of_day(QGuestAllocator *alloc, struct tm *tm, uint32_t *ns) 51 { 52 int res; 53 uint32_t ret[8]; 54 55 res = qrtas_call(alloc, "get-time-of-day", 0, NULL, 8, ret); 56 if (res != 0) { 57 return res; 58 } 59 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]; 69 70 return res; 71 } 72