1 // Support for enabling/disabling BIOS ram shadowing.
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 "util.h" // memcpy
9 #include "pci.h" // pci_config_writeb
10 #include "config.h" // CONFIG_*
12 // Test if 'addr' is in the range from 'start'..'start+size'
13 #define IN_RANGE(addr, start, size) ({ \
14 u32 __addr = (addr); \
15 u32 __start = (start); \
16 u32 __size = (size); \
17 (__addr - __start < __size); \
20 // Enable shadowing and copy bios.
22 copy_bios(PCIDevice d)
24 int v = pci_config_readb(d, 0x59);
26 pci_config_writeb(d, 0x59, v);
27 memcpy((void *)BUILD_BIOS_ADDR, (void *)BUILD_BIOS_TMP_ADDR
31 // Make the BIOS code segment area (0xf0000) writable.
38 dprintf(3, "enabling shadow ram\n");
40 // Locate chip controlling ram shadowing.
42 int ret = pci_find_device(0x8086, 0x1237, 0, &d);
44 dprintf(1, "Unable to unlock ram - bridge not found\n");
48 // Copy the bios to a temporary area.
49 memcpy((void *)BUILD_BIOS_TMP_ADDR, (void *)BUILD_BIOS_ADDR
52 // Enable shadowing and copy bios.
53 if (IN_RANGE((u32)copy_bios, BUILD_BIOS_ADDR, BUILD_BIOS_SIZE)) {
54 // Jump to shadow enable function - use the copy in the
55 // temporary storage area so that memory does not change under
56 // the executing code.
57 u32 pos = (u32)copy_bios - BUILD_BIOS_ADDR + BUILD_BIOS_TMP_ADDR;
58 void (*func)(PCIDevice) = (void*)pos;
64 // Clear the temporary area.
65 memset((void *)BUILD_BIOS_TMP_ADDR, 0, BUILD_BIOS_SIZE);
68 // Make the BIOS code segment area (0xf0000) read-only.
75 dprintf(3, "locking shadow ram\n");
78 int ret = pci_find_device(0x8086, 0x1237, 0, &d);
80 dprintf(1, "Unable to lock ram - bridge not found\n");
85 int v = pci_config_readb(d, 0x59);
86 v = (v & 0x0f) | (0x10);
87 pci_config_writeb(d, 0x59, v);