12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21965746bSMichael Ellerman /*
31965746bSMichael Ellerman * pSeries firmware setup code.
41965746bSMichael Ellerman *
51965746bSMichael Ellerman * Portions from arch/powerpc/platforms/pseries/setup.c:
61965746bSMichael Ellerman * Copyright (C) 1995 Linus Torvalds
71965746bSMichael Ellerman * Adapted from 'alpha' version by Gary Thomas
81965746bSMichael Ellerman * Modified by Cort Dougan (cort@cs.nmt.edu)
91965746bSMichael Ellerman * Modified by PPC64 Team, IBM Corp
101965746bSMichael Ellerman *
111965746bSMichael Ellerman * Portions from arch/powerpc/kernel/firmware.c
121965746bSMichael Ellerman * Copyright (C) 2001 Ben. Herrenschmidt (benh@kernel.crashing.org)
131965746bSMichael Ellerman * Modifications for ppc64:
141965746bSMichael Ellerman * Copyright (C) 2003 Dave Engebretsen <engebret@us.ibm.com>
151965746bSMichael Ellerman * Copyright (C) 2005 Stephen Rothwell, IBM Corporation
161965746bSMichael Ellerman *
171965746bSMichael Ellerman * Copyright 2006 IBM Corporation.
181965746bSMichael Ellerman */
191965746bSMichael Ellerman
201965746bSMichael Ellerman
213808a889SBenjamin Herrenschmidt #include <linux/of_fdt.h>
221965746bSMichael Ellerman #include <asm/firmware.h>
231965746bSMichael Ellerman #include <asm/prom.h>
24aa39be09Swill schmidt #include <asm/udbg.h>
25978bff4eSAlexey Kardashevskiy #include <asm/svm.h>
261965746bSMichael Ellerman
273ff1999bSMichael Ellerman #include "pseries.h"
281965746bSMichael Ellerman
29f0ff7eb4SNathan Fontenot struct hypertas_fw_feature {
301965746bSMichael Ellerman unsigned long val;
311965746bSMichael Ellerman char * name;
32f0ff7eb4SNathan Fontenot };
331965746bSMichael Ellerman
342f1d4ea7SMichael Neuling /*
352f1d4ea7SMichael Neuling * The names in this table match names in rtas/ibm,hypertas-functions. If the
362f1d4ea7SMichael Neuling * entry ends in a '*', only upto the '*' is matched. Otherwise the entire
372f1d4ea7SMichael Neuling * string must match.
382f1d4ea7SMichael Neuling */
39f0ff7eb4SNathan Fontenot static __initdata struct hypertas_fw_feature
40f0ff7eb4SNathan Fontenot hypertas_fw_features_table[] = {
411965746bSMichael Ellerman {FW_FEATURE_PFT, "hcall-pft"},
421965746bSMichael Ellerman {FW_FEATURE_TCE, "hcall-tce"},
431965746bSMichael Ellerman {FW_FEATURE_SPRG0, "hcall-sprg0"},
441965746bSMichael Ellerman {FW_FEATURE_DABR, "hcall-dabr"},
451965746bSMichael Ellerman {FW_FEATURE_COPY, "hcall-copy"},
461965746bSMichael Ellerman {FW_FEATURE_ASR, "hcall-asr"},
471965746bSMichael Ellerman {FW_FEATURE_DEBUG, "hcall-debug"},
481965746bSMichael Ellerman {FW_FEATURE_PERF, "hcall-perf"},
491965746bSMichael Ellerman {FW_FEATURE_DUMP, "hcall-dump"},
501965746bSMichael Ellerman {FW_FEATURE_INTERRUPT, "hcall-interrupt"},
511965746bSMichael Ellerman {FW_FEATURE_MIGRATE, "hcall-migrate"},
521965746bSMichael Ellerman {FW_FEATURE_PERFMON, "hcall-perfmon"},
531965746bSMichael Ellerman {FW_FEATURE_CRQ, "hcall-crq"},
541965746bSMichael Ellerman {FW_FEATURE_VIO, "hcall-vio"},
551965746bSMichael Ellerman {FW_FEATURE_RDMA, "hcall-rdma"},
561965746bSMichael Ellerman {FW_FEATURE_LLAN, "hcall-lLAN"},
57b6dcde5cSAnton Blanchard {FW_FEATURE_BULK_REMOVE, "hcall-bulk"},
581965746bSMichael Ellerman {FW_FEATURE_XDABR, "hcall-xdabr"},
5917a0364cSAlexey Kardashevskiy {FW_FEATURE_PUT_TCE_IND | FW_FEATURE_STUFF_TCE,
6017a0364cSAlexey Kardashevskiy "hcall-multi-tce"},
611965746bSMichael Ellerman {FW_FEATURE_SPLPAR, "hcall-splpar"},
6236f567b4SJesse Larrew {FW_FEATURE_VPHN, "hcall-vphn"},
63d8f48eccSIan Munsie {FW_FEATURE_SET_MODE, "hcall-set-mode"},
640388c79cSMichael Neuling {FW_FEATURE_BEST_ENERGY, "hcall-best-energy-1*"},
6564b40ffbSDavid Gibson {FW_FEATURE_HPT_RESIZE, "hcall-hpt-resize"},
665600fbe3SLaurent Dufour {FW_FEATURE_BLOCK_REMOVE, "hcall-block-remove"},
674c5d87dbSOliver O'Halloran {FW_FEATURE_PAPR_SCM, "hcall-scm"},
68bf6b7661SAneesh Kumar K.V {FW_FEATURE_RPT_INVALIDATE, "hcall-rpt-invalidate"},
693c14b734SPratik R. Sampat {FW_FEATURE_ENERGY_SCALE_INFO, "hcall-energy-scale-info"},
701621563eSScott Cheloha {FW_FEATURE_WATCHDOG, "hcall-watchdog"},
71*df9cad09SAndrew Donnellan {FW_FEATURE_PLPKS, "hcall-pks"},
721965746bSMichael Ellerman };
731965746bSMichael Ellerman
741965746bSMichael Ellerman /* Build up the firmware features bitmask using the contents of
751965746bSMichael Ellerman * device-tree/ibm,hypertas-functions. Ultimately this functionality may
761965746bSMichael Ellerman * be moved into prom.c prom_init().
771965746bSMichael Ellerman */
fw_hypertas_feature_init(const char * hypertas,unsigned long len)783808a889SBenjamin Herrenschmidt static void __init fw_hypertas_feature_init(const char *hypertas,
793808a889SBenjamin Herrenschmidt unsigned long len)
801965746bSMichael Ellerman {
81ca8ffc97SMichael Neuling const char *s;
82ca8ffc97SMichael Neuling int i;
831965746bSMichael Ellerman
84f0ff7eb4SNathan Fontenot pr_debug(" -> fw_hypertas_feature_init()\n");
851965746bSMichael Ellerman
861965746bSMichael Ellerman for (s = hypertas; s < hypertas + len; s += strlen(s) + 1) {
87f0ff7eb4SNathan Fontenot for (i = 0; i < ARRAY_SIZE(hypertas_fw_features_table); i++) {
88f0ff7eb4SNathan Fontenot const char *name = hypertas_fw_features_table[i].name;
892f1d4ea7SMichael Neuling size_t size;
9043c0ea60SNathan Fontenot
912f1d4ea7SMichael Neuling /*
922f1d4ea7SMichael Neuling * If there is a '*' at the end of name, only check
932f1d4ea7SMichael Neuling * upto there
942f1d4ea7SMichael Neuling */
952f1d4ea7SMichael Neuling size = strlen(name);
962f1d4ea7SMichael Neuling if (size && name[size - 1] == '*') {
972f1d4ea7SMichael Neuling if (strncmp(name, s, size - 1))
982f1d4ea7SMichael Neuling continue;
992f1d4ea7SMichael Neuling } else if (strcmp(name, s))
1001965746bSMichael Ellerman continue;
1011965746bSMichael Ellerman
1021965746bSMichael Ellerman /* we have a match */
103d0160bf0SMichael Ellerman powerpc_firmware_features |=
104f0ff7eb4SNathan Fontenot hypertas_fw_features_table[i].val;
1051965746bSMichael Ellerman break;
1061965746bSMichael Ellerman }
1071965746bSMichael Ellerman }
1081965746bSMichael Ellerman
109978bff4eSAlexey Kardashevskiy if (is_secure_guest() &&
110978bff4eSAlexey Kardashevskiy (powerpc_firmware_features & FW_FEATURE_PUT_TCE_IND)) {
111978bff4eSAlexey Kardashevskiy powerpc_firmware_features &= ~FW_FEATURE_PUT_TCE_IND;
112978bff4eSAlexey Kardashevskiy pr_debug("SVM: disabling PUT_TCE_IND firmware feature\n");
113978bff4eSAlexey Kardashevskiy }
114978bff4eSAlexey Kardashevskiy
115f0ff7eb4SNathan Fontenot pr_debug(" <- fw_hypertas_feature_init()\n");
116f0ff7eb4SNathan Fontenot }
117f0ff7eb4SNathan Fontenot
118f0ff7eb4SNathan Fontenot struct vec5_fw_feature {
119f0ff7eb4SNathan Fontenot unsigned long val;
120f0ff7eb4SNathan Fontenot unsigned int feature;
121f0ff7eb4SNathan Fontenot };
122f0ff7eb4SNathan Fontenot
123f0ff7eb4SNathan Fontenot static __initdata struct vec5_fw_feature
124f0ff7eb4SNathan Fontenot vec5_fw_features_table[] = {
1250eacd06bSAneesh Kumar K.V {FW_FEATURE_FORM1_AFFINITY, OV5_FORM1_AFFINITY},
1265d88aa85SJesse Larrew {FW_FEATURE_PRRN, OV5_PRRN},
1270c38ed6fSNathan Fontenot {FW_FEATURE_DRMEM_V2, OV5_DRMEM_V2},
1283f38000eSMichael Bringmann {FW_FEATURE_DRC_INFO, OV5_DRC_INFO},
1291c6b5a7eSAneesh Kumar K.V {FW_FEATURE_FORM2_AFFINITY, OV5_FORM2_AFFINITY},
130f0ff7eb4SNathan Fontenot };
131f0ff7eb4SNathan Fontenot
fw_vec5_feature_init(const char * vec5,unsigned long len)1323808a889SBenjamin Herrenschmidt static void __init fw_vec5_feature_init(const char *vec5, unsigned long len)
133f0ff7eb4SNathan Fontenot {
134f0ff7eb4SNathan Fontenot unsigned int index, feat;
135f0ff7eb4SNathan Fontenot int i;
136f0ff7eb4SNathan Fontenot
137f0ff7eb4SNathan Fontenot pr_debug(" -> fw_vec5_feature_init()\n");
138f0ff7eb4SNathan Fontenot
139f0ff7eb4SNathan Fontenot for (i = 0; i < ARRAY_SIZE(vec5_fw_features_table); i++) {
140f0ff7eb4SNathan Fontenot index = OV5_INDX(vec5_fw_features_table[i].feature);
141f0ff7eb4SNathan Fontenot feat = OV5_FEAT(vec5_fw_features_table[i].feature);
142f0ff7eb4SNathan Fontenot
1433f4ab2f8SPaul Mackerras if (index < len && (vec5[index] & feat))
144f0ff7eb4SNathan Fontenot powerpc_firmware_features |=
145f0ff7eb4SNathan Fontenot vec5_fw_features_table[i].val;
146f0ff7eb4SNathan Fontenot }
147f0ff7eb4SNathan Fontenot
148f0ff7eb4SNathan Fontenot pr_debug(" <- fw_vec5_feature_init()\n");
1491965746bSMichael Ellerman }
1503808a889SBenjamin Herrenschmidt
1513808a889SBenjamin Herrenschmidt /*
1523808a889SBenjamin Herrenschmidt * Called very early, MMU is off, device-tree isn't unflattened
1533808a889SBenjamin Herrenschmidt */
probe_fw_features(unsigned long node,const char * uname,int depth,void * data)1543808a889SBenjamin Herrenschmidt static int __init probe_fw_features(unsigned long node, const char *uname, int
1553808a889SBenjamin Herrenschmidt depth, void *data)
1563808a889SBenjamin Herrenschmidt {
1573808a889SBenjamin Herrenschmidt const char *prop;
1583808a889SBenjamin Herrenschmidt int len;
1593808a889SBenjamin Herrenschmidt static int hypertas_found;
1603808a889SBenjamin Herrenschmidt static int vec5_found;
1613808a889SBenjamin Herrenschmidt
1623808a889SBenjamin Herrenschmidt if (depth != 1)
1633808a889SBenjamin Herrenschmidt return 0;
1643808a889SBenjamin Herrenschmidt
1653808a889SBenjamin Herrenschmidt if (!strcmp(uname, "rtas") || !strcmp(uname, "rtas@0")) {
1663808a889SBenjamin Herrenschmidt prop = of_get_flat_dt_prop(node, "ibm,hypertas-functions",
1673808a889SBenjamin Herrenschmidt &len);
1683808a889SBenjamin Herrenschmidt if (prop) {
1693808a889SBenjamin Herrenschmidt powerpc_firmware_features |= FW_FEATURE_LPAR;
1703808a889SBenjamin Herrenschmidt fw_hypertas_feature_init(prop, len);
1713808a889SBenjamin Herrenschmidt }
1723808a889SBenjamin Herrenschmidt
1733808a889SBenjamin Herrenschmidt hypertas_found = 1;
1743808a889SBenjamin Herrenschmidt }
1753808a889SBenjamin Herrenschmidt
1763808a889SBenjamin Herrenschmidt if (!strcmp(uname, "chosen")) {
1773808a889SBenjamin Herrenschmidt prop = of_get_flat_dt_prop(node, "ibm,architecture-vec-5",
1783808a889SBenjamin Herrenschmidt &len);
1793808a889SBenjamin Herrenschmidt if (prop)
1803808a889SBenjamin Herrenschmidt fw_vec5_feature_init(prop, len);
1813808a889SBenjamin Herrenschmidt
1823808a889SBenjamin Herrenschmidt vec5_found = 1;
1833808a889SBenjamin Herrenschmidt }
1843808a889SBenjamin Herrenschmidt
1853808a889SBenjamin Herrenschmidt return hypertas_found && vec5_found;
1863808a889SBenjamin Herrenschmidt }
1873808a889SBenjamin Herrenschmidt
pseries_probe_fw_features(void)1883808a889SBenjamin Herrenschmidt void __init pseries_probe_fw_features(void)
1893808a889SBenjamin Herrenschmidt {
1903808a889SBenjamin Herrenschmidt of_scan_flat_dt(probe_fw_features, NULL);
1913808a889SBenjamin Herrenschmidt }
192