nb/intel/sandybridge/raminit: Add XMP support

Some vendors store lower frequency profiles in the regular SPD,
if the SPD contains a XMP profile. To make use of the board's and DIMM's
maximum supported DRAM frequency, try to parse the XMP profile and
use it instead.

Validate the XMP profile to make sure that the installed DIMM count
per channel is supported and the requested voltage is supported.

To reduce complexity only XMP Profile 1 is read.

Allows my DRAM to run at 800Mhz instead of 666Mhz as encoded in the
default SPD.

Test system:
 * Gigabyte GA-B75M-D3H
 * Intel Pentium CPU G2130

Change-Id: Ib4dd68debfdcfdce138e813ad5b0e8e2ce3a40b2
Signed-off-by: Patrick Rudolph <siro@das-labor.org>
Reviewed-on: https://review.coreboot.org/13486
Reviewed-by: Martin Roth <martinroth@google.com>
Tested-by: build bot (Jenkins)
diff --git a/src/include/device/dram/ddr3.h b/src/include/device/dram/ddr3.h
index de75aee..0520ead 100644
--- a/src/include/device/dram/ddr3.h
+++ b/src/include/device/dram/ddr3.h
@@ -161,6 +161,10 @@
 	u32 tFAW;
 
 	u8 reference_card;
+	/* XMP: Module voltage in mV */
+	u16 voltage;
+	/* XMP: max DIMMs per channel supported (1-4) */
+	u8 dimms_per_channel;
 } dimm_attr;
 
 /** Result of the SPD decoding process */
@@ -171,12 +175,20 @@
 	SPD_STATUS_INVALID_FIELD,
 };
 
+enum ddr3_xmp_profile {
+	DDR3_XMP_PROFILE_1 = 0,
+	DDR3_XMP_PROFILE_2 = 1,
+};
+
 typedef u8 spd_raw_data[256];
 
 u16 spd_ddr3_calc_crc(u8 *spd, int len);
 int spd_decode_ddr3(dimm_attr * dimm, spd_raw_data spd_data);
 int dimm_is_registered(enum spd_dimm_type type);
 void dram_print_spd_ddr3(const dimm_attr * dimm);
+int spd_xmp_decode_ddr3(dimm_attr * dimm,
+		        spd_raw_data spd,
+		        enum ddr3_xmp_profile profile);
 
 /**
  * \brief Read double word from specified address