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