From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Chen, Yingwen" <yingwen.chen@intel.com>,
edk2-devel-groups-io <devel@edk2.groups.io>,
Phillip Goerl <phillip.goerl@oracle.com>,
"Yao, Jiewen" <jiewen.yao@intel.com>,
"Nakajima, Jun" <jun.nakajima@intel.com>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
edk2-rfc-groups-io <rfc@edk2.groups.io>,
Laszlo Ersek <lersek@redhat.com>,
Joao Marcal Lemos Martins <joao.m.martins@oracle.com>,
pbonzini@redhat.com
Subject: [POC Seabios PATCH] seabios: use isolated SMM address space for relocation
Date: Fri, 16 Aug 2019 07:24:07 -0400 [thread overview]
Message-ID: <20190816112407.28180-3-imammedo@redhat.com> (raw)
In-Reply-To: <20190816112407.28180-1-imammedo@redhat.com>
for purpose of demo SMRAM (at 0x30000) is aliased at a0000 in system address space
for easy initialization of SMI entry point.
Here is resulting debug output showing that RAM at 0x30000 is not affected
by SMM and only RAM in SMM adderss space is modified:
init smm
smm_relocate: before relocaten
smm_relocate: RAM codeentry 0
smm_relocate: RAM cpu.i64.smm_base 0
smm_relocate: SMRAM codeentry f000c831eac88c
smm_relocate: SMRAM cpu.i64.smm_base 0
handle_smi cmd=0 smbase=0x00030000
smm_relocate: after relocaten
smm_relocate: RAM codeentry 0
smm_relocate: RAM cpu.i64.smm_base 0
smm_relocate: SMRAM codeentry f000c831eac88c
smm_relocate: SMRAM cpu.i64.smm_base a0000
Patch depends on QEMU POC patch that adds SMRAM at 0x30000 in SMM address space
PS:
configure bios with level 9 debugging and debug port
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
src/fw/smm.c | 43 +++++++++++++++++++------------------------
1 file changed, 19 insertions(+), 24 deletions(-)
diff --git a/src/fw/smm.c b/src/fw/smm.c
index d90e43a9..27f9747e 100644
--- a/src/fw/smm.c
+++ b/src/fw/smm.c
@@ -140,21 +140,22 @@ extern void entry_smi(void);
| ((u64)((u32)entry_smi - BUILD_BIOS_ADDR) << 24))
static void
-smm_save_and_copy(void)
+smm_relocate(void)
{
- // save original memory content
struct smm_layout *initsmm = (void*)BUILD_SMM_INIT_ADDR;
struct smm_layout *smm = (void*)BUILD_SMM_ADDR;
- memcpy(&smm->cpu, &initsmm->cpu, sizeof(smm->cpu));
- memcpy(&smm->codeentry, &initsmm->codeentry, sizeof(smm->codeentry));
- // Setup code entry point.
- initsmm->codeentry = SMI_INSN;
-}
+ dprintf(3, "smm_relocate: before relocaten\n");
+ dprintf(3, "smm_relocate: RAM codeentry %llx\n", initsmm->codeentry);
+ dprintf(3, "smm_relocate: RAM cpu.i64.smm_base %lx\n", initsmm->cpu.i64.smm_base);
+
+
+ /* BUILD_SMM_ADDR aliased to BUILD_SMM_INIT_ADDR in SMM AS
+ * so we could set SMI entry point there */
+ smm->codeentry = SMI_INSN;
+ dprintf(3, "smm_relocate: SMRAM codeentry %llx\n", smm->codeentry);
+ dprintf(3, "smm_relocate: SMRAM cpu.i64.smm_base %lx\n", smm->cpu.i64.smm_base);
-static void
-smm_relocate_and_restore(void)
-{
/* init APM status port */
outb(0x01, PORT_SMI_STATUS);
@@ -165,15 +166,13 @@ smm_relocate_and_restore(void)
while (inb(PORT_SMI_STATUS) != 0x00)
;
- /* restore original memory content */
- struct smm_layout *initsmm = (void*)BUILD_SMM_INIT_ADDR;
- struct smm_layout *smm = (void*)BUILD_SMM_ADDR;
- memcpy(&initsmm->cpu, &smm->cpu, sizeof(initsmm->cpu));
- memcpy(&initsmm->codeentry, &smm->codeentry, sizeof(initsmm->codeentry));
-
- // Setup code entry point.
- smm->codeentry = SMI_INSN;
wbinvd();
+
+ dprintf(3, "smm_relocate: after relocaten\n");
+ dprintf(3, "smm_relocate: RAM codeentry %llx\n", initsmm->codeentry);
+ dprintf(3, "smm_relocate: RAM cpu.i64.smm_base %lx\n", initsmm->cpu.i64.smm_base);
+ dprintf(3, "smm_relocate: SMRAM codeentry %llx\n", smm->codeentry);
+ dprintf(3, "smm_relocate: SMRAM cpu.i64.smm_base %lx\n", smm->cpu.i64.smm_base);
}
// This code is hardcoded for PIIX4 Power Management device.
@@ -187,8 +186,6 @@ static void piix4_apmc_smm_setup(int isabdf, int i440_bdf)
/* enable the SMM memory window */
pci_config_writeb(i440_bdf, I440FX_SMRAM, 0x02 | 0x48);
- smm_save_and_copy();
-
/* enable SMI generation when writing to the APMC register */
pci_config_writel(isabdf, PIIX_DEVACTB, value | PIIX_DEVACTB_APMC_EN);
@@ -196,7 +193,7 @@ static void piix4_apmc_smm_setup(int isabdf, int i440_bdf)
value = inl(acpi_pm_base + PIIX_PMIO_GLBCTL);
outl(value | PIIX_PMIO_GLBCTL_SMI_EN, acpi_pm_base + PIIX_PMIO_GLBCTL);
- smm_relocate_and_restore();
+ smm_relocate();
/* close the SMM memory window and enable normal SMM */
pci_config_writeb(i440_bdf, I440FX_SMRAM, 0x02 | 0x08);
@@ -213,8 +210,6 @@ void ich9_lpc_apmc_smm_setup(int isabdf, int mch_bdf)
/* enable the SMM memory window */
pci_config_writeb(mch_bdf, Q35_HOST_BRIDGE_SMRAM, 0x02 | 0x48);
- smm_save_and_copy();
-
/* enable SMI generation when writing to the APMC register */
outl(value | ICH9_PMIO_SMI_EN_APMC_EN | ICH9_PMIO_SMI_EN_GLB_SMI_EN,
acpi_pm_base + ICH9_PMIO_SMI_EN);
@@ -224,7 +219,7 @@ void ich9_lpc_apmc_smm_setup(int isabdf, int mch_bdf)
pci_config_writel(isabdf, ICH9_LPC_GEN_PMCON_1,
value | ICH9_LPC_GEN_PMCON_1_SMI_LOCK);
- smm_relocate_and_restore();
+ smm_relocate();
/* close the SMM memory window and enable normal SMM */
pci_config_writeb(mch_bdf, Q35_HOST_BRIDGE_SMRAM, 0x02 | 0x08);
--
2.18.1
next prev parent reply other threads:[~2019-08-16 11:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-16 11:24 [POC QEMU PATCH 0/2] CPU hotplug: use dedicated SMRAM at 0x30000 in SMM address space Igor Mammedov
2019-08-16 11:24 ` [PATCH QEMU 1/1] q35: use dedicated SMRAM at default SMM_BASE Igor Mammedov
2019-08-16 11:24 ` Igor Mammedov [this message]
2019-08-16 22:43 ` [POC Seabios PATCH] seabios: use isolated SMM address space for relocation Boris Ostrovsky
2019-08-26 13:57 ` Igor Mammedov
2019-08-27 1:28 ` Boris Ostrovsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190816112407.28180-3-imammedo@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox