sys/bus/pci: Remove left over inclusion <sys/cdefs.h>.
[dragonfly.git] / sys / bus / pci / vga_pci.c
1 /*-
2  * Copyright (c) 2005 John Baldwin <jhb@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  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the author nor the names of any co-contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD: src/sys/dev/pci/vga_pci.c,v 1.5.8.1 2009/04/15 03:14:26 kensmith Exp $
30  */
31
32 /*
33  * Simple driver for PCI VGA display devices.  Drivers such as agp(4) and
34  * drm(4) should attach as children of this device.
35  *
36  * XXX: The vgapci name is a hack until we somehow merge the isa vga driver
37  * in or rename it.
38  */
39
40 #include <sys/param.h>
41 #include <sys/bus.h>
42 #include <sys/kernel.h>
43 #include <sys/module.h>
44
45 #include <bus/pci/pcireg.h>
46 #include <bus/pci/pcivar.h>
47
48 static int
49 vga_pci_probe(device_t dev)
50 {
51
52         switch (pci_get_class(dev)) {
53         case PCIC_DISPLAY:
54                 break;
55         case PCIC_OLD:
56                 if (pci_get_subclass(dev) != PCIS_OLD_VGA)
57                         return (ENXIO);
58                 break;
59         default:
60                 return (ENXIO);
61         }
62         device_set_desc(dev, "VGA-compatible display");
63         return (BUS_PROBE_GENERIC);
64 }
65
66 static int
67 vga_pci_attach(device_t dev)
68 {
69
70         bus_generic_probe(dev);
71
72         /* Always create a drm child for now to make it easier on drm. */
73         device_add_child(dev, "drm", -1);
74         bus_generic_attach(dev);
75         return (0);
76 }
77
78 static int
79 vga_pci_suspend(device_t dev)
80 {
81
82         return (bus_generic_suspend(dev));
83 }
84
85 static int
86 vga_pci_resume(device_t dev)
87 {
88
89         return (bus_generic_resume(dev));
90 }
91
92 /* Bus interface. */
93
94 static int
95 vga_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
96 {
97
98         return (BUS_READ_IVAR(device_get_parent(dev), dev, which, result));
99 }
100
101 static int
102 vga_pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
103 {
104
105         return (EINVAL);
106 }
107
108 static struct resource *
109 vga_pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
110     u_long start, u_long end, u_long count, u_int flags)
111 {
112
113         return (bus_alloc_resource(dev, type, rid, start, end, count, flags));
114 }
115
116 static int
117 vga_pci_release_resource(device_t dev, device_t child, int type, int rid,
118     struct resource *r)
119 {
120
121         return (bus_release_resource(dev, type, rid, r));
122 }
123
124 /* PCI interface. */
125
126 static uint32_t
127 vga_pci_read_config(device_t dev, device_t child, int reg, int width)
128 {
129
130         return (pci_read_config(dev, reg, width));
131 }
132
133 static void
134 vga_pci_write_config(device_t dev, device_t child, int reg, 
135     uint32_t val, int width)
136 {
137
138         pci_write_config(dev, reg, val, width);
139 }
140
141 static int
142 vga_pci_enable_busmaster(device_t dev, device_t child)
143 {
144
145         device_printf(dev, "child %s requested pci_enable_busmaster\n",
146             device_get_nameunit(child));
147         return (pci_enable_busmaster(dev));
148 }
149
150 static int
151 vga_pci_disable_busmaster(device_t dev, device_t child)
152 {
153
154         device_printf(dev, "child %s requested pci_disable_busmaster\n",
155             device_get_nameunit(child));
156         return (pci_disable_busmaster(dev));
157 }
158
159 static int
160 vga_pci_enable_io(device_t dev, device_t child, int space)
161 {
162
163         device_printf(dev, "child %s requested pci_enable_io\n",
164             device_get_nameunit(child));
165         return (pci_enable_io(dev, space));
166 }
167
168 static int
169 vga_pci_disable_io(device_t dev, device_t child, int space)
170 {
171
172         device_printf(dev, "child %s requested pci_disable_io\n",
173             device_get_nameunit(child));
174         return (pci_disable_io(dev, space));
175 }
176
177 static int
178 vga_pci_set_powerstate(device_t dev, device_t child, int state)
179 {
180
181         device_printf(dev, "child %s requested pci_set_powerstate\n",
182             device_get_nameunit(child));
183         return (pci_set_powerstate(dev, state));
184 }
185
186 static int
187 vga_pci_get_powerstate(device_t dev, device_t child)
188 {
189
190         device_printf(dev, "child %s requested pci_get_powerstate\n",
191             device_get_nameunit(child));
192         return (pci_get_powerstate(dev));
193 }
194
195 static int
196 vga_pci_assign_interrupt(device_t dev, device_t child)
197 {
198
199         device_printf(dev, "child %s requested pci_assign_interrupt\n",
200             device_get_nameunit(child));
201         return (PCI_ASSIGN_INTERRUPT(device_get_parent(dev), dev));
202 }
203
204 static int
205 vga_pci_find_extcap(device_t dev, device_t child, int capability,
206     int *capreg)
207 {
208
209         return (pci_find_extcap(dev, capability, capreg));
210 }
211
212 static device_method_t vga_pci_methods[] = {
213         /* Device interface */
214         DEVMETHOD(device_probe,         vga_pci_probe),
215         DEVMETHOD(device_attach,        vga_pci_attach),
216         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
217         DEVMETHOD(device_suspend,       vga_pci_suspend),
218         DEVMETHOD(device_resume,        vga_pci_resume),
219
220         /* Bus interface */
221         DEVMETHOD(bus_read_ivar,        vga_pci_read_ivar),
222         DEVMETHOD(bus_write_ivar,       vga_pci_write_ivar),
223         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
224         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
225
226         DEVMETHOD(bus_alloc_resource,   vga_pci_alloc_resource),
227         DEVMETHOD(bus_release_resource, vga_pci_release_resource),
228         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
229         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
230
231         /* PCI interface */
232         DEVMETHOD(pci_read_config,      vga_pci_read_config),
233         DEVMETHOD(pci_write_config,     vga_pci_write_config),
234         DEVMETHOD(pci_enable_busmaster, vga_pci_enable_busmaster),
235         DEVMETHOD(pci_disable_busmaster, vga_pci_disable_busmaster),
236         DEVMETHOD(pci_enable_io,        vga_pci_enable_io),
237         DEVMETHOD(pci_disable_io,       vga_pci_disable_io),
238         DEVMETHOD(pci_get_powerstate,   vga_pci_get_powerstate),
239         DEVMETHOD(pci_set_powerstate,   vga_pci_set_powerstate),
240         DEVMETHOD(pci_assign_interrupt, vga_pci_assign_interrupt),
241         DEVMETHOD(pci_find_extcap,      vga_pci_find_extcap),
242
243         { 0, 0 }
244 };
245
246 static driver_t vga_pci_driver = {
247         "vgapci",
248         vga_pci_methods,
249         1,
250 };
251
252 static devclass_t vga_devclass;
253
254 DRIVER_MODULE(vgapci, pci, vga_pci_driver, vga_devclass, 0, 0);