<p>Raul Rangel has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/25412">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">src/lib/dimm_info_util.c: Add methods to convert from SMBIOS to SPD<br><br>AMD AGESA returns DIMM info in SMBIOS format. dimm_info expects the data<br>in SPD format. These methods will be used to update amd_late_init.c so<br>it sets the correct values.<br><br>BUG=b:65403853<br>TEST=Tested on grunt<br><br>Change-Id: Id9fa98e9aad83dfd0a86f45e18b3c312665dce9b<br>Signed-off-by: Raul E Rangel <rrangel@chromium.org><br>---<br>A src/include/dimm_info_util.h<br>M src/include/spd.h<br>M src/lib/Makefile.inc<br>A src/lib/dimm_info_util.c<br>4 files changed, 148 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/12/25412/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/include/dimm_info_util.h b/src/include/dimm_info_util.h</span><br><span>new file mode 100644</span><br><span>index 0000000..71630ac</span><br><span>--- /dev/null</span><br><span>+++ b/src/include/dimm_info_util.h</span><br><span>@@ -0,0 +1,46 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright 2018 Google Inc.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or</span><br><span style="color: hsl(120, 100%, 40%);">+ * modify it under the terms of the GNU General Public License version</span><br><span style="color: hsl(120, 100%, 40%);">+ * 2 as published by the Free Software Foundation.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef _DIMM_INFO_UTIL_H_</span><br><span style="color: hsl(120, 100%, 40%);">+#define _DIMM_INFO_UTIL_H_</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <smbios.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdint.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/**</span><br><span style="color: hsl(120, 100%, 40%);">+ * Convert the SMBIOS bit widths into an SPD encoded width.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Use this when setting dimm_info.bus_width if the raw SPD values are not</span><br><span style="color: hsl(120, 100%, 40%);">+ * available.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+uint8_t smbios_bus_width_to_spd_width(uint16_t total_width,</span><br><span style="color: hsl(120, 100%, 40%);">+                                   uint16_t data_width);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/**</span><br><span style="color: hsl(120, 100%, 40%);">+ * Convert the SMBIOS size values into the total number of MiB.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Use this when setting dimm_info.dimm_size.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+uint32_t smbios_memory_size_to_mib(uint16_t memory_size,</span><br><span style="color: hsl(120, 100%, 40%);">+                            uint32_t extended_size);</span><br><span style="color: hsl(120, 100%, 40%);">+/**</span><br><span style="color: hsl(120, 100%, 40%);">+ * Convert the SMBIOS form factor to the SPD module type.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Use this when setting dimm_info.mod_type.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+uint8_t</span><br><span style="color: hsl(120, 100%, 40%);">+smbios_form_factor_to_spd_mod_type(smbios_memory_form_factor form_factor);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span>diff --git a/src/include/spd.h b/src/include/spd.h</span><br><span>index 9ada5c3..e9c23f2 100644</span><br><span>--- a/src/include/spd.h</span><br><span>+++ b/src/include/spd.h</span><br><span>@@ -289,7 +289,7 @@</span><br><span> #define RC62 62</span><br><span> #define RC63 63</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* Byte 20: DIMM type information */</span><br><span style="color: hsl(120, 100%, 40%);">+/* Byte 3: Module type information */</span><br><span> #define SPD_UNDEFINED 0x00</span><br><span> #define SPD_RDIMM 0x01</span><br><span> #define SPD_UDIMM 0x02</span><br><span>@@ -300,4 +300,6 @@</span><br><span> #define SPD_MINI_RDIMM 0x10</span><br><span> #define SPD_MINI_UDIMM 0x20</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define SPD_ECC_8BIT (1<<3)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #endif</span><br><span>diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc</span><br><span>index 3ae77a6..fcc3d7c 100644</span><br><span>--- a/src/lib/Makefile.inc</span><br><span>+++ b/src/lib/Makefile.inc</span><br><span>@@ -110,6 +110,7 @@</span><br><span> ramstage-y += memcmp.c</span><br><span> ramstage-y += malloc.c</span><br><span> smm-$(CONFIG_SMM_TSEG) += malloc.c</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-y += dimm_info_util.c</span><br><span> ramstage-y += delay.c</span><br><span> ramstage-y += fallback_boot.c</span><br><span> ramstage-y += compute_ip_checksum.c</span><br><span>diff --git a/src/lib/dimm_info_util.c b/src/lib/dimm_info_util.c</span><br><span>new file mode 100644</span><br><span>index 0000000..3e0d87f</span><br><span>--- /dev/null</span><br><span>+++ b/src/lib/dimm_info_util.c</span><br><span>@@ -0,0 +1,98 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright 2018 Google Inc.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <dimm_info_util.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <smbios.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <spd.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <console/console.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+uint8_t smbios_bus_width_to_spd_width(uint16_t total_width, uint16_t data_width)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     uint8_t out;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* Lookup table as defined in the JEDEC Standard. */</span><br><span style="color: hsl(120, 100%, 40%);">+  switch (data_width) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case 64:</span><br><span style="color: hsl(120, 100%, 40%);">+              out = MEMORY_BUS_WIDTH_64;</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case 32:</span><br><span style="color: hsl(120, 100%, 40%);">+              out = MEMORY_BUS_WIDTH_32;</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case 16:</span><br><span style="color: hsl(120, 100%, 40%);">+              out = MEMORY_BUS_WIDTH_16;</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case 8:</span><br><span style="color: hsl(120, 100%, 40%);">+               out = MEMORY_BUS_WIDTH_8;</span><br><span style="color: hsl(120, 100%, 40%);">+             break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              printk(BIOS_NOTICE, "Unknown memory size %hu", data_width);</span><br><span style="color: hsl(120, 100%, 40%);">+         /*</span><br><span style="color: hsl(120, 100%, 40%);">+             * The SMBIOS spec says we should set 0xFFFF on an unknown</span><br><span style="color: hsl(120, 100%, 40%);">+             * value, but we don't have a way of passing that signal via SPD</span><br><span style="color: hsl(120, 100%, 40%);">+           * encoded values.</span><br><span style="color: hsl(120, 100%, 40%);">+             */</span><br><span style="color: hsl(120, 100%, 40%);">+           out = MEMORY_BUS_WIDTH_8;</span><br><span style="color: hsl(120, 100%, 40%);">+             break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   uint16_t extension_bits = total_width - data_width;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (extension_bits) {</span><br><span style="color: hsl(120, 100%, 40%);">+     case 8:</span><br><span style="color: hsl(120, 100%, 40%);">+               out |= SPD_ECC_8BIT;</span><br><span style="color: hsl(120, 100%, 40%);">+          break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case 0:</span><br><span style="color: hsl(120, 100%, 40%);">+               /* No extension bits */</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              printk(BIOS_NOTICE, "Unknown number of extension bits %hu",</span><br><span style="color: hsl(120, 100%, 40%);">+                extension_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return out;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+uint32_t smbios_memory_size_to_mib(uint16_t memory_size, uint32_t extended_size)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Memory size is unknown */</span><br><span style="color: hsl(120, 100%, 40%);">+  if (memory_size == 0xFFFF)</span><br><span style="color: hsl(120, 100%, 40%);">+            return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     /* (32 GiB - 1 MiB) or greater is expressed in the extended size. */</span><br><span style="color: hsl(120, 100%, 40%);">+  else if (memory_size == 0x7FFF)</span><br><span style="color: hsl(120, 100%, 40%);">+               return extended_size;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* When the MSB is flipped, the value is specified in kilobytes */</span><br><span style="color: hsl(120, 100%, 40%);">+    else if (memory_size & 0x8000)</span><br><span style="color: hsl(120, 100%, 40%);">+            return (memory_size ^ 0x8000) / KiB;</span><br><span style="color: hsl(120, 100%, 40%);">+  /* Value contains MiB */</span><br><span style="color: hsl(120, 100%, 40%);">+      else</span><br><span style="color: hsl(120, 100%, 40%);">+          return memory_size;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+uint8_t</span><br><span style="color: hsl(120, 100%, 40%);">+smbios_form_factor_to_spd_mod_type(smbios_memory_form_factor form_factor)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       /* This switch reverses the switch in smbios.c */</span><br><span style="color: hsl(120, 100%, 40%);">+     switch (form_factor) {</span><br><span style="color: hsl(120, 100%, 40%);">+        case MEMORY_FORMFACTOR_DIMM:</span><br><span style="color: hsl(120, 100%, 40%);">+          return SPD_UDIMM;</span><br><span style="color: hsl(120, 100%, 40%);">+     case MEMORY_FORMFACTOR_RIMM:</span><br><span style="color: hsl(120, 100%, 40%);">+          return SPD_RDIMM;</span><br><span style="color: hsl(120, 100%, 40%);">+     case MEMORY_FORMFACTOR_SODIMM:</span><br><span style="color: hsl(120, 100%, 40%);">+                return SPD_SODIMM;</span><br><span style="color: hsl(120, 100%, 40%);">+    default:</span><br><span style="color: hsl(120, 100%, 40%);">+              return SPD_UNDEFINED;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/25412">change 25412</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/25412"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Id9fa98e9aad83dfd0a86f45e18b3c312665dce9b </div>
<div style="display:none"> Gerrit-Change-Number: 25412 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Raul Rangel <rrangel@chromium.org> </div>