1275649Sroyger/*
2275649Sroyger * Copyright (c) 2014 Roger Pau Monn�� <roger.pau@citrix.com>
3275649Sroyger * All rights reserved.
4275649Sroyger *
5275649Sroyger * Redistribution and use in source and binary forms, with or without
6275649Sroyger * modification, are permitted provided that the following conditions
7275649Sroyger * are met:
8275649Sroyger * 1. Redistributions of source code must retain the above copyright
9275649Sroyger *    notice, this list of conditions and the following disclaimer.
10275649Sroyger * 2. Redistributions in binary form must reproduce the above copyright
11275649Sroyger *    notice, this list of conditions and the following disclaimer in the
12275649Sroyger *    documentation and/or other materials provided with the distribution.
13275649Sroyger *
14275649Sroyger * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
15275649Sroyger * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16275649Sroyger * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17275649Sroyger * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18275649Sroyger * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19275649Sroyger * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20275649Sroyger * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21275649Sroyger * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22275649Sroyger * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23275649Sroyger * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24275649Sroyger * SUCH DAMAGE.
25275649Sroyger */
26275649Sroyger
27275649Sroyger#include <sys/cdefs.h>
28275649Sroyger__FBSDID("$FreeBSD$");
29275649Sroyger
30275649Sroyger#include <sys/param.h>
31275649Sroyger#include <sys/systm.h>
32275649Sroyger#include <sys/bus.h>
33275649Sroyger#include <sys/kernel.h>
34275649Sroyger#include <sys/malloc.h>
35275649Sroyger#include <sys/module.h>
36275649Sroyger
37275649Sroyger#include <sys/pciio.h>
38275649Sroyger#include <dev/pci/pcireg.h>
39275649Sroyger#include <dev/pci/pcivar.h>
40275649Sroyger#include <dev/pci/pci_private.h>
41275649Sroyger
42275649Sroyger#include <xen/xen-os.h>
43275649Sroyger#include <xen/hypervisor.h>
44275649Sroyger#include <xen/xen_pci.h>
45275649Sroyger
46275649Sroyger#include "pcib_if.h"
47275649Sroyger#include "pci_if.h"
48275649Sroyger
49275649Sroygerstatic int
50275649Sroygerxen_pci_probe(device_t dev)
51275649Sroyger{
52275649Sroyger
53275649Sroyger	if (!xen_pv_domain())
54275649Sroyger		return (ENXIO);
55275649Sroyger
56275649Sroyger	device_set_desc(dev, "Xen PCI bus");
57275649Sroyger
58275649Sroyger	return (BUS_PROBE_DEFAULT);
59275649Sroyger}
60275649Sroyger
61275649Sroygerstatic device_method_t xen_pci_methods[] = {
62275649Sroyger	/* Device interface */
63275649Sroyger	DEVMETHOD(device_probe,		xen_pci_probe),
64275649Sroyger
65275649Sroyger	/* PCI interface overwrites */
66275649Sroyger	DEVMETHOD(pci_enable_msi,	xen_pci_enable_msi_method),
67275649Sroyger	DEVMETHOD(pci_disable_msi,	xen_pci_disable_msi_method),
68275649Sroyger	DEVMETHOD(pci_child_added,	xen_pci_child_added_method),
69275649Sroyger
70275649Sroyger	DEVMETHOD_END
71275649Sroyger};
72275649Sroyger
73275649Sroygerstatic devclass_t pci_devclass;
74275649Sroyger
75275649SroygerDEFINE_CLASS_1(pci, xen_pci_driver, xen_pci_methods, sizeof(struct pci_softc),
76275649Sroyger    pci_driver);
77275649SroygerDRIVER_MODULE(xen_pci, pcib, xen_pci_driver, pci_devclass, 0, 0);
78275649SroygerMODULE_DEPEND(xen_pci, pci, 1, 1, 1);
79275649SroygerMODULE_VERSION(xen_pci, 1);
80