1 /*- 2 * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.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 * without modification. 11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13 * redistribution must be conditioned upon including a substantially 14 * similar Disclaimer requirement for further binary redistribution. 15 * 16 * NO WARRANTY 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGES. 28 */ 29 30 #include <sys/cdefs.h> 31 __FBSDID("$FreeBSD$"); 32 33 /* 34 * BHNDB PCI SPROM driver. 35 * 36 * Provides support for early PCI bridge cores that vend SPROM CSRs 37 * via PCI configuration space. 38 */ 39 40 #include <sys/param.h> 41 #include <sys/kernel.h> 42 #include <sys/bus.h> 43 #include <sys/limits.h> 44 #include <sys/malloc.h> 45 #include <sys/module.h> 46 #include <sys/systm.h> 47 48 #include <dev/pci/pcireg.h> 49 #include <dev/pci/pcivar.h> 50 51 #include <dev/bhnd/bhnd.h> 52 #include <dev/bhnd/cores/pci/bhnd_pci_hostbvar.h> 53 #include <dev/bhnd/nvram/bhnd_spromvar.h> 54 55 #include "bhnd_nvram_if.h" 56 57 #include "bhndb_pcireg.h" 58 #include "bhndb_pcivar.h" 59 60 static int 61 bhndb_pci_sprom_probe(device_t dev) 62 { 63 device_t bridge; 64 int error; 65 66 /* Our parent must be a PCI-BHND bridge */ 67 bridge = device_get_parent(dev); 68 if (device_get_driver(bridge) != &bhndb_pci_driver) 69 return (ENXIO); 70 71 /* Defer to default driver implementation */ 72 if ((error = bhnd_sprom_probe(dev)) > 0) 73 return (error); 74 75 return (BUS_PROBE_NOWILDCARD); 76 } 77 78 static device_method_t bhndb_pci_sprom_methods[] = { 79 /* Device interface */ 80 DEVMETHOD(device_probe, bhndb_pci_sprom_probe), 81 DEVMETHOD_END 82 }; 83 84 DEFINE_CLASS_1(bhnd_nvram, bhndb_pci_sprom_driver, bhndb_pci_sprom_methods, sizeof(struct bhnd_sprom_softc), bhnd_sprom_driver); 85 86 DRIVER_MODULE(bhndb_pci_sprom, bhndb, bhndb_pci_sprom_driver, bhnd_nvram_devclass, NULL, NULL); 87 MODULE_DEPEND(bhndb_pci_sprom, bhnd, 1, 1, 1); 88 MODULE_DEPEND(bhndb_pci_sprom, bhnd_sprom, 1, 1, 1); 89 MODULE_VERSION(bhndb_pci_sprom, 1); 90