14 #include "rv_plic_regs.h"
38 uint8_t register_index = (uint8_t)(irq / RV_PLIC_PARAM_REG_WIDTH);
39 return register_index *
sizeof(uint32_t);
51 return irq % RV_PLIC_PARAM_REG_WIDTH;
58 ptrdiff_t range = RV_PLIC_IE0_MULTIREG_COUNT *
sizeof(uint32_t);
59 return RV_PLIC_IE0_0_REG_OFFSET + (range * (ptrdiff_t)target);
65 static ptrdiff_t plic_software_irq_base_for_target(
67 return RV_PLIC_MSIP0_REG_OFFSET + (ptrdiff_t)(target *
sizeof(uint32_t));
74 return RV_PLIC_THRESHOLD0_REG_OFFSET + (ptrdiff_t)(target *
sizeof(uint32_t));
80 static ptrdiff_t plic_claim_complete_base_for_target(
82 return RV_PLIC_CC0_REG_OFFSET + (ptrdiff_t)(target *
sizeof(uint32_t));
90 ptrdiff_t offset = plic_offset_from_reg0(irq);
92 .offset = plic_irq_enable_base_for_target(target) + offset,
93 .bit_index = plic_irq_bit_index(irq),
101 ptrdiff_t offset = plic_offset_from_reg0(irq);
103 .offset = RV_PLIC_IP_0_REG_OFFSET + offset,
104 .bit_index = plic_irq_bit_index(irq),
115 ptrdiff_t offset = (ptrdiff_t)(irq *
sizeof(uint32_t));
116 return RV_PLIC_PRIO0_REG_OFFSET + offset;
125 for (uint32_t i = 0; i < RV_PLIC_PARAM_NUM_SRC; ++i) {
126 ptrdiff_t offset = plic_priority_reg_offset(i);
127 mmio_region_write32(plic->
base_addr, offset, 0);
134 ptrdiff_t offset = plic_irq_enable_base_for_target(target);
135 for (
size_t i = 0; i < RV_PLIC_IE0_MULTIREG_COUNT; ++i) {
136 ptrdiff_t multireg_offset = offset + (ptrdiff_t)(i *
sizeof(uint32_t));
137 mmio_region_write32(plic->
base_addr, multireg_offset, 0);
141 offset = plic_threshold_base_for_target(target);
142 mmio_region_write32(plic->
base_addr, offset, 0);
145 offset = plic_software_irq_base_for_target(target);
146 mmio_region_write32(plic->
base_addr, offset, 0);
156 if (plic == NULL || irq >= RV_PLIC_PARAM_NUM_SRC ||
157 target >= RV_PLIC_PARAM_NUM_TARGET) {
163 uint32_t reg = mmio_region_read32(plic->
base_addr, reg_info.offset);
174 if (plic == NULL || irq >= RV_PLIC_PARAM_NUM_SRC ||
175 target >= RV_PLIC_PARAM_NUM_TARGET) {
193 uint32_t reg = mmio_region_read32(plic->
base_addr, reg_info.offset);
195 mmio_region_write32(plic->
base_addr, reg_info.offset, reg);
203 if (plic == NULL || irq >= RV_PLIC_PARAM_NUM_SRC ||
208 ptrdiff_t offset = plic_priority_reg_offset(irq);
209 mmio_region_write32(plic->
base_addr, offset, priority);
216 uint32_t threshold) {
217 if (plic == NULL || target >= RV_PLIC_PARAM_NUM_TARGET ||
222 ptrdiff_t threshold_offset = plic_threshold_base_for_target(target);
223 mmio_region_write32(plic->
base_addr, threshold_offset, threshold);
231 if (plic == NULL || irq >= RV_PLIC_PARAM_NUM_SRC || is_pending == NULL) {
236 uint32_t reg = mmio_region_read32(plic->
base_addr, reg_info.offset);
245 if (plic == NULL || target >= RV_PLIC_PARAM_NUM_TARGET ||
246 claim_data == NULL) {
250 ptrdiff_t claim_complete_reg = plic_claim_complete_base_for_target(target);
251 *claim_data = mmio_region_read32(plic->
base_addr, claim_complete_reg);
259 if (plic == NULL || target >= RV_PLIC_PARAM_NUM_TARGET) {
265 ptrdiff_t claim_complete_reg = plic_claim_complete_base_for_target(target);
266 mmio_region_write32(plic->
base_addr, claim_complete_reg, complete_data);
273 if (plic == NULL || target >= RV_PLIC_PARAM_NUM_TARGET) {
277 ptrdiff_t msip_offset = plic_software_irq_base_for_target(target);
278 mmio_region_write32(plic->
base_addr, msip_offset, 1);
285 if (plic == NULL || target >= RV_PLIC_PARAM_NUM_TARGET) {
289 ptrdiff_t msip_offset = plic_software_irq_base_for_target(target);
290 mmio_region_write32(plic->
base_addr, msip_offset, 0);
298 if (plic == NULL || target >= RV_PLIC_PARAM_NUM_TARGET ||
299 is_pending == NULL) {
303 ptrdiff_t msip_offset = plic_software_irq_base_for_target(target);
304 uint32_t register_value = mmio_region_read32(plic->
base_addr, msip_offset);
306 *is_pending = (register_value == 1) ?
true :
false;