Skip to content

Commit 284a66a

Browse files
philmdalistair23
authored andcommitted
hw/char/mchp_pfsoc_mmuart: Simplify MCHP_PFSOC_MMUART_REG definition
The current MCHP_PFSOC_MMUART_REG_SIZE definition represent the size occupied by all the registers. However all registers are 32-bit wide, and the MemoryRegionOps handlers are restricted to 32-bit: static const MemoryRegionOps mchp_pfsoc_mmuart_ops = { .read = mchp_pfsoc_mmuart_read, .write = mchp_pfsoc_mmuart_write, .impl = { .min_access_size = 4, .max_access_size = 4, }, Avoid being triskaidekaphobic, simplify by using the number of registers. Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Bin Meng <[email protected]> Tested-by: Bin Meng <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Message-id: [email protected] Signed-off-by: Alistair Francis <[email protected]>
1 parent 6a03349 commit 284a66a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

hw/char/mchp_pfsoc_mmuart.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ static uint64_t mchp_pfsoc_mmuart_read(void *opaque, hwaddr addr, unsigned size)
2929
{
3030
MchpPfSoCMMUartState *s = opaque;
3131

32-
if (addr >= MCHP_PFSOC_MMUART_REG_SIZE) {
32+
addr >>= 2;
33+
if (addr >= MCHP_PFSOC_MMUART_REG_COUNT) {
3334
qemu_log_mask(LOG_GUEST_ERROR, "%s: read: addr=0x%" HWADDR_PRIx "\n",
34-
__func__, addr);
35+
__func__, addr << 2);
3536
return 0;
3637
}
3738

38-
return s->reg[addr / sizeof(uint32_t)];
39+
return s->reg[addr];
3940
}
4041

4142
static void mchp_pfsoc_mmuart_write(void *opaque, hwaddr addr,
@@ -44,13 +45,14 @@ static void mchp_pfsoc_mmuart_write(void *opaque, hwaddr addr,
4445
MchpPfSoCMMUartState *s = opaque;
4546
uint32_t val32 = (uint32_t)value;
4647

47-
if (addr >= MCHP_PFSOC_MMUART_REG_SIZE) {
48+
addr >>= 2;
49+
if (addr >= MCHP_PFSOC_MMUART_REG_COUNT) {
4850
qemu_log_mask(LOG_GUEST_ERROR, "%s: bad write: addr=0x%" HWADDR_PRIx
49-
" v=0x%x\n", __func__, addr, val32);
51+
" v=0x%x\n", __func__, addr << 2, val32);
5052
return;
5153
}
5254

53-
s->reg[addr / sizeof(uint32_t)] = val32;
55+
s->reg[addr] = val32;
5456
}
5557

5658
static const MemoryRegionOps mchp_pfsoc_mmuart_ops = {

include/hw/char/mchp_pfsoc_mmuart.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#include "hw/char/serial.h"
3232

33-
#define MCHP_PFSOC_MMUART_REG_SIZE 52
33+
#define MCHP_PFSOC_MMUART_REG_COUNT 13
3434

3535
typedef struct MchpPfSoCMMUartState {
3636
MemoryRegion iomem;
@@ -39,7 +39,7 @@ typedef struct MchpPfSoCMMUartState {
3939

4040
SerialMM *serial;
4141

42-
uint32_t reg[MCHP_PFSOC_MMUART_REG_SIZE / sizeof(uint32_t)];
42+
uint32_t reg[MCHP_PFSOC_MMUART_REG_COUNT];
4343
} MchpPfSoCMMUartState;
4444

4545
/**

0 commit comments

Comments
 (0)