]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - arch/powerpc/platforms/pseries/firmware.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
[mirror_ubuntu-kernels.git] / arch / powerpc / platforms / pseries / firmware.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
1965746b
ME
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.
1965746b
ME
18 */
19
1965746b 20
3808a889 21#include <linux/of_fdt.h>
1965746b
ME
22#include <asm/firmware.h>
23#include <asm/prom.h>
aa39be09 24#include <asm/udbg.h>
1965746b 25
3ff1999b 26#include "pseries.h"
1965746b 27
f0ff7eb4 28struct hypertas_fw_feature {
1965746b
ME
29 unsigned long val;
30 char * name;
f0ff7eb4 31};
1965746b 32
2f1d4ea7
MN
33/*
34 * The names in this table match names in rtas/ibm,hypertas-functions. If the
35 * entry ends in a '*', only upto the '*' is matched. Otherwise the entire
36 * string must match.
37 */
f0ff7eb4
NF
38static __initdata struct hypertas_fw_feature
39hypertas_fw_features_table[] = {
1965746b
ME
40 {FW_FEATURE_PFT, "hcall-pft"},
41 {FW_FEATURE_TCE, "hcall-tce"},
42 {FW_FEATURE_SPRG0, "hcall-sprg0"},
43 {FW_FEATURE_DABR, "hcall-dabr"},
44 {FW_FEATURE_COPY, "hcall-copy"},
45 {FW_FEATURE_ASR, "hcall-asr"},
46 {FW_FEATURE_DEBUG, "hcall-debug"},
47 {FW_FEATURE_PERF, "hcall-perf"},
48 {FW_FEATURE_DUMP, "hcall-dump"},
49 {FW_FEATURE_INTERRUPT, "hcall-interrupt"},
50 {FW_FEATURE_MIGRATE, "hcall-migrate"},
51 {FW_FEATURE_PERFMON, "hcall-perfmon"},
52 {FW_FEATURE_CRQ, "hcall-crq"},
53 {FW_FEATURE_VIO, "hcall-vio"},
54 {FW_FEATURE_RDMA, "hcall-rdma"},
55 {FW_FEATURE_LLAN, "hcall-lLAN"},
b6dcde5c 56 {FW_FEATURE_BULK_REMOVE, "hcall-bulk"},
1965746b
ME
57 {FW_FEATURE_XDABR, "hcall-xdabr"},
58 {FW_FEATURE_MULTITCE, "hcall-multi-tce"},
59 {FW_FEATURE_SPLPAR, "hcall-splpar"},
36f567b4 60 {FW_FEATURE_VPHN, "hcall-vphn"},
d8f48ecc 61 {FW_FEATURE_SET_MODE, "hcall-set-mode"},
0388c79c 62 {FW_FEATURE_BEST_ENERGY, "hcall-best-energy-1*"},
64b40ffb 63 {FW_FEATURE_HPT_RESIZE, "hcall-hpt-resize"},
5600fbe3 64 {FW_FEATURE_BLOCK_REMOVE, "hcall-block-remove"},
4c5d87db 65 {FW_FEATURE_PAPR_SCM, "hcall-scm"},
1965746b
ME
66};
67
68/* Build up the firmware features bitmask using the contents of
69 * device-tree/ibm,hypertas-functions. Ultimately this functionality may
70 * be moved into prom.c prom_init().
71 */
3808a889
BH
72static void __init fw_hypertas_feature_init(const char *hypertas,
73 unsigned long len)
1965746b 74{
ca8ffc97
MN
75 const char *s;
76 int i;
1965746b 77
f0ff7eb4 78 pr_debug(" -> fw_hypertas_feature_init()\n");
1965746b 79
1965746b 80 for (s = hypertas; s < hypertas + len; s += strlen(s) + 1) {
f0ff7eb4
NF
81 for (i = 0; i < ARRAY_SIZE(hypertas_fw_features_table); i++) {
82 const char *name = hypertas_fw_features_table[i].name;
2f1d4ea7 83 size_t size;
43c0ea60 84
2f1d4ea7
MN
85 /*
86 * If there is a '*' at the end of name, only check
87 * upto there
88 */
89 size = strlen(name);
90 if (size && name[size - 1] == '*') {
91 if (strncmp(name, s, size - 1))
92 continue;
93 } else if (strcmp(name, s))
1965746b
ME
94 continue;
95
96 /* we have a match */
d0160bf0 97 powerpc_firmware_features |=
f0ff7eb4 98 hypertas_fw_features_table[i].val;
1965746b
ME
99 break;
100 }
101 }
102
f0ff7eb4
NF
103 pr_debug(" <- fw_hypertas_feature_init()\n");
104}
105
106struct vec5_fw_feature {
107 unsigned long val;
108 unsigned int feature;
109};
110
111static __initdata struct vec5_fw_feature
112vec5_fw_features_table[] = {
113 {FW_FEATURE_TYPE1_AFFINITY, OV5_TYPE1_AFFINITY},
5d88aa85 114 {FW_FEATURE_PRRN, OV5_PRRN},
0c38ed6f 115 {FW_FEATURE_DRMEM_V2, OV5_DRMEM_V2},
3f38000e 116 {FW_FEATURE_DRC_INFO, OV5_DRC_INFO},
f0ff7eb4
NF
117};
118
3808a889 119static void __init fw_vec5_feature_init(const char *vec5, unsigned long len)
f0ff7eb4
NF
120{
121 unsigned int index, feat;
122 int i;
123
124 pr_debug(" -> fw_vec5_feature_init()\n");
125
126 for (i = 0; i < ARRAY_SIZE(vec5_fw_features_table); i++) {
127 index = OV5_INDX(vec5_fw_features_table[i].feature);
128 feat = OV5_FEAT(vec5_fw_features_table[i].feature);
129
3f4ab2f8 130 if (index < len && (vec5[index] & feat))
f0ff7eb4
NF
131 powerpc_firmware_features |=
132 vec5_fw_features_table[i].val;
133 }
134
135 pr_debug(" <- fw_vec5_feature_init()\n");
1965746b 136}
3808a889
BH
137
138/*
139 * Called very early, MMU is off, device-tree isn't unflattened
140 */
141static int __init probe_fw_features(unsigned long node, const char *uname, int
142 depth, void *data)
143{
144 const char *prop;
145 int len;
146 static int hypertas_found;
147 static int vec5_found;
148
149 if (depth != 1)
150 return 0;
151
152 if (!strcmp(uname, "rtas") || !strcmp(uname, "rtas@0")) {
153 prop = of_get_flat_dt_prop(node, "ibm,hypertas-functions",
154 &len);
155 if (prop) {
156 powerpc_firmware_features |= FW_FEATURE_LPAR;
157 fw_hypertas_feature_init(prop, len);
158 }
159
160 hypertas_found = 1;
161 }
162
163 if (!strcmp(uname, "chosen")) {
164 prop = of_get_flat_dt_prop(node, "ibm,architecture-vec-5",
165 &len);
166 if (prop)
167 fw_vec5_feature_init(prop, len);
168
169 vec5_found = 1;
170 }
171
172 return hypertas_found && vec5_found;
173}
174
175void __init pseries_probe_fw_features(void)
176{
177 of_scan_flat_dt(probe_fw_features, NULL);
178}