Raul Rangel has uploaded this change for review. ( https://review.coreboot.org/25412
Change subject: src/lib/dimm_info_util.c: Add methods to convert from SMBIOS to SPD
......................................................................
src/lib/dimm_info_util.c: Add methods to convert from SMBIOS to SPD
AMD AGESA returns DIMM info in SMBIOS format. dimm_info expects the data
in SPD format. These methods will be used to update amd_late_init.c so
it sets the correct values.
BUG=b:65403853
TEST=Tested on grunt
Change-Id: Id9fa98e9aad83dfd0a86f45e18b3c312665dce9b
Signed-off-by: Raul E Rangel <rrangel(a)chromium.org>
---
A src/include/dimm_info_util.h
M src/include/spd.h
M src/lib/Makefile.inc
A src/lib/dimm_info_util.c
4 files changed, 148 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/12/25412/1
diff --git a/src/include/dimm_info_util.h b/src/include/dimm_info_util.h
new file mode 100644
index 0000000..71630ac
--- /dev/null
+++ b/src/include/dimm_info_util.h
@@ -0,0 +1,46 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _DIMM_INFO_UTIL_H_
+#define _DIMM_INFO_UTIL_H_
+
+#include <smbios.h>
+#include <stdint.h>
+
+/**
+ * Convert the SMBIOS bit widths into an SPD encoded width.
+ *
+ * Use this when setting dimm_info.bus_width if the raw SPD values are not
+ * available.
+ */
+uint8_t smbios_bus_width_to_spd_width(uint16_t total_width,
+ uint16_t data_width);
+
+/**
+ * Convert the SMBIOS size values into the total number of MiB.
+ *
+ * Use this when setting dimm_info.dimm_size.
+ */
+uint32_t smbios_memory_size_to_mib(uint16_t memory_size,
+ uint32_t extended_size);
+/**
+ * Convert the SMBIOS form factor to the SPD module type.
+ *
+ * Use this when setting dimm_info.mod_type.
+ */
+uint8_t
+smbios_form_factor_to_spd_mod_type(smbios_memory_form_factor form_factor);
+
+#endif
diff --git a/src/include/spd.h b/src/include/spd.h
index 9ada5c3..e9c23f2 100644
--- a/src/include/spd.h
+++ b/src/include/spd.h
@@ -289,7 +289,7 @@
#define RC62 62
#define RC63 63
-/* Byte 20: DIMM type information */
+/* Byte 3: Module type information */
#define SPD_UNDEFINED 0x00
#define SPD_RDIMM 0x01
#define SPD_UDIMM 0x02
@@ -300,4 +300,6 @@
#define SPD_MINI_RDIMM 0x10
#define SPD_MINI_UDIMM 0x20
+#define SPD_ECC_8BIT (1<<3)
+
#endif
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index 3ae77a6..fcc3d7c 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -110,6 +110,7 @@
ramstage-y += memcmp.c
ramstage-y += malloc.c
smm-$(CONFIG_SMM_TSEG) += malloc.c
+ramstage-y += dimm_info_util.c
ramstage-y += delay.c
ramstage-y += fallback_boot.c
ramstage-y += compute_ip_checksum.c
diff --git a/src/lib/dimm_info_util.c b/src/lib/dimm_info_util.c
new file mode 100644
index 0000000..3e0d87f
--- /dev/null
+++ b/src/lib/dimm_info_util.c
@@ -0,0 +1,98 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <dimm_info_util.h>
+#include <smbios.h>
+#include <spd.h>
+#include <console/console.h>
+
+uint8_t smbios_bus_width_to_spd_width(uint16_t total_width, uint16_t data_width)
+{
+ uint8_t out;
+
+ /* Lookup table as defined in the JEDEC Standard. */
+ switch (data_width) {
+ case 64:
+ out = MEMORY_BUS_WIDTH_64;
+ break;
+ case 32:
+ out = MEMORY_BUS_WIDTH_32;
+ break;
+ case 16:
+ out = MEMORY_BUS_WIDTH_16;
+ break;
+ case 8:
+ out = MEMORY_BUS_WIDTH_8;
+ break;
+ default:
+ printk(BIOS_NOTICE, "Unknown memory size %hu", data_width);
+ /*
+ * The SMBIOS spec says we should set 0xFFFF on an unknown
+ * value, but we don't have a way of passing that signal via SPD
+ * encoded values.
+ */
+ out = MEMORY_BUS_WIDTH_8;
+ break;
+ }
+
+ uint16_t extension_bits = total_width - data_width;
+
+ switch (extension_bits) {
+ case 8:
+ out |= SPD_ECC_8BIT;
+ break;
+ case 0:
+ /* No extension bits */
+ break;
+ default:
+ printk(BIOS_NOTICE, "Unknown number of extension bits %hu",
+ extension_bits);
+ break;
+ }
+
+ return out;
+}
+
+uint32_t smbios_memory_size_to_mib(uint16_t memory_size, uint32_t extended_size)
+{
+ /* Memory size is unknown */
+ if (memory_size == 0xFFFF)
+ return 0;
+ /* (32 GiB - 1 MiB) or greater is expressed in the extended size. */
+ else if (memory_size == 0x7FFF)
+ return extended_size;
+ /* When the MSB is flipped, the value is specified in kilobytes */
+ else if (memory_size & 0x8000)
+ return (memory_size ^ 0x8000) / KiB;
+ /* Value contains MiB */
+ else
+ return memory_size;
+}
+
+uint8_t
+smbios_form_factor_to_spd_mod_type(smbios_memory_form_factor form_factor)
+{
+ /* This switch reverses the switch in smbios.c */
+ switch (form_factor) {
+ case MEMORY_FORMFACTOR_DIMM:
+ return SPD_UDIMM;
+ case MEMORY_FORMFACTOR_RIMM:
+ return SPD_RDIMM;
+ case MEMORY_FORMFACTOR_SODIMM:
+ return SPD_SODIMM;
+ default:
+ return SPD_UNDEFINED;
+ }
+}
--
To view, visit https://review.coreboot.org/25412
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9fa98e9aad83dfd0a86f45e18b3c312665dce9b
Gerrit-Change-Number: 25412
Gerrit-PatchSet: 1
Gerrit-Owner: Raul Rangel <rrangel(a)chromium.org>
Raul Rangel has uploaded this change for review. ( https://review.coreboot.org/25411
Change subject: src/include/hexutil.h: Add converters for working with hex strings
......................................................................
src/include/hexutil.h: Add converters for working with hex strings
These utilities will be used as part of fixing SMBIOS generation for
soc/amd.
I have a bunch of unit tests for these functions outside of this commit. Is
there somewhere I can commit them?
BUG=b:65403853
TEST=tested on grunt
Change-Id: Ifcabf09be4dc053f8b6e132b4014380cdb5c521b
Signed-off-by: Raul E Rangel <rrangel(a)chromium.org>
---
A src/include/hexutil.h
M src/lib/Makefile.inc
A src/lib/hexutil.c
3 files changed, 137 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/11/25411/1
diff --git a/src/include/hexutil.h b/src/include/hexutil.h
new file mode 100644
index 0000000..847d39c
--- /dev/null
+++ b/src/include/hexutil.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Google LLC.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef HEXUTIL_H
+#define HEXUTIL_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+/**
+ * Decodes a hex character [0-9A-Za-z] into a byte.
+ *
+ * Invalid characters are mapped to 0.
+ * */
+uint8_t decode_hex_character(char hex);
+
+/**
+ * Decodes a hex string into a byte array.
+ *
+ * Examples:
+ * * "01AF" => {0x01, 0xAF}
+ * * "1AF" => {0x01, 0xAF}
+ * * "1AF" => {0x00, 0x00, 0x01, 0xAF} w/ 4 byte dest buffer.
+ *
+ * @param src_size size of the src buffer
+ * @param dest_size must be at least (strlen(src) + 1) / 2 in size. If the
+ * buffer is bigger than required the most significant bytes are cleared.
+ */
+void decode_hex_string(const char *src, size_t src_size, uint8_t *dest,
+ size_t dest_size);
+
+/**
+ * Encodes a byte array into a hex string.
+ *
+ * e.g., {0x01, 0x02} => "0102"
+ *
+ * @param dest_size must be at least (src_size * 2 + 1). If it is smaller, the
+ * least significant bytes will be truncated.
+ * @return number of characters written excluding the null terminator.
+ */
+size_t encode_as_hex_string(const uint8_t *src, size_t src_size, char *dest,
+ size_t dest_size);
+#endif
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index 960b5cb..3ae77a6 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -133,6 +133,7 @@
ramstage-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
ramstage-$(CONFIG_GENERIC_UDELAY) += timer.c
ramstage-y += b64_decode.c
+ramstage-y += hexutil.c
ramstage-$(CONFIG_ACPI_NHLT) += nhlt.c
romstage-y += cbmem_common.c
diff --git a/src/lib/hexutil.c b/src/lib/hexutil.c
new file mode 100644
index 0000000..a41a94a
--- /dev/null
+++ b/src/lib/hexutil.c
@@ -0,0 +1,81 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Google LLC.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <hexutil.h>
+#include <string.h>
+
+uint8_t decode_hex_character(char hex)
+{
+ if (isdigit(hex))
+ return hex - '0';
+ else if (isxdigit(hex) && isupper(hex))
+ return hex - 'A' + 10;
+ else if (isxdigit(hex) && islower(hex))
+ return hex - 'a' + 10;
+ else
+ return 0;
+}
+
+void decode_hex_string(const char *src, size_t src_size, uint8_t *dest,
+ size_t dest_size)
+{
+ const size_t src_len = strnlen(src, src_size);
+
+ for (size_t dest_idx = 0; dest_idx < dest_size; ++dest_idx) {
+ int src_idx = (src_len - 1) - dest_idx * 2;
+
+ uint8_t byte = 0;
+
+ if (src_idx >= 0) {
+ char low = src[src_idx];
+ byte |= decode_hex_character(low);
+ }
+
+ if (src_idx >= 1) {
+ char high = src[src_idx - 1];
+ byte |= decode_hex_character(high) << 4;
+ }
+
+ dest[(dest_size - 1) - dest_idx] = byte;
+ }
+}
+
+size_t encode_as_hex_string(const uint8_t *src, size_t src_size, char *dest,
+ size_t dest_size)
+{
+ size_t cnt = 0;
+
+ if (src_size == 0 && dest_size > 0)
+ dest[0] = '\0';
+
+ for (size_t src_idx = 0; src_idx < src_size; ++src_idx) {
+ size_t dest_offset = src_idx * 2;
+
+ if (dest_offset + 3 <= dest_size) {
+ snprintf(dest + dest_offset, 3, "%02hhx", src[src_idx]);
+ cnt += 2;
+ } else if (dest_offset + 2 <= dest_size) {
+ snprintf(dest + dest_offset, 2, "%hhx",
+ src[src_idx] >> 4);
+ cnt += 1;
+ } else if (dest_offset < dest_size) {
+ dest[dest_offset] = '\0';
+
+ break;
+ }
+ }
+
+ return cnt;
+}
--
To view, visit https://review.coreboot.org/25411
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifcabf09be4dc053f8b6e132b4014380cdb5c521b
Gerrit-Change-Number: 25411
Gerrit-PatchSet: 1
Gerrit-Owner: Raul Rangel <rrangel(a)chromium.org>
Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/25407
Change subject: Add GPU_Port types that are convenient for GMCH to use
......................................................................
Add GPU_Port types that are convenient for GMCH to use
Change-Id: I9120d084637d36a7e2276fcf3f630b3f7ed32509
Signed-off-by: Arthur Heymans <arthur(a)aheymans.xyz>
---
M common/haswell_shared/hw-gfx-gma-connectors-ddi.ads
M common/haswell_shared/hw-gfx-gma-connectors.adb
M common/hw-gfx-gma-connector_info.adb
M common/hw-gfx-gma.ads
4 files changed, 25 insertions(+), 11 deletions(-)
git pull ssh://review.coreboot.org:29418/libgfxinit refs/changes/07/25407/1
diff --git a/common/haswell_shared/hw-gfx-gma-connectors-ddi.ads b/common/haswell_shared/hw-gfx-gma-connectors-ddi.ads
index ec1fce2..d43db97 100644
--- a/common/haswell_shared/hw-gfx-gma-connectors-ddi.ads
+++ b/common/haswell_shared/hw-gfx-gma-connectors-ddi.ads
@@ -22,9 +22,14 @@
procedure Pre_On
(Port_Cfg : in Port_Config;
PLL_Hint : in Word32;
- Success : out Boolean);
+ Success : out Boolean)
+ with
+ Pre => Port_Cfg.Port in Digital_Port;
- procedure Post_On (Port_Cfg : Port_Config);
+ procedure Post_On (Port_Cfg : Port_Config)
+ with
+ Pre => Port_Cfg.Port in Digital_Port;
+
procedure Off (Port : Digital_Port);
diff --git a/common/haswell_shared/hw-gfx-gma-connectors.adb b/common/haswell_shared/hw-gfx-gma-connectors.adb
index 0d0ed71..0aed750 100644
--- a/common/haswell_shared/hw-gfx-gma-connectors.adb
+++ b/common/haswell_shared/hw-gfx-gma-connectors.adb
@@ -41,8 +41,11 @@
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
-
- DDI.Pre_On (Port_Cfg, PLL_Hint, Success);
+ if Port_Cfg.Port in Digital_Port then
+ DDI.Pre_On (Port_Cfg, PLL_Hint, Success);
+ else
+ success := False; -- Should not happen
+ end if;
end Pre_On;
procedure Post_On
@@ -53,10 +56,12 @@
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
- DDI.Post_On (Port_Cfg);
+ if Port_Cfg.Port in Digital_Port then
+ DDI.Post_On (Port_Cfg);
- if Port_Cfg.Port = DIGI_A then
- Panel.Backlight_On;
+ if Port_Cfg.Port = DIGI_A then
+ Panel.Backlight_On;
+ end if;
end if;
Success := True;
@@ -79,8 +84,9 @@
is
begin
pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
-
- DDI.Off (Port_Cfg.Port);
+ if Port_Cfg.Port in Digital_Port then
+ DDI.Off (Port_Cfg.Port);
+ end if;
end Post_Off;
----------------------------------------------------------------------------
diff --git a/common/hw-gfx-gma-connector_info.adb b/common/hw-gfx-gma-connector_info.adb
index 798e61c..e8357be 100644
--- a/common/hw-gfx-gma-connector_info.adb
+++ b/common/hw-gfx-gma-connector_info.adb
@@ -87,7 +87,8 @@
begin
return
(if Port_Cfg.Port = DIGI_A or
- (Port_Cfg.Is_FDI and Port_Cfg.PCH_Port = PCH_LVDS)
+ (Port_Cfg.Is_FDI and Port_Cfg.PCH_Port = PCH_LVDS) or
+ Port_Cfg.Port = LVDS
then 6
else 8);
end Default_BPC;
diff --git a/common/hw-gfx-gma.ads b/common/hw-gfx-gma.ads
index 50a76a0..fadf437 100644
--- a/common/hw-gfx-gma.ads
+++ b/common/hw-gfx-gma.ads
@@ -126,9 +126,11 @@
subtype Active_Port_Type is Port_Type
range Port_Type'Succ (Disabled) .. Port_Type'Last;
- type GPU_Port is (DIGI_A, DIGI_B, DIGI_C, DIGI_D, DIGI_E);
+ type GPU_Port is (DIGI_A, DIGI_B, DIGI_C, DIGI_D, DIGI_E, LVDS, VGA);
subtype Digital_Port is GPU_Port range DIGI_A .. DIGI_E;
+ subtype GMCH_DP_Port is GPU_Port range DIGI_B .. DIGI_D;
+ subtype GMCH_HDMI_Port is GPU_Port range DIGI_B .. DIGI_C;
type PCH_Port is
(PCH_DAC, PCH_LVDS,
--
To view, visit https://review.coreboot.org/25407
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: libgfxinit
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9120d084637d36a7e2276fcf3f630b3f7ed32509
Gerrit-Change-Number: 25407
Gerrit-PatchSet: 1
Gerrit-Owner: Arthur Heymans <arthur(a)aheymans.xyz>