1/**
2 * \file
3 * \brief init user-space domain special structures.
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2009, 2010, 2012, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef BARRELFISH_KPI_INIT_H
16#define BARRELFISH_KPI_INIT_H
17
18#include <stdbool.h>
19
20/**
21 * Size of bootinfo mapping.
22 */
23#define BOOTINFO_SIZEBITS       (BASE_PAGE_BITS + 2)
24#define BOOTINFO_SIZE           (1UL << BOOTINFO_SIZEBITS)
25
26/**
27 * Address (in spawned domain) of page with command-line arguments and environment
28 */
29#define ARGS_FRAME_BITS    17 // 128 kB
30#define ARGS_SIZE          ((genpaddr_t)1 << ARGS_FRAME_BITS)
31#define MAX_CMDLINE_ARGS   128
32#define MAX_ENVIRON_VARS   128
33
34/**
35 * Size of page with inherited file descriptors
36 */
37#define FDS_SIZE          (32 * 1024)  // estimate worst case here.
38
39
40/**
41 * Size of dispatcher frame
42 */
43#define DISPATCHER_SIZE         ((genpaddr_t)1 << DISPATCHER_FRAME_BITS)
44
45/**
46 * Size of initial page to carry out monitor URPC
47 */
48// Supports at least #MON_URPC_CHANNEL_LEN
49// Change #MON_URPC_CHANNEL_LEN if changing this
50#define MON_URPC_SIZE           (2 * BASE_PAGE_SIZE)
51
52/**
53
54 * Maximum possible number of entries in the memory regions array. This is
55 * limited by the page size minus the size of the initial part of the bootinfo
56 * structure.
57 */
58#define MAX_MEM_REGIONS         ((BOOTINFO_SIZE - sizeof(struct bootinfo)) / \
59                                 sizeof(struct mem_region))
60
61/* Root CNode */
62#define ROOTCN_SLOT_TASKCN       0   ///< Taskcn slot in root cnode
63#define ROOTCN_SLOT_PAGECN       1   ///< Pagecn slot in root cnode
64#define ROOTCN_SLOT_BASE_PAGE_CN 2   ///< Slot for a cnode of BASE_PAGE_SIZE frames
65#define ROOTCN_SLOT_SUPERCN      3   ///< Slot for a cnode of SUPER frames
66#define ROOTCN_SLOT_SEGCN        4   ///< SegCN slot in root cnode
67#define ROOTCN_SLOT_PACN         5   ///< PhysAddr cnode slot in root cnode
68#define ROOTCN_SLOT_MODULECN     6   ///< Multiboot modules cnode slot in root cnode
69#define ROOTCN_SLOT_SLOT_ALLOC0  7   ///< Root of slot alloc0
70#define ROOTCN_SLOT_SLOT_ALLOC1  8   ///< Root of slot alloc1
71#define ROOTCN_SLOT_SLOT_ALLOC2  9   ///< Root of slot alloc2
72#define ROOTCN_SLOT_ARGCN        10  ///< Argcn slot in root cnode
73#define ROOTCN_SLOT_BSPKCB       11  ///< BSP KCB cap to fix reverse lookup issues
74#define ROOTCN_SLOTS_USER        12  ///< First free slot in root cnode for user
75
76/* Size of CNodes in Root CNode if not the default size */
77#define SLOT_ALLOC_CNODE_BITS   L2_CNODE_BITS
78#define SLOT_ALLOC_CNODE_SLOTS  L2_CNODE_SLOTS
79
80/* Task CNode */
81#define TASKCN_SLOT_TASKCN      0   ///< Task CNode in itself (XXX)
82#define TASKCN_SLOT_DISPATCHER  1   ///< Dispatcher cap in task cnode
83#define TASKCN_SLOT_ROOTCN      2   ///< RootCN slot in task cnode
84#define TASKCN_SLOT_DISPFRAME   4   ///< Dispatcher frame cap in task cnode
85#define TASKCN_SLOT_IRQ         5   ///< IRQ cap in task cnode
86#define TASKCN_SLOT_IO          6   ///< IO cap in task cnode
87#define TASKCN_SLOT_BOOTINFO    7   ///< Bootinfo frame slot in task cnode
88#define TASKCN_SLOT_KERNELCAP   8   ///< Kernel cap in task cnode
89#define TASKCN_SLOT_TRACEBUF    9   ///< Trace buffer cap in task cnode
90#define TASKCN_SLOT_ARGSPAGE    10  ///< ?
91#define TASKCN_SLOT_MON_URPC    11  ///< Frame cap for urpc comm.
92#define TASKCN_SLOT_SESSIONID   12  ///< Session ID domain belongs to
93#define TASKCN_SLOT_FDSPAGE     13  ///< cap for inherited file descriptors
94#define TASKCN_SLOT_PERF_MON    14  ///< cap for performance monitoring
95#define TASKCN_SLOT_SYSMEM      15  ///< ???
96#define TASKCN_SLOT_COREBOOT    16  ///< Copy of realmode section used to bootstrap a core
97#define TASKCN_SLOT_IPI         17  ///< Copy of IPI cap
98#define TASKCN_SLOT_PROC_MNG    18  ///< Cap for the process manager
99#define TASKCN_SLOT_DOMAINID    19  ///< Domain ID cap
100#define TASKCN_SLOTS_USER       20  ///< First free slot in taskcn for user
101
102/* Page CNode */
103#define PAGECN_SLOT_VROOT       0 ///< First slot of page cnode is root page table
104
105#define ROOTCN_SLOT_LEVEL       CSPACE_LEVEL_L1
106#define ROOTCN_SLOT_ADDR(slot)  ((slot) << L2_CNODE_BITS)
107
108// Cspace addresses for well-defined L2 CNodes
109#define CPTR_TASKCN_BASE        ROOTCN_SLOT_ADDR(ROOTCN_SLOT_TASKCN)
110#define CPTR_BASE_PAGE_CN_BASE  ROOTCN_SLOT_ADDR(ROOTCN_SLOT_BASE_PAGE_CN)
111#define CPTR_SUPERCN_BASE       ROOTCN_SLOT_ADDR(ROOTCN_SLOT_SUPERCN)
112#define CPTR_PHYADDRCN_BASE     ROOTCN_SLOT_ADDR(ROOTCN_SLOT_PACN)
113#define CPTR_MODULECN_BASE      ROOTCN_SLOT_ADDR(ROOTCN_SLOT_MODULECN)
114#define CPTR_PAGECN_BASE        ROOTCN_SLOT_ADDR(ROOTCN_SLOT_PAGECN)
115
116/**
117 * Memory region types.
118 */
119enum region_type {
120    /// Empty memory: describes a RAM cap in supercn
121    RegionType_Empty,
122    /// Code/Data of init itself: describes a Frame cap in segcn
123    RegionType_RootTask,
124    /// Physical address range (not RAM): describes a PhysAddr cap in physaddrcn
125    RegionType_PhyAddr,
126    /// BIOS tables and platform-specific data: describes a PhysAddr cap in physaddrcn
127    RegionType_PlatformData,
128    /// Multiboot module: describes multiple Frame caps in modulecn
129    RegionType_Module,
130    ///< describes memory region that is an ACPI table
131    RegionType_ACPI_TABLE,
132    RegionType_Max ///< Must be last
133};
134
135/**
136 * A memory region.
137 */
138struct mem_region {
139    genpaddr_t       mr_base;///< Address of the start of the region
140    enum region_type mr_type;///< Type of region
141    gensize_t        mr_bytes;///< Size in bytes
142    bool             mr_consumed;///< Flag for user code to mark region consumed
143    size_t           mrmod_size;///< Size in bytes (module type only)
144    ptrdiff_t        mrmod_data;///< Offset of module string (module type only)
145    int              mrmod_slot;///< First slot containing caps (module only)
146};
147
148/**
149 * This structure holds essential information for the init process to
150 * allocate and manage its address space.
151 */
152struct bootinfo {
153    /// For __k1om__
154    uint64_t host_msg;
155    uint8_t host_msg_bits;
156
157    /// Number of entries in regions array
158    size_t              regions_length;
159    /// Amount of memory required to spawn another core
160    size_t              mem_spawn_core;
161    /// Memory regions array
162    struct mem_region   regions[];
163};
164
165#endif
166