24ce762df7
Our device have 2 different I/O regions: - a 16550 UART mapped for 32-bit accesses - 13 extra registers Instead of mapping each region on the main bus, introduce a container, map the 2 devices regions on the container, and map the container on the main bus. Before: (qemu) info mtree ... 0000000020100000-000000002010001f (prio 0, i/o): serial 0000000020100020-000000002010101f (prio 0, i/o): mchp.pfsoc.mmuart 0000000020102000-000000002010201f (prio 0, i/o): serial 0000000020102020-000000002010301f (prio 0, i/o): mchp.pfsoc.mmuart 0000000020104000-000000002010401f (prio 0, i/o): serial 0000000020104020-000000002010501f (prio 0, i/o): mchp.pfsoc.mmuart 0000000020106000-000000002010601f (prio 0, i/o): serial 0000000020106020-000000002010701f (prio 0, i/o): mchp.pfsoc.mmuart After: (qemu) info mtree ... 0000000020100000-0000000020100fff (prio 0, i/o): mchp.pfsoc.mmuart 0000000020100000-000000002010001f (prio 0, i/o): serial 0000000020100020-0000000020100fff (prio 0, i/o): mchp.pfsoc.mmuart.regs 0000000020102000-0000000020102fff (prio 0, i/o): mchp.pfsoc.mmuart 0000000020102000-000000002010201f (prio 0, i/o): serial 0000000020102020-0000000020102fff (prio 0, i/o): mchp.pfsoc.mmuart.regs 0000000020104000-0000000020104fff (prio 0, i/o): mchp.pfsoc.mmuart 0000000020104000-000000002010401f (prio 0, i/o): serial 0000000020104020-0000000020104fff (prio 0, i/o): mchp.pfsoc.mmuart.regs 0000000020106000-0000000020106fff (prio 0, i/o): mchp.pfsoc.mmuart 0000000020106000-000000002010601f (prio 0, i/o): serial 0000000020106020-0000000020106fff (prio 0, i/o): mchp.pfsoc.mmuart.regs Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Bin Meng <bin.meng@windriver.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Tested-by: Bin Meng <bin.meng@windriver.com> Message-id: 20210925133407.1259392-3-f4bug@amsat.org Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
93 lines
2.7 KiB
C
93 lines
2.7 KiB
C
/*
|
|
* Microchip PolarFire SoC MMUART emulation
|
|
*
|
|
* Copyright (c) 2020 Wind River Systems, Inc.
|
|
*
|
|
* Author:
|
|
* Bin Meng <bin.meng@windriver.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License as
|
|
* published by the Free Software Foundation; either version 2 or
|
|
* (at your option) version 3 of the License.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/log.h"
|
|
#include "chardev/char.h"
|
|
#include "hw/char/mchp_pfsoc_mmuart.h"
|
|
|
|
#define REGS_OFFSET 0x20
|
|
|
|
static uint64_t mchp_pfsoc_mmuart_read(void *opaque, hwaddr addr, unsigned size)
|
|
{
|
|
MchpPfSoCMMUartState *s = opaque;
|
|
|
|
addr >>= 2;
|
|
if (addr >= MCHP_PFSOC_MMUART_REG_COUNT) {
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: read: addr=0x%" HWADDR_PRIx "\n",
|
|
__func__, addr << 2);
|
|
return 0;
|
|
}
|
|
|
|
return s->reg[addr];
|
|
}
|
|
|
|
static void mchp_pfsoc_mmuart_write(void *opaque, hwaddr addr,
|
|
uint64_t value, unsigned size)
|
|
{
|
|
MchpPfSoCMMUartState *s = opaque;
|
|
uint32_t val32 = (uint32_t)value;
|
|
|
|
addr >>= 2;
|
|
if (addr >= MCHP_PFSOC_MMUART_REG_COUNT) {
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: bad write: addr=0x%" HWADDR_PRIx
|
|
" v=0x%x\n", __func__, addr << 2, val32);
|
|
return;
|
|
}
|
|
|
|
s->reg[addr] = val32;
|
|
}
|
|
|
|
static const MemoryRegionOps mchp_pfsoc_mmuart_ops = {
|
|
.read = mchp_pfsoc_mmuart_read,
|
|
.write = mchp_pfsoc_mmuart_write,
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
.impl = {
|
|
.min_access_size = 4,
|
|
.max_access_size = 4,
|
|
},
|
|
};
|
|
|
|
MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem,
|
|
hwaddr base, qemu_irq irq, Chardev *chr)
|
|
{
|
|
MchpPfSoCMMUartState *s;
|
|
|
|
s = g_new0(MchpPfSoCMMUartState, 1);
|
|
|
|
memory_region_init(&s->container, NULL, "mchp.pfsoc.mmuart", 0x1000);
|
|
|
|
memory_region_init_io(&s->iomem, NULL, &mchp_pfsoc_mmuart_ops, s,
|
|
"mchp.pfsoc.mmuart.regs", 0x1000 - REGS_OFFSET);
|
|
memory_region_add_subregion(&s->container, REGS_OFFSET, &s->iomem);
|
|
|
|
s->base = base;
|
|
s->irq = irq;
|
|
|
|
s->serial = serial_mm_init(&s->container, 0, 2, irq, 399193, chr,
|
|
DEVICE_LITTLE_ENDIAN);
|
|
|
|
memory_region_add_subregion(sysmem, base, &s->container);
|
|
|
|
return s;
|
|
}
|