hw/isa/Kconfig: Add missing dependency VIA VT82C686 -> APM
[qemu/ar7.git] / hw / i386 / e820_memory_layout.c
blobbcf9eaf83762217249a1dfc6e55720b9d3d5f35e
1 /*
2 * QEMU BIOS e820 routines
4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * SPDX-License-Identifier: MIT
7 */
9 #include "qemu/osdep.h"
10 #include "qemu/bswap.h"
11 #include "e820_memory_layout.h"
13 static size_t e820_entries;
14 struct e820_table e820_reserve;
15 struct e820_entry *e820_table;
17 int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
19 int index = le32_to_cpu(e820_reserve.count);
20 struct e820_entry *entry;
22 if (type != E820_RAM) {
23 /* old FW_CFG_E820_TABLE entry -- reservations only */
24 if (index >= E820_NR_ENTRIES) {
25 return -EBUSY;
27 entry = &e820_reserve.entry[index++];
29 entry->address = cpu_to_le64(address);
30 entry->length = cpu_to_le64(length);
31 entry->type = cpu_to_le32(type);
33 e820_reserve.count = cpu_to_le32(index);
36 /* new "etc/e820" file -- include ram too */
37 e820_table = g_renew(struct e820_entry, e820_table, e820_entries + 1);
38 e820_table[e820_entries].address = cpu_to_le64(address);
39 e820_table[e820_entries].length = cpu_to_le64(length);
40 e820_table[e820_entries].type = cpu_to_le32(type);
41 e820_entries++;
43 return e820_entries;
46 int e820_get_num_entries(void)
48 return e820_entries;
51 bool e820_get_entry(int idx, uint32_t type, uint64_t *address, uint64_t *length)
53 if (idx < e820_entries && e820_table[idx].type == cpu_to_le32(type)) {
54 *address = le64_to_cpu(e820_table[idx].address);
55 *length = le64_to_cpu(e820_table[idx].length);
56 return true;
58 return false;