From patchwork Wed Oct 31 05:57:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peter A. G. Crosthwaite" X-Patchwork-Id: 195745 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BBA2A2C00B1 for ; Wed, 31 Oct 2012 16:57:30 +1100 (EST) Received: from localhost ([::1]:58340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTRIu-0000yY-VY for incoming@patchwork.ozlabs.org; Wed, 31 Oct 2012 01:57:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTRIm-0000yH-Rf for qemu-devel@nongnu.org; Wed, 31 Oct 2012 01:57:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTRIl-0006zV-21 for qemu-devel@nongnu.org; Wed, 31 Oct 2012 01:57:20 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:63570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTRIk-0006zH-Ob for qemu-devel@nongnu.org; Wed, 31 Oct 2012 01:57:18 -0400 Received: by mail-pa0-f45.google.com with SMTP id fb10so690263pad.4 for ; Tue, 30 Oct 2012 22:57:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:x-gm-message-state; bh=pLE5NlM9yvLP1HUafP3vIEbKyUkHPeqY5pKp4aTDRfw=; b=l3QQzeT6beHj78Hne2coB6buOm2bpLiUgC5NoQJ+vRtbN1ASODZq8qj/SkIz4Xpjee /XBJdo8dRpqg5gO4ckNBFcw/pk6jN5+srWuftFbYh53Hbh3QF1aTKWuVc6AfhiK6Y0Ii 6mZRNnqapeEMnw7HWNdT7kh4Xpsz9OPUaZSeQ9lBbdMdk8HiYcsrKD2WS7DyfeUP5CHL T5t/CbnCjxSGjiJlH98mOQYKwAIpq08nCPu8ExzeQBg55jDtryuAm+l0Nyd0ehZNt4dx r/QtN8Ob2qgouK0unU20IOcUXHqVVe/ibKRwj6ly8iP8h/LOxvZbdHNANub16ivBrQBt Udow== Received: by 10.68.204.132 with SMTP id ky4mr108911961pbc.164.1351663036336; Tue, 30 Oct 2012 22:57:16 -0700 (PDT) Received: from [192.168.1.58] ([124.148.20.9]) by mx.google.com with ESMTPS id rg9sm924166pbc.46.2012.10.30.22.57.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 30 Oct 2012 22:57:15 -0700 (PDT) From: Peter Crosthwaite To: Gerd Hoffmann In-Reply-To: <1351607214-4007-15-git-send-email-kraxel@redhat.com> References: <1351607214-4007-1-git-send-email-kraxel@redhat.com> <1351607214-4007-15-git-send-email-kraxel@redhat.com> Date: Wed, 31 Oct 2012 15:57:11 +1000 Message-ID: <1351663031.24283.14.camel@PetaLogix-ws2> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 X-Gm-Message-State: ALoCoQlEHx17qFz5ru7UzdomDIGDlGKNiHEqCfD+TC6ewrm9Nkziy4Qwy+6f/szUZCR8HzaIkicj X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.220.45 Cc: qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH 14/22] usb/ehci: add sysbus variant X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org All good, Needs a hack to get around the dma_memory_foo segfault (attached), but that will come out in the wash with the memory API refactorings. Regards, Peter On Tue, 2012-10-30 at 15:26 +0100, Gerd Hoffmann wrote: > Signed-off-by: Gerd Hoffmann Reviewed-by: Peter Crosthwaite Tested-by: Peter Crosthwaite > --- > hw/usb/Makefile.objs | 2 +- > hw/usb/hcd-ehci-sysbus.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 78 insertions(+), 1 deletions(-) > create mode 100644 hw/usb/hcd-ehci-sysbus.c > > diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs > index 5c7b024..7669938 100644 > --- a/hw/usb/Makefile.objs > +++ b/hw/usb/Makefile.objs > @@ -1,6 +1,6 @@ > common-obj-$(CONFIG_USB_UHCI) += hcd-uhci.o > common-obj-$(CONFIG_USB_OHCI) += hcd-ohci.o > -common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o > +common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o hcd-ehci-sysbus.o > common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o > common-obj-y += libhw.o > > diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c > new file mode 100644 > index 0000000..1584079 > --- /dev/null > +++ b/hw/usb/hcd-ehci-sysbus.c > @@ -0,0 +1,77 @@ > +/* > + * QEMU USB EHCI Emulation > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2 of the License, or(at your option) any later version. > + * > + * This library 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 > + * Lesser 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 . > + */ > + > +#include "hw/usb/hcd-ehci.h" > +#include "hw/sysbus.h" > + > +typedef struct EHCISysBusState { > + SysBusDevice busdev; > + EHCIState ehci; > +} EHCISysBusState; > + > +static const VMStateDescription vmstate_ehci_sysbus = { > + .name = "ehci-sysbus", > + .version_id = 2, > + .minimum_version_id = 1, > + .fields = (VMStateField[]) { > + VMSTATE_STRUCT(ehci, EHCISysBusState, 2, vmstate_ehci, EHCIState), > + VMSTATE_END_OF_LIST() > + } > +}; > + > +static Property ehci_sysbus_properties[] = { > + DEFINE_PROP_UINT32("maxframes", EHCISysBusState, ehci.maxframes, 128), > + DEFINE_PROP_END_OF_LIST(), > +}; > + > +static int usb_ehci_sysbus_initfn(SysBusDevice *dev) > +{ > + EHCISysBusState *i = FROM_SYSBUS(EHCISysBusState, dev); > + EHCIState *s = &i->ehci; > + > + s->capsbase = 0x100; > + s->opregbase = 0x140; > + > + usb_ehci_initfn(s, DEVICE(dev)); > + sysbus_init_irq(dev, &s->irq); > + sysbus_init_mmio(dev, &s->mem); > + return 0; > +} > + > +static void ehci_sysbus_class_init(ObjectClass *klass, void *data) > +{ > + DeviceClass *dc = DEVICE_CLASS(klass); > + SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); > + > + k->init = usb_ehci_sysbus_initfn; > + dc->vmsd = &vmstate_ehci_sysbus; > + dc->props = ehci_sysbus_properties; > +} > + > +TypeInfo ehci_xlnx_type_info = { > + .name = "xlnx,ps7-usb", > + .parent = TYPE_SYS_BUS_DEVICE, > + .instance_size = sizeof(EHCISysBusState), > + .class_init = ehci_sysbus_class_init, > +}; > + > +static void ehci_sysbus_register_types(void) > +{ > + type_register_static(&ehci_xlnx_type_info); > +} > + > +type_init(ehci_sysbus_register_types) From b3dc8992bbea0358752efdd8ca8803c8f150f083 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 23 Oct 2012 18:26:51 +0100 Subject: [PATCH] dma: Define dma_context_memory and use by default Define a new global dma_context_memory which is a DMAContext corresponding to the global address_space_memory AddressSpace. This can be used by sysbus peripherals like sysbus-ohci which need to do DMA. [PC] Use this dma context by default if NULL is passed to the dma API for DMAContext *dma Signed-off-by: Peter Maydell Signed-off-by: Peter Crosthwaite --- dma.h | 17 +++++++++++++++++ exec.c | 5 +++++ 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/dma.h b/dma.h index 91ccdb5..defed50 100644 --- a/dma.h +++ b/dma.h @@ -68,6 +68,11 @@ struct DMAContext { DMAUnmapFunc *unmap; }; +/* A global DMA context corresponding to the address_space_memory + * AddressSpace, for sysbus devices which do DMA. + */ +extern DMAContext dma_context_memory; + static inline void dma_barrier(DMAContext *dma, DMADirection dir) { /* @@ -107,6 +112,9 @@ static inline bool dma_memory_valid(DMAContext *dma, dma_addr_t addr, dma_addr_t len, DMADirection dir) { + if (!dma) { + dma = &dma_context_memory; + } if (!dma_has_iommu(dma)) { return true; } else { @@ -120,6 +128,9 @@ static inline int dma_memory_rw_relaxed(DMAContext *dma, dma_addr_t addr, void *buf, dma_addr_t len, DMADirection dir) { + if (!dma) { + dma = &dma_context_memory; + } if (!dma_has_iommu(dma)) { /* Fast-path for no IOMMU */ address_space_rw(dma->as, addr, buf, len, dir == DMA_DIRECTION_FROM_DEVICE); @@ -176,6 +187,9 @@ static inline void *dma_memory_map(DMAContext *dma, dma_addr_t addr, dma_addr_t *len, DMADirection dir) { + if (!dma) { + dma = &dma_context_memory; + } if (!dma_has_iommu(dma)) { hwaddr xlen = *len; void *p; @@ -195,6 +209,9 @@ static inline void dma_memory_unmap(DMAContext *dma, void *buffer, dma_addr_t len, DMADirection dir, dma_addr_t access_len) { + if (!dma) { + dma = &dma_context_memory; + } if (!dma_has_iommu(dma)) { address_space_unmap(dma->as, buffer, (hwaddr)len, dir == DMA_DIRECTION_FROM_DEVICE, access_len); diff --git a/exec.c b/exec.c index b0ed593..d2f6e79 100644 --- a/exec.c +++ b/exec.c @@ -34,6 +34,7 @@ #include "hw/xen.h" #include "qemu-timer.h" #include "memory.h" +#include "dma.h" #include "exec-memory.h" #if defined(CONFIG_USER_ONLY) #include @@ -103,6 +104,7 @@ static MemoryRegion *system_io; AddressSpace address_space_io; AddressSpace address_space_memory; +DMAContext dma_context_memory; MemoryRegion io_mem_ram, io_mem_rom, io_mem_unassigned, io_mem_notdirty; static MemoryRegion io_mem_subpage_ram; @@ -3276,6 +3278,9 @@ static void memory_map_init(void) memory_listener_register(&core_memory_listener, &address_space_memory); memory_listener_register(&io_memory_listener, &address_space_io); memory_listener_register(&tcg_memory_listener, &address_space_memory); + + dma_context_init(&dma_context_memory, &address_space_memory, + NULL, NULL, NULL); } MemoryRegion *get_system_memory(void) -- 1.7.0.4