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