]>
git.proxmox.com Git - mirror_qemu.git/blob - tests/acpi-utils.c
2 * ACPI Utility Functions
4 * Copyright (c) 2013 Red Hat Inc.
5 * Copyright (c) 2017 Skyport Systems
8 * Michael S. Tsirkin <mst@redhat.com>,
9 * Ben Warren <ben@skyportsystems.com>
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.
15 #include "qemu/osdep.h"
16 #include <glib/gstdio.h>
17 #include "qemu-common.h"
18 #include "qemu/bitmap.h"
19 #include "acpi-utils.h"
20 #include "boot-sector.h"
22 uint8_t acpi_calc_checksum(const uint8_t *data
, int len
)
27 for (i
= 0; i
< len
; i
++) {
34 uint32_t acpi_find_rsdp_address(QTestState
*qts
)
38 /* RSDP location can vary across a narrow range */
39 for (off
= 0xf0000; off
< 0x100000; off
+= 0x10) {
40 uint8_t sig
[] = "RSD PTR ";
43 for (i
= 0; i
< sizeof sig
- 1; ++i
) {
44 sig
[i
] = qtest_readb(qts
, off
+ i
);
47 if (!memcmp(sig
, "RSD PTR ", sizeof sig
)) {
54 void acpi_fetch_rsdp_table(QTestState
*qts
, uint64_t addr
, uint8_t *rsdp_table
)
58 /* Read mandatory revision 0 table data (20 bytes) first */
59 qtest_memread(qts
, addr
, rsdp_table
, 20);
60 revision
= rsdp_table
[15 /* Revision offset */];
63 case 0: /* ACPI 1.0 RSDP */
65 case 2: /* ACPI 2.0+ RSDP */
66 /* Read the rest of the RSDP table */
67 qtest_memread(qts
, addr
+ 20, rsdp_table
+ 20, 16);
70 g_assert_not_reached();
73 ACPI_ASSERT_CMP64(*((uint64_t *)(rsdp_table
)), "RSD PTR ");
77 * load ACPI table at @addr_ptr offset pointer into buffer and return it in
78 * @aml, its length in @aml_len and check that signature/checksum matches
81 void acpi_fetch_table(QTestState
*qts
, uint8_t **aml
, uint32_t *aml_len
,
82 const uint8_t *addr_ptr
, int addr_size
, const char *sig
,
88 g_assert(addr_size
== 4 || addr_size
== 8);
89 memcpy(&addr
, addr_ptr
, addr_size
);
90 addr
= le64_to_cpu(addr
);
91 qtest_memread(qts
, addr
+ 4, &len
, 4); /* Length of ACPI table */
92 *aml_len
= le32_to_cpu(len
);
93 *aml
= g_malloc0(*aml_len
);
95 qtest_memread(qts
, addr
, *aml
, *aml_len
);
98 ACPI_ASSERT_CMP(**aml
, sig
);
100 if (verify_checksum
) {
101 g_assert(!acpi_calc_checksum(*aml
, *aml_len
));