[coreboot-gerrit] Change in ...coreboot[master]: drivers: Add eMMC reset driver

Richard Spiegel (Code Review) gerrit at coreboot.org
Fri Dec 14 23:13:32 CET 2018


Richard Spiegel has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/30225


Change subject: drivers: Add eMMC reset driver
......................................................................

drivers: Add eMMC reset driver

The eMMC takes a long time to reset. To improve boot speed, create code
that starts reset as early as possible, and checks for reset completion
just before starting payload. This code should pass this information to
the payload through cbmem, so it can know reset was issued, where it's
(completed/pending) and take appropriate action (not starting reset a
second time). This might save up to 100 milliseconds (exact value TBD).

BUG=b:118680303
TEST=Added debug code to call both functions and analyze its effects.
Build and boot grunt.

Change-Id: I4bb55fde23e3b70da1cca76e5672e880317b8bd2
Signed-off-by: Richard Spiegel <richard.spiegel at silverbackltd.com>
---
M src/commonlib/include/commonlib/cbmem_id.h
A src/drivers/emmc/Kconfig
A src/drivers/emmc/Makefile.inc
A src/drivers/emmc/emmc_ram.c
A src/drivers/emmc/emmc_rom.c
A src/include/device/emmc.h
6 files changed, 154 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/25/30225/1

diff --git a/src/commonlib/include/commonlib/cbmem_id.h b/src/commonlib/include/commonlib/cbmem_id.h
index 2e0eeb6..3fbb80b 100644
--- a/src/commonlib/include/commonlib/cbmem_id.h
+++ b/src/commonlib/include/commonlib/cbmem_id.h
@@ -39,6 +39,7 @@
 #define CBMEM_ID_IMD_SMALL	0x53a11439
 #define CBMEM_ID_MEMINFO	0x494D454D
 #define CBMEM_ID_MMA_DATA	0x4D4D4144
+#define CBMEM_ID_MMC_STATUS	0x4d4d4353
 #define CBMEM_ID_MPTABLE	0x534d5054
 #define CBMEM_ID_MRCDATA	0x4d524344
 #define CBMEM_ID_VAR_MRCDATA	0x4d524345
@@ -100,6 +101,7 @@
 	{ CBMEM_ID_IMD_SMALL,		"IMD SMALL  " }, \
 	{ CBMEM_ID_MEMINFO,		"MEM INFO   " }, \
 	{ CBMEM_ID_MMA_DATA,		"MMA DATA   " }, \
+	{ CBMEM_ID_MMC_STATUS,		"MMC STATUS " }, \
 	{ CBMEM_ID_MPTABLE,		"SMP TABLE  " }, \
 	{ CBMEM_ID_MRCDATA,		"MRC DATA   " }, \
 	{ CBMEM_ID_VAR_MRCDATA,		"VARMRC DATA" }, \
diff --git a/src/drivers/emmc/Kconfig b/src/drivers/emmc/Kconfig
new file mode 100644
index 0000000..e5825ec
--- /dev/null
+++ b/src/drivers/emmc/Kconfig
@@ -0,0 +1,2 @@
+config DRIVERS_EMMC_RESET
+	bool
diff --git a/src/drivers/emmc/Makefile.inc b/src/drivers/emmc/Makefile.inc
new file mode 100644
index 0000000..123c91b
--- /dev/null
+++ b/src/drivers/emmc/Makefile.inc
@@ -0,0 +1,2 @@
+romstage-$(CONFIG_DRIVERS_EMMC_RESET) += emmc_rom.c
+ramstage-$(CONFIG_DRIVERS_EMMC_RESET) += emmc_ram.c
diff --git a/src/drivers/emmc/emmc_ram.c b/src/drivers/emmc/emmc_ram.c
new file mode 100644
index 0000000..6263198
--- /dev/null
+++ b/src/drivers/emmc/emmc_ram.c
@@ -0,0 +1,43 @@
+/*
+ * eMMC reset send and check, warning payload..
+ *
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Silverback Ltd.
+ *
+ * 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 <device/emmc.h>
+#include <cbmem.h>
+
+int emmc_check_reset(uint8_t *base_address)
+{
+	struct payload_info *pinfo;
+	uint8_t *reset, byte = 0xff;
+
+	pinfo = cbmem_find(CBMEM_ID_MMC_STATUS);
+	if (pinfo == NULL)
+		return EMMC_STATUS_CBMEM_FAILED;
+	if (base_address == NULL)
+		return EMMC_STATUS_INVALID_ADDR;
+	if (pinfo->status != EMMC_CONFIRMED_RESET_ACCEPTED)
+		return EMMC_STATUS_RESET_FAILED;
+	reset = base_address + EMMC_SOFTWARE_RESET;
+	byte = *reset;
+	if (byte == 0xff)
+		return EMMC_STATUS_INVALID_ADDR;
+
+	if (byte & EMMC_RESET_ALL)
+		pinfo->status = EMMC_RESET_STILL_ACTIVE;
+	else
+		pinfo->status = EMMC_RESET_COMPLETED;
+	return EMMC_STATUS_SUCCESS;
+}
diff --git a/src/drivers/emmc/emmc_rom.c b/src/drivers/emmc/emmc_rom.c
new file mode 100644
index 0000000..1935a2e
--- /dev/null
+++ b/src/drivers/emmc/emmc_rom.c
@@ -0,0 +1,47 @@
+/*
+ * eMMC reset send and check, warning payload..
+ *
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Silverback Ltd.
+ *
+ * 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 <device/emmc.h>
+#include <cbmem.h>
+
+int emmc_start_reset(uint8_t *base_address)
+{
+	struct payload_info *pinfo;
+	uint8_t *reset, byte = 0xff;
+
+	pinfo = cbmem_add(CBMEM_ID_MMC_STATUS, sizeof(struct payload_info));
+	if (pinfo == NULL)
+		return EMMC_STATUS_CBMEM_FAILED;
+	pinfo->identifier = EMMC_ID;
+	if (base_address == NULL)
+		return EMMC_STATUS_INVALID_ADDR;
+	reset = base_address + EMMC_SOFTWARE_RESET;
+	byte = *reset;
+	if (byte == 0xff)
+		return EMMC_STATUS_INVALID_ADDR;
+	pinfo->status = EMMC_SEND_RESET;
+
+	byte |= EMMC_RESET_ALL;
+	*reset = byte;
+	byte = 0; /* preclear */
+	byte = *reset;
+	if (byte & EMMC_RESET_ALL) {
+		pinfo->status = EMMC_CONFIRMED_RESET_ACCEPTED;
+		return EMMC_STATUS_SUCCESS;
+	}
+	return EMMC_STATUS_RESET_FAILED;
+}
diff --git a/src/include/device/emmc.h b/src/include/device/emmc.h
new file mode 100644
index 0000000..aa0d520
--- /dev/null
+++ b/src/include/device/emmc.h
@@ -0,0 +1,58 @@
+/*
+ * eMMC reset send and check, warning payload..
+ *
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Silverback Ltd.
+ *
+ * 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 <arch/io.h>
+
+#define EMMC_SEND_RESET			1
+#define EMMC_CONFIRMED_RESET_ACCEPTED	2
+#define EMMC_RESET_STILL_ACTIVE		3
+#define EMMC_RESET_COMPLETED		4
+
+/*
+ * EMMC_SEND_RESET			About to send the reset command
+ * EMMC_CONFIRMED_RESET_ACCEPTED	Reset accepted by eMMC
+ * EMMC_RESET_STILL_ACTIVE		Reset checked, but still on going
+ * EMMC_RESET_COMPLETED			Reset completed successfully
+ */
+
+#define EMMC_STATUS_SUCCESS		0
+#define EMMC_STATUS_INVALID_ADDR	-1
+#define EMMC_STATUS_CBMEM_FAILED	-2
+#define EMMC_STATUS_RESET_FAILED	-3
+
+#define EMMC_SOFTWARE_RESET	0x2F
+#define   EMMC_RESET_ALL	0x01
+#define   EMMC_RESET_CMD	0x02
+#define   EMMC_RESET_DATA	0x04
+
+#define EMMC_ID			0x65555543
+
+/*
+ * In order to permit other code also send information to payload, this
+ * structure always starts with an identifier. If the same mechanism of
+ * sending information to payload is desired, but with more that just a
+ * single byte (or maybe one byte, but different definitions), having an
+ * identifier as its header allows code to change to different pointers
+ * type depending on identifier.
+ */
+struct payload_info {
+	uint32_t identifier;
+	uint8_t status;
+};
+
+int emmc_start_reset(uint8_t *base_address);
+int emmc_check_reset(uint8_t *base_address);

-- 
To view, visit https://review.coreboot.org/c/coreboot/+/30225
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I4bb55fde23e3b70da1cca76e5672e880317b8bd2
Gerrit-Change-Number: 30225
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Spiegel <richard.spiegel at silverbackltd.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20181214/554aee97/attachment-0001.html>


More information about the coreboot-gerrit mailing list