2 * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * Copyright (c) 2009-2013 Microsoft Corp.
28 * Copyright (c) 2012 NetApp Inc.
29 * Copyright (c) 2012 Citrix Inc.
30 * All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice unmodified, this list of conditions, and the following
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
43 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
45 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
46 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
51 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 #include <sys/cdefs.h>
55 __FBSDID("$FreeBSD$");
57 #include <sys/param.h>
58 #include <sys/systm.h>
59 #include <sys/kernel.h>
60 #include <sys/module.h>
64 #include <sys/malloc.h>
66 #include <sys/taskqueue.h>
68 #include <machine/stdarg.h>
69 #include <machine/resource.h>
70 #include <machine/bus.h>
72 #include <dev/pci/pcivar.h>
73 #include <dev/pci/pcireg.h>
74 #include <dev/ata/ata-all.h>
75 #include <dev/ata/ata-pci.h>
79 static int hv_ata_pci_probe(device_t dev);
80 static int hv_ata_pci_attach(device_t dev);
81 static int hv_ata_pci_detach(device_t dev);
84 * generic PCI ATA device probe
87 hv_ata_pci_probe(device_t dev)
89 device_t parent = device_get_parent(dev);
95 * Don't probe if not running in a Hyper-V environment
97 if (vm_guest != VM_GUEST_HV)
100 if (device_get_unit(parent) != 0 || device_get_ivars(dev) != 0)
104 * On Hyper-V the default is to use the enlightened driver for
105 * IDE disks. However, if the user wishes to use the native
106 * ATA driver, the environment variable
107 * hw_ata.disk_enable must be explicitly set to 1.
109 if (getenv_int("hw.ata.disk_enable", &ata_disk_enable)) {
112 "hw.ata.disk_enable flag is disabling Hyper-V"
113 " ATA driver support\n");
117 device_set_desc(dev, "Hyper-V ATA storage disengage driver");
119 return (BUS_PROBE_DEFAULT);
123 hv_ata_pci_attach(device_t dev)
130 hv_ata_pci_detach(device_t dev)
136 static device_method_t hv_ata_pci_methods[] = {
137 /* device interface */
138 DEVMETHOD(device_probe, hv_ata_pci_probe),
139 DEVMETHOD(device_attach, hv_ata_pci_attach),
140 DEVMETHOD(device_detach, hv_ata_pci_detach),
141 DEVMETHOD(device_shutdown, bus_generic_shutdown),
146 devclass_t hv_ata_pci_devclass;
148 static driver_t hv_ata_pci_disengage_driver = {
154 DRIVER_MODULE(atapci_dis, atapci, hv_ata_pci_disengage_driver,
155 hv_ata_pci_devclass, NULL, NULL);
156 MODULE_VERSION(atapci_dis, 1);
157 MODULE_DEPEND(atapci_dis, ata, 1, 1, 1);