<p>Subrata Banik has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/26327">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">arch/x86: Use core apic id to get cpu_index()<br><br>coreboot x86 cpu_index() implementation has strong dependencies over stack natural<br>alignment which might not work if CONFIG_STACK_SIZE > natural alignment (4KiB).<br><br>This cpu_index() implementation has also assume that cpu_index() function might<br>always getting called from coreboot context (ESP stack pointer will always refer<br>to coreboot). This might not true incase of proposed PI spec MP_SERVICES_PPI<br>implementation, where FSP context (stack pointer refers to fsp) will request<br>to get cpu_index(), natural alignment logic will use ESP and retrieve<br>struct cpu_info *ci from (stack_top - 8 byte). This is not the place where<br>cpu_index is actually stored by ramstage c_start.S<br><br>Hence this patch tries to remove those dependencies while retriving cpu_index(),<br>rather it uses cpuid to fetch lapic id and matches with cpu_mp structure to get<br>correct cpu_index()<br><br>BRANCH=none<br>BUG=b:79562868<br>TEST=Ensures functions can be run on APs without any failiure and cpu_index() also<br>provides correct index number.<br><br>Change-Id: I52c2cc17d825a5dd53759df516c5b74d88fa0580<br>Signed-off-by: Subrata Banik <subrata.banik@intel.com><br>---<br>M src/arch/x86/cpu.c<br>M src/arch/x86/include/arch/cpu.h<br>M src/cpu/x86/mp_init.c<br>M src/include/cpu/x86/mp.h<br>4 files changed, 17 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/27/26327/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/arch/x86/cpu.c b/src/arch/x86/cpu.c</span><br><span>index 7a7c99b..aae7965 100644</span><br><span>--- a/src/arch/x86/cpu.c</span><br><span>+++ b/src/arch/x86/cpu.c</span><br><span>@@ -220,6 +220,18 @@</span><br><span>   cpu->ops = driver ? driver->ops : NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int cpu_index(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      for (i = 0; i < CONFIG_MAX_CPUS; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+            if (mp_get_apic_id(i) == lapicid()) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 return i;</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%);">+     return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void cpu_initialize(unsigned int index)</span><br><span> {</span><br><span>      /* Because we busy wait at the printk spinlock.</span><br><span>diff --git a/src/arch/x86/include/arch/cpu.h b/src/arch/x86/include/arch/cpu.h</span><br><span>index 5d44aae..db12fa4 100644</span><br><span>--- a/src/arch/x86/include/arch/cpu.h</span><br><span>+++ b/src/arch/x86/include/arch/cpu.h</span><br><span>@@ -212,12 +212,8 @@</span><br><span>      return ci;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static inline unsigned long cpu_index(void)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- struct cpu_info *ci;</span><br><span style="color: hsl(0, 100%, 40%);">-    ci = cpu_info();</span><br><span style="color: hsl(0, 100%, 40%);">-        return ci->index;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(120, 100%, 40%);">+int cpu_index(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #endif</span><br><span> </span><br><span> #ifndef __ROMCC__ // romcc is segfaulting in some cases</span><br><span>diff --git a/src/cpu/x86/mp_init.c b/src/cpu/x86/mp_init.c</span><br><span>index ef576ec..900019d 100644</span><br><span>--- a/src/cpu/x86/mp_init.c</span><br><span>+++ b/src/cpu/x86/mp_init.c</span><br><span>@@ -659,7 +659,7 @@</span><br><span> }</span><br><span> </span><br><span> /* Returns APIC id for coreboot CPU number or < 0 on failure. */</span><br><span style="color: hsl(0, 100%, 40%);">-static int mp_get_apic_id(int cpu_slot)</span><br><span style="color: hsl(120, 100%, 40%);">+int mp_get_apic_id(int cpu_slot)</span><br><span> {</span><br><span>  if (cpu_slot >= CONFIG_MAX_CPUS || cpu_slot < 0)</span><br><span>               return -1;</span><br><span>diff --git a/src/include/cpu/x86/mp.h b/src/include/cpu/x86/mp.h</span><br><span>index fba3e75..989a195 100644</span><br><span>--- a/src/include/cpu/x86/mp.h</span><br><span>+++ b/src/include/cpu/x86/mp.h</span><br><span>@@ -145,5 +145,7 @@</span><br><span> void smm_initiate_relocation_parallel(void);</span><br><span> /* Send SMI to self with single execution. */</span><br><span> void smm_initiate_relocation(void);</span><br><span style="color: hsl(120, 100%, 40%);">+/* Get CPU Index based on apic id */</span><br><span style="color: hsl(120, 100%, 40%);">+int mp_get_apic_id(int cpu_slot);</span><br><span> </span><br><span> #endif /* _X86_MP_H_ */</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/26327">change 26327</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/26327"/><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: I52c2cc17d825a5dd53759df516c5b74d88fa0580 </div>
<div style="display:none"> Gerrit-Change-Number: 26327 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Subrata Banik <subrata.banik@intel.com> </div>