Path: blob/master/arch/powerpc/platforms/pseries/firmware.c
26481 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* pSeries firmware setup code.3*4* Portions from arch/powerpc/platforms/pseries/setup.c:5* Copyright (C) 1995 Linus Torvalds6* Adapted from 'alpha' version by Gary Thomas7* Modified by Cort Dougan ([email protected])8* Modified by PPC64 Team, IBM Corp9*10* Portions from arch/powerpc/kernel/firmware.c11* Copyright (C) 2001 Ben. Herrenschmidt ([email protected])12* Modifications for ppc64:13* Copyright (C) 2003 Dave Engebretsen <[email protected]>14* Copyright (C) 2005 Stephen Rothwell, IBM Corporation15*16* Copyright 2006 IBM Corporation.17*/181920#include <linux/of_fdt.h>21#include <asm/firmware.h>22#include <asm/prom.h>23#include <asm/udbg.h>24#include <asm/svm.h>2526#include "pseries.h"2728struct hypertas_fw_feature {29unsigned long val;30char * name;31};3233/*34* The names in this table match names in rtas/ibm,hypertas-functions. If the35* entry ends in a '*', only upto the '*' is matched. Otherwise the entire36* string must match.37*/38static __initdata struct hypertas_fw_feature39hypertas_fw_features_table[] = {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"},56{FW_FEATURE_BULK_REMOVE, "hcall-bulk"},57{FW_FEATURE_XDABR, "hcall-xdabr"},58{FW_FEATURE_PUT_TCE_IND | FW_FEATURE_STUFF_TCE,59"hcall-multi-tce"},60{FW_FEATURE_SPLPAR, "hcall-splpar"},61{FW_FEATURE_VPHN, "hcall-vphn"},62{FW_FEATURE_SET_MODE, "hcall-set-mode"},63{FW_FEATURE_BEST_ENERGY, "hcall-best-energy-1*"},64{FW_FEATURE_HPT_RESIZE, "hcall-hpt-resize"},65{FW_FEATURE_BLOCK_REMOVE, "hcall-block-remove"},66{FW_FEATURE_PAPR_SCM, "hcall-scm"},67{FW_FEATURE_RPT_INVALIDATE, "hcall-rpt-invalidate"},68{FW_FEATURE_ENERGY_SCALE_INFO, "hcall-energy-scale-info"},69{FW_FEATURE_WATCHDOG, "hcall-watchdog"},70{FW_FEATURE_PLPKS, "hcall-pks"},71};7273/* Build up the firmware features bitmask using the contents of74* device-tree/ibm,hypertas-functions. Ultimately this functionality may75* be moved into prom.c prom_init().76*/77static void __init fw_hypertas_feature_init(const char *hypertas,78unsigned long len)79{80const char *s;81int i;8283pr_debug(" -> fw_hypertas_feature_init()\n");8485for (s = hypertas; s < hypertas + len; s += strlen(s) + 1) {86for (i = 0; i < ARRAY_SIZE(hypertas_fw_features_table); i++) {87const char *name = hypertas_fw_features_table[i].name;88size_t size;8990/*91* If there is a '*' at the end of name, only check92* upto there93*/94size = strlen(name);95if (size && name[size - 1] == '*') {96if (strncmp(name, s, size - 1))97continue;98} else if (strcmp(name, s))99continue;100101/* we have a match */102powerpc_firmware_features |=103hypertas_fw_features_table[i].val;104break;105}106}107108if (is_secure_guest() &&109(powerpc_firmware_features & FW_FEATURE_PUT_TCE_IND)) {110powerpc_firmware_features &= ~FW_FEATURE_PUT_TCE_IND;111pr_debug("SVM: disabling PUT_TCE_IND firmware feature\n");112}113114pr_debug(" <- fw_hypertas_feature_init()\n");115}116117struct vec5_fw_feature {118unsigned long val;119unsigned int feature;120};121122static __initdata struct vec5_fw_feature123vec5_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};130131static void __init fw_vec5_feature_init(const char *vec5, unsigned long len)132{133unsigned int index, feat;134int i;135136pr_debug(" -> fw_vec5_feature_init()\n");137138for (i = 0; i < ARRAY_SIZE(vec5_fw_features_table); i++) {139index = OV5_INDX(vec5_fw_features_table[i].feature);140feat = OV5_FEAT(vec5_fw_features_table[i].feature);141142if (index < len && (vec5[index] & feat))143powerpc_firmware_features |=144vec5_fw_features_table[i].val;145}146147pr_debug(" <- fw_vec5_feature_init()\n");148}149150/*151* Called very early, MMU is off, device-tree isn't unflattened152*/153static int __init probe_fw_features(unsigned long node, const char *uname, int154depth, void *data)155{156const char *prop;157int len;158static int hypertas_found;159static int vec5_found;160161if (depth != 1)162return 0;163164if (!strcmp(uname, "rtas") || !strcmp(uname, "rtas@0")) {165prop = of_get_flat_dt_prop(node, "ibm,hypertas-functions",166&len);167if (prop) {168powerpc_firmware_features |= FW_FEATURE_LPAR;169fw_hypertas_feature_init(prop, len);170}171172hypertas_found = 1;173}174175if (!strcmp(uname, "chosen")) {176prop = of_get_flat_dt_prop(node, "ibm,architecture-vec-5",177&len);178if (prop)179fw_vec5_feature_init(prop, len);180181vec5_found = 1;182}183184return hypertas_found && vec5_found;185}186187void __init pseries_probe_fw_features(void)188{189of_scan_flat_dt(probe_fw_features, NULL);190}191192193