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