From patchwork Sat Apr 6 15:44:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 15956 Return-Path: X-Original-To: linaro@staging.patches.linaro.org Delivered-To: linaro@staging.patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9749A26EC2 for ; Sat, 6 Apr 2013 16:13:21 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id jw11sf7496531veb.2 for ; Sat, 06 Apr 2013 09:13:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :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:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=5e0PNFYwVW+eNmPU833piocoQko/tDdmh01mfuhozL8=; b=pfi8aOitVSNkRN8IVdBuIHYvCcNGoupHDzzMxhgsPccmMPOt7Cg/OACtdDmwQwadOH QVpTErL2ZXnWNuq81cI9v+tNsTlIPBlGVfRnF76STHqZRuKhxh2TvFncqzjsCjLUIU3I CrOPB7SqetVFY238knI1rLd/Shy5vaBIKpRkmxEORaoZD8H0jpiRhHYxjKKg47j2K6aE NlXv/I8GLEZTJRA7tIaRtD92506cIcTwpZC05pIZ4YzQCwLRSecmdMYl4/UR+5kdi8Jn xOKkb3FPwtsJwE6BQhSAkR4NlcqzoXlGAavIZyx7bDEyq7gdul7P/cLrtnedXjkmhFfr yN/A== X-Received: by 10.224.160.65 with SMTP id m1mr1530136qax.2.1365264791503; Sat, 06 Apr 2013 09:13:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.18.162 with SMTP id x2ls2491581qed.37.gmail; Sat, 06 Apr 2013 09:13:11 -0700 (PDT) X-Received: by 10.52.119.175 with SMTP id kv15mr9509660vdb.23.1365264791387; Sat, 06 Apr 2013 09:13:11 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id ii11si13879693vcb.42.2013.04.06.09.13.11 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 06 Apr 2013 09:13:11 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id kw10so1693001vcb.5 for ; Sat, 06 Apr 2013 09:13:11 -0700 (PDT) X-Received: by 10.220.77.138 with SMTP id g10mr5928077vck.69.1365264791260; Sat, 06 Apr 2013 09:13:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.85.136 with SMTP id h8csp297364vez; Sat, 6 Apr 2013 09:13:10 -0700 (PDT) X-Received: by 10.180.82.33 with SMTP id f1mr4717713wiy.13.1365264789805; Sat, 06 Apr 2013 09:13:09 -0700 (PDT) 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 hg8si7500831wjb.126.2013.04.06.09.13.09 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 06 Apr 2013 09:13:09 -0700 (PDT) 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; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1UOVID-0004PU-A2; Sat, 06 Apr 2013 16:44:37 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , "Michael S. Tsirkin" , Paul Brook , Arnd Bergmann , Will Deacon Subject: [PATCH v4 10/11] versatile_pci: Expose PCI memory space to system Date: Sat, 6 Apr 2013 16:44:35 +0100 Message-Id: <1365263076-16909-11-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1365263076-16909-1-git-send-email-peter.maydell@linaro.org> References: <1365263076-16909-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQk5lwPCyEYEHgrOQbXHBdozW0K61036cVaThVMc+1gTv4VXMZ53ZKGDoedBSNHrBCEzNGYE X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The VersatilePB's PCI controller exposes the PCI memory space to the system via three regions controlled by the mapping control registers. Implement this so that guests can actually use MMIO-BAR PCI cards. Signed-off-by: Peter Maydell Acked-by: Paul Brook --- hw/arm/realview.c | 3 +++ hw/arm/versatilepb.c | 3 +++ hw/versatile_pci.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/hw/arm/realview.c b/hw/arm/realview.c index 23c968b..db41525 100644 --- a/hw/arm/realview.c +++ b/hw/arm/realview.c @@ -221,6 +221,9 @@ static void realview_init(QEMUMachineInitArgs *args, sysbus_mmio_map(busdev, 1, 0x60000000); /* PCI self-config */ sysbus_mmio_map(busdev, 2, 0x61000000); /* PCI config */ sysbus_mmio_map(busdev, 3, 0x62000000); /* PCI I/O */ + sysbus_mmio_map(busdev, 4, 0x63000000); /* PCI memory window 1 */ + sysbus_mmio_map(busdev, 5, 0x64000000); /* PCI memory window 2 */ + sysbus_mmio_map(busdev, 6, 0x68000000); /* PCI memory window 3 */ sysbus_connect_irq(busdev, 0, pic[48]); sysbus_connect_irq(busdev, 1, pic[49]); sysbus_connect_irq(busdev, 2, pic[50]); diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c index 9c9bfde..413f0e9 100644 --- a/hw/arm/versatilepb.c +++ b/hw/arm/versatilepb.c @@ -228,6 +228,9 @@ static void versatile_init(QEMUMachineInitArgs *args, int board_id) sysbus_mmio_map(busdev, 1, 0x41000000); /* PCI self-config */ sysbus_mmio_map(busdev, 2, 0x42000000); /* PCI config */ sysbus_mmio_map(busdev, 3, 0x43000000); /* PCI I/O */ + sysbus_mmio_map(busdev, 4, 0x44000000); /* PCI memory window 1 */ + sysbus_mmio_map(busdev, 5, 0x50000000); /* PCI memory window 2 */ + sysbus_mmio_map(busdev, 6, 0x60000000); /* PCI memory window 3 */ sysbus_connect_irq(busdev, 0, sic[27]); sysbus_connect_irq(busdev, 1, sic[28]); sysbus_connect_irq(busdev, 2, sic[29]); diff --git a/hw/versatile_pci.c b/hw/versatile_pci.c index b0132e6..e99f35f 100644 --- a/hw/versatile_pci.c +++ b/hw/versatile_pci.c @@ -42,13 +42,20 @@ typedef struct { MemoryRegion controlregs; MemoryRegion mem_config; MemoryRegion mem_config2; + /* Containers representing the PCI address spaces */ MemoryRegion pci_io_space; + MemoryRegion pci_mem_space; + /* Alias regions into PCI address spaces which we expose as sysbus regions. + * The offsets into pci_mem_space are controlled by the imap registers. + */ MemoryRegion pci_io_window; + MemoryRegion pci_mem_window[3]; PCIBus pci_bus; PCIDevice pci_dev; /* Constant for life of device: */ int realview; + uint32_t mem_win_size[3]; /* Variable state: */ uint32_t imap[3]; @@ -58,10 +65,49 @@ typedef struct { uint8_t irq_mapping; } PCIVPBState; +static void pci_vpb_update_window(PCIVPBState *s, int i) +{ + /* Adjust the offset of the alias region we use for + * the memory window i to account for a change in the + * value of the corresponding IMAP register. + * Note that the semantics of the IMAP register differ + * for realview and versatile variants of the controller. + */ + hwaddr offset; + if (s->realview) { + /* Top bits of register (masked according to window size) provide + * top bits of PCI address. + */ + offset = s->imap[i] & ~(s->mem_win_size[i] - 1); + } else { + /* Bottom 4 bits of register provide top 4 bits of PCI address */ + offset = s->imap[i] << 28; + } + memory_region_set_alias_offset(&s->pci_mem_window[i], offset); +} + +static void pci_vpb_update_all_windows(PCIVPBState *s) +{ + /* Update all alias windows based on the current register state */ + int i; + + for (i = 0; i < 3; i++) { + pci_vpb_update_window(s, i); + } +} + +static int pci_vpb_post_load(void *opaque, int version_id) +{ + PCIVPBState *s = opaque; + pci_vpb_update_all_windows(s); + return 0; +} + static const VMStateDescription pci_vpb_vmstate = { .name = "versatile-pci", .version_id = 1, .minimum_version_id = 1, + .post_load = pci_vpb_post_load, .fields = (VMStateField[]) { VMSTATE_UINT32_ARRAY(imap, PCIVPBState, 3), VMSTATE_UINT32_ARRAY(smap, PCIVPBState, 3), @@ -103,6 +149,7 @@ static void pci_vpb_reg_write(void *opaque, hwaddr addr, { int win = (addr - PCI_IMAP0) >> 2; s->imap[win] = val; + pci_vpb_update_window(s, win); break; } case PCI_SELFID: @@ -270,6 +317,8 @@ static void pci_vpb_reset(DeviceState *d) s->selfid = 0; s->flags = 0; s->irq_mapping = PCI_VPB_IRQMAP_ASSUME_OK; + + pci_vpb_update_all_windows(s); } static void pci_vpb_init(Object *obj) @@ -278,9 +327,10 @@ static void pci_vpb_init(Object *obj) PCIVPBState *s = PCI_VPB(obj); memory_region_init(&s->pci_io_space, "pci_io", 1ULL << 32); + memory_region_init(&s->pci_mem_space, "pci_mem", 1ULL << 32); pci_bus_new_inplace(&s->pci_bus, DEVICE(obj), "pci", - get_system_memory(), &s->pci_io_space, + &s->pci_mem_space, &s->pci_io_space, PCI_DEVFN(11, 0), TYPE_PCI_BUS); h->bus = &s->pci_bus; @@ -288,6 +338,11 @@ static void pci_vpb_init(Object *obj) qdev_set_parent_bus(DEVICE(&s->pci_dev), BUS(&s->pci_bus)); object_property_set_int(OBJECT(&s->pci_dev), PCI_DEVFN(29, 0), "addr", NULL); + + /* Window sizes for VersatilePB; realview_pci's init will override */ + s->mem_win_size[0] = 0x0c000000; + s->mem_win_size[1] = 0x10000000; + s->mem_win_size[2] = 0x10000000; } static void pci_vpb_realize(DeviceState *dev, Error **errp) @@ -314,6 +369,7 @@ static void pci_vpb_realize(DeviceState *dev, Error **errp) * 1 : PCI self config window * 2 : PCI config window * 3 : PCI IO window + * 4..6 : PCI memory windows */ memory_region_init_io(&s->controlregs, &pci_vpb_reg_ops, s, "pci-vpb-regs", 0x1000); @@ -333,6 +389,16 @@ static void pci_vpb_realize(DeviceState *dev, Error **errp) sysbus_init_mmio(sbd, &s->pci_io_space); + /* Create the alias regions corresponding to our three windows onto + * PCI memory space. The sizes vary from board to board; the base + * offsets are guest controllable via the IMAP registers. + */ + for (i = 0; i < 3; i++) { + memory_region_init_alias(&s->pci_mem_window[i], "pci-vbp-window", + &s->pci_mem_space, 0, s->mem_win_size[i]); + sysbus_init_mmio(sbd, &s->pci_mem_window[i]); + } + /* TODO Remove once realize propagates to child devices. */ object_property_set_bool(OBJECT(&s->pci_dev), true, "realized", errp); } @@ -384,6 +450,10 @@ static void pci_realview_init(Object *obj) PCIVPBState *s = PCI_VPB(obj); s->realview = 1; + /* The PCI window sizes are different on Realview boards */ + s->mem_win_size[0] = 0x01000000; + s->mem_win_size[1] = 0x04000000; + s->mem_win_size[2] = 0x08000000; } static const TypeInfo pci_realview_info = {