-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandover.h
159 lines (120 loc) · 3.78 KB
/
handover.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef HANDOVER_H_INCLUDED
#define HANDOVER_H_INCLUDED
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define HANDOVER_KERNEL_BASE 0xffffffff80000000
#define HANDOVER_UPPER_HALF 0xffff800000000000
#define HANDOVER_COOLBOOT 0xc001b001
#define HANDOVER_SECTION ".handover"
#define HANDOVER_TAGS(TAG) \
TAG(FREE, 0x00000000) \
TAG(MAGIC, HANDOVER_COOLBOOT) \
TAG(SELF, 0xa24f988d) \
TAG(STACK, 0xf65b391b) \
TAG(KERNEL, 0xbfc71b20) \
TAG(LOADER, 0xf1f80c26) \
TAG(FILE, 0xcbc36d3b) \
TAG(RSDP, 0x8ef29c18) \
TAG(FDT, 0xb628bbc1) \
TAG(FB, 0xe2d55685) \
TAG(CMDLINE, 0x435140c4) \
TAG(RESERVED, 0xb8841d2d) \
TAG(END, 0xffffffff)
typedef enum
{
#define TAG(NAME, VALUE) HANDOVER_##NAME = VALUE,
HANDOVER_TAGS(TAG)
#undef TAG
} HandoverTag;
typedef struct
{
uint32_t tag;
uint32_t flags;
uint64_t start;
uint64_t size;
union
{
struct
{
uint16_t width;
uint16_t height;
uint16_t pitch;
#define HANDOVER_RGBX8888 0x7451
#define HANDOVER_BGRX8888 0xd040
uint16_t format;
} fb;
struct
{
uint32_t name;
uint32_t meta;
} file;
uint64_t more;
};
} HandoverRecord;
typedef struct
{
uint32_t magic, agent, size, count;
HandoverRecord records[];
} HandoverPayload;
typedef struct
{
uint32_t tag;
uint32_t flags;
uint64_t more;
} HandoverRequest;
typedef void HandoverEntry(
uint64_t magic,
HandoverPayload const *payload);
/* --- Header Utilities ----------------------------------------------------- */
#ifdef HANDOVER_INCLUDE_MACROS
# define HANDOVER_REQ_START \
{ \
.tag = HANDOVER_MAGIC \
}
# define HANDOVER_REQ_END \
{ \
.tag = HANDOVER_END \
}
# define WITH_FB \
{ \
.tag = HANDOVER_FB \
}
# define WITH_ACPI \
{ \
.tag = HANDOVER_RSDP \
}
# define WITH_FDT \
{ \
.tag = HANDOVER_FDT \
}
# define WITH_FILES \
{ \
.tag = HANDOVER_FILE \
}
# define WITH_CMDLINE \
{ \
.tag = HANDOVER_CMDLINE \
}
# define HANDOVER(...) \
__attribute__((section(HANDOVER_SECTION), \
used)) static HandoverRequest handover_header[] = { \
{.tag = HANDOVER_MAGIC}, \
__VA_ARGS__ __VA_OPT__(, ){.tag = HANDOVER_END}, \
};
#endif
/* --- Utilities ------------------------------------------------------------ */
#ifdef HANDOVER_INCLUDE_UTILITES
char const *handover_tag_name(HandoverTag tag);
bool handover_mergeable(uint32_t tag);
bool handover_overlap(HandoverRecord lhs, HandoverRecord rhs);
bool handover_just_before(HandoverRecord lhs, HandoverRecord rhs);
bool handover_just_after(HandoverRecord lhs, HandoverRecord rhs);
HandoverRecord handover_half_under(HandoverRecord self, HandoverRecord other);
HandoverRecord handover_half_over(HandoverRecord self, HandoverRecord other);
void handover_insert(HandoverPayload *payload, size_t index, HandoverRecord record);
void handover_remove(HandoverPayload *payload, size_t index);
void handover_append(HandoverPayload *payload, HandoverRecord record);
char const *handover_str(HandoverPayload const *payload, uint32_t offset);
#endif
#endif