<p>Richard Spiegel has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/c/coreboot/+/30225">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">drivers: Add eMMC reset driver<br><br>The eMMC takes a long time to reset. To improve boot speed, create code<br>that starts reset as early as possible, and checks for reset completion<br>just before starting payload. This code should pass this information to<br>the payload through cbmem, so it can know reset was issued, where it's<br>(completed/pending) and take appropriate action (not starting reset a<br>second time). This might save up to 100 milliseconds (exact value TBD).<br><br>BUG=b:118680303<br>TEST=Added debug code to call both functions and analyze its effects.<br>Build and boot grunt.<br><br>Change-Id: I4bb55fde23e3b70da1cca76e5672e880317b8bd2<br>Signed-off-by: Richard Spiegel <richard.spiegel@silverbackltd.com><br>---<br>M src/commonlib/include/commonlib/cbmem_id.h<br>A src/drivers/emmc/Kconfig<br>A src/drivers/emmc/Makefile.inc<br>A src/drivers/emmc/emmc_ram.c<br>A src/drivers/emmc/emmc_rom.c<br>A src/include/device/emmc.h<br>6 files changed, 154 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/25/30225/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/commonlib/include/commonlib/cbmem_id.h b/src/commonlib/include/commonlib/cbmem_id.h</span><br><span>index 2e0eeb6..3fbb80b 100644</span><br><span>--- a/src/commonlib/include/commonlib/cbmem_id.h</span><br><span>+++ b/src/commonlib/include/commonlib/cbmem_id.h</span><br><span>@@ -39,6 +39,7 @@</span><br><span> #define CBMEM_ID_IMD_SMALL   0x53a11439</span><br><span> #define CBMEM_ID_MEMINFO  0x494D454D</span><br><span> #define CBMEM_ID_MMA_DATA 0x4D4D4144</span><br><span style="color: hsl(120, 100%, 40%);">+#define CBMEM_ID_MMC_STATUS 0x4d4d4353</span><br><span> #define CBMEM_ID_MPTABLE  0x534d5054</span><br><span> #define CBMEM_ID_MRCDATA  0x4d524344</span><br><span> #define CBMEM_ID_VAR_MRCDATA      0x4d524345</span><br><span>@@ -100,6 +101,7 @@</span><br><span>     { CBMEM_ID_IMD_SMALL,           "IMD SMALL  " }, \</span><br><span>         { CBMEM_ID_MEMINFO,             "MEM INFO   " }, \</span><br><span>         { CBMEM_ID_MMA_DATA,            "MMA DATA   " }, \</span><br><span style="color: hsl(120, 100%, 40%);">+  { CBMEM_ID_MMC_STATUS,          "MMC STATUS " }, \</span><br><span>         { CBMEM_ID_MPTABLE,             "SMP TABLE  " }, \</span><br><span>         { CBMEM_ID_MRCDATA,             "MRC DATA   " }, \</span><br><span>         { CBMEM_ID_VAR_MRCDATA,         "VARMRC DATA" }, \</span><br><span>diff --git a/src/drivers/emmc/Kconfig b/src/drivers/emmc/Kconfig</span><br><span>new file mode 100644</span><br><span>index 0000000..e5825ec</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/emmc/Kconfig</span><br><span>@@ -0,0 +1,2 @@</span><br><span style="color: hsl(120, 100%, 40%);">+config DRIVERS_EMMC_RESET</span><br><span style="color: hsl(120, 100%, 40%);">+ bool</span><br><span>diff --git a/src/drivers/emmc/Makefile.inc b/src/drivers/emmc/Makefile.inc</span><br><span>new file mode 100644</span><br><span>index 0000000..123c91b</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/emmc/Makefile.inc</span><br><span>@@ -0,0 +1,2 @@</span><br><span style="color: hsl(120, 100%, 40%);">+romstage-$(CONFIG_DRIVERS_EMMC_RESET) += emmc_rom.c</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-$(CONFIG_DRIVERS_EMMC_RESET) += emmc_ram.c</span><br><span>diff --git a/src/drivers/emmc/emmc_ram.c b/src/drivers/emmc/emmc_ram.c</span><br><span>new file mode 100644</span><br><span>index 0000000..6263198</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/emmc/emmc_ram.c</span><br><span>@@ -0,0 +1,43 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * eMMC reset send and check, warning payload..</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 Silverback Ltd.</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 <device/emmc.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <cbmem.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int emmc_check_reset(uint8_t *base_address)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct payload_info *pinfo;</span><br><span style="color: hsl(120, 100%, 40%);">+   uint8_t *reset, byte = 0xff;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        pinfo = cbmem_find(CBMEM_ID_MMC_STATUS);</span><br><span style="color: hsl(120, 100%, 40%);">+      if (pinfo == NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+            return EMMC_STATUS_CBMEM_FAILED;</span><br><span style="color: hsl(120, 100%, 40%);">+      if (base_address == NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+             return EMMC_STATUS_INVALID_ADDR;</span><br><span style="color: hsl(120, 100%, 40%);">+      if (pinfo->status != EMMC_CONFIRMED_RESET_ACCEPTED)</span><br><span style="color: hsl(120, 100%, 40%);">+                return EMMC_STATUS_RESET_FAILED;</span><br><span style="color: hsl(120, 100%, 40%);">+      reset = base_address + EMMC_SOFTWARE_RESET;</span><br><span style="color: hsl(120, 100%, 40%);">+   byte = *reset;</span><br><span style="color: hsl(120, 100%, 40%);">+        if (byte == 0xff)</span><br><span style="color: hsl(120, 100%, 40%);">+             return EMMC_STATUS_INVALID_ADDR;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if (byte & EMMC_RESET_ALL)</span><br><span style="color: hsl(120, 100%, 40%);">+                pinfo->status = EMMC_RESET_STILL_ACTIVE;</span><br><span style="color: hsl(120, 100%, 40%);">+   else</span><br><span style="color: hsl(120, 100%, 40%);">+          pinfo->status = EMMC_RESET_COMPLETED;</span><br><span style="color: hsl(120, 100%, 40%);">+      return EMMC_STATUS_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/drivers/emmc/emmc_rom.c b/src/drivers/emmc/emmc_rom.c</span><br><span>new file mode 100644</span><br><span>index 0000000..1935a2e</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/emmc/emmc_rom.c</span><br><span>@@ -0,0 +1,47 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * eMMC reset send and check, warning payload..</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 Silverback Ltd.</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 <device/emmc.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <cbmem.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int emmc_start_reset(uint8_t *base_address)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      struct payload_info *pinfo;</span><br><span style="color: hsl(120, 100%, 40%);">+   uint8_t *reset, byte = 0xff;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        pinfo = cbmem_add(CBMEM_ID_MMC_STATUS, sizeof(struct payload_info));</span><br><span style="color: hsl(120, 100%, 40%);">+  if (pinfo == NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+            return EMMC_STATUS_CBMEM_FAILED;</span><br><span style="color: hsl(120, 100%, 40%);">+      pinfo->identifier = EMMC_ID;</span><br><span style="color: hsl(120, 100%, 40%);">+       if (base_address == NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+             return EMMC_STATUS_INVALID_ADDR;</span><br><span style="color: hsl(120, 100%, 40%);">+      reset = base_address + EMMC_SOFTWARE_RESET;</span><br><span style="color: hsl(120, 100%, 40%);">+   byte = *reset;</span><br><span style="color: hsl(120, 100%, 40%);">+        if (byte == 0xff)</span><br><span style="color: hsl(120, 100%, 40%);">+             return EMMC_STATUS_INVALID_ADDR;</span><br><span style="color: hsl(120, 100%, 40%);">+      pinfo->status = EMMC_SEND_RESET;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ byte |= EMMC_RESET_ALL;</span><br><span style="color: hsl(120, 100%, 40%);">+       *reset = byte;</span><br><span style="color: hsl(120, 100%, 40%);">+        byte = 0; /* preclear */</span><br><span style="color: hsl(120, 100%, 40%);">+      byte = *reset;</span><br><span style="color: hsl(120, 100%, 40%);">+        if (byte & EMMC_RESET_ALL) {</span><br><span style="color: hsl(120, 100%, 40%);">+              pinfo->status = EMMC_CONFIRMED_RESET_ACCEPTED;</span><br><span style="color: hsl(120, 100%, 40%);">+             return EMMC_STATUS_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+     return EMMC_STATUS_RESET_FAILED;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/include/device/emmc.h b/src/include/device/emmc.h</span><br><span>new file mode 100644</span><br><span>index 0000000..aa0d520</span><br><span>--- /dev/null</span><br><span>+++ b/src/include/device/emmc.h</span><br><span>@@ -0,0 +1,58 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * eMMC reset send and check, warning payload..</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 Silverback Ltd.</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 <arch/io.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define EMMC_SEND_RESET                      1</span><br><span style="color: hsl(120, 100%, 40%);">+#define EMMC_CONFIRMED_RESET_ACCEPTED        2</span><br><span style="color: hsl(120, 100%, 40%);">+#define EMMC_RESET_STILL_ACTIVE              3</span><br><span style="color: hsl(120, 100%, 40%);">+#define EMMC_RESET_COMPLETED         4</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%);">+ * EMMC_SEND_RESET                     About to send the reset command</span><br><span style="color: hsl(120, 100%, 40%);">+ * EMMC_CONFIRMED_RESET_ACCEPTED       Reset accepted by eMMC</span><br><span style="color: hsl(120, 100%, 40%);">+ * EMMC_RESET_STILL_ACTIVE              Reset checked, but still on going</span><br><span style="color: hsl(120, 100%, 40%);">+ * EMMC_RESET_COMPLETED                      Reset completed successfully</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%);">+#define EMMC_STATUS_SUCCESS                0</span><br><span style="color: hsl(120, 100%, 40%);">+#define EMMC_STATUS_INVALID_ADDR     -1</span><br><span style="color: hsl(120, 100%, 40%);">+#define EMMC_STATUS_CBMEM_FAILED    -2</span><br><span style="color: hsl(120, 100%, 40%);">+#define EMMC_STATUS_RESET_FAILED    -3</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define EMMC_SOFTWARE_RESET       0x2F</span><br><span style="color: hsl(120, 100%, 40%);">+#define   EMMC_RESET_ALL  0x01</span><br><span style="color: hsl(120, 100%, 40%);">+#define   EMMC_RESET_CMD  0x02</span><br><span style="color: hsl(120, 100%, 40%);">+#define   EMMC_RESET_DATA 0x04</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define EMMC_ID                 0x65555543</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%);">+ * In order to permit other code also send information to payload, this</span><br><span style="color: hsl(120, 100%, 40%);">+ * structure always starts with an identifier. If the same mechanism of</span><br><span style="color: hsl(120, 100%, 40%);">+ * sending information to payload is desired, but with more that just a</span><br><span style="color: hsl(120, 100%, 40%);">+ * single byte (or maybe one byte, but different definitions), having an</span><br><span style="color: hsl(120, 100%, 40%);">+ * identifier as its header allows code to change to different pointers</span><br><span style="color: hsl(120, 100%, 40%);">+ * type depending on identifier.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct payload_info {</span><br><span style="color: hsl(120, 100%, 40%);">+  uint32_t identifier;</span><br><span style="color: hsl(120, 100%, 40%);">+  uint8_t status;</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%);">+int emmc_start_reset(uint8_t *base_address);</span><br><span style="color: hsl(120, 100%, 40%);">+int emmc_check_reset(uint8_t *base_address);</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/c/coreboot/+/30225">change 30225</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/c/coreboot/+/30225"/><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-Change-Id: I4bb55fde23e3b70da1cca76e5672e880317b8bd2 </div>
<div style="display:none"> Gerrit-Change-Number: 30225 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Spiegel <richard.spiegel@silverbackltd.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>