From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alexander Graf <agraf@suse.de>
Cc: Blue Swirl <blauwirbel@gmail.com>,
Isaku Yamahata <yamahata@valinux.co.jp>,
qemu-devel@nongnu.org, Aurelien Jarno <aurelien@aurel32.net>,
Paul Brook <paul@codesourcery.com>
Subject: Re: [Qemu-devel] [PATCH 6/6] pci host: make pci_data_{write, read}() get PCIConfigAddress.
Date: Tue, 12 Jan 2010 20:33:08 +0200 [thread overview]
Message-ID: <20100112183308.GA3036@redhat.com> (raw)
In-Reply-To: <4B4CB738.3000708@suse.de>
Guys, I was wondering whether the following helper function will be
helpful, as a lot of common code seems to be around identical b/w/l
callbacks. Comments?
diff --git a/cpu-common.h b/cpu-common.h
index 0ec9b72..be7e992 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -42,6 +42,24 @@ int cpu_register_io_memory(CPUReadMemoryFunc * const *mem_read,
void *opaque);
void cpu_unregister_io_memory(int table_address);
+typedef struct CpuIoMemoryHandler CpuIoMemoryHandler;
+/* len is guaranteed to be one of 1, 2 or 4 and does not need
+ * to be range checked. */
+typedef void CpuWriteMemorySimple(CpuIoMemoryHandler *,
+ target_phys_addr_t addr,
+ uint32_t value, int len);
+typedef uint32_t CpuReadMemorySimple(CpuIoMemoryHandler *,
+ target_phys_addr_t addr, int len);
+
+struct CpuIoMemoryHandler {
+ CpuWriteMemorySimple *write;
+ CpuReadMemorySimple *read;
+};
+
+/* Helper routine for when we want to use a single routine with
+ * length instead. */
+int cpu_register_io_memory_simple(struct CpuIoMemoryHandler *);
+
void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
int len, int is_write);
static inline void cpu_physical_memory_read(target_phys_addr_t addr,
diff --git a/exec.c b/exec.c
index 8a1c08e..cc0bf43 100644
--- a/exec.c
+++ b/exec.c
@@ -3065,6 +3065,67 @@ void cpu_unregister_io_memory(int io_table_address)
io_mem_used[io_index] = 0;
}
+static void cpu_io_memory_simple_writeb(void *opaque, target_phys_addr_t addr,
+ uint32_t value)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ handler->write(handler, addr, value, 1);
+}
+
+static uint32_t cpu_io_memory_simple_readb(void *opaque,
+ target_phys_addr_t addr)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ return handler->read(handler, addr, 1);
+}
+
+static void cpu_io_memory_simple_writew(void *opaque, target_phys_addr_t addr,
+ uint32_t value)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ handler->write(handler, addr, value, 2);
+}
+
+static uint32_t cpu_io_memory_simple_readw(void *opaque,
+ target_phys_addr_t addr)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ return handler->read(handler, addr, 2);
+}
+
+static void cpu_io_memory_simple_writel(void *opaque, target_phys_addr_t addr,
+ uint32_t value)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ handler->write(handler, addr, value, 4);
+}
+
+static uint32_t cpu_io_memory_simple_readl(void *opaque,
+ target_phys_addr_t addr)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ return handler->read(handler, addr, 4);
+}
+
+static CPUWriteMemoryFunc * const cpu_io_memory_simple_write[] = {
+ &cpu_io_memory_simple_writeb,
+ &cpu_io_memory_simple_writew,
+ &cpu_io_memory_simple_writel,
+};
+
+static CPUReadMemoryFunc * const cpu_io_memory_simple_read[] = {
+ &cpu_io_memory_simple_readb,
+ &cpu_io_memory_simple_readw,
+ &cpu_io_memory_simple_readl,
+};
+
+int cpu_register_io_memory_simple(struct CPUIoMemoryHandler *handler)
+{
+ return cpu_register_io_memory(cpu_io_memory_simple_read,
+ cpu_io_memory_simple_write,
+ handler);
+}
+
static void io_mem_init(void)
{
int i;
next prev parent reply other threads:[~2010-01-12 18:36 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-12 8:52 [Qemu-devel] [PATCH 0/6] pci: pci_data_{write, read}() clean up Isaku Yamahata
2010-01-12 8:52 ` [Qemu-devel] [PATCH 1/6] sh_pci: use PCIHostState instead of PCIBus Isaku Yamahata
2010-01-12 8:52 ` [Qemu-devel] [PATCH 2/6] sh_pci: s/sh_pci_data_write/sh_pci_mem_write/g for consistency Isaku Yamahata
2010-01-12 8:52 ` [Qemu-devel] [PATCH 3/6] versatile_pci: user PCIHostState instead of PCIBus Isaku Yamahata
2010-01-13 13:02 ` Paul Brook
2010-01-13 13:04 ` Michael S. Tsirkin
2010-01-12 8:52 ` [Qemu-devel] [PATCH 4/6] pci_host: remove code duplication in pci_host_template.h Isaku Yamahata
2010-01-12 8:52 ` [Qemu-devel] [PATCH 5/6] pci: introduce PCIAddress, PCIConfigAddress and helper functions Isaku Yamahata
2010-01-12 10:04 ` [Qemu-devel] " Michael S. Tsirkin
2010-01-12 10:06 ` Michael S. Tsirkin
2010-01-12 8:52 ` [Qemu-devel] [PATCH 6/6] pci host: make pci_data_{write, read}() get PCIConfigAddress Isaku Yamahata
2010-01-12 10:12 ` [Qemu-devel] " Michael S. Tsirkin
2010-01-12 10:43 ` Isaku Yamahata
2010-01-12 17:54 ` Alexander Graf
2010-01-13 13:08 ` Paul Brook
2010-01-12 17:54 ` [Qemu-devel] " Alexander Graf
2010-01-12 18:33 ` Michael S. Tsirkin [this message]
2010-01-13 12:09 ` Alexander Graf
2010-01-12 10:18 ` [Qemu-devel] Re: [PATCH 0/6] pci: pci_data_{write, read}() clean up Michael S. Tsirkin
2010-01-12 10:31 ` Alexander Graf
2010-01-12 10:39 ` Alexander Graf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100112183308.GA3036@redhat.com \
--to=mst@redhat.com \
--cc=agraf@suse.de \
--cc=aurelien@aurel32.net \
--cc=blauwirbel@gmail.com \
--cc=paul@codesourcery.com \
--cc=qemu-devel@nongnu.org \
--cc=yamahata@valinux.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).