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 typedef enum PnvChipType
{
14 PNV_CHIP_POWER8E
, /* AKA Murano (default) */
15 PNV_CHIP_POWER8
, /* AKA Venice */
16 PNV_CHIP_POWER8NVL
, /* AKA Naples */
17 PNV_CHIP_POWER9
, /* AKA Nimbus */
20 typedef struct PnvChip
{
21 PnvChipType chip_type
;
22 const char *cpu_model
;
28 static const PnvChip pnv_chips
[] = {
30 .chip_type
= PNV_CHIP_POWER8
,
31 .cpu_model
= "POWER8",
32 .xscom_base
= 0x0003fc0000000000ull
,
33 .cfam_id
= 0x220ea04980000000ull
,
36 .chip_type
= PNV_CHIP_POWER8NVL
,
37 .cpu_model
= "POWER8NVL",
38 .xscom_base
= 0x0003fc0000000000ull
,
39 .cfam_id
= 0x120d304980000000ull
,
42 #if 0 /* POWER9 support is not ready yet */
44 .chip_type
= PNV_CHIP_POWER9
,
45 .cpu_model
= "POWER9",
46 .xscom_base
= 0x000603fc00000000ull
,
47 .cfam_id
= 0x220d104900008000ull
,
53 static uint64_t pnv_xscom_addr(const PnvChip
*chip
, uint32_t pcba
)
55 uint64_t addr
= chip
->xscom_base
;
57 if (chip
->chip_type
== PNV_CHIP_POWER9
) {
58 addr
|= ((uint64_t) pcba
<< 3);
60 addr
|= (((uint64_t) pcba
<< 4) & ~0xffull
) |
61 (((uint64_t) pcba
<< 3) & 0x78);
66 static uint64_t pnv_xscom_read(QTestState
*qts
, const PnvChip
*chip
,
69 return qtest_readq(qts
, pnv_xscom_addr(chip
, pcba
));
72 static void test_xscom_cfam_id(QTestState
*qts
, const PnvChip
*chip
)
74 uint64_t f000f
= pnv_xscom_read(qts
, chip
, 0xf000f);
76 g_assert_cmphex(f000f
, ==, chip
->cfam_id
);
79 static void test_cfam_id(const void *data
)
81 const PnvChip
*chip
= data
;
84 qts
= qtest_initf("-M powernv,accel=tcg -cpu %s", chip
->cpu_model
);
85 test_xscom_cfam_id(qts
, chip
);
90 #define PNV_XSCOM_EX_CORE_BASE 0x10000000ull
91 #define PNV_XSCOM_EX_BASE(core) \
92 (PNV_XSCOM_EX_CORE_BASE | ((uint64_t)(core) << 24))
93 #define PNV_XSCOM_P9_EC_BASE(core) \
94 ((uint64_t)(((core) & 0x1F) + 0x20) << 24)
96 #define PNV_XSCOM_EX_DTS_RESULT0 0x50000
98 static void test_xscom_core(QTestState
*qts
, const PnvChip
*chip
)
100 uint32_t first_core_dts0
= PNV_XSCOM_EX_DTS_RESULT0
;
103 if (chip
->chip_type
!= PNV_CHIP_POWER9
) {
104 first_core_dts0
|= PNV_XSCOM_EX_BASE(chip
->first_core
);
106 first_core_dts0
|= PNV_XSCOM_P9_EC_BASE(chip
->first_core
);
109 dts0
= pnv_xscom_read(qts
, chip
, first_core_dts0
);
111 g_assert_cmphex(dts0
, ==, 0x26f024f023f0000ull
);
114 static void test_core(const void *data
)
116 const PnvChip
*chip
= data
;
119 qts
= qtest_initf("-M powernv,accel=tcg -cpu %s", chip
->cpu_model
);
120 test_xscom_core(qts
, chip
);
124 static void add_test(const char *name
, void (*test
)(const void *data
))
128 for (i
= 0; i
< ARRAY_SIZE(pnv_chips
); i
++) {
129 char *tname
= g_strdup_printf("pnv-xscom/%s/%s", name
,
130 pnv_chips
[i
].cpu_model
);
131 qtest_add_data_func(tname
, &pnv_chips
[i
], test
);
136 int main(int argc
, char **argv
)
138 g_test_init(&argc
, &argv
, NULL
);
140 add_test("cfam_id", test_cfam_id
);
141 add_test("core", test_core
);