Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 1 | /* |
| 2 | * pSeries firmware setup code. |
| 3 | * |
| 4 | * Portions from arch/powerpc/platforms/pseries/setup.c: |
| 5 | * Copyright (C) 1995 Linus Torvalds |
| 6 | * Adapted from 'alpha' version by Gary Thomas |
| 7 | * Modified by Cort Dougan (cort@cs.nmt.edu) |
| 8 | * Modified by PPC64 Team, IBM Corp |
| 9 | * |
| 10 | * Portions from arch/powerpc/kernel/firmware.c |
| 11 | * Copyright (C) 2001 Ben. Herrenschmidt (benh@kernel.crashing.org) |
| 12 | * Modifications for ppc64: |
| 13 | * Copyright (C) 2003 Dave Engebretsen <engebret@us.ibm.com> |
| 14 | * Copyright (C) 2005 Stephen Rothwell, IBM Corporation |
| 15 | * |
| 16 | * Copyright 2006 IBM Corporation. |
| 17 | * |
| 18 | * This program is free software; you can redistribute it and/or |
| 19 | * modify it under the terms of the GNU General Public License |
| 20 | * as published by the Free Software Foundation; either version |
| 21 | * 2 of the License, or (at your option) any later version. |
| 22 | */ |
| 23 | |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 24 | |
Benjamin Herrenschmidt | 3808a88 | 2016-07-05 15:03:48 +1000 | [diff] [blame] | 25 | #include <linux/of_fdt.h> |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 26 | #include <asm/firmware.h> |
| 27 | #include <asm/prom.h> |
will schmidt | aa39be0 | 2007-10-30 06:24:19 +1100 | [diff] [blame] | 28 | #include <asm/udbg.h> |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 29 | |
Michael Ellerman | 3ff1999 | 2008-05-08 14:27:21 +1000 | [diff] [blame] | 30 | #include "pseries.h" |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 31 | |
Nathan Fontenot | f0ff7eb | 2013-04-24 05:57:18 +0000 | [diff] [blame] | 32 | struct hypertas_fw_feature { |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 33 | unsigned long val; |
| 34 | char * name; |
Nathan Fontenot | f0ff7eb | 2013-04-24 05:57:18 +0000 | [diff] [blame] | 35 | }; |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 36 | |
Michael Neuling | 2f1d4ea | 2012-11-06 14:49:15 +0000 | [diff] [blame] | 37 | /* |
| 38 | * The names in this table match names in rtas/ibm,hypertas-functions. If the |
| 39 | * entry ends in a '*', only upto the '*' is matched. Otherwise the entire |
| 40 | * string must match. |
| 41 | */ |
Nathan Fontenot | f0ff7eb | 2013-04-24 05:57:18 +0000 | [diff] [blame] | 42 | static __initdata struct hypertas_fw_feature |
| 43 | hypertas_fw_features_table[] = { |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 44 | {FW_FEATURE_PFT, "hcall-pft"}, |
| 45 | {FW_FEATURE_TCE, "hcall-tce"}, |
| 46 | {FW_FEATURE_SPRG0, "hcall-sprg0"}, |
| 47 | {FW_FEATURE_DABR, "hcall-dabr"}, |
| 48 | {FW_FEATURE_COPY, "hcall-copy"}, |
| 49 | {FW_FEATURE_ASR, "hcall-asr"}, |
| 50 | {FW_FEATURE_DEBUG, "hcall-debug"}, |
| 51 | {FW_FEATURE_PERF, "hcall-perf"}, |
| 52 | {FW_FEATURE_DUMP, "hcall-dump"}, |
| 53 | {FW_FEATURE_INTERRUPT, "hcall-interrupt"}, |
| 54 | {FW_FEATURE_MIGRATE, "hcall-migrate"}, |
| 55 | {FW_FEATURE_PERFMON, "hcall-perfmon"}, |
| 56 | {FW_FEATURE_CRQ, "hcall-crq"}, |
| 57 | {FW_FEATURE_VIO, "hcall-vio"}, |
| 58 | {FW_FEATURE_RDMA, "hcall-rdma"}, |
| 59 | {FW_FEATURE_LLAN, "hcall-lLAN"}, |
Anton Blanchard | b6dcde5 | 2009-10-11 21:47:34 +0000 | [diff] [blame] | 60 | {FW_FEATURE_BULK_REMOVE, "hcall-bulk"}, |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 61 | {FW_FEATURE_XDABR, "hcall-xdabr"}, |
| 62 | {FW_FEATURE_MULTITCE, "hcall-multi-tce"}, |
| 63 | {FW_FEATURE_SPLPAR, "hcall-splpar"}, |
Jesse Larrew | 36f567b | 2010-11-09 13:24:48 +0000 | [diff] [blame] | 64 | {FW_FEATURE_VPHN, "hcall-vphn"}, |
Ian Munsie | d8f48ec | 2012-11-06 16:15:17 +1100 | [diff] [blame] | 65 | {FW_FEATURE_SET_MODE, "hcall-set-mode"}, |
Michael Neuling | 0388c79 | 2012-11-06 14:49:16 +0000 | [diff] [blame] | 66 | {FW_FEATURE_BEST_ENERGY, "hcall-best-energy-1*"}, |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /* Build up the firmware features bitmask using the contents of |
| 70 | * device-tree/ibm,hypertas-functions. Ultimately this functionality may |
| 71 | * be moved into prom.c prom_init(). |
| 72 | */ |
Benjamin Herrenschmidt | 3808a88 | 2016-07-05 15:03:48 +1000 | [diff] [blame] | 73 | static void __init fw_hypertas_feature_init(const char *hypertas, |
| 74 | unsigned long len) |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 75 | { |
Michael Neuling | ca8ffc9 | 2007-07-19 07:56:32 +1000 | [diff] [blame] | 76 | const char *s; |
| 77 | int i; |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 78 | |
Nathan Fontenot | f0ff7eb | 2013-04-24 05:57:18 +0000 | [diff] [blame] | 79 | pr_debug(" -> fw_hypertas_feature_init()\n"); |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 80 | |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 81 | for (s = hypertas; s < hypertas + len; s += strlen(s) + 1) { |
Nathan Fontenot | f0ff7eb | 2013-04-24 05:57:18 +0000 | [diff] [blame] | 82 | for (i = 0; i < ARRAY_SIZE(hypertas_fw_features_table); i++) { |
| 83 | const char *name = hypertas_fw_features_table[i].name; |
Michael Neuling | 2f1d4ea | 2012-11-06 14:49:15 +0000 | [diff] [blame] | 84 | size_t size; |
Nathan Fontenot | 43c0ea6 | 2013-04-24 05:55:08 +0000 | [diff] [blame] | 85 | |
Michael Neuling | 2f1d4ea | 2012-11-06 14:49:15 +0000 | [diff] [blame] | 86 | /* |
| 87 | * If there is a '*' at the end of name, only check |
| 88 | * upto there |
| 89 | */ |
| 90 | size = strlen(name); |
| 91 | if (size && name[size - 1] == '*') { |
| 92 | if (strncmp(name, s, size - 1)) |
| 93 | continue; |
| 94 | } else if (strcmp(name, s)) |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 95 | continue; |
| 96 | |
| 97 | /* we have a match */ |
Michael Ellerman | d0160bf | 2006-03-27 14:26:25 +1100 | [diff] [blame] | 98 | powerpc_firmware_features |= |
Nathan Fontenot | f0ff7eb | 2013-04-24 05:57:18 +0000 | [diff] [blame] | 99 | hypertas_fw_features_table[i].val; |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |
Nathan Fontenot | f0ff7eb | 2013-04-24 05:57:18 +0000 | [diff] [blame] | 104 | pr_debug(" <- fw_hypertas_feature_init()\n"); |
| 105 | } |
| 106 | |
| 107 | struct vec5_fw_feature { |
| 108 | unsigned long val; |
| 109 | unsigned int feature; |
| 110 | }; |
| 111 | |
| 112 | static __initdata struct vec5_fw_feature |
| 113 | vec5_fw_features_table[] = { |
| 114 | {FW_FEATURE_TYPE1_AFFINITY, OV5_TYPE1_AFFINITY}, |
Jesse Larrew | 5d88aa8 | 2013-04-24 06:00:35 +0000 | [diff] [blame] | 115 | {FW_FEATURE_PRRN, OV5_PRRN}, |
Nathan Fontenot | f0ff7eb | 2013-04-24 05:57:18 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
Benjamin Herrenschmidt | 3808a88 | 2016-07-05 15:03:48 +1000 | [diff] [blame] | 118 | static void __init fw_vec5_feature_init(const char *vec5, unsigned long len) |
Nathan Fontenot | f0ff7eb | 2013-04-24 05:57:18 +0000 | [diff] [blame] | 119 | { |
| 120 | unsigned int index, feat; |
| 121 | int i; |
| 122 | |
| 123 | pr_debug(" -> fw_vec5_feature_init()\n"); |
| 124 | |
| 125 | for (i = 0; i < ARRAY_SIZE(vec5_fw_features_table); i++) { |
| 126 | index = OV5_INDX(vec5_fw_features_table[i].feature); |
| 127 | feat = OV5_FEAT(vec5_fw_features_table[i].feature); |
| 128 | |
| 129 | if (vec5[index] & feat) |
| 130 | powerpc_firmware_features |= |
| 131 | vec5_fw_features_table[i].val; |
| 132 | } |
| 133 | |
| 134 | pr_debug(" <- fw_vec5_feature_init()\n"); |
Michael Ellerman | 1965746 | 2006-02-10 15:47:36 +1100 | [diff] [blame] | 135 | } |
Benjamin Herrenschmidt | 3808a88 | 2016-07-05 15:03:48 +1000 | [diff] [blame] | 136 | |
| 137 | /* |
| 138 | * Called very early, MMU is off, device-tree isn't unflattened |
| 139 | */ |
| 140 | static int __init probe_fw_features(unsigned long node, const char *uname, int |
| 141 | depth, void *data) |
| 142 | { |
| 143 | const char *prop; |
| 144 | int len; |
| 145 | static int hypertas_found; |
| 146 | static int vec5_found; |
| 147 | |
| 148 | if (depth != 1) |
| 149 | return 0; |
| 150 | |
| 151 | if (!strcmp(uname, "rtas") || !strcmp(uname, "rtas@0")) { |
| 152 | prop = of_get_flat_dt_prop(node, "ibm,hypertas-functions", |
| 153 | &len); |
| 154 | if (prop) { |
| 155 | powerpc_firmware_features |= FW_FEATURE_LPAR; |
| 156 | fw_hypertas_feature_init(prop, len); |
| 157 | } |
| 158 | |
| 159 | hypertas_found = 1; |
| 160 | } |
| 161 | |
| 162 | if (!strcmp(uname, "chosen")) { |
| 163 | prop = of_get_flat_dt_prop(node, "ibm,architecture-vec-5", |
| 164 | &len); |
| 165 | if (prop) |
| 166 | fw_vec5_feature_init(prop, len); |
| 167 | |
| 168 | vec5_found = 1; |
| 169 | } |
| 170 | |
| 171 | return hypertas_found && vec5_found; |
| 172 | } |
| 173 | |
| 174 | void __init pseries_probe_fw_features(void) |
| 175 | { |
| 176 | of_scan_flat_dt(probe_fw_features, NULL); |
| 177 | } |