Skip to contentSkip to conversation

Add support for caching Memory Reference Code data

PATCH Superseded Simon Glass 2 participants 20 messages Jan 9, 2015 – Jan 13, 2015

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for caching Memory Reference Code data

Since the memory reference code is so slow on x86, add a feature to bypass this, storing the previous parameters in SPI flash. This saves around 500ms on each boot.

Also enable a SPI flash environment.

Changes in v2:
- Use intel,ich-spi as the compatible string
- Refactor IP checksum patches
- Refactor IP checksum patches
- Adjust the mc146818 driver instead of adding a new cmos.h header
- Make changes to chromebook_link.dts since link.dts is gone
- Use intel,ich-spi as the compatible string
- Update for the new CMOS RAM access functions in the RTC
- Add a comment about why both CMOS RAM and SPI flash are used for the cache

Simon Glass (11):
x86: dts: Add compatible string for Intel ICH9 SPI controller
x86: Move ipchecksum into common area and rename it
x86: Allow adding of IP checksums
x86: rtc: mc146818: Add helpers to read/write CMOS RAM
x86: spi: Add device tree support
Allow architecture-specific memory reservation
x86: dts: Add SPI flash MRC details for chromebook_link
x86: Implement a cache for Memory Reference Code parameters
x86: config: Enable hook for saving MRC configuration
x86: ivybridge: Drop the Kconfig MRC cache information
x86: config: chromebook_link: Enable environment

 arch/x86/cpu/Makefile                           |   1 +
 arch/x86/cpu/coreboot/Makefile                  |   1 -
 arch/x86/cpu/coreboot/ipchecksum.c              |  55 ------
 arch/x86/cpu/coreboot/tables.c                  |   8 +-
 arch/x86/cpu/ip_checksum.c                      |  55 ++++++
 arch/x86/cpu/ivybridge/Kconfig                  |  28 ---
 arch/x86/cpu/ivybridge/Makefile                 |   1 +
 arch/x86/cpu/ivybridge/mrccache.c               | 156 +++++++++++++++
 arch/x86/cpu/ivybridge/sdram.c                  | 253 ++++++++++++++++++++++++
 arch/x86/dts/chromebook_link.dts                |  15 +-
 arch/x86/dts/link.dts                           | 229 +++++++++++++++++++++
 arch/x86/include/asm/arch-coreboot/ipchecksum.h |  37 ----
 arch/x86/include/asm/arch-ivybridge/mrccache.h  |  51 +++++
 arch/x86/include/asm/global_data.h              |   3 +
 arch/x86/include/asm/ip_checksum.h              |  16 ++
 common/board_f.c                                |   7 +
 drivers/rtc/mc146818.c                          |  53 +++--
 drivers/spi/ich.c                               |   7 +
 include/configs/chromebook_link.h               |   8 +
 include/configs/x86-common.h                    |   1 +
 include/fdtdec.h                                |   1 +
 include/rtc.h                                   |  32 +++
 lib/fdtdec.c                                    |   1 +
 23 files changed, 879 insertions(+), 140 deletions(-)
 delete mode 100644 arch/x86/cpu/coreboot/ipchecksum.c
 create mode 100644 arch/x86/cpu/ip_checksum.c
 create mode 100644 arch/x86/cpu/ivybridge/mrccache.c
 create mode 100644 arch/x86/dts/link.dts
 delete mode 100644 arch/x86/include/asm/arch-coreboot/ipchecksum.h
 create mode 100644 arch/x86/include/asm/arch-ivybridge/mrccache.h
 create mode 100644 arch/x86/include/asm/ip_checksum.h
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#1 lore raw

PATCH v2 1/11 x86: dts: Add compatible string for Intel ICH9 SPI controller

Add this to the enum so that we can use the various fdtdec functions. A later commit will move this driver to driver model.

---

Changes in v2:
- Use intel,ich-spi as the compatible string

 include/fdtdec.h | 1 +
 lib/fdtdec.c     | 1 +
 2 files changed, 2 insertions(+)
include/fdtdec.h +1 -0
index 4901c0d..de46562 100644
@@ -172,6 +172,7 @@ enum fdt_compat_id {
 	COMPAT_INTEL_MODEL_206AX,	/* Intel Model 206AX CPU */
 	COMPAT_INTEL_GMA,		/* Intel Graphics Media Accelerator */
 	COMPAT_AMS_AS3722,		/* AMS AS3722 PMIC */
+	COMPAT_INTEL_ICH_SPI,		/* Intel ICH7/9 SPI controller */
 
 	COMPAT_COUNT,
 };
lib/fdtdec.c +1 -0
index 487122e..e989241 100644
@@ -83,6 +83,7 @@ static const char * const compat_names[COMPAT_COUNT] = {
 	COMPAT(INTEL_MODEL_206AX, "intel,model-206ax"),
 	COMPAT(INTEL_GMA, "intel,gma"),
 	COMPAT(AMS_AS3722, "ams,as3722"),
+	COMPAT(INTEL_ICH_SPI, "intel,ich-spi"),
 };
 
 const char *fdtdec_get_compatible(enum fdt_compat_id id)
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#2 lore raw

PATCH v2 2/11 x86: Move ipchecksum into common area and rename it

In reply to Simon Glass

The existing IP checksum function is only accessible to the 'coreboot' cpu. Move it into the common area and rename it slightly to remove the abbreviations.

---

Changes in v2:
- Refactor IP checksum patches

 arch/x86/cpu/Makefile                           |  1 +
 arch/x86/cpu/coreboot/Makefile                  |  1 -
 arch/x86/cpu/coreboot/ipchecksum.c              | 55 -------------------------
 arch/x86/cpu/coreboot/tables.c                  |  8 ++--
 arch/x86/cpu/ip_checksum.c                      | 34 +++++++++++++++
 arch/x86/include/asm/arch-coreboot/ipchecksum.h | 37 -----------------
 arch/x86/include/asm/ip_checksum.h              | 16 +++++++
 7 files changed, 55 insertions(+), 97 deletions(-)
 delete mode 100644 arch/x86/cpu/coreboot/ipchecksum.c
 create mode 100644 arch/x86/cpu/ip_checksum.c
 delete mode 100644 arch/x86/include/asm/arch-coreboot/ipchecksum.h
 create mode 100644 arch/x86/include/asm/ip_checksum.h
arch/x86/cpu/Makefile +1 -0
index 62e43c0..eee2289 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_SYS_COREBOOT) += coreboot/
 obj-$(CONFIG_NORTHBRIDGE_INTEL_SANDYBRIDGE) += ivybridge/
 obj-$(CONFIG_NORTHBRIDGE_INTEL_IVYBRIDGE) += ivybridge/
 obj-$(CONFIG_INTEL_QUEENSBAY) += queensbay/
+obj-y += ip_checksum.o
 obj-y += lapic.o
 obj-y += mtrr.o
 obj-$(CONFIG_PCI) += pci.o
arch/x86/cpu/coreboot/Makefile +0 -1
index 35e6cdd..b6e870a 100644
@@ -16,7 +16,6 @@
 obj-y += car.o
 obj-y += coreboot.o
 obj-y += tables.o
-obj-y += ipchecksum.o
 obj-y += sdram.o
 obj-y += timestamp.o
 obj-$(CONFIG_PCI) += pci.o
arch/x86/cpu/coreboot/ipchecksum.c deleted +0 -55

55 lines not on this page · raw message

arch/x86/cpu/coreboot/tables.c +4 -4
index 92b7528..662af95 100644
@@ -8,7 +8,7 @@
  */
 
 #include <common.h>
-#include <asm/arch/ipchecksum.h>
+#include <asm/ip_checksum.h>
 #include <asm/arch/sysinfo.h>
 #include <asm/arch/tables.h>
 
@@ -131,11 +131,11 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
 		return 0;
 
 	/* Make sure the checksums match. */
-	if (ipchksum((u16 *) header, sizeof(*header)) != 0)
+	if (compute_ip_checksum((u16 *)header, sizeof(*header)) != 0)
 		return -1;
 
-	if (ipchksum((u16 *) (ptr + sizeof(*header)),
-		     header->table_bytes) != header->table_checksum)
+	if (compute_ip_checksum((u16 *)(ptr + sizeof(*header)),
+				header->table_bytes) != header->table_checksum)
 		return -1;
 
 	/* Now, walk the tables. */
arch/x86/cpu/ip_checksum.c new file +34 -0
new file mode 100644
index 0000000..1b529da
@@ -0,0 +1,34 @@
+/*
+ * This file was originally taken from the FreeBSD project.
+ *
+ * Copyright (c) 2001 Charles Mott <[email protected]>
+ * Copyright (c) 2008 coresystems GmbH
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:	BSD-2-Clause
+ */
+
+#include <linux/types.h>
+#include <linux/compiler.h>
+#include <asm/ip_checksum.h>
+
+unsigned short compute_ip_checksum(const void *vptr, unsigned long nbytes)
+{
+	int sum, oddbyte;
+	const unsigned short *ptr = vptr;
+
+	sum = 0;
+	while (nbytes > 1) {
+		sum += *ptr++;
+		nbytes -= 2;
+	}
+	if (nbytes == 1) {
+		oddbyte = 0;
+		((u8 *)&oddbyte)[0] = *(u8 *)ptr;
+		((u8 *)&oddbyte)[1] = 0;
+		sum += oddbyte;
+	}
+	sum = (sum >> 16) + (sum & 0xffff);
+	sum += (sum >> 16);
+	return ~sum;
+}
arch/x86/include/asm/arch-coreboot/ipchecksum.h deleted +0 -37
deleted file mode 100644
index 1d73b4d..0000000
@@ -1,37 +0,0 @@
-/*
- * This file is part of the libpayload project.
- *
- * It has originally been taken from the FreeBSD project.
- *
- * Copyright (c) 2001 Charles Mott <[email protected]>
- * Copyright (c) 2008 coresystems GmbH
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _COREBOOT_IPCHECKSUM_H
-#define _COREBOOT_IPCHECKSUM_H
-
-unsigned short ipchksum(const void *vptr, unsigned long nbytes);
-
-#endif
arch/x86/include/asm/ip_checksum.h new file +16 -0
new file mode 100644
index 0000000..8d9626d
@@ -0,0 +1,16 @@
+/*
+ * From Coreboot ip_checksum.h
+ *
+ * Copyright (c) 2014 Google, Inc
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ */
+
+#ifndef _IP_CHECKSUM_H
+#define _IP_CHECKSUM_H
+
+unsigned short compute_ip_checksum(const void *addr, unsigned long length);
+unsigned long add_ip_checksums(unsigned long offset, unsigned long sum,
+			       unsigned long new);
+
+#endif /* IP_CHECKSUM_H */
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#3 lore raw

PATCH v2 2/11 x86: Move ipchecksum into common area and rename it

Hi Simon,

Quoted 7 lines · Simon Glass

The existing IP checksum function is only accessible to the 'coreboot' cpu. Move it into the common area and rename it slightly to remove the abbreviations.

---

Quoted 8 lines

Changes in v2:
- Refactor IP checksum patches

 arch/x86/cpu/Makefile                           |  1 +
 arch/x86/cpu/coreboot/Makefile                  |  1 -
 arch/x86/cpu/coreboot/ipchecksum.c              | 55 -------------------------
 arch/x86/cpu/coreboot/tables.c                  |  8 ++--
 arch/x86/cpu/ip_checksum.c                      | 34 +++++++++++++++

What about the namings we discussed in the v1 patch thread? ip_xxx indicates ip protocol, but acutally they are not.

[snip]

Regards,
Bin

#4 lore raw

PATCH v2 2/11 x86: Move ipchecksum into common area and rename it

Hi Bin,

Quoted 13 lines · Bin Meng

Hi Simon,

Quoted 10 lines · Simon Glass

The existing IP checksum function is only accessible to the 'coreboot' cpu. Move it into the common area and rename it slightly to remove the abbreviations.

---

Changes in v2:
- Refactor IP checksum patches

Quoted 8 lines
Quoted 5 lines
 arch/x86/cpu/Makefile                           |  1 +
 arch/x86/cpu/coreboot/Makefile                  |  1 -
 arch/x86/cpu/coreboot/ipchecksum.c              | 55 -------------------------
 arch/x86/cpu/coreboot/tables.c                  |  8 ++--
 arch/x86/cpu/ip_checksum.c                      | 34 +++++++++++++++

What about the namings we discussed in the v1 patch thread? ip_xxx indicates ip protocol, but acutally they are not.

Is it not? This is not actually CMOS-specific - e.g. it is used by Coreboot to send data through to U-Boot in the tables it provides.

I thought it was an IP checksum...

Regards,
Simon

#5 lore raw

PATCH v2 2/11 x86: Move ipchecksum into common area and rename it

Hi Simon,

Quoted 22 lines · Simon Glass

Hi Bin,

Quoted 19 lines · Bin Meng

Hi Simon,

Quoted 15 lines · Simon Glass

The existing IP checksum function is only accessible to the 'coreboot' cpu. Move it into the common area and rename it slightly to remove the abbreviations.

---

Changes in v2:
- Refactor IP checksum patches

 arch/x86/cpu/Makefile                           |  1 +
 arch/x86/cpu/coreboot/Makefile                  |  1 -
 arch/x86/cpu/coreboot/ipchecksum.c              | 55 -------------------------
 arch/x86/cpu/coreboot/tables.c                  |  8 ++--
 arch/x86/cpu/ip_checksum.c                      | 34 +++++++++++++++
Quoted 8 lines
Quoted 2 lines

What about the namings we discussed in the v1 patch thread? ip_xxx indicates ip protocol, but acutally they are not.

Is it not? This is not actually CMOS-specific - e.g. it is used by Coreboot to send data through to U-Boot in the tables it provides.

I thought it was an IP checksum...

OK, so you mean coreboot is using the same IP checksum algorithm to generate checksums for coreboot tables to be passed to U-Boot. If that is the case, I think we should put the these files to u-boot/net or u-boot/lib. Are there existing codes that we can reuse?

Regards,
Bin

#6 lore raw

PATCH v2 2/11 x86: Move ipchecksum into common area and rename it

Hi Bin,

Quoted 32 lines · Bin Meng

Hi Simon,

Quoted 28 lines · Simon Glass

Hi Bin,

Quoted 13 lines · Bin Meng

Hi Simon,

Quoted 10 lines · Simon Glass

The existing IP checksum function is only accessible to the 'coreboot' cpu. Move it into the common area and rename it slightly to remove the abbreviations.

---

Changes in v2:
- Refactor IP checksum patches

Quoted 8 lines
Quoted 5 lines
 arch/x86/cpu/Makefile                           |  1 +
 arch/x86/cpu/coreboot/Makefile                  |  1 -
 arch/x86/cpu/coreboot/ipchecksum.c              | 55 -------------------------
 arch/x86/cpu/coreboot/tables.c                  |  8 ++--
 arch/x86/cpu/ip_checksum.c                      | 34 +++++++++++++++

What about the namings we discussed in the v1 patch thread? ip_xxx indicates ip protocol, but acutally they are not.

Is it not? This is not actually CMOS-specific - e.g. it is used by Coreboot to send data through to U-Boot in the tables it provides.

Quoted 7 lines
Quoted 2 lines

I thought it was an IP checksum...

OK, so you mean coreboot is using the same IP checksum algorithm to generate checksums for coreboot tables to be passed to U-Boot. If that is the case, I think we should put the these files to u-boot/net or u-boot/lib. Are there existing codes that we can reuse?

NetCkSum() is similar but does not need to worry about an odd length. So I doubt I can use that.

Regards,
Simon

#7 lore raw

PATCH v2 2/11 x86: Move ipchecksum into common area and rename it

Hi Simon,

Quoted 38 lines · Simon Glass

Hi Bin,

Quoted 35 lines · Bin Meng

Hi Simon,

Quoted 30 lines · Simon Glass

Hi Bin,

Quoted 13 lines · Bin Meng

Hi Simon,

Quoted 10 lines · Simon Glass

The existing IP checksum function is only accessible to the 'coreboot' cpu. Move it into the common area and rename it slightly to remove the abbreviations.

---

Changes in v2:
- Refactor IP checksum patches

Quoted 8 lines
Quoted 5 lines
 arch/x86/cpu/Makefile                           |  1 +
 arch/x86/cpu/coreboot/Makefile                  |  1 -
 arch/x86/cpu/coreboot/ipchecksum.c              | 55 -------------------------
 arch/x86/cpu/coreboot/tables.c                  |  8 ++--
 arch/x86/cpu/ip_checksum.c                      | 34 +++++++++++++++

What about the namings we discussed in the v1 patch thread? ip_xxx indicates ip protocol, but acutally they are not.

Is it not? This is not actually CMOS-specific - e.g. it is used by Coreboot to send data through to U-Boot in the tables it provides.

I thought it was an IP checksum...

Quoted 8 lines
Quoted 4 lines

OK, so you mean coreboot is using the same IP checksum algorithm to generate checksums for coreboot tables to be passed to U-Boot. If that is the case, I think we should put the these files to u-boot/net or u-boot/lib. Are there existing codes that we can reuse?

NetCkSum() is similar but does not need to worry about an odd length. So I doubt I can use that.

But would you consider moving it to some another place more suitable than arch/x86/cpu/? I feel that it is IP related stuff and it may make people confused when seeing it in arch/x86 directory. If we move it to u-boot/net, maybe you can replace NetCkSum() with the one we have here since it can deal with odd length.

Regards,
Bin

#8 lore raw

PATCH v2 2/11 x86: Move ipchecksum into common area and rename it

Hi Bin,

Quoted 50 lines · Bin Meng

Hi Simon,

Quoted 38 lines · Simon Glass

Hi Bin,

Quoted 35 lines · Bin Meng

Hi Simon,

Quoted 30 lines · Simon Glass

Hi Bin,

Quoted 13 lines · Bin Meng

Hi Simon,

Quoted 10 lines · Simon Glass

The existing IP checksum function is only accessible to the 'coreboot' cpu. Move it into the common area and rename it slightly to remove the abbreviations.

---

Changes in v2:
- Refactor IP checksum patches

Quoted 8 lines
Quoted 5 lines
 arch/x86/cpu/Makefile                           |  1 +
 arch/x86/cpu/coreboot/Makefile                  |  1 -
 arch/x86/cpu/coreboot/ipchecksum.c              | 55 -------------------------
 arch/x86/cpu/coreboot/tables.c                  |  8 ++--
 arch/x86/cpu/ip_checksum.c                      | 34 +++++++++++++++

What about the namings we discussed in the v1 patch thread? ip_xxx indicates ip protocol, but acutally they are not.

Is it not? This is not actually CMOS-specific - e.g. it is used by Coreboot to send data through to U-Boot in the tables it provides.

I thought it was an IP checksum...

Quoted 8 lines
Quoted 4 lines

OK, so you mean coreboot is using the same IP checksum algorithm to generate checksums for coreboot tables to be passed to U-Boot. If that is the case, I think we should put the these files to u-boot/net or u-boot/lib. Are there existing codes that we can reuse?

NetCkSum() is similar but does not need to worry about an odd length. So I doubt I can use that.

Quoted 5 lines

But would you consider moving it to some another place more suitable than arch/x86/cpu/? I feel that it is IP related stuff and it may make people confused when seeing it in arch/x86 directory. If we move it to u-boot/net, maybe you can replace NetCkSum() with the one we have here since it can deal with odd length.

I suspect it might be confusing in any case. But I think we can move this file to net/ - at least I don't see any big problems. I wonder whether people might complain about changing the existing NetChkSum() function, but we will see.

Regards,
Simon

#9 lore raw

PATCH v2 3/11 x86: Allow adding of IP checksums

In reply to Simon Glass

Add a function to add IP checksums.

---

Changes in v2:
- Refactor IP checksum patches

 arch/x86/cpu/ip_checksum.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/x86/cpu/ip_checksum.c +21 -0
index 1b529da..ddfc0d7 100644
@@ -32,3 +32,24 @@ unsigned short compute_ip_checksum(const void *vptr, unsigned long nbytes)
 	sum += (sum >> 16);
 	return ~sum;
 }
+
+unsigned long add_ip_checksums(unsigned long offset, unsigned long sum,
+			       unsigned long new)
+{
+	unsigned long checksum;
+
+	sum = ~sum & 0xffff;
+	new = ~new & 0xffff;
+	if (offset & 1) {
+		/*
+		 * byte-swap the sum if it came from an odd offset; since the
+		 * computation is endian independant this works.
+		 */
+		new = ((new >> 8) & 0xff) | ((new << 8) & 0xff00);
+	}
+	checksum = sum + new;
+	if (checksum > 0xffff)
+		checksum -= 0xffff;
+
+	return (~checksum) & 0xffff;
+}
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#10 lore raw

PATCH v2 4/11 x86: rtc: mc146818: Add helpers to read/write CMOS RAM

In reply to Simon Glass

On x86 we use CMOS RAM to read and write some settings. Add basic support for this, including access to registers 128-255.

---

Changes in v2:
- Adjust the mc146818 driver instead of adding a new cmos.h header

 drivers/rtc/mc146818.c | 53 +++++++++++++++++++++++++++++++++++++-------------
 include/rtc.h          | 32 ++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 14 deletions(-)
drivers/rtc/mc146818.c +39 -14
index 39e6041..b506b16 100644
@@ -27,9 +27,6 @@
 /* Set this to 1 to clear the CMOS RAM */
 #define CLEAR_CMOS 0
 
-static uchar rtc_read  (uchar reg);
-static void  rtc_write (uchar reg, uchar val);
-
 #define RTC_PORT_MC146818	CONFIG_SYS_ISA_IO_BASE_ADDRESS +  0x70
 #define RTC_SECONDS		0x00
 #define RTC_SECONDS_ALARM	0x01
@@ -133,32 +130,60 @@ void rtc_reset (void)
 
 /* ------------------------------------------------------------------------- */
 
-#ifdef CONFIG_SYS_RTC_REG_BASE_ADDR
 /*
  * use direct memory access
  */
-static uchar rtc_read (uchar reg)
+int rtc_read(int reg)
 {
+#ifdef CONFIG_SYS_RTC_REG_BASE_ADDR
 	return in8(CONFIG_SYS_RTC_REG_BASE_ADDR + reg);
+#else
+	int ofs = 0;
+
+	if (reg >= 128) {
+		ofs = 2;
+		reg -= 128;
+	}
+	out8(RTC_PORT_MC146818 + ofs, reg);
+
+	return in8(RTC_PORT_MC146818 + ofs + 1);
+#endif
 }
 
-static void rtc_write (uchar reg, uchar val)
+void rtc_write(int reg, uchar val)
 {
+#ifdef CONFIG_SYS_RTC_REG_BASE_ADDR
 	out8(CONFIG_SYS_RTC_REG_BASE_ADDR + reg, val);
-}
 #else
-static uchar rtc_read (uchar reg)
+	int ofs = 0;
+
+	if (reg >= 128) {
+		ofs = 2;
+		reg -= 128;
+	}
+	out8(RTC_PORT_MC146818 + ofs, reg);
+	out8(RTC_PORT_MC146818 + ofs + 1, val);
+#endif
+}
+
+u32 rtc_read32(int reg)
 {
-	out8(RTC_PORT_MC146818,reg);
-	return in8(RTC_PORT_MC146818 + 1);
+	u32 value = 0;
+	int i;
+
+	for (i = 0; i < sizeof(value); i++)
+		value |= rtc_read(reg + i) << (i << 3);
+
+	return value;
 }
 
-static void rtc_write (uchar reg, uchar val)
+void rtc_write32(int reg, u32 value)
 {
-	out8(RTC_PORT_MC146818,reg);
-	out8(RTC_PORT_MC146818+1, val);
+	int i;
+
+	for (i = 0; i < sizeof(value); i++)
+		rtc_write(reg + i, (value >> (i << 3)) & 0xff);
 }
-#endif
 
 void rtc_init(void)
 {
include/rtc.h +32 -0
index d11aa8b..b6df1f4 100644
@@ -51,6 +51,38 @@ unsigned long mktime (unsigned int, unsigned int, unsigned int,
 		      unsigned int, unsigned int, unsigned int);
 
 /**
+ * rtc_read() - Read an 8-bit register
+ *
+ * @reg:	Register to read
+ * @return value read
+ */
+int rtc_read(int reg);
+
+/**
+ * rtc_write() - Write an 8-bit register
+ *
+ * @reg:	Register to write
+ * @value:	Value to write
+ */
+void rtc_write(int reg, uchar val);
+
+/**
+ * rtc_read32() - Read a 32-bit value from the RTC
+ *
+ * @reg:	Offset to start reading from
+ * @return value read
+ */
+u32 rtc_read32(int reg);
+
+/**
+ * rtc_write32() - Write a 32-bit value to the RTC
+ *
+ * @reg:	Register to start writing to
+ * @value:	Value to write
+ */
+void rtc_write32(int reg, u32 value);
+
+/**
  * rtc_init() - Set up the real time clock ready for use
  */
 void rtc_init(void);
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#11 lore raw

PATCH v2 5/11 x86: spi: Add device tree support

In reply to Simon Glass

As a temporary measure before the ICH driver moves over to driver model, add device tree support to the driver.

---

Changes in v2: None

 drivers/spi/ich.c            | 7 +++++++
 include/configs/x86-common.h | 1 +
 2 files changed, 8 insertions(+)
drivers/spi/ich.c +7 -0
index 0379444..fdff158 100644
@@ -153,6 +153,13 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	return &ich->slave;
 }
 
+struct spi_slave *spi_setup_slave_fdt(const void *blob, int slave_node,
+				      int spi_node)
+{
+	/* We only support a single SPI at present */
+	return spi_setup_slave(0, 0, 20000000, 0);
+}
+
 void spi_free_slave(struct spi_slave *slave)
 {
 	struct ich_spi_slave *ich = to_ich_spi(slave);
include/configs/x86-common.h +1 -0
index 4f0a3c5..ecedfc3 100644
@@ -211,6 +211,7 @@
 #define CONFIG_CMD_SF_TEST
 #define CONFIG_CMD_SPI
 #define CONFIG_SPI
+#define CONFIG_OF_SPI_FLASH
 
 /*-----------------------------------------------------------------------
  * Environment configuration
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#12 lore raw

PATCH v2 6/11 Allow architecture-specific memory reservation

In reply to Simon Glass

All memory to be reserved for use after relocation by adding a new call to perform this reservation.

---

Changes in v2: None

 common/board_f.c | 7 +++++++
 1 file changed, 7 insertions(+)
common/board_f.c +7 -0
index 3a4b32c..215108b 100644
@@ -807,6 +807,12 @@ static int initf_dm(void)
 	return 0;
 }
 
+/* Architecture-specific memory reservation */
+__weak int reserve_arch(void)
+{
+	return 0;
+}
+
 static init_fnc_t init_sequence_f[] = {
 #ifdef CONFIG_SANDBOX
 	setup_ram_buf,
@@ -970,6 +976,7 @@ static init_fnc_t init_sequence_f[] = {
 	setup_machine,
 	reserve_global_data,
 	reserve_fdt,
+	reserve_arch,
 	reserve_stacks,
 	setup_dram_config,
 	show_dram_config,
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#13 lore raw

PATCH v2 7/11 x86: dts: Add SPI flash MRC details for chromebook_link

In reply to Simon Glass

Correct the SPI flash compatible string, add an alias and specify the position of the MRC cache, used to store SDRAM training settings for the Memory Reference Code.

---

Changes in v2:
- Make changes to chromebook_link.dts since link.dts is gone
- Use intel,ich-spi as the compatible string

 arch/x86/dts/chromebook_link.dts |  15 ++-
 arch/x86/dts/link.dts            | 229 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 243 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/dts/link.dts
arch/x86/dts/chromebook_link.dts +14 -1
index 9490b16..45ada61 100644
@@ -7,6 +7,10 @@
 	model = "Google Link";
 	compatible = "google,link", "intel,celeron-ivybridge";
 
+	aliases {
+		spi0 = "/spi";
+	};
+
 	config {
 	       silent_console = <0>;
 	};
@@ -150,11 +154,20 @@
 	spi {
 		#address-cells = <1>;
 		#size-cells = <0>;
-		compatible = "intel,ich9";
+		compatible = "intel,ich-spi";
 		spi-flash at 0 {
+			#size-cells = <1>;
+			#address-cells = <1>;
 			reg = <0>;
 			compatible = "winbond,w25q64", "spi-flash";
 			memory-map = <0xff800000 0x00800000>;
+			rw-mrc-cache {
+				label = "rw-mrc-cache";
+				/* Alignment: 4k (for updating) */
+				reg = <0x003e0000 0x00010000>;
+				type = "wiped";
+				wipe-value = [ff];
+			};
 		};
 	};
 
arch/x86/dts/link.dts new file +229 -0

229 lines not on this page · raw message

Signature · 1 line
2.2.0.rc0.207.ga3a616c
#14 lore raw

PATCH v2 7/11 x86: dts: Add SPI flash MRC details for chromebook_link

Hi Simon,

arch/x86/dts/link.dts

Quoted 55 lines · Simon Glass

Correct the SPI flash compatible string, add an alias and specify the position of the MRC cache, used to store SDRAM training settings for the Memory Reference Code.

---

Changes in v2:
- Make changes to chromebook_link.dts since link.dts is gone
- Use intel,ich-spi as the compatible string

 arch/x86/dts/chromebook_link.dts |  15 ++-
 arch/x86/dts/link.dts            | 229 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 243 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/dts/link.dts
arch/x86/dts/chromebook_link.dts +14 -1
index 9490b16..45ada61 100644
@@ -7,6 +7,10 @@
        model = "Google Link";
        compatible = "google,link", "intel,celeron-ivybridge";
 
+       aliases {
+               spi0 = "/spi";
+       };
+
        config {
               silent_console = <0>;
        };
@@ -150,11 +154,20 @@
        spi {
                #address-cells = <1>;
                #size-cells = <0>;
-               compatible = "intel,ich9";
+               compatible = "intel,ich-spi";
                spi-flash at 0 {
+                       #size-cells = <1>;
+                       #address-cells = <1>;
                        reg = <0>;
                        compatible = "winbond,w25q64", "spi-flash";
                        memory-map = <0xff800000 0x00800000>;
+                       rw-mrc-cache {
+                               label = "rw-mrc-cache";
+                               /* Alignment: 4k (for updating) */
+                               reg = <0x003e0000 0x00010000>;
+                               type = "wiped";
+                               wipe-value = [ff];
+                       };
                };
        };
 
arch/x86/dts/link.dts new file +0 -0
new file mode 100644

Looks that you created link.dts again? Guess you may not rebase to u-boot-x86/next branch correctly?

[snip]

Regards,
Bin

#15 lore raw

PATCH v2 8/11 x86: Implement a cache for Memory Reference Code parameters

In reply to Simon Glass

The memory reference code takes a very long time to 'train' its SDRAM interface, around half a second. To avoid this delay on every boot we can store the parameters from the last training sessions to speed up the next.

Add an implementation of this, storing the training data in CMOS RAM and SPI flash.

---

Changes in v2:
- Update for the new CMOS RAM access functions in the RTC
- Add a comment about why both CMOS RAM and SPI flash are used for the cache

 arch/x86/cpu/ivybridge/Makefile                |   1 +
 arch/x86/cpu/ivybridge/mrccache.c              | 156 +++++++++++++++
 arch/x86/cpu/ivybridge/sdram.c                 | 253 +++++++++++++++++++++++++
 arch/x86/include/asm/arch-ivybridge/mrccache.h |  51 +++++
 arch/x86/include/asm/global_data.h             |   3 +
 5 files changed, 464 insertions(+)
 create mode 100644 arch/x86/cpu/ivybridge/mrccache.c
 create mode 100644 arch/x86/include/asm/arch-ivybridge/mrccache.h
arch/x86/cpu/ivybridge/Makefile +1 -0
index 0c7efae..3576b83 100644
@@ -14,6 +14,7 @@ obj-y += lpc.o
 obj-y += me_status.o
 obj-y += model_206ax.o
 obj-y += microcode_intel.o
+obj-y += mrccache.o
 obj-y += northbridge.o
 obj-y += pch.o
 obj-y += pci.o
arch/x86/cpu/ivybridge/mrccache.c new file +156 -0

156 lines not on this page · raw message

arch/x86/cpu/ivybridge/sdram.c +253 -0

301 lines not on this page · raw message

arch/x86/include/asm/arch-ivybridge/mrccache.h new file +51 -0

51 lines not on this page · raw message

arch/x86/include/asm/global_data.h +3 -0
index 24e3052..7d76f4a 100644
@@ -64,6 +64,9 @@ struct arch_global_data {
 #endif
 	struct mtrr_request mtrr_req[MAX_MTRR_REQUESTS];
 	int mtrr_req_count;
+	/* MRC training data to save for the next boot */
+	char *mrc_output;
+	unsigned int mrc_output_len;
 };
 
 #endif
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#16 lore raw

PATCH v2 9/11 x86: config: Enable hook for saving MRC configuration

In reply to Simon Glass

Add a hook to ensure that this information is saved.

---

Changes in v2: None

 include/configs/chromebook_link.h | 1 +
 1 file changed, 1 insertion(+)
include/configs/chromebook_link.h +1 -0
index 7e6d239..6e8b9ef 100644
@@ -20,6 +20,7 @@
 
 #define CONFIG_DCACHE_RAM_MRC_VAR_SIZE		0x4000
 #define CONFIG_BOARD_EARLY_INIT_F
+#define CONFIG_MISC_INIT_R
 
 #define CONFIG_NR_DRAM_BANKS			8
 #define CONFIG_X86_MRC_ADDR			0xfffa0000
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#17 lore raw

PATCH v2 10/11 x86: ivybridge: Drop the Kconfig MRC cache information

In reply to Simon Glass

This is now stored in the device tree.

---

Changes in v2: None

 arch/x86/cpu/ivybridge/Kconfig | 28 ----------------------------
 1 file changed, 28 deletions(-)
arch/x86/cpu/ivybridge/Kconfig +0 -28
index afca957..e4595be 100644
@@ -26,20 +26,6 @@ config CACHE_MRC_SIZE_KB
 	int
 	default 256
 
-config MRC_CACHE_BASE
-	hex
-	default 0xff800000
-
-config MRC_CACHE_LOCATION
-	hex
-	depends on !CHROMEOS
-	default 0x1ec000
-
-config MRC_CACHE_SIZE
-	hex
-	depends on !CHROMEOS
-	default 0x10000
-
 config DCACHE_RAM_BASE
 	hex
 	default 0xff7f0000
@@ -64,20 +50,6 @@ config CACHE_MRC_SIZE_KB
 	int
 	default 512
 
-config MRC_CACHE_BASE
-	hex
-	default 0xff800000
-
-config MRC_CACHE_LOCATION
-	hex
-	depends on !CHROMEOS
-	default 0x370000
-
-config MRC_CACHE_SIZE
-	hex
-	depends on !CHROMEOS
-	default 0x10000
-
 config DCACHE_RAM_BASE
 	hex
 	default 0xff7e0000
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#18 lore raw

PATCH v2 11/11 x86: config: chromebook_link: Enable environment

In reply to Simon Glass

Enable an environment area.

---

Changes in v2: None

 include/configs/chromebook_link.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/configs/chromebook_link.h +7 -0
index 6e8b9ef..7b460e8 100644
@@ -64,6 +64,13 @@
 #define CONFIG_CMD_CROS_EC
 #define CONFIG_ARCH_EARLY_INIT_R
 
+#undef CONFIG_ENV_IS_NOWHERE
+#undef CONFIG_ENV_SIZE
+#define CONFIG_ENV_SIZE			0x1000
+#define CONFIG_ENV_SECT_SIZE		0x1000
+#define CONFIG_ENV_IS_IN_SPI_FLASH
+#define CONFIG_ENV_OFFSET		0x003f8000
+
 #define CONFIG_STD_DEVICES_SETTINGS     "stdin=usbkbd,vga,serial\0" \
 					"stdout=vga,serial\0" \
 					"stderr=vga,serial\0"
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#19 lore raw

PATCH v2 11/11 x86: config: chromebook_link: Enable environment

Quoted 19 lines · Simon Glass

Enable an environment area.

---

Changes in v2: None

 include/configs/chromebook_link.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/configs/chromebook_link.h +1 -0
index 6e8b9ef..7b460e8 100644
@@ -64,6 +64,13 @@
 #define CONFIG_CMD_CROS_EC
 #define CONFIG_ARCH_EARLY_INIT_R
 
+#undef CONFIG_ENV_IS_NOWHERE

include/configs/chromebook_link.h

Quoted 10 lines
include/configs/chromebook_link.h +6 -1
+#undef CONFIG_ENV_SIZE
+#define CONFIG_ENV_SIZE                        0x1000
+#define CONFIG_ENV_SECT_SIZE           0x1000
+#define CONFIG_ENV_IS_IN_SPI_FLASH
+#define CONFIG_ENV_OFFSET              0x003f8000
+
 #define CONFIG_STD_DEVICES_SETTINGS     "stdin=usbkbd,vga,serial\0" \
                                        "stdout=vga,serial\0" \
                                        "stderr=vga,serial\0"
--