Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / tests / qtest / pnv-xscom-test.c
blobc814c0f4f5b1fda9f33c70080c6a9b52053f7689
1 /*
2 * QTest testcase for PowerNV XSCOM bus
4 * Copyright (c) 2016, IBM Corporation.
6 * This work is licensed under the terms of the GNU GPL, version 2 or
7 * later. See the COPYING file in the top-level directory.
8 */
9 #include "qemu/osdep.h"
11 #include "libqtest.h"
13 #include "pnv-xscom.h"
15 static uint64_t pnv_xscom_read(QTestState *qts, const PnvChip *chip,
16 uint32_t pcba)
18 return qtest_readq(qts, pnv_xscom_addr(chip, pcba));
21 static void test_xscom_cfam_id(QTestState *qts, const PnvChip *chip)
23 uint64_t f000f = pnv_xscom_read(qts, chip, 0xf000f);
25 g_assert_cmphex(f000f, ==, chip->cfam_id);
28 static void test_cfam_id(const void *data)
30 const PnvChip *chip = data;
31 const char *machine = "powernv8";
32 QTestState *qts;
34 if (chip->chip_type == PNV_CHIP_POWER9) {
35 machine = "powernv9";
36 } else if (chip->chip_type == PNV_CHIP_POWER10) {
37 machine = "powernv10";
40 qts = qtest_initf("-M %s -accel tcg -cpu %s",
41 machine, chip->cpu_model);
42 test_xscom_cfam_id(qts, chip);
43 qtest_quit(qts);
47 #define PNV_XSCOM_EX_CORE_BASE 0x10000000ull
48 #define PNV_XSCOM_EX_BASE(core) \
49 (PNV_XSCOM_EX_CORE_BASE | ((uint64_t)(core) << 24))
50 #define PNV_XSCOM_P9_EC_BASE(core) \
51 ((uint64_t)(((core) & 0x1F) + 0x20) << 24)
52 #define PNV_XSCOM_P10_EC_BASE(core) \
53 ((uint64_t)((((core) & ~0x3) + 0x20) << 24) + 0x20000 + \
54 (0x1000 << (3 - (core & 0x3))))
56 #define PNV_XSCOM_EX_DTS_RESULT0 0x50000
58 static void test_xscom_core(QTestState *qts, const PnvChip *chip)
60 if (chip->chip_type == PNV_CHIP_POWER10) {
61 uint32_t first_core_thread_state =
62 PNV_XSCOM_P10_EC_BASE(chip->first_core) + 0x412;
63 uint64_t thread_state;
65 thread_state = pnv_xscom_read(qts, chip, first_core_thread_state);
67 g_assert_cmphex(thread_state, ==, 0);
68 } else {
69 uint32_t first_core_dts0 = PNV_XSCOM_EX_DTS_RESULT0;
70 uint64_t dts0;
72 if (chip->chip_type == PNV_CHIP_POWER9) {
73 first_core_dts0 |= PNV_XSCOM_P9_EC_BASE(chip->first_core);
74 } else { /* POWER8 */
75 first_core_dts0 |= PNV_XSCOM_EX_BASE(chip->first_core);
78 dts0 = pnv_xscom_read(qts, chip, first_core_dts0);
80 g_assert_cmphex(dts0, ==, 0x26f024f023f0000ull);
84 static void test_core(const void *data)
86 const PnvChip *chip = data;
87 QTestState *qts;
88 const char *machine = "powernv8";
90 if (chip->chip_type == PNV_CHIP_POWER9) {
91 machine = "powernv9";
92 } else if (chip->chip_type == PNV_CHIP_POWER10) {
93 machine = "powernv10";
96 qts = qtest_initf("-M %s -accel tcg -cpu %s",
97 machine, chip->cpu_model);
98 test_xscom_core(qts, chip);
99 qtest_quit(qts);
102 static void add_test(const char *name, void (*test)(const void *data))
104 int i;
106 for (i = 0; i < ARRAY_SIZE(pnv_chips); i++) {
107 char *tname = g_strdup_printf("pnv-xscom/%s/%s", name,
108 pnv_chips[i].cpu_model);
109 qtest_add_data_func(tname, &pnv_chips[i], test);
110 g_free(tname);
114 int main(int argc, char **argv)
116 g_test_init(&argc, &argv, NULL);
118 add_test("cfam_id", test_cfam_id);
119 add_test("core", test_core);
120 return g_test_run();