199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Obtain memory configuration information from the BIOS
199767f8919635c4928607450d9e0abb932109ceToomas Soomevm_offset_t memtop, memtop_copyin, high_heap_base;
199767f8919635c4928607450d9e0abb932109ceToomas Soomeuint32_t bios_basemem, bios_extmem, high_heap_size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Used to track which method was used to set BIOS memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The minimum amount of memory to reserve in bios_extmem for the heap.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Products in this list need quirks to detect
199767f8919635c4928607450d9e0abb932109ceToomas Soome * memory correctly. You need both maker and product as
199767f8919635c4928607450d9e0abb932109ceToomas Soome * reported by smbios.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BQ_DISTRUST_E820_EXTMEM 0x1 /* e820 might not return useful
199767f8919635c4928607450d9e0abb932109ceToomas Soome extended memory */
199767f8919635c4928607450d9e0abb932109ceToomas Soome {"coreboot", "Acer", "Peppy", BQ_DISTRUST_E820_EXTMEM},
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (smbios_match(quirks[i].bios_vendor, quirks[i].maker,
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Parse system memory map */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((V86_CY(v86.efl)) || (v86.eax != SMAP_SIG))
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* look for a low-memory segment that's large enough */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base == 0) &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* look for the first segment in 'extended' memory */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base == 0x100000) &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome !(bios_getquirks() & BQ_DISTRUST_E820_EXTMEM)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Look for the largest segment in 'extended' memory beyond
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1MB but below 4GB.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base > 0x100000) &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If this segment crosses the 4GB boundary, truncate it.
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Fall back to the old compatibility function for base memory */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Fall back through several compatibility functions for extended memory */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Clear high_heap; it may end up overlapping
199767f8919635c4928607450d9e0abb932109ceToomas Soome * with the segment we're determining here.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Let the default "steal stuff from top of
199767f8919635c4928607450d9e0abb932109ceToomas Soome * bios_extmem" code below pick up on it.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * %cx is the number of 1KiB blocks between 1..16MiB.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * It can only be up to 0x3c00; if it's smaller then
199767f8919635c4928607450d9e0abb932109ceToomas Soome * there's a PC AT memory hole so we can't treat
199767f8919635c4928607450d9e0abb932109ceToomas Soome * it as contiguous.
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* truncate bios_extmem */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Set memtop to actual top of memory */
199767f8919635c4928607450d9e0abb932109ceToomas Soome memtop = memtop_copyin = 0x100000 + bios_extmem;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If we have extended memory and did not find a suitable heap
199767f8919635c4928607450d9e0abb932109ceToomas Soome * region in the SMAP, use the last 3MB of 'extended' memory as a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * high heap candidate.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (bios_extmem >= HEAP_MIN && high_heap_size < HEAP_MIN) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("bios_basemem: 0x%llx\n", (unsigned long long) bios_basemem);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("bios_extmem: 0x%llx\n", (unsigned long long) bios_extmem);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("memtop: 0x%llx\n", (unsigned long long) memtop);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("high_heap_base: 0x%llx\n", (unsigned long long) high_heap_base);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("high_heap_size: 0x%llx\n", (unsigned long long) high_heap_size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("b_bios_probed: 0x%02x", (int) b_bios_probed);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(biosmem, "biosmem", "show BIOS memory setup", command_biosmem);