blob: a26d5c9ae1069984860788c284ddb251e9a985a1 [file] [log] [blame]
Damjan Marion522e4862016-03-04 12:44:14 +01001/*
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 Marion522e4862016-03-04 12:44:14 +010019#define foreach_x86_cpu_uarch \
Damjan Marionbd4b5902016-04-18 12:45:15 +020020 _(0x06, 0x4f, "Broadwell", "Broadwell-EP/EX") \
Damjan Marion522e4862016-03-04 12:44:14 +010021 _(0x06, 0x3d, "Broadwell", "Broadwell") \
22 _(0x06, 0x3f, "Haswell", "Haswell-E") \
23 _(0x06, 0x3c, "Haswell", "Haswell") \
24 _(0x06, 0x3e, "IvyBridge", "IvyBridge-E/EN/EP") \
25 _(0x06, 0x3a, "IvyBridge", "IvyBridge") \
26 _(0x06, 0x2a, "SandyBridge", "SandyBridge") \
27 _(0x06, 0x2d, "SandyBridge", "SandyBridge-E/EN/EP") \
28 _(0x06, 0x25, "Westmere", "Arrandale,Clarksdale") \
29 _(0x06, 0x2c, "Westmere", "Westmere-EP/EX,Gulftown") \
30 _(0x06, 0x2f, "Westmere", "Westmere-EX") \
31 _(0x06, 0x1e, "Nehalem", "Clarksfield,Lynnfield,Jasper Forest") \
32 _(0x06, 0x1a, "Nehalem", "Nehalem-EP,Bloomfield)") \
33 _(0x06, 0x2e, "Nehalem", "Nehalem-EX") \
34 _(0x06, 0x17, "Penryn", "Yorkfield,Wolfdale,Penryn,Harpertown (DP)") \
35 _(0x06, 0x1d, "Penryn", "Dunnington (MP)") \
36 _(0x06, 0x37, "Atom", "Bay Trail") \
37 _(0x06, 0x36, "Atom", "Cedarview") \
38 _(0x06, 0x26, "Atom", "Lincroft") \
39 _(0x06, 0x1c, "Atom", "Pineview/Silverthorne")
40
41u8 *
42format_cpu_uarch (u8 * s, va_list * args)
43{
44#if __x86_64__
Dave Barachc3799992016-08-15 11:12:27 -040045 u32 __attribute__ ((unused)) eax, ebx, ecx, edx;
Damjan Marion522e4862016-03-04 12:44:14 +010046 u8 model, family;
47
48 if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0)
49 return format (s, "unknown (missing cpuid)");
50
51 model = ((eax >> 4) & 0x0f) | ((eax >> 12) & 0xf0);
52 family = (eax >> 8) & 0x0f;
53
54#define _(f,m,a,c) if ((model == m) && (family == f)) return format(s, "%s (%s)", a, c);
55 foreach_x86_cpu_uarch
56#undef _
Dave Barachc3799992016-08-15 11:12:27 -040057 return format (s, "unknown (family 0x%02x model 0x%02x)", family, model);
Damjan Marion522e4862016-03-04 12:44:14 +010058
59#else /* ! __x86_64__ */
60 return format (s, "unknown");
61#endif
62}
63
64u8 *
65format_cpu_model_name (u8 * s, va_list * args)
66{
67#if __x86_64__
Dave Barachc3799992016-08-15 11:12:27 -040068 u32 __attribute__ ((unused)) eax, ebx, ecx, edx;
69 u8 *name = 0;
70 u32 *name_u32;
Damjan Marion522e4862016-03-04 12:44:14 +010071
72 if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0)
73 return format (s, "unknown (missing cpuid)");
74
75 __get_cpuid (0x80000000, &eax, &ebx, &ecx, &edx);
76 if (eax < 0x80000004)
77 return format (s, "unknown (missing ext feature)");
78
Dave Barachc3799992016-08-15 11:12:27 -040079 vec_validate (name, 48);
Damjan Marion522e4862016-03-04 12:44:14 +010080 name_u32 = (u32 *) name;
81
82 __get_cpuid (0x80000002, &eax, &ebx, &ecx, &edx);
83 name_u32[0] = eax;
84 name_u32[1] = ebx;
85 name_u32[2] = ecx;
86 name_u32[3] = edx;
87
88 __get_cpuid (0x80000003, &eax, &ebx, &ecx, &edx);
89 name_u32[4] = eax;
90 name_u32[5] = ebx;
91 name_u32[6] = ecx;
92 name_u32[7] = edx;
93
94 __get_cpuid (0x80000004, &eax, &ebx, &ecx, &edx);
95 name_u32[8] = eax;
96 name_u32[9] = ebx;
97 name_u32[10] = ecx;
98 name_u32[11] = edx;
99
100 s = format (s, "%s", name);
Dave Barachc3799992016-08-15 11:12:27 -0400101 vec_free (name);
Damjan Marion522e4862016-03-04 12:44:14 +0100102 return s;
103
Christophe Fontaine33e81952016-12-19 14:41:52 +0100104#elif defined(__aarch64__)
105 return format (s, "armv8");
Damjan Marion522e4862016-03-04 12:44:14 +0100106#else /* ! __x86_64__ */
107 return format (s, "unknown");
108#endif
Damjan Marion1c80e832016-05-11 23:07:18 +0200109}
110
111u8 *
112format_cpu_flags (u8 * s, va_list * args)
113{
Christophe Fontaine33e81952016-12-19 14:41:52 +0100114#if defined(__x86_64__)
Damjan Marion1c80e832016-05-11 23:07:18 +0200115#define _(flag, func, reg, bit) \
116 if (clib_cpu_supports_ ## flag()) \
117 s = format (s, #flag " ");
Dave Barachc3799992016-08-15 11:12:27 -0400118 foreach_x86_64_flags return s;
Damjan Marion1c80e832016-05-11 23:07:18 +0200119#undef _
120#else /* ! __x86_64__ */
121 return format (s, "unknown");
122#endif
123}
124
125
Dave Barachc3799992016-08-15 11:12:27 -0400126
127/*
128 * fd.io coding-style-patch-verification: ON
129 *
130 * Local Variables:
131 * eval: (c-set-style "gnu")
132 * End:
133 */