[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 05/16] hw/intc/loongarch_pch: Use relative address in MemoryRe
From: |
Bibo Mao |
Subject: |
[PATCH v4 05/16] hw/intc/loongarch_pch: Use relative address in MemoryRegionOps |
Date: |
Wed, 7 May 2025 10:31:37 +0800 |
Parameter address for read and write callback in MemoryRegionOps is
relative offset with base address of this MemoryRegionOps. It can
be directly used as offset and offset calculation can be removed.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Reviewed-by: Song Gao <gaosong@loongson.cn>
---
hw/intc/loongarch_pch_pic.c | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c
index f732c292f8..9b64bf938f 100644
--- a/hw/intc/loongarch_pch_pic.c
+++ b/hw/intc/loongarch_pch_pic.c
@@ -76,9 +76,8 @@ static uint64_t loongarch_pch_pic_low_readw(void *opaque,
hwaddr addr,
{
LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
uint64_t val = 0;
- uint32_t offset = addr & 0xfff;
- switch (offset) {
+ switch (addr) {
case PCH_PIC_INT_ID:
val = s->id.data & UINT_MAX;
break;
@@ -129,13 +128,12 @@ static void loongarch_pch_pic_low_writew(void *opaque,
hwaddr addr,
uint64_t value, unsigned size)
{
LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
- uint32_t offset, old_valid, data = (uint32_t)value;
+ uint32_t old_valid, data = (uint32_t)value;
uint64_t old, int_mask;
- offset = addr & 0xfff;
trace_loongarch_pch_pic_low_writew(size, addr, data);
- switch (offset) {
+ switch (addr) {
case PCH_PIC_INT_MASK:
old = s->int_mask;
s->int_mask = get_writew_val(old, data, 0);
@@ -203,9 +201,9 @@ static uint64_t loongarch_pch_pic_high_readw(void *opaque,
hwaddr addr,
{
LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
uint64_t val = 0;
- uint32_t offset = addr + PCH_PIC_INT_STATUS;
- switch (offset) {
+ addr += PCH_PIC_INT_STATUS;
+ switch (addr) {
case PCH_PIC_INT_STATUS:
val = (uint32_t)(s->intisr & (~s->int_mask));
break;
@@ -230,12 +228,12 @@ static void loongarch_pch_pic_high_writew(void *opaque,
hwaddr addr,
uint64_t value, unsigned size)
{
LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
- uint32_t offset, data = (uint32_t)value;
- offset = addr + PCH_PIC_INT_STATUS;
+ uint32_t data = (uint32_t)value;
+ addr += PCH_PIC_INT_STATUS;
trace_loongarch_pch_pic_high_writew(size, addr, data);
- switch (offset) {
+ switch (addr) {
case PCH_PIC_INT_STATUS:
s->intisr = get_writew_val(s->intisr, data, 0);
break;
@@ -258,18 +256,18 @@ static uint64_t loongarch_pch_pic_readb(void *opaque,
hwaddr addr,
{
LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
uint64_t val = 0;
- uint32_t offset = (addr & 0xfff) + PCH_PIC_ROUTE_ENTRY;
int64_t offset_tmp;
- switch (offset) {
+ addr += PCH_PIC_ROUTE_ENTRY;
+ switch (addr) {
case PCH_PIC_HTMSI_VEC ... PCH_PIC_HTMSI_VEC_END:
- offset_tmp = offset - PCH_PIC_HTMSI_VEC;
+ offset_tmp = addr - PCH_PIC_HTMSI_VEC;
if (offset_tmp >= 0 && offset_tmp < 64) {
val = s->htmsi_vector[offset_tmp];
}
break;
case PCH_PIC_ROUTE_ENTRY ... PCH_PIC_ROUTE_ENTRY_END:
- offset_tmp = offset - PCH_PIC_ROUTE_ENTRY;
+ offset_tmp = addr - PCH_PIC_ROUTE_ENTRY;
if (offset_tmp >= 0 && offset_tmp < 64) {
val = s->route_entry[offset_tmp];
}
@@ -287,19 +285,19 @@ static void loongarch_pch_pic_writeb(void *opaque, hwaddr
addr,
{
LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
int32_t offset_tmp;
- uint32_t offset = (addr & 0xfff) + PCH_PIC_ROUTE_ENTRY;
+ addr += PCH_PIC_ROUTE_ENTRY;
trace_loongarch_pch_pic_writeb(size, addr, data);
- switch (offset) {
+ switch (addr) {
case PCH_PIC_HTMSI_VEC ... PCH_PIC_HTMSI_VEC_END:
- offset_tmp = offset - PCH_PIC_HTMSI_VEC;
+ offset_tmp = addr - PCH_PIC_HTMSI_VEC;
if (offset_tmp >= 0 && offset_tmp < 64) {
s->htmsi_vector[offset_tmp] = (uint8_t)(data & 0xff);
}
break;
case PCH_PIC_ROUTE_ENTRY ... PCH_PIC_ROUTE_ENTRY_END:
- offset_tmp = offset - PCH_PIC_ROUTE_ENTRY;
+ offset_tmp = addr - PCH_PIC_ROUTE_ENTRY;
if (offset_tmp >= 0 && offset_tmp < 64) {
s->route_entry[offset_tmp] = (uint8_t)(data & 0xff);
}
--
2.39.3
- [PATCH v4 00/16] hw/intc/loongarch_pch: Cleanup with memory region ops, Bibo Mao, 2025/05/06
- [PATCH v4 01/16] hw/intc/loongarch_pch: Modify name of some registers, Bibo Mao, 2025/05/06
- [PATCH v4 04/16] hw/intc/loongarch_pch: Set version information at initial stage, Bibo Mao, 2025/05/06
- [PATCH v4 05/16] hw/intc/loongarch_pch: Use relative address in MemoryRegionOps,
Bibo Mao <=
- [PATCH v4 06/16] hw/intc/loongarch_pch: Discard write operation with ISR register, Bibo Mao, 2025/05/06
- [PATCH v4 02/16] hw/intc/loongarch_pch: Modify register name PCH_PIC_xxx_OFFSET with PCH_PIC_xxx, Bibo Mao, 2025/05/06
- [PATCH v4 03/16] hw/intc/loongarch_pch: Remove some duplicate macro, Bibo Mao, 2025/05/06
- [PATCH v4 07/16] hw/intc/loongarch_pch: Use generic read callback for iomem32_low region, Bibo Mao, 2025/05/06
- [PATCH v4 09/16] hw/intc/loongarch_pch: Use generic read callback for iomem8 region, Bibo Mao, 2025/05/06
- [PATCH v4 10/16] hw/intc/loongarch_pch: Use generic write callback for iomem32_low region, Bibo Mao, 2025/05/06
- [PATCH v4 08/16] hw/intc/loongarch_pch: Use generic read callback for iomem32_high region, Bibo Mao, 2025/05/06
- [PATCH v4 11/16] hw/intc/loongarch_pch: Use generic write callback for iomem32_high region, Bibo Mao, 2025/05/06
- [PATCH v4 12/16] hw/intc/loongarch_pch: Use generic write callback for iomem8 region, Bibo Mao, 2025/05/06