Merge tag 'bsd-user-misc-2024q2-pull-request' of gitlab.com:bsdimp/qemu into staging
[qemu/kevin.git] / hw / i386 / e820_memory_layout.c
blob06970ac44a2e3f5aaab972334a0304ed16a93b38
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_entry *e820_table;
16 int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
18 /* new "etc/e820" file -- include ram and reserved entries */
19 e820_table = g_renew(struct e820_entry, e820_table, e820_entries + 1);
20 e820_table[e820_entries].address = cpu_to_le64(address);
21 e820_table[e820_entries].length = cpu_to_le64(length);
22 e820_table[e820_entries].type = cpu_to_le32(type);
23 e820_entries++;
25 return e820_entries;
28 int e820_get_num_entries(void)
30 return e820_entries;
33 bool e820_get_entry(int idx, uint32_t type, uint64_t *address, uint64_t *length)
35 if (idx < e820_entries && e820_table[idx].type == cpu_to_le32(type)) {
36 *address = le64_to_cpu(e820_table[idx].address);
37 *length = le64_to_cpu(e820_table[idx].length);
38 return true;
40 return false;