1 /******************************************************************************
4 * Xen platform PCI device driver
6 * Authors: ssmith@xensource.com and stefano.stabellini@eu.citrix.com
8 * Copyright (c) 2005, Intel Corporation.
9 * Copyright (c) 2007, XenSource Inc.
10 * Copyright (c) 2010, Citrix
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms and conditions of the GNU General Public License,
14 * version 2, as published by the Free Software Foundation.
16 * This program is distributed in the hope it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * You should have received a copy of the GNU General Public License along with
22 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 * Place - Suite 330, Boston, MA 02111-1307 USA.
28 #include <linux/interrupt.h>
30 #include <linux/init.h>
31 #include <linux/pci.h>
33 #include <xen/platform_pci.h>
34 #include <xen/grant_table.h>
35 #include <xen/xenbus.h>
36 #include <xen/events.h>
38 #include <xen/xen-ops.h>
40 #define DRV_NAME "xen-platform-pci"
42 static unsigned long platform_mmio
;
43 static unsigned long platform_mmio_alloc
;
44 static unsigned long platform_mmiolen
;
46 static unsigned long alloc_xen_mmio(unsigned long len
)
50 addr
= platform_mmio
+ platform_mmio_alloc
;
51 platform_mmio_alloc
+= len
;
52 BUG_ON(platform_mmio_alloc
> platform_mmiolen
);
57 static int platform_pci_probe(struct pci_dev
*pdev
,
58 const struct pci_device_id
*ent
)
62 long mmio_addr
, mmio_len
;
63 unsigned int max_nr_gframes
;
64 unsigned long grant_frames
;
69 i
= pci_enable_device(pdev
);
73 ioaddr
= pci_resource_start(pdev
, 0);
75 mmio_addr
= pci_resource_start(pdev
, 1);
76 mmio_len
= pci_resource_len(pdev
, 1);
78 if (mmio_addr
== 0 || ioaddr
== 0) {
79 dev_err(&pdev
->dev
, "no resources found\n");
84 ret
= pci_request_region(pdev
, 1, DRV_NAME
);
88 ret
= pci_request_region(pdev
, 0, DRV_NAME
);
92 platform_mmio
= mmio_addr
;
93 platform_mmiolen
= mmio_len
;
95 max_nr_gframes
= gnttab_max_grant_frames();
96 grant_frames
= alloc_xen_mmio(PAGE_SIZE
* max_nr_gframes
);
97 ret
= gnttab_setup_auto_xlat_frames(grant_frames
);
106 gnttab_free_auto_xlat_frames();
108 pci_release_region(pdev
, 0);
110 pci_release_region(pdev
, 1);
112 pci_disable_device(pdev
);
116 static struct pci_device_id platform_pci_tbl
[] = {
117 {PCI_VENDOR_ID_XEN
, PCI_DEVICE_ID_XEN_PLATFORM
,
118 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
122 static struct pci_driver platform_driver
= {
124 .probe
= platform_pci_probe
,
125 .id_table
= platform_pci_tbl
,
128 builtin_pci_driver(platform_driver
);