source: mainline/kernel/arch/arm32/src/cpu/cpu.c@ 4bd3f45

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4bd3f45 was 4bd3f45, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

arm32: Consolidate control register values

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Copyright (c) 2007 Michal Kebrt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup arm32
30 * @{
31 */
32/** @file
33 * @brief CPU identification.
34 */
35
36#include <arch/cpu.h>
37#include <cpu.h>
38#include <arch.h>
39#include <print.h>
40
41/** Number of indexes left out in the #imp_data array */
42#define IMP_DATA_START_OFFSET 0x40
43
44/** Implementators (vendor) names */
45static const char *imp_data[] = {
46 "?", /* IMP_DATA_START_OFFSET */
47 "ARM Limited", /* 0x41 */
48 "", "", /* 0x42 - 0x43 */
49 "Digital Equipment Corporation", /* 0x44 */
50 "", "", "", "", "", "", "", "", /* 0x45 - 0x4c */
51 "Motorola, Freescale Semicondutor Inc.", /* 0x4d */
52 "", "", "", /* 0x4e - 0x50 */
53 "Qualcomm Inc.", /* 0x51 */
54 "", "", "", "", /* 0x52 - 0x55 */
55 "Marvell Semiconductor", /* 0x56 */
56 "", "", "", "", "", "", "", "", "", "", /* 0x57 - 0x60 */
57 "", "", "", "", "", "", "", "", /* 0x61 - 0x68 */
58 "Intel Corporation" /* 0x69 */
59};
60
61/** Length of the #imp_data array */
62static unsigned int imp_data_length = sizeof(imp_data) / sizeof(char *);
63
64/** Architecture names */
65static const char *arch_data[] = {
66 "?", /* 0x0 */
67 "4", /* 0x1 */
68 "4T", /* 0x2 */
69 "5", /* 0x3 */
70 "5T", /* 0x4 */
71 "5TE", /* 0x5 */
72 "5TEJ", /* 0x6 */
73 "6" /* 0x7 */
74};
75
76/** Length of the #arch_data array */
77static unsigned int arch_data_length = sizeof(arch_data) / sizeof(char *);
78
79
80/** Retrieves processor identification from CP15 register 0.
81 *
82 * @param cpu Structure for storing CPU identification.
83 */
84static void arch_cpu_identify(cpu_arch_t *cpu)
85{
86 uint32_t ident;
87 asm volatile (
88 "mrc p15, 0, %[ident], c0, c0, 0\n"
89 : [ident] "=r" (ident)
90 );
91
92 cpu->imp_num = ident >> 24;
93 cpu->variant_num = (ident << 8) >> 28;
94 cpu->arch_num = (ident << 12) >> 28;
95 cpu->prim_part_num = (ident << 16) >> 20;
96 cpu->rev_num = (ident << 28) >> 28;
97}
98
99/** Does nothing on ARM. */
100void cpu_arch_init(void)
101{
102#if defined(PROCESSOR_armv7_a) | defined(PROCESSOR_armv6)
103 uint32_t control_reg = 0;
104 asm volatile (
105 "mrc p15, 0, %[control_reg], c1, c0"
106 : [control_reg] "=r" (control_reg)
107 );
108
109 /* Turn off tex remap */
110 control_reg &= ~CP15_R1_TEX_REMAP_EN;
111 /* Turn off accessed flag */
112 control_reg &= ~(CP15_R1_ACCESS_FLAG_EN | CP15_R1_HW_ACCESS_FLAG_EN);
113 /* Enable unaligned access (U bit is armv6 only) */
114 control_reg |= CP15_R1_UNALIGNED_EN;
115 /* Disable alignment checks */
116 control_reg &= ~CP15_R1_ALIGN_CHECK_EN;
117 /* Enable caching */
118 control_reg |= CP15_R1_CACHE_EN;
119
120 asm volatile (
121 "mcr p15, 0, %[control_reg], c1, c0"
122 :: [control_reg] "r" (control_reg)
123 );
124#endif
125}
126
127/** Retrieves processor identification and stores it to #CPU.arch */
128void cpu_identify(void)
129{
130 arch_cpu_identify(&CPU->arch);
131}
132
133/** Prints CPU identification. */
134void cpu_print_report(cpu_t *m)
135{
136 const char *vendor = imp_data[0];
137 const char *architecture = arch_data[0];
138 cpu_arch_t * cpu_arch = &m->arch;
139
140 const unsigned imp_offset = cpu_arch->imp_num - IMP_DATA_START_OFFSET;
141
142 if (imp_offset < imp_data_length) {
143 vendor = imp_data[cpu_arch->imp_num - IMP_DATA_START_OFFSET];
144 }
145
146 // TODO CPUs with arch_num == 0xf use CPUID scheme for identification
147 if (cpu_arch->arch_num < arch_data_length) {
148 architecture = arch_data[cpu_arch->arch_num];
149 }
150
151 printf("cpu%d: vendor=%s, architecture=ARM%s, part number=%x, "
152 "variant=%x, revision=%x\n",
153 m->id, vendor, architecture, cpu_arch->prim_part_num,
154 cpu_arch->variant_num, cpu_arch->rev_num);
155}
156
157/** @}
158 */
Note: See TracBrowser for help on using the repository browser.