sbi_types.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #ifndef __SBI_TYPES_H__
  10. #define __SBI_TYPES_H__
  11. #ifndef OPENSBI_EXTERNAL_SBI_TYPES
  12. /* clang-format off */
  13. typedef char s8;
  14. typedef unsigned char u8;
  15. typedef unsigned char uint8_t;
  16. typedef short s16;
  17. typedef unsigned short u16;
  18. typedef short int16_t;
  19. typedef unsigned short uint16_t;
  20. typedef int s32;
  21. typedef unsigned int u32;
  22. typedef int int32_t;
  23. typedef unsigned int uint32_t;
  24. #if __riscv_xlen == 64
  25. typedef long s64;
  26. typedef unsigned long u64;
  27. typedef long int64_t;
  28. typedef unsigned long uint64_t;
  29. #define PRILX "016lx"
  30. #elif __riscv_xlen == 32
  31. typedef long long s64;
  32. typedef unsigned long long u64;
  33. typedef long long int64_t;
  34. typedef unsigned long long uint64_t;
  35. #define PRILX "08lx"
  36. #else
  37. #error "Unexpected __riscv_xlen"
  38. #endif
  39. typedef int bool;
  40. typedef unsigned long ulong;
  41. typedef unsigned long uintptr_t;
  42. typedef unsigned long size_t;
  43. typedef long ssize_t;
  44. typedef unsigned long virtual_addr_t;
  45. typedef unsigned long virtual_size_t;
  46. typedef unsigned long physical_addr_t;
  47. typedef unsigned long physical_size_t;
  48. #define TRUE 1
  49. #define FALSE 0
  50. #define NULL ((void *)0)
  51. #define __packed __attribute__((packed))
  52. #define __noreturn __attribute__((noreturn))
  53. #define likely(x) __builtin_expect((x), 1)
  54. #define unlikely(x) __builtin_expect((x), 0)
  55. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  56. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  57. #define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)
  58. #define STR(x) XSTR(x)
  59. #define XSTR(x) #x
  60. #define ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b))
  61. #define ROUNDDOWN(a, b) ((a) / (b) * (b))
  62. /* clang-format on */
  63. #else
  64. /* OPENSBI_EXTERNAL_SBI_TYPES could be defined in CFLAGS for using the
  65. * external definitions of data types and common macros.
  66. * OPENSBI_EXTERNAL_SBI_TYPES is the file name to external header file,
  67. * the external build system should address the additional include
  68. * directory ccordingly.
  69. */
  70. #define XSTR(x) #x
  71. #define STR(x) XSTR(x)
  72. #include STR(OPENSBI_EXTERNAL_SBI_TYPES)
  73. #endif
  74. #endif