From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Arnd Bergmann" <arnd@arndb.de>,
"Michael S. Tsirkin" <mst@redhat.com>,
patches@linaro.org, "Will Deacon" <will.deacon@arm.com>,
"Paul Brook" <paul@codesourcery.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH 08/10] versatile_pci: Implement the PCI controller's control registers
Date: Sun, 24 Mar 2013 11:32:38 +0000 [thread overview]
Message-ID: <1364124760-5794-9-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1364124760-5794-1-git-send-email-peter.maydell@linaro.org>
The versatile_pci PCI controller has a set of control registers which
handle the mapping between PCI and system address spaces. Implement
these registers (though for now they have no effect since we don't
implement mapping PCI space into system memory at all).
The most natural order for our sysbus regions has the control
registers at the start, so move all the others down one.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/arm/realview.c | 7 +--
hw/arm/versatilepb.c | 7 +--
hw/versatile_pci.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 138 insertions(+), 11 deletions(-)
diff --git a/hw/arm/realview.c b/hw/arm/realview.c
index 5fb490c..ba61d18 100644
--- a/hw/arm/realview.c
+++ b/hw/arm/realview.c
@@ -217,9 +217,10 @@ static void realview_init(QEMUMachineInitArgs *args,
dev = qdev_create(NULL, "realview_pci");
busdev = SYS_BUS_DEVICE(dev);
qdev_init_nofail(dev);
- sysbus_mmio_map(busdev, 0, 0x61000000); /* PCI self-config */
- sysbus_mmio_map(busdev, 1, 0x62000000); /* PCI config */
- sysbus_mmio_map(busdev, 2, 0x63000000); /* PCI I/O */
+ sysbus_mmio_map(busdev, 0, 0x10019000); /* PCI controller registers */
+ sysbus_mmio_map(busdev, 1, 0x61000000); /* PCI self-config */
+ sysbus_mmio_map(busdev, 2, 0x62000000); /* PCI config */
+ sysbus_mmio_map(busdev, 3, 0x63000000); /* PCI I/O */
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 0d08d15..9c9bfde 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -224,9 +224,10 @@ static void versatile_init(QEMUMachineInitArgs *args, int board_id)
dev = qdev_create(NULL, "versatile_pci");
busdev = SYS_BUS_DEVICE(dev);
qdev_init_nofail(dev);
- sysbus_mmio_map(busdev, 0, 0x41000000); /* PCI self-config */
- sysbus_mmio_map(busdev, 1, 0x42000000); /* PCI config */
- sysbus_mmio_map(busdev, 2, 0x43000000); /* PCI I/O */
+ sysbus_mmio_map(busdev, 0, 0x10001000); /* PCI controller regs */
+ 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_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 7739f4c..a617675 100644
--- a/hw/versatile_pci.c
+++ b/hw/versatile_pci.c
@@ -17,6 +17,7 @@ typedef struct {
PCIHostState parent_obj;
qemu_irq irq[4];
+ MemoryRegion controlregs;
MemoryRegion mem_config;
MemoryRegion mem_config2;
MemoryRegion pci_io_space;
@@ -27,8 +28,27 @@ typedef struct {
/* Constant for life of device: */
int realview;
uint8_t broken_irq_mapping;
+
+ /* Register state: */
+ uint32_t imap[3];
+ uint32_t smap[3];
+ uint32_t selfid;
+ uint32_t flags;
} PCIVPBState;
+static const VMStateDescription pci_vpb_vmstate = {
+ .name = "versatile-pci",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT32_ARRAY(imap, PCIVPBState, 3),
+ VMSTATE_UINT32_ARRAY(smap, PCIVPBState, 3),
+ VMSTATE_UINT32(selfid, PCIVPBState),
+ VMSTATE_UINT32(flags, PCIVPBState),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
#define TYPE_VERSATILE_PCI "versatile_pci"
#define PCI_VPB(obj) \
OBJECT_CHECK(PCIVPBState, (obj), TYPE_VERSATILE_PCI)
@@ -37,6 +57,93 @@ typedef struct {
#define PCI_VPB_HOST(obj) \
OBJECT_CHECK(PCIDevice, (obj), TYPE_VERSATILE_PCIHOST)
+typedef enum {
+ PCI_IMAP0 = 0x0,
+ PCI_IMAP1 = 0x4,
+ PCI_IMAP2 = 0x8,
+ PCI_SELFID = 0xc,
+ PCI_FLAGS = 0x10,
+ PCI_SMAP0 = 0x14,
+ PCI_SMAP1 = 0x18,
+ PCI_SMAP2 = 0x1c,
+} PCIVPBControlRegs;
+
+static void pci_vpb_reg_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+ PCIVPBState *s = opaque;
+
+ switch (addr) {
+ case PCI_IMAP0:
+ case PCI_IMAP1:
+ case PCI_IMAP2:
+ {
+ int win = (addr - PCI_IMAP0) >> 2;
+ s->imap[win] = val;
+ break;
+ }
+ case PCI_SELFID:
+ s->selfid = val;
+ break;
+ case PCI_FLAGS:
+ s->flags = val;
+ break;
+ case PCI_SMAP0:
+ case PCI_SMAP1:
+ case PCI_SMAP2:
+ {
+ int win = (addr - PCI_SMAP0) >> 2;
+ s->smap[win] = val;
+ break;
+ }
+ default:
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "pci_vpb_reg_write: Bad offset %x\n", (int)addr);
+ break;
+ }
+}
+
+static uint64_t pci_vpb_reg_read(void *opaque, hwaddr addr,
+ unsigned size)
+{
+ PCIVPBState *s = opaque;
+
+ switch (addr) {
+ case PCI_IMAP0:
+ case PCI_IMAP1:
+ case PCI_IMAP2:
+ {
+ int win = (addr - PCI_IMAP0) >> 2;
+ return s->imap[win];
+ }
+ case PCI_SELFID:
+ return s->selfid;
+ case PCI_FLAGS:
+ return s->flags;
+ case PCI_SMAP0:
+ case PCI_SMAP1:
+ case PCI_SMAP2:
+ {
+ int win = (addr - PCI_SMAP0) >> 2;
+ return s->smap[win];
+ }
+ default:
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "pci_vpb_reg_read: Bad offset %x\n", (int)addr);
+ return 0;
+ }
+}
+
+static const MemoryRegionOps pci_vpb_reg_ops = {
+ .read = pci_vpb_reg_read,
+ .write = pci_vpb_reg_write,
+ .endianness = DEVICE_NATIVE_ENDIAN,
+ .valid = {
+ .min_access_size = 4,
+ .max_access_size = 4,
+ },
+};
+
static inline uint32_t vpb_pci_config_addr(hwaddr addr)
{
return addr & 0xffffff;
@@ -115,6 +222,20 @@ static void pci_vpb_set_irq(void *opaque, int irq_num, int level)
qemu_set_irq(pic[irq_num], level);
}
+static void pci_vpb_reset(DeviceState *d)
+{
+ PCIVPBState *s = PCI_VPB(d);
+
+ s->imap[0] = 0;
+ s->imap[1] = 0;
+ s->imap[2] = 0;
+ s->smap[0] = 0;
+ s->smap[1] = 0;
+ s->smap[2] = 0;
+ s->selfid = 0;
+ s->flags = 0;
+}
+
static void pci_vpb_init(Object *obj)
{
PCIHostState *h = PCI_HOST_BRIDGE(obj);
@@ -154,13 +275,15 @@ static void pci_vpb_realize(DeviceState *dev, Error **errp)
pci_bus_irqs(&s->pci_bus, pci_vpb_set_irq, mapfn, s->irq, 4);
- /* ??? Register memory space. */
-
/* Our memory regions are:
- * 0 : PCI self config window
- * 1 : PCI config window
- * 2 : PCI IO window
+ * 0 : our control registers
+ * 1 : PCI self config window
+ * 2 : PCI config window
+ * 3 : PCI IO window
*/
+ memory_region_init_io(&s->controlregs, &pci_vpb_reg_ops, s, "pci-vpb-regs",
+ 0x1000);
+ sysbus_init_mmio(sbd, &s->controlregs);
memory_region_init_io(&s->mem_config, &pci_vpb_config_ops, &s->pci_bus,
"pci-vpb-selfconfig", 0x1000000);
sysbus_init_mmio(sbd, &s->mem_config);
@@ -216,6 +339,8 @@ static void pci_vpb_class_init(ObjectClass *klass, void *data)
dc->realize = pci_vpb_realize;
dc->props = pci_vpb_properties;
+ dc->reset = pci_vpb_reset;
+ dc->vmsd = &pci_vpb_vmstate;
}
static const TypeInfo pci_vpb_info = {
--
1.7.9.5
next prev parent reply other threads:[~2013-03-24 11:33 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-24 11:32 [Qemu-devel] [PATCH 00/10] Fix versatile_pci (and break versatilepb linux guests!) Peter Maydell
2013-03-24 11:32 ` [Qemu-devel] [PATCH 01/10] versatile_pci: Fix hardcoded tabs Peter Maydell
2013-03-24 11:32 ` [Qemu-devel] [PATCH 02/10] versatile_pci: Expose PCI I/O region on Versatile PB Peter Maydell
2013-03-25 1:01 ` Peter Crosthwaite
2013-03-25 9:47 ` Peter Maydell
2013-03-25 10:15 ` Peter Maydell
2013-03-24 11:32 ` [Qemu-devel] [PATCH 03/10] versatile_pci: Update to realize and instance init functions Peter Maydell
2013-03-24 11:32 ` [Qemu-devel] [PATCH 04/10] versatile_pci: Change to subclassing TYPE_PCI_HOST_BRIDGE Peter Maydell
2013-03-24 11:32 ` [Qemu-devel] [PATCH 05/10] versatile_pci: Use separate PCI I/O space rather than system I/O space Peter Maydell
2013-03-24 11:32 ` [Qemu-devel] [PATCH 06/10] versatile_pci: Put the host bridge PCI device at slot 29 Peter Maydell
2013-03-24 11:32 ` [Qemu-devel] [PATCH 07/10] versatile_pci: Implement the correct PCI IRQ mapping Peter Maydell
2013-03-25 12:12 ` Michael S. Tsirkin
2013-03-25 12:17 ` Peter Maydell
2013-03-25 12:28 ` Michael S. Tsirkin
2013-03-24 11:32 ` Peter Maydell [this message]
2013-03-24 11:32 ` [Qemu-devel] [PATCH 09/10] arm/realview: Fix mapping of PCI regions Peter Maydell
2013-03-24 11:32 ` [Qemu-devel] [PATCH 10/10] versatile_pci: Expose PCI memory space to system Peter Maydell
2013-03-24 15:58 ` [Qemu-devel] [PATCH 00/10] Fix versatile_pci (and break versatilepb linux guests!) Aurelien Jarno
2013-03-24 16:49 ` Peter Maydell
2013-03-24 20:12 ` Aurelien Jarno
2013-03-24 19:17 ` Michael S. Tsirkin
2013-03-24 20:53 ` Peter Maydell
2013-03-24 21:16 ` Arnd Bergmann
2013-03-24 21:29 ` Peter Maydell
2013-03-24 22:45 ` Arnd Bergmann
2013-03-24 21:37 ` Michael S. Tsirkin
2013-03-24 22:59 ` Arnd Bergmann
2013-03-25 11:56 ` Peter Maydell
2013-03-24 21:34 ` Michael S. Tsirkin
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=1364124760-5794-9-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=afaerber@suse.de \
--cc=arnd@arndb.de \
--cc=mst@redhat.com \
--cc=patches@linaro.org \
--cc=paul@codesourcery.com \
--cc=qemu-devel@nongnu.org \
--cc=will.deacon@arm.com \
/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).