Fix high interrupt ISRs
[viridis.git] / kernel / platforms / efi / efi.h
1 /* vim: set ts=4 sw=4 sts=4 et : */
2
3 #pragma once
4
5 /* Memory types and attributes straight from the spec */
6
7 typedef enum {
8         EfiReservedMemoryType,
9         EfiLoaderCode,
10         EfiLoaderData,
11         EfiBootServicesCode,
12         EfiBootServicesData,
13         EfiRuntimeServicesCode,
14         EfiRuntimeServicesData,
15         EfiConventionalMemory,
16         EfiUnusableMemory,
17         EfiACPIReclaimMemory,
18         EfiACPIMemoryNVS,
19         EfiMemoryMappedIO,
20         EfiMemoryMappedIOPortSpace,
21         EfiPalCode,
22         EfiPersistentMemory,
23         EfiMaxMemoryType
24 } EFI_MEMORY_TYPE;
25
26 #define EFI_MEMORY_UC                           0x0000000000000001
27 #define EFI_MEMORY_WC                           0x0000000000000002
28 #define EFI_MEMORY_WT                           0x0000000000000004
29 #define EFI_MEMORY_WB                           0x0000000000000008
30 #define EFI_MEMORY_UCE                          0x0000000000000010
31 #define EFI_MEMORY_WP                           0x0000000000001000
32 #define EFI_MEMORY_RP                           0x0000000000002000
33 #define EFI_MEMORY_XP                           0x0000000000004000
34 #define EFI_MEMORY_NV                           0x0000000000008000
35 #define EFI_MEMORY_MORE_RELIABLE    0x0000000000010000
36 #define EFI_MEMORY_RO                           0x0000000000020000
37 #define EFI_MEMORY_RUNTIME                      0x8000000000000000
38
39 struct efi_mem_desc {
40     u32 type;
41     u64 phys;
42     u64 virt;
43     u64 num_pages;
44     u64 attributes;
45 };
46
47 /* Almost everything in this file is standard EFI, but this corresponds to
48  * pointers we gave to GetMemoryMap back in efi.asm */
49
50 struct efi_mem_hdr {
51     u64 map_size;
52     u64 map_key;
53     u64 descriptor_size;
54     u32 descriptor_version;
55     struct efi_mem_desc map[];
56 };
57
58 struct efi_table_header {
59     u64 signature;
60     u32 revision;
61     u32 header_size;
62     u32 crc32;
63     u32 reserved;
64 };
65
66 struct efi_runtime_services {
67     struct efi_table_header header;
68     void *get_time;
69     void *set_time;
70     void *get_wakeup_time;
71     void *set_wakeup_time;
72     void *set_virtual_address_map;
73     void *convert_pointer;
74     void *get_variable;
75     void *get_next_variable_name;
76     void *set_variable;
77 };
78
79 union efi_guid {
80     struct {
81         u32 a;
82         u16 b;
83         u16 c;
84         u8 d[8];
85     } guid;
86     struct {
87         u64 hi;
88         u64 lo;
89     } data;
90 } __attribute__((packed));
91
92 struct efi_configuration_table {
93     union efi_guid guid;
94     void *table;
95 };
96
97 struct efi_sys_table {
98     struct efi_table_header header;
99     u16 *fw_vendor;
100     u32 fw_revision;
101     u64 console_in_handle;
102     u64 *con_in;
103     u64 console_out_handle;
104     void *con_out;
105     u64 console_err_handle;
106     void *con_err;
107     struct efi_runtime_services *runtime_services;
108     void *boot_services;
109     u64 num_entries;
110     struct efi_configuration_table *configuration_table;
111 };
112
113 typedef enum {
114     PixelRedGreenBlueReserved8BitPerColor,
115     PixelBlueGreenRedReserved8BitPerColor,
116     PixelBitMask,
117     PixelBltOnly,
118     PixelFormatMax
119 } EFI_GRAPHICS_PIXEL_FORMAT;
120
121 struct efi_gop_info {
122         u32 version;
123         u32 h_res;
124         u32 v_res;
125         EFI_GRAPHICS_PIXEL_FORMAT pixel_format;
126         u64 pixel_bitmask[2];
127         u32 pixels_per_scanline;
128 };
129
130 struct efi_gop_mode {
131         u32 max_mode;
132         u32 mode;
133         struct efi_gop_info *info;
134         u64 info_size;
135         u64     fb_phys;
136         u64 fb_size;
137 };
138
139 extern int efi_call(void *func_ptr, int pad, ...);
140
141 #define EFI_CALL(f, ...) efi_call(f, 0, __VA_ARGS__)
142
143 static inline int efi_guid_equal(union efi_guid *a, union efi_guid *b)
144 {
145     return ((a->data.hi == b->data.hi)&&(a->data.lo == b->data.lo));
146 }