qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [patch 18/19] From: Markus Armbruster <armbru@pond.sub.org>
Date: Tue, 10 Feb 2009 18:31:09 -0200	[thread overview]
Message-ID: <20090210203208.461179416@emt.localdomain> (raw)
In-Reply-To: 20090210203051.064692466@emt.localdomain

[-- Attachment #1: pci-helper-parser --]
[-- Type: text/plain, Size: 2945 bytes --]

This code parses full PCI device addresses.  It then rejects domains
other than zero, because these are not supported in QEMU.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: trunk/hw/pci.c
===================================================================
--- trunk.orig/hw/pci.c
+++ trunk/hw/pci.c
@@ -26,6 +26,7 @@
 #include "console.h"
 #include "net.h"
 #include "virtio-net.h"
+#include "sysemu.h"
 
 //#define DEBUG_PCI
 
@@ -158,6 +159,82 @@ static int pci_set_default_subsystem_id(
     return 0;
 }
 
+/*
+ * Parse [[<domain>:]<bus>:]<slot>, return -1 on error
+ */
+static int pci_parse_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp)
+{
+    const char *p;
+    char *e;
+    unsigned long val;
+    unsigned long dom = 0, bus = 0;
+    unsigned slot = 0;
+
+    p = addr;
+    val = strtoul(p, &e, 16);
+    if (e == p)
+	return -1;
+    if (*e == ':') {
+	bus = val;
+	p = e + 1;
+	val = strtoul(p, &e, 16);
+	if (e == p)
+	    return -1;
+	if (*e == ':') {
+	    dom = bus;
+	    bus = val;
+	    p = e + 1;
+	    val = strtoul(p, &e, 16);
+	    if (e == p)
+		return -1;
+	}
+    }
+
+    if (dom > 0xffff || bus > 0xff || val > 0x1f)
+	return -1;
+
+    slot = val;
+
+    if (*e)
+	return -1;
+
+    /* Note: QEMU doesn't implement domains other than 0 */
+    if (dom != 0 || pci_find_bus(bus) == NULL)
+	return -1;
+
+    *domp = dom;
+    *busp = bus;
+    *slotp = slot;
+    return 0;
+}
+
+int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp)
+{
+    char devaddr[32];
+
+    if (!get_param_value(devaddr, sizeof(devaddr), "pci_addr", addr))
+        return -1;
+
+    return pci_parse_devaddr(devaddr, domp, busp, slotp);
+}
+
+int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp)
+{
+    char devaddr[32];
+
+    if (!get_param_value(devaddr, sizeof(devaddr), "pci_addr", addr))
+	return -1;
+
+    if (!strcmp(devaddr, "auto")) {
+        *domp = *busp = 0;
+        *slotp = -1;
+        /* want to support dom/bus auto-assign at some point */
+        return 0;
+    }
+
+    return pci_parse_devaddr(devaddr, domp, busp, slotp);
+}
+
 /* -1 for devfn means auto assign */
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
                                int instance_size, int devfn,
Index: trunk/hw/pci.h
===================================================================
--- trunk.orig/hw/pci.h
+++ trunk/hw/pci.h
@@ -232,6 +232,9 @@ void pci_for_each_device(int bus_num, vo
 PCIBus *pci_find_bus(int bus_num);
 PCIDevice *pci_find_device(int bus_num, int slot, int function);
 
+int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp);
+int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp);
+
 void pci_info(void);
 PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
                         pci_map_irq_fn map_irq, const char *name);

-- 

  parent reply	other threads:[~2009-02-10 20:49 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-10 20:30 [Qemu-devel] [patch 00/19] acpi pci hotplug Marcelo Tosatti
2009-02-10 20:30 ` [Qemu-devel] [patch 01/19] qemu: add pci helper functions Marcelo Tosatti
2009-02-10 20:30 ` [Qemu-devel] [patch 02/19] qemu: return PCIDevice on net device init and record devfn Marcelo Tosatti
2009-02-10 20:30 ` [Qemu-devel] [patch 03/19] qemu: dynamic drive/drive_opt index allocation Marcelo Tosatti
2009-02-10 20:30 ` [Qemu-devel] [patch 04/19] qemu: dynamic nic info " Marcelo Tosatti
2009-02-10 20:30 ` [Qemu-devel] [patch 05/19] qemu: drive removal support Marcelo Tosatti
2009-02-10 20:30 ` [Qemu-devel] [patch 06/19] qemu: record devfn on block driver instance Marcelo Tosatti
2009-02-10 20:30 ` [Qemu-devel] [patch 07/19] qemu: move drives_opt for external use Marcelo Tosatti
2009-02-10 20:30 ` [Qemu-devel] [patch 08/19] qemu: net/drive add/remove tweaks Marcelo Tosatti
2009-02-10 20:31 ` [Qemu-devel] [patch 09/19] qemu: add net_client_uninit / qemu_find_vlan_client Marcelo Tosatti
2009-02-10 20:31 ` [Qemu-devel] [patch 10/19] qemu: add cpu_unregister_io_memory and make io mem table index dynamic Marcelo Tosatti
2009-02-10 20:31 ` [Qemu-devel] [patch 11/19] qemu: add qemu_free_irqs Marcelo Tosatti
2009-02-10 20:31 ` [Qemu-devel] [patch 12/19] qemu: add pci_unregister_device Marcelo Tosatti
2009-02-10 20:31 ` [Qemu-devel] [patch 13/19] qemu: warn if PCI region is not power of two Marcelo Tosatti
2009-02-10 20:31 ` [Qemu-devel] [patch 14/19] qemu: LSI SCSI and e1000 unregister callbacks Marcelo Tosatti
2009-02-10 20:31 ` [Qemu-devel] [patch 15/19] qemu: zero ioport_opaque on isa_unassign_ioport Marcelo Tosatti
2009-02-10 20:31 ` [Qemu-devel] [patch 16/19] qemu: initialize hot add system / acpi gpe Marcelo Tosatti
2009-02-10 20:31 ` [Qemu-devel] [patch 17/19] qemu: pci hotplug GPE support Marcelo Tosatti
2009-02-10 20:31 ` Marcelo Tosatti [this message]
2009-02-10 20:31 ` [Qemu-devel] [patch 19/19] qemu: PCI device, disk and host network hot-add / hot-remove Marcelo Tosatti
2009-02-11  2:26   ` [Qemu-devel] " Anthony Liguori
2009-02-11 15:00     ` Marcelo Tosatti
2009-02-11 15:32       ` Avi Kivity
2009-02-11 12:42 ` [Qemu-devel] [patch 00/19] acpi pci hotplug Markus Armbruster
2009-02-11 15:19 ` [Qemu-devel] " Anthony Liguori

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=20090210203208.461179416@emt.localdomain \
    --to=mtosatti@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /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).