1153570Sjhb/* 2153570Sjhb * Copyright (c) 1997, Stefan Esser <se@freebsd.org> 3153570Sjhb * All rights reserved. 4153570Sjhb * 5153570Sjhb * Redistribution and use in source and binary forms, with or without 6153570Sjhb * modification, are permitted provided that the following conditions 7153570Sjhb * are met: 8153570Sjhb * 1. Redistributions of source code must retain the above copyright 9153570Sjhb * notice unmodified, this list of conditions, and the following 10153570Sjhb * disclaimer. 11153570Sjhb * 2. Redistributions in binary form must reproduce the above copyright 12153570Sjhb * notice, this list of conditions and the following disclaimer in the 13153570Sjhb * documentation and/or other materials provided with the distribution. 14153570Sjhb * 15153570Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16153570Sjhb * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17153570Sjhb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18153570Sjhb * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19153570Sjhb * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20153570Sjhb * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21153570Sjhb * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22153570Sjhb * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23153570Sjhb * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24153570Sjhb * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25153570Sjhb */ 26153570Sjhb 27153570Sjhb#include <sys/cdefs.h> 28153570Sjhb__FBSDID("$FreeBSD$"); 29153570Sjhb 30153570Sjhb#include <sys/param.h> 31153570Sjhb#include <sys/bus.h> 32153570Sjhb#include <sys/kernel.h> 33153570Sjhb#include <sys/module.h> 34153570Sjhb 35153570Sjhb#include <dev/pci/pcivar.h> 36153570Sjhb#include <dev/pci/pcireg.h> 37153570Sjhb 38153570Sjhb/* 39153570Sjhb * Provide a device to "eat" the host->pci bridge devices that show up 40153570Sjhb * on PCI busses and stop them showing up twice on the probes. This also 41153570Sjhb * stops them showing up as 'none' in pciconf -l. If the host bridge 42153570Sjhb * provides an AGP capability then we create a child agp device for the 43153570Sjhb * agp GART driver to attach to. 44153570Sjhb */ 45153570Sjhbstatic int 46153570Sjhbpci_hostb_probe(device_t dev) 47153570Sjhb{ 48153570Sjhb u_int32_t id; 49153570Sjhb 50153570Sjhb id = pci_get_devid(dev); 51153570Sjhb 52153570Sjhb switch (id) { 53153570Sjhb 54153570Sjhb /* VIA VT82C596 Power Managment Function */ 55153570Sjhb case 0x30501106: 56153570Sjhb return (ENXIO); 57153570Sjhb 58153570Sjhb default: 59153570Sjhb break; 60153570Sjhb } 61153570Sjhb 62153570Sjhb if (pci_get_class(dev) == PCIC_BRIDGE && 63153570Sjhb pci_get_subclass(dev) == PCIS_BRIDGE_HOST) { 64153570Sjhb device_set_desc(dev, "Host to PCI bridge"); 65153570Sjhb device_quiet(dev); 66153570Sjhb return (-10000); 67153570Sjhb } 68153570Sjhb return (ENXIO); 69153570Sjhb} 70153570Sjhb 71153570Sjhbstatic int 72153570Sjhbpci_hostb_attach(device_t dev) 73153570Sjhb{ 74153570Sjhb 75153570Sjhb bus_generic_probe(dev); 76153570Sjhb 77153570Sjhb /* 78153570Sjhb * If AGP capabilities are present on this device, then create 79153570Sjhb * an AGP child. 80153570Sjhb */ 81219902Sjhb if (pci_find_cap(dev, PCIY_AGP, NULL) == 0) 82153570Sjhb device_add_child(dev, "agp", -1); 83153570Sjhb bus_generic_attach(dev); 84153570Sjhb return (0); 85153570Sjhb} 86153570Sjhb 87153570Sjhb/* Bus interface. */ 88153570Sjhb 89153570Sjhbstatic int 90153570Sjhbpci_hostb_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) 91153570Sjhb{ 92153570Sjhb 93153570Sjhb return (BUS_READ_IVAR(device_get_parent(dev), dev, which, result)); 94153570Sjhb} 95153570Sjhb 96153570Sjhbstatic int 97153570Sjhbpci_hostb_write_ivar(device_t dev, device_t child, int which, uintptr_t value) 98153570Sjhb{ 99153570Sjhb 100153570Sjhb return (EINVAL); 101153570Sjhb} 102153570Sjhb 103153570Sjhbstatic struct resource * 104153570Sjhbpci_hostb_alloc_resource(device_t dev, device_t child, int type, int *rid, 105153570Sjhb u_long start, u_long end, u_long count, u_int flags) 106153570Sjhb{ 107153570Sjhb 108153570Sjhb return (bus_alloc_resource(dev, type, rid, start, end, count, flags)); 109153570Sjhb} 110153570Sjhb 111153570Sjhbstatic int 112153570Sjhbpci_hostb_release_resource(device_t dev, device_t child, int type, int rid, 113153570Sjhb struct resource *r) 114153570Sjhb{ 115153570Sjhb 116153570Sjhb return (bus_release_resource(dev, type, rid, r)); 117153570Sjhb} 118153570Sjhb 119153570Sjhb/* PCI interface. */ 120153570Sjhb 121153570Sjhbstatic uint32_t 122153570Sjhbpci_hostb_read_config(device_t dev, device_t child, int reg, int width) 123153570Sjhb{ 124153570Sjhb 125153570Sjhb return (pci_read_config(dev, reg, width)); 126153570Sjhb} 127153570Sjhb 128153570Sjhbstatic void 129153570Sjhbpci_hostb_write_config(device_t dev, device_t child, int reg, 130153570Sjhb uint32_t val, int width) 131153570Sjhb{ 132153570Sjhb 133153570Sjhb pci_write_config(dev, reg, val, width); 134153570Sjhb} 135153570Sjhb 136153570Sjhbstatic int 137153570Sjhbpci_hostb_enable_busmaster(device_t dev, device_t child) 138153570Sjhb{ 139153570Sjhb 140153570Sjhb device_printf(dev, "child %s requested pci_enable_busmaster\n", 141153570Sjhb device_get_nameunit(child)); 142153570Sjhb return (pci_enable_busmaster(dev)); 143153570Sjhb} 144153570Sjhb 145153570Sjhbstatic int 146153570Sjhbpci_hostb_disable_busmaster(device_t dev, device_t child) 147153570Sjhb{ 148153570Sjhb 149153570Sjhb device_printf(dev, "child %s requested pci_disable_busmaster\n", 150153570Sjhb device_get_nameunit(child)); 151153570Sjhb return (pci_disable_busmaster(dev)); 152153570Sjhb} 153153570Sjhb 154153570Sjhbstatic int 155153570Sjhbpci_hostb_enable_io(device_t dev, device_t child, int space) 156153570Sjhb{ 157153570Sjhb 158153570Sjhb device_printf(dev, "child %s requested pci_enable_io\n", 159153570Sjhb device_get_nameunit(child)); 160153570Sjhb return (pci_enable_io(dev, space)); 161153570Sjhb} 162153570Sjhb 163153570Sjhbstatic int 164153570Sjhbpci_hostb_disable_io(device_t dev, device_t child, int space) 165153570Sjhb{ 166153570Sjhb 167153570Sjhb device_printf(dev, "child %s requested pci_disable_io\n", 168153570Sjhb device_get_nameunit(child)); 169153570Sjhb return (pci_disable_io(dev, space)); 170153570Sjhb} 171153570Sjhb 172153570Sjhbstatic int 173153570Sjhbpci_hostb_set_powerstate(device_t dev, device_t child, int state) 174153570Sjhb{ 175153570Sjhb 176153570Sjhb device_printf(dev, "child %s requested pci_set_powerstate\n", 177153570Sjhb device_get_nameunit(child)); 178153570Sjhb return (pci_set_powerstate(dev, state)); 179153570Sjhb} 180153570Sjhb 181153570Sjhbstatic int 182153570Sjhbpci_hostb_get_powerstate(device_t dev, device_t child) 183153570Sjhb{ 184153570Sjhb 185153570Sjhb device_printf(dev, "child %s requested pci_get_powerstate\n", 186153570Sjhb device_get_nameunit(child)); 187153570Sjhb return (pci_get_powerstate(dev)); 188153570Sjhb} 189153570Sjhb 190153570Sjhbstatic int 191153570Sjhbpci_hostb_assign_interrupt(device_t dev, device_t child) 192153570Sjhb{ 193153570Sjhb 194153570Sjhb device_printf(dev, "child %s requested pci_assign_interrupt\n", 195153570Sjhb device_get_nameunit(child)); 196153570Sjhb return (PCI_ASSIGN_INTERRUPT(device_get_parent(dev), dev)); 197153570Sjhb} 198153570Sjhb 199153570Sjhbstatic int 200232472Sjhbpci_hostb_find_cap(device_t dev, device_t child, int capability, 201232472Sjhb int *capreg) 202232472Sjhb{ 203232472Sjhb 204232472Sjhb return (pci_find_cap(dev, capability, capreg)); 205232472Sjhb} 206232472Sjhb 207232472Sjhbstatic int 208153570Sjhbpci_hostb_find_extcap(device_t dev, device_t child, int capability, 209153570Sjhb int *capreg) 210153570Sjhb{ 211153570Sjhb 212153570Sjhb return (pci_find_extcap(dev, capability, capreg)); 213153570Sjhb} 214153570Sjhb 215232472Sjhbstatic int 216232472Sjhbpci_hostb_find_htcap(device_t dev, device_t child, int capability, 217232472Sjhb int *capreg) 218232472Sjhb{ 219232472Sjhb 220232472Sjhb return (pci_find_htcap(dev, capability, capreg)); 221232472Sjhb} 222232472Sjhb 223153570Sjhbstatic device_method_t pci_hostb_methods[] = { 224153570Sjhb /* Device interface */ 225153570Sjhb DEVMETHOD(device_probe, pci_hostb_probe), 226153570Sjhb DEVMETHOD(device_attach, pci_hostb_attach), 227153570Sjhb DEVMETHOD(device_shutdown, bus_generic_shutdown), 228153570Sjhb DEVMETHOD(device_suspend, bus_generic_suspend), 229153570Sjhb DEVMETHOD(device_resume, bus_generic_resume), 230153570Sjhb 231153570Sjhb /* Bus interface */ 232153570Sjhb DEVMETHOD(bus_read_ivar, pci_hostb_read_ivar), 233153570Sjhb DEVMETHOD(bus_write_ivar, pci_hostb_write_ivar), 234153570Sjhb DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 235153570Sjhb DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 236153570Sjhb 237153570Sjhb DEVMETHOD(bus_alloc_resource, pci_hostb_alloc_resource), 238153570Sjhb DEVMETHOD(bus_release_resource, pci_hostb_release_resource), 239153570Sjhb DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 240153570Sjhb DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 241153570Sjhb 242153570Sjhb /* PCI interface */ 243153570Sjhb DEVMETHOD(pci_read_config, pci_hostb_read_config), 244153570Sjhb DEVMETHOD(pci_write_config, pci_hostb_write_config), 245153570Sjhb DEVMETHOD(pci_enable_busmaster, pci_hostb_enable_busmaster), 246153570Sjhb DEVMETHOD(pci_disable_busmaster, pci_hostb_disable_busmaster), 247153570Sjhb DEVMETHOD(pci_enable_io, pci_hostb_enable_io), 248153570Sjhb DEVMETHOD(pci_disable_io, pci_hostb_disable_io), 249153570Sjhb DEVMETHOD(pci_get_powerstate, pci_hostb_get_powerstate), 250153570Sjhb DEVMETHOD(pci_set_powerstate, pci_hostb_set_powerstate), 251153570Sjhb DEVMETHOD(pci_assign_interrupt, pci_hostb_assign_interrupt), 252232472Sjhb DEVMETHOD(pci_find_cap, pci_hostb_find_cap), 253153570Sjhb DEVMETHOD(pci_find_extcap, pci_hostb_find_extcap), 254232472Sjhb DEVMETHOD(pci_find_htcap, pci_hostb_find_htcap), 255153570Sjhb 256153570Sjhb { 0, 0 } 257153570Sjhb}; 258153570Sjhb 259153570Sjhbstatic driver_t pci_hostb_driver = { 260153570Sjhb "hostb", 261153570Sjhb pci_hostb_methods, 262153570Sjhb 1, 263153570Sjhb}; 264153570Sjhb 265153570Sjhbstatic devclass_t pci_hostb_devclass; 266153570Sjhb 267153570SjhbDRIVER_MODULE(hostb, pci, pci_hostb_driver, pci_hostb_devclass, 0, 0); 268