WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 1 of 7] pcifront: translate physical into virtual add

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 1 of 7] pcifront: translate physical into virtual addresses
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Mon, 12 Oct 2009 18:19:49 +0100
Delivery-date: Mon, 12 Oct 2009 10:21:52 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)
Qemu understands physical pci addresses while pciback expects virtual
pci addresses: this patch adds a translation function in pcifront to
make the conversion.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>

---

diff -r 77ccebcefbf8 extras/mini-os/pcifront.c
--- a/extras/mini-os/pcifront.c Wed Jul 22 15:49:24 2009 +0100
+++ b/extras/mini-os/pcifront.c Wed Jul 22 15:53:29 2009 +0100
@@ -189,10 +189,10 @@
     n = xenbus_read_integer(path);
 
     for (i = 0; i < n; i++) {
-        snprintf(path, sizeof(path), "%s/vdev-%d", dev->backend, i);
+        snprintf(path, sizeof(path), "%s/dev-%d", dev->backend, i);
         msg = xenbus_read(XBT_NIL, path, &s);
         if (msg) {
-            printk("Error %s when reading the PCI root name at %s\n", path);
+            printk("Error %s when reading the PCI root name at %s\n", msg, 
path);
             continue;
         }
 
@@ -258,6 +258,55 @@
     free_pcifront(dev);
 }
 
+int pcifront_physical_to_virtual (struct pcifront_dev *dev,
+                                  unsigned int *dom,
+                                  unsigned int *bus,
+                                  unsigned int *slot,
+                                  unsigned long *fun)
+{
+    char path[strlen(dev->backend) + 1 + 5 + 10 + 1];
+    int i, n;
+    char *s, *msg = NULL;
+    unsigned int dom1, bus1, slot1, fun1;
+
+    snprintf(path, sizeof(path), "%s/num_devs", dev->backend);
+    n = xenbus_read_integer(path);
+
+    for (i = 0; i < n; i++) {
+        snprintf(path, sizeof(path), "%s/dev-%d", dev->backend, i);
+        msg = xenbus_read(XBT_NIL, path, &s);
+        if (msg) {
+            printk("Error %s when reading the PCI root name at %s\n", msg, 
path);
+            continue;
+        }
+
+        if (sscanf(s, "%x:%x:%x.%x", &dom1, &bus1, &slot1, &fun1) != 4) {
+            printk("\"%s\" does not look like a PCI device address\n", s);
+            free(s);
+            continue;
+        }
+        free(s);
+
+        if (dom1 == *dom && bus1 == *bus && slot1 == *slot && fun1 == *fun) {
+            snprintf(path, sizeof(path), "%s/vdev-%d", dev->backend, i);
+            msg = xenbus_read(XBT_NIL, path, &s);
+            if (msg) {
+                printk("Error %s when reading the PCI root name at %s\n", msg, 
path);
+                continue;
+            }
+
+            if (sscanf(s, "%x:%x:%x.%x", dom, bus, slot, fun) != 4) {
+                printk("\"%s\" does not look like a PCI device address\n", s);
+                free(s);
+                continue;
+            }
+            free(s);
+
+            return 0;
+        }
+    }
+    return -1;
+}
 
 void pcifront_op(struct pcifront_dev *dev, struct xen_pci_op *op)
 {
@@ -281,6 +330,8 @@
 {
     struct xen_pci_op op;
 
+    if (pcifront_physical_to_virtual(dev, &dom, &bus, &slot, &fun) < 0)
+        return XEN_PCI_ERR_dev_not_found;
     memset(&op, 0, sizeof(op));
 
     op.cmd = XEN_PCI_OP_conf_read;
@@ -307,6 +358,8 @@
 {
     struct xen_pci_op op;
 
+    if (pcifront_physical_to_virtual(dev, &dom, &bus, &slot, &fun) < 0)
+        return XEN_PCI_ERR_dev_not_found;
     memset(&op, 0, sizeof(op));
 
     op.cmd = XEN_PCI_OP_conf_write;
@@ -329,6 +382,8 @@
 {
     struct xen_pci_op op;
 
+    if (pcifront_physical_to_virtual(dev, &dom, &bus, &slot, &fun) < 0)
+        return XEN_PCI_ERR_dev_not_found;
     memset(&op, 0, sizeof(op));
 
     op.cmd = XEN_PCI_OP_enable_msi;
@@ -350,6 +405,8 @@
 {
     struct xen_pci_op op;
 
+    if (pcifront_physical_to_virtual(dev, &dom, &bus, &slot, &fun) < 0)
+        return XEN_PCI_ERR_dev_not_found;
     memset(&op, 0, sizeof(op));
 
     op.cmd = XEN_PCI_OP_disable_msi;
@@ -369,6 +426,8 @@
 {
     struct xen_pci_op op;
 
+    if (pcifront_physical_to_virtual(dev, &dom, &bus, &slot, &fun) < 0)
+        return XEN_PCI_ERR_dev_not_found;
     if (n > SH_INFO_MAX_VEC)
         return XEN_PCI_ERR_op_failed;
 
@@ -399,6 +458,8 @@
 {
     struct xen_pci_op op;
 
+    if (pcifront_physical_to_virtual(dev, &dom, &bus, &slot, &fun) < 0)
+        return XEN_PCI_ERR_dev_not_found;
     memset(&op, 0, sizeof(op));
 
     op.cmd = XEN_PCI_OP_disable_msix;

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH 1 of 7] pcifront: translate physical into virtual addresses, Stefano Stabellini <=