]> Git Repo - qemu.git/blob - tests/libqos/rtas.c
block: Move NVMe constants to a separate header
[qemu.git] / tests / libqos / rtas.c
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
73 uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
74                                    uint32_t addr, uint32_t size)
75 {
76     int res;
77     uint32_t args[4], ret[2];
78
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;
86     }
87
88     if (ret[0] != 0) {
89         return -1;
90     }
91
92     return ret[1];
93 }
94
95 int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid,
96                                uint32_t addr, uint32_t size, uint32_t val)
97 {
98     int res;
99     uint32_t args[5], ret[1];
100
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;
109     }
110
111     if (ret[0] != 0) {
112         return -1;
113     }
114
115     return 0;
116 }
This page took 0.026563 seconds and 4 git commands to generate.