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 | /** Implementers (vendor) names */
|
---|
42 | static const char * implementer(unsigned id)
|
---|
43 | {
|
---|
44 | switch (id)
|
---|
45 | {
|
---|
46 | case 0x41: return "ARM Limited";
|
---|
47 | case 0x44: return "Digital Equipment Corporation";
|
---|
48 | case 0x4d: return "Motorola, Freescale Semiconductor Inc.";
|
---|
49 | case 0x51: return "Qualcomm Inc.";
|
---|
50 | case 0x56: return "Marvell Semiconductor Inc.";
|
---|
51 | case 0x69: return "Intel Corporation";
|
---|
52 | }
|
---|
53 | return "Unknown implementer";
|
---|
54 | }
|
---|
55 |
|
---|
56 | /** Architecture names */
|
---|
57 | static const char * architecture_string(cpu_arch_t *arch)
|
---|
58 | {
|
---|
59 | static const char *arch_data[] = {
|
---|
60 | "ARM", /* 0x0 */
|
---|
61 | "ARMv4", /* 0x1 */
|
---|
62 | "ARMv4T", /* 0x2 */
|
---|
63 | "ARMv5", /* 0x3 */
|
---|
64 | "ARMv5T", /* 0x4 */
|
---|
65 | "ARMv5TE", /* 0x5 */
|
---|
66 | "ARMv5TEJ", /* 0x6 */
|
---|
67 | "ARMv6" /* 0x7 */
|
---|
68 | };
|
---|
69 | if (arch->arch_num < (sizeof(arch_data) / sizeof(arch_data[0])))
|
---|
70 | return arch_data[arch->arch_num];
|
---|
71 | else
|
---|
72 | return arch_data[0];
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | /** Retrieves processor identification from CP15 register 0.
|
---|
77 | *
|
---|
78 | * @param cpu Structure for storing CPU identification.
|
---|
79 | * See page B4-1630 of ARM Architecture Reference Manual.
|
---|
80 | */
|
---|
81 | static void arch_cpu_identify(cpu_arch_t *cpu)
|
---|
82 | {
|
---|
83 | uint32_t ident;
|
---|
84 | asm volatile (
|
---|
85 | "mrc p15, 0, %[ident], c0, c0, 0\n"
|
---|
86 | : [ident] "=r" (ident)
|
---|
87 | );
|
---|
88 |
|
---|
89 | cpu->imp_num = ident >> 24;
|
---|
90 | cpu->variant_num = (ident << 8) >> 28;
|
---|
91 | cpu->arch_num = (ident << 12) >> 28;
|
---|
92 | cpu->prim_part_num = (ident << 16) >> 20;
|
---|
93 | cpu->rev_num = (ident << 28) >> 28;
|
---|
94 | // TODO CPUs with arch_num == 0xf use CPUID scheme for identification
|
---|
95 | }
|
---|
96 |
|
---|
97 | /** Enables unaligned access and caching for armv6+ */
|
---|
98 | void cpu_arch_init(void)
|
---|
99 | {
|
---|
100 | #if defined(PROCESSOR_armv7_a) | defined(PROCESSOR_armv6)
|
---|
101 | uint32_t control_reg = 0;
|
---|
102 | asm volatile (
|
---|
103 | "mrc p15, 0, %[control_reg], c1, c0"
|
---|
104 | : [control_reg] "=r" (control_reg)
|
---|
105 | );
|
---|
106 |
|
---|
107 | /* Turn off tex remap, RAZ/WI prior to armv7 */
|
---|
108 | control_reg &= ~CP15_R1_TEX_REMAP_EN;
|
---|
109 | /* Turn off accessed flag, RAZ/WI prior to armv7 */
|
---|
110 | control_reg &= ~(CP15_R1_ACCESS_FLAG_EN | CP15_R1_HW_ACCESS_FLAG_EN);
|
---|
111 | /* Enable unaligned access, RAZ/WI prior to armv6
|
---|
112 | * switchable on armv6, RAO/WI writes on armv7,
|
---|
113 | * see ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition
|
---|
114 | * L.3.1 (p. 2456) */
|
---|
115 | control_reg |= CP15_R1_UNALIGNED_EN;
|
---|
116 | /* Disable alignment checks, this turns unaligned access to undefined,
|
---|
117 | * unless U bit is set. */
|
---|
118 | control_reg &= ~CP15_R1_ALIGN_CHECK_EN;
|
---|
119 | /* Enable caching, On arm prior to armv7 there is only one level
|
---|
120 | * of caches. Data cache is coherent.
|
---|
121 | * "This means that the behavior of accesses from the same observer to
|
---|
122 | * different VAs, that are translated to the same PA
|
---|
123 | * with the same memory attributes, is fully coherent."
|
---|
124 | * ARM Architecture Reference Manual ARMv7-A and ARMv7-R Edition
|
---|
125 | * B3.11.1 (p. 1383)
|
---|
126 | * ICache coherency is elaborate on in barrier.h.
|
---|
127 | * We are safe to turn these on.
|
---|
128 | */
|
---|
129 | control_reg |= CP15_R1_CACHE_EN | CP15_R1_INST_CACHE_EN;
|
---|
130 |
|
---|
131 | asm volatile (
|
---|
132 | "mcr p15, 0, %[control_reg], c1, c0"
|
---|
133 | :: [control_reg] "r" (control_reg)
|
---|
134 | );
|
---|
135 | #endif
|
---|
136 | #ifdef CONFIG_FPU
|
---|
137 | fpu_setup();
|
---|
138 | #endif
|
---|
139 | }
|
---|
140 |
|
---|
141 | /** Retrieves processor identification and stores it to #CPU.arch */
|
---|
142 | void cpu_identify(void)
|
---|
143 | {
|
---|
144 | arch_cpu_identify(&CPU->arch);
|
---|
145 | }
|
---|
146 |
|
---|
147 | /** Prints CPU identification. */
|
---|
148 | void cpu_print_report(cpu_t *m)
|
---|
149 | {
|
---|
150 | printf("cpu%d: vendor=%s, architecture=%s, part number=%x, "
|
---|
151 | "variant=%x, revision=%x\n",
|
---|
152 | m->id, implementer(m->arch.imp_num),
|
---|
153 | architecture_string(&m->arch), m->arch.prim_part_num,
|
---|
154 | m->arch.variant_num, m->arch.rev_num);
|
---|
155 | }
|
---|
156 |
|
---|
157 | /** @}
|
---|
158 | */
|
---|