libfdt: add acpi table verification support
am: e433acb347
Change-Id: I778d39a3e44559418484f7197c620d9f0b16c9b2
This commit is contained in:
commit
8df5f5b1e0
4 changed files with 124 additions and 1 deletions
|
@ -17,6 +17,7 @@ cc_library_static {
|
|||
"fdt_empty_tree.c",
|
||||
"fdt_addresses.c",
|
||||
"fdt_overlay.c",
|
||||
"acpi.c",
|
||||
],
|
||||
export_include_dirs: ["."],
|
||||
}
|
||||
|
|
|
@ -7,5 +7,5 @@ LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
|
|||
LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h
|
||||
LIBFDT_VERSION = version.lds
|
||||
LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \
|
||||
fdt_addresses.c fdt_overlay.c
|
||||
fdt_addresses.c fdt_overlay.c acpi.c
|
||||
LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
|
||||
|
|
48
libfdt/acpi.c
Normal file
48
libfdt/acpi.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libacpi.h"
|
||||
|
||||
uint8_t acpi_csum(const void *base, int n) {
|
||||
uint8_t *p;
|
||||
uint8_t sum;
|
||||
int bytesDone;
|
||||
|
||||
p = (uint8_t*)base;
|
||||
|
||||
sum = 0;
|
||||
for (bytesDone = 0; bytesDone < n; bytesDone++) {
|
||||
sum += *p;
|
||||
p++;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
74
libfdt/libacpi.h
Normal file
74
libfdt/libacpi.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _LIBACPI_H
|
||||
#define _LIBACPI_H
|
||||
|
||||
#include "libfdt.h"
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
uint32_t Signature; /* ASCII Table identifier */
|
||||
uint32_t Length; /* Length of the table, including the header */
|
||||
uint8_t Revision; /* Revision of the structure */
|
||||
uint8_t Checksum; /* Sum of all fields must be 0 */
|
||||
uint8_t OemId[6]; /* ASCII OEM identifier */
|
||||
uint64_t OemTableId; /* ASCII OEM table identifier */
|
||||
uint32_t OemRevision; /* OEM supplied revision number */
|
||||
uint32_t CreatorId; /* Vendor ID of utility creator of the table */
|
||||
uint32_t CreatorRevision; /* Revision of utility creator of the table */
|
||||
} EFI_ACPI_DESCRIPTION_HEADER;
|
||||
#pragma pack()
|
||||
|
||||
/**********************************************************************/
|
||||
/* General functions */
|
||||
/**********************************************************************/
|
||||
#define acpi_get_header(acpi, field) \
|
||||
((const EFI_ACPI_DESCRIPTION_HEADER *)(acpi))->field
|
||||
#define acpi_signature(acpi) (acpi_get_header(acpi, Signature))
|
||||
#define acpi_length(acpi) (acpi_get_header(acpi, Length))
|
||||
|
||||
/* convert 2 bytes ASCII to uint16 */
|
||||
#define SIGNATURE_16(A, B) ((A) | (B << 8))
|
||||
/* convert 4 bytes ASCII to uint32 */
|
||||
#define SIGNATURE_32(A, B, C, D) ((SIGNATURE_16 (A, B)) | (SIGNATURE_16 (C, D) << 16))
|
||||
/* convert 8 bytes ASCII to uint64 */
|
||||
#define SIGNATURE_64(A, B, C, D, E, F, G, H) \
|
||||
(SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32))
|
||||
|
||||
#define SSDT_MAGIC (const unsigned)SIGNATURE_32('S', 'S', 'D', 'T')
|
||||
#define DSDT_MAGIC (const unsigned)SIGNATURE_32('D', 'S', 'D', 'T')
|
||||
|
||||
#define ACPI_TABLE_MAGIC 0x41435049
|
||||
|
||||
/* checksum byte by byte for acpi table */
|
||||
uint8_t acpi_csum(const void *base, int n);
|
||||
|
||||
#endif /* ifndef _LIBACPI_H */
|
Loading…
Reference in a new issue