From 5da132f38ddca3076bc197d84cee18e6e7b77353 Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Sat, 1 Sep 2018 13:17:16 +1200 Subject: [PATCH] Move CLIC parameterization constants to its header --- hw/riscv/sifive_clic.c | 29 +++++++++++++++++------------ include/hw/riscv/sifive_clic.h | 10 ++++++++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/hw/riscv/sifive_clic.c b/hw/riscv/sifive_clic.c index 04e7a1aa1c2..f7638b237b0 100644 --- a/hw/riscv/sifive_clic.c +++ b/hw/riscv/sifive_clic.c @@ -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); @@ -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) @@ -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); diff --git a/include/hw/riscv/sifive_clic.h b/include/hw/riscv/sifive_clic.h index 5c4a473672f..ce5ad22a684 100644 --- a/include/hw/riscv/sifive_clic.h +++ b/include/hw/riscv/sifive_clic.h @@ -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,