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 /*
32 * BHNDB PCI SPROM driver.
33 *
34 * Provides support for early PCI bridge cores that vend SPROM CSRs
35 * via PCI configuration space.
36 */
37
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/bus.h>
41 #include <sys/limits.h>
42 #include <sys/malloc.h>
43 #include <sys/module.h>
44 #include <sys/systm.h>
45
46 #include <dev/pci/pcireg.h>
47 #include <dev/pci/pcivar.h>
48
49 #include <dev/bhnd/bhnd.h>
50 #include <dev/bhnd/cores/pci/bhnd_pci_hostbvar.h>
51 #include <dev/bhnd/nvram/bhnd_spromvar.h>
52
53 #include "bhnd_nvram_if.h"
54
55 #include "bhndb_pcireg.h"
56 #include "bhndb_pcivar.h"
57
58 static int
bhndb_pci_sprom_probe(device_t dev)59 bhndb_pci_sprom_probe(device_t dev)
60 {
61 device_t bridge;
62 int error;
63
64 /* Our parent must be a PCI-BHND bridge */
65 bridge = device_get_parent(dev);
66 if (device_get_driver(bridge) != &bhndb_pci_driver)
67 return (ENXIO);
68
69 /* Defer to default driver implementation */
70 if ((error = bhnd_sprom_probe(dev)) > 0)
71 return (error);
72
73 return (BUS_PROBE_NOWILDCARD);
74 }
75
76 static device_method_t bhndb_pci_sprom_methods[] = {
77 /* Device interface */
78 DEVMETHOD(device_probe, bhndb_pci_sprom_probe),
79 DEVMETHOD_END
80 };
81
82 DEFINE_CLASS_1(bhnd_nvram, bhndb_pci_sprom_driver, bhndb_pci_sprom_methods, sizeof(struct bhnd_sprom_softc), bhnd_sprom_driver);
83
84 DRIVER_MODULE(bhndb_pci_sprom, bhndb, bhndb_pci_sprom_driver, NULL, NULL);
85 MODULE_DEPEND(bhndb_pci_sprom, bhnd, 1, 1, 1);
86 MODULE_DEPEND(bhndb_pci_sprom, bhnd_sprom, 1, 1, 1);
87 MODULE_VERSION(bhndb_pci_sprom, 1);
88