]> git.proxmox.com Git - mirror_qemu.git/blame - tests/acpi-utils.c
tests: acpi: reuse fetch_table() for fetching FACS and DSDT
[mirror_qemu.git] / tests / acpi-utils.c
CommitLineData
3248f1b4
BW
1/*
2 * ACPI Utility Functions
3 *
4 * Copyright (c) 2013 Red Hat Inc.
5 * Copyright (c) 2017 Skyport Systems
6 *
7 * Authors:
8 * Michael S. Tsirkin <mst@redhat.com>,
9 * Ben Warren <ben@skyportsystems.com>
10 *
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
13 */
14
15#include "qemu/osdep.h"
16#include <glib/gstdio.h>
17#include "qemu-common.h"
3248f1b4
BW
18#include "qemu/bitmap.h"
19#include "acpi-utils.h"
20#include "boot-sector.h"
21
22uint8_t acpi_calc_checksum(const uint8_t *data, int len)
23{
24 int i;
25 uint8_t sum = 0;
26
27 for (i = 0; i < len; i++) {
28 sum += data[i];
29 }
30
31 return sum;
32}
33
273e3d92 34uint32_t acpi_find_rsdp_address(QTestState *qts)
3248f1b4
BW
35{
36 uint32_t off;
37
38 /* RSDP location can vary across a narrow range */
39 for (off = 0xf0000; off < 0x100000; off += 0x10) {
40 uint8_t sig[] = "RSD PTR ";
41 int i;
42
43 for (i = 0; i < sizeof sig - 1; ++i) {
273e3d92 44 sig[i] = qtest_readb(qts, off + i);
3248f1b4
BW
45 }
46
47 if (!memcmp(sig, "RSD PTR ", sizeof sig)) {
48 break;
49 }
50 }
51 return off;
52}
53
d6caf363 54uint32_t acpi_get_rsdt_address(uint8_t *rsdp_table)
3248f1b4 55{
d6caf363
SO
56 uint32_t rsdt_physical_address;
57
58 memcpy(&rsdt_physical_address, &rsdp_table[16 /* RsdtAddress offset */], 4);
59 return le32_to_cpu(rsdt_physical_address);
60}
61
62uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table)
63{
64 uint64_t xsdt_physical_address;
65 uint8_t revision = rsdp_table[15 /* Revision offset */];
66
67 /* We must have revision 2 if we're looking for an XSDT pointer */
68 g_assert(revision == 2);
69
70 memcpy(&xsdt_physical_address, &rsdp_table[24 /* XsdtAddress offset */], 8);
71 return le64_to_cpu(xsdt_physical_address);
72}
73
74void acpi_parse_rsdp_table(QTestState *qts, uint32_t addr, uint8_t *rsdp_table)
75{
76 uint8_t revision;
77
78 /* Read mandatory revision 0 table data (20 bytes) first */
79 qtest_memread(qts, addr, rsdp_table, 20);
80 revision = rsdp_table[15 /* Revision offset */];
81
82 switch (revision) {
83 case 0: /* ACPI 1.0 RSDP */
84 break;
85 case 2: /* ACPI 2.0+ RSDP */
86 /* Read the rest of the RSDP table */
87 qtest_memread(qts, addr + 20, rsdp_table + 20, 16);
88 break;
89 default:
90 g_assert_not_reached();
91 }
92
93 ACPI_ASSERT_CMP64(*((uint64_t *)(rsdp_table)), "RSD PTR ");
3248f1b4 94}