blob: 3be18986fcc73dcb2900b6c44f3450e09a91b832 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001From 03a886252f6555d6b0af76b654e76459642b89da Mon Sep 17 00:00:00 2001
2From: Yunguo Wei <yunguo.wei@windriver.com>
3Date: Tue, 3 Dec 2013 18:12:50 +0800
4Subject: [PATCH] pmtools: switch to dynamic buffer for huge ACPI tables
5
6For servers like Canoe Pass or Thunder Ridge, there are much more
7entries in ACPI table, so original 1K buffer is insufficient.
8
9We switch to dynamic buffer on this situation.
10
11Signed-off-by: Yunguo Wei <yunguo.wei@windriver.com>
12
13
14Upstream-Status: Pending
15
16Signed-off-by: Kai Kang <kai.kang@windriver.com>
17---
18 madt/madt.c | 18 +++++++++++++++++-
19 1 file changed, 17 insertions(+), 1 deletion(-)
20
Patrick Williamsb48b7b42016-08-17 15:04:38 -050021--- a/madt/madt.c
22+++ b/madt/madt.c
Andrew Geissler87f5cff2022-09-30 13:13:31 -050023@@ -34,14 +34,16 @@ typedef unsigned long long u64;
24 //#include <sys/mman.h>
25 #include <stdio.h> // fread
26 #include <stdlib.h> // malloc
27+#include <string.h> // memset/memcpy
28
29 #include "./tables.c"
30
31 int verbose = 0;
32 /*
33-/* read standard input
34+ * read standard input
35 * write decoded madt to standard output
36 */
37+size_t
38 get_next_entry(acpi_table_entry_header * entry_header)
39 {
40 size_t retval;
41@@ -51,9 +53,11 @@ get_next_entry(acpi_table_entry_header *
Patrick Williamsb48b7b42016-08-17 15:04:38 -050042 return retval;
43 }
44
45-u8 buffer[1024];
Andrew Geissler87f5cff2022-09-30 13:13:31 -050046
47-main()
Patrick Williamsb48b7b42016-08-17 15:04:38 -050048+u8 buf[1024];
49+u8 *buffer = buf;
Andrew Geissler87f5cff2022-09-30 13:13:31 -050050+int
51+main(int argc, char *argv[])
Patrick Williamsb48b7b42016-08-17 15:04:38 -050052 {
Andrew Geissler87f5cff2022-09-30 13:13:31 -050053 size_t retval;
54 struct acpi_table_madt *madt_header;
55@@ -75,6 +79,17 @@ main()
Patrick Williamsb48b7b42016-08-17 15:04:38 -050056
57 if (verbose) printf("header.length %d\n", madt_header->header.length);
58
59+ /* if 1K buffer is insufficient for acpi table, switch to a larger memory buffer */
60+ if(expected_length > sizeof(buf)) {
61+ buffer = malloc(expected_length);
62+ if (!buffer) {
63+ perror("malloc");
64+ exit(1);
65+ }
66+ memset(buffer, 0, expected_length);
67+ memcpy(buffer, buf, sizeof(struct acpi_table_madt));
68+ }
69+
70 acpi_table_print((void*)&(buffer[bytes_read]), 0);
71
72 bytes_read = sizeof(struct acpi_table_madt);
Andrew Geissler87f5cff2022-09-30 13:13:31 -050073@@ -118,6 +133,9 @@ done:
Patrick Williamsb48b7b42016-08-17 15:04:38 -050074 printf("Checksum 0x%x != 0; 0x%x in header ERROR\n", csum,
75 madt_header->header.checksum);
76
77+ if(buffer != buf)
78+ free(buffer);
79+
80 return 0;
81 }
82