-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(intr, aia): update xtopi and use xtopi to update intr deleg
* NEMU could get xtopei csr register to update xtopi by difftest * add m/s/vsiprio struct and add init iprio method * add update xtopi method to update interrupt deleg when intr raise * add xtopei, xtopi, xireg csr registers read/write
- Loading branch information
1 parent
fe45f57
commit 3d3534a
Showing
9 changed files
with
497 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifdef CONFIG_RV_IMSIC | ||
|
||
#ifndef __AIA_H__ | ||
#define __AIA_H__ | ||
|
||
#include "common.h" | ||
#include "csr.h" | ||
#include "intr.h" | ||
|
||
#define IPRIO_ENABLE_NUM (CONFIG_INTR_NUM - 3) | ||
|
||
typedef struct { | ||
word_t val; | ||
} Iprio; | ||
|
||
typedef struct IpriosModule { | ||
Iprio iprios[CONFIG_IPRIO_NUM]; | ||
} IpriosModule; | ||
|
||
typedef struct { | ||
bool enable; | ||
uint8_t priority; | ||
} IpriosEnable; | ||
|
||
typedef struct IpriosSort { | ||
IpriosEnable ipriosEnable[IPRIO_ENABLE_NUM]; | ||
} IpriosSort; | ||
|
||
bool iprio_is_zero(IpriosModule* iprios); | ||
void set_iprios_sort(uint64_t topi_gather, IpriosSort* iprios_sort, IpriosModule* iprios); | ||
void set_viprios_sort(uint64_t topi_gather); | ||
uint8_t high_iprio(IpriosSort* ipriosSort, uint8_t xei); | ||
uint8_t get_prio_idx_in_group(uint8_t irq); | ||
|
||
extern int interrupt_default_prio[IPRIO_ENABLE_NUM]; | ||
|
||
#endif // __AIA_H__ | ||
#endif // CONFIG_RV_IMSIC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#include "isa.h" | ||
#include "cpu/cpu.h" | ||
#include "../local-include/aia.h" | ||
|
||
#ifdef CONFIG_RV_IMSIC | ||
|
||
int interrupt_default_prio[IPRIO_ENABLE_NUM] = { | ||
// custom highest group | ||
63, 31, 62, | ||
61, 30, 60, | ||
// local high group | ||
47, 23, 46, | ||
45, 22, 44, | ||
43, 21, 42, | ||
41, 20, 40, | ||
// custom middle high group | ||
59, 29, 58, | ||
57, 28, 56, | ||
// priv arch group | ||
IRQ_MEIP, IRQ_MSIP, IRQ_MTIP, | ||
IRQ_SEIP, IRQ_SSIP, IRQ_STIP, | ||
IRQ_SGEI, | ||
IRQ_VSEIP, IRQ_VSSIP, IRQ_VSTIP, | ||
IRQ_LCOFI, 14, 15, | ||
// custom middle low group | ||
55, 27, 54, | ||
53, 26, 52, | ||
// local low group | ||
39, 19, 38, | ||
37, 18, 36, | ||
35, 17, 34, | ||
33, 16, 32, | ||
// custom lowest group | ||
51, 25, 50, | ||
49, 24, 48 | ||
}; | ||
|
||
bool iprio_is_zero(IpriosModule* iprios) { | ||
bool is_zero = true; | ||
for (int i = 0; i < CONFIG_IPRIO_NUM; i++) { | ||
is_zero &= iprios->iprios[i].val == 0; | ||
} | ||
return is_zero; | ||
} | ||
|
||
uint8_t get_prio_idx_in_group(uint8_t irq) { | ||
uint8_t idx = 0; | ||
for (int i = 0; i < IPRIO_ENABLE_NUM; i++) { | ||
if (irq == interrupt_default_prio[i]) { | ||
idx = i; | ||
} | ||
} | ||
return idx; | ||
} | ||
|
||
void set_iprios_sort(uint64_t topi_gather, IpriosSort* iprios_sort, IpriosModule* iprios) { | ||
for (int i = 0; i < IPRIO_ENABLE_NUM; i++) { | ||
if ((topi_gather >> interrupt_default_prio[i]) & 0x1) { | ||
iprios_sort->ipriosEnable[i].enable = true; | ||
iprios_sort->ipriosEnable[i].priority = (iprios->iprios[interrupt_default_prio[i]/8].val >> (8 * (interrupt_default_prio[i]%8))) & 0xff; | ||
} else { | ||
iprios_sort->ipriosEnable[i].enable = false; | ||
iprios_sort->ipriosEnable[i].priority = 0; | ||
} | ||
} | ||
} | ||
|
||
void set_viprios_sort(uint64_t topi_gather) { | ||
// supervisor software interrupt | ||
word_t idx = 0; | ||
if ((topi_gather >> IRQ_SSIP) & 0x1) { | ||
idx = get_prio_idx_in_group(IRQ_SSIP); | ||
cpu.VSIpriosSort->ipriosEnable[idx].enable = true; | ||
cpu.VSIpriosSort->ipriosEnable[idx].priority = hviprio1->ssi; | ||
} | ||
// supervisor timer interrupt | ||
if ((topi_gather >> IRQ_STIP) & 0x1) { | ||
idx = get_prio_idx_in_group(IRQ_STIP); | ||
cpu.VSIpriosSort->ipriosEnable[idx].enable = true; | ||
cpu.VSIpriosSort->ipriosEnable[idx].priority = hviprio1->sti; | ||
} | ||
// counter overflow interrupt | ||
if ((topi_gather >> IRQ_LCOFI) & 0x1) { | ||
idx = get_prio_idx_in_group(IRQ_LCOFI); | ||
cpu.VSIpriosSort->ipriosEnable[idx].enable = true; | ||
cpu.VSIpriosSort->ipriosEnable[idx].priority = hviprio1->coi; | ||
} | ||
for (int i = 0; i <= 1; i++) { | ||
if ((topi_gather >> (i+14)) & 0x1) { | ||
idx = get_prio_idx_in_group(i+14); | ||
cpu.VSIpriosSort->ipriosEnable[idx].enable = true; | ||
cpu.VSIpriosSort->ipriosEnable[idx].priority = hviprio1->val & (0xf << 8*(i+6)); | ||
} | ||
} | ||
for (int i = 0; i <= 7; i++) { | ||
if ((topi_gather >> (i+16)) & 0x1) { | ||
idx = get_prio_idx_in_group(i+16); | ||
cpu.VSIpriosSort->ipriosEnable[idx].enable = true; | ||
cpu.VSIpriosSort->ipriosEnable[idx].priority = hviprio2->val & (0xf << 8*i); | ||
} | ||
} | ||
} | ||
|
||
uint8_t high_iprio(IpriosSort* ipriosSort, uint8_t xei) { | ||
uint8_t high_prio_idx = 0; | ||
for (int i = 0; i < IPRIO_ENABLE_NUM; i++) { | ||
if (ipriosSort->ipriosEnable[i].enable && !ipriosSort->ipriosEnable[i+1].enable) { | ||
high_prio_idx = i; | ||
} else if (!ipriosSort->ipriosEnable[i].enable && ipriosSort->ipriosEnable[i+1].enable) { | ||
high_prio_idx = i + 1; | ||
} else if (ipriosSort->ipriosEnable[i].enable && ipriosSort->ipriosEnable[i+1].enable) { | ||
if ((ipriosSort->ipriosEnable[i].priority == 0) && (ipriosSort->ipriosEnable[i+1].priority == 0)) { | ||
high_prio_idx = i; | ||
} else if ((ipriosSort->ipriosEnable[i].priority == 0) && (ipriosSort->ipriosEnable[i+1].priority != 0)) { | ||
if (i <= get_prio_idx_in_group(xei)) { | ||
high_prio_idx = i; | ||
} else { | ||
high_prio_idx = i + 1; | ||
} | ||
} else if ((ipriosSort->ipriosEnable[i].priority != 0) && (ipriosSort->ipriosEnable[i+1].priority == 0)) { | ||
if (i + 1 <= get_prio_idx_in_group(xei)) { | ||
high_prio_idx = i + 1; | ||
} else { | ||
high_prio_idx = i; | ||
} | ||
} else if ((ipriosSort->ipriosEnable[i].priority != 0) && (ipriosSort->ipriosEnable[i+1].priority != 0)) { | ||
if (ipriosSort->ipriosEnable[i].priority <= ipriosSort->ipriosEnable[i+1].priority) { | ||
high_prio_idx = i; | ||
} else { | ||
high_prio_idx = i + 1; | ||
} | ||
} | ||
} | ||
} | ||
return high_prio_idx; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.