- Update Xen patches to 3.3-rc5 and c/s 1157.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / pcifront / pci.c
1 /*
2  * PCI Frontend Operations - ensure only one PCI frontend runs at a time
3  *
4  *   Author: Ryan Wilson <hap9@epoch.ncsc.mil>
5  */
6 #include <linux/pci.h>
7 #include <linux/spinlock.h>
8 #include "pcifront.h"
9
10 DEFINE_SPINLOCK(pcifront_dev_lock);
11 static struct pcifront_device *pcifront_dev = NULL;
12
13 int pcifront_connect(struct pcifront_device *pdev)
14 {
15         int err = 0;
16
17         spin_lock(&pcifront_dev_lock);
18
19         if (!pcifront_dev) {
20                 dev_info(&pdev->xdev->dev, "Installing PCI frontend\n");
21                 pcifront_dev = pdev;
22         }
23         else {
24                 dev_err(&pdev->xdev->dev, "PCI frontend already installed!\n");
25                 err = -EEXIST;
26         }
27
28         spin_unlock(&pcifront_dev_lock);
29
30         return err;
31 }
32
33 void pcifront_disconnect(struct pcifront_device *pdev)
34 {
35         spin_lock(&pcifront_dev_lock);
36
37         if (pdev == pcifront_dev) {
38                 dev_info(&pdev->xdev->dev,
39                          "Disconnecting PCI Frontend Buses\n");
40                 pcifront_dev = NULL;
41         }
42
43         spin_unlock(&pcifront_dev_lock);
44 }