[d630139] | 1 | /*
|
---|
[6b781c0] | 2 | * Copyright (c) 2007 Michal Kebrt
|
---|
[d630139] | 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
|
---|
[6b781c0] | 33 | * @brief CPU identification.
|
---|
[d630139] | 34 | */
|
---|
| 35 |
|
---|
[6b781c0] | 36 | #include <arch/cpu.h>
|
---|
[d630139] | 37 | #include <cpu.h>
|
---|
[6b781c0] | 38 | #include <arch.h>
|
---|
[e762b43] | 39 | #include <print.h>
|
---|
[d630139] | 40 |
|
---|
[6b781c0] | 41 | /** Number of indexes left out in the #imp_data array */
|
---|
| 42 | #define IMP_DATA_START_OFFSET 0x40
|
---|
| 43 |
|
---|
| 44 | /** Implementators (vendor) names */
|
---|
[a000878c] | 45 | static const char *imp_data[] = {
|
---|
[79e84c9] | 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 */
|
---|
[6b781c0] | 59 | };
|
---|
| 60 |
|
---|
| 61 | /** Length of the #imp_data array */
|
---|
[6c441cf8] | 62 | static unsigned int imp_data_length = sizeof(imp_data) / sizeof(char *);
|
---|
[6b781c0] | 63 |
|
---|
| 64 | /** Architecture names */
|
---|
[a000878c] | 65 | static const char *arch_data[] = {
|
---|
[6b781c0] | 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 */
|
---|
[6c441cf8] | 77 | static unsigned int arch_data_length = sizeof(arch_data) / sizeof(char *);
|
---|
[6b781c0] | 78 |
|
---|
| 79 |
|
---|
| 80 | /** Retrieves processor identification from CP15 register 0.
|
---|
| 81 | *
|
---|
| 82 | * @param cpu Structure for storing CPU identification.
|
---|
| 83 | */
|
---|
| 84 | static void arch_cpu_identify(cpu_arch_t *cpu)
|
---|
| 85 | {
|
---|
| 86 | uint32_t ident;
|
---|
| 87 | asm volatile (
|
---|
[e762b43] | 88 | "mrc p15, 0, %[ident], c0, c0, 0\n"
|
---|
| 89 | : [ident] "=r" (ident)
|
---|
[6b781c0] | 90 | );
|
---|
[e762b43] | 91 |
|
---|
[6b781c0] | 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. */
|
---|
[d630139] | 100 | void cpu_arch_init(void)
|
---|
| 101 | {
|
---|
[f94b95b1] | 102 | #if defined(PROCESSOR_armv7_a) | defined(PROCESSOR_armv6)
|
---|
[1bd99214] | 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 */
|
---|
[4bd3f45] | 110 | control_reg &= ~CP15_R1_TEX_REMAP_EN;
|
---|
[1bd99214] | 111 | /* Turn off accessed flag */
|
---|
[4bd3f45] | 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;
|
---|
[1bd99214] | 117 | /* Enable caching */
|
---|
[4bd3f45] | 118 | control_reg |= CP15_R1_CACHE_EN;
|
---|
[1bd99214] | 119 |
|
---|
| 120 | asm volatile (
|
---|
| 121 | "mcr p15, 0, %[control_reg], c1, c0"
|
---|
| 122 | :: [control_reg] "r" (control_reg)
|
---|
| 123 | );
|
---|
| 124 | #endif
|
---|
[d630139] | 125 | }
|
---|
| 126 |
|
---|
[6b781c0] | 127 | /** Retrieves processor identification and stores it to #CPU.arch */
|
---|
[f94b95b1] | 128 | void cpu_identify(void)
|
---|
[d630139] | 129 | {
|
---|
[6b781c0] | 130 | arch_cpu_identify(&CPU->arch);
|
---|
[d630139] | 131 | }
|
---|
| 132 |
|
---|
[6b781c0] | 133 | /** Prints CPU identification. */
|
---|
[d630139] | 134 | void cpu_print_report(cpu_t *m)
|
---|
| 135 | {
|
---|
[a000878c] | 136 | const char *vendor = imp_data[0];
|
---|
| 137 | const char *architecture = arch_data[0];
|
---|
[6b781c0] | 138 | cpu_arch_t * cpu_arch = &m->arch;
|
---|
| 139 |
|
---|
[79e84c9] | 140 | const unsigned imp_offset = cpu_arch->imp_num - IMP_DATA_START_OFFSET;
|
---|
| 141 |
|
---|
| 142 | if (imp_offset < imp_data_length) {
|
---|
[6b781c0] | 143 | vendor = imp_data[cpu_arch->imp_num - IMP_DATA_START_OFFSET];
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[79e84c9] | 146 | // TODO CPUs with arch_num == 0xf use CPUID scheme for identification
|
---|
| 147 | if (cpu_arch->arch_num < arch_data_length) {
|
---|
[6b781c0] | 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);
|
---|
[d630139] | 155 | }
|
---|
| 156 |
|
---|
| 157 | /** @}
|
---|
| 158 | */
|
---|