register: fix incorrect read mask
The register_read() and register_write() functions expect a bitmask argument. To avoid duplicated code, a new inlined function register_enabled_mask() is introduced. Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
parent
6048018ef6
commit
4729b3a41d
@ -59,6 +59,15 @@ static inline uint64_t register_read_val(RegisterInfo *reg)
|
|||||||
return 0; /* unreachable */
|
return 0; /* unreachable */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline uint64_t register_enabled_mask(int data_size, unsigned size)
|
||||||
|
{
|
||||||
|
if (data_size < size) {
|
||||||
|
size = data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MAKE_64BIT_MASK(0, size * 8);
|
||||||
|
}
|
||||||
|
|
||||||
void register_write(RegisterInfo *reg, uint64_t val, uint64_t we,
|
void register_write(RegisterInfo *reg, uint64_t val, uint64_t we,
|
||||||
const char *prefix, bool debug)
|
const char *prefix, bool debug)
|
||||||
{
|
{
|
||||||
@ -192,11 +201,7 @@ void register_write_memory(void *opaque, hwaddr addr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate appropriate write enable mask */
|
/* Generate appropriate write enable mask */
|
||||||
if (reg->data_size < size) {
|
we = register_enabled_mask(reg->data_size, size);
|
||||||
we = MAKE_64BIT_MASK(0, reg->data_size * 8);
|
|
||||||
} else {
|
|
||||||
we = MAKE_64BIT_MASK(0, size * 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
register_write(reg, value, we, reg_array->prefix,
|
register_write(reg, value, we, reg_array->prefix,
|
||||||
reg_array->debug);
|
reg_array->debug);
|
||||||
@ -208,6 +213,7 @@ uint64_t register_read_memory(void *opaque, hwaddr addr,
|
|||||||
RegisterInfoArray *reg_array = opaque;
|
RegisterInfoArray *reg_array = opaque;
|
||||||
RegisterInfo *reg = NULL;
|
RegisterInfo *reg = NULL;
|
||||||
uint64_t read_val;
|
uint64_t read_val;
|
||||||
|
uint64_t re;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < reg_array->num_elements; i++) {
|
for (i = 0; i < reg_array->num_elements; i++) {
|
||||||
@ -223,7 +229,10 @@ uint64_t register_read_memory(void *opaque, hwaddr addr,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_val = register_read(reg, size * 8, reg_array->prefix,
|
/* Generate appropriate read enable mask */
|
||||||
|
re = register_enabled_mask(reg->data_size, size);
|
||||||
|
|
||||||
|
read_val = register_read(reg, re, reg_array->prefix,
|
||||||
reg_array->debug);
|
reg_array->debug);
|
||||||
|
|
||||||
return extract64(read_val, 0, size * 8);
|
return extract64(read_val, 0, size * 8);
|
||||||
|
Loading…
Reference in New Issue
Block a user