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 30 #include <sys/cdefs.h> 31 __FBSDID("$FreeBSD$"); 32 33 /* 34 * Simple driver for PCI VGA display devices. Drivers such as agp(4) and 35 * drm(4) should attach as children of this device. 36 * 37 * XXX: The vgapci name is a hack until we somehow merge the isa vga driver 38 * in or rename it. 39 */ 40 41 #include <sys/param.h> 42 #include <sys/bus.h> 43 #include <sys/kernel.h> 44 #include <sys/module.h> 45 46 #include <dev/pci/pcireg.h> 47 #include <dev/pci/pcivar.h> 48 49 static int 50 vga_pci_probe(device_t dev) 51 { 52 53 switch (pci_get_class(dev)) { 54 case PCIC_DISPLAY: 55 break; 56 case PCIC_OLD: 57 if (pci_get_subclass(dev) != PCIS_OLD_VGA) 58 return (ENXIO); 59 break; 60 default: 61 return (ENXIO); 62 } 63 device_set_desc(dev, "VGA-compatible display"); 64 return (BUS_PROBE_GENERIC); 65 } 66 67 static int 68 vga_pci_attach(device_t dev) 69 { 70 71 bus_generic_probe(dev); 72 73 /* Always create a drm child for now to make it easier on drm. */ 74 device_add_child(dev, "drm", -1); 75 bus_generic_attach(dev); 76 return (0); 77 } 78 79 static int 80 vga_pci_suspend(device_t dev) 81 { 82 83 return (bus_generic_suspend(dev)); 84 } 85 86 static int 87 vga_pci_resume(device_t dev) 88 { 89 90 return (bus_generic_resume(dev)); 91 } 92 93 /* Bus interface. */ 94 95 static int 96 vga_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) 97 { 98 99 return (BUS_READ_IVAR(device_get_parent(dev), dev, which, result)); 100 } 101 102 static int 103 vga_pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value) 104 { 105 106 return (EINVAL); 107 } 108 109 static struct resource * 110 vga_pci_alloc_resource(device_t dev, device_t child, int type, int *rid, 111 u_long start, u_long end, u_long count, u_int flags) 112 { 113 114 return (bus_alloc_resource(dev, type, rid, start, end, count, flags)); 115 } 116 117 static int 118 vga_pci_release_resource(device_t dev, device_t child, int type, int rid, 119 struct resource *r) 120 { 121 122 return (bus_release_resource(dev, type, rid, r)); 123 } 124 125 /* PCI interface. */ 126 127 static uint32_t 128 vga_pci_read_config(device_t dev, device_t child, int reg, int width) 129 { 130 131 return (pci_read_config(dev, reg, width)); 132 } 133 134 static void 135 vga_pci_write_config(device_t dev, device_t child, int reg, 136 uint32_t val, int width) 137 { 138 139 pci_write_config(dev, reg, val, width); 140 } 141 142 static int 143 vga_pci_enable_busmaster(device_t dev, device_t child) 144 { 145 146 device_printf(dev, "child %s requested pci_enable_busmaster\n", 147 device_get_nameunit(child)); 148 return (pci_enable_busmaster(dev)); 149 } 150 151 static int 152 vga_pci_disable_busmaster(device_t dev, device_t child) 153 { 154 155 device_printf(dev, "child %s requested pci_disable_busmaster\n", 156 device_get_nameunit(child)); 157 return (pci_disable_busmaster(dev)); 158 } 159 160 static int 161 vga_pci_enable_io(device_t dev, device_t child, int space) 162 { 163 164 device_printf(dev, "child %s requested pci_enable_io\n", 165 device_get_nameunit(child)); 166 return (pci_enable_io(dev, space)); 167 } 168 169 static int 170 vga_pci_disable_io(device_t dev, device_t child, int space) 171 { 172 173 device_printf(dev, "child %s requested pci_disable_io\n", 174 device_get_nameunit(child)); 175 return (pci_disable_io(dev, space)); 176 } 177 178 static int 179 vga_pci_set_powerstate(device_t dev, device_t child, int state) 180 { 181 182 device_printf(dev, "child %s requested pci_set_powerstate\n", 183 device_get_nameunit(child)); 184 return (pci_set_powerstate(dev, state)); 185 } 186 187 static int 188 vga_pci_get_powerstate(device_t dev, device_t child) 189 { 190 191 device_printf(dev, "child %s requested pci_get_powerstate\n", 192 device_get_nameunit(child)); 193 return (pci_get_powerstate(dev)); 194 } 195 196 static int 197 vga_pci_assign_interrupt(device_t dev, device_t child) 198 { 199 200 device_printf(dev, "child %s requested pci_assign_interrupt\n", 201 device_get_nameunit(child)); 202 return (PCI_ASSIGN_INTERRUPT(device_get_parent(dev), dev)); 203 } 204 205 static int 206 vga_pci_find_extcap(device_t dev, device_t child, int capability, 207 int *capreg) 208 { 209 210 return (pci_find_extcap(dev, capability, capreg)); 211 } 212 213 static device_method_t vga_pci_methods[] = { 214 /* Device interface */ 215 DEVMETHOD(device_probe, vga_pci_probe), 216 DEVMETHOD(device_attach, vga_pci_attach), 217 DEVMETHOD(device_shutdown, bus_generic_shutdown), 218 DEVMETHOD(device_suspend, vga_pci_suspend), 219 DEVMETHOD(device_resume, vga_pci_resume), 220 221 /* Bus interface */ 222 DEVMETHOD(bus_read_ivar, vga_pci_read_ivar), 223 DEVMETHOD(bus_write_ivar, vga_pci_write_ivar), 224 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 225 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 226 227 DEVMETHOD(bus_alloc_resource, vga_pci_alloc_resource), 228 DEVMETHOD(bus_release_resource, vga_pci_release_resource), 229 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 230 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 231 232 /* PCI interface */ 233 DEVMETHOD(pci_read_config, vga_pci_read_config), 234 DEVMETHOD(pci_write_config, vga_pci_write_config), 235 DEVMETHOD(pci_enable_busmaster, vga_pci_enable_busmaster), 236 DEVMETHOD(pci_disable_busmaster, vga_pci_disable_busmaster), 237 DEVMETHOD(pci_enable_io, vga_pci_enable_io), 238 DEVMETHOD(pci_disable_io, vga_pci_disable_io), 239 DEVMETHOD(pci_get_powerstate, vga_pci_get_powerstate), 240 DEVMETHOD(pci_set_powerstate, vga_pci_set_powerstate), 241 DEVMETHOD(pci_assign_interrupt, vga_pci_assign_interrupt), 242 DEVMETHOD(pci_find_extcap, vga_pci_find_extcap), 243 244 { 0, 0 } 245 }; 246 247 static driver_t vga_pci_driver = { 248 "vgapci", 249 vga_pci_methods, 250 1, 251 }; 252 253 static devclass_t vga_devclass; 254 255 DRIVER_MODULE(vgapci, pci, vga_pci_driver, vga_devclass, 0, 0); 256