[abd9401] | 1 | /* |
---|
| 2 | * cpuIdent.c -- Cpu identification code |
---|
| 3 | * |
---|
| 4 | * Copyright (C) 1999 Eric Valette. valette@crf.canon.fr |
---|
| 5 | * |
---|
[48694da] | 6 | * Added MPC8260 Andy Dachs <a.dachs@sstl.co.uk> |
---|
| 7 | * Surrey Satellite Technology Limited |
---|
| 8 | * |
---|
[abd9401] | 9 | * The license and distribution terms for this file may be |
---|
[e71a3a84] | 10 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 11 | * http://www.rtems.org/license/LICENSE. |
---|
[abd9401] | 12 | * |
---|
| 13 | */ |
---|
| 14 | |
---|
[f054b51] | 15 | #include <libcpu/cpuIdent.h> |
---|
[abd9401] | 16 | #include <libcpu/spr.h> |
---|
[5c76213] | 17 | #include <rtems/bspIo.h> |
---|
[abd9401] | 18 | |
---|
| 19 | /* |
---|
| 20 | * Generate inline code to read Processor Version Register |
---|
| 21 | */ |
---|
[1d367a49] | 22 | SPR_RO(PPC_PVR) |
---|
[abd9401] | 23 | |
---|
[e955b06] | 24 | ppc_cpu_id_t current_ppc_cpu = PPC_UNKNOWN; |
---|
[abd9401] | 25 | ppc_cpu_revision_t current_ppc_revision = 0xff; |
---|
[644448f] | 26 | ppc_feature_t current_ppc_features; |
---|
[abd9401] | 27 | |
---|
[9521992] | 28 | const char *get_ppc_cpu_type_name(ppc_cpu_id_t cpu) |
---|
[0d776cd2] | 29 | { |
---|
| 30 | switch (cpu) { |
---|
[73cdeb6] | 31 | case PPC_405: return "PPC405"; |
---|
[3c6fe2e] | 32 | case PPC_405GP: return "PPC405GP"; |
---|
| 33 | case PPC_405EX: return "PPC405EX"; |
---|
[16a8616] | 34 | case PPC_440: return "PPC440"; |
---|
[0d776cd2] | 35 | case PPC_601: return "MPC601"; |
---|
[9c4a30e2] | 36 | case PPC_5XX: return "MPC5XX"; |
---|
[0d776cd2] | 37 | case PPC_603: return "MPC603"; |
---|
| 38 | case PPC_603ev: return "MPC603ev"; |
---|
| 39 | case PPC_604: return "MPC604"; |
---|
| 40 | case PPC_750: return "MPC750"; |
---|
[848007c] | 41 | case PPC_750_IBM: return "IBM PPC750"; |
---|
[0d776cd2] | 42 | case PPC_7400: return "MPC7400"; |
---|
[408bb71] | 43 | case PPC_7455: return "MPC7455"; |
---|
[73cdeb6] | 44 | case PPC_7457: return "MPC7457"; |
---|
[56c4cae] | 45 | case PPC_603le: return "MPC603le"; |
---|
[0d776cd2] | 46 | case PPC_604e: return "MPC604e"; |
---|
[d49389a] | 47 | case PPC_604r: return "MPC604r"; |
---|
[0d776cd2] | 48 | case PPC_620: return "MPC620"; |
---|
| 49 | case PPC_860: return "MPC860"; |
---|
| 50 | case PPC_8260: return "MPC8260"; |
---|
[408bb71] | 51 | case PPC_8245: return "MPC8245"; |
---|
[25a92bc1] | 52 | case PPC_8540: return "MPC8540"; |
---|
| 53 | case PPC_PSIM: return "PSIM"; |
---|
[29313369] | 54 | case PPC_e200z0: return "e200z0"; |
---|
| 55 | case PPC_e200z1: return "e200z1"; |
---|
[a762dc2] | 56 | case PPC_e200z4: return "e200z4"; |
---|
[25a92bc1] | 57 | case PPC_e200z6: return "e200z6"; |
---|
[b2aa729] | 58 | case PPC_e200z7: return "e200z7"; |
---|
[644448f] | 59 | case PPC_e500v2: return "e500v2"; |
---|
[f6660bfb] | 60 | case PPC_e6500: return "e6500"; |
---|
[0d776cd2] | 61 | default: |
---|
[a84392d] | 62 | printk("Unknown CPU value of 0x%x. Please add it to " |
---|
| 63 | "<libcpu/powerpc/shared/include/cpuIdent.c>\n", cpu ); |
---|
[0d776cd2] | 64 | } |
---|
| 65 | return "UNKNOWN"; |
---|
| 66 | } |
---|
| 67 | |
---|
[3776348f] | 68 | ppc_cpu_id_t get_ppc_cpu_type(void) |
---|
[abd9401] | 69 | { |
---|
[9a66caae] | 70 | /* |
---|
| 71 | * cpu types listed here have the lowermost nibble as a version identifier |
---|
[b2aa729] | 72 | * we will tweak them to the standard version |
---|
[9a66caae] | 73 | */ |
---|
| 74 | const uint32_t ppc_cpu_id_version_nibble[] = { |
---|
| 75 | PPC_e200z0, |
---|
[b2aa729] | 76 | PPC_e200z1, |
---|
[a762dc2] | 77 | PPC_e200z4, |
---|
[b2aa729] | 78 | PPC_e200z6, |
---|
| 79 | PPC_e200z7 |
---|
| 80 | }; |
---|
[9a66caae] | 81 | |
---|
[e955b06] | 82 | unsigned int pvr; |
---|
[9a66caae] | 83 | int i; |
---|
[e955b06] | 84 | |
---|
| 85 | if ( PPC_UNKNOWN != current_ppc_cpu ) |
---|
| 86 | return current_ppc_cpu; |
---|
| 87 | |
---|
[1d367a49] | 88 | pvr = (_read_PPC_PVR() >> 16); |
---|
[9a66caae] | 89 | /* |
---|
| 90 | * apply tweaks to ignore version |
---|
| 91 | */ |
---|
| 92 | for (i = 0; |
---|
| 93 | i < (sizeof(ppc_cpu_id_version_nibble) |
---|
| 94 | /sizeof(ppc_cpu_id_version_nibble[0])); |
---|
| 95 | i++) { |
---|
| 96 | if ((pvr & 0xfff0) == (ppc_cpu_id_version_nibble[i] & 0xfff0)) { |
---|
| 97 | pvr = ppc_cpu_id_version_nibble[i]; |
---|
| 98 | break; |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | |
---|
[abd9401] | 102 | current_ppc_cpu = (ppc_cpu_id_t) pvr; |
---|
[e955b06] | 103 | |
---|
[abd9401] | 104 | switch (pvr) { |
---|
[73cdeb6] | 105 | case PPC_405: |
---|
[9a66caae] | 106 | case PPC_405GP: |
---|
| 107 | case PPC_405EX: |
---|
[16a8616] | 108 | case PPC_440: |
---|
[eaedd00] | 109 | case PPC_601: |
---|
[9c4a30e2] | 110 | case PPC_5XX: |
---|
[eaedd00] | 111 | case PPC_603: |
---|
| 112 | case PPC_603ev: |
---|
[56c4cae] | 113 | case PPC_603le: |
---|
[acddd7d2] | 114 | case PPC_604: |
---|
[8ca2e5b] | 115 | case PPC_604r: |
---|
[eaedd00] | 116 | case PPC_750: |
---|
[848007c] | 117 | case PPC_750_IBM: |
---|
[0d776cd2] | 118 | case PPC_7400: |
---|
[56c4cae] | 119 | case PPC_7455: |
---|
[73cdeb6] | 120 | case PPC_7457: |
---|
[eaedd00] | 121 | case PPC_604e: |
---|
| 122 | case PPC_620: |
---|
| 123 | case PPC_860: |
---|
[48694da] | 124 | case PPC_8260: |
---|
[a84392d] | 125 | case PPC_8245: |
---|
[25a92bc1] | 126 | case PPC_PSIM: |
---|
| 127 | case PPC_8540: |
---|
[29313369] | 128 | case PPC_e200z0: |
---|
| 129 | case PPC_e200z1: |
---|
[a762dc2] | 130 | case PPC_e200z4: |
---|
[25a92bc1] | 131 | case PPC_e200z6: |
---|
[b2aa729] | 132 | case PPC_e200z7: |
---|
[25a92bc1] | 133 | case PPC_e300c1: |
---|
| 134 | case PPC_e300c2: |
---|
| 135 | case PPC_e300c3: |
---|
[644448f] | 136 | case PPC_e500v2: |
---|
[f6660bfb] | 137 | case PPC_e6500: |
---|
[e955b06] | 138 | break; |
---|
[eaedd00] | 139 | default: |
---|
[a84392d] | 140 | printk("Unknown PVR value of 0x%x. Please add it to " |
---|
| 141 | "<libcpu/powerpc/shared/include/cpuIdent.c>\n", pvr ); |
---|
[abd9401] | 142 | return PPC_UNKNOWN; |
---|
| 143 | } |
---|
[e955b06] | 144 | |
---|
| 145 | /* determine features */ |
---|
| 146 | |
---|
| 147 | /* FIXME: This is incomplete; I couldn't go through all the |
---|
| 148 | * manuals (yet). |
---|
| 149 | */ |
---|
| 150 | switch ( current_ppc_cpu ) { |
---|
| 151 | case PPC_7455: |
---|
| 152 | case PPC_7457: |
---|
| 153 | current_ppc_features.has_8_bats = 1; |
---|
| 154 | case PPC_7400: |
---|
[c46c2b63] | 155 | /* NOTE: PSIM PVR doesn't tell us anything (its |
---|
| 156 | * contents are not set based on what model |
---|
[16a8616] | 157 | * the user chooses but has to be programmed via |
---|
[c46c2b63] | 158 | * the device file with the special value 0xfffe |
---|
| 159 | * telling us that we have a 'psim cpu'). |
---|
| 160 | * |
---|
| 161 | * I'm not sure pagetables work if the user chooses |
---|
| 162 | * e.g., the 603 model... |
---|
| 163 | */ |
---|
| 164 | case PPC_PSIM: |
---|
[e955b06] | 165 | current_ppc_features.has_altivec = 1; |
---|
| 166 | case PPC_604: |
---|
| 167 | case PPC_604e: |
---|
| 168 | case PPC_604r: |
---|
| 169 | case PPC_750: |
---|
[848007c] | 170 | case PPC_750_IBM: |
---|
[e955b06] | 171 | current_ppc_features.has_hw_ptbl_lkup = 1; |
---|
| 172 | case PPC_8260: |
---|
| 173 | case PPC_8245: |
---|
| 174 | case PPC_601: |
---|
| 175 | case PPC_603: |
---|
| 176 | case PPC_603e: |
---|
| 177 | case PPC_603ev: |
---|
| 178 | case PPC_603le: |
---|
| 179 | current_ppc_features.is_60x = 1; |
---|
| 180 | default: |
---|
| 181 | break; |
---|
| 182 | } |
---|
| 183 | |
---|
[f6660bfb] | 184 | switch ( current_ppc_cpu ) { |
---|
| 185 | case PPC_e6500: |
---|
| 186 | current_ppc_features.has_altivec = 1; |
---|
| 187 | break; |
---|
| 188 | default: |
---|
| 189 | break; |
---|
| 190 | } |
---|
| 191 | |
---|
[e955b06] | 192 | switch ( current_ppc_cpu ) { |
---|
| 193 | case PPC_405: |
---|
[3c6fe2e] | 194 | case PPC_405GP: |
---|
| 195 | case PPC_405EX: |
---|
[4be2812f] | 196 | current_ppc_features.is_bookE = PPC_BOOKE_405; |
---|
| 197 | break; |
---|
[16a8616] | 198 | case PPC_440: |
---|
| 199 | current_ppc_features.is_bookE = PPC_BOOKE_STD; |
---|
[f63e9a3] | 200 | break; |
---|
[e955b06] | 201 | case PPC_8540: |
---|
[29313369] | 202 | case PPC_e200z0: |
---|
| 203 | case PPC_e200z1: |
---|
[a762dc2] | 204 | case PPC_e200z4: |
---|
[25a92bc1] | 205 | case PPC_e200z6: |
---|
[b2aa729] | 206 | case PPC_e200z7: |
---|
[644448f] | 207 | case PPC_e500v2: |
---|
[f6660bfb] | 208 | case PPC_e6500: |
---|
[4be2812f] | 209 | current_ppc_features.is_bookE = PPC_BOOKE_E500; |
---|
[f63e9a3] | 210 | break; |
---|
[e955b06] | 211 | default: |
---|
| 212 | break; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | switch ( current_ppc_cpu ) { |
---|
| 216 | case PPC_860: |
---|
[76a5a3cc] | 217 | current_ppc_features.has_16byte_clne = 1; |
---|
| 218 | default: |
---|
| 219 | break; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | switch ( current_ppc_cpu ) { |
---|
| 223 | case PPC_603e: |
---|
| 224 | case PPC_603ev: |
---|
| 225 | case PPC_603le: |
---|
| 226 | case PPC_e300c1: |
---|
| 227 | case PPC_e300c2: |
---|
| 228 | case PPC_e300c3: |
---|
| 229 | case PPC_8240: |
---|
| 230 | current_ppc_features.has_shadowed_gprs = 1; |
---|
[e955b06] | 231 | default: |
---|
| 232 | break; |
---|
| 233 | } |
---|
[25a92bc1] | 234 | |
---|
[e955b06] | 235 | return current_ppc_cpu; |
---|
[abd9401] | 236 | } |
---|
[0d776cd2] | 237 | |
---|
[3776348f] | 238 | ppc_cpu_revision_t get_ppc_cpu_revision(void) |
---|
[abd9401] | 239 | { |
---|
[1d367a49] | 240 | ppc_cpu_revision_t rev = (ppc_cpu_revision_t) (_read_PPC_PVR() & 0xffff); |
---|
[abd9401] | 241 | current_ppc_revision = rev; |
---|
| 242 | return rev; |
---|
| 243 | } |
---|