pnv-xscom-test.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * QTest testcase for PowerNV XSCOM bus
  3. *
  4. * Copyright (c) 2016, IBM Corporation.
  5. *
  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"
  10. #include "libqtest.h"
  11. typedef enum PnvChipType {
  12. PNV_CHIP_POWER8E, /* AKA Murano (default) */
  13. PNV_CHIP_POWER8, /* AKA Venice */
  14. PNV_CHIP_POWER8NVL, /* AKA Naples */
  15. PNV_CHIP_POWER9, /* AKA Nimbus */
  16. } PnvChipType;
  17. typedef struct PnvChip {
  18. PnvChipType chip_type;
  19. const char *cpu_model;
  20. uint64_t xscom_base;
  21. uint64_t cfam_id;
  22. uint32_t first_core;
  23. } PnvChip;
  24. static const PnvChip pnv_chips[] = {
  25. {
  26. .chip_type = PNV_CHIP_POWER8,
  27. .cpu_model = "POWER8",
  28. .xscom_base = 0x0003fc0000000000ull,
  29. .cfam_id = 0x220ea04980000000ull,
  30. .first_core = 0x1,
  31. }, {
  32. .chip_type = PNV_CHIP_POWER8NVL,
  33. .cpu_model = "POWER8NVL",
  34. .xscom_base = 0x0003fc0000000000ull,
  35. .cfam_id = 0x120d304980000000ull,
  36. .first_core = 0x1,
  37. },
  38. {
  39. .chip_type = PNV_CHIP_POWER9,
  40. .cpu_model = "POWER9",
  41. .xscom_base = 0x000603fc00000000ull,
  42. .cfam_id = 0x220d104900008000ull,
  43. .first_core = 0x0,
  44. },
  45. };
  46. static uint64_t pnv_xscom_addr(const PnvChip *chip, uint32_t pcba)
  47. {
  48. uint64_t addr = chip->xscom_base;
  49. if (chip->chip_type == PNV_CHIP_POWER9) {
  50. addr |= ((uint64_t) pcba << 3);
  51. } else {
  52. addr |= (((uint64_t) pcba << 4) & ~0xffull) |
  53. (((uint64_t) pcba << 3) & 0x78);
  54. }
  55. return addr;
  56. }
  57. static uint64_t pnv_xscom_read(QTestState *qts, const PnvChip *chip,
  58. uint32_t pcba)
  59. {
  60. return qtest_readq(qts, pnv_xscom_addr(chip, pcba));
  61. }
  62. static void test_xscom_cfam_id(QTestState *qts, const PnvChip *chip)
  63. {
  64. uint64_t f000f = pnv_xscom_read(qts, chip, 0xf000f);
  65. g_assert_cmphex(f000f, ==, chip->cfam_id);
  66. }
  67. static void test_cfam_id(const void *data)
  68. {
  69. const PnvChip *chip = data;
  70. const char *machine = "powernv8";
  71. QTestState *qts;
  72. if (chip->chip_type == PNV_CHIP_POWER9) {
  73. machine = "powernv9";
  74. }
  75. qts = qtest_initf("-M %s,accel=tcg -cpu %s",
  76. machine, chip->cpu_model);
  77. test_xscom_cfam_id(qts, chip);
  78. qtest_quit(qts);
  79. }
  80. #define PNV_XSCOM_EX_CORE_BASE 0x10000000ull
  81. #define PNV_XSCOM_EX_BASE(core) \
  82. (PNV_XSCOM_EX_CORE_BASE | ((uint64_t)(core) << 24))
  83. #define PNV_XSCOM_P9_EC_BASE(core) \
  84. ((uint64_t)(((core) & 0x1F) + 0x20) << 24)
  85. #define PNV_XSCOM_EX_DTS_RESULT0 0x50000
  86. static void test_xscom_core(QTestState *qts, const PnvChip *chip)
  87. {
  88. uint32_t first_core_dts0 = PNV_XSCOM_EX_DTS_RESULT0;
  89. uint64_t dts0;
  90. if (chip->chip_type != PNV_CHIP_POWER9) {
  91. first_core_dts0 |= PNV_XSCOM_EX_BASE(chip->first_core);
  92. } else {
  93. first_core_dts0 |= PNV_XSCOM_P9_EC_BASE(chip->first_core);
  94. }
  95. dts0 = pnv_xscom_read(qts, chip, first_core_dts0);
  96. g_assert_cmphex(dts0, ==, 0x26f024f023f0000ull);
  97. }
  98. static void test_core(const void *data)
  99. {
  100. const PnvChip *chip = data;
  101. QTestState *qts;
  102. const char *machine = "powernv8";
  103. if (chip->chip_type == PNV_CHIP_POWER9) {
  104. machine = "powernv9";
  105. }
  106. qts = qtest_initf("-M %s,accel=tcg -cpu %s",
  107. machine, chip->cpu_model);
  108. test_xscom_core(qts, chip);
  109. qtest_quit(qts);
  110. }
  111. static void add_test(const char *name, void (*test)(const void *data))
  112. {
  113. int i;
  114. for (i = 0; i < ARRAY_SIZE(pnv_chips); i++) {
  115. char *tname = g_strdup_printf("pnv-xscom/%s/%s", name,
  116. pnv_chips[i].cpu_model);
  117. qtest_add_data_func(tname, &pnv_chips[i], test);
  118. g_free(tname);
  119. }
  120. }
  121. int main(int argc, char **argv)
  122. {
  123. g_test_init(&argc, &argv, NULL);
  124. add_test("cfam_id", test_cfam_id);
  125. add_test("core", test_core);
  126. return g_test_run();
  127. }