2 * Copyright (c) 2005 John Baldwin <jhb@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 * 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.
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
29 * $FreeBSD: src/sys/dev/pci/vga_pci.c,v 1.5.8.1 2009/04/15 03:14:26 kensmith Exp $
33 * Simple driver for PCI VGA display devices. Drivers such as agp(4) and
34 * drm(4) should attach as children of this device.
36 * XXX: The vgapci name is a hack until we somehow merge the isa vga driver
40 #include <sys/param.h>
42 #include <sys/kernel.h>
43 #include <sys/module.h>
45 #include <bus/pci/pcireg.h>
46 #include <bus/pci/pcivar.h>
49 vga_pci_probe(device_t dev)
52 switch (pci_get_class(dev)) {
56 if (pci_get_subclass(dev) != PCIS_OLD_VGA)
62 device_set_desc(dev, "VGA-compatible display");
63 return (BUS_PROBE_GENERIC);
67 vga_pci_attach(device_t dev)
70 bus_generic_probe(dev);
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);
79 vga_pci_suspend(device_t dev)
82 return (bus_generic_suspend(dev));
86 vga_pci_resume(device_t dev)
89 return (bus_generic_resume(dev));
95 vga_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
98 return (BUS_READ_IVAR(device_get_parent(dev), dev, which, result));
102 vga_pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
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, int cpuid __unused)
113 return (bus_alloc_resource(dev, type, rid, start, end, count, flags));
117 vga_pci_release_resource(device_t dev, device_t child, int type, int rid,
121 return (bus_release_resource(dev, type, rid, r));
127 vga_pci_read_config(device_t dev, device_t child, int reg, int width)
130 return (pci_read_config(dev, reg, width));
134 vga_pci_write_config(device_t dev, device_t child, int reg,
135 uint32_t val, int width)
138 pci_write_config(dev, reg, val, width);
142 vga_pci_enable_busmaster(device_t dev, device_t child)
145 device_printf(dev, "child %s requested pci_enable_busmaster\n",
146 device_get_nameunit(child));
147 return (pci_enable_busmaster(dev));
151 vga_pci_disable_busmaster(device_t dev, device_t child)
154 device_printf(dev, "child %s requested pci_disable_busmaster\n",
155 device_get_nameunit(child));
156 return (pci_disable_busmaster(dev));
160 vga_pci_enable_io(device_t dev, device_t child, int space)
163 device_printf(dev, "child %s requested pci_enable_io\n",
164 device_get_nameunit(child));
165 return (pci_enable_io(dev, space));
169 vga_pci_disable_io(device_t dev, device_t child, int space)
172 device_printf(dev, "child %s requested pci_disable_io\n",
173 device_get_nameunit(child));
174 return (pci_disable_io(dev, space));
178 vga_pci_set_powerstate(device_t dev, device_t child, int state)
181 device_printf(dev, "child %s requested pci_set_powerstate\n",
182 device_get_nameunit(child));
183 return (pci_set_powerstate(dev, state));
187 vga_pci_get_powerstate(device_t dev, device_t child)
190 device_printf(dev, "child %s requested pci_get_powerstate\n",
191 device_get_nameunit(child));
192 return (pci_get_powerstate(dev));
196 vga_pci_assign_interrupt(device_t dev, device_t child)
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));
205 vga_pci_find_extcap(device_t dev, device_t child, int capability,
209 return (pci_find_extcap(dev, capability, capreg));
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),
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),
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),
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),
246 static driver_t vga_pci_driver = {
252 static devclass_t vga_devclass;
254 DRIVER_MODULE(vgapci, pci, vga_pci_driver, vga_devclass, NULL, NULL);