1/*
2 * Copyright (c) 2014, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#ifndef COREBOOT_H
11#define COREBOOT_H
12
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16#include <assert.h>
17#include <inttypes.h>
18
19#include <barrelfish/barrelfish.h>
20#include <barrelfish/spawn_client.h>
21#include <barrelfish_kpi/capabilities.h>
22#include <barrelfish_kpi/types.h>
23
24#include <elf/elf.h>
25#include <bench/bench.h>
26#include <vfs/vfs.h>
27#include <octopus/octopus.h>
28#include <octopus/capability_storage.h>
29#include <spawndomain/spawndomain.h>
30
31#include <if/monitor_defs.h>
32#include <if/intermon_defs.h>
33
34#if defined(__aarch64__) || (defined(__x86__) && !defined(__k1om__))
35#include <acpi_client/acpi_client.h>
36#include <if/acpi_defs.h>
37#endif
38
39
40#ifdef DEBUG_CPUBOOT
41#define DEBUG(x...) if (debug_flag) debug_printf(x)
42#else
43#define DEBUG(x...) ((void)0)
44#endif
45
46typedef coreid_t kcbid_t;
47
48// Globals
49extern bool benchmark_flag;
50extern bool debug_flag;
51extern bool new_kcb_flag;
52
53struct elf_allocate_state {
54    void *vbase;
55    genvaddr_t elfbase;
56};
57
58struct bench_data {
59    uint64_t load;
60    uint64_t alloc_cpu;
61    uint64_t alloc_mon;
62    uint64_t elf_load;
63    uint64_t elf_reloc;
64};
65struct bench_data *bench_data;
66
67// common.c
68void boot_core_reply(struct monitor_binding *st, errval_t msgerr);
69errval_t create_or_get_kcb_cap(coreid_t coreid, struct capref* kcb);
70errval_t give_kcb_to_new_core(coreid_t destination_id, struct capref new_kcb);
71errval_t frame_alloc_identify(struct capref *dest, size_t bytes,
72                              size_t *retbytes, struct frame_identity *id);
73errval_t lookup_module(const char *module_name, lvaddr_t *binary_virt,
74                       genpaddr_t *binary_phys, size_t *binary_size);
75errval_t cap_mark_remote(struct capref cap);
76errval_t elfload_allocate(void *state, genvaddr_t base,
77                          size_t size, uint32_t flags,
78                          void **retbase);
79char* get_binary_path(char* fmt, char* binary_name);
80
81
82// platform specific code {x86boot.c, armboot.c}
83errval_t get_architecture_config(enum cpu_type type,
84                                 genpaddr_t *arch_page_size,
85                                 const char **monitor_binary,
86                                 const char **cpu_binary);
87errval_t spawn_xcore_monitor(coreid_t coreid, hwid_t hwid,
88                             enum cpu_type cpu_type,
89                             const char *cmdline,
90                             struct frame_identity urpc_frame_id,
91                             struct capref kcb);
92errval_t get_core_info(coreid_t core_id, hwid_t* apic_id, enum cpu_type* cpu_type);
93errval_t invoke_monitor_cap_remote(capaddr_t cap, int bits, bool is_remote,
94                                   bool *has_descendents);
95
96
97#endif // COREBOOT_H
98