1 // System Management Mode support (on emulators)
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2006 Fabrice Bellard
6 // This file may be distributed under the terms of the GNU GPLv3 license.
8 #include "pci.h" // PCIDevice
9 #include "util.h" // wbinvd
10 #include "config.h" // CONFIG_*
11 #include "ioport.h" // outb
14 ".global smm_relocation_start\n"
15 ".global smm_relocation_end\n"
16 ".global smm_code_start\n"
17 ".global smm_code_end\n"
20 /* code to relocate SMBASE to 0xa0000 */
21 "smm_relocation_start:\n"
22 " mov $0x38000 + 0x7efc, %ebx\n"
23 " addr32 mov (%ebx), %al\n" /* revision ID to see if x86_64 or x86 */
26 " mov $0x38000 + 0x7ef8, %ebx\n"
29 " mov $0x38000 + 0x7f00, %ebx\n"
31 " movl $0xa0000, %eax\n"
32 " addr32 movl %eax, (%ebx)\n"
33 /* indicate to the BIOS that the SMM code was executed */
38 "smm_relocation_end:\n"
40 /* minimal SMM code to enable or disable ACPI */
48 " mov $" __stringify(BUILD_PM_IO_BASE) " + 0x04, %dx\n" /* PMCNTRL */
60 " mov $" __stringify(BUILD_PM_IO_BASE) " + 0x04, %dx\n" /* PMCNTRL */
71 extern u8 smm_relocation_start, smm_relocation_end;
72 extern u8 smm_code_start, smm_code_end;
80 // This code is hardcoded for PIIX4 Power Management device.
81 PCIDevice i440_pcidev, d;
82 int ret = pci_find_device(0x8086, 0x7113, 0, &d);
86 ret = pci_find_device(0x8086, 0x1237, 0, &i440_pcidev);
90 /* check if SMM init is already done */
91 u32 value = pci_config_readl(d, 0x58);
92 if (value & (1 << 25))
95 /* copy the SMM relocation code */
96 memcpy((void *)0x38000, &smm_relocation_start,
97 &smm_relocation_end - &smm_relocation_start);
99 /* enable SMI generation when writing to the APMC register */
100 pci_config_writel(d, 0x58, value | (1 << 25));
102 /* init APM status port */
105 /* raise an SMI interrupt */
108 /* wait until SMM code executed */
109 while (inb(0xb3) != 0x00)
112 /* enable the SMM memory window */
113 pci_config_writeb(i440_pcidev, 0x72, 0x02 | 0x48);
115 /* copy the SMM code */
116 memcpy((void *)0xa8000, &smm_code_start,
117 &smm_code_end - &smm_code_start);
120 /* close the SMM memory window and enable normal SMM */
121 pci_config_writeb(i440_pcidev, 0x72, 0x02 | 0x08);