Skip to contentSkip to conversation

abstract shadow and smm opreration.

PATCH In review Isaku Yamahata 2 participants 4 messages Jul 20, 2010 – Jul 24, 2010

lore
Share & tools
lore
#0 lore raw

v2 cover abstract shadow and smm opreration.

This is on top of the patch series of
PATCH v2 "abstract chipset(i440fx) specific register operation."

Patch descriontion:
This patch set abstract out shadow and smm operation which are specific to chipset. and spit out i440fx specific part into dev-i440fx.c. Thus q35 specific register value/operation will be added easily.

Changes v1 -> v2:
- separated non-arguable part to make the merge easy.
- factor out intel specific shadow memory operation.
- factor out smm operation.
- abstract at device level, not register level.

Isaku Yamahata (2):
seabios: shadow: make device finding more generic.
seabios: smm: move out piix4 specific smram logic to dev-i440fx.c

 src/dev-i440fx.c |   44 ++++++++++++++++++++++
 src/dev-i440fx.h |    3 ++
 src/shadow.c     |  106 +++++++++++++++++++++++++++++++++---------------------
 src/smm.c        |   58 +++++++++++++-----------------
 src/util.h       |    6 +++
 5 files changed, 143 insertions(+), 74 deletions(-)
#1 lore raw

PATCH v2 1/2 seabios: shadow: make device finding more generic.

pam register offset is north bridge specific. So determine the offset based on found north bridge.

---
changes v2 -> v3.
- abstract at device level, not at register offset level.
- factor out intel chipset operation.

---
 src/dev-i440fx.c |   12 ++++++
 src/dev-i440fx.h |    2 +
 src/shadow.c     |  106 +++++++++++++++++++++++++++++++++---------------------
 src/util.h       |    2 +
 4 files changed, 81 insertions(+), 41 deletions(-)
src/dev-i440fx.c +12 -0
index 15c6cac..366a2db 100644
@@ -17,6 +17,18 @@
 #include "acpi.h"
 #include "dev-i440fx.h"
 
+#define I440FX_PAM0     0x59
+
+void i440fx_bios_make_writable(u16 bdf, void *arg)
+{
+    make_bios_writable_intel(bdf, I440FX_PAM0);
+}
+
+void i440fx_bios_make_readonly(u16 bdf, void *arg)
+{
+    make_bios_readonly_intel(bdf, I440FX_PAM0);
+}
+
 /* PIIX3/PIIX4 PCI to ISA bridge */
 void piix_isa_bridge_init(u16 bdf, void *arg)
 {
src/dev-i440fx.h +2 -0
index 661860a..6d1b687 100644
@@ -3,6 +3,8 @@
 
 #include "types.h" // u16
 
+void i440fx_bios_make_writable(u16 bdf, void *arg);
+void i440fx_bios_make_readonly(u16 bdf, void *arg);
 void piix_isa_bridge_init(u16 bdf, void *arg);
 void piix_ide_init(u16 bdf, void *arg);
 void piix4_pm_init(u16 bdf, void *arg);
src/shadow.c +65 -41

167 lines not on this page · raw message

src/util.h +2 -0
index 6c08a3c..96f4ff7 100644
@@ -332,6 +332,8 @@ void bios32_setup(void);
 // shadow.c
 void make_bios_writable(void);
 void make_bios_readonly(void);
+void make_bios_writable_intel(u16 bdf, u32 pam0);
+void make_bios_readonly_intel(u16 bdf, u32 pam0);
 
 // pciinit.c
 extern const u8 pci_irqs[4];
Signature · 1 line
1.7.1.1
#2 lore raw

PATCH v2 2/2 seabios: smm: move out piix4 specific smram logic to dev-i440fx.c

In reply to Isaku Yamahata

move out piix4 specific smram logic to dev-i440fx.c.

---
changes v2 -> v3.
- abstract device level and simplified it.
- factor out smm ram relocation.

---
 src/dev-i440fx.c |   32 +++++++++++++++++++++++++++++
 src/dev-i440fx.h |    1 +
 src/smm.c        |   58 +++++++++++++++++++++++------------------------------
 src/util.h       |    4 +++
 4 files changed, 62 insertions(+), 33 deletions(-)
src/dev-i440fx.c +32 -0
index 366a2db..346f6d0 100644
@@ -13,6 +13,7 @@
 #include "util.h" // dprintf
 #include "ioport.h" // outb
 #include "pci.h" // pci_config_writeb
+#include "pci_ids.h"
 #include "pci_regs.h" // PCI_INTERRUPT_LINE
 #include "acpi.h"
 #include "dev-i440fx.h"
@@ -82,3 +83,34 @@ void piix4_fadt_init(u16 bdf, void *arg)
     fadt->gpe0_blk = cpu_to_le32(PIIX4_GPE0_BLK);
     fadt->gpe0_blk_len = PIIX4_GPE0_BLK_LEN;
 }
+
+#define I440FX_SMRAM    0x72
+#define PIIX_DEVACTB    0x58
+#define PIIX_APMC_EN    (1 << 25)
+
+// This code is hardcoded for PIIX4 Power Management device.
+void piix4_apmc_smm_init(u16 bdf, void *arg)
+{
+    int i440_bdf = pci_find_device(PCI_VENDOR_ID_INTEL
+                                   , PCI_DEVICE_ID_INTEL_82441);
+    if (i440_bdf < 0)
+        return;
+
+    /* check if SMM init is already done */
+    u32 value = pci_config_readl(bdf, PIIX_DEVACTB);
+    if (value & PIIX_APMC_EN)
+        return;
+
+    /* 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(bdf, PIIX_DEVACTB, value | PIIX_APMC_EN);
+
+    smm_relocate_and_restore();
+
+    /* close the SMM memory window and enable normal SMM */
+    pci_config_writeb(i440_bdf, I440FX_SMRAM, 0x02 | 0x08);
+}
src/dev-i440fx.h +1 -0
index 6d1b687..ab5a4d1 100644
@@ -9,5 +9,6 @@ void piix_isa_bridge_init(u16 bdf, void *arg);
 void piix_ide_init(u16 bdf, void *arg);
 void piix4_pm_init(u16 bdf, void *arg);
 void piix4_fadt_init(u16 bdf, void *arg);
+void piix4_apmc_smm_init(u16 bdf, void *arg);
 
 #endif // __I440FX_H
src/smm.c +25 -33

83 lines not on this page · raw message

src/util.h +4 -0
index 96f4ff7..85cf3f5 100644
@@ -335,6 +335,10 @@ void make_bios_readonly(void);
 void make_bios_writable_intel(u16 bdf, u32 pam0);
 void make_bios_readonly_intel(u16 bdf, u32 pam0);
 
+// smm.c
+void smm_save_and_copy(void);
+void smm_relocate_and_restore(void);
+
 // pciinit.c
 extern const u8 pci_irqs[4];
 void pci_bios_allocate_regions(u16 bdf, void *arg);
Signature · 1 line
1.7.1.1
#3 lore raw
In reply to Isaku Yamahata
Quoted 7 lines · Isaku Yamahata

This is on top of the patch series of
PATCH v2 "abstract chipset(i440fx) specific register operation."

Patch descriontion:
This patch set abstract out shadow and smm operation which are specific to chipset. and spit out i440fx specific part into dev-i440fx.c. Thus q35 specific register value/operation will be added easily.

Thanks! I've committed both series.

As a side note, I'm not sure if moving the smm/shadow code into dev-i440fx.c is best - the code seems more specific to smm/shadow then to the i440fx. Lets see how it works out.

-Kevin