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.
9 #include "qemu/osdep.h"
13 #include "pnv-xscom.h"
15 static uint64_t pnv_xscom_read(QTestState
*qts
, const PnvChip
*chip
,
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";
34 if (chip
->chip_type
== PNV_CHIP_POWER9
) {
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
);
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);
69 uint32_t first_core_dts0
= PNV_XSCOM_EX_DTS_RESULT0
;
72 if (chip
->chip_type
== PNV_CHIP_POWER9
) {
73 first_core_dts0
|= PNV_XSCOM_P9_EC_BASE(chip
->first_core
);
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
;
88 const char *machine
= "powernv8";
90 if (chip
->chip_type
== PNV_CHIP_POWER9
) {
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
);
102 static void add_test(const char *name
, void (*test
)(const void *data
))
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
);
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
);