xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Jean Guyader <jean.guyader@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian.Jackson@eu.citrix.com, allen.m.kay@intel.com,
	Jean Guyader <jean.guyader@eu.citrix.com>
Subject: [PATCH 1/2] qemu-xen: Pass through, utility functions
Date: Tue, 31 Jan 2012 18:39:39 +0000	[thread overview]
Message-ID: <1328035180-26966-1-git-send-email-jean.guyader@eu.citrix.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 380 bytes --]


Add a function to map a specific bar into a pt_dev.

Add a function that gets called everytime the bar of a pass
through device gets remap.

Signed-off-by: Jean Guyader <jean.guyader@eu.citrix.com>
---
 hw/pass-through.c |   34 ++++++++++++++++++++++++++++++++++
 hw/pass-through.h |    3 +++
 hw/pt-graphics.c  |    7 +++++++
 3 files changed, 44 insertions(+), 0 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-qemu-xen-Pass-through-utility-functions.patch --]
[-- Type: text/x-patch; name="0001-qemu-xen-Pass-through-utility-functions.patch", Size: 3801 bytes --]

diff --git a/hw/pass-through.c b/hw/pass-through.c
index dbe8804..1bdb223 100644
--- a/hw/pass-through.c
+++ b/hw/pass-through.c
@@ -93,6 +93,7 @@
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <assert.h>
+#include <sys/mman.h>
 
 extern int gfx_passthru;
 int igd_passthru = 0;
@@ -1155,6 +1156,9 @@ static void pt_iomem_map(PCIDevice *d, int i, uint32_t e_phys, uint32_t e_size,
     if ( e_size == 0 )
         return;
 
+    if (assigned_device->pci_dev->device_class == 0x0300)
+        pt_graphic_bar_remap(assigned_device, i, first_map, DPCI_ADD_MAPPING);
+
     if ( !first_map && old_ebase != -1 )
     {
         if ( has_msix_mapping(assigned_device, i) )
@@ -1969,6 +1973,9 @@ static void pt_unregister_regions(struct pt_dev *assigned_device)
         if ( type == PCI_ADDRESS_SPACE_MEM ||
              type == PCI_ADDRESS_SPACE_MEM_PREFETCH )
         {
+            if (assigned_device->pci_dev->device_class == 0x0300)
+                pt_graphic_bar_remap(assigned_device, i, 0, DPCI_REMOVE_MAPPING);
+
             ret = xc_domain_memory_mapping(xc_handle, domid,
                     assigned_device->bases[i].e_physbase >> XC_PAGE_SHIFT,
                     assigned_device->bases[i].access.maddr >> XC_PAGE_SHIFT,
@@ -2101,6 +2108,33 @@ int pt_pci_host_write(struct pci_dev *pci_dev, u32 addr, u32 val, int len)
     return ret;
 }
 
+int pt_pci_host_map_bar(struct pt_dev *pt_dev, int bar)
+{
+    int fd;
+    struct stat s;
+    uint8_t *map;
+
+    char filename[1024];
+
+    snprintf(filename, 1024, "/sys/bus/pci/devices/0000:%02x:%02x.%01x/resource%d",
+            pt_dev->pci_dev->bus,
+            pt_dev->pci_dev->dev,
+            pt_dev->pci_dev->func,
+            bar);
+    fd = open(filename, O_RDWR | O_SYNC);
+    if (fd < 0)
+        return fd;
+    fstat(fd, &s);
+
+    map = mmap(0, s.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    if (map != MAP_FAILED)
+    {
+        pt_dev->bases[bar].map = map;
+        return 0;
+    }
+    return errno;
+}
+
 /* parse BAR */
 static int pt_bar_reg_parse(
         struct pt_dev *ptdev, struct pt_reg_info_tbl *reg)
diff --git a/hw/pass-through.h b/hw/pass-through.h
index 884139c..26e6ff1 100644
--- a/hw/pass-through.h
+++ b/hw/pass-through.h
@@ -170,6 +170,7 @@ struct pt_region {
         uint64_t pio_base;
         uint64_t u;
     } access;
+    uint8_t *map;
 };
 
 struct pt_msi_info {
@@ -414,6 +415,7 @@ uint8_t pci_intx(struct pt_dev *ptdev);
 struct pci_dev *pt_pci_get_dev(int bus, int dev, int func);
 u32 pt_pci_host_read(struct pci_dev *pci_dev, u32 addr, int len);
 int pt_pci_host_write(struct pci_dev *pci_dev, u32 addr, u32 val, int len);
+int pt_pci_host_map_bar(struct pt_dev *pt_dev, int bar);
 void intel_pch_init(PCIBus *bus);
 int register_vga_regions(struct pt_dev *real_device);
 int unregister_vga_regions(struct pt_dev *real_device);
@@ -422,6 +424,7 @@ PCIBus *intel_pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid,
            uint16_t did, const char *name, uint16_t revision);
 void igd_pci_write(PCIDevice *pci_dev, uint32_t config_addr, uint32_t val, int len);
 uint32_t igd_pci_read(PCIDevice *pci_dev, uint32_t config_addr, int len);
+void pt_graphic_bar_remap(struct pt_dev *real_device, int bar, int first_map, int map);
 
 #endif /* __PASSTHROUGH_H__ */
 
diff --git a/hw/pt-graphics.c b/hw/pt-graphics.c
index fec7390..5d5e5da 100644
--- a/hw/pt-graphics.c
+++ b/hw/pt-graphics.c
@@ -94,6 +94,13 @@ uint32_t igd_pci_read(PCIDevice *pci_dev, uint32_t config_addr, int len)
 }
 
 /*
+ * Callback whenever a bar get remapped
+ */
+void pt_graphic_bar_remap(struct pt_dev *real_device, int bar, int first_map, int map)
+{
+}
+
+/*
  * register VGA resources for the domain with assigned gfx
  */
 int register_vga_regions(struct pt_dev *real_device)

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

             reply	other threads:[~2012-01-31 18:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-31 18:39 Jean Guyader [this message]
2012-01-31 18:39 ` [PATCH 2/2] qemu-xen: Intel GPU passthrough Jean Guyader
2012-02-01 14:52   ` Stefano Stabellini
2012-02-01 15:28     ` Jean Guyader
2012-02-01 22:32   ` Kay, Allen M
2012-02-01 14:47 ` [PATCH 1/2] qemu-xen: Pass through, utility functions Stefano Stabellini
2012-02-01 15:26   ` Jean Guyader

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=1328035180-26966-1-git-send-email-jean.guyader@eu.citrix.com \
    --to=jean.guyader@eu.citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=allen.m.kay@intel.com \
    --cc=xen-devel@lists.xensource.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).