Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #include <vppinfra/clib.h> |
| 16 | #include <vppinfra/format.h> |
| 17 | #include <vppinfra/cpu.h> |
| 18 | |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 19 | #define foreach_x86_cpu_uarch \ |
Damjan Marion | bfe470c | 2017-11-11 02:21:34 +0100 | [diff] [blame] | 20 | _(0x06, 0x9e, "Kaby Lake", "Kaby Lake DT/H/S/X") \ |
| 21 | _(0x06, 0x8e, "Kaby Lake", "Kaby Lake Y/U") \ |
| 22 | _(0x06, 0x85, "Knights Mill", "Knights Mill") \ |
| 23 | _(0x06, 0x5f, "Goldmont", "Denverton") \ |
| 24 | _(0x06, 0x5e, "Skylake", "Skylake DT/H/S") \ |
| 25 | _(0x06, 0x5c, "Goldmont", "Apollo Lake") \ |
| 26 | _(0x06, 0x5a, "Silvermont", "Moorefield") \ |
| 27 | _(0x06, 0x57, "Knights Landing", "Knights Landing") \ |
| 28 | _(0x06, 0x56, "Broadwell", "Broadwell DE") \ |
| 29 | _(0x06, 0x55, "Skylake", "Skylake X/SP") \ |
| 30 | _(0x06, 0x4f, "Broadwell", "Broadwell EP/EX") \ |
| 31 | _(0x06, 0x4e, "Skylake", "Skylake Y/U") \ |
| 32 | _(0x06, 0x4d, "Silvermont", "Rangeley") \ |
| 33 | _(0x06, 0x4c, "Airmont", "Braswell") \ |
| 34 | _(0x06, 0x47, "Broadwell", "Broadwell H") \ |
| 35 | _(0x06, 0x46, "Haswell", "Crystalwell") \ |
| 36 | _(0x06, 0x45, "Haswell", "Haswell ULT") \ |
| 37 | _(0x06, 0x3f, "Haswell", "Haswell E") \ |
| 38 | _(0x06, 0x3e, "Ivy Bridge", "Ivy Bridge E/EN/EP") \ |
| 39 | _(0x06, 0x3d, "Broadwell", "Broadwell U") \ |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 40 | _(0x06, 0x3c, "Haswell", "Haswell") \ |
Damjan Marion | bfe470c | 2017-11-11 02:21:34 +0100 | [diff] [blame] | 41 | _(0x06, 0x3a, "Ivy Bridge", "IvyBridge") \ |
| 42 | _(0x06, 0x37, "Silvermont", "BayTrail") \ |
| 43 | _(0x06, 0x36, "Saltwell", "Cedarview,Centerton") \ |
| 44 | _(0x06, 0x35, "Saltwell", "Cloverview") \ |
| 45 | _(0x06, 0x2f, "Westmere", "Westmere EX") \ |
| 46 | _(0x06, 0x2e, "Nehalem", "Nehalem EX") \ |
| 47 | _(0x06, 0x2d, "Sandy Bridge", "SandyBridge E/EN/EP") \ |
| 48 | _(0x06, 0x2c, "Westmere", "Westmere EP/EX,Gulftown") \ |
| 49 | _(0x06, 0x2a, "Sandy Bridge", "Sandy Bridge") \ |
| 50 | _(0x06, 0x27, "Saltwell", "Medfield") \ |
| 51 | _(0x06, 0x26, "Bonnell", "Tunnel Creek") \ |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 52 | _(0x06, 0x25, "Westmere", "Arrandale,Clarksdale") \ |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 53 | _(0x06, 0x1e, "Nehalem", "Clarksfield,Lynnfield,Jasper Forest") \ |
Damjan Marion | bfe470c | 2017-11-11 02:21:34 +0100 | [diff] [blame] | 54 | _(0x06, 0x1d, "Penryn", "Dunnington") \ |
| 55 | _(0x06, 0x1c, "Bonnell", "Pineview,Silverthorne") \ |
| 56 | _(0x06, 0x1a, "Nehalem", "Nehalem EP,Bloomfield)") \ |
| 57 | _(0x06, 0x17, "Penryn", "Yorkfield,Wolfdale,Penryn,Harpertown") |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 58 | |
| 59 | u8 * |
| 60 | format_cpu_uarch (u8 * s, va_list * args) |
| 61 | { |
| 62 | #if __x86_64__ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 63 | u32 __attribute__ ((unused)) eax, ebx, ecx, edx; |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 64 | u8 model, family; |
| 65 | |
| 66 | if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0) |
| 67 | return format (s, "unknown (missing cpuid)"); |
| 68 | |
| 69 | model = ((eax >> 4) & 0x0f) | ((eax >> 12) & 0xf0); |
| 70 | family = (eax >> 8) & 0x0f; |
| 71 | |
| 72 | #define _(f,m,a,c) if ((model == m) && (family == f)) return format(s, "%s (%s)", a, c); |
| 73 | foreach_x86_cpu_uarch |
| 74 | #undef _ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 75 | return format (s, "unknown (family 0x%02x model 0x%02x)", family, model); |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 76 | |
| 77 | #else /* ! __x86_64__ */ |
| 78 | return format (s, "unknown"); |
| 79 | #endif |
| 80 | } |
| 81 | |
| 82 | u8 * |
| 83 | format_cpu_model_name (u8 * s, va_list * args) |
| 84 | { |
| 85 | #if __x86_64__ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 86 | u32 __attribute__ ((unused)) eax, ebx, ecx, edx; |
| 87 | u8 *name = 0; |
| 88 | u32 *name_u32; |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 89 | |
| 90 | if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0) |
| 91 | return format (s, "unknown (missing cpuid)"); |
| 92 | |
| 93 | __get_cpuid (0x80000000, &eax, &ebx, &ecx, &edx); |
| 94 | if (eax < 0x80000004) |
| 95 | return format (s, "unknown (missing ext feature)"); |
| 96 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 97 | vec_validate (name, 48); |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 98 | name_u32 = (u32 *) name; |
| 99 | |
| 100 | __get_cpuid (0x80000002, &eax, &ebx, &ecx, &edx); |
| 101 | name_u32[0] = eax; |
| 102 | name_u32[1] = ebx; |
| 103 | name_u32[2] = ecx; |
| 104 | name_u32[3] = edx; |
| 105 | |
| 106 | __get_cpuid (0x80000003, &eax, &ebx, &ecx, &edx); |
| 107 | name_u32[4] = eax; |
| 108 | name_u32[5] = ebx; |
| 109 | name_u32[6] = ecx; |
| 110 | name_u32[7] = edx; |
| 111 | |
| 112 | __get_cpuid (0x80000004, &eax, &ebx, &ecx, &edx); |
| 113 | name_u32[8] = eax; |
| 114 | name_u32[9] = ebx; |
| 115 | name_u32[10] = ecx; |
| 116 | name_u32[11] = edx; |
| 117 | |
| 118 | s = format (s, "%s", name); |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 119 | vec_free (name); |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 120 | return s; |
| 121 | |
Christophe Fontaine | 33e8195 | 2016-12-19 14:41:52 +0100 | [diff] [blame] | 122 | #elif defined(__aarch64__) |
| 123 | return format (s, "armv8"); |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 124 | #else /* ! __x86_64__ */ |
| 125 | return format (s, "unknown"); |
| 126 | #endif |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | u8 * |
| 130 | format_cpu_flags (u8 * s, va_list * args) |
| 131 | { |
Christophe Fontaine | 33e8195 | 2016-12-19 14:41:52 +0100 | [diff] [blame] | 132 | #if defined(__x86_64__) |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 133 | #define _(flag, func, reg, bit) \ |
| 134 | if (clib_cpu_supports_ ## flag()) \ |
| 135 | s = format (s, #flag " "); |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 136 | foreach_x86_64_flags return s; |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 137 | #undef _ |
| 138 | #else /* ! __x86_64__ */ |
| 139 | return format (s, "unknown"); |
| 140 | #endif |
| 141 | } |
| 142 | |
| 143 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * fd.io coding-style-patch-verification: ON |
| 147 | * |
| 148 | * Local Variables: |
| 149 | * eval: (c-set-style "gnu") |
| 150 | * End: |
| 151 | */ |