2021-05-21 17:03:30 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2021-05-20 bigmagic first version
|
2021-10-19 14:46:48 +08:00
|
|
|
* 2021-10-20 bernard fix s-mode issue
|
2021-05-21 17:03:30 +08:00
|
|
|
*/
|
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
#ifndef __PLIC_H__
|
|
|
|
#define __PLIC_H__
|
2021-05-21 17:03:30 +08:00
|
|
|
|
|
|
|
#include <rtconfig.h>
|
2022-12-03 12:07:44 +08:00
|
|
|
#include <rthw.h>
|
2021-10-19 14:46:48 +08:00
|
|
|
|
2022-12-10 22:16:42 +08:00
|
|
|
#define PLIC_PRIORITY_BASE 0x0
|
|
|
|
#define PLIC_PENDING_BASE 0x1000
|
|
|
|
#define PLIC_ENABLE_BASE 0x2000
|
|
|
|
#define PLIC_CONTEXT_BASE 0x200000
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2022-12-10 22:16:42 +08:00
|
|
|
extern size_t plic_base;
|
2022-12-03 12:07:44 +08:00
|
|
|
|
2022-12-10 22:16:42 +08:00
|
|
|
#define VIRT_PLIC_BASE (plic_base)
|
2021-10-19 14:46:48 +08:00
|
|
|
|
|
|
|
#define PLIC_PRIORITY_OFFSET (0x0)
|
|
|
|
#define PLIC_PENDING_OFFSET (0x1000)
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2021-10-19 14:46:48 +08:00
|
|
|
#define PLIC_ENABLE_STRIDE 0x80
|
|
|
|
#define PLIC_CONTEXT_STRIDE 0x1000
|
2021-05-21 17:03:30 +08:00
|
|
|
|
|
|
|
#ifndef RISCV_S_MODE
|
2021-10-19 14:46:48 +08:00
|
|
|
#define PLIC_MENABLE_OFFSET (0x2000)
|
|
|
|
#define PLIC_MTHRESHOLD_OFFSET (0x200000)
|
|
|
|
#define PLIC_MCLAIM_OFFSET (0x200004)
|
|
|
|
#define PLIC_MCOMPLETE_OFFSET (0x200004)
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2021-10-19 14:46:48 +08:00
|
|
|
#define PLIC_ENABLE(hart) (VIRT_PLIC_BASE + PLIC_MENABLE_OFFSET + (hart * 2) * PLIC_ENABLE_STRIDE)
|
|
|
|
#define PLIC_THRESHOLD(hart) (VIRT_PLIC_BASE + PLIC_MTHRESHOLD_OFFSET + (hart * 2) * PLIC_CONTEXT_STRIDE)
|
|
|
|
#define PLIC_CLAIM(hart) (VIRT_PLIC_BASE + PLIC_MCLAIM_OFFSET + (hart * 2) * PLIC_CONTEXT_STRIDE)
|
|
|
|
#define PLIC_COMPLETE(hart) (VIRT_PLIC_BASE + PLIC_MCOMPLETE_OFFSET + (hart * 2) * PLIC_CONTEXT_STRIDE)
|
2021-05-21 17:03:30 +08:00
|
|
|
|
|
|
|
#else
|
2021-10-19 14:46:48 +08:00
|
|
|
#define PLIC_SENABLE_OFFSET (0x2000 + PLIC_ENABLE_STRIDE)
|
|
|
|
#define PLIC_STHRESHOLD_OFFSET (0x200000 + PLIC_CONTEXT_STRIDE)
|
|
|
|
#define PLIC_SCLAIM_OFFSET (0x200004 + PLIC_CONTEXT_STRIDE)
|
|
|
|
#define PLIC_SCOMPLETE_OFFSET (0x200004 + PLIC_CONTEXT_STRIDE)
|
|
|
|
|
|
|
|
#define PLIC_ENABLE(hart) (VIRT_PLIC_BASE + PLIC_SENABLE_OFFSET + (hart * 2) * PLIC_ENABLE_STRIDE)
|
|
|
|
#define PLIC_THRESHOLD(hart) (VIRT_PLIC_BASE + PLIC_STHRESHOLD_OFFSET + (hart * 2) * PLIC_CONTEXT_STRIDE)
|
|
|
|
#define PLIC_CLAIM(hart) (VIRT_PLIC_BASE + PLIC_SCLAIM_OFFSET + (hart * 2) * PLIC_CONTEXT_STRIDE)
|
|
|
|
#define PLIC_COMPLETE(hart) (VIRT_PLIC_BASE + PLIC_SCOMPLETE_OFFSET + (hart * 2) * PLIC_CONTEXT_STRIDE)
|
2021-05-21 17:03:30 +08:00
|
|
|
#endif
|
|
|
|
|
2021-10-19 14:46:48 +08:00
|
|
|
#define PLIC_PRIORITY(id) (VIRT_PLIC_BASE + PLIC_PRIORITY_OFFSET + (id) * 4)
|
|
|
|
#define PLIC_PENDING(id) (VIRT_PLIC_BASE + PLIC_PENDING_OFFSET + ((id) / 32))
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2022-12-10 22:16:42 +08:00
|
|
|
#define WORD_CNT_BYTE (1024 / 8)
|
|
|
|
|
|
|
|
/* IRQ config in system, max 1024 (from 0 to 1023) */
|
|
|
|
#define CONFIG_IRQ_NR (128)
|
|
|
|
#define CONFIG_IRQ_WORD (CONFIG_IRQ_NR / 32)
|
|
|
|
|
2021-05-21 17:03:30 +08:00
|
|
|
void plic_set_priority(int irq, int priority);
|
|
|
|
void plic_irq_enable(int irq);
|
|
|
|
void plic_irq_disable(int irq);
|
|
|
|
void plic_set_threshold(int mthreshold);
|
|
|
|
int plic_claim(void);
|
|
|
|
void plic_complete(int irq);
|
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
void plic_set_thresh(rt_uint32_t val);
|
|
|
|
void plic_set_ie(rt_uint32_t word_index,rt_uint32_t val);
|
|
|
|
void plic_init();
|
|
|
|
|
2021-05-21 17:03:30 +08:00
|
|
|
#endif
|