source: rtems/c/src/lib/libcpu/powerpc/shared/include/cpuIdent.c @ f63e9a3

4.115
Last change on this file since f63e9a3 was f63e9a3, checked in by Sebastian Huber <sebastian.huber@…>, on 01/23/15 at 10:31:54

bsps/powerpc: Fix switch statement in CPU ident

Close #2237.

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