<p>Marshall Dawson has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/21746">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">amd/stoneyridge: Refactor SMI handler<br><br>Rewrite the handler to be more compact and extendable.  The old<br>functionality is duplicated after the rewrite.  All SMI source registers<br>(except for SmiSciStatus) behave identically so these are consolidated.<br>Register 0x80 contains sources 0-31, 0x81 sources 32-63, and so on.<br><br>Create a table of mini-handlers to be supported in the soc directory.<br>As SMI sources are discovered, attempt to find the corresponding handler<br>and then execute it.<br><br>Change-Id: Ic7050ecf65c2af036fe297f429a0bbdc709ad4c1<br>Signed-off-by: Marshall Dawson <marshalldawson3rd@gmail.com><br>---<br>M src/soc/amd/stoneyridge/include/soc/smi.h<br>M src/soc/amd/stoneyridge/smihandler.c<br>2 files changed, 56 insertions(+), 50 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/46/21746/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/src/soc/amd/stoneyridge/include/soc/smi.h b/src/soc/amd/stoneyridge/include/soc/smi.h<br>index c024c08..ed4a6c0 100644<br>--- a/src/soc/amd/stoneyridge/include/soc/smi.h<br>+++ b/src/soc/amd/stoneyridge/include/soc/smi.h<br>@@ -196,6 +196,11 @@<br>   SMI_LVL_HIGH = 1,<br> };<br> <br>+struct smi_sources_t {<br>+   int type;<br>+    void (*handler)(void);<br>+};<br>+<br> static inline uint32_t smi_read32(uint8_t offset)<br> {<br>        return read32((void *)(SMI_BASE + offset));<br>diff --git a/src/soc/amd/stoneyridge/smihandler.c b/src/soc/amd/stoneyridge/smihandler.c<br>index cabfd3d..8551631 100644<br>--- a/src/soc/amd/stoneyridge/smihandler.c<br>+++ b/src/soc/amd/stoneyridge/smihandler.c<br>@@ -1,8 +1,17 @@<br> /*<br>- * SMI handler for Hudson southbridges<br>+ * This file is part of the coreboot project.<br>  *<br>+ * Copyright (C) 2017 Advanced Micro Devices, Inc.<br>  * Copyright (C) 2014 Alexandru Gagniuc <mr.nuke.me@gmail.com><br>- * Subject to the GNU GPL v2, or (at your option) any later version.<br>+ *<br>+ * This program is free software; you can redistribute it and/or modify<br>+ * it under the terms of the GNU General Public License as published by<br>+ * the Free Software Foundation; version 2 of the License.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>+ * GNU General Public License for more details.<br>  */<br> <br> #include <console/console.h><br>@@ -37,6 +46,14 @@<br>       return 0;<br> }<br> <br>+/*<br>+ * Table of functions supported in the SMI handler.  Note that SMI source setup<br>+ * in southbridge.c is unrelated to this list.<br>+ */<br>+struct smi_sources_t smi_sources[] = {<br>+              {SMITYPE_SMI_CMD_PORT, sb_apmc_smi_handler},<br>+};<br>+<br> static void process_smi_sci(void)<br> {<br>  const uint32_t status = smi_read32(SMI_SCI_STATUS);<br>@@ -45,54 +62,38 @@<br>      smi_write32(SMI_SCI_STATUS, status);<br> }<br> <br>-static void process_gpe_smi(void)<br>+static void *get_source_handler(int source)<br> {<br>-    const uint32_t status = smi_read32(SMI_REG_SMISTS0);<br>+ int i;<br> <br>-    /* Only Bits [23:0] indicate GEVENT SMIs. */<br>- if (status & GEVENT_MASK) {<br>-              /* A GEVENT SMI occurred */<br>-          mainboard_smi_gpi(status & GEVENT_MASK);<br>+ for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++)<br>+           if (smi_sources[i].type == source)<br>+                   return smi_sources[i].handler;<br>+<br>+    return NULL;<br>+}<br>+<br>+static void process_smi_sources(uint32_t reg)<br>+{<br>+      const uint32_t status = smi_read32(reg);<br>+     int offset = 32 * (reg - SMI_REG_SMISTS0) / 4;<br>+       void (*source_handler)(void);<br>+        int i;<br>+<br>+    for (i = 0 ; i < 32 ; i++) {<br>+              if (status & (1 << i)) {<br>+                   source_handler = get_source_handler(i + offset);<br>+                     if (source_handler)<br>+                          source_handler();<br>+            }<br>     }<br> <br>- /* Clear events to prevent re-entering SMI if event isn't handled */<br>-     smi_write32(SMI_REG_SMISTS0, status);<br>-}<br>+    if (reg == SMI_REG_SMISTS0)<br>+          if (status & GEVENT_MASK)<br>+                        mainboard_smi_gpi(status & GEVENT_MASK);<br> <br>-static void process_smi_0x84(void)<br>-{<br>-     const uint32_t status = smi_read32(SMI_REG_SMISTS1);<br>-<br>-      /* Clear events to prevent re-entering SMI if event isn't handled */<br>-     smi_write32(SMI_REG_SMISTS1, status);<br>-}<br>-<br>-static void process_smi_0x88(void)<br>-{<br>-        const uint32_t status = smi_read32(SMI_REG_SMISTS2);<br>-<br>-      if (status & TYPE_TO_MASK(SMITYPE_SMI_CMD_PORT)) {<br>-               /* Command received via ACPI SMI command port */<br>-             sb_apmc_smi_handler();<br>-       }<br>-    /* Clear events to prevent re-entering SMI if event isn't handled */<br>-     smi_write32(SMI_REG_SMISTS2, status);<br>-}<br>-<br>-static void process_smi_0x8c(void)<br>-{<br>-        const uint32_t status = smi_read32(SMI_REG_SMISTS3);<br>-<br>-      /* Clear events to prevent re-entering SMI if event isn't handled */<br>-     smi_write32(SMI_REG_SMISTS4, status);<br>-}<br>-<br>-static void process_smi_0x90(void)<br>-{<br>-        const uint32_t status = smi_read32(SMI_REG_SMISTS4);<br>-<br>-      /* Clear events to prevent re-entering SMI if event isn't handled */<br>-     smi_write32(SMI_REG_SMISTS4, status);<br>+        /* Clear all events in this register */<br>+      smi_write32(reg, status);<br> }<br> <br> void southbridge_smi_handler(void)<br>@@ -102,15 +103,15 @@<br>  if (smi_src & SMI_STATUS_SRC_SCI)<br>                 process_smi_sci();<br>    if (smi_src & SMI_STATUS_SRC_0)<br>-          process_gpe_smi();<br>+           process_smi_sources(SMI_REG_SMISTS0);<br>         if (smi_src & SMI_STATUS_SRC_1)<br>-          process_smi_0x84();<br>+          process_smi_sources(SMI_REG_SMISTS1);<br>         if (smi_src & SMI_STATUS_SRC_2)<br>-          process_smi_0x88();<br>+          process_smi_sources(SMI_REG_SMISTS2);<br>         if (smi_src & SMI_STATUS_SRC_3)<br>-          process_smi_0x8c();<br>+          process_smi_sources(SMI_REG_SMISTS3);<br>         if (smi_src & SMI_STATUS_SRC_4)<br>-          process_smi_0x90();<br>+          process_smi_sources(SMI_REG_SMISTS4);<br> }<br> <br> void southbridge_smi_set_eos(void)<br></pre><p>To view, visit <a href="https://review.coreboot.org/21746">change 21746</a>. To unsubscribe, 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/21746"/><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: Ic7050ecf65c2af036fe297f429a0bbdc709ad4c1 </div>
<div style="display:none"> Gerrit-Change-Number: 21746 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Marshall Dawson <marshalldawson3rd@gmail.com> </div>