From: Gerd Hoffmann <kraxel@suse.de>
To: Xen devel list <xen-devel@lists.xensource.com>
Subject: [rfc/patch] pv-on-hvm: make netfront grab PCI ressources.
Date: Thu, 08 Feb 2007 17:50:51 +0100 [thread overview]
Message-ID: <45CB54EB.8000506@suse.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 933 bytes --]
Hi,
This patch makes netfront grab the rtl8139 PCI ressources when running
as paravirtualized driver in a HVM domain. If the driver fails to grab
the ressources it refuses to load. If it succeeds grabbing the
ressources this shoulld prevent any other driver from taking the device.
This makes sure that we don't have two drivers (8139 pci driver and
netfront) active for the same device.
The device is matched by both pci id and pci subsystem id (which was
added a few days ago), so netfront (aka xen-vnif) will grab a virtual
network card only, not a real rtl8139 card.
As a bonus we'll get driver auto loading support as the modutils are
able now to figure the
Comments?
Gerd
PS: The same would be good for blkfront too, although there it is less
critical as only one of the drivers succeeds registering the ide
major number, so it can't happen that both grab the same disk.
--
Gerd Hoffmann <kraxel@suse.de>
[-- Attachment #2: grab-ports.diff --]
[-- Type: text/x-patch, Size: 3177 bytes --]
diff -r 780f097b54c5 linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Wed Feb 07 17:29:52 2007 +0000
+++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Thu Feb 08 16:44:05 2007 +0100
@@ -2074,8 +2074,97 @@ static struct notifier_block notifier_in
.priority = 0
};
+/* ------------------------------------------------------------------ */
+
+#ifndef CONFIG_XEN
+#include <linux/pci.h>
+
+#define DRV_NAME "netfront"
+
+static int rtl8139_taken = 0;
+
+static void __devexit rtl8139_release(struct pci_dev *pdev)
+{
+ long ioaddr, iolen;
+ long mmio_addr, mmio_len;
+
+ ioaddr = pci_resource_start(pdev, 0);
+ iolen = pci_resource_len(pdev, 0);
+ mmio_addr = pci_resource_start(pdev, 1);
+ mmio_len = pci_resource_len(pdev, 1);
+
+ release_region(ioaddr, iolen);
+ release_mem_region(mmio_addr, mmio_len);
+
+ printk(KERN_INFO DRV_NAME ": released rtl8139 card\n");
+ rtl8139_taken--;
+}
+
+static int __devinit rtl8139_grab(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
+{
+ int ret;
+ long ioaddr, iolen;
+ long mmio_addr, mmio_len;
+
+ ret = pci_enable_device(pdev);
+ if (ret) {
+ printk(KERN_ERR DRV_NAME ": can't enable device\n");
+ return ret;
+ }
+
+ ioaddr = pci_resource_start(pdev, 0);
+ iolen = pci_resource_len(pdev, 0);
+
+ mmio_addr = pci_resource_start(pdev, 1);
+ mmio_len = pci_resource_len(pdev, 1);
+
+ if (request_mem_region(mmio_addr, mmio_len, DRV_NAME) == NULL)
+ {
+ printk(KERN_ERR DRV_NAME ": MEM I/O resource 0x%lx @ 0x%lx busy\n",
+ mmio_addr, mmio_len);
+ return -EBUSY;
+ }
+
+ if (request_region(ioaddr, iolen, DRV_NAME) == NULL)
+ {
+ printk(KERN_ERR DRV_NAME ": I/O resource 0x%lx @ 0x%lx busy\n",
+ iolen, ioaddr);
+ release_mem_region(mmio_addr, mmio_len);
+ return -EBUSY;
+ }
+
+ printk(KERN_INFO DRV_NAME ": grabbed rtl8139 card\n");
+ rtl8139_taken++;
+ return 0;
+}
+
+static struct pci_device_id rtl8139_pci_tbl[] __devinitdata = {
+ {
+ .vendor = 0x10ec, // Realtek
+ .device = 0x8139, // 8139
+ .subvendor = 0x5853, // XenSource
+ .subdevice = 0x0001, // #1
+ },
+ {0,}
+};
+MODULE_DEVICE_TABLE(pci, rtl8139_pci_tbl);
+
+static struct pci_driver rtl8139_grabber = {
+ .name = DRV_NAME,
+ .probe = rtl8139_grab,
+ .remove = __devexit_p(rtl8139_release),
+ .id_table = rtl8139_pci_tbl,
+};
+
+#endif
+
+/* ------------------------------------------------------------------ */
+
static int __init netif_init(void)
{
+ int ret;
+
if (!is_running_on_xen())
return -ENODEV;
@@ -2092,6 +2181,14 @@ static int __init netif_init(void)
if (is_initial_xendomain())
return 0;
+#ifndef CONFIG_XEN
+ ret = pci_module_init(&rtl8139_grabber);
+ if (ret)
+ return ret;
+ if (!rtl8139_taken)
+ return -EBUSY;
+#endif
+
IPRINTK("Initialising virtual ethernet driver.\n");
(void)register_inetaddr_notifier(¬ifier_inetdev);
@@ -2108,6 +2205,9 @@ static void __exit netif_exit(void)
unregister_inetaddr_notifier(¬ifier_inetdev);
+#ifndef CONFIG_XEN
+ pci_unregister_driver(&rtl8139_grabber);
+#endif
return xenbus_unregister_driver(&netfront);
}
module_exit(netif_exit);
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next reply other threads:[~2007-02-08 16:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-08 16:50 Gerd Hoffmann [this message]
2007-02-08 16:56 ` [rfc/patch] pv-on-hvm: make netfront grab PCI ressources Petersson, Mats
2007-02-08 17:05 ` Gerd Hoffmann
2007-02-08 17:55 ` Mark Williamson
2007-02-08 17:13 ` Keir Fraser
2007-02-09 11:17 ` Gerd Hoffmann
2007-02-09 16:03 ` Kirk Allan
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=45CB54EB.8000506@suse.de \
--to=kraxel@suse.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.