firmware.c 4.8 KB

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