qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/6] pci: various clean up and 64bit bar support.
@ 2009-07-07  6:59 Isaku Yamahata
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 1/6] pci.c: remove unnecessary #ifdef DEBUG_PCI Isaku Yamahata
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Isaku Yamahata @ 2009-07-07  6:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: yamahata

The first 4 patches are trivial clean up patches, so they are
ready to commit.
The last 2 patches implement pci 64bit bar support.
At this moment there is no user. I'm implementing
q35 based chipset emulator which uses 64bit bar.

thanks,

Isaku Yamahata (6):
  pci.c: remove unnecessary #ifdef DEBUG_PCI.
  pci: use uint8_t for pci_register_bar() type argument of int.
  pci: minor clean up of pci_update_mappings().
  pci: define a constant to represent a unmapped bar and use it.
  pci: use uint64_t for bar addr and size instead of uint32_t.
  pci: 64bit bar support.

 hw/ac97.c         |    2 +-
 hw/cirrus_vga.c   |    6 +-
 hw/e1000.c        |   12 +++--
 hw/eepro100.c     |    8 ++--
 hw/ide.c          |    4 +-
 hw/lsi53c895a.c   |    6 +-
 hw/msix.c         |    2 +-
 hw/msix.h         |    2 +-
 hw/ne2000.c       |    2 +-
 hw/pci.c          |  110 ++++++++++++++++++++++++++++++++++++----------------
 hw/pci.h          |   18 +++++++--
 hw/pcnet.c        |    9 ++--
 hw/rtl8139.c      |    4 +-
 hw/usb-ohci.c     |    2 +-
 hw/usb-uhci.c     |    2 +-
 hw/vga.c          |    2 +-
 hw/virtio-pci.c   |    2 +-
 hw/vmware_vga.c   |    4 +-
 hw/wdt_i6300esb.c |    5 +-
 19 files changed, 129 insertions(+), 73 deletions(-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 1/6] pci.c: remove unnecessary #ifdef DEBUG_PCI.
  2009-07-07  6:59 [Qemu-devel] [PATCH 0/6] pci: various clean up and 64bit bar support Isaku Yamahata
@ 2009-07-07  6:59 ` Isaku Yamahata
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 2/6] pci: use uint8_t for pci_register_bar() type argument of int Isaku Yamahata
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Isaku Yamahata @ 2009-07-07  6:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: yamahata

remove unnecessary #ifdef DEBUG_PCI.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/pci.c |   29 +++++++++++++++--------------
 1 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 4458079..7ee9dde 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -28,6 +28,11 @@
 #include "sysemu.h"
 
 //#define DEBUG_PCI
+#ifdef DEBUG_PCI
+# define PCI_DPRINTF(format, ...)       printf(format, __VA_ARGS__)
+#else
+# define PCI_DPRINTF(format, ...)       do { } while (0)
+#endif
 
 struct PCIBus {
     BusState qbus;
@@ -540,9 +545,9 @@ void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len)
     PCIDevice *pci_dev;
     int config_addr, bus_num;
 
-#if defined(DEBUG_PCI) && 0
-    printf("pci_data_write: addr=%08x val=%08x len=%d\n",
-           addr, val, len);
+#if 0
+    PCI_DPRINTF("pci_data_write: addr=%08x val=%08x len=%d\n",
+                addr, val, len);
 #endif
     bus_num = (addr >> 16) & 0xff;
     while (s && s->bus_num != bus_num)
@@ -553,10 +558,8 @@ void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len)
     if (!pci_dev)
         return;
     config_addr = addr & 0xff;
-#if defined(DEBUG_PCI)
-    printf("pci_config_write: %s: addr=%02x val=%08x len=%d\n",
-           pci_dev->name, config_addr, val, len);
-#endif
+    PCI_DPRINTF("pci_config_write: %s: addr=%02x val=%08x len=%d\n",
+                pci_dev->name, config_addr, val, len);
     pci_dev->config_write(pci_dev, config_addr, val, len);
 }
 
@@ -591,14 +594,12 @@ uint32_t pci_data_read(void *opaque, uint32_t addr, int len)
     }
     config_addr = addr & 0xff;
     val = pci_dev->config_read(pci_dev, config_addr, len);
-#if defined(DEBUG_PCI)
-    printf("pci_config_read: %s: addr=%02x val=%08x len=%d\n",
-           pci_dev->name, config_addr, val, len);
-#endif
+    PCI_DPRINTF("pci_config_read: %s: addr=%02x val=%08x len=%d\n",
+                pci_dev->name, config_addr, val, len);
  the_end:
-#if defined(DEBUG_PCI) && 0
-    printf("pci_data_read: addr=%08x val=%08x len=%d\n",
-           addr, val, len);
+#if 0
+    PCI_DPRINTF("pci_data_read: addr=%08x val=%08x len=%d\n",
+                addr, val, len);
 #endif
     return val;
 }
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 2/6] pci: use uint8_t for pci_register_bar() type argument of int.
  2009-07-07  6:59 [Qemu-devel] [PATCH 0/6] pci: various clean up and 64bit bar support Isaku Yamahata
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 1/6] pci.c: remove unnecessary #ifdef DEBUG_PCI Isaku Yamahata
@ 2009-07-07  6:59 ` Isaku Yamahata
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 3/6] pci: minor clean up of pci_update_mappings() Isaku Yamahata
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Isaku Yamahata @ 2009-07-07  6:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: yamahata

use uint8_t for pci_register_bar() type argument instead of int.
uint8_t is more appropriate because PCIIORegion::type is uint8_t.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/pci.c |    2 +-
 hw/pci.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 7ee9dde..289a62f 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -381,7 +381,7 @@ int pci_unregister_device(PCIDevice *pci_dev)
 }
 
 void pci_register_bar(PCIDevice *pci_dev, int region_num,
-                            uint32_t size, int type,
+                            uint32_t size, int8_t type,
                             PCIMapIORegionFunc *map_func)
 {
     PCIIORegion *r;
diff --git a/hw/pci.h b/hw/pci.h
index cb0e382..7e99cf6 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -218,7 +218,7 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name,
 int pci_unregister_device(PCIDevice *pci_dev);
 
 void pci_register_bar(PCIDevice *pci_dev, int region_num,
-                            uint32_t size, int type,
+                            uint32_t size, int8_t type,
                             PCIMapIORegionFunc *map_func);
 
 int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 3/6] pci: minor clean up of pci_update_mappings().
  2009-07-07  6:59 [Qemu-devel] [PATCH 0/6] pci: various clean up and 64bit bar support Isaku Yamahata
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 1/6] pci.c: remove unnecessary #ifdef DEBUG_PCI Isaku Yamahata
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 2/6] pci: use uint8_t for pci_register_bar() type argument of int Isaku Yamahata
@ 2009-07-07  6:59 ` Isaku Yamahata
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 4/6] pci: define a constant to represent a unmapped bar and use it Isaku Yamahata
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Isaku Yamahata @ 2009-07-07  6:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: yamahata

use uint8_t for pci command register instead of int.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/pci.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 289a62f..7c7bab5 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -419,7 +419,8 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
 static void pci_update_mappings(PCIDevice *d)
 {
     PCIIORegion *r;
-    int cmd, i;
+    int i;
+    uint16_t cmd;
     uint32_t last_addr, new_addr, config_ofs;
 
     cmd = le16_to_cpu(*(uint16_t *)(d->config + PCI_COMMAND));
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 4/6] pci: define a constant to represent a unmapped bar and use it.
  2009-07-07  6:59 [Qemu-devel] [PATCH 0/6] pci: various clean up and 64bit bar support Isaku Yamahata
                   ` (2 preceding siblings ...)
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 3/6] pci: minor clean up of pci_update_mappings() Isaku Yamahata
@ 2009-07-07  6:59 ` Isaku Yamahata
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 5/6] pci: use uint64_t for bar addr and size instead of uint32_t Isaku Yamahata
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 6/6] pci: 64bit bar support Isaku Yamahata
  5 siblings, 0 replies; 7+ messages in thread
From: Isaku Yamahata @ 2009-07-07  6:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: yamahata

define a constant to represent a unmapped bar and use it.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/cirrus_vga.c |    2 +-
 hw/pci.c        |   18 +++++++++---------
 hw/pci.h        |    1 +
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 902b3ee..0b4615d 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -3296,7 +3296,7 @@ static void pci_cirrus_write_config(PCIDevice *d,
     CirrusVGAState *s = &pvs->cirrus_vga;
 
     pci_default_write_config(d, address, val, len);
-    if (s->vga.map_addr && pvs->dev.io_regions[0].addr == -1)
+    if (s->vga.map_addr && pvs->dev.io_regions[0].addr == PCI_BAR_UNMAPPED)
         s->vga.map_addr = 0;
     cirrus_update_memory_access(s);
 }
diff --git a/hw/pci.c b/hw/pci.c
index 7c7bab5..aa3e188 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -351,7 +351,7 @@ static void pci_unregister_io_regions(PCIDevice *pci_dev)
 
     for(i = 0; i < PCI_NUM_REGIONS; i++) {
         r = &pci_dev->io_regions[i];
-        if (!r->size || r->addr == -1)
+        if (!r->size || r->addr == PCI_BAR_UNMAPPED)
             continue;
         if (r->type == PCI_ADDRESS_SPACE_IO) {
             isa_unassign_ioport(r->addr, r->size);
@@ -398,7 +398,7 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
     }
 
     r = &pci_dev->io_regions[region_num];
-    r->addr = -1;
+    r->addr = PCI_BAR_UNMAPPED;
     r->size = size;
     r->type = type;
     r->map_func = map_func;
@@ -441,10 +441,10 @@ static void pci_update_mappings(PCIDevice *d)
                     /* NOTE: we have only 64K ioports on PC */
                     if (last_addr <= new_addr || new_addr == 0 ||
                         last_addr >= 0x10000) {
-                        new_addr = -1;
+                        new_addr = PCI_BAR_UNMAPPED;
                     }
                 } else {
-                    new_addr = -1;
+                    new_addr = PCI_BAR_UNMAPPED;
                 }
             } else {
                 if (cmd & PCI_COMMAND_MEMORY) {
@@ -460,17 +460,17 @@ static void pci_update_mappings(PCIDevice *d)
                        mappings, we handle specific values as invalid
                        mappings. */
                     if (last_addr <= new_addr || new_addr == 0 ||
-                        last_addr == -1) {
-                        new_addr = -1;
+                        last_addr == PCI_BAR_UNMAPPED) {
+                        new_addr = PCI_BAR_UNMAPPED;
                     }
                 } else {
                 no_mem_map:
-                    new_addr = -1;
+                    new_addr = PCI_BAR_UNMAPPED;
                 }
             }
             /* now do the real mapping */
             if (new_addr != r->addr) {
-                if (r->addr != -1) {
+                if (r->addr != PCI_BAR_UNMAPPED) {
                     if (r->type & PCI_ADDRESS_SPACE_IO) {
                         int class;
                         /* NOTE: specific hack for IDE in PC case:
@@ -489,7 +489,7 @@ static void pci_update_mappings(PCIDevice *d)
                     }
                 }
                 r->addr = new_addr;
-                if (r->addr != -1) {
+                if (r->addr != PCI_BAR_UNMAPPED) {
                     r->map_func(d, i, r->addr, r->size, r->type);
                 }
             }
diff --git a/hw/pci.h b/hw/pci.h
index 7e99cf6..a3d755d 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -84,6 +84,7 @@ typedef int PCIUnregisterFunc(PCIDevice *pci_dev);
 
 typedef struct PCIIORegion {
     uint32_t addr; /* current PCI mapping address. -1 means not mapped */
+#define PCI_BAR_UNMAPPED        (~(uint32_t)0)
     uint32_t size;
     uint8_t type;
     PCIMapIORegionFunc *map_func;
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 5/6] pci: use uint64_t for bar addr and size instead of uint32_t.
  2009-07-07  6:59 [Qemu-devel] [PATCH 0/6] pci: various clean up and 64bit bar support Isaku Yamahata
                   ` (3 preceding siblings ...)
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 4/6] pci: define a constant to represent a unmapped bar and use it Isaku Yamahata
@ 2009-07-07  6:59 ` Isaku Yamahata
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 6/6] pci: 64bit bar support Isaku Yamahata
  5 siblings, 0 replies; 7+ messages in thread
From: Isaku Yamahata @ 2009-07-07  6:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: yamahata

This patch is preliminary for 64bit bar support.
For 64bit bar support, replace uint32_t with uint64_t.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/ac97.c         |    2 +-
 hw/cirrus_vga.c   |    4 ++--
 hw/e1000.c        |   12 +++++++-----
 hw/eepro100.c     |    8 ++++----
 hw/ide.c          |    4 ++--
 hw/lsi53c895a.c   |    6 +++---
 hw/msix.c         |    2 +-
 hw/msix.h         |    2 +-
 hw/ne2000.c       |    2 +-
 hw/pci.c          |   21 +++++++++++++--------
 hw/pci.h          |   11 ++++++-----
 hw/pcnet.c        |    9 +++++----
 hw/rtl8139.c      |    4 ++--
 hw/usb-ohci.c     |    2 +-
 hw/usb-uhci.c     |    2 +-
 hw/vga.c          |    2 +-
 hw/virtio-pci.c   |    2 +-
 hw/vmware_vga.c   |    4 ++--
 hw/wdt_i6300esb.c |    5 +++--
 19 files changed, 57 insertions(+), 47 deletions(-)

diff --git a/hw/ac97.c b/hw/ac97.c
index b9dac3c..0d50966 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -1267,7 +1267,7 @@ static int ac97_load (QEMUFile *f, void *opaque, int version_id)
 }
 
 static void ac97_map (PCIDevice *pci_dev, int region_num,
-                      uint32_t addr, uint32_t size, int type)
+                      uint64_t addr, uint64_t size, int type)
 {
     PCIAC97LinkState *d = (PCIAC97LinkState *) pci_dev;
     AC97LinkState *s = &d->ac97;
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 0b4615d..5c2067b 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -3260,7 +3260,7 @@ void isa_cirrus_vga_init(void)
  ***************************************/
 
 static void cirrus_pci_lfb_map(PCIDevice *d, int region_num,
-			       uint32_t addr, uint32_t size, int type)
+			       uint64_t addr, uint64_t size, int type)
 {
     CirrusVGAState *s = &((PCICirrusVGAState *)d)->cirrus_vga;
 
@@ -3281,7 +3281,7 @@ static void cirrus_pci_lfb_map(PCIDevice *d, int region_num,
 }
 
 static void cirrus_pci_mmio_map(PCIDevice *d, int region_num,
-				uint32_t addr, uint32_t size, int type)
+				uint64_t addr, uint64_t size, int type)
 {
     CirrusVGAState *s = &((PCICirrusVGAState *)d)->cirrus_vga;
 
diff --git a/hw/e1000.c b/hw/e1000.c
index da07c46..8bbe2e6 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -143,10 +143,11 @@ static const char phy_regcap[0x20] = {
 };
 
 static void
-ioport_map(PCIDevice *pci_dev, int region_num, uint32_t addr,
-           uint32_t size, int type)
+ioport_map(PCIDevice *pci_dev, int region_num, uint64_t addr,
+           uint64_t size, int type)
 {
-    DBGOUT(IO, "e1000_ioport_map addr=0x%04x size=0x%08x\n", addr, size);
+    DBGOUT(IO, "e1000_ioport_map addr=0x%04"PRIx64" size=0x%08"PRIx64"\n",
+           addr, size);
 }
 
 static void
@@ -1021,7 +1022,7 @@ static CPUReadMemoryFunc *e1000_mmio_read[] = {
 
 static void
 e1000_mmio_map(PCIDevice *pci_dev, int region_num,
-                uint32_t addr, uint32_t size, int type)
+                uint64_t addr, uint64_t size, int type)
 {
     E1000State *d = (E1000State *)pci_dev;
     int i;
@@ -1031,7 +1032,8 @@ e1000_mmio_map(PCIDevice *pci_dev, int region_num,
     };
 
 
-    DBGOUT(MMIO, "e1000_mmio_map addr=0x%08x 0x%08x\n", addr, size);
+    DBGOUT(MMIO, "e1000_mmio_map addr=0x%08"PRIx64" 0x%08"PRIx64"\n",
+           addr, size);
 
     cpu_register_physical_memory(addr, PNPMMIO_SIZE, d->mmio_index);
     qemu_register_coalesced_mmio(addr, excluded_regs[0]);
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 0002140..b7f189c 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1345,12 +1345,12 @@ typedef struct PCIEEPRO100State {
 } PCIEEPRO100State;
 
 static void pci_map(PCIDevice * pci_dev, int region_num,
-                    uint32_t addr, uint32_t size, int type)
+                    uint64_t addr, uint64_t size, int type)
 {
     PCIEEPRO100State *d = (PCIEEPRO100State *) pci_dev;
     EEPRO100State *s = &d->eepro100;
 
-    logout("region %d, addr=0x%08x, size=0x%08x, type=%d\n",
+    logout("region %d, addr=0x%08"PRIx64", size=0x%08"PRIx64", type=%d\n",
            region_num, addr, size, type);
 
     assert(region_num == 1);
@@ -1419,11 +1419,11 @@ static CPUReadMemoryFunc *pci_mmio_read[] = {
 };
 
 static void pci_mmio_map(PCIDevice * pci_dev, int region_num,
-                         uint32_t addr, uint32_t size, int type)
+                         uint64_t addr, uint64_t size, int type)
 {
     PCIEEPRO100State *d = (PCIEEPRO100State *) pci_dev;
 
-    logout("region %d, addr=0x%08x, size=0x%08x, type=%d\n",
+    logout("region %d, addr=0x%08"PRIx64", size=0x%08"PRIx64", type=%d\n",
            region_num, addr, size, type);
 
     if (region_num == 0) {
diff --git a/hw/ide.c b/hw/ide.c
index 1e56786..d2f801a 100644
--- a/hw/ide.c
+++ b/hw/ide.c
@@ -2921,7 +2921,7 @@ void isa_ide_init(int iobase, int iobase2, qemu_irq irq,
 static void cmd646_update_irq(PCIIDEState *d);
 
 static void ide_map(PCIDevice *pci_dev, int region_num,
-                    uint32_t addr, uint32_t size, int type)
+                    uint64_t addr, uint64_t size, int type)
 {
     PCIIDEState *d = (PCIIDEState *)pci_dev;
     IDEState *ide_state;
@@ -3152,7 +3152,7 @@ static void bmdma_addr_writel(void *opaque, uint32_t addr, uint32_t val)
 }
 
 static void bmdma_map(PCIDevice *pci_dev, int region_num,
-                    uint32_t addr, uint32_t size, int type)
+                    uint64_t addr, uint64_t size, int type)
 {
     PCIIDEState *d = (PCIIDEState *)pci_dev;
     int i;
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index 71f8281..07d1feb 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -1923,7 +1923,7 @@ static void lsi_io_writel(void *opaque, uint32_t addr, uint32_t val)
 }
 
 static void lsi_io_mapfunc(PCIDevice *pci_dev, int region_num,
-                           uint32_t addr, uint32_t size, int type)
+                           uint64_t addr, uint64_t size, int type)
 {
     LSIState *s = (LSIState *)pci_dev;
 
@@ -1938,7 +1938,7 @@ static void lsi_io_mapfunc(PCIDevice *pci_dev, int region_num,
 }
 
 static void lsi_ram_mapfunc(PCIDevice *pci_dev, int region_num,
-                            uint32_t addr, uint32_t size, int type)
+                            uint64_t addr, uint64_t size, int type)
 {
     LSIState *s = (LSIState *)pci_dev;
 
@@ -1948,7 +1948,7 @@ static void lsi_ram_mapfunc(PCIDevice *pci_dev, int region_num,
 }
 
 static void lsi_mmio_mapfunc(PCIDevice *pci_dev, int region_num,
-                             uint32_t addr, uint32_t size, int type)
+                             uint64_t addr, uint64_t size, int type)
 {
     LSIState *s = (LSIState *)pci_dev;
 
diff --git a/hw/msix.c b/hw/msix.c
index c031842..eb7421c 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -204,7 +204,7 @@ static CPUReadMemoryFunc *msix_mmio_read[] = {
 
 /* Should be called from device's map method. */
 void msix_mmio_map(PCIDevice *d, int region_num,
-                   uint32_t addr, uint32_t size, int type)
+                   uint64_t addr, uint64_t size, int type)
 {
     uint8_t *config = d->config + d->msix_cap;
     uint32_t table = pci_get_long(config + MSIX_TABLE_OFFSET);
diff --git a/hw/msix.h b/hw/msix.h
index 3427778..99f1647 100644
--- a/hw/msix.h
+++ b/hw/msix.h
@@ -10,7 +10,7 @@ void msix_write_config(PCIDevice *pci_dev, uint32_t address,
                        uint32_t val, int len);
 
 void msix_mmio_map(PCIDevice *pci_dev, int region_num,
-                   uint32_t addr, uint32_t size, int type);
+                   uint64_t addr, uint64_t size, int type);
 
 int msix_uninit(PCIDevice *d);
 
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 66ae9ab..7701705 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -777,7 +777,7 @@ typedef struct PCINE2000State {
 } PCINE2000State;
 
 static void ne2000_map(PCIDevice *pci_dev, int region_num,
-                       uint32_t addr, uint32_t size, int type)
+                       uint64_t addr, uint64_t size, int type)
 {
     PCINE2000State *d = (PCINE2000State *)pci_dev;
     NE2000State *s = &d->ne2000;
diff --git a/hw/pci.c b/hw/pci.c
index aa3e188..4f5b6e9 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -381,19 +381,19 @@ int pci_unregister_device(PCIDevice *pci_dev)
 }
 
 void pci_register_bar(PCIDevice *pci_dev, int region_num,
-                            uint32_t size, int8_t type,
+                            uint64_t size, int8_t type,
                             PCIMapIORegionFunc *map_func)
 {
     PCIIORegion *r;
     uint32_t addr;
-    uint32_t wmask;
+    uint64_t wmask;
 
     if ((unsigned int)region_num >= PCI_NUM_REGIONS)
         return;
 
     if (size & (size-1)) {
         fprintf(stderr, "ERROR: PCI region size must be pow2 "
-                    "type=0x%x, size=0x%x\n", type, size);
+                    "type=0x%x, size=0x%"PRIx64"\n", type, size);
         exit(1);
     }
 
@@ -412,7 +412,7 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
         addr = 0x10 + region_num * 4;
     }
     *(uint32_t *)(pci_dev->config + addr) = cpu_to_le32(type);
-    *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
+    *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask & 0xffffffff);
     *(uint32_t *)(pci_dev->cmask + addr) = 0xffffffff;
 }
 
@@ -421,7 +421,8 @@ static void pci_update_mappings(PCIDevice *d)
     PCIIORegion *r;
     int i;
     uint16_t cmd;
-    uint32_t last_addr, new_addr, config_ofs;
+    uint64_t last_addr, new_addr;
+    uint32_t config_ofs;
 
     cmd = le16_to_cpu(*(uint16_t *)(d->config + PCI_COMMAND));
     for(i = 0; i < PCI_NUM_REGIONS; i++) {
@@ -460,7 +461,11 @@ static void pci_update_mappings(PCIDevice *d)
                        mappings, we handle specific values as invalid
                        mappings. */
                     if (last_addr <= new_addr || new_addr == 0 ||
-                        last_addr == PCI_BAR_UNMAPPED) {
+                        last_addr == PCI_BAR_UNMAPPED ||
+
+                        /* keep old behaviour
+                         * without this, PC ide doesn't work well. */
+                        last_addr == PCI_BAR_UNMAPPED32) {
                         new_addr = PCI_BAR_UNMAPPED;
                     }
                 } else {
@@ -714,10 +719,10 @@ static void pci_info_device(PCIDevice *d)
         if (r->size != 0) {
             monitor_printf(mon, "      BAR%d: ", i);
             if (r->type & PCI_ADDRESS_SPACE_IO) {
-                monitor_printf(mon, "I/O at 0x%04x [0x%04x].\n",
+                monitor_printf(mon, "I/O at 0x%04"PRIx64" [0x%04"PRIx64"].\n",
                                r->addr, r->addr + r->size - 1);
             } else {
-                monitor_printf(mon, "32 bit memory at 0x%08x [0x%08x].\n",
+                monitor_printf(mon, "32 bit memory at 0x%08"PRIx64" [0x%08"PRIx64"].\n",
                                r->addr, r->addr + r->size - 1);
             }
         }
diff --git a/hw/pci.h b/hw/pci.h
index a3d755d..5290176 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -75,7 +75,7 @@ typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
 typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev,
                                    uint32_t address, int len);
 typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num,
-                                uint32_t addr, uint32_t size, int type);
+                                uint64_t addr, uint64_t size, int type);
 typedef int PCIUnregisterFunc(PCIDevice *pci_dev);
 
 #define PCI_ADDRESS_SPACE_MEM		0x00
@@ -83,9 +83,10 @@ typedef int PCIUnregisterFunc(PCIDevice *pci_dev);
 #define PCI_ADDRESS_SPACE_MEM_PREFETCH	0x08
 
 typedef struct PCIIORegion {
-    uint32_t addr; /* current PCI mapping address. -1 means not mapped */
-#define PCI_BAR_UNMAPPED        (~(uint32_t)0)
-    uint32_t size;
+    uint64_t addr; /* current PCI mapping address. -1 means not mapped */
+#define PCI_BAR_UNMAPPED32      (~(uint32_t)0)
+#define PCI_BAR_UNMAPPED        (~(uint64_t)0)
+    uint64_t size;
     uint8_t type;
     PCIMapIORegionFunc *map_func;
 } PCIIORegion;
@@ -219,7 +220,7 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name,
 int pci_unregister_device(PCIDevice *pci_dev);
 
 void pci_register_bar(PCIDevice *pci_dev, int region_num,
-                            uint32_t size, int8_t type,
+                            uint64_t size, int8_t type,
                             PCIMapIORegionFunc *map_func);
 
 int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
diff --git a/hw/pcnet.c b/hw/pcnet.c
index a184146..f6e6851 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1762,12 +1762,13 @@ static uint32_t pcnet_ioport_readl(void *opaque, uint32_t addr)
 }
 
 static void pcnet_ioport_map(PCIDevice *pci_dev, int region_num,
-                             uint32_t addr, uint32_t size, int type)
+                             uint64_t addr, uint64_t size, int type)
 {
     PCNetState *d = &((PCIPCNetState *)pci_dev)->state;
 
 #ifdef PCNET_DEBUG_IO
-    printf("pcnet_ioport_map addr=0x%04x size=0x%04x\n", addr, size);
+    printf("pcnet_ioport_map addr=0x%04"PRIx64" size=0x%04"PRIx64"\n",
+           addr, size);
 #endif
 
     register_ioport_write(addr, 16, 1, pcnet_aprom_writeb, d);
@@ -1976,12 +1977,12 @@ static CPUReadMemoryFunc *pcnet_mmio_read[] = {
 };
 
 static void pcnet_mmio_map(PCIDevice *pci_dev, int region_num,
-                            uint32_t addr, uint32_t size, int type)
+                            uint64_t addr, uint64_t size, int type)
 {
     PCIPCNetState *d = (PCIPCNetState *)pci_dev;
 
 #ifdef PCNET_DEBUG_IO
-    printf("pcnet_mmio_map addr=0x%08x 0x%08x\n", addr, size);
+    printf("pcnet_mmio_map addr=0x%08"PRIx64" 0x%08"PRIx64"\n", addr, size);
 #endif
 
     cpu_register_physical_memory(addr, PCNET_PNPMMIO_SIZE, d->state.mmio_index);
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 2280018..7ed4ae8 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3329,7 +3329,7 @@ typedef struct PCIRTL8139State {
 } PCIRTL8139State;
 
 static void rtl8139_mmio_map(PCIDevice *pci_dev, int region_num,
-                       uint32_t addr, uint32_t size, int type)
+                       uint64_t addr, uint64_t size, int type)
 {
     PCIRTL8139State *d = (PCIRTL8139State *)pci_dev;
     RTL8139State *s = &d->rtl8139;
@@ -3338,7 +3338,7 @@ static void rtl8139_mmio_map(PCIDevice *pci_dev, int region_num,
 }
 
 static void rtl8139_ioport_map(PCIDevice *pci_dev, int region_num,
-                       uint32_t addr, uint32_t size, int type)
+                       uint64_t addr, uint64_t size, int type)
 {
     PCIRTL8139State *d = (PCIRTL8139State *)pci_dev;
     RTL8139State *s = &d->rtl8139;
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 23b5e21..1d8da5b 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1705,7 +1705,7 @@ typedef struct {
 } OHCIPCIState;
 
 static void ohci_mapfunc(PCIDevice *pci_dev, int i,
-            uint32_t addr, uint32_t size, int type)
+            uint64_t addr, uint64_t size, int type)
 {
     OHCIPCIState *ohci = (OHCIPCIState *)pci_dev;
     cpu_register_physical_memory(addr, size, ohci->state.mem);
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 7b74207..5ffe612 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1058,7 +1058,7 @@ static void uhci_frame_timer(void *opaque)
 }
 
 static void uhci_map(PCIDevice *pci_dev, int region_num,
-                    uint32_t addr, uint32_t size, int type)
+                    uint64_t addr, uint64_t size, int type)
 {
     UHCIState *s = (UHCIState *)pci_dev;
 
diff --git a/hw/vga.c b/hw/vga.c
index 403f6ff..6cdcfa8 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -2236,7 +2236,7 @@ void vga_dirty_log_start(VGAState *s)
 }
 
 static void vga_map(PCIDevice *pci_dev, int region_num,
-                    uint32_t addr, uint32_t size, int type)
+                    uint64_t addr, uint64_t size, int type)
 {
     PCIVGAState *d = (PCIVGAState *)pci_dev;
     VGAState *s = &d->vga_state;
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index f7da503..756a651 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -332,7 +332,7 @@ static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val)
 }
 
 static void virtio_map(PCIDevice *pci_dev, int region_num,
-                       uint32_t addr, uint32_t size, int type)
+                       uint64_t addr, uint64_t size, int type)
 {
     VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev);
     VirtIODevice *vdev = proxy->vdev;
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index accdac4..8b52d23 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -1173,7 +1173,7 @@ static int pci_vmsvga_load(QEMUFile *f, void *opaque, int version_id)
 }
 
 static void pci_vmsvga_map_ioport(PCIDevice *pci_dev, int region_num,
-                uint32_t addr, uint32_t size, int type)
+                uint64_t addr, uint64_t size, int type)
 {
     struct pci_vmsvga_state_s *d = (struct pci_vmsvga_state_s *) pci_dev;
     struct vmsvga_state_s *s = &d->chip;
@@ -1193,7 +1193,7 @@ static void pci_vmsvga_map_ioport(PCIDevice *pci_dev, int region_num,
 }
 
 static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num,
-                uint32_t addr, uint32_t size, int type)
+                uint64_t addr, uint64_t size, int type)
 {
     struct pci_vmsvga_state_s *d = (struct pci_vmsvga_state_s *) pci_dev;
     struct vmsvga_state_s *s = &d->chip;
diff --git a/hw/wdt_i6300esb.c b/hw/wdt_i6300esb.c
index 42642c7..678eb17 100644
--- a/hw/wdt_i6300esb.c
+++ b/hw/wdt_i6300esb.c
@@ -351,7 +351,7 @@ static void i6300esb_mem_writel(void *vp, target_phys_addr_t addr, uint32_t val)
 }
 
 static void i6300esb_map(PCIDevice *dev, int region_num,
-                         uint32_t addr, uint32_t size, int type)
+                         uint64_t addr, uint64_t size, int type)
 {
     static CPUReadMemoryFunc *mem_read[3] = {
         i6300esb_mem_readb,
@@ -366,7 +366,8 @@ static void i6300esb_map(PCIDevice *dev, int region_num,
     I6300State *d = (I6300State *) dev;
     int io_mem;
 
-    i6300esb_debug("addr = %x, size = %x, type = %d\n", addr, size, type);
+    i6300esb_debug("addr = %"PRIx64", size = %"PRIx64", type = %d\n",
+                   addr, size, type);
 
     io_mem = cpu_register_io_memory(mem_read, mem_write, d);
     cpu_register_physical_memory (addr, 0x10, io_mem);
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 6/6] pci: 64bit bar support.
  2009-07-07  6:59 [Qemu-devel] [PATCH 0/6] pci: various clean up and 64bit bar support Isaku Yamahata
                   ` (4 preceding siblings ...)
  2009-07-07  6:59 ` [Qemu-devel] [PATCH 5/6] pci: use uint64_t for bar addr and size instead of uint32_t Isaku Yamahata
@ 2009-07-07  6:59 ` Isaku Yamahata
  5 siblings, 0 replies; 7+ messages in thread
From: Isaku Yamahata @ 2009-07-07  6:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: yamahata

implemented pci 64bit bar support.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/pci.c |   47 +++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |    8 ++++++++
 2 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 4f5b6e9..79a66b8 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -411,9 +411,15 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
     } else {
         addr = 0x10 + region_num * 4;
     }
+
     *(uint32_t *)(pci_dev->config + addr) = cpu_to_le32(type);
-    *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask & 0xffffffff);
-    *(uint32_t *)(pci_dev->cmask + addr) = 0xffffffff;
+    if (pci_bar_is_64bit(r)) {
+        *(uint64_t *)(pci_dev->wmask + addr) = cpu_to_le64(wmask);
+        *(uint64_t *)(pci_dev->cmask + addr) = ~0ULL;
+    } else {
+        *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask & 0xffffffff);
+        *(uint32_t *)(pci_dev->cmask + addr) = 0xffffffff;
+    }
 }
 
 static void pci_update_mappings(PCIDevice *d)
@@ -449,8 +455,14 @@ static void pci_update_mappings(PCIDevice *d)
                 }
             } else {
                 if (cmd & PCI_COMMAND_MEMORY) {
-                    new_addr = le32_to_cpu(*(uint32_t *)(d->config +
-                                                         config_ofs));
+
+                    if (pci_bar_is_64bit(r)) {
+                        new_addr = le64_to_cpu(*(uint64_t *)(d->config +
+                                                             config_ofs));
+                    } else {
+                        new_addr = le32_to_cpu(*(uint32_t *)(d->config +
+                                                             config_ofs));
+                    }
                     /* the ROM slot has a specific enable bit */
                     if (i == PCI_ROM_SLOT && !(new_addr & 1))
                         goto no_mem_map;
@@ -465,7 +477,8 @@ static void pci_update_mappings(PCIDevice *d)
 
                         /* keep old behaviour
                          * without this, PC ide doesn't work well. */
-                        last_addr == PCI_BAR_UNMAPPED32) {
+                        (!pci_bar_is_64bit(r) &&
+                         last_addr == PCI_BAR_UNMAPPED32)) {
                         new_addr = PCI_BAR_UNMAPPED;
                     }
                 } else {
@@ -722,7 +735,29 @@ static void pci_info_device(PCIDevice *d)
                 monitor_printf(mon, "I/O at 0x%04"PRIx64" [0x%04"PRIx64"].\n",
                                r->addr, r->addr + r->size - 1);
             } else {
-                monitor_printf(mon, "32 bit memory at 0x%08"PRIx64" [0x%08"PRIx64"].\n",
+                const char *type;
+                const char* prefetch;
+
+                switch (r->type & PCI_ADDRESS_SPACE_MEM_TYPE_MASK) {
+                case PCI_ADDRESS_SPACE_MEM:
+                    type = "32 bit";
+                    break;
+                case PCI_ADDRESS_SPACE_MEM_64:
+                    type = "64 bit";
+                    break;
+                default:
+                    type = "unknown";
+                    break;
+                }
+
+                prefetch = "";
+                if (r->type & PCI_ADDRESS_SPACE_MEM_PREFETCH) {
+                    prefetch = " prefetchable";
+                }
+
+                monitor_printf(mon, "%s%s memory at "
+                               "0x%08"PRIx64" [0x%08"PRIx64"].\n",
+                               type, prefetch,
                                r->addr, r->addr + r->size - 1);
             }
         }
diff --git a/hw/pci.h b/hw/pci.h
index 5290176..e4a280f 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -80,6 +80,8 @@ typedef int PCIUnregisterFunc(PCIDevice *pci_dev);
 
 #define PCI_ADDRESS_SPACE_MEM		0x00
 #define PCI_ADDRESS_SPACE_IO		0x01
+#define PCI_ADDRESS_SPACE_MEM_64        0x04    /* 64 bit address */
+#define PCI_ADDRESS_SPACE_MEM_TYPE_MASK 0x06
 #define PCI_ADDRESS_SPACE_MEM_PREFETCH	0x08
 
 typedef struct PCIIORegion {
@@ -91,6 +93,12 @@ typedef struct PCIIORegion {
     PCIMapIORegionFunc *map_func;
 } PCIIORegion;
 
+static inline int pci_bar_is_64bit(const PCIIORegion *r)
+{
+    return (r->type & PCI_ADDRESS_SPACE_MEM_TYPE_MASK) ==
+        PCI_ADDRESS_SPACE_MEM_64;
+}
+
 #define PCI_ROM_SLOT 6
 #define PCI_NUM_REGIONS 7
 
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-07-07  8:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-07  6:59 [Qemu-devel] [PATCH 0/6] pci: various clean up and 64bit bar support Isaku Yamahata
2009-07-07  6:59 ` [Qemu-devel] [PATCH 1/6] pci.c: remove unnecessary #ifdef DEBUG_PCI Isaku Yamahata
2009-07-07  6:59 ` [Qemu-devel] [PATCH 2/6] pci: use uint8_t for pci_register_bar() type argument of int Isaku Yamahata
2009-07-07  6:59 ` [Qemu-devel] [PATCH 3/6] pci: minor clean up of pci_update_mappings() Isaku Yamahata
2009-07-07  6:59 ` [Qemu-devel] [PATCH 4/6] pci: define a constant to represent a unmapped bar and use it Isaku Yamahata
2009-07-07  6:59 ` [Qemu-devel] [PATCH 5/6] pci: use uint64_t for bar addr and size instead of uint32_t Isaku Yamahata
2009-07-07  6:59 ` [Qemu-devel] [PATCH 6/6] pci: 64bit bar support Isaku Yamahata

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).