summaryrefslogtreecommitdiffstats
path: root/c
diff options
context:
space:
mode:
authorTill Straumann <strauman@slac.stanford.edu>2007-12-01 00:06:00 +0000
committerTill Straumann <strauman@slac.stanford.edu>2007-12-01 00:06:00 +0000
commite955b062fbae3f0602471cf3f91377556f677c1f (patch)
tree596f522d7a32851d1b2f549cb764d8ca912d6fd5 /c
parent2007-11-30 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-e955b062fbae3f0602471cf3f91377556f677c1f.tar.bz2
2007-11-29 Till Straumann <strauman@slac.stanford.edu>
* shared/include/cpuIdent.h, shared/include/cpuIdent.c: Added a simple 'feature check' facility. Code should not check for a particular CPU type if possible but check the respective feature bit (e.g., 'has_altivec'). This makes it much less cumbersome to add more CPU types in the future.
Diffstat (limited to 'c')
-rw-r--r--c/src/lib/libcpu/powerpc/ChangeLog9
-rw-r--r--c/src/lib/libcpu/powerpc/shared/include/cpuIdent.c60
-rw-r--r--c/src/lib/libcpu/powerpc/shared/include/cpuIdent.h34
3 files changed, 100 insertions, 3 deletions
diff --git a/c/src/lib/libcpu/powerpc/ChangeLog b/c/src/lib/libcpu/powerpc/ChangeLog
index 9cc6005956..4413742366 100644
--- a/c/src/lib/libcpu/powerpc/ChangeLog
+++ b/c/src/lib/libcpu/powerpc/ChangeLog
@@ -1,5 +1,14 @@
2007-11-29 Till Straumann <strauman@slac.stanford.edu>
+ * shared/include/cpuIdent.h, shared/include/cpuIdent.c:
+ Added a simple 'feature check' facility. Code should
+ not check for a particular CPU type if possible but
+ check the respective feature bit (e.g., 'has_altivec').
+ This makes it much less cumbersome to add more CPU
+ types in the future.
+
+2007-11-29 Till Straumann <strauman@slac.stanford.edu>
+
* mpc6xx/mmu/bat.c, mpc6xx/mmu/bat.h: Added support
for setting & reading IBATs.
diff --git a/c/src/lib/libcpu/powerpc/shared/include/cpuIdent.c b/c/src/lib/libcpu/powerpc/shared/include/cpuIdent.c
index 03e710192b..c1c0fd5da8 100644
--- a/c/src/lib/libcpu/powerpc/shared/include/cpuIdent.c
+++ b/c/src/lib/libcpu/powerpc/shared/include/cpuIdent.c
@@ -23,8 +23,9 @@
*/
SPR_RO(PVR)
-ppc_cpu_id_t current_ppc_cpu = PPC_UNKNOWN;
+ppc_cpu_id_t current_ppc_cpu = PPC_UNKNOWN;
ppc_cpu_revision_t current_ppc_revision = 0xff;
+ppc_feature_t current_ppc_features = {0};
char *get_ppc_cpu_type_name(ppc_cpu_id_t cpu)
{
@@ -46,6 +47,7 @@ char *get_ppc_cpu_type_name(ppc_cpu_id_t cpu)
case PPC_860: return "MPC860";
case PPC_8260: return "MPC8260";
case PPC_8245: return "MPC8245";
+ case PPC_8540: return "MPC8540";
case PPC_PSIM: return "PSIM";
default:
printk("Unknown CPU value of 0x%x. Please add it to "
@@ -56,8 +58,14 @@ char *get_ppc_cpu_type_name(ppc_cpu_id_t cpu)
ppc_cpu_id_t get_ppc_cpu_type()
{
- unsigned int pvr = (_read_PVR() >> 16);
+ unsigned int pvr;
+
+ if ( PPC_UNKNOWN != current_ppc_cpu )
+ return current_ppc_cpu;
+
+ pvr = (_read_PVR() >> 16);
current_ppc_cpu = (ppc_cpu_id_t) pvr;
+
switch (pvr) {
case PPC_405:
case PPC_601:
@@ -77,12 +85,58 @@ ppc_cpu_id_t get_ppc_cpu_type()
case PPC_8260:
case PPC_8245:
case PPC_PSIM:
- return current_ppc_cpu;
+ case PPC_8540:
+ break;
default:
printk("Unknown PVR value of 0x%x. Please add it to "
"<libcpu/powerpc/shared/include/cpuIdent.c>\n", pvr );
return PPC_UNKNOWN;
}
+
+ /* determine features */
+
+ /* FIXME: This is incomplete; I couldn't go through all the
+ * manuals (yet).
+ */
+ switch ( current_ppc_cpu ) {
+ case PPC_7455:
+ case PPC_7457:
+ current_ppc_features.has_8_bats = 1;
+ case PPC_7400:
+ current_ppc_features.has_altivec = 1;
+ case PPC_604:
+ case PPC_604e:
+ case PPC_604r:
+ case PPC_750:
+ current_ppc_features.has_hw_ptbl_lkup = 1;
+ case PPC_8260:
+ case PPC_8245:
+ case PPC_601:
+ case PPC_603:
+ case PPC_603e:
+ case PPC_603ev:
+ case PPC_603le:
+ current_ppc_features.is_60x = 1;
+ default:
+ break;
+ }
+
+ switch ( current_ppc_cpu ) {
+ case PPC_405:
+ case PPC_8540:
+ current_ppc_features.is_bookE = 1;
+ default:
+ break;
+ }
+
+ switch ( current_ppc_cpu ) {
+ case PPC_860:
+ current_ppc_features.has_16byte_clne =1;
+ default:
+ break;
+ }
+
+ return current_ppc_cpu;
}
ppc_cpu_revision_t get_ppc_cpu_revision()
diff --git a/c/src/lib/libcpu/powerpc/shared/include/cpuIdent.h b/c/src/lib/libcpu/powerpc/shared/include/cpuIdent.h
index cb79e4c34c..37f03c4601 100644
--- a/c/src/lib/libcpu/powerpc/shared/include/cpuIdent.h
+++ b/c/src/lib/libcpu/powerpc/shared/include/cpuIdent.h
@@ -39,6 +39,7 @@ typedef enum
PPC_8260 = 0x81,
PPC_8240 = PPC_8260,
PPC_8245 = 0x8081,
+ PPC_8540 = 0x8020,
PPC_603le = 0x8082, /* 603le core, in MGT5100 and MPC5200 */
PPC_e300c1 = 0x8083, /* e300c1 core, in MPC83xx*/
PPC_e300c2 = 0x8084, /* e300c2 core */
@@ -47,6 +48,39 @@ typedef enum
PPC_UNKNOWN = 0xffff
} ppc_cpu_id_t;
+/* Bitfield of for identifying features or groups of cpu flavors.
+ * DO NOT USE DIRECTLY (as implementation may change)
+ * only use the 'ppc_is_xxx() / ppc_has_xxx()' macros/inlines
+ * below.
+ */
+
+typedef struct {
+ unsigned has_altivec : 1;
+ unsigned has_fpu : 1;
+ unsigned has_hw_ptbl_lkup : 1;
+ unsigned is_bookE : 1;
+ unsigned has_16byte_clne : 1;
+ unsigned is_60x : 1;
+ unsigned has_8_bats : 1;
+ unsigned has_epic : 1;
+} ppc_feature_t;
+
+extern ppc_feature_t current_ppc_features;
+
+/* PUBLIC ACCESS ROUTINES */
+#define _PPC_FEAT_DECL(x) \
+static inline ppc_cpu_##x() { if ( PPC_UNKNOWN == current_ppc_cpu ) get_ppc_cpu_type(); return current_ppc_features.x; }
+
+_PPC_FEAT_DECL(has_altivec)
+/* has_fpu not implemented yet */
+_PPC_FEAT_DECL(has_hw_ptbl_lkup)
+_PPC_FEAT_DECL(is_bookE)
+_PPC_FEAT_DECL(is_60x)
+_PPC_FEAT_DECL(has_8_bats)
+_PPC_FEAT_DECL(has_epic)
+
+#undef _PPC_FEAT_DECL
+
typedef unsigned short ppc_cpu_revision_t;
extern ppc_cpu_id_t get_ppc_cpu_type ();