xref: /netbsd-src/sys/external/bsd/gnu-efi/dist/inc/riscv64/efibind.h (revision be2c2428c95e24cf364d0fba606edb6654190a0f)
1 /*	$NetBSD: efibind.h,v 1.2 2021/09/30 19:09:10 jmcneill Exp $	*/
2 
3 /*
4  * Copright (C) 2014 - 2015 Linaro Ltd.
5  * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice and this list of conditions, without modification.
12  * 2. The name of the author may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission.
14  *
15  * Alternatively, this software may be distributed under the terms of the
16  * GNU General Public License as published by the Free Software Foundation;
17  * either version 2 of the License, or (at your option) any later version.
18  */
19 
20 #if defined(__NetBSD__)
21 #include <sys/stdint.h>
22 #else
23 #include <stdint.h>
24 #endif
25 
26 //
27 // Basic EFI types of various widths
28 //
29 
30 
31 
32 typedef uint64_t                UINT64;
33 typedef int64_t                 INT64;
34 typedef uint32_t                UINT32;
35 typedef int32_t                 INT32;
36 typedef uint16_t                UINT16;
37 typedef int16_t                 INT16;
38 typedef uint8_t                 UINT8;
39 typedef int8_t                  INT8;
40 #ifndef __WCHAR_TYPE__
41 #define __WCHAR_TYPE__          short
42 #endif
43 typedef __WCHAR_TYPE__          WCHAR;
44 #ifndef BOOLEAN
45 typedef uint8_t                 BOOLEAN;
46 #endif
47 #undef VOID
48 #define VOID                    void
49 typedef int64_t                 INTN;
50 typedef uint64_t                UINTN;
51 
52 #define EFI_ERROR_MASK          0x8000000000000000
53 #define EFIERR(a)               (EFI_ERROR_MASK | a)
54 #define EFIERR_OEM(a)           (0xc000000000000000 | a)
55 
56 #define BAD_POINTER             0xFBFBFBFBFBFBFBFB
57 #define MAX_ADDRESS             0xFFFFFFFFFFFFFFFF
58 
59 #define BREAKPOINT()            while(1);
60 
61 //
62 // Pointers must be aligned to these address to function
63 //
64 #define MIN_ALIGNMENT_SIZE      8
65 
66 #define ALIGN_VARIABLE(Value, Adjustment) \
67    (UINTN)Adjustment = 0; \
68    if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
69        (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
70    Value = (UINTN)Value + (UINTN)Adjustment
71 
72 //
73 // Define macros to build data structure signatures from characters.
74 //
75 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
76 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
77 #define EFI_SIGNATURE_64(A,B,C,D,E,F,G,H) (EFI_SIGNATURE_32(A,B,C,D) | ((UINT64)(EFI_SIGNATURE_32(E,F,G,H)) << 32))
78 
79 //
80 // EFIAPI - prototype calling convention for EFI function pointers
81 // BOOTSERVICE - prototype for implementation of a boot service interface
82 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
83 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
84 // RUNTIME_CODE - pragma macro for declaring runtime code
85 //
86 #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
87 #define EFIAPI                  // Substitute expresion to force C calling convention
88 #endif
89 #define BOOTSERVICE
90 #define RUNTIMESERVICE
91 #define RUNTIMEFUNCTION
92 #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
93 #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
94 #define END_RUNTIME_DATA()      data_seg("")
95 
96 #define VOLATILE                volatile
97 #define MEMORY_FENCE            __sync_synchronize
98 
99 //
100 // When build similiar to FW, then link everything together as
101 // one big module. For the MSVC toolchain, we simply tell the
102 // linker what our driver init function is using /ENTRY.
103 //
104 #if defined(_MSC_EXTENSIONS)
105 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
106     __pragma(comment(linker, "/ENTRY:" # InitFunction))
107 #else
108 #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
109     UINTN                                       \
110     InitializeDriver (                          \
111         VOID    *ImageHandle,                   \
112         VOID    *SystemTable                    \
113         )                                       \
114     {                                           \
115         return InitFunction(ImageHandle,        \
116                 SystemTable);                   \
117     }                                           \
118                                                 \
119     EFI_STATUS efi_main(                        \
120         EFI_HANDLE image,                       \
121         EFI_SYSTEM_TABLE *systab                \
122         ) __attribute__((weak,                  \
123                 alias ("InitializeDriver")));
124 #endif
125 
126 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
127    (_if)->LoadInternal(type, name, entry)
128 
129 //
130 // Some compilers don't support the forward reference construct:
131 //  typedef struct XXXXX
132 //
133 // The following macro provide a workaround for such cases.
134 #define INTERFACE_DECL(x)       struct x
135 
136 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
137 #define EFI_FUNCTION
138