From patchwork Mon Feb 25 17:09:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 15077 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 628E823E24 for ; Mon, 25 Feb 2013 17:09:14 +0000 (UTC) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by fiordland.canonical.com (Postfix) with ESMTP id E1312A18AB8 for ; Mon, 25 Feb 2013 17:09:13 +0000 (UTC) Received: by mail-vc0-f170.google.com with SMTP id p16so1871659vcq.29 for ; Mon, 25 Feb 2013 09:09:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=5KKyeFilA8oPA9LBLd51/Gzl3n6D4FDHLNXIv9CFUDU=; b=eETWACEY0NtaEfuR6Nf1ZnxM+vw+263OFGgbBpvu2Bd3Q6chwYsPiiIR17VVi755LA 6r3YiD6WRB7Xqt1JUpvDp67EqFpcw90xPSqKWTV7VRGWDUYt03iqV+1kq8IxBLYCa3ms L2xisk98lw+IdCw5P5CZbyI0Ou62axGfanEqWeKbUSq+hF1enYL9AWKeVqrgMSUPOlhz /xUFt5aK6zTUmBvk6sjFqnlUaSbFGmCE9H/08VAyZ9GzHizDVtm4iVXNPoYzsNdyOroq g53oKNG1bPKE4z8hfqzCBJPnZERkvsr+pVIxATRXXFhl3p6mWr6rSgRPTtzWNAGk7Lzw pE2Q== X-Received: by 10.58.188.48 with SMTP id fx16mr10484655vec.22.1361812153328; Mon, 25 Feb 2013 09:09:13 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp68606veb; Mon, 25 Feb 2013 09:09:12 -0800 (PST) X-Received: by 10.67.5.193 with SMTP id co1mr20149320pad.6.1361812147494; Mon, 25 Feb 2013 09:09:07 -0800 (PST) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id o9si12819169paw.79.2013.02.25.09.09.06 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 25 Feb 2013 09:09:07 -0800 (PST) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1UA1Xy-0006wF-HY; Mon, 25 Feb 2013 17:09:02 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Michael Walle , Jan Kiszka , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Paolo Bonzini Subject: [PATCH v2 4/5] milkymist-softusb: Don't map RAM memory regions in the device itself Date: Mon, 25 Feb 2013 17:09:01 +0000 Message-Id: <1361812142-26640-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1361812142-26640-1-git-send-email-peter.maydell@linaro.org> References: <1361812142-26640-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQn9KV1SWvOySOUVYM5eHvWbHi9RXQ3w8t+kJNC7rNM4m6AWZvih936STp48g8cv3fyf8Sf3 Don't map the pmem and dmem RAM memory regions in the milkymist-softusb device itself. Instead just expose them as sysbus mmio regions which the device creator can map appropriately. This allows us to drop the pmem_base and dmem_base properties. Instead of going via cpu_physical_memory_read/_write when the device wants to access the RAMs, we just keep a host pointer to the memory and use that. Signed-off-by: Peter Maydell Reviewed-by: Andreas Färber Acked-by: Michael Walle --- hw/milkymist-hw.h | 4 ++-- hw/milkymist-softusb.c | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/hw/milkymist-hw.h b/hw/milkymist-hw.h index 21e202b..47f6d50 100644 --- a/hw/milkymist-hw.h +++ b/hw/milkymist-hw.h @@ -210,12 +210,12 @@ static inline DeviceState *milkymist_softusb_create(hwaddr base, DeviceState *dev; dev = qdev_create(NULL, "milkymist-softusb"); - qdev_prop_set_uint32(dev, "pmem_base", pmem_base); qdev_prop_set_uint32(dev, "pmem_size", pmem_size); - qdev_prop_set_uint32(dev, "dmem_base", dmem_base); qdev_prop_set_uint32(dev, "dmem_size", dmem_size); qdev_init_nofail(dev); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, pmem_base); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, dmem_base); sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq); return dev; diff --git a/hw/milkymist-softusb.c b/hw/milkymist-softusb.c index 01660be..a3e935f 100644 --- a/hw/milkymist-softusb.c +++ b/hw/milkymist-softusb.c @@ -54,10 +54,11 @@ struct MilkymistSoftUsbState { MemoryRegion dmem; qemu_irq irq; + void *pmem_ptr; + void *dmem_ptr; + /* device properties */ - uint32_t pmem_base; uint32_t pmem_size; - uint32_t dmem_base; uint32_t dmem_size; /* device registers */ @@ -134,7 +135,7 @@ static inline void softusb_read_dmem(MilkymistSoftUsbState *s, return; } - cpu_physical_memory_read(s->dmem_base + offset, buf, len); + memcpy(buf, s->dmem_ptr + offset, len); } static inline void softusb_write_dmem(MilkymistSoftUsbState *s, @@ -146,7 +147,7 @@ static inline void softusb_write_dmem(MilkymistSoftUsbState *s, return; } - cpu_physical_memory_write(s->dmem_base + offset, buf, len); + memcpy(s->dmem_ptr + offset, buf, len); } static inline void softusb_read_pmem(MilkymistSoftUsbState *s, @@ -158,7 +159,7 @@ static inline void softusb_read_pmem(MilkymistSoftUsbState *s, return; } - cpu_physical_memory_read(s->pmem_base + offset, buf, len); + memcpy(buf, s->pmem_ptr + offset, len); } static inline void softusb_write_pmem(MilkymistSoftUsbState *s, @@ -170,7 +171,7 @@ static inline void softusb_write_pmem(MilkymistSoftUsbState *s, return; } - cpu_physical_memory_write(s->pmem_base + offset, buf, len); + memcpy(s->pmem_ptr + offset, buf, len); } static void softusb_mouse_changed(MilkymistSoftUsbState *s) @@ -270,11 +271,13 @@ static int milkymist_softusb_init(SysBusDevice *dev) memory_region_init_ram(&s->pmem, "milkymist-softusb.pmem", s->pmem_size); vmstate_register_ram_global(&s->pmem); - sysbus_add_memory(dev, s->pmem_base, &s->pmem); + s->pmem_ptr = memory_region_get_ram_ptr(&s->pmem); + sysbus_init_mmio(dev, &s->pmem); memory_region_init_ram(&s->dmem, "milkymist-softusb.dmem", s->dmem_size); vmstate_register_ram_global(&s->dmem); - sysbus_add_memory(dev, s->dmem_base, &s->dmem); + s->dmem_ptr = memory_region_get_ram_ptr(&s->dmem); + sysbus_init_mmio(dev, &s->dmem); hid_init(&s->hid_kbd, HID_KEYBOARD, softusb_kbd_hid_datain); hid_init(&s->hid_mouse, HID_MOUSE, softusb_mouse_hid_datain); @@ -298,9 +301,7 @@ static const VMStateDescription vmstate_milkymist_softusb = { }; static Property milkymist_softusb_properties[] = { - DEFINE_PROP_UINT32("pmem_base", MilkymistSoftUsbState, pmem_base, 0xa0000000), DEFINE_PROP_UINT32("pmem_size", MilkymistSoftUsbState, pmem_size, 0x00001000), - DEFINE_PROP_UINT32("dmem_base", MilkymistSoftUsbState, dmem_base, 0xa0020000), DEFINE_PROP_UINT32("dmem_size", MilkymistSoftUsbState, dmem_size, 0x00002000), DEFINE_PROP_END_OF_LIST(), };