From patchwork Tue Jan 12 18:33:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 42738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 999F11007D2 for ; Wed, 13 Jan 2010 05:39:49 +1100 (EST) Received: from localhost ([127.0.0.1]:58884 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUleC-0007C2-Jc for incoming@patchwork.ozlabs.org; Tue, 12 Jan 2010 13:39:20 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NUlbR-0006gG-FX for qemu-devel@nongnu.org; Tue, 12 Jan 2010 13:36:29 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NUlbM-0006dA-DF for qemu-devel@nongnu.org; Tue, 12 Jan 2010 13:36:28 -0500 Received: from [199.232.76.173] (port=57305 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUlbM-0006d1-5w for qemu-devel@nongnu.org; Tue, 12 Jan 2010 13:36:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:28201) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NUlbL-00020X-Js for qemu-devel@nongnu.org; Tue, 12 Jan 2010 13:36:23 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0CIa5ka025859 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 12 Jan 2010 13:36:05 -0500 Received: from redhat.com (dhcp-0-94.tlv.redhat.com [10.35.0.94]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o0CIa2fm021834; Tue, 12 Jan 2010 13:36:03 -0500 Date: Tue, 12 Jan 2010 20:33:08 +0200 From: "Michael S. Tsirkin" To: Alexander Graf Subject: Re: [Qemu-devel] [PATCH 6/6] pci host: make pci_data_{write, read}() get PCIConfigAddress. Message-ID: <20100112183308.GA3036@redhat.com> References: <1263286378-10398-1-git-send-email-yamahata@valinux.co.jp> <1263286378-10398-7-git-send-email-yamahata@valinux.co.jp> <4B4CB738.3000708@suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4B4CB738.3000708@suse.de> User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Blue Swirl , Isaku Yamahata , qemu-devel@nongnu.org, Aurelien Jarno , Paul Brook X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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;