sbi_scratch.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_SCRATCH_H__
  10. #define __SBI_SCRATCH_H__
  11. #include <sbi/riscv_asm.h>
  12. /* clang-format off */
  13. /** Offset of fw_start member in sbi_scratch */
  14. #define SBI_SCRATCH_FW_START_OFFSET (0 * __SIZEOF_POINTER__)
  15. /** Offset of fw_size member in sbi_scratch */
  16. #define SBI_SCRATCH_FW_SIZE_OFFSET (1 * __SIZEOF_POINTER__)
  17. /** Offset of next_arg1 member in sbi_scratch */
  18. #define SBI_SCRATCH_NEXT_ARG1_OFFSET (2 * __SIZEOF_POINTER__)
  19. /** Offset of next_addr member in sbi_scratch */
  20. #define SBI_SCRATCH_NEXT_ADDR_OFFSET (3 * __SIZEOF_POINTER__)
  21. /** Offset of next_mode member in sbi_scratch */
  22. #define SBI_SCRATCH_NEXT_MODE_OFFSET (4 * __SIZEOF_POINTER__)
  23. /** Offset of warmboot_addr member in sbi_scratch */
  24. #define SBI_SCRATCH_WARMBOOT_ADDR_OFFSET (5 * __SIZEOF_POINTER__)
  25. /** Offset of platform_addr member in sbi_scratch */
  26. #define SBI_SCRATCH_PLATFORM_ADDR_OFFSET (6 * __SIZEOF_POINTER__)
  27. /** Offset of hartid_to_scratch member in sbi_scratch */
  28. #define SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET (7 * __SIZEOF_POINTER__)
  29. /** Offset of tmp0 member in sbi_scratch */
  30. #define SBI_SCRATCH_TMP0_OFFSET (8 * __SIZEOF_POINTER__)
  31. /** Offset of options member in sbi_scratch */
  32. #define SBI_SCRATCH_OPTIONS_OFFSET (9 * __SIZEOF_POINTER__)
  33. /** sbi_ipi_data is located behind sbi_scratch. This struct is not packed. */
  34. /** Offset of ipi_type in sbi_ipi_data */
  35. #define SBI_IPI_DATA_IPI_TYPE_OFFSET (15 * __SIZEOF_POINTER__)
  36. #define SBI_SCRATCH_TLB_QUEUE_HEAD_OFFSET (16 * __SIZEOF_POINTER__)
  37. #define SBI_SCRATCH_TLB_QUEUE_MEM_OFFSET (SBI_SCRATCH_TLB_QUEUE_HEAD_OFFSET + SBI_TLB_INFO_SIZE)
  38. /** Maximum size of sbi_scratch and sbi_ipi_data */
  39. #define SBI_SCRATCH_SIZE (64 * __SIZEOF_POINTER__)
  40. /* clang-format on */
  41. #ifndef __ASSEMBLY__
  42. #include <sbi/sbi_types.h>
  43. #include <sbi/sbi_ipi.h>
  44. /** Representation of per-HART scratch space */
  45. struct sbi_scratch {
  46. /** Start (or base) address of firmware linked to OpenSBI library */
  47. unsigned long fw_start;
  48. /** Size (in bytes) of firmware linked to OpenSBI library */
  49. unsigned long fw_size;
  50. /** Arg1 (or 'a1' register) of next booting stage for this HART */
  51. unsigned long next_arg1;
  52. /** Address of next booting stage for this HART */
  53. unsigned long next_addr;
  54. /** Priviledge mode of next booting stage for this HART */
  55. unsigned long next_mode;
  56. /** Warm boot entry point address for this HART */
  57. unsigned long warmboot_addr;
  58. /** Address of sbi_platform */
  59. unsigned long platform_addr;
  60. /** Address of HART ID to sbi_scratch conversion function */
  61. unsigned long hartid_to_scratch;
  62. /** Temporary storage */
  63. unsigned long tmp0;
  64. /** Options for OpenSBI library */
  65. unsigned long options;
  66. } __packed;
  67. /** Possible options for OpenSBI library */
  68. enum sbi_scratch_options {
  69. /** Disable prints during boot */
  70. SBI_SCRATCH_NO_BOOT_PRINTS = (1 << 0),
  71. };
  72. /** Get pointer to sbi_scratch for current HART */
  73. #define sbi_scratch_thishart_ptr() \
  74. ((struct sbi_scratch *)csr_read(CSR_MSCRATCH))
  75. /** Get Arg1 of next booting stage for current HART */
  76. #define sbi_scratch_thishart_arg1_ptr() \
  77. ((void *)(sbi_scratch_thishart_ptr()->next_arg1))
  78. /** Get pointer to sbi_ipi_data from sbi_scratch */
  79. #define sbi_ipi_data_ptr(scratch) \
  80. ((struct sbi_ipi_data *)(void *)scratch + SBI_IPI_DATA_IPI_TYPE_OFFSET)
  81. /** Get pointer to tlb flush info fifo header from sbi_scratch */
  82. #define sbi_tlb_fifo_head_ptr(scratch) \
  83. ((struct sbi_fifo *)(void *)scratch + SBI_SCRATCH_TLB_QUEUE_HEAD_OFFSET)
  84. /** Get pointer to tlb flush info fifo queue address from sbi_scratch */
  85. #define sbi_tlb_fifo_mem_ptr(scratch) \
  86. (void *)((void *)scratch + SBI_SCRATCH_TLB_QUEUE_MEM_OFFSET)
  87. #endif
  88. #endif