18e8e46ccSJohn Baldwin /*- 28e8e46ccSJohn Baldwin * Copyright (c) 2005 John Baldwin <jhb@FreeBSD.org> 38e8e46ccSJohn Baldwin * All rights reserved. 48e8e46ccSJohn Baldwin * 58e8e46ccSJohn Baldwin * Redistribution and use in source and binary forms, with or without 68e8e46ccSJohn Baldwin * modification, are permitted provided that the following conditions 78e8e46ccSJohn Baldwin * are met: 88e8e46ccSJohn Baldwin * 1. Redistributions of source code must retain the above copyright 98e8e46ccSJohn Baldwin * notice, this list of conditions and the following disclaimer. 108e8e46ccSJohn Baldwin * 2. Redistributions in binary form must reproduce the above copyright 118e8e46ccSJohn Baldwin * notice, this list of conditions and the following disclaimer in the 128e8e46ccSJohn Baldwin * documentation and/or other materials provided with the distribution. 138e8e46ccSJohn Baldwin * 3. Neither the name of the author nor the names of any co-contributors 148e8e46ccSJohn Baldwin * may be used to endorse or promote products derived from this software 158e8e46ccSJohn Baldwin * without specific prior written permission. 168e8e46ccSJohn Baldwin * 178e8e46ccSJohn Baldwin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 188e8e46ccSJohn Baldwin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 198e8e46ccSJohn Baldwin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 208e8e46ccSJohn Baldwin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 218e8e46ccSJohn Baldwin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 228e8e46ccSJohn Baldwin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 238e8e46ccSJohn Baldwin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 248e8e46ccSJohn Baldwin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 258e8e46ccSJohn Baldwin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 268e8e46ccSJohn Baldwin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 278e8e46ccSJohn Baldwin * SUCH DAMAGE. 288e8e46ccSJohn Baldwin */ 298e8e46ccSJohn Baldwin 308e8e46ccSJohn Baldwin #include <sys/cdefs.h> 318e8e46ccSJohn Baldwin __FBSDID("$FreeBSD$"); 328e8e46ccSJohn Baldwin 338e8e46ccSJohn Baldwin /* 348e8e46ccSJohn Baldwin * Simple driver for PCI VGA display devices. Drivers such as agp(4) and 358e8e46ccSJohn Baldwin * drm(4) should attach as children of this device. 368e8e46ccSJohn Baldwin * 378e8e46ccSJohn Baldwin * XXX: The vgapci name is a hack until we somehow merge the isa vga driver 388e8e46ccSJohn Baldwin * in or rename it. 398e8e46ccSJohn Baldwin */ 408e8e46ccSJohn Baldwin 418e8e46ccSJohn Baldwin #include <sys/param.h> 428e8e46ccSJohn Baldwin #include <sys/bus.h> 438e8e46ccSJohn Baldwin #include <sys/kernel.h> 448e8e46ccSJohn Baldwin #include <sys/module.h> 45e8b145c2SJohn Baldwin #include <sys/rman.h> 46e8b145c2SJohn Baldwin #include <sys/systm.h> 478e8e46ccSJohn Baldwin 488e8e46ccSJohn Baldwin #include <dev/pci/pcireg.h> 498e8e46ccSJohn Baldwin #include <dev/pci/pcivar.h> 508e8e46ccSJohn Baldwin 51e8b145c2SJohn Baldwin struct vga_resource { 52e8b145c2SJohn Baldwin struct resource *vr_res; 53e8b145c2SJohn Baldwin int vr_refs; 54e8b145c2SJohn Baldwin }; 55e8b145c2SJohn Baldwin 56e7e2941bSJohn Baldwin struct vga_pci_softc { 57e7e2941bSJohn Baldwin device_t vga_msi_child; /* Child driver using MSI. */ 58e8b145c2SJohn Baldwin struct vga_resource vga_res[PCIR_MAX_BAR_0 + 1]; 59e7e2941bSJohn Baldwin }; 60e7e2941bSJohn Baldwin 618e8e46ccSJohn Baldwin static int 628e8e46ccSJohn Baldwin vga_pci_probe(device_t dev) 638e8e46ccSJohn Baldwin { 648e8e46ccSJohn Baldwin 658e8e46ccSJohn Baldwin switch (pci_get_class(dev)) { 668e8e46ccSJohn Baldwin case PCIC_DISPLAY: 678e8e46ccSJohn Baldwin break; 688e8e46ccSJohn Baldwin case PCIC_OLD: 698e8e46ccSJohn Baldwin if (pci_get_subclass(dev) != PCIS_OLD_VGA) 708e8e46ccSJohn Baldwin return (ENXIO); 718e8e46ccSJohn Baldwin break; 728e8e46ccSJohn Baldwin default: 738e8e46ccSJohn Baldwin return (ENXIO); 748e8e46ccSJohn Baldwin } 758e8e46ccSJohn Baldwin device_set_desc(dev, "VGA-compatible display"); 76be7ccc4bSJohn Baldwin return (BUS_PROBE_GENERIC); 778e8e46ccSJohn Baldwin } 788e8e46ccSJohn Baldwin 798e8e46ccSJohn Baldwin static int 808e8e46ccSJohn Baldwin vga_pci_attach(device_t dev) 818e8e46ccSJohn Baldwin { 828e8e46ccSJohn Baldwin 838e8e46ccSJohn Baldwin bus_generic_probe(dev); 848e8e46ccSJohn Baldwin 858e8e46ccSJohn Baldwin /* Always create a drm child for now to make it easier on drm. */ 868e8e46ccSJohn Baldwin device_add_child(dev, "drm", -1); 878e8e46ccSJohn Baldwin bus_generic_attach(dev); 888e8e46ccSJohn Baldwin return (0); 898e8e46ccSJohn Baldwin } 908e8e46ccSJohn Baldwin 918e8e46ccSJohn Baldwin static int 928e8e46ccSJohn Baldwin vga_pci_suspend(device_t dev) 938e8e46ccSJohn Baldwin { 948e8e46ccSJohn Baldwin 958e8e46ccSJohn Baldwin return (bus_generic_suspend(dev)); 968e8e46ccSJohn Baldwin } 978e8e46ccSJohn Baldwin 988e8e46ccSJohn Baldwin static int 998e8e46ccSJohn Baldwin vga_pci_resume(device_t dev) 1008e8e46ccSJohn Baldwin { 1018e8e46ccSJohn Baldwin 1028e8e46ccSJohn Baldwin return (bus_generic_resume(dev)); 1038e8e46ccSJohn Baldwin } 1048e8e46ccSJohn Baldwin 1058e8e46ccSJohn Baldwin /* Bus interface. */ 1068e8e46ccSJohn Baldwin 1078e8e46ccSJohn Baldwin static int 1088e8e46ccSJohn Baldwin vga_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) 1098e8e46ccSJohn Baldwin { 1108e8e46ccSJohn Baldwin 1118e8e46ccSJohn Baldwin return (BUS_READ_IVAR(device_get_parent(dev), dev, which, result)); 1128e8e46ccSJohn Baldwin } 1138e8e46ccSJohn Baldwin 1148e8e46ccSJohn Baldwin static int 1158e8e46ccSJohn Baldwin vga_pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value) 1168e8e46ccSJohn Baldwin { 1178e8e46ccSJohn Baldwin 1188e8e46ccSJohn Baldwin return (EINVAL); 1198e8e46ccSJohn Baldwin } 1208e8e46ccSJohn Baldwin 1216be0323dSRobert Noland static int 1226be0323dSRobert Noland vga_pci_setup_intr(device_t dev, device_t child, struct resource *irq, 1236be0323dSRobert Noland int flags, driver_filter_t *filter, driver_intr_t *intr, void *arg, 1246be0323dSRobert Noland void **cookiep) 1256be0323dSRobert Noland { 1266be0323dSRobert Noland return (BUS_SETUP_INTR(device_get_parent(dev), dev, irq, flags, 1276be0323dSRobert Noland filter, intr, arg, cookiep)); 1286be0323dSRobert Noland } 1296be0323dSRobert Noland 1306be0323dSRobert Noland static int 1316be0323dSRobert Noland vga_pci_teardown_intr(device_t dev, device_t child, struct resource *irq, 1326be0323dSRobert Noland void *cookie) 1336be0323dSRobert Noland { 1346be0323dSRobert Noland return (BUS_TEARDOWN_INTR(device_get_parent(dev), dev, irq, cookie)); 1356be0323dSRobert Noland } 1366be0323dSRobert Noland 1378e8e46ccSJohn Baldwin static struct resource * 1388e8e46ccSJohn Baldwin vga_pci_alloc_resource(device_t dev, device_t child, int type, int *rid, 1398e8e46ccSJohn Baldwin u_long start, u_long end, u_long count, u_int flags) 1408e8e46ccSJohn Baldwin { 141e8b145c2SJohn Baldwin struct vga_pci_softc *sc; 142e8b145c2SJohn Baldwin int bar; 1438e8e46ccSJohn Baldwin 144e8b145c2SJohn Baldwin switch (type) { 145e8b145c2SJohn Baldwin case SYS_RES_MEMORY: 146e8b145c2SJohn Baldwin case SYS_RES_IOPORT: 147e8b145c2SJohn Baldwin /* 148e8b145c2SJohn Baldwin * For BARs, we cache the resource so that we only allocate it 149e8b145c2SJohn Baldwin * from the PCI bus once. 150e8b145c2SJohn Baldwin */ 151e8b145c2SJohn Baldwin bar = PCI_RID2BAR(*rid); 152e8b145c2SJohn Baldwin if (bar < 0 || bar > PCIR_MAX_BAR_0) 153e8b145c2SJohn Baldwin return (NULL); 154e8b145c2SJohn Baldwin sc = device_get_softc(dev); 155e8b145c2SJohn Baldwin if (sc->vga_res[bar].vr_res == NULL) 156e8b145c2SJohn Baldwin sc->vga_res[bar].vr_res = bus_alloc_resource(dev, type, 157e8b145c2SJohn Baldwin rid, start, end, count, flags); 158e8b145c2SJohn Baldwin if (sc->vga_res[bar].vr_res != NULL) 159e8b145c2SJohn Baldwin sc->vga_res[bar].vr_refs++; 160e8b145c2SJohn Baldwin return (sc->vga_res[bar].vr_res); 161e8b145c2SJohn Baldwin } 1628e8e46ccSJohn Baldwin return (bus_alloc_resource(dev, type, rid, start, end, count, flags)); 1638e8e46ccSJohn Baldwin } 1648e8e46ccSJohn Baldwin 1658e8e46ccSJohn Baldwin static int 1668e8e46ccSJohn Baldwin vga_pci_release_resource(device_t dev, device_t child, int type, int rid, 1678e8e46ccSJohn Baldwin struct resource *r) 1688e8e46ccSJohn Baldwin { 169e8b145c2SJohn Baldwin struct vga_pci_softc *sc; 170e8b145c2SJohn Baldwin int bar, error; 171e8b145c2SJohn Baldwin 172e8b145c2SJohn Baldwin switch (type) { 173e8b145c2SJohn Baldwin case SYS_RES_MEMORY: 174e8b145c2SJohn Baldwin case SYS_RES_IOPORT: 175e8b145c2SJohn Baldwin /* 176e8b145c2SJohn Baldwin * For BARs, we release the resource from the PCI bus 177e8b145c2SJohn Baldwin * when the last child reference goes away. 178e8b145c2SJohn Baldwin */ 179e8b145c2SJohn Baldwin bar = PCI_RID2BAR(rid); 180e8b145c2SJohn Baldwin if (bar < 0 || bar > PCIR_MAX_BAR_0) 181e8b145c2SJohn Baldwin return (EINVAL); 182e8b145c2SJohn Baldwin sc = device_get_softc(dev); 183e8b145c2SJohn Baldwin if (sc->vga_res[bar].vr_res == NULL) 184e8b145c2SJohn Baldwin return (EINVAL); 185e8b145c2SJohn Baldwin KASSERT(sc->vga_res[bar].vr_res == r, 186e8b145c2SJohn Baldwin ("vga_pci resource mismatch")); 187e8b145c2SJohn Baldwin if (sc->vga_res[bar].vr_refs > 1) { 188e8b145c2SJohn Baldwin sc->vga_res[bar].vr_refs--; 189e8b145c2SJohn Baldwin return (0); 190e8b145c2SJohn Baldwin } 191e8b145c2SJohn Baldwin KASSERT(sc->vga_res[bar].vr_refs > 0, 192e8b145c2SJohn Baldwin ("vga_pci resource reference count underflow")); 193e8b145c2SJohn Baldwin error = bus_release_resource(dev, type, rid, r); 194e8b145c2SJohn Baldwin if (error == 0) { 195e8b145c2SJohn Baldwin sc->vga_res[bar].vr_res = NULL; 196e8b145c2SJohn Baldwin sc->vga_res[bar].vr_refs = 0; 197e8b145c2SJohn Baldwin } 198e8b145c2SJohn Baldwin return (error); 199e8b145c2SJohn Baldwin } 2008e8e46ccSJohn Baldwin 2018e8e46ccSJohn Baldwin return (bus_release_resource(dev, type, rid, r)); 2028e8e46ccSJohn Baldwin } 2038e8e46ccSJohn Baldwin 2048e8e46ccSJohn Baldwin /* PCI interface. */ 2058e8e46ccSJohn Baldwin 2068e8e46ccSJohn Baldwin static uint32_t 2078e8e46ccSJohn Baldwin vga_pci_read_config(device_t dev, device_t child, int reg, int width) 2088e8e46ccSJohn Baldwin { 2098e8e46ccSJohn Baldwin 2108e8e46ccSJohn Baldwin return (pci_read_config(dev, reg, width)); 2118e8e46ccSJohn Baldwin } 2128e8e46ccSJohn Baldwin 2138e8e46ccSJohn Baldwin static void 2148e8e46ccSJohn Baldwin vga_pci_write_config(device_t dev, device_t child, int reg, 2158e8e46ccSJohn Baldwin uint32_t val, int width) 2168e8e46ccSJohn Baldwin { 2178e8e46ccSJohn Baldwin 2188e8e46ccSJohn Baldwin pci_write_config(dev, reg, val, width); 2198e8e46ccSJohn Baldwin } 2208e8e46ccSJohn Baldwin 2218e8e46ccSJohn Baldwin static int 2228e8e46ccSJohn Baldwin vga_pci_enable_busmaster(device_t dev, device_t child) 2238e8e46ccSJohn Baldwin { 2248e8e46ccSJohn Baldwin 2258e8e46ccSJohn Baldwin device_printf(dev, "child %s requested pci_enable_busmaster\n", 2268e8e46ccSJohn Baldwin device_get_nameunit(child)); 2278e8e46ccSJohn Baldwin return (pci_enable_busmaster(dev)); 2288e8e46ccSJohn Baldwin } 2298e8e46ccSJohn Baldwin 2308e8e46ccSJohn Baldwin static int 2318e8e46ccSJohn Baldwin vga_pci_disable_busmaster(device_t dev, device_t child) 2328e8e46ccSJohn Baldwin { 2338e8e46ccSJohn Baldwin 2348e8e46ccSJohn Baldwin device_printf(dev, "child %s requested pci_disable_busmaster\n", 2358e8e46ccSJohn Baldwin device_get_nameunit(child)); 2368e8e46ccSJohn Baldwin return (pci_disable_busmaster(dev)); 2378e8e46ccSJohn Baldwin } 2388e8e46ccSJohn Baldwin 2398e8e46ccSJohn Baldwin static int 2408e8e46ccSJohn Baldwin vga_pci_enable_io(device_t dev, device_t child, int space) 2418e8e46ccSJohn Baldwin { 2428e8e46ccSJohn Baldwin 2438e8e46ccSJohn Baldwin device_printf(dev, "child %s requested pci_enable_io\n", 2448e8e46ccSJohn Baldwin device_get_nameunit(child)); 2458e8e46ccSJohn Baldwin return (pci_enable_io(dev, space)); 2468e8e46ccSJohn Baldwin } 2478e8e46ccSJohn Baldwin 2488e8e46ccSJohn Baldwin static int 2498e8e46ccSJohn Baldwin vga_pci_disable_io(device_t dev, device_t child, int space) 2508e8e46ccSJohn Baldwin { 2518e8e46ccSJohn Baldwin 2528e8e46ccSJohn Baldwin device_printf(dev, "child %s requested pci_disable_io\n", 2538e8e46ccSJohn Baldwin device_get_nameunit(child)); 2548e8e46ccSJohn Baldwin return (pci_disable_io(dev, space)); 2558e8e46ccSJohn Baldwin } 2568e8e46ccSJohn Baldwin 2578e8e46ccSJohn Baldwin static int 258e7e2941bSJohn Baldwin vga_pci_get_vpd_ident(device_t dev, device_t child, const char **identptr) 259e7e2941bSJohn Baldwin { 260e7e2941bSJohn Baldwin 261e7e2941bSJohn Baldwin return (pci_get_vpd_ident(dev, identptr)); 262e7e2941bSJohn Baldwin } 263e7e2941bSJohn Baldwin 264e7e2941bSJohn Baldwin static int 265e7e2941bSJohn Baldwin vga_pci_get_vpd_readonly(device_t dev, device_t child, const char *kw, 266e7e2941bSJohn Baldwin const char **vptr) 267e7e2941bSJohn Baldwin { 268e7e2941bSJohn Baldwin 269e7e2941bSJohn Baldwin return (pci_get_vpd_readonly(dev, kw, vptr)); 270e7e2941bSJohn Baldwin } 271e7e2941bSJohn Baldwin 272e7e2941bSJohn Baldwin static int 2738e8e46ccSJohn Baldwin vga_pci_set_powerstate(device_t dev, device_t child, int state) 2748e8e46ccSJohn Baldwin { 2758e8e46ccSJohn Baldwin 2768e8e46ccSJohn Baldwin device_printf(dev, "child %s requested pci_set_powerstate\n", 2778e8e46ccSJohn Baldwin device_get_nameunit(child)); 2788e8e46ccSJohn Baldwin return (pci_set_powerstate(dev, state)); 2798e8e46ccSJohn Baldwin } 2808e8e46ccSJohn Baldwin 2818e8e46ccSJohn Baldwin static int 2828e8e46ccSJohn Baldwin vga_pci_get_powerstate(device_t dev, device_t child) 2838e8e46ccSJohn Baldwin { 2848e8e46ccSJohn Baldwin 2858e8e46ccSJohn Baldwin device_printf(dev, "child %s requested pci_get_powerstate\n", 2868e8e46ccSJohn Baldwin device_get_nameunit(child)); 2878e8e46ccSJohn Baldwin return (pci_get_powerstate(dev)); 2888e8e46ccSJohn Baldwin } 2898e8e46ccSJohn Baldwin 2908e8e46ccSJohn Baldwin static int 2918e8e46ccSJohn Baldwin vga_pci_assign_interrupt(device_t dev, device_t child) 2928e8e46ccSJohn Baldwin { 2938e8e46ccSJohn Baldwin 2948e8e46ccSJohn Baldwin device_printf(dev, "child %s requested pci_assign_interrupt\n", 2958e8e46ccSJohn Baldwin device_get_nameunit(child)); 2968e8e46ccSJohn Baldwin return (PCI_ASSIGN_INTERRUPT(device_get_parent(dev), dev)); 2978e8e46ccSJohn Baldwin } 2988e8e46ccSJohn Baldwin 2998e8e46ccSJohn Baldwin static int 3008e8e46ccSJohn Baldwin vga_pci_find_extcap(device_t dev, device_t child, int capability, 3018e8e46ccSJohn Baldwin int *capreg) 3028e8e46ccSJohn Baldwin { 3038e8e46ccSJohn Baldwin 3048e8e46ccSJohn Baldwin return (pci_find_extcap(dev, capability, capreg)); 3058e8e46ccSJohn Baldwin } 3068e8e46ccSJohn Baldwin 307e7e2941bSJohn Baldwin static int 308e7e2941bSJohn Baldwin vga_pci_alloc_msi(device_t dev, device_t child, int *count) 309e7e2941bSJohn Baldwin { 310e7e2941bSJohn Baldwin struct vga_pci_softc *sc; 311e7e2941bSJohn Baldwin int error; 312e7e2941bSJohn Baldwin 313e7e2941bSJohn Baldwin sc = device_get_softc(dev); 314e7e2941bSJohn Baldwin if (sc->vga_msi_child != NULL) 315e7e2941bSJohn Baldwin return (EBUSY); 316e7e2941bSJohn Baldwin error = pci_alloc_msi(dev, count); 317e7e2941bSJohn Baldwin if (error == 0) 318e7e2941bSJohn Baldwin sc->vga_msi_child = child; 319e7e2941bSJohn Baldwin return (error); 320e7e2941bSJohn Baldwin } 321e7e2941bSJohn Baldwin 322e7e2941bSJohn Baldwin static int 323e7e2941bSJohn Baldwin vga_pci_alloc_msix(device_t dev, device_t child, int *count) 324e7e2941bSJohn Baldwin { 325e7e2941bSJohn Baldwin struct vga_pci_softc *sc; 326e7e2941bSJohn Baldwin int error; 327e7e2941bSJohn Baldwin 328e7e2941bSJohn Baldwin sc = device_get_softc(dev); 329e7e2941bSJohn Baldwin if (sc->vga_msi_child != NULL) 330e7e2941bSJohn Baldwin return (EBUSY); 331e7e2941bSJohn Baldwin error = pci_alloc_msix(dev, count); 332e7e2941bSJohn Baldwin if (error == 0) 333e7e2941bSJohn Baldwin sc->vga_msi_child = child; 334e7e2941bSJohn Baldwin return (error); 335e7e2941bSJohn Baldwin } 336e7e2941bSJohn Baldwin 337e7e2941bSJohn Baldwin static int 338e7e2941bSJohn Baldwin vga_pci_remap_msix(device_t dev, device_t child, int count, 339e7e2941bSJohn Baldwin const u_int *vectors) 340e7e2941bSJohn Baldwin { 341e7e2941bSJohn Baldwin struct vga_pci_softc *sc; 342e7e2941bSJohn Baldwin 343e7e2941bSJohn Baldwin sc = device_get_softc(dev); 344e7e2941bSJohn Baldwin if (sc->vga_msi_child != child) 345e7e2941bSJohn Baldwin return (ENXIO); 346e7e2941bSJohn Baldwin return (pci_remap_msix(dev, count, vectors)); 347e7e2941bSJohn Baldwin } 348e7e2941bSJohn Baldwin 349e7e2941bSJohn Baldwin static int 350e7e2941bSJohn Baldwin vga_pci_release_msi(device_t dev, device_t child) 351e7e2941bSJohn Baldwin { 352e7e2941bSJohn Baldwin struct vga_pci_softc *sc; 353e7e2941bSJohn Baldwin int error; 354e7e2941bSJohn Baldwin 355e7e2941bSJohn Baldwin sc = device_get_softc(dev); 356e7e2941bSJohn Baldwin if (sc->vga_msi_child != child) 357e7e2941bSJohn Baldwin return (ENXIO); 358e7e2941bSJohn Baldwin error = pci_release_msi(dev); 359e7e2941bSJohn Baldwin if (error == 0) 360e7e2941bSJohn Baldwin sc->vga_msi_child = NULL; 361e7e2941bSJohn Baldwin return (error); 362e7e2941bSJohn Baldwin } 363e7e2941bSJohn Baldwin 364e7e2941bSJohn Baldwin static int 365e7e2941bSJohn Baldwin vga_pci_msi_count(device_t dev, device_t child) 366e7e2941bSJohn Baldwin { 367e7e2941bSJohn Baldwin 368e7e2941bSJohn Baldwin return (pci_msi_count(dev)); 369e7e2941bSJohn Baldwin } 370e7e2941bSJohn Baldwin 371e7e2941bSJohn Baldwin static int 372e7e2941bSJohn Baldwin vga_pci_msix_count(device_t dev, device_t child) 373e7e2941bSJohn Baldwin { 374e7e2941bSJohn Baldwin 375e7e2941bSJohn Baldwin return (pci_msix_count(dev)); 376e7e2941bSJohn Baldwin } 377e7e2941bSJohn Baldwin 3788e8e46ccSJohn Baldwin static device_method_t vga_pci_methods[] = { 3798e8e46ccSJohn Baldwin /* Device interface */ 3808e8e46ccSJohn Baldwin DEVMETHOD(device_probe, vga_pci_probe), 3818e8e46ccSJohn Baldwin DEVMETHOD(device_attach, vga_pci_attach), 3828e8e46ccSJohn Baldwin DEVMETHOD(device_shutdown, bus_generic_shutdown), 3838e8e46ccSJohn Baldwin DEVMETHOD(device_suspend, vga_pci_suspend), 3848e8e46ccSJohn Baldwin DEVMETHOD(device_resume, vga_pci_resume), 3858e8e46ccSJohn Baldwin 3868e8e46ccSJohn Baldwin /* Bus interface */ 3878e8e46ccSJohn Baldwin DEVMETHOD(bus_read_ivar, vga_pci_read_ivar), 3888e8e46ccSJohn Baldwin DEVMETHOD(bus_write_ivar, vga_pci_write_ivar), 3896be0323dSRobert Noland DEVMETHOD(bus_setup_intr, vga_pci_setup_intr), 3906be0323dSRobert Noland DEVMETHOD(bus_teardown_intr, vga_pci_teardown_intr), 3918e8e46ccSJohn Baldwin 3928e8e46ccSJohn Baldwin DEVMETHOD(bus_alloc_resource, vga_pci_alloc_resource), 3938e8e46ccSJohn Baldwin DEVMETHOD(bus_release_resource, vga_pci_release_resource), 3948e8e46ccSJohn Baldwin DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 3958e8e46ccSJohn Baldwin DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 3968e8e46ccSJohn Baldwin 3978e8e46ccSJohn Baldwin /* PCI interface */ 3988e8e46ccSJohn Baldwin DEVMETHOD(pci_read_config, vga_pci_read_config), 3998e8e46ccSJohn Baldwin DEVMETHOD(pci_write_config, vga_pci_write_config), 4008e8e46ccSJohn Baldwin DEVMETHOD(pci_enable_busmaster, vga_pci_enable_busmaster), 4018e8e46ccSJohn Baldwin DEVMETHOD(pci_disable_busmaster, vga_pci_disable_busmaster), 4028e8e46ccSJohn Baldwin DEVMETHOD(pci_enable_io, vga_pci_enable_io), 4038e8e46ccSJohn Baldwin DEVMETHOD(pci_disable_io, vga_pci_disable_io), 404e7e2941bSJohn Baldwin DEVMETHOD(pci_get_vpd_ident, vga_pci_get_vpd_ident), 405e7e2941bSJohn Baldwin DEVMETHOD(pci_get_vpd_readonly, vga_pci_get_vpd_readonly), 4068e8e46ccSJohn Baldwin DEVMETHOD(pci_get_powerstate, vga_pci_get_powerstate), 4078e8e46ccSJohn Baldwin DEVMETHOD(pci_set_powerstate, vga_pci_set_powerstate), 4088e8e46ccSJohn Baldwin DEVMETHOD(pci_assign_interrupt, vga_pci_assign_interrupt), 4098e8e46ccSJohn Baldwin DEVMETHOD(pci_find_extcap, vga_pci_find_extcap), 410e7e2941bSJohn Baldwin DEVMETHOD(pci_alloc_msi, vga_pci_alloc_msi), 411e7e2941bSJohn Baldwin DEVMETHOD(pci_alloc_msix, vga_pci_alloc_msix), 412e7e2941bSJohn Baldwin DEVMETHOD(pci_remap_msix, vga_pci_remap_msix), 413e7e2941bSJohn Baldwin DEVMETHOD(pci_release_msi, vga_pci_release_msi), 414e7e2941bSJohn Baldwin DEVMETHOD(pci_msi_count, vga_pci_msi_count), 415e7e2941bSJohn Baldwin DEVMETHOD(pci_msix_count, vga_pci_msix_count), 4168e8e46ccSJohn Baldwin 4178e8e46ccSJohn Baldwin { 0, 0 } 4188e8e46ccSJohn Baldwin }; 4198e8e46ccSJohn Baldwin 4208e8e46ccSJohn Baldwin static driver_t vga_pci_driver = { 4218e8e46ccSJohn Baldwin "vgapci", 4228e8e46ccSJohn Baldwin vga_pci_methods, 423e7e2941bSJohn Baldwin sizeof(struct vga_pci_softc), 4248e8e46ccSJohn Baldwin }; 4258e8e46ccSJohn Baldwin 4268e8e46ccSJohn Baldwin static devclass_t vga_devclass; 4278e8e46ccSJohn Baldwin 4288e8e46ccSJohn Baldwin DRIVER_MODULE(vgapci, pci, vga_pci_driver, vga_devclass, 0, 0); 429