Home | History | Annotate | Line # | Download | only in mips64el
efibind.h revision 1.1
      1  1.1  jmcneill /*	$NetBSD: efibind.h,v 1.1 2018/08/16 18:17:47 jmcneill Exp $	*/
      2  1.1  jmcneill 
      3  1.1  jmcneill /*
      4  1.1  jmcneill  * Copright (C) 2014 - 2015 Linaro Ltd.
      5  1.1  jmcneill  * Author: Ard Biesheuvel <ard.biesheuvel (at) linaro.org>
      6  1.1  jmcneill  * Copright (C) 2017 Lemote Co.
      7  1.1  jmcneill  * Author: Heiher <r (at) hev.cc>
      8  1.1  jmcneill  *
      9  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
     10  1.1  jmcneill  * modification, are permitted provided that the following conditions
     11  1.1  jmcneill  * are met:
     12  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     13  1.1  jmcneill  *    notice and this list of conditions, without modification.
     14  1.1  jmcneill  * 2. The name of the author may not be used to endorse or promote products
     15  1.1  jmcneill  *    derived from this software without specific prior written permission.
     16  1.1  jmcneill  *
     17  1.1  jmcneill  * Alternatively, this software may be distributed under the terms of the
     18  1.1  jmcneill  * GNU General Public License as published by the Free Software Foundation;
     19  1.1  jmcneill  * either version 2 of the License, or (at your option) any later version.
     20  1.1  jmcneill  */
     21  1.1  jmcneill 
     22  1.1  jmcneill #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
     23  1.1  jmcneill 
     24  1.1  jmcneill // ANSI C 1999/2000 stdint.h integer width declarations
     25  1.1  jmcneill 
     26  1.1  jmcneill typedef unsigned long       uint64_t;
     27  1.1  jmcneill typedef long                int64_t;
     28  1.1  jmcneill typedef unsigned int        uint32_t;
     29  1.1  jmcneill typedef int                 int32_t;
     30  1.1  jmcneill typedef unsigned short      uint16_t;
     31  1.1  jmcneill typedef short               int16_t;
     32  1.1  jmcneill typedef unsigned char       uint8_t;
     33  1.1  jmcneill typedef signed char         int8_t;   // unqualified 'char' is unsigned on ARM
     34  1.1  jmcneill 
     35  1.1  jmcneill #else
     36  1.1  jmcneill #include <stdint.h>
     37  1.1  jmcneill #endif
     38  1.1  jmcneill 
     39  1.1  jmcneill //
     40  1.1  jmcneill // Basic EFI types of various widths
     41  1.1  jmcneill //
     42  1.1  jmcneill 
     43  1.1  jmcneill #ifndef __WCHAR_TYPE__
     44  1.1  jmcneill # define __WCHAR_TYPE__ short
     45  1.1  jmcneill #endif
     46  1.1  jmcneill 
     47  1.1  jmcneill typedef uint64_t   UINT64;
     48  1.1  jmcneill typedef int64_t    INT64;
     49  1.1  jmcneill 
     50  1.1  jmcneill typedef uint32_t   UINT32;
     51  1.1  jmcneill typedef int32_t    INT32;
     52  1.1  jmcneill 
     53  1.1  jmcneill typedef uint16_t   UINT16;
     54  1.1  jmcneill typedef int16_t    INT16;
     55  1.1  jmcneill typedef uint8_t    UINT8;
     56  1.1  jmcneill typedef int8_t     INT8;
     57  1.1  jmcneill typedef __WCHAR_TYPE__ WCHAR;
     58  1.1  jmcneill 
     59  1.1  jmcneill #undef VOID
     60  1.1  jmcneill #define VOID    void
     61  1.1  jmcneill 
     62  1.1  jmcneill typedef int64_t    INTN;
     63  1.1  jmcneill typedef uint64_t   UINTN;
     64  1.1  jmcneill 
     65  1.1  jmcneill #define EFIERR(a)           (0x8000000000000000 | a)
     66  1.1  jmcneill #define EFI_ERROR_MASK      0x8000000000000000
     67  1.1  jmcneill #define EFIERR_OEM(a)       (0xc000000000000000 | a)
     68  1.1  jmcneill 
     69  1.1  jmcneill #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
     70  1.1  jmcneill #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
     71  1.1  jmcneill 
     72  1.1  jmcneill #define BREAKPOINT()        while (TRUE);    // Make it hang on Bios[Dbg]32
     73  1.1  jmcneill 
     74  1.1  jmcneill //
     75  1.1  jmcneill // Pointers must be aligned to these address to function
     76  1.1  jmcneill //
     77  1.1  jmcneill 
     78  1.1  jmcneill #define MIN_ALIGNMENT_SIZE  8
     79  1.1  jmcneill 
     80  1.1  jmcneill #define ALIGN_VARIABLE(Value ,Adjustment) \
     81  1.1  jmcneill             (UINTN)Adjustment = 0; \
     82  1.1  jmcneill             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
     83  1.1  jmcneill                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
     84  1.1  jmcneill             Value = (UINTN)Value + (UINTN)Adjustment
     85  1.1  jmcneill 
     86  1.1  jmcneill 
     87  1.1  jmcneill //
     88  1.1  jmcneill // Define macros to build data structure signatures from characters.
     89  1.1  jmcneill //
     90  1.1  jmcneill 
     91  1.1  jmcneill #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
     92  1.1  jmcneill #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
     93  1.1  jmcneill #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))
     94  1.1  jmcneill 
     95  1.1  jmcneill //
     96  1.1  jmcneill // EFIAPI - prototype calling convention for EFI function pointers
     97  1.1  jmcneill // BOOTSERVICE - prototype for implementation of a boot service interface
     98  1.1  jmcneill // RUNTIMESERVICE - prototype for implementation of a runtime service interface
     99  1.1  jmcneill // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
    100  1.1  jmcneill // RUNTIME_CODE - pragma macro for declaring runtime code
    101  1.1  jmcneill //
    102  1.1  jmcneill 
    103  1.1  jmcneill #ifndef EFIAPI          // Forces EFI calling conventions reguardless of compiler options
    104  1.1  jmcneill #define EFIAPI          // Substitute expresion to force C calling convention
    105  1.1  jmcneill #endif
    106  1.1  jmcneill 
    107  1.1  jmcneill #define BOOTSERVICE
    108  1.1  jmcneill #define RUNTIMESERVICE
    109  1.1  jmcneill #define RUNTIMEFUNCTION
    110  1.1  jmcneill 
    111  1.1  jmcneill 
    112  1.1  jmcneill #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
    113  1.1  jmcneill #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
    114  1.1  jmcneill #define END_RUNTIME_DATA()      data_seg("")
    115  1.1  jmcneill 
    116  1.1  jmcneill #define VOLATILE                volatile
    117  1.1  jmcneill 
    118  1.1  jmcneill #define MEMORY_FENCE            __sync_synchronize
    119  1.1  jmcneill 
    120  1.1  jmcneill //
    121  1.1  jmcneill // When build similiar to FW, then link everything together as
    122  1.1  jmcneill // one big module.
    123  1.1  jmcneill //
    124  1.1  jmcneill 
    125  1.1  jmcneill #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
    126  1.1  jmcneill     UINTN                                       \
    127  1.1  jmcneill     InitializeDriver (                          \
    128  1.1  jmcneill         VOID    *ImageHandle,                   \
    129  1.1  jmcneill         VOID    *SystemTable                    \
    130  1.1  jmcneill         )                                       \
    131  1.1  jmcneill     {                                           \
    132  1.1  jmcneill         return InitFunction(ImageHandle,        \
    133  1.1  jmcneill                 SystemTable);                   \
    134  1.1  jmcneill     }                                           \
    135  1.1  jmcneill                                                 \
    136  1.1  jmcneill     EFI_STATUS efi_main(                        \
    137  1.1  jmcneill         EFI_HANDLE image,                       \
    138  1.1  jmcneill         EFI_SYSTEM_TABLE *systab                \
    139  1.1  jmcneill         ) __attribute__((weak,                  \
    140  1.1  jmcneill                 alias ("InitializeDriver")));
    141  1.1  jmcneill 
    142  1.1  jmcneill #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
    143  1.1  jmcneill         (_if)->LoadInternal(type, name, entry)
    144  1.1  jmcneill 
    145  1.1  jmcneill 
    146  1.1  jmcneill //
    147  1.1  jmcneill // Some compilers don't support the forward reference construct:
    148  1.1  jmcneill //  typedef struct XXXXX
    149  1.1  jmcneill //
    150  1.1  jmcneill // The following macro provide a workaround for such cases.
    151  1.1  jmcneill 
    152  1.1  jmcneill #define INTERFACE_DECL(x) struct x
    153  1.1  jmcneill 
    154  1.1  jmcneill #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
    155  1.1  jmcneill #define EFI_FUNCTION
    156  1.1  jmcneill 
    157  1.1  jmcneill static inline UINT64 swap_uint64 (UINT64 v)
    158  1.1  jmcneill {
    159  1.1  jmcneill 	asm volatile (
    160  1.1  jmcneill 		"dsbh	%[v], %[v] \n\t"
    161  1.1  jmcneill 		"dshd	%[v], %[v] \n\t"
    162  1.1  jmcneill 		:[v]"+r"(v)
    163  1.1  jmcneill 	);
    164  1.1  jmcneill 
    165  1.1  jmcneill 	return v;
    166  1.1  jmcneill }
    167