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
12 ".global smm_relocation_start\n"
13 ".global smm_relocation_end\n"
14 ".global smm_code_start\n"
15 ".global smm_code_end\n"
18 /* code to relocate SMBASE to 0xa0000 */
19 "smm_relocation_start:\n"
20 " mov $0x38000 + 0x7efc, %ebx\n"
21 " addr32 mov (%ebx), %al\n" /* revision ID to see if x86_64 or x86 */
24 " mov $0x38000 + 0x7ef8, %ebx\n"
27 " mov $0x38000 + 0x7f00, %ebx\n"
29 " movl $0xa0000, %eax\n"
30 " addr32 movl %eax, (%ebx)\n"
31 /* indicate to the BIOS that the SMM code was executed */
36 "smm_relocation_end:\n"
38 /* minimal SMM code to enable or disable ACPI */
46 " mov $" __stringify(BUILD_PM_IO_BASE) " + 0x04, %dx\n" /* PMCNTRL */
58 " mov $" __stringify(BUILD_PM_IO_BASE) " + 0x04, %dx\n" /* PMCNTRL */
69 extern u8 smm_relocation_start, smm_relocation_end;
70 extern u8 smm_code_start, smm_code_end;
78 // This code is hardcoded for PIIX4 Power Management device.
79 PCIDevice i440_pcidev, d;
80 int ret = pci_find_device(0x8086, 0x7113, 0, &d);
84 ret = pci_find_device(0x8086, 0x1237, 0, &i440_pcidev);
88 /* check if SMM init is already done */
89 u32 value = pci_config_readl(d, 0x58);
90 if (value & (1 << 25))
93 /* copy the SMM relocation code */
94 memcpy((void *)0x38000, &smm_relocation_start,
95 &smm_relocation_end - &smm_relocation_start);
97 /* enable SMI generation when writing to the APMC register */
98 pci_config_writel(d, 0x58, value | (1 << 25));
100 /* init APM status port */
103 /* raise an SMI interrupt */
106 /* wait until SMM code executed */
107 while (inb(0xb3) != 0x00)
110 /* enable the SMM memory window */
111 pci_config_writeb(i440_pcidev, 0x72, 0x02 | 0x48);
113 /* copy the SMM code */
114 memcpy((void *)0xa8000, &smm_code_start,
115 &smm_code_end - &smm_code_start);
118 /* close the SMM memory window and enable normal SMM */
119 pci_config_writeb(i440_pcidev, 0x72, 0x02 | 0x08);