]>
Commit | Line | Data |
---|---|---|
edbd790d MA |
1 | /* |
2 | * Boot order test cases. | |
3 | * | |
4 | * Copyright (c) 2013 Red Hat Inc. | |
5 | * | |
6 | * Authors: | |
7 | * Markus Armbruster <armbru@redhat.com>, | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
10 | * See the COPYING file in the top-level directory. | |
11 | */ | |
12 | ||
530a7e48 | 13 | #include <string.h> |
edbd790d | 14 | #include <glib.h> |
530a7e48 | 15 | #include "libqos/fw_cfg.h" |
edbd790d MA |
16 | #include "libqtest.h" |
17 | ||
484986e2 MA |
18 | #define NO_QEMU_PROTOS |
19 | #include "hw/nvram/fw_cfg.h" | |
20 | #undef NO_QEMU_PROTOS | |
aea6a169 | 21 | |
484986e2 MA |
22 | typedef struct { |
23 | const char *args; | |
24 | uint64_t expected_boot; | |
25 | uint64_t expected_reboot; | |
26 | } boot_order_test; | |
edbd790d | 27 | |
aea6a169 MA |
28 | static void test_a_boot_order(const char *machine, |
29 | const char *test_args, | |
30 | uint64_t (*read_boot_order)(void), | |
31 | uint64_t expected_boot, | |
32 | uint64_t expected_reboot) | |
edbd790d | 33 | { |
aea6a169 MA |
34 | char *args; |
35 | uint64_t actual; | |
edbd790d | 36 | |
2ad645d2 | 37 | args = g_strdup_printf("-nodefaults%s%s %s", |
aea6a169 MA |
38 | machine ? " -M " : "", |
39 | machine ?: "", | |
40 | test_args); | |
edbd790d | 41 | qtest_start(args); |
aea6a169 MA |
42 | actual = read_boot_order(); |
43 | g_assert_cmphex(actual, ==, expected_boot); | |
0d1aa05e | 44 | qmp_discard_response("{ 'execute': 'system_reset' }"); |
edbd790d MA |
45 | /* |
46 | * system_reset only requests reset. We get a RESET event after | |
47 | * the actual reset completes. Need to wait for that. | |
48 | */ | |
0d1aa05e | 49 | qmp_discard_response(""); /* HACK: wait for event */ |
aea6a169 MA |
50 | actual = read_boot_order(); |
51 | g_assert_cmphex(actual, ==, expected_reboot); | |
edbd790d MA |
52 | qtest_quit(global_qtest); |
53 | g_free(args); | |
54 | } | |
55 | ||
aea6a169 MA |
56 | static void test_boot_orders(const char *machine, |
57 | uint64_t (*read_boot_order)(void), | |
58 | const boot_order_test *tests) | |
edbd790d | 59 | { |
aea6a169 MA |
60 | int i; |
61 | ||
62 | for (i = 0; tests[i].args; i++) { | |
63 | test_a_boot_order(machine, tests[i].args, | |
64 | read_boot_order, | |
65 | tests[i].expected_boot, | |
66 | tests[i].expected_reboot); | |
67 | } | |
edbd790d MA |
68 | } |
69 | ||
484986e2 MA |
70 | static uint8_t read_mc146818(uint16_t port, uint8_t reg) |
71 | { | |
72 | outb(port, reg); | |
73 | return inb(port + 1); | |
74 | } | |
75 | ||
76 | static uint64_t read_boot_order_pc(void) | |
77 | { | |
78 | uint8_t b1 = read_mc146818(0x70, 0x38); | |
79 | uint8_t b2 = read_mc146818(0x70, 0x3d); | |
80 | ||
81 | return b1 | (b2 << 8); | |
82 | } | |
83 | ||
aea6a169 MA |
84 | static const boot_order_test test_cases_pc[] = { |
85 | { "", | |
86 | 0x1230, 0x1230 }, | |
87 | { "-no-fd-bootchk", | |
88 | 0x1231, 0x1231 }, | |
89 | { "-boot c", | |
90 | 0x0200, 0x0200 }, | |
91 | { "-boot nda", | |
92 | 0x3410, 0x3410 }, | |
93 | { "-boot order=", | |
94 | 0, 0 }, | |
95 | { "-boot order= -boot order=c", | |
96 | 0x0200, 0x0200 }, | |
97 | { "-boot once=a", | |
98 | 0x0100, 0x1230 }, | |
99 | { "-boot once=a -no-fd-bootchk", | |
100 | 0x0101, 0x1231 }, | |
101 | { "-boot once=a,order=c", | |
102 | 0x0100, 0x0200 }, | |
103 | { "-boot once=d -boot order=nda", | |
104 | 0x0300, 0x3410 }, | |
105 | { "-boot once=a -boot once=b -boot once=c", | |
106 | 0x0200, 0x1230 }, | |
107 | {} | |
108 | }; | |
109 | ||
110 | static void test_pc_boot_order(void) | |
111 | { | |
112 | test_boot_orders(NULL, read_boot_order_pc, test_cases_pc); | |
113 | } | |
530a7e48 | 114 | |
e99f87cc MA |
115 | static uint8_t read_m48t59(uint64_t addr, uint16_t reg) |
116 | { | |
117 | writeb(addr, reg & 0xff); | |
118 | writeb(addr + 1, reg >> 8); | |
119 | return readb(addr + 3); | |
120 | } | |
121 | ||
122 | static uint64_t read_boot_order_prep(void) | |
123 | { | |
124 | return read_m48t59(0x80000000 + 0x74, 0x34); | |
125 | } | |
126 | ||
127 | static const boot_order_test test_cases_prep[] = { | |
128 | { "", 'c', 'c' }, | |
129 | { "-boot c", 'c', 'c' }, | |
130 | { "-boot d", 'd', 'd' }, | |
131 | {} | |
132 | }; | |
133 | ||
134 | static void test_prep_boot_order(void) | |
135 | { | |
136 | test_boot_orders("prep", read_boot_order_prep, test_cases_prep); | |
137 | } | |
138 | ||
aea6a169 | 139 | static uint64_t read_boot_order_pmac(void) |
530a7e48 | 140 | { |
aea6a169 | 141 | QFWCFG *fw_cfg = mm_fw_cfg_init(0xf0000510); |
530a7e48 | 142 | |
aea6a169 | 143 | return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE); |
530a7e48 AF |
144 | } |
145 | ||
aea6a169 MA |
146 | static const boot_order_test test_cases_fw_cfg[] = { |
147 | { "", 'c', 'c' }, | |
148 | { "-boot c", 'c', 'c' }, | |
149 | { "-boot d", 'd', 'd' }, | |
150 | { "-boot once=d,order=c", 'd', 'c' }, | |
151 | {} | |
152 | }; | |
530a7e48 | 153 | |
aea6a169 MA |
154 | static void test_pmac_oldworld_boot_order(void) |
155 | { | |
156 | test_boot_orders("g3beige", read_boot_order_pmac, test_cases_fw_cfg); | |
157 | } | |
530a7e48 | 158 | |
aea6a169 MA |
159 | static void test_pmac_newworld_boot_order(void) |
160 | { | |
161 | test_boot_orders("mac99", read_boot_order_pmac, test_cases_fw_cfg); | |
530a7e48 AF |
162 | } |
163 | ||
f88dc7dd MA |
164 | static uint64_t read_boot_order_sun4m(void) |
165 | { | |
166 | QFWCFG *fw_cfg = mm_fw_cfg_init(0xd00000510ULL); | |
167 | ||
168 | return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE); | |
169 | } | |
170 | ||
171 | static void test_sun4m_boot_order(void) | |
172 | { | |
173 | test_boot_orders("SS-5", read_boot_order_sun4m, test_cases_fw_cfg); | |
174 | } | |
175 | ||
24943978 MA |
176 | static uint64_t read_boot_order_sun4u(void) |
177 | { | |
178 | QFWCFG *fw_cfg = io_fw_cfg_init(0x510); | |
179 | ||
180 | return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE); | |
181 | } | |
182 | ||
183 | static void test_sun4u_boot_order(void) | |
184 | { | |
185 | test_boot_orders("sun4u", read_boot_order_sun4u, test_cases_fw_cfg); | |
186 | } | |
187 | ||
edbd790d MA |
188 | int main(int argc, char *argv[]) |
189 | { | |
530a7e48 AF |
190 | const char *arch = qtest_get_arch(); |
191 | ||
edbd790d MA |
192 | g_test_init(&argc, &argv, NULL); |
193 | ||
530a7e48 AF |
194 | if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { |
195 | qtest_add_func("boot-order/pc", test_pc_boot_order); | |
196 | } else if (strcmp(arch, "ppc") == 0 || strcmp(arch, "ppc64") == 0) { | |
e99f87cc | 197 | qtest_add_func("boot-order/prep", test_prep_boot_order); |
aea6a169 MA |
198 | qtest_add_func("boot-order/pmac_oldworld", |
199 | test_pmac_oldworld_boot_order); | |
200 | qtest_add_func("boot-order/pmac_newworld", | |
201 | test_pmac_newworld_boot_order); | |
f88dc7dd MA |
202 | } else if (strcmp(arch, "sparc") == 0) { |
203 | qtest_add_func("boot-order/sun4m", test_sun4m_boot_order); | |
24943978 MA |
204 | } else if (strcmp(arch, "sparc64") == 0) { |
205 | qtest_add_func("boot-order/sun4u", test_sun4u_boot_order); | |
530a7e48 | 206 | } |
edbd790d MA |
207 | |
208 | return g_test_run(); | |
209 | } |