firmware.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * pSeries firmware setup code.
  4. *
  5. * Portions from arch/powerpc/platforms/pseries/setup.c:
  6. * Copyright (C) 1995 Linus Torvalds
  7. * Adapted from 'alpha' version by Gary Thomas
  8. * Modified by Cort Dougan ([email protected])
  9. * Modified by PPC64 Team, IBM Corp
  10. *
  11. * Portions from arch/powerpc/kernel/firmware.c
  12. * Copyright (C) 2001 Ben. Herrenschmidt ([email protected])
  13. * Modifications for ppc64:
  14. * Copyright (C) 2003 Dave Engebretsen <[email protected]>
  15. * Copyright (C) 2005 Stephen Rothwell, IBM Corporation
  16. *
  17. * Copyright 2006 IBM Corporation.
  18. */
  19. #include <linux/of_fdt.h>
  20. #include <asm/firmware.h>
  21. #include <asm/prom.h>
  22. #include <asm/udbg.h>
  23. #include <asm/svm.h>
  24. #include "pseries.h"
  25. struct hypertas_fw_feature {
  26. unsigned long val;
  27. char * name;
  28. };
  29. /*
  30. * The names in this table match names in rtas/ibm,hypertas-functions. If the
  31. * entry ends in a '*', only upto the '*' is matched. Otherwise the entire
  32. * string must match.
  33. */
  34. static __initdata struct hypertas_fw_feature
  35. hypertas_fw_features_table[] = {
  36. {FW_FEATURE_PFT, "hcall-pft"},
  37. {FW_FEATURE_TCE, "hcall-tce"},
  38. {FW_FEATURE_SPRG0, "hcall-sprg0"},
  39. {FW_FEATURE_DABR, "hcall-dabr"},
  40. {FW_FEATURE_COPY, "hcall-copy"},
  41. {FW_FEATURE_ASR, "hcall-asr"},
  42. {FW_FEATURE_DEBUG, "hcall-debug"},
  43. {FW_FEATURE_PERF, "hcall-perf"},
  44. {FW_FEATURE_DUMP, "hcall-dump"},
  45. {FW_FEATURE_INTERRUPT, "hcall-interrupt"},
  46. {FW_FEATURE_MIGRATE, "hcall-migrate"},
  47. {FW_FEATURE_PERFMON, "hcall-perfmon"},
  48. {FW_FEATURE_CRQ, "hcall-crq"},
  49. {FW_FEATURE_VIO, "hcall-vio"},
  50. {FW_FEATURE_RDMA, "hcall-rdma"},
  51. {FW_FEATURE_LLAN, "hcall-lLAN"},
  52. {FW_FEATURE_BULK_REMOVE, "hcall-bulk"},
  53. {FW_FEATURE_XDABR, "hcall-xdabr"},
  54. {FW_FEATURE_PUT_TCE_IND | FW_FEATURE_STUFF_TCE,
  55. "hcall-multi-tce"},
  56. {FW_FEATURE_SPLPAR, "hcall-splpar"},
  57. {FW_FEATURE_VPHN, "hcall-vphn"},
  58. {FW_FEATURE_SET_MODE, "hcall-set-mode"},
  59. {FW_FEATURE_BEST_ENERGY, "hcall-best-energy-1*"},
  60. {FW_FEATURE_HPT_RESIZE, "hcall-hpt-resize"},
  61. {FW_FEATURE_BLOCK_REMOVE, "hcall-block-remove"},
  62. {FW_FEATURE_PAPR_SCM, "hcall-scm"},
  63. {FW_FEATURE_RPT_INVALIDATE, "hcall-rpt-invalidate"},
  64. {FW_FEATURE_ENERGY_SCALE_INFO, "hcall-energy-scale-info"},
  65. {FW_FEATURE_WATCHDOG, "hcall-watchdog"},
  66. };
  67. /* Build up the firmware features bitmask using the contents of
  68. * device-tree/ibm,hypertas-functions. Ultimately this functionality may
  69. * be moved into prom.c prom_init().
  70. */
  71. static void __init fw_hypertas_feature_init(const char *hypertas,
  72. unsigned long len)
  73. {
  74. const char *s;
  75. int i;
  76. pr_debug(" -> fw_hypertas_feature_init()\n");
  77. for (s = hypertas; s < hypertas + len; s += strlen(s) + 1) {
  78. for (i = 0; i < ARRAY_SIZE(hypertas_fw_features_table); i++) {
  79. const char *name = hypertas_fw_features_table[i].name;
  80. size_t size;
  81. /*
  82. * If there is a '*' at the end of name, only check
  83. * upto there
  84. */
  85. size = strlen(name);
  86. if (size && name[size - 1] == '*') {
  87. if (strncmp(name, s, size - 1))
  88. continue;
  89. } else if (strcmp(name, s))
  90. continue;
  91. /* we have a match */
  92. powerpc_firmware_features |=
  93. hypertas_fw_features_table[i].val;
  94. break;
  95. }
  96. }
  97. if (is_secure_guest() &&
  98. (powerpc_firmware_features & FW_FEATURE_PUT_TCE_IND)) {
  99. powerpc_firmware_features &= ~FW_FEATURE_PUT_TCE_IND;
  100. pr_debug("SVM: disabling PUT_TCE_IND firmware feature\n");
  101. }
  102. pr_debug(" <- fw_hypertas_feature_init()\n");
  103. }
  104. struct vec5_fw_feature {
  105. unsigned long val;
  106. unsigned int feature;
  107. };
  108. static __initdata struct vec5_fw_feature
  109. vec5_fw_features_table[] = {
  110. {FW_FEATURE_FORM1_AFFINITY, OV5_FORM1_AFFINITY},
  111. {FW_FEATURE_PRRN, OV5_PRRN},
  112. {FW_FEATURE_DRMEM_V2, OV5_DRMEM_V2},
  113. {FW_FEATURE_DRC_INFO, OV5_DRC_INFO},
  114. {FW_FEATURE_FORM2_AFFINITY, OV5_FORM2_AFFINITY},
  115. };
  116. static void __init fw_vec5_feature_init(const char *vec5, unsigned long len)
  117. {
  118. unsigned int index, feat;
  119. int i;
  120. pr_debug(" -> fw_vec5_feature_init()\n");
  121. for (i = 0; i < ARRAY_SIZE(vec5_fw_features_table); i++) {
  122. index = OV5_INDX(vec5_fw_features_table[i].feature);
  123. feat = OV5_FEAT(vec5_fw_features_table[i].feature);
  124. if (index < len && (vec5[index] & feat))
  125. powerpc_firmware_features |=
  126. vec5_fw_features_table[i].val;
  127. }
  128. pr_debug(" <- fw_vec5_feature_init()\n");
  129. }
  130. /*
  131. * Called very early, MMU is off, device-tree isn't unflattened
  132. */
  133. static int __init probe_fw_features(unsigned long node, const char *uname, int
  134. depth, void *data)
  135. {
  136. const char *prop;
  137. int len;
  138. static int hypertas_found;
  139. static int vec5_found;
  140. if (depth != 1)
  141. return 0;
  142. if (!strcmp(uname, "rtas") || !strcmp(uname, "rtas@0")) {
  143. prop = of_get_flat_dt_prop(node, "ibm,hypertas-functions",
  144. &len);
  145. if (prop) {
  146. powerpc_firmware_features |= FW_FEATURE_LPAR;
  147. fw_hypertas_feature_init(prop, len);
  148. }
  149. hypertas_found = 1;
  150. }
  151. if (!strcmp(uname, "chosen")) {
  152. prop = of_get_flat_dt_prop(node, "ibm,architecture-vec-5",
  153. &len);
  154. if (prop)
  155. fw_vec5_feature_init(prop, len);
  156. vec5_found = 1;
  157. }
  158. return hypertas_found && vec5_found;
  159. }
  160. void __init pseries_probe_fw_features(void)
  161. {
  162. of_scan_flat_dt(probe_fw_features, NULL);
  163. }