Skip to content
This repository was archived by the owner on Apr 13, 2019. It is now read-only.

Commit 5da132f

Browse files
author
Michael Clark
committed
Move CLIC parameterization constants to its header
1 parent d13a3d7 commit 5da132f

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

hw/riscv/sifive_clic.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ static const bool debug = false;
3535
static void intcfg_decode(SiFiveCLICState *clic, int hartid, int intcfg,
3636
int *mode, int *level, int *priority)
3737
{
38-
int nmbits = clic->nmbits[hartid], nmshift = 8 - nmbits;
39-
int nlbits = clic->nlbits[hartid], nlshift = 8 - nmbits - nlbits;
40-
int npbits = clic->npbits[hartid], npshift = 8 - nmbits - nlbits - npbits;
38+
int nmbits = clic->nmbits[hartid];
39+
int nlbits = clic->nlbits[hartid];
40+
int npbits = clic->npbits[hartid];
41+
int nmshift = SIFIVE_CLIC_MAX_INT_BITS - nmbits;
42+
int nlshift = SIFIVE_CLIC_MAX_INT_BITS - nmbits - nlbits;
43+
int npshift = SIFIVE_CLIC_MAX_INT_BITS - nmbits - nlbits - npbits;
4144
int decoded_mode = (intcfg >> nmshift) & ((1 << nmbits) - 1);
4245
int decoded_level = (intcfg >> nlshift) & ((1 << nlbits) - 1);
4346
int decoded_priority = (intcfg >> npshift) & ((1 << npbits) - 1);
@@ -55,12 +58,12 @@ static void intcfg_decode(SiFiveCLICState *clic, int hartid, int intcfg,
5558
}
5659

5760
/* unused level bits are set to 1 */
58-
*level = decoded_level << (SIFIVE_CLIC_LEVEL_BITS - nlbits) |
59-
((1 << (SIFIVE_CLIC_LEVEL_BITS - nlbits)) - 1);
61+
*level = decoded_level << (SIFIVE_CLIC_MAX_LEVEL_BITS - nlbits) |
62+
((1 << (SIFIVE_CLIC_MAX_LEVEL_BITS - nlbits)) - 1);
6063

6164
/* unused priority bits are set to 1 */
62-
*priority = decoded_priority << (SIFIVE_CLIC_PRIORITY_BITS - nlbits) |
63-
((1 << (SIFIVE_CLIC_PRIORITY_BITS - npbits)) - 1);
65+
*priority = decoded_priority << (SIFIVE_CLIC_MAX_PRIORITY_BITS - nlbits) |
66+
((1 << (SIFIVE_CLIC_MAX_PRIORITY_BITS - npbits)) - 1);
6467
}
6568

6669
static void sifive_clic_next_interrupt(SiFiveCLICState *clic, int hartid)
@@ -779,11 +782,13 @@ DeviceState *sifive_clic_create(hwaddr addr, hwaddr size,
779782
{
780783
int i;
781784

782-
assert(num_sources >= 4 && num_sources <= 1024);
783-
assert(int_bits >= 2 && int_bits <= 8);
784-
assert(mode_bits <= 2);
785-
assert(level_bits <= 8);
786-
assert(vec_bits <= 1);
785+
assert(num_sources >= SIFIVE_CLIC_MIN_SOURCES);
786+
assert(num_sources <= SIFIVE_CLIC_MAX_SOURCES);
787+
assert(int_bits >= SIFIVE_CLIC_MIN_INT_BITS);
788+
assert(int_bits <= SIFIVE_CLIC_MAX_INT_BITS);
789+
assert(mode_bits <= SIFIVE_CLIC_MAX_MODE_BITS);
790+
assert(level_bits <= SIFIVE_CLIC_MAX_LEVEL_BITS);
791+
assert(vec_bits <= SIFIVE_CLIC_MAX_VEC_BITS);
787792

788793
DeviceState *dev = qdev_create(NULL, TYPE_SIFIVE_CLIC);
789794

include/hw/riscv/sifive_clic.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ enum {
9797
SIFIVE_CLIC_CLIC_MMODE_OFFSET = 0x800000,
9898
SIFIVE_CLIC_CLIC_SMODE_OFFSET = 0xc00000,
9999

100-
SIFIVE_CLIC_PRIORITY_BITS = 8,
101-
SIFIVE_CLIC_LEVEL_BITS = 8
100+
SIFIVE_CLIC_MIN_SOURCES = 4,
101+
SIFIVE_CLIC_MAX_SOURCES = 1024,
102+
SIFIVE_CLIC_MIN_INT_BITS = 2,
103+
SIFIVE_CLIC_MAX_INT_BITS = 8,
104+
SIFIVE_CLIC_MAX_MODE_BITS = 8,
105+
SIFIVE_CLIC_MAX_LEVEL_BITS = 8,
106+
SIFIVE_CLIC_MAX_PRIORITY_BITS = 8,
107+
SIFIVE_CLIC_MAX_VEC_BITS = 1
102108
};
103109

104110
DeviceState *sifive_clic_create(hwaddr addr, hwaddr size,

0 commit comments

Comments
 (0)