2009-07-02 12:32:06 +02:00
|
|
|
/*
|
|
|
|
* QEMU System Emulator
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
/*
|
2023-08-23 08:53:30 +02:00
|
|
|
* split out ioport related stuffs from vl.c.
|
2009-07-02 12:32:06 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-29 18:50:05 +01:00
|
|
|
#include "qemu/osdep.h"
|
2016-03-15 16:58:45 +01:00
|
|
|
#include "cpu.h"
|
2012-12-17 18:19:49 +01:00
|
|
|
#include "exec/ioport.h"
|
|
|
|
#include "exec/memory.h"
|
2013-06-24 10:45:09 +02:00
|
|
|
#include "exec/address-spaces.h"
|
2020-08-05 15:02:20 +02:00
|
|
|
#include "trace.h"
|
2009-07-02 12:32:06 +02:00
|
|
|
|
2023-04-19 17:16:51 +02:00
|
|
|
struct MemoryRegionPortioList {
|
|
|
|
Object obj;
|
|
|
|
|
2013-06-24 10:45:09 +02:00
|
|
|
MemoryRegion mr;
|
|
|
|
void *portio_opaque;
|
2023-04-19 17:16:50 +02:00
|
|
|
MemoryRegionPortio *ports;
|
2023-04-19 17:16:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define TYPE_MEMORY_REGION_PORTIO_LIST "memory-region-portio-list"
|
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(MemoryRegionPortioList, MEMORY_REGION_PORTIO_LIST)
|
2013-06-24 10:45:09 +02:00
|
|
|
|
2013-09-02 18:43:30 +02:00
|
|
|
static uint64_t unassigned_io_read(void *opaque, hwaddr addr, unsigned size)
|
|
|
|
{
|
|
|
|
return -1ULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unassigned_io_write(void *opaque, hwaddr addr, uint64_t val,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const MemoryRegionOps unassigned_io_ops = {
|
|
|
|
.read = unassigned_io_read,
|
|
|
|
.write = unassigned_io_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2016-03-16 10:20:34 +01:00
|
|
|
void cpu_outb(uint32_t addr, uint8_t val)
|
2009-07-02 12:32:06 +02:00
|
|
|
{
|
2015-10-16 15:08:34 +02:00
|
|
|
trace_cpu_out(addr, 'b', val);
|
2015-04-26 17:49:24 +02:00
|
|
|
address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
|
|
|
|
&val, 1);
|
2009-07-02 12:32:06 +02:00
|
|
|
}
|
|
|
|
|
2016-03-16 10:20:34 +01:00
|
|
|
void cpu_outw(uint32_t addr, uint16_t val)
|
2009-07-02 12:32:06 +02:00
|
|
|
{
|
2013-06-24 10:45:09 +02:00
|
|
|
uint8_t buf[2];
|
|
|
|
|
2015-10-16 15:08:34 +02:00
|
|
|
trace_cpu_out(addr, 'w', val);
|
2013-06-24 10:45:09 +02:00
|
|
|
stw_p(buf, val);
|
2015-04-26 17:49:24 +02:00
|
|
|
address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
|
|
|
|
buf, 2);
|
2009-07-02 12:32:06 +02:00
|
|
|
}
|
|
|
|
|
2016-03-16 10:20:34 +01:00
|
|
|
void cpu_outl(uint32_t addr, uint32_t val)
|
2009-07-02 12:32:06 +02:00
|
|
|
{
|
2013-06-24 10:45:09 +02:00
|
|
|
uint8_t buf[4];
|
|
|
|
|
2015-10-16 15:08:34 +02:00
|
|
|
trace_cpu_out(addr, 'l', val);
|
2013-06-24 10:45:09 +02:00
|
|
|
stl_p(buf, val);
|
2015-04-26 17:49:24 +02:00
|
|
|
address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
|
|
|
|
buf, 4);
|
2009-07-02 12:32:06 +02:00
|
|
|
}
|
|
|
|
|
2016-03-16 10:20:34 +01:00
|
|
|
uint8_t cpu_inb(uint32_t addr)
|
2009-07-02 12:32:06 +02:00
|
|
|
{
|
ioport: use uint{32, 16, 8}_t for ioport value and pio_addr_t for ioport address.
Using int for cpu_{in, out}[bwl] is inconsistent with other part
because for address or value, uintN_t is used by other qemu part.
At least, softmmu, CPU{Read, Write}MemoryFunc, pci, target_phys_addr_t
and the callers of cpu_{in, out}[bwl]().
This patch removes the inconsistency.
IO port has its own address space so define pio_addr_t as uint32_t
because PCI io space width is 32bit.
And use uint{32, 16, 8}_t for ioport value.
Changing signedness of value might cause subtle issue. However
only a suspicious caller is kvm_handle_io() which is ok. And other callers
pass unsigned value in the first place.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: Stuart Brady <sdbrady@ntlworld.com>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Cc: Samuel Thibault <samuel.thibault@gnu.org>
Cc: Tristan Gingold <gingold@adacore.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-14 12:10:43 +02:00
|
|
|
uint8_t val;
|
2013-06-24 10:45:09 +02:00
|
|
|
|
2015-04-26 17:49:24 +02:00
|
|
|
address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
|
|
|
|
&val, 1);
|
2015-10-16 15:08:34 +02:00
|
|
|
trace_cpu_in(addr, 'b', val);
|
2009-07-02 12:32:06 +02:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2016-03-16 10:20:34 +01:00
|
|
|
uint16_t cpu_inw(uint32_t addr)
|
2009-07-02 12:32:06 +02:00
|
|
|
{
|
2013-06-24 10:45:09 +02:00
|
|
|
uint8_t buf[2];
|
ioport: use uint{32, 16, 8}_t for ioport value and pio_addr_t for ioport address.
Using int for cpu_{in, out}[bwl] is inconsistent with other part
because for address or value, uintN_t is used by other qemu part.
At least, softmmu, CPU{Read, Write}MemoryFunc, pci, target_phys_addr_t
and the callers of cpu_{in, out}[bwl]().
This patch removes the inconsistency.
IO port has its own address space so define pio_addr_t as uint32_t
because PCI io space width is 32bit.
And use uint{32, 16, 8}_t for ioport value.
Changing signedness of value might cause subtle issue. However
only a suspicious caller is kvm_handle_io() which is ok. And other callers
pass unsigned value in the first place.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: Stuart Brady <sdbrady@ntlworld.com>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Cc: Samuel Thibault <samuel.thibault@gnu.org>
Cc: Tristan Gingold <gingold@adacore.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-14 12:10:43 +02:00
|
|
|
uint16_t val;
|
2013-06-24 10:45:09 +02:00
|
|
|
|
2015-04-26 17:49:24 +02:00
|
|
|
address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED, buf, 2);
|
2013-06-24 10:45:09 +02:00
|
|
|
val = lduw_p(buf);
|
2015-10-16 15:08:34 +02:00
|
|
|
trace_cpu_in(addr, 'w', val);
|
2009-07-02 12:32:06 +02:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2016-03-16 10:20:34 +01:00
|
|
|
uint32_t cpu_inl(uint32_t addr)
|
2009-07-02 12:32:06 +02:00
|
|
|
{
|
2013-06-24 10:45:09 +02:00
|
|
|
uint8_t buf[4];
|
ioport: use uint{32, 16, 8}_t for ioport value and pio_addr_t for ioport address.
Using int for cpu_{in, out}[bwl] is inconsistent with other part
because for address or value, uintN_t is used by other qemu part.
At least, softmmu, CPU{Read, Write}MemoryFunc, pci, target_phys_addr_t
and the callers of cpu_{in, out}[bwl]().
This patch removes the inconsistency.
IO port has its own address space so define pio_addr_t as uint32_t
because PCI io space width is 32bit.
And use uint{32, 16, 8}_t for ioport value.
Changing signedness of value might cause subtle issue. However
only a suspicious caller is kvm_handle_io() which is ok. And other callers
pass unsigned value in the first place.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: Stuart Brady <sdbrady@ntlworld.com>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Cc: Samuel Thibault <samuel.thibault@gnu.org>
Cc: Tristan Gingold <gingold@adacore.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-14 12:10:43 +02:00
|
|
|
uint32_t val;
|
2013-06-24 10:45:09 +02:00
|
|
|
|
2015-04-26 17:49:24 +02:00
|
|
|
address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED, buf, 4);
|
2013-06-24 10:45:09 +02:00
|
|
|
val = ldl_p(buf);
|
2015-10-16 15:08:34 +02:00
|
|
|
trace_cpu_in(addr, 'l', val);
|
2009-07-02 12:32:06 +02:00
|
|
|
return val;
|
|
|
|
}
|
2011-09-26 13:52:26 +02:00
|
|
|
|
|
|
|
void portio_list_init(PortioList *piolist,
|
2013-06-07 03:19:53 +02:00
|
|
|
Object *owner,
|
2011-09-26 13:52:26 +02:00
|
|
|
const MemoryRegionPortio *callbacks,
|
|
|
|
void *opaque, const char *name)
|
|
|
|
{
|
|
|
|
unsigned n = 0;
|
|
|
|
|
|
|
|
while (callbacks[n].size) {
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
|
|
|
|
piolist->ports = callbacks;
|
|
|
|
piolist->nr = 0;
|
|
|
|
piolist->regions = g_new0(MemoryRegion *, n);
|
|
|
|
piolist->address_space = NULL;
|
2024-01-14 13:39:05 +01:00
|
|
|
piolist->addr = 0;
|
2011-09-26 13:52:26 +02:00
|
|
|
piolist->opaque = opaque;
|
2013-06-07 03:19:53 +02:00
|
|
|
piolist->owner = owner;
|
2011-09-26 13:52:26 +02:00
|
|
|
piolist->name = name;
|
2013-07-02 20:22:37 +02:00
|
|
|
piolist->flush_coalesced_mmio = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void portio_list_set_flush_coalesced(PortioList *piolist)
|
|
|
|
{
|
|
|
|
piolist->flush_coalesced_mmio = true;
|
2011-09-26 13:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void portio_list_destroy(PortioList *piolist)
|
|
|
|
{
|
2014-06-11 13:02:51 +02:00
|
|
|
MemoryRegionPortioList *mrpio;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < piolist->nr; ++i) {
|
|
|
|
mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
|
2014-06-11 12:42:01 +02:00
|
|
|
object_unparent(OBJECT(&mrpio->mr));
|
2023-04-19 17:16:51 +02:00
|
|
|
object_unref(mrpio);
|
2014-06-11 13:02:51 +02:00
|
|
|
}
|
2011-09-26 13:52:26 +02:00
|
|
|
g_free(piolist->regions);
|
|
|
|
}
|
|
|
|
|
2013-06-24 10:45:09 +02:00
|
|
|
static const MemoryRegionPortio *find_portio(MemoryRegionPortioList *mrpio,
|
|
|
|
uint64_t offset, unsigned size,
|
|
|
|
bool write)
|
|
|
|
{
|
|
|
|
const MemoryRegionPortio *mrp;
|
|
|
|
|
|
|
|
for (mrp = mrpio->ports; mrp->size; ++mrp) {
|
|
|
|
if (offset >= mrp->offset && offset < mrp->offset + mrp->len &&
|
|
|
|
size == mrp->size &&
|
|
|
|
(write ? (bool)mrp->write : (bool)mrp->read)) {
|
|
|
|
return mrp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t portio_read(void *opaque, hwaddr addr, unsigned size)
|
|
|
|
{
|
|
|
|
MemoryRegionPortioList *mrpio = opaque;
|
|
|
|
const MemoryRegionPortio *mrp = find_portio(mrpio, addr, size, false);
|
|
|
|
uint64_t data;
|
|
|
|
|
|
|
|
data = ((uint64_t)1 << (size * 8)) - 1;
|
|
|
|
if (mrp) {
|
2024-01-14 13:39:04 +01:00
|
|
|
data = mrp->read(mrpio->portio_opaque, mrpio->mr.addr + addr);
|
2013-06-24 10:45:09 +02:00
|
|
|
} else if (size == 2) {
|
|
|
|
mrp = find_portio(mrpio, addr, 1, false);
|
2015-03-30 12:49:40 +02:00
|
|
|
if (mrp) {
|
2024-01-14 13:39:04 +01:00
|
|
|
data = mrp->read(mrpio->portio_opaque, mrpio->mr.addr + addr);
|
2015-03-30 12:49:40 +02:00
|
|
|
if (addr + 1 < mrp->offset + mrp->len) {
|
2024-01-14 13:39:04 +01:00
|
|
|
data |= mrp->read(mrpio->portio_opaque, mrpio->mr.addr + addr + 1) << 8;
|
2015-03-30 12:49:40 +02:00
|
|
|
} else {
|
|
|
|
data |= 0xff00;
|
|
|
|
}
|
|
|
|
}
|
2013-06-24 10:45:09 +02:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void portio_write(void *opaque, hwaddr addr, uint64_t data,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
MemoryRegionPortioList *mrpio = opaque;
|
|
|
|
const MemoryRegionPortio *mrp = find_portio(mrpio, addr, size, true);
|
|
|
|
|
|
|
|
if (mrp) {
|
2024-01-14 13:39:04 +01:00
|
|
|
mrp->write(mrpio->portio_opaque, mrpio->mr.addr + addr, data);
|
2013-06-24 10:45:09 +02:00
|
|
|
} else if (size == 2) {
|
|
|
|
mrp = find_portio(mrpio, addr, 1, true);
|
2015-03-30 12:49:40 +02:00
|
|
|
if (mrp) {
|
2024-01-14 13:39:04 +01:00
|
|
|
mrp->write(mrpio->portio_opaque, mrpio->mr.addr + addr, data & 0xff);
|
2015-03-30 12:49:40 +02:00
|
|
|
if (addr + 1 < mrp->offset + mrp->len) {
|
2024-01-14 13:39:04 +01:00
|
|
|
mrp->write(mrpio->portio_opaque, mrpio->mr.addr + addr + 1, data >> 8);
|
2015-03-30 12:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-24 10:45:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps portio_ops = {
|
|
|
|
.read = portio_read,
|
|
|
|
.write = portio_write,
|
2013-07-22 15:54:25 +02:00
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2013-06-24 10:45:09 +02:00
|
|
|
.valid.unaligned = true,
|
|
|
|
.impl.unaligned = true,
|
|
|
|
};
|
|
|
|
|
2011-09-26 13:52:26 +02:00
|
|
|
static void portio_list_add_1(PortioList *piolist,
|
|
|
|
const MemoryRegionPortio *pio_init,
|
|
|
|
unsigned count, unsigned start,
|
|
|
|
unsigned off_low, unsigned off_high)
|
|
|
|
{
|
2013-06-24 10:45:09 +02:00
|
|
|
MemoryRegionPortioList *mrpio;
|
2023-04-19 17:16:52 +02:00
|
|
|
Object *owner;
|
|
|
|
char *name;
|
2011-09-26 13:52:26 +02:00
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* Copy the sub-list and null-terminate it. */
|
2023-04-19 17:16:51 +02:00
|
|
|
mrpio = MEMORY_REGION_PORTIO_LIST(
|
|
|
|
object_new(TYPE_MEMORY_REGION_PORTIO_LIST));
|
2013-06-24 10:45:09 +02:00
|
|
|
mrpio->portio_opaque = piolist->opaque;
|
2023-04-19 17:16:50 +02:00
|
|
|
mrpio->ports = g_malloc0(sizeof(MemoryRegionPortio) * (count + 1));
|
2013-06-24 10:45:09 +02:00
|
|
|
memcpy(mrpio->ports, pio_init, sizeof(MemoryRegionPortio) * count);
|
|
|
|
memset(mrpio->ports + count, 0, sizeof(MemoryRegionPortio));
|
2011-09-26 13:52:26 +02:00
|
|
|
|
|
|
|
/* Adjust the offsets to all be zero-based for the region. */
|
|
|
|
for (i = 0; i < count; ++i) {
|
2013-06-24 10:45:09 +02:00
|
|
|
mrpio->ports[i].offset -= off_low;
|
2011-09-26 13:52:26 +02:00
|
|
|
}
|
|
|
|
|
2023-04-19 17:16:52 +02:00
|
|
|
/*
|
|
|
|
* The MemoryRegion owner is the MemoryRegionPortioList since that manages
|
|
|
|
* the lifecycle via the refcount
|
|
|
|
*/
|
|
|
|
memory_region_init_io(&mrpio->mr, OBJECT(mrpio), &portio_ops, mrpio,
|
2013-06-07 03:19:53 +02:00
|
|
|
piolist->name, off_high - off_low);
|
2023-04-19 17:16:52 +02:00
|
|
|
|
|
|
|
/* Reparent the MemoryRegion to the piolist owner */
|
|
|
|
object_ref(&mrpio->mr);
|
|
|
|
object_unparent(OBJECT(&mrpio->mr));
|
|
|
|
if (!piolist->owner) {
|
|
|
|
owner = container_get(qdev_get_machine(), "/unattached");
|
|
|
|
} else {
|
|
|
|
owner = piolist->owner;
|
|
|
|
}
|
|
|
|
name = g_strdup_printf("%s[*]", piolist->name);
|
|
|
|
object_property_add_child(owner, name, OBJECT(&mrpio->mr));
|
|
|
|
g_free(name);
|
|
|
|
|
2013-07-02 20:22:37 +02:00
|
|
|
if (piolist->flush_coalesced_mmio) {
|
|
|
|
memory_region_set_flush_coalesced(&mrpio->mr);
|
|
|
|
}
|
2011-09-26 13:52:26 +02:00
|
|
|
memory_region_add_subregion(piolist->address_space,
|
2013-06-24 10:45:09 +02:00
|
|
|
start + off_low, &mrpio->mr);
|
|
|
|
piolist->regions[piolist->nr] = &mrpio->mr;
|
2012-01-08 18:46:17 +01:00
|
|
|
++piolist->nr;
|
2011-09-26 13:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void portio_list_add(PortioList *piolist,
|
|
|
|
MemoryRegion *address_space,
|
|
|
|
uint32_t start)
|
|
|
|
{
|
|
|
|
const MemoryRegionPortio *pio, *pio_start = piolist->ports;
|
|
|
|
unsigned int off_low, off_high, off_last, count;
|
|
|
|
|
|
|
|
piolist->address_space = address_space;
|
2024-01-14 13:39:05 +01:00
|
|
|
piolist->addr = start;
|
2011-09-26 13:52:26 +02:00
|
|
|
|
|
|
|
/* Handle the first entry specially. */
|
|
|
|
off_last = off_low = pio_start->offset;
|
2015-03-30 12:35:00 +02:00
|
|
|
off_high = off_low + pio_start->len + pio_start->size - 1;
|
2011-09-26 13:52:26 +02:00
|
|
|
count = 1;
|
|
|
|
|
|
|
|
for (pio = pio_start + 1; pio->size != 0; pio++, count++) {
|
|
|
|
/* All entries must be sorted by offset. */
|
|
|
|
assert(pio->offset >= off_last);
|
|
|
|
off_last = pio->offset;
|
|
|
|
|
|
|
|
/* If we see a hole, break the region. */
|
|
|
|
if (off_last > off_high) {
|
|
|
|
portio_list_add_1(piolist, pio_start, count, start, off_low,
|
|
|
|
off_high);
|
|
|
|
/* ... and start collecting anew. */
|
|
|
|
pio_start = pio;
|
|
|
|
off_low = off_last;
|
2015-03-30 12:35:00 +02:00
|
|
|
off_high = off_low + pio->len + pio_start->size - 1;
|
2011-09-26 13:52:26 +02:00
|
|
|
count = 0;
|
|
|
|
} else if (off_last + pio->len > off_high) {
|
2015-03-30 12:35:00 +02:00
|
|
|
off_high = off_last + pio->len + pio_start->size - 1;
|
2011-09-26 13:52:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There will always be an open sub-list. */
|
|
|
|
portio_list_add_1(piolist, pio_start, count, start, off_low, off_high);
|
|
|
|
}
|
|
|
|
|
|
|
|
void portio_list_del(PortioList *piolist)
|
|
|
|
{
|
2013-06-24 10:45:09 +02:00
|
|
|
MemoryRegionPortioList *mrpio;
|
2011-09-26 13:52:26 +02:00
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < piolist->nr; ++i) {
|
2013-06-24 10:45:09 +02:00
|
|
|
mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
|
|
|
|
memory_region_del_subregion(piolist->address_space, &mrpio->mr);
|
2011-09-26 13:52:26 +02:00
|
|
|
}
|
|
|
|
}
|
2023-04-19 17:16:51 +02:00
|
|
|
|
2024-01-14 13:39:06 +01:00
|
|
|
void portio_list_set_enabled(PortioList *piolist, bool enabled)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < piolist->nr; ++i) {
|
|
|
|
memory_region_set_enabled(piolist->regions[i], enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-14 13:39:05 +01:00
|
|
|
void portio_list_set_address(PortioList *piolist, uint32_t addr)
|
|
|
|
{
|
|
|
|
MemoryRegionPortioList *mrpio;
|
|
|
|
unsigned i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < piolist->nr; ++i) {
|
|
|
|
mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
|
|
|
|
memory_region_set_address(&mrpio->mr,
|
|
|
|
mrpio->mr.addr - piolist->addr + addr);
|
|
|
|
for (j = 0; mrpio->ports[j].size; ++j) {
|
|
|
|
mrpio->ports[j].offset += addr - piolist->addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
piolist->addr = addr;
|
|
|
|
}
|
|
|
|
|
2023-04-19 17:16:51 +02:00
|
|
|
static void memory_region_portio_list_finalize(Object *obj)
|
|
|
|
{
|
|
|
|
MemoryRegionPortioList *mrpio = MEMORY_REGION_PORTIO_LIST(obj);
|
|
|
|
|
2023-04-19 17:16:52 +02:00
|
|
|
object_unref(&mrpio->mr);
|
2023-04-19 17:16:51 +02:00
|
|
|
g_free(mrpio->ports);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo memory_region_portio_list_info = {
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.name = TYPE_MEMORY_REGION_PORTIO_LIST,
|
|
|
|
.instance_size = sizeof(MemoryRegionPortioList),
|
|
|
|
.instance_finalize = memory_region_portio_list_finalize,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ioport_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&memory_region_portio_list_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(ioport_register_types)
|