Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  pSeries firmware setup code.
0004  *
0005  *  Portions from arch/powerpc/platforms/pseries/setup.c:
0006  *   Copyright (C) 1995  Linus Torvalds
0007  *   Adapted from 'alpha' version by Gary Thomas
0008  *   Modified by Cort Dougan (cort@cs.nmt.edu)
0009  *   Modified by PPC64 Team, IBM Corp
0010  *
0011  *  Portions from arch/powerpc/kernel/firmware.c
0012  *   Copyright (C) 2001 Ben. Herrenschmidt (benh@kernel.crashing.org)
0013  *   Modifications for ppc64:
0014  *    Copyright (C) 2003 Dave Engebretsen <engebret@us.ibm.com>
0015  *    Copyright (C) 2005 Stephen Rothwell, IBM Corporation
0016  *
0017  *  Copyright 2006 IBM Corporation.
0018  */
0019 
0020 
0021 #include <linux/of_fdt.h>
0022 #include <asm/firmware.h>
0023 #include <asm/prom.h>
0024 #include <asm/udbg.h>
0025 #include <asm/svm.h>
0026 
0027 #include "pseries.h"
0028 
0029 struct hypertas_fw_feature {
0030     unsigned long val;
0031     char * name;
0032 };
0033 
0034 /*
0035  * The names in this table match names in rtas/ibm,hypertas-functions.  If the
0036  * entry ends in a '*', only upto the '*' is matched.  Otherwise the entire
0037  * string must match.
0038  */
0039 static __initdata struct hypertas_fw_feature
0040 hypertas_fw_features_table[] = {
0041     {FW_FEATURE_PFT,        "hcall-pft"},
0042     {FW_FEATURE_TCE,        "hcall-tce"},
0043     {FW_FEATURE_SPRG0,      "hcall-sprg0"},
0044     {FW_FEATURE_DABR,       "hcall-dabr"},
0045     {FW_FEATURE_COPY,       "hcall-copy"},
0046     {FW_FEATURE_ASR,        "hcall-asr"},
0047     {FW_FEATURE_DEBUG,      "hcall-debug"},
0048     {FW_FEATURE_PERF,       "hcall-perf"},
0049     {FW_FEATURE_DUMP,       "hcall-dump"},
0050     {FW_FEATURE_INTERRUPT,      "hcall-interrupt"},
0051     {FW_FEATURE_MIGRATE,        "hcall-migrate"},
0052     {FW_FEATURE_PERFMON,        "hcall-perfmon"},
0053     {FW_FEATURE_CRQ,        "hcall-crq"},
0054     {FW_FEATURE_VIO,        "hcall-vio"},
0055     {FW_FEATURE_RDMA,       "hcall-rdma"},
0056     {FW_FEATURE_LLAN,       "hcall-lLAN"},
0057     {FW_FEATURE_BULK_REMOVE,    "hcall-bulk"},
0058     {FW_FEATURE_XDABR,      "hcall-xdabr"},
0059     {FW_FEATURE_PUT_TCE_IND | FW_FEATURE_STUFF_TCE,
0060                     "hcall-multi-tce"},
0061     {FW_FEATURE_SPLPAR,     "hcall-splpar"},
0062     {FW_FEATURE_VPHN,       "hcall-vphn"},
0063     {FW_FEATURE_SET_MODE,       "hcall-set-mode"},
0064     {FW_FEATURE_BEST_ENERGY,    "hcall-best-energy-1*"},
0065     {FW_FEATURE_HPT_RESIZE,     "hcall-hpt-resize"},
0066     {FW_FEATURE_BLOCK_REMOVE,   "hcall-block-remove"},
0067     {FW_FEATURE_PAPR_SCM,       "hcall-scm"},
0068     {FW_FEATURE_RPT_INVALIDATE, "hcall-rpt-invalidate"},
0069     {FW_FEATURE_ENERGY_SCALE_INFO,  "hcall-energy-scale-info"},
0070     {FW_FEATURE_WATCHDOG,       "hcall-watchdog"},
0071 };
0072 
0073 /* Build up the firmware features bitmask using the contents of
0074  * device-tree/ibm,hypertas-functions.  Ultimately this functionality may
0075  * be moved into prom.c prom_init().
0076  */
0077 static void __init fw_hypertas_feature_init(const char *hypertas,
0078                         unsigned long len)
0079 {
0080     const char *s;
0081     int i;
0082 
0083     pr_debug(" -> fw_hypertas_feature_init()\n");
0084 
0085     for (s = hypertas; s < hypertas + len; s += strlen(s) + 1) {
0086         for (i = 0; i < ARRAY_SIZE(hypertas_fw_features_table); i++) {
0087             const char *name = hypertas_fw_features_table[i].name;
0088             size_t size;
0089 
0090             /*
0091              * If there is a '*' at the end of name, only check
0092              * upto there
0093              */
0094             size = strlen(name);
0095             if (size && name[size - 1] == '*') {
0096                 if (strncmp(name, s, size - 1))
0097                     continue;
0098             } else if (strcmp(name, s))
0099                 continue;
0100 
0101             /* we have a match */
0102             powerpc_firmware_features |=
0103                 hypertas_fw_features_table[i].val;
0104             break;
0105         }
0106     }
0107 
0108     if (is_secure_guest() &&
0109         (powerpc_firmware_features & FW_FEATURE_PUT_TCE_IND)) {
0110         powerpc_firmware_features &= ~FW_FEATURE_PUT_TCE_IND;
0111         pr_debug("SVM: disabling PUT_TCE_IND firmware feature\n");
0112     }
0113 
0114     pr_debug(" <- fw_hypertas_feature_init()\n");
0115 }
0116 
0117 struct vec5_fw_feature {
0118     unsigned long   val;
0119     unsigned int    feature;
0120 };
0121 
0122 static __initdata struct vec5_fw_feature
0123 vec5_fw_features_table[] = {
0124     {FW_FEATURE_FORM1_AFFINITY, OV5_FORM1_AFFINITY},
0125     {FW_FEATURE_PRRN,       OV5_PRRN},
0126     {FW_FEATURE_DRMEM_V2,       OV5_DRMEM_V2},
0127     {FW_FEATURE_DRC_INFO,       OV5_DRC_INFO},
0128     {FW_FEATURE_FORM2_AFFINITY, OV5_FORM2_AFFINITY},
0129 };
0130 
0131 static void __init fw_vec5_feature_init(const char *vec5, unsigned long len)
0132 {
0133     unsigned int index, feat;
0134     int i;
0135 
0136     pr_debug(" -> fw_vec5_feature_init()\n");
0137 
0138     for (i = 0; i < ARRAY_SIZE(vec5_fw_features_table); i++) {
0139         index = OV5_INDX(vec5_fw_features_table[i].feature);
0140         feat = OV5_FEAT(vec5_fw_features_table[i].feature);
0141 
0142         if (index < len && (vec5[index] & feat))
0143             powerpc_firmware_features |=
0144                 vec5_fw_features_table[i].val;
0145     }
0146 
0147     pr_debug(" <- fw_vec5_feature_init()\n");
0148 }
0149 
0150 /*
0151  * Called very early, MMU is off, device-tree isn't unflattened
0152  */
0153 static int __init probe_fw_features(unsigned long node, const char *uname, int
0154                     depth, void *data)
0155 {
0156     const char *prop;
0157     int len;
0158     static int hypertas_found;
0159     static int vec5_found;
0160 
0161     if (depth != 1)
0162         return 0;
0163 
0164     if (!strcmp(uname, "rtas") || !strcmp(uname, "rtas@0")) {
0165         prop = of_get_flat_dt_prop(node, "ibm,hypertas-functions",
0166                        &len);
0167         if (prop) {
0168             powerpc_firmware_features |= FW_FEATURE_LPAR;
0169             fw_hypertas_feature_init(prop, len);
0170         }
0171 
0172         hypertas_found = 1;
0173     }
0174 
0175     if (!strcmp(uname, "chosen")) {
0176         prop = of_get_flat_dt_prop(node, "ibm,architecture-vec-5",
0177                        &len);
0178         if (prop)
0179             fw_vec5_feature_init(prop, len);
0180 
0181         vec5_found = 1;
0182     }
0183 
0184     return hypertas_found && vec5_found;
0185 }
0186 
0187 void __init pseries_probe_fw_features(void)
0188 {
0189     of_scan_flat_dt(probe_fw_features, NULL);
0190 }