Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/32131
Change subject: arch/x86/smbios: Add type 7 ......................................................................
arch/x86/smbios: Add type 7
The SMBIOS spec requires type 7 to be present.
Add the type 7 fields and enums for SMBIOS 3.1+ and fill it with the "Deterministic Cache Parameters" as available on Intel and AMD.
As CPUID only provides partial information on caches, some fields are set to unknown. The following fields are supported: * Cache Level * Cache Size * Cache Type * Cache Ways of Associativity
Change-Id: I80ed25b8f2c7b425136b2f0c755324a8f5d1636d Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M src/arch/x86/smbios.c M src/include/smbios.h 2 files changed, 256 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/31/32131/1
diff --git a/src/arch/x86/smbios.c b/src/arch/x86/smbios.c index 8cb59df..be024c16 100644 --- a/src/arch/x86/smbios.c +++ b/src/arch/x86/smbios.c @@ -34,6 +34,14 @@ #include <vendorcode/google/chromeos/gnvs.h> #endif
+#define update_max(len, max_len, stmt) \ + do { \ + int tmp = stmt; \ + \ + max_len = MAX(max_len, tmp); \ + len += tmp; \ + } while (0) + static u8 smbios_checksum(u8 *p, u32 length) { u8 ret = 0; @@ -580,6 +588,192 @@ return len; }
+/* + * Write SMBIOS type 7. + * Fill in some fields with constant values, as gathering the information + * from CPUID is impossible. + */ +static int +smbios_write_type7(unsigned long *current, + const int handle, + const u8 level, + const u8 sram_type, + const enum smbios_cache_associativity associativity, + const enum smbios_cache_type type, + const size_t max_cache_size, + const size_t cache_size) +{ + struct smbios_type7 *t = (struct smbios_type7 *)*current; + int len = sizeof(struct smbios_type7); + static size_t cnt = 0; + char buf[8]; + + memset(t, 0, sizeof(struct smbios_type7)); + t->type = SMBIOS_CACHE_INFORMATION; + t->handle = handle; + t->length = len - 2; + + snprintf(buf, sizeof(buf), "CACHE%x", cnt++); + t->socket_designation = smbios_add_string(t->eos, buf); + + /* Cache level, Internal, Enabled, Mode Varies with Memory Address */ + t->cache_configuration = ((level & 7) << 0) | (1 << 7) | (2 << 8); + + if (max_cache_size < (32 * KiB)) { + t->max_cache_size = max_cache_size; + t->max_cache_size2 = t->max_cache_size; + } else if (max_cache_size < (0x7fff * 64 * KiB)) { + t->max_cache_size = (max_cache_size / (64 * KiB)) | (1 << 15); + t->max_cache_size2 = (max_cache_size / (64 * KiB)) | (1 << 31); + } else { + t->max_cache_size = 0xffff; + t->max_cache_size2 = (max_cache_size / (64 * KiB)) | (1 << 31); + } + + if (cache_size < (32 * KiB)) { + t->installed_size = cache_size; + t->installed_size2 = t->installed_size; + } else if (cache_size < (0x7fff * 64 * KiB)) { + t->installed_size = (cache_size / (64 * KiB)) | (1 << 15); + t->installed_size2 = (cache_size / (64 * KiB)) | (1 << 31); + } else { + t->installed_size = 0xffff; + t->installed_size2 = (cache_size / (64 * KiB)) | (1 << 31); + } + + t->associativity = associativity; + t->supported_sram_type = sram_type; + t->cache_speed = 0; //Unknown + t->error_correction_type = SMBIOS_CACHE_ERROR_CORRECTION_UNKNOWN; + t->system_cache_type = type; + + len = t->length + smbios_string_table_len(t->eos); + *current += len; + return len; +} + +/* Convert the associativity as integer to the SMBIOS enum if available */ +static enum smbios_cache_associativity +smbios_cache_associativity(const u8 num) +{ + switch (num) { + case 1: + return SMBIOS_CACHE_ASSOCIATIVITY_DIRECT; + case 2: + return SMBIOS_CACHE_ASSOCIATIVITY_2WAY; + case 4: + return SMBIOS_CACHE_ASSOCIATIVITY_4WAY; + case 8: + return SMBIOS_CACHE_ASSOCIATIVITY_8WAY; + case 12: + return SMBIOS_CACHE_ASSOCIATIVITY_12WAY; + case 16: + return SMBIOS_CACHE_ASSOCIATIVITY_16WAY; + case 20: + return SMBIOS_CACHE_ASSOCIATIVITY_20WAY; + case 24: + return SMBIOS_CACHE_ASSOCIATIVITY_24WAY; + case 32: + return SMBIOS_CACHE_ASSOCIATIVITY_32WAY; + case 48: + return SMBIOS_CACHE_ASSOCIATIVITY_48WAY; + case 64: + return SMBIOS_CACHE_ASSOCIATIVITY_64WAY; + case 0xff: + return SMBIOS_CACHE_ASSOCIATIVITY_FULL; + default: + return SMBIOS_CACHE_ASSOCIATIVITY_UNKNOWN; + }; + +} + +/* + * Parse the "Deterministic Cache Parameters" as provided by Intel in + * leaf 4 or AMD in extended leaf 0x8000001d. + * + * @param current Pointer to memory address to write the tables to + * @param handle Pointer to the handle for the tables + * @param max_struct_size Pointer to maximum struct size + */ +static int smbios_write_type7_cache_parameters(unsigned long *current, + int *handle, + int *max_struct_size) +{ + struct cpuid_result res; + unsigned int cnt = 0; + int len = 0; + u32 leaf; + + if (!cpu_have_cpuid()) + return len; + + if (cpu_is_intel()) { + res = cpuid(0); + if (res.eax < 4) + return len; + leaf = 4; + } else if (cpu_is_amd()) { + res = cpuid(0x80000000); + if (res.eax < 0x80000001) + return len; + + res = cpuid(0x80000001); + if (!(res.ecx & (1 << 22))) + return len; + + leaf = 0x8000001d; + } else { + printk(BIOS_DEBUG, "SMBIOS: Unknown CPU\n"); + return len; + } + + while (1) { + enum smbios_cache_associativity associativity; + enum smbios_cache_type type; + + res = cpuid_ext(leaf, cnt++); + + const size_t cache_type = res.eax & 0x1f; + const size_t level = (res.eax >> 5) & 0x7; + const size_t assoc = ((res.ebx >> 22) & 0x3ff) + 1; + const size_t partitions = ((res.ebx >> 12) & 0x3ff) + 1; + const size_t cache_line_size = ((res.ebx >> 0) & 0xfff) + 1; + const size_t number_of_sets = res.ecx + 1; + const size_t cache_size = assoc * partitions * cache_line_size * + number_of_sets; + + if (!cache_type) + /* No more caches in the system */ + break; + + switch (cache_type) { + case 1: + type = SMBIOS_CACHE_TYPE_DATA; + break; + case 2: + type = SMBIOS_CACHE_TYPE_INSTRUCTION; + break; + case 3: + type = SMBIOS_CACHE_TYPE_UNIFIED; + break; + default: + type = SMBIOS_CACHE_TYPE_UNKNOWN; + break; + } + + if (res.eax & (1 << 9)) + associativity = SMBIOS_CACHE_ASSOCIATIVITY_FULL; + else + associativity = smbios_cache_associativity(assoc); + + update_max(len, *max_struct_size, smbios_write_type7(current, + *handle++, level, SMBIOS_CACHE_SRAM_TYPE_UNKNOWN, + associativity, type, cache_size, cache_size)); + }; + + return len; +} + static int smbios_write_type11(unsigned long *current, int *handle) { struct smbios_type11 *t = (struct smbios_type11 *)*current; @@ -726,14 +920,6 @@ return len; }
-#define update_max(len, max_len, stmt) \ - do { \ - int tmp = stmt; \ - \ - max_len = MAX(max_len, tmp); \ - len += tmp; \ - } while (0) - unsigned long smbios_write_tables(unsigned long current) { struct smbios_entry *se; @@ -761,6 +947,8 @@ handle++)); update_max(len, max_struct_size, smbios_write_type4(¤t, handle++)); + smbios_write_type7_cache_parameters(¤t, &handle, + &max_struct_size); update_max(len, max_struct_size, smbios_write_type11(¤t, &handle)); if (CONFIG(ELOG)) diff --git a/src/include/smbios.h b/src/include/smbios.h index af83bfe..c9deca5 100644 --- a/src/include/smbios.h +++ b/src/include/smbios.h @@ -393,6 +393,66 @@ u8 eos[2]; } __packed;
+#define SMBIOS_CACHE_SRAM_TYPE_OTHER (1 << 0) +#define SMBIOS_CACHE_SRAM_TYPE_UNKNOWN (1 << 1) +#define SMBIOS_CACHE_SRAM_TYPE_NON_BURST (1 << 2) +#define SMBIOS_CACHE_SRAM_TYPE_BURST (1 << 3) +#define SMBIOS_CACHE_SRAM_TYPE_PIPELINE_BURST (1 << 4) +#define SMBIOS_CACHE_SRAM_TYPE_SYNCHRONOUS (1 << 5) +#define SMBIOS_CACHE_SRAM_TYPE_ASYNCHRONOUS (1 << 6) + +enum smbios_cache_error_corr { + SMBIOS_CACHE_ERROR_CORRECTION_OTHER = 0, + SMBIOS_CACHE_ERROR_CORRECTION_UNKNOWN, + SMBIOS_CACHE_ERROR_CORRECTION_NONE, + SMBIOS_CACHE_ERROR_CORRECTION_PARITY, + SMBIOS_CACHE_ERROR_CORRECTION_SINGLE_BIT, + SMBIOS_CACHE_ERROR_CORRECTION_MULTI_BIT, +}; + +enum smbios_cache_type { + SMBIOS_CACHE_TYPE_OTHER = 0, + SMBIOS_CACHE_TYPE_UNKNOWN, + SMBIOS_CACHE_TYPE_INSTRUCTION, + SMBIOS_CACHE_TYPE_DATA, + SMBIOS_CACHE_TYPE_UNIFIED, +}; + +enum smbios_cache_associativity { + SMBIOS_CACHE_ASSOCIATIVITY_OTHER = 0, + SMBIOS_CACHE_ASSOCIATIVITY_UNKNOWN, + SMBIOS_CACHE_ASSOCIATIVITY_DIRECT, + SMBIOS_CACHE_ASSOCIATIVITY_2WAY, + SMBIOS_CACHE_ASSOCIATIVITY_4WAY, + SMBIOS_CACHE_ASSOCIATIVITY_FULL, + SMBIOS_CACHE_ASSOCIATIVITY_8WAY, + SMBIOS_CACHE_ASSOCIATIVITY_16WAY, + SMBIOS_CACHE_ASSOCIATIVITY_12WAY, + SMBIOS_CACHE_ASSOCIATIVITY_24WAY, + SMBIOS_CACHE_ASSOCIATIVITY_32WAY, + SMBIOS_CACHE_ASSOCIATIVITY_48WAY, + SMBIOS_CACHE_ASSOCIATIVITY_64WAY, + SMBIOS_CACHE_ASSOCIATIVITY_20WAY, +}; + +struct smbios_type7 { + u8 type; + u8 length; + u16 handle; + u8 socket_designation; + u16 cache_configuration; + u16 max_cache_size; + u16 installed_size; + u16 supported_sram_type; + u8 cache_speed; + u8 error_correction_type; + u8 system_cache_type; + u8 associativity; + u32 max_cache_size2; + u32 installed_size2; + u8 eos[2]; +} __packed; + struct smbios_type11 { u8 type; u8 length;
Hello build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/32131
to look at the new patch set (#2).
Change subject: arch/x86/smbios: Add type 7 ......................................................................
arch/x86/smbios: Add type 7
The SMBIOS spec requires type 7 to be present.
Add the type 7 fields and enums for SMBIOS 3.1+ and fill it with the "Deterministic Cache Parameters" as available on Intel and AMD.
As CPUID only provides partial information on caches, some fields are set to unknown. The following fields are supported: * Cache Level * Cache Size * Cache Type * Cache Ways of Associativity
Change-Id: I80ed25b8f2c7b425136b2f0c755324a8f5d1636d Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M src/arch/x86/smbios.c M src/include/smbios.h 2 files changed, 256 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/31/32131/2
HAOUAS Elyes has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 2: Code-Review+1
Richard Spiegel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/#/c/32131/2//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/32131/2//COMMIT_MSG@21 PS2, Line 21: Was it tested? How?
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/#/c/32131/2//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/32131/2//COMMIT_MSG@21 PS2, Line 21:
Was it tested? How?
Not yet tested, I'm looking for a test system.
Lijian Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 2:
the following is the whiskeylake CPU I get Handle 0x0005, DMI type 7, 25 bytes Cache Information Socket Designation: CACHE0 Configuration: Enabled, Not Socketed, Level 2 Operational Mode: Varies With Memory Address Location: Internal Installed Size: 0 kB Maximum Size: 32768 kB Supported SRAM Types: Unknown Installed SRAM Type: None Speed: 4 ns Error Correction Type: <OUT OF SPEC> System Type: <OUT OF SPEC> Associativity: <OUT OF SPEC>
Handle 0x0006, DMI type 7, 25 bytes Cache Information Socket Designation: CACHE1 Configuration: Enabled, Not Socketed, Level 2 Operational Mode: Varies With Memory Address Location: Internal Installed Size: 0 kB Maximum Size: 32768 kB Supported SRAM Types: Unknown Installed SRAM Type: None Speed: 3 ns Error Correction Type: <OUT OF SPEC> System Type: <OUT OF SPEC> Associativity: <OUT OF SPEC>
Handle 0x0007, DMI type 7, 25 bytes Cache Information Socket Designation: CACHE2 Configuration: Enabled, Not Socketed, Level 3 Operational Mode: Varies With Memory Address Location: Internal Installed Size: 256 kB Maximum Size: 294912 kB Supported SRAM Types: Unknown Installed SRAM Type: None Speed: 5 ns Error Correction Type: Single-bit ECC System Type: Data Associativity: <OUT OF SPEC>
Lijian Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 2:
Patch Set 2:
the following is the whiskeylake CPU I get Handle 0x0005, DMI type 7, 25 bytes Cache Information Socket Designation: CACHE0 Configuration: Enabled, Not Socketed, Level 2 Operational Mode: Varies With Memory Address Location: Internal Installed Size: 0 kB Maximum Size: 32768 kB Supported SRAM Types: Unknown Installed SRAM Type: None Speed: 4 ns Error Correction Type: <OUT OF SPEC> System Type: <OUT OF SPEC> Associativity: <OUT OF SPEC>
Handle 0x0006, DMI type 7, 25 bytes Cache Information Socket Designation: CACHE1 Configuration: Enabled, Not Socketed, Level 2 Operational Mode: Varies With Memory Address Location: Internal Installed Size: 0 kB Maximum Size: 32768 kB Supported SRAM Types: Unknown Installed SRAM Type: None Speed: 3 ns Error Correction Type: <OUT OF SPEC> System Type: <OUT OF SPEC> Associativity: <OUT OF SPEC>
Handle 0x0007, DMI type 7, 25 bytes Cache Information Socket Designation: CACHE2 Configuration: Enabled, Not Socketed, Level 3 Operational Mode: Varies With Memory Address Location: Internal Installed Size: 256 kB Maximum Size: 294912 kB Supported SRAM Types: Unknown Installed SRAM Type: None Speed: 5 ns Error Correction Type: Single-bit ECC System Type: Data Associativity: <OUT OF SPEC>
Dmidecode report that at the end
Wrong DMI structures count: 16 announced, only 12 decoded. Wrong DMI structures length: 626 bytes announced, structures occupy 657 bytes.
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 2:
Patch Set 2:
the following is the whiskeylake CPU I get Handle 0x0005, DMI type 7, 25 bytes Cache Information Socket Designation: CACHE0 Configuration: Enabled, Not Socketed, Level 2 Operational Mode: Varies With Memory Address Location: Internal Installed Size: 0 kB Maximum Size: 32768 kB Supported SRAM Types: Unknown Installed SRAM Type: None Speed: 4 ns Error Correction Type: <OUT OF SPEC> System Type: <OUT OF SPEC> Associativity: <OUT OF SPEC>
Handle 0x0006, DMI type 7, 25 bytes Cache Information Socket Designation: CACHE1 Configuration: Enabled, Not Socketed, Level 2 Operational Mode: Varies With Memory Address Location: Internal Installed Size: 0 kB Maximum Size: 32768 kB Supported SRAM Types: Unknown Installed SRAM Type: None Speed: 3 ns Error Correction Type: <OUT OF SPEC> System Type: <OUT OF SPEC> Associativity: <OUT OF SPEC>
Handle 0x0007, DMI type 7, 25 bytes Cache Information Socket Designation: CACHE2 Configuration: Enabled, Not Socketed, Level 3 Operational Mode: Varies With Memory Address Location: Internal Installed Size: 256 kB Maximum Size: 294912 kB Supported SRAM Types: Unknown Installed SRAM Type: None Speed: 5 ns Error Correction Type: Single-bit ECC System Type: Data Associativity: <OUT OF SPEC>
Dmidecode report that at the end
Wrong DMI structures count: 16 announced, only 12 decoded. Wrong DMI structures length: 626 bytes announced, structures occupy 657 bytes.
Thanks for testing. It looks like the "Current SRAM Type" field is missing, causing the corruption. I'll update the patch series.
HAOUAS Elyes has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/#/c/32131/2//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/32131/2//COMMIT_MSG@11 PS2, Line 11: SMBIOS 3.1+ Please, why isn't 3.2 ?
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 2: Code-Review+1
(2 comments)
https://review.coreboot.org/#/c/32131/2/src/arch/x86/smbios.c File src/arch/x86/smbios.c:
https://review.coreboot.org/#/c/32131/2/src/arch/x86/smbios.c@687 PS2, Line 687: Remove the blank line?
https://review.coreboot.org/#/c/32131/2/src/arch/x86/smbios.c@695 PS2, Line 695: the Remove the article, because it’s not a full sentence, and no article is used in the other description.
Hello Aaron Durbin, HAOUAS Elyes, Sven Schnelle, Kane Chen, Lee Leahy, Richard Spiegel, Paul Menzel, Philipp Deppenwiese, build bot (Jenkins), Martin Roth, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/32131
to look at the new patch set (#3).
Change subject: arch/x86/smbios: Add type 7 ......................................................................
arch/x86/smbios: Add type 7
The SMBIOS spec requires type 7 to be present.
Add the type 7 fields and enums for SMBIOS 3.1+ and fill it with the "Deterministic Cache Parameters" as available on Intel and AMD.
As CPUID only provides partial information on caches, some fields are set to unknown. The following fields are supported: * Cache Level * Cache Size * Cache Type * Cache Ways of Associativity
Tested on Intel Sandy Bridge (Lenovo T520). All 4 caches are displayed in dmidecode and show the correct information.
Change-Id: I80ed25b8f2c7b425136b2f0c755324a8f5d1636d Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M src/arch/x86/smbios.c M src/include/smbios.h 2 files changed, 258 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/31/32131/3
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 3:
(3 comments)
Tested on Lenovo T520 (Intel Sandy Bridge). All caches are listed.
https://review.coreboot.org/#/c/32131/2//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/32131/2//COMMIT_MSG@11 PS2, Line 11: SMBIOS 3.1+
Please, why isn't 3. […]
The structure was last updated with 3.1. It didn't change with 3.2.
https://review.coreboot.org/#/c/32131/2/src/arch/x86/smbios.c File src/arch/x86/smbios.c:
https://review.coreboot.org/#/c/32131/2/src/arch/x86/smbios.c@687 PS2, Line 687:
Remove the blank line?
Done
https://review.coreboot.org/#/c/32131/2/src/arch/x86/smbios.c@695 PS2, Line 695: the
Remove the article, because it’s not a full sentence, and no article is used in the other descriptio […]
Done
Richard Spiegel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 3:
(1 comment)
One little detail I did not noticed before, then I'll approve it.
https://review.coreboot.org/#/c/32131/3/src/arch/x86/smbios.c File src/arch/x86/smbios.c:
https://review.coreboot.org/#/c/32131/3/src/arch/x86/smbios.c@648 PS3, Line 648: ; //Unknown /* unknown */
Lijian Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 3:
Handle 0x0005, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE0 Configuration: Enabled, Not Socketed, Level 1 Operational Mode: Unknown Location: Internal Installed Size: 32 kB Maximum Size: 32 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Data Associativity: 8-way Set-associative
Handle 0x0006, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE1 Configuration: Enabled, Not Socketed, Level 1 Operational Mode: Unknown Location: Internal Installed Size: 32 kB Maximum Size: 32 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Instruction Associativity: 8-way Set-associative
Handle 0x0007, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE2 Configuration: Enabled, Not Socketed, Level 2 Operational Mode: Unknown Location: Internal Installed Size: 256 kB Maximum Size: 256 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Unified Associativity: 4-way Set-associative
Handle 0x0008, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE3 Configuration: Enabled, Not Socketed, Level 3 Operational Mode: Unknown Location: Internal Installed Size: 8192 kB Maximum Size: 8192 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Unified Associativity: 16-way Set-associative
From whiskeylake, I think the patch itself is already okay, but we may need to update the details
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 3:
Patch Set 3:
Handle 0x0005, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE0 Configuration: Enabled, Not Socketed, Level 1 Operational Mode: Unknown Location: Internal Installed Size: 32 kB Maximum Size: 32 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Data Associativity: 8-way Set-associative
Handle 0x0006, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE1 Configuration: Enabled, Not Socketed, Level 1 Operational Mode: Unknown Location: Internal Installed Size: 32 kB Maximum Size: 32 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Instruction Associativity: 8-way Set-associative
Handle 0x0007, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE2 Configuration: Enabled, Not Socketed, Level 2 Operational Mode: Unknown Location: Internal Installed Size: 256 kB Maximum Size: 256 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Unified Associativity: 4-way Set-associative
Handle 0x0008, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE3 Configuration: Enabled, Not Socketed, Level 3 Operational Mode: Unknown Location: Internal Installed Size: 8192 kB Maximum Size: 8192 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Unified Associativity: 16-way Set-associative
From whiskeylake, I think the patch itself is already okay, but we may need to update the details
Is it possible to query the unknown bits from hardware using CPUID or MSR? I couldn't find anything useful in the public documentation.
Lijian Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 3:
Patch Set 3:
Patch Set 3:
Handle 0x0005, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE0 Configuration: Enabled, Not Socketed, Level 1 Operational Mode: Unknown Location: Internal Installed Size: 32 kB Maximum Size: 32 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Data Associativity: 8-way Set-associative
Handle 0x0006, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE1 Configuration: Enabled, Not Socketed, Level 1 Operational Mode: Unknown Location: Internal Installed Size: 32 kB Maximum Size: 32 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Instruction Associativity: 8-way Set-associative
Handle 0x0007, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE2 Configuration: Enabled, Not Socketed, Level 2 Operational Mode: Unknown Location: Internal Installed Size: 256 kB Maximum Size: 256 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Unified Associativity: 4-way Set-associative
Handle 0x0008, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE3 Configuration: Enabled, Not Socketed, Level 3 Operational Mode: Unknown Location: Internal Installed Size: 8192 kB Maximum Size: 8192 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Unified Associativity: 16-way Set-associative
From whiskeylake, I think the patch itself is already okay, but we may need to update the details
Is it possible to query the unknown bits from hardware using CPUID or MSR? I couldn't find anything useful in the public documentation.
I am not able to find the report, the FSP code side just blindly report sram type as synchronous for all the caches
Hello Aaron Durbin, HAOUAS Elyes, Sven Schnelle, Kane Chen, Lee Leahy, Richard Spiegel, Paul Menzel, Philipp Deppenwiese, build bot (Jenkins), Martin Roth, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/32131
to look at the new patch set (#4).
Change subject: arch/x86/smbios: Add type 7 ......................................................................
arch/x86/smbios: Add type 7
The SMBIOS spec requires type 7 to be present.
Add the type 7 fields and enums for SMBIOS 3.1+ and fill it with the "Deterministic Cache Parameters" as available on Intel and AMD.
As CPUID only provides partial information on caches, some fields are set to unknown. The following fields are supported: * Cache Level * Cache Size * Cache Type * Cache Ways of Associativity
Tested on Intel Sandy Bridge (Lenovo T520). All 4 caches are displayed in dmidecode and show the correct information.
Change-Id: I80ed25b8f2c7b425136b2f0c755324a8f5d1636d Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M src/arch/x86/smbios.c M src/include/smbios.h 2 files changed, 258 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/31/32131/4
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 4:
(1 comment)
https://review.coreboot.org/#/c/32131/3/src/arch/x86/smbios.c File src/arch/x86/smbios.c:
https://review.coreboot.org/#/c/32131/3/src/arch/x86/smbios.c@648 PS3, Line 648: ; //Unknown
/* unknown */
Done
HAOUAS Elyes has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 4: Code-Review+1
Richard Spiegel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 4: Code-Review+1
There's a lot of "magic numbers", but I don't see an easy way to replace them without making expressions huge (beyond 80 characters). Still, if possible, I would like to see shift values and masks converted to literals. You might have to break lines into multiple lines (due to 80 characters limit). That's the only reason I'm not going for a +2. I don't care about CPUID, as I saw many other examples using magic numbers. I only care about shifts, masks, and values that are publicly available on the WEB. If a value is only on NDA documents, it's OK to have magic numbers.
Hello Aaron Durbin, Sven Schnelle, Angel Pons, Arthur Heymans, Kane Chen, Richard Spiegel, Paul Menzel, build bot (Jenkins), Patrick Georgi, Johannes Hahn, Werner Zeh, HAOUAS Elyes, Lee Leahy, Philipp Deppenwiese, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/32131
to look at the new patch set (#5).
Change subject: arch/x86/smbios: Add type 7 ......................................................................
arch/x86/smbios: Add type 7
The SMBIOS spec requires type 7 to be present.
Add the type 7 fields and enums for SMBIOS 3.1+ and fill it with the "Deterministic Cache Parameters" as available on Intel and AMD.
As CPUID only provides partial information on caches, some fields are set to unknown. The following fields are supported: * Cache Level * Cache Size * Cache Type * Cache Ways of Associativity
Tested on Intel Sandy Bridge (Lenovo T520). All 4 caches are displayed in dmidecode and show the correct information.
Change-Id: I80ed25b8f2c7b425136b2f0c755324a8f5d1636d Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M src/arch/x86/include/arch/cpu.h M src/arch/x86/smbios.c M src/include/smbios.h 3 files changed, 338 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/31/32131/5
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 5:
Patch Set 4: Code-Review+1
There's a lot of "magic numbers", but I don't see an easy way to replace them without making expressions huge (beyond 80 characters). Still, if possible, I would like to see shift values and masks converted to literals. You might have to break lines into multiple lines (due to 80 characters limit). That's the only reason I'm not going for a +2. I don't care about CPUID, as I saw many other examples using magic numbers. I only care about shifts, masks, and values that are publicly available on the WEB. If a value is only on NDA documents, it's OK to have magic numbers.
Done. Added more macros and replaced magic numbers. Tested on Lenovo T520, still works.
Hello Aaron Durbin, Sven Schnelle, Angel Pons, Arthur Heymans, Kane Chen, Richard Spiegel, Paul Menzel, build bot (Jenkins), Patrick Georgi, Johannes Hahn, Werner Zeh, HAOUAS Elyes, Lee Leahy, Philipp Deppenwiese, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/32131
to look at the new patch set (#6).
Change subject: arch/x86/smbios: Add type 7 ......................................................................
arch/x86/smbios: Add type 7
The SMBIOS spec requires type 7 to be present.
Add the type 7 fields and enums for SMBIOS 3.1+ and fill it with the "Deterministic Cache Parameters" as available on Intel and AMD.
As CPUID only provides partial information on caches, some fields are set to unknown. The following fields are supported: * Cache Level * Cache Size * Cache Type * Cache Ways of Associativity
Tested on Intel Sandy Bridge (Lenovo T520). All 4 caches are displayed in dmidecode and show the correct information.
Change-Id: I80ed25b8f2c7b425136b2f0c755324a8f5d1636d Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M src/arch/x86/include/arch/cpu.h M src/arch/x86/smbios.c M src/include/smbios.h 3 files changed, 338 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/31/32131/6
Werner Zeh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 6:
Hey Patrick. I have tested this patchtrain on mc_apl2 now. Seems to work so far though there is still a warning left over in dmidecode. Here is the part of interest of dmidecode: Handle 0x0004, DMI type 4, 42 bytes Processor Information Socket Designation: Not Specified Type: Central Processor Family: Pentium Pro Manufacturer: GenuineIntel ID: C9 06 05 00 FF FB EB BF Signature: Type 0, Family 6, Model 92, Stepping 9 Flags: FPU (Floating-point unit on-chip) VME (Virtual mode extension) DE (Debugging extension) PSE (Page size extension) TSC (Time stamp counter) MSR (Model specific registers) PAE (Physical address extension) MCE (Machine check exception) CX8 (CMPXCHG8 instruction supported) APIC (On-chip APIC hardware supported) SEP (Fast system call) MTRR (Memory type range registers) PGE (Page global enable) MCA (Machine check architecture) CMOV (Conditional move instruction supported) PAT (Page attribute table) PSE-36 (36-bit page size extension) CLFSH (CLFLUSH instruction supported) DS (Debug store) ACPI (ACPI supported) MMX (MMX technology supported) FXSR (FXSAVE and FXSTOR instructions supported) SSE (Streaming SIMD extensions) SSE2 (Streaming SIMD extensions 2) SS (Self-snoop) HTT (Multi-threading) TM (Thermal monitor supported) PBE (Pending break enabled) Version: Intel(R) Atom(TM) Processor E3940 @ 1.60GHz Voltage: Unknown External Clock: Unknown Max Speed: Unknown Current Speed: Unknown Status: Unpopulated Upgrade: Unknown L1 Cache Handle: 0x0006 L2 Cache Handle: 0x0007 L3 Cache Handle: Not Provided Serial Number: Not Specified Asset Tag: Not Specified Part Number: Not Specified Core Count: 32 Characteristics: None
Handle 0x0005, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE0 Configuration: Enabled, Not Socketed, Level 1 Operational Mode: Unknown Location: Internal Installed Size: 24 kB Maximum Size: 24 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Data Associativity: Unknown
Handle 0x0006, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE1 Configuration: Enabled, Not Socketed, Level 1 Operational Mode: Unknown Location: Internal Installed Size: 32 kB Maximum Size: 32 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Instruction Associativity: 8-way Set-associative
Handle 0x0007, DMI type 7, 27 bytes Cache Information Socket Designation: CACHE2 Configuration: Enabled, Not Socketed, Level 2 Operational Mode: Unknown Location: Internal Installed Size: 1024 kB Maximum Size: 1024 kB Supported SRAM Types: Unknown Installed SRAM Type: Unknown Speed: Unknown Error Correction Type: Unknown System Type: Unified Associativity: 16-way Set-associative
Handle 0x0009, DMI type 32, 11 bytes System Boot Information Status: No errors detected
Handle 0x000A, DMI type 127, 4 bytes End Of Table
Wrong DMI structures count: 11 announced, only 10 decoded.
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 6:
Wrong DMI structures count: 11 announced, only 10 decoded.
That's due to a bug in https://review.coreboot.org/c/coreboot/+/32132 patchset 6, fixed in patchset 7.
Richard Spiegel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 6:
Looks really good now from a code review point of view. It would merit a +2. However, there's the error Werner Zeh reported. Please fix it.
Richard Spiegel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
Patch Set 6: Code-Review+2
Patch Set 6:
Wrong DMI structures count: 11 announced, only 10 decoded.
That's due to a bug in https://review.coreboot.org/c/coreboot/+/32132 patchset 6, fixed in patchset 7.
If you already found and fixed it, approved.
Patrick Georgi has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/32131 )
Change subject: arch/x86/smbios: Add type 7 ......................................................................
arch/x86/smbios: Add type 7
The SMBIOS spec requires type 7 to be present.
Add the type 7 fields and enums for SMBIOS 3.1+ and fill it with the "Deterministic Cache Parameters" as available on Intel and AMD.
As CPUID only provides partial information on caches, some fields are set to unknown. The following fields are supported: * Cache Level * Cache Size * Cache Type * Cache Ways of Associativity
Tested on Intel Sandy Bridge (Lenovo T520). All 4 caches are displayed in dmidecode and show the correct information.
Change-Id: I80ed25b8f2c7b425136b2f0c755324a8f5d1636d Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/32131 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Richard Spiegel richard.spiegel@silverbackltd.com --- M src/arch/x86/include/arch/cpu.h M src/arch/x86/smbios.c M src/include/smbios.h 3 files changed, 338 insertions(+), 8 deletions(-)
Approvals: build bot (Jenkins): Verified Richard Spiegel: Looks good to me, approved
diff --git a/src/arch/x86/include/arch/cpu.h b/src/arch/x86/include/arch/cpu.h index 3e464e4..61b17a6 100644 --- a/src/arch/x86/include/arch/cpu.h +++ b/src/arch/x86/include/arch/cpu.h @@ -158,6 +158,47 @@ #define CPUID_FEATURE_PAE (1 << 6) #define CPUID_FEATURE_PSE36 (1 << 17)
+// Intel leaf 0x4, AMD leaf 0x8000001d EAX + +#define CPUID_CACHE(x, res) \ + (((res) >> CPUID_CACHE_##x##_SHIFT) & CPUID_CACHE_##x##_MASK) + +#define CPUID_CACHE_FULL_ASSOC_SHIFT 9 +#define CPUID_CACHE_FULL_ASSOC_MASK 0x1 +#define CPUID_CACHE_FULL_ASSOC(res) CPUID_CACHE(FULL_ASSOC, (res).eax) + +#define CPUID_CACHE_SELF_INIT_SHIFT 8 +#define CPUID_CACHE_SELF_INIT_MASK 0x1 +#define CPUID_CACHE_SELF_INIT(res) CPUID_CACHE(SELF_INIT, (res).eax) + +#define CPUID_CACHE_LEVEL_SHIFT 5 +#define CPUID_CACHE_LEVEL_MASK 0x7 +#define CPUID_CACHE_LEVEL(res) CPUID_CACHE(LEVEL, (res).eax) + +#define CPUID_CACHE_TYPE_SHIFT 0 +#define CPUID_CACHE_TYPE_MASK 0x1f +#define CPUID_CACHE_TYPE(res) CPUID_CACHE(TYPE, (res).eax) + +// Intel leaf 0x4, AMD leaf 0x8000001d EBX + +#define CPUID_CACHE_WAYS_OF_ASSOC_SHIFT 22 +#define CPUID_CACHE_WAYS_OF_ASSOC_MASK 0x3ff +#define CPUID_CACHE_WAYS_OF_ASSOC(res) CPUID_CACHE(WAYS_OF_ASSOC, (res).ebx) + +#define CPUID_CACHE_PHYS_LINE_SHIFT 12 +#define CPUID_CACHE_PHYS_LINE_MASK 0x3ff +#define CPUID_CACHE_PHYS_LINE(res) CPUID_CACHE(PHYS_LINE, (res).ebx) + +#define CPUID_CACHE_COHER_LINE_SHIFT 0 +#define CPUID_CACHE_COHER_LINE_MASK 0xfff +#define CPUID_CACHE_COHER_LINE(res) CPUID_CACHE(COHER_LINE, (res).ebx) + +// Intel leaf 0x4, AMD leaf 0x8000001d ECX + +#define CPUID_CACHE_NO_OF_SETS_SHIFT 0 +#define CPUID_CACHE_NO_OF_SETS_MASK 0xffffffff +#define CPUID_CACHE_NO_OF_SETS(res) CPUID_CACHE(NO_OF_SETS, (res).ecx) + int cpu_cpuid_extended_level(void); int cpu_have_cpuid(void);
diff --git a/src/arch/x86/smbios.c b/src/arch/x86/smbios.c index c01892a..0f9b458 100644 --- a/src/arch/x86/smbios.c +++ b/src/arch/x86/smbios.c @@ -34,6 +34,14 @@ #include <vendorcode/google/chromeos/gnvs.h> #endif
+#define update_max(len, max_len, stmt) \ + do { \ + int tmp = stmt; \ + \ + max_len = MAX(max_len, tmp); \ + len += tmp; \ + } while (0) + static u8 smbios_checksum(u8 *p, u32 length) { u8 ret = 0; @@ -602,6 +610,206 @@ return len; }
+/* + * Write SMBIOS type 7. + * Fill in some fields with constant values, as gathering the information + * from CPUID is impossible. + */ +static int +smbios_write_type7(unsigned long *current, + const int handle, + const u8 level, + const u8 sram_type, + const enum smbios_cache_associativity associativity, + const enum smbios_cache_type type, + const size_t max_cache_size, + const size_t cache_size) +{ + struct smbios_type7 *t = (struct smbios_type7 *)*current; + int len = sizeof(struct smbios_type7); + static unsigned int cnt = 0; + char buf[8]; + + memset(t, 0, sizeof(struct smbios_type7)); + t->type = SMBIOS_CACHE_INFORMATION; + t->handle = handle; + t->length = len - 2; + + snprintf(buf, sizeof(buf), "CACHE%x", cnt++); + t->socket_designation = smbios_add_string(t->eos, buf); + + t->cache_configuration = SMBIOS_CACHE_CONF_LEVEL(level) | + SMBIOS_CACHE_CONF_LOCATION(0) | /* Internal */ + SMBIOS_CACHE_CONF_ENABLED(1) | /* Enabled */ + SMBIOS_CACHE_CONF_OPERATION_MODE(3); /* Unknown */ + + if (max_cache_size < (SMBIOS_CACHE_SIZE_MASK * KiB)) { + t->max_cache_size = max_cache_size / KiB; + t->max_cache_size2 = t->max_cache_size; + + t->max_cache_size |= SMBIOS_CACHE_SIZE_UNIT_1KB; + t->max_cache_size2 |= SMBIOS_CACHE_SIZE2_UNIT_1KB; + } else { + if (cache_size < (SMBIOS_CACHE_SIZE_MASK * 64 * KiB)) + t->max_cache_size = max_cache_size / (64 * KiB); + else + t->max_cache_size = SMBIOS_CACHE_SIZE_OVERFLOW; + t->max_cache_size2 = max_cache_size / (64 * KiB); + + t->max_cache_size |= SMBIOS_CACHE_SIZE_UNIT_64KB; + t->max_cache_size2 |= SMBIOS_CACHE_SIZE2_UNIT_64KB; + } + + if (cache_size < (SMBIOS_CACHE_SIZE_MASK * KiB)) { + t->installed_size = cache_size / KiB; + t->installed_size2 = t->installed_size; + + t->installed_size |= SMBIOS_CACHE_SIZE_UNIT_1KB; + t->installed_size2 |= SMBIOS_CACHE_SIZE2_UNIT_1KB; + } else { + if (cache_size < (SMBIOS_CACHE_SIZE_MASK * 64 * KiB)) + t->installed_size = cache_size / (64 * KiB); + else + t->installed_size = SMBIOS_CACHE_SIZE_OVERFLOW; + t->installed_size2 = cache_size / (64 * KiB); + + t->installed_size |= SMBIOS_CACHE_SIZE_UNIT_64KB; + t->installed_size2 |= SMBIOS_CACHE_SIZE2_UNIT_64KB; + } + + t->associativity = associativity; + t->supported_sram_type = sram_type; + t->current_sram_type = sram_type; + t->cache_speed = 0; /* Unknown */ + t->error_correction_type = SMBIOS_CACHE_ERROR_CORRECTION_UNKNOWN; + t->system_cache_type = type; + + len = t->length + smbios_string_table_len(t->eos); + *current += len; + return len; +} + +/* Convert the associativity as integer to the SMBIOS enum if available */ +static enum smbios_cache_associativity +smbios_cache_associativity(const u8 num) +{ + switch (num) { + case 1: + return SMBIOS_CACHE_ASSOCIATIVITY_DIRECT; + case 2: + return SMBIOS_CACHE_ASSOCIATIVITY_2WAY; + case 4: + return SMBIOS_CACHE_ASSOCIATIVITY_4WAY; + case 8: + return SMBIOS_CACHE_ASSOCIATIVITY_8WAY; + case 12: + return SMBIOS_CACHE_ASSOCIATIVITY_12WAY; + case 16: + return SMBIOS_CACHE_ASSOCIATIVITY_16WAY; + case 20: + return SMBIOS_CACHE_ASSOCIATIVITY_20WAY; + case 24: + return SMBIOS_CACHE_ASSOCIATIVITY_24WAY; + case 32: + return SMBIOS_CACHE_ASSOCIATIVITY_32WAY; + case 48: + return SMBIOS_CACHE_ASSOCIATIVITY_48WAY; + case 64: + return SMBIOS_CACHE_ASSOCIATIVITY_64WAY; + case 0xff: + return SMBIOS_CACHE_ASSOCIATIVITY_FULL; + default: + return SMBIOS_CACHE_ASSOCIATIVITY_UNKNOWN; + }; +} + +/* + * Parse the "Deterministic Cache Parameters" as provided by Intel in + * leaf 4 or AMD in extended leaf 0x8000001d. + * + * @param current Pointer to memory address to write the tables to + * @param handle Pointer to handle for the tables + * @param max_struct_size Pointer to maximum struct size + */ +static int smbios_write_type7_cache_parameters(unsigned long *current, + int *handle, + int *max_struct_size) +{ + struct cpuid_result res; + unsigned int cnt = 0; + int len = 0; + u32 leaf; + + if (!cpu_have_cpuid()) + return len; + + if (cpu_is_intel()) { + res = cpuid(0); + if (res.eax < 4) + return len; + leaf = 4; + } else if (cpu_is_amd()) { + res = cpuid(0x80000000); + if (res.eax < 0x80000001) + return len; + + res = cpuid(0x80000001); + if (!(res.ecx & (1 << 22))) + return len; + + leaf = 0x8000001d; + } else { + printk(BIOS_DEBUG, "SMBIOS: Unknown CPU\n"); + return len; + } + + while (1) { + enum smbios_cache_associativity associativity; + enum smbios_cache_type type; + + res = cpuid_ext(leaf, cnt++); + + const u8 cache_type = CPUID_CACHE_TYPE(res); + const u8 level = CPUID_CACHE_LEVEL(res); + const size_t assoc = CPUID_CACHE_WAYS_OF_ASSOC(res) + 1; + const size_t partitions = CPUID_CACHE_PHYS_LINE(res) + 1; + const size_t cache_line_size = CPUID_CACHE_COHER_LINE(res) + 1; + const size_t number_of_sets = CPUID_CACHE_NO_OF_SETS(res) + 1; + const size_t cache_size = assoc * partitions * cache_line_size * + number_of_sets; + + if (!cache_type) + /* No more caches in the system */ + break; + + switch (cache_type) { + case 1: + type = SMBIOS_CACHE_TYPE_DATA; + break; + case 2: + type = SMBIOS_CACHE_TYPE_INSTRUCTION; + break; + case 3: + type = SMBIOS_CACHE_TYPE_UNIFIED; + break; + default: + type = SMBIOS_CACHE_TYPE_UNKNOWN; + break; + } + + if (CPUID_CACHE_FULL_ASSOC(res)) + associativity = SMBIOS_CACHE_ASSOCIATIVITY_FULL; + else + associativity = smbios_cache_associativity(assoc); + + update_max(len, *max_struct_size, smbios_write_type7(current, + *handle++, level, SMBIOS_CACHE_SRAM_TYPE_UNKNOWN, + associativity, type, cache_size, cache_size)); + }; + + return len; +} + static int smbios_write_type11(unsigned long *current, int *handle) { struct smbios_type11 *t = (struct smbios_type11 *)*current; @@ -748,14 +956,6 @@ return len; }
-#define update_max(len, max_len, stmt) \ - do { \ - int tmp = stmt; \ - \ - max_len = MAX(max_len, tmp); \ - len += tmp; \ - } while (0) - unsigned long smbios_write_tables(unsigned long current) { struct smbios_entry *se; @@ -783,6 +983,8 @@ handle++)); update_max(len, max_struct_size, smbios_write_type4(¤t, handle++)); + len += smbios_write_type7_cache_parameters(¤t, &handle, + &max_struct_size); update_max(len, max_struct_size, smbios_write_type11(¤t, &handle)); if (CONFIG(ELOG)) diff --git a/src/include/smbios.h b/src/include/smbios.h index af83bfe..08e6b61 100644 --- a/src/include/smbios.h +++ b/src/include/smbios.h @@ -393,6 +393,93 @@ u8 eos[2]; } __packed;
+/* defines for supported_sram_type/current_sram_type */ + +#define SMBIOS_CACHE_SRAM_TYPE_OTHER (1 << 0) +#define SMBIOS_CACHE_SRAM_TYPE_UNKNOWN (1 << 1) +#define SMBIOS_CACHE_SRAM_TYPE_NON_BURST (1 << 2) +#define SMBIOS_CACHE_SRAM_TYPE_BURST (1 << 3) +#define SMBIOS_CACHE_SRAM_TYPE_PIPELINE_BURST (1 << 4) +#define SMBIOS_CACHE_SRAM_TYPE_SYNCHRONOUS (1 << 5) +#define SMBIOS_CACHE_SRAM_TYPE_ASYNCHRONOUS (1 << 6) + +/* enum for error_correction_type */ + +enum smbios_cache_error_corr { + SMBIOS_CACHE_ERROR_CORRECTION_OTHER = 1, + SMBIOS_CACHE_ERROR_CORRECTION_UNKNOWN, + SMBIOS_CACHE_ERROR_CORRECTION_NONE, + SMBIOS_CACHE_ERROR_CORRECTION_PARITY, + SMBIOS_CACHE_ERROR_CORRECTION_SINGLE_BIT, + SMBIOS_CACHE_ERROR_CORRECTION_MULTI_BIT, +}; + +/* enum for system_cache_type */ + +enum smbios_cache_type { + SMBIOS_CACHE_TYPE_OTHER = 1, + SMBIOS_CACHE_TYPE_UNKNOWN, + SMBIOS_CACHE_TYPE_INSTRUCTION, + SMBIOS_CACHE_TYPE_DATA, + SMBIOS_CACHE_TYPE_UNIFIED, +}; + +/* enum for associativity */ + +enum smbios_cache_associativity { + SMBIOS_CACHE_ASSOCIATIVITY_OTHER = 1, + SMBIOS_CACHE_ASSOCIATIVITY_UNKNOWN, + SMBIOS_CACHE_ASSOCIATIVITY_DIRECT, + SMBIOS_CACHE_ASSOCIATIVITY_2WAY, + SMBIOS_CACHE_ASSOCIATIVITY_4WAY, + SMBIOS_CACHE_ASSOCIATIVITY_FULL, + SMBIOS_CACHE_ASSOCIATIVITY_8WAY, + SMBIOS_CACHE_ASSOCIATIVITY_16WAY, + SMBIOS_CACHE_ASSOCIATIVITY_12WAY, + SMBIOS_CACHE_ASSOCIATIVITY_24WAY, + SMBIOS_CACHE_ASSOCIATIVITY_32WAY, + SMBIOS_CACHE_ASSOCIATIVITY_48WAY, + SMBIOS_CACHE_ASSOCIATIVITY_64WAY, + SMBIOS_CACHE_ASSOCIATIVITY_20WAY, +}; + +/* defines for cache_configuration */ + +#define SMBIOS_CACHE_CONF_LEVEL(x) ((((x) - 1) & 0x7) << 0) +#define SMBIOS_CACHE_CONF_LOCATION(x) (((x) & 0x3) << 5) +#define SMBIOS_CACHE_CONF_ENABLED(x) (((x) & 0x1) << 7) +#define SMBIOS_CACHE_CONF_OPERATION_MODE(x) (((x) & 0x3) << 8) + +/* defines for max_cache_size and installed_size */ + +#define SMBIOS_CACHE_SIZE_UNIT_1KB (0 << 15) +#define SMBIOS_CACHE_SIZE_UNIT_64KB (1 << 15) +#define SMBIOS_CACHE_SIZE_MASK 0x7fff +#define SMBIOS_CACHE_SIZE_OVERFLOW 0xffff + +#define SMBIOS_CACHE_SIZE2_UNIT_1KB (0 << 31) +#define SMBIOS_CACHE_SIZE2_UNIT_64KB (1UL << 31) +#define SMBIOS_CACHE_SIZE2_MASK 0x7fffffff + +struct smbios_type7 { + u8 type; + u8 length; + u16 handle; + u8 socket_designation; + u16 cache_configuration; + u16 max_cache_size; + u16 installed_size; + u16 supported_sram_type; + u16 current_sram_type; + u8 cache_speed; + u8 error_correction_type; + u8 system_cache_type; + u8 associativity; + u32 max_cache_size2; + u32 installed_size2; + u8 eos[2]; +} __packed; + struct smbios_type11 { u8 type; u8 length;