plic.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2006-2025 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-05-20 bigmagic first version
  9. * 2021-10-20 bernard fix s-mode issue
  10. * 2025-01-26 ZhangJing Porting to ultrarisc cp100
  11. */
  12. #ifndef __PLIC_H__
  13. #define __PLIC_H__
  14. #include <rtconfig.h>
  15. #include <rthw.h>
  16. #define PLIC_PRIORITY_BASE 0x0
  17. #define PLIC_PENDING_BASE 0x1000
  18. #define PLIC_ENABLE_BASE 0x2000
  19. #define PLIC_CONTEXT_BASE 0x200000
  20. extern size_t plic_base;
  21. #define PLIC_BASE (plic_base)
  22. #define PLIC_PRIORITY_OFFSET (0x0)
  23. #define PLIC_PENDING_OFFSET (0x1000)
  24. #define PLIC_ENABLE_STRIDE 0x80
  25. #define PLIC_CONTEXT_STRIDE 0x1000
  26. #define RISCV_S_MODE
  27. #ifndef RISCV_S_MODE
  28. /*using context 0*/
  29. #define PLIC_MENABLE_OFFSET (0x2000)
  30. #define PLIC_MTHRESHOLD_OFFSET (0x200000)
  31. #define PLIC_MCLAIM_OFFSET (0x200004)
  32. #define PLIC_MCOMPLETE_OFFSET (0x200004)
  33. #define PLIC_ENABLE(hart) (PLIC_BASE + PLIC_MENABLE_OFFSET + (hart * 3) * PLIC_ENABLE_STRIDE)
  34. #define PLIC_THRESHOLD(hart) (PLIC_BASE + PLIC_MTHRESHOLD_OFFSET + (hart * 3) * PLIC_CONTEXT_STRIDE)
  35. #define PLIC_CLAIM(hart) (PLIC_BASE + PLIC_MCLAIM_OFFSET + (hart * 3) * PLIC_CONTEXT_STRIDE)
  36. #define PLIC_COMPLETE(hart) (PLIC_BASE + PLIC_MCOMPLETE_OFFSET + (hart * 3) * PLIC_CONTEXT_STRIDE)
  37. #else
  38. /*using context 1*/
  39. #define PLIC_SENABLE_OFFSET (0x2000 + PLIC_ENABLE_STRIDE)
  40. #define PLIC_STHRESHOLD_OFFSET (0x200000 + PLIC_CONTEXT_STRIDE)
  41. #define PLIC_SCLAIM_OFFSET (0x200004 + PLIC_CONTEXT_STRIDE)
  42. #define PLIC_SCOMPLETE_OFFSET (0x200004 + PLIC_CONTEXT_STRIDE)
  43. #define PLIC_ENABLE(hart) (PLIC_BASE + PLIC_SENABLE_OFFSET + (hart * 3) * PLIC_ENABLE_STRIDE)
  44. #define PLIC_THRESHOLD(hart) (PLIC_BASE + PLIC_STHRESHOLD_OFFSET + (hart * 3) * PLIC_CONTEXT_STRIDE)
  45. #define PLIC_CLAIM(hart) (PLIC_BASE + PLIC_SCLAIM_OFFSET + (hart * 3) * PLIC_CONTEXT_STRIDE)
  46. #define PLIC_COMPLETE(hart) (PLIC_BASE + PLIC_SCOMPLETE_OFFSET + (hart * 3) * PLIC_CONTEXT_STRIDE)
  47. #endif
  48. #define PLIC_PRIORITY(id) (PLIC_BASE + PLIC_PRIORITY_OFFSET + (id) * 4)
  49. #define PLIC_PENDING(id) (PLIC_BASE + PLIC_PENDING_OFFSET + ((id) / 32))
  50. #define WORD_CNT_BYTE (1024 / 8)
  51. #define CONFIG_IRQ_NR (32)
  52. #define CONFIG_IRQ_WORD (CONFIG_IRQ_NR / 32)
  53. void plic_set_priority(int irq, int priority);
  54. void plic_irq_enable(int irq);
  55. void plic_irq_disable(int irq);
  56. void plic_set_threshold(int mthreshold);
  57. rt_uint32_t plic_claim(void);
  58. void plic_complete(int irq);
  59. void plic_set_thresh(rt_uint32_t val);
  60. void plic_set_ie(rt_uint32_t word_index, rt_uint32_t val);
  61. void plic_init();
  62. void plic_handle_irq(void);
  63. #endif