1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <arch/cache.h>
4 #include <arch/lib_helpers.h>
9 static void smbios_processor_id(u32
*processor_id
)
11 uint32_t jep106code
, soc_revision
;
14 if (smccc_supports_arch_soc_id()) {
15 smccc_arch_soc_id(&jep106code
, &soc_revision
);
16 processor_id
[0] = jep106code
;
17 processor_id
[1] = soc_revision
;
19 midr_el1
= raw_read_midr_el1();
20 processor_id
[0] = midr_el1
;
25 static int smbios_processor_manufacturer(u8
*start
)
27 char midr_el1_implementer
;
30 // [31:24] - Implementer code
31 midr_el1_implementer
= (raw_read_midr_el1() & 0xff000000) >> 24;
33 snprintf(buf
, sizeof(buf
), "CPU implementer %x", midr_el1_implementer
);
34 return smbios_add_string(start
, buf
);
37 static int smbios_processor_name(u8
*start
)
39 uint16_t midr_el1_partnumber
;
43 midr_el1_partnumber
= (raw_read_midr_el1() & 0xfff0) >> 4;
45 snprintf(buf
, sizeof(buf
), "ARMv8 Processor rev %d", midr_el1_partnumber
);
46 return smbios_add_string(start
, buf
);
49 #define MAX_CPUS_ENABLED(cpus) (cpus > 0xff ? 0xff : cpus)
51 /* NOTE: Not handling big.LITTLE clusters. Consider using MP services (not yet) or the DSU. */
52 int smbios_write_type4(unsigned long *current
, int handle
)
54 static unsigned int cnt
= 0;
56 uint16_t characteristics
= 0;
57 unsigned int cpu_voltage
;
59 struct smbios_type4
*t
= smbios_carve_table(*current
, SMBIOS_PROCESSOR_INFORMATION
,
62 snprintf(buf
, sizeof(buf
), "CPU%d", cnt
++);
63 t
->socket_designation
= smbios_add_string(t
->eos
, buf
);
65 smbios_processor_id(t
->processor_id
);
66 t
->processor_manufacturer
= smbios_processor_manufacturer(t
->eos
);
67 t
->processor_version
= smbios_processor_name(t
->eos
);
68 t
->processor_family
= SMBIOS_PROCESSOR_FAMILY_FROM_FAMILY2
;
69 t
->processor_family2
= SMBIOS_PROCESSOR_FAMILY2_ARMV8
;
70 t
->processor_type
= SMBIOS_PROCESSOR_TYPE_CENTRAL
;
72 smbios_cpu_get_core_counts(&t
->core_count2
, &t
->thread_count2
);
73 t
->core_count
= MAX_CPUS_ENABLED(t
->core_count2
);
74 t
->thread_count
= MAX_CPUS_ENABLED(t
->thread_count2
);
75 /* Assume we always enable all cores */
76 t
->core_enabled
= t
->core_count
;
77 t
->core_enabled2
= t
->core_count2
;
78 t
->l1_cache_handle
= 0xffff;
79 t
->l2_cache_handle
= 0xffff;
80 t
->l3_cache_handle
= 0xffff;
81 t
->serial_number
= smbios_add_string(t
->eos
, smbios_processor_serial_number());
82 t
->status
= SMBIOS_PROCESSOR_STATUS_CPU_ENABLED
| SMBIOS_PROCESSOR_STATUS_POPULATED
;
83 t
->processor_upgrade
= PROCESSOR_UPGRADE_UNKNOWN
;
85 t
->external_clock
= smbios_processor_external_clock();
86 if (t
->external_clock
== 0)
87 t
->external_clock
= (raw_read_cntfrq_el0() / 1000 / 1000);
89 t
->current_speed
= smbios_cpu_get_current_speed_mhz();
91 /* This field identifies a capability for the system, not the processor itself. */
92 t
->max_speed
= smbios_cpu_get_max_speed_mhz();
94 /* TODO: Are "Enhanced Virtualization" (by EL2) and "Power/Performance Control" supported? */
95 characteristics
|= PROCESSOR_64BIT_CAPABLE
;
96 characteristics
|= BIT(5); /* Execute Protection */
98 if (t
->core_count
> 1)
99 characteristics
|= PROCESSOR_MULTI_CORE
;
100 if (t
->thread_count
> 1)
101 characteristics
|= BIT(4); /* BIT4: Hardware Thread */
102 if (smccc_supports_arch_soc_id())
103 characteristics
|= BIT(9); /* Arm64 SoC ID */
105 t
->processor_characteristics
= characteristics
| smbios_processor_characteristics();
107 cpu_voltage
= smbios_cpu_get_voltage();
109 t
->voltage
= 0x80 | cpu_voltage
;
111 const int len
= smbios_full_table_len(&t
->header
, t
->eos
);
116 int smbios_write_type7_cache_parameters(unsigned long *current
,
118 int *max_struct_size
,
119 struct smbios_type4
*type4
)
121 enum cache_level level
= CACHE_L1
;
126 enum smbios_cache_type type
;
127 struct cache_info info
;
129 const u8 cache_type
= cpu_get_cache_type(level
);
130 /* No more caches in the system */
134 switch (cache_type
) {
135 case CACHE_INSTRUCTION
:
136 type
= SMBIOS_CACHE_TYPE_INSTRUCTION
;
137 cpu_get_cache_info(level
, cache_type
, &info
);
140 type
= SMBIOS_CACHE_TYPE_DATA
;
141 cpu_get_cache_info(level
, cache_type
, &info
);
144 type
= SMBIOS_CACHE_TYPE_DATA
;
145 cpu_get_cache_info(level
, CACHE_DATA
, &info
);
147 update_max(len
, *max_struct_size
, smbios_write_type7(current
, h
,
148 level
, smbios_cache_sram_type(), smbios_cache_associativity(info
.associativity
),
149 type
, info
.size
, info
.size
));
151 type
= SMBIOS_CACHE_TYPE_INSTRUCTION
;
152 cpu_get_cache_info(level
, CACHE_INSTRUCTION
, &info
);
155 type
= SMBIOS_CACHE_TYPE_UNIFIED
;
156 cpu_get_cache_info(level
, cache_type
, &info
);
159 type
= SMBIOS_CACHE_TYPE_UNKNOWN
;
160 info
.size
= info
.associativity
= 0;
165 update_max(len
, *max_struct_size
, smbios_write_type7(current
, h
,
166 level
, smbios_cache_sram_type(), smbios_cache_associativity(info
.associativity
),
167 type
, info
.size
, info
.size
));
172 type4
->l1_cache_handle
= h
;
175 type4
->l2_cache_handle
= h
;
178 type4
->l3_cache_handle
= h
;