1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "dt_table.h"
18 
19 #include <memory.h>
20 
21 #include "libacpi.h"
22 #include "libfdt.h"
23 #include "libufdt_sysdeps.h"
24 
dt_table_header_init(struct dt_table_header * header,enum DT_TYPE dt_type)25 void dt_table_header_init(struct dt_table_header *header, enum DT_TYPE dt_type) {
26   const uint32_t header_size = sizeof(struct dt_table_header);
27   const uint32_t entry_size = sizeof(struct dt_table_entry);
28 
29   dto_memset(header, 0, header_size);
30   if (dt_type == ACPI)
31     header->magic = cpu_to_fdt32(ACPI_TABLE_MAGIC);
32   else
33     header->magic = cpu_to_fdt32(DT_TABLE_MAGIC);
34 
35   header->total_size = cpu_to_fdt32(header_size);
36   header->header_size = cpu_to_fdt32(header_size);
37   header->dt_entry_size = cpu_to_fdt32(entry_size);
38   header->dt_entries_offset = cpu_to_fdt32(header_size);
39   header->page_size = cpu_to_fdt32(DT_TABLE_DEFAULT_PAGE_SIZE);
40   header->version = cpu_to_fdt32(DT_TABLE_DEFAULT_VERSION);
41 }
42