]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/hyperv/stordisengage/hv_ata_pci_disengage.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / hyperv / stordisengage / hv_ata_pci_disengage.c
1 /*-
2  * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
14  *
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.
25  */
26 /*-
27  * Copyright (c) 2009-2013 Microsoft Corp.
28  * Copyright (c) 2012 NetApp Inc.
29  * Copyright (c) 2012 Citrix Inc.
30  * All rights reserved.
31  *
32  * Redistribution and use in source and binary forms, with or without
33  * modification, are permitted provided that the following conditions
34  * are met:
35  * 1. Redistributions of source code must retain the above copyright
36  *    notice unmodified, this list of conditions, and the following
37  *    disclaimer.
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.
41  *
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.
52  */
53
54 #include <sys/cdefs.h>
55 __FBSDID("$FreeBSD$");
56
57 #include <sys/param.h>
58 #include <sys/systm.h>
59 #include <sys/kernel.h>
60 #include <sys/module.h>
61 #include <sys/ata.h>
62 #include <sys/bus.h>
63 #include <sys/conf.h>
64 #include <sys/malloc.h>
65 #include <sys/sema.h>
66 #include <sys/taskqueue.h>
67 #include <vm/uma.h>
68 #include <machine/stdarg.h>
69 #include <machine/resource.h>
70 #include <machine/bus.h>
71 #include <sys/rman.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>
76 #include <ata_if.h>
77
78 /* prototypes */
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);
82
83 /*
84  * generic PCI ATA device probe
85  */
86 static int
87 hv_ata_pci_probe(device_t dev)
88 {
89         device_t parent = device_get_parent(dev);
90         int ata_disk_enable;
91
92         ata_disk_enable = 0;
93
94         /*
95          * Don't probe if not running in a Hyper-V environment
96          */
97         if (vm_guest != VM_GUEST_HV)
98                 return (ENXIO);
99
100         if (device_get_unit(parent) != 0 || device_get_ivars(dev) != 0)
101                 return (ENXIO);
102
103         /*
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.
108          */
109         if (getenv_int("hw.ata.disk_enable", &ata_disk_enable)) {
110                 if (bootverbose)
111                         device_printf(dev,
112                             "hw.ata.disk_enable flag is disabling Hyper-V"
113                             " ATA driver support\n");
114                         return (ENXIO);
115         }
116
117         device_set_desc(dev, "Hyper-V ATA storage disengage driver");
118
119         return (BUS_PROBE_VENDOR);
120 }
121
122 static int
123 hv_ata_pci_attach(device_t dev)
124 {
125
126         return (0);
127 }
128
129 static int
130 hv_ata_pci_detach(device_t dev)
131 {
132
133         return (0);
134 }
135
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),
142
143         DEVMETHOD_END
144 };
145
146 devclass_t hv_ata_pci_devclass;
147
148 static driver_t hv_ata_pci_disengage_driver = {
149         "ata",
150         hv_ata_pci_methods,
151         0,
152 };
153
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);