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

Commit

Permalink
Move CLIC parameterization constants to its header
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Clark committed Sep 1, 2018
1 parent d13a3d7 commit 5da132f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
29 changes: 17 additions & 12 deletions hw/riscv/sifive_clic.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ static const bool debug = false;
static void intcfg_decode(SiFiveCLICState *clic, int hartid, int intcfg,
int *mode, int *level, int *priority)
{
int nmbits = clic->nmbits[hartid], nmshift = 8 - nmbits;
int nlbits = clic->nlbits[hartid], nlshift = 8 - nmbits - nlbits;
int npbits = clic->npbits[hartid], npshift = 8 - nmbits - nlbits - npbits;
int nmbits = clic->nmbits[hartid];
int nlbits = clic->nlbits[hartid];
int npbits = clic->npbits[hartid];
int nmshift = SIFIVE_CLIC_MAX_INT_BITS - nmbits;
int nlshift = SIFIVE_CLIC_MAX_INT_BITS - nmbits - nlbits;
int npshift = SIFIVE_CLIC_MAX_INT_BITS - nmbits - nlbits - npbits;
int decoded_mode = (intcfg >> nmshift) & ((1 << nmbits) - 1);
int decoded_level = (intcfg >> nlshift) & ((1 << nlbits) - 1);
int decoded_priority = (intcfg >> npshift) & ((1 << npbits) - 1);
Expand All @@ -55,12 +58,12 @@ static void intcfg_decode(SiFiveCLICState *clic, int hartid, int intcfg,
}

/* unused level bits are set to 1 */
*level = decoded_level << (SIFIVE_CLIC_LEVEL_BITS - nlbits) |
((1 << (SIFIVE_CLIC_LEVEL_BITS - nlbits)) - 1);
*level = decoded_level << (SIFIVE_CLIC_MAX_LEVEL_BITS - nlbits) |
((1 << (SIFIVE_CLIC_MAX_LEVEL_BITS - nlbits)) - 1);

/* unused priority bits are set to 1 */
*priority = decoded_priority << (SIFIVE_CLIC_PRIORITY_BITS - nlbits) |
((1 << (SIFIVE_CLIC_PRIORITY_BITS - npbits)) - 1);
*priority = decoded_priority << (SIFIVE_CLIC_MAX_PRIORITY_BITS - nlbits) |
((1 << (SIFIVE_CLIC_MAX_PRIORITY_BITS - npbits)) - 1);
}

static void sifive_clic_next_interrupt(SiFiveCLICState *clic, int hartid)
Expand Down Expand Up @@ -779,11 +782,13 @@ DeviceState *sifive_clic_create(hwaddr addr, hwaddr size,
{
int i;

assert(num_sources >= 4 && num_sources <= 1024);
assert(int_bits >= 2 && int_bits <= 8);
assert(mode_bits <= 2);
assert(level_bits <= 8);
assert(vec_bits <= 1);
assert(num_sources >= SIFIVE_CLIC_MIN_SOURCES);
assert(num_sources <= SIFIVE_CLIC_MAX_SOURCES);
assert(int_bits >= SIFIVE_CLIC_MIN_INT_BITS);
assert(int_bits <= SIFIVE_CLIC_MAX_INT_BITS);
assert(mode_bits <= SIFIVE_CLIC_MAX_MODE_BITS);
assert(level_bits <= SIFIVE_CLIC_MAX_LEVEL_BITS);
assert(vec_bits <= SIFIVE_CLIC_MAX_VEC_BITS);

DeviceState *dev = qdev_create(NULL, TYPE_SIFIVE_CLIC);

Expand Down
10 changes: 8 additions & 2 deletions include/hw/riscv/sifive_clic.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ enum {
SIFIVE_CLIC_CLIC_MMODE_OFFSET = 0x800000,
SIFIVE_CLIC_CLIC_SMODE_OFFSET = 0xc00000,

SIFIVE_CLIC_PRIORITY_BITS = 8,
SIFIVE_CLIC_LEVEL_BITS = 8
SIFIVE_CLIC_MIN_SOURCES = 4,
SIFIVE_CLIC_MAX_SOURCES = 1024,
SIFIVE_CLIC_MIN_INT_BITS = 2,
SIFIVE_CLIC_MAX_INT_BITS = 8,
SIFIVE_CLIC_MAX_MODE_BITS = 8,
SIFIVE_CLIC_MAX_LEVEL_BITS = 8,
SIFIVE_CLIC_MAX_PRIORITY_BITS = 8,
SIFIVE_CLIC_MAX_VEC_BITS = 1
};

DeviceState *sifive_clic_create(hwaddr addr, hwaddr size,
Expand Down

0 comments on commit 5da132f

Please sign in to comment.