1809923caSJustin Hibbits /*-
2809923caSJustin Hibbits * Copyright 2015 Justin Hibbits
3809923caSJustin Hibbits * All rights reserved.
4809923caSJustin Hibbits *
5809923caSJustin Hibbits * Redistribution and use in source and binary forms, with or without
6809923caSJustin Hibbits * modification, are permitted provided that the following conditions
7809923caSJustin Hibbits * are met:
8809923caSJustin Hibbits * 1. Redistributions of source code must retain the above copyright
9809923caSJustin Hibbits * notice, this list of conditions and the following disclaimer.
10809923caSJustin Hibbits * 2. Redistributions in binary form must reproduce the above copyright
11809923caSJustin Hibbits * notice, this list of conditions and the following disclaimer in the
12809923caSJustin Hibbits * documentation and/or other materials provided with the distribution.
13809923caSJustin Hibbits * 3. The name of the author may not be used to endorse or promote products
14809923caSJustin Hibbits * derived from this software without specific prior written permission.
15809923caSJustin Hibbits *
16809923caSJustin Hibbits * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17809923caSJustin Hibbits * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18809923caSJustin Hibbits * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19809923caSJustin Hibbits * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20809923caSJustin Hibbits * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21809923caSJustin Hibbits * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22809923caSJustin Hibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23809923caSJustin Hibbits * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24809923caSJustin Hibbits * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25809923caSJustin Hibbits * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26809923caSJustin Hibbits * SUCH DAMAGE.
27809923caSJustin Hibbits *
28809923caSJustin Hibbits * From: FreeBSD: src/sys/powerpc/mpc85xx/pci_ocp.c,v 1.9 2010/03/23 23:46:28 marcel
29809923caSJustin Hibbits */
30809923caSJustin Hibbits
31809923caSJustin Hibbits #include <sys/param.h>
32809923caSJustin Hibbits #include <sys/systm.h>
33809923caSJustin Hibbits #include <sys/ktr.h>
34809923caSJustin Hibbits #include <sys/sockio.h>
35809923caSJustin Hibbits #include <sys/mbuf.h>
36809923caSJustin Hibbits #include <sys/malloc.h>
37809923caSJustin Hibbits #include <sys/kernel.h>
38809923caSJustin Hibbits #include <sys/module.h>
39809923caSJustin Hibbits #include <sys/socket.h>
40809923caSJustin Hibbits #include <sys/queue.h>
41809923caSJustin Hibbits #include <sys/bus.h>
42809923caSJustin Hibbits #include <sys/lock.h>
43809923caSJustin Hibbits #include <sys/mutex.h>
44809923caSJustin Hibbits #include <sys/rman.h>
45809923caSJustin Hibbits #include <sys/endian.h>
46809923caSJustin Hibbits
47809923caSJustin Hibbits #include <vm/vm.h>
48809923caSJustin Hibbits #include <vm/pmap.h>
49809923caSJustin Hibbits
5027353776SJustin Hibbits #include <dev/ofw/openfirm.h>
5127353776SJustin Hibbits #include <dev/ofw/ofw_pci.h>
5227353776SJustin Hibbits #include <dev/ofw/ofw_bus.h>
5327353776SJustin Hibbits #include <dev/ofw/ofw_bus_subr.h>
5427353776SJustin Hibbits
55809923caSJustin Hibbits #include <dev/pci/pcivar.h>
56809923caSJustin Hibbits #include <dev/pci/pcireg.h>
57809923caSJustin Hibbits #include <dev/pci/pcib_private.h>
58809923caSJustin Hibbits
5927353776SJustin Hibbits #include <machine/intr_machdep.h>
6027353776SJustin Hibbits
61809923caSJustin Hibbits #include "pcib_if.h"
62809923caSJustin Hibbits
63c9bd5beeSJustin Hibbits DECLARE_CLASS(ofw_pcib_pci_driver);
64c9bd5beeSJustin Hibbits
6527353776SJustin Hibbits struct fsl_pcib_softc {
6627353776SJustin Hibbits /*
6727353776SJustin Hibbits * This is here so that we can use pci bridge methods, too - the
6827353776SJustin Hibbits * generic routines only need the dev, secbus and subbus members
6927353776SJustin Hibbits * filled.
70c9bd5beeSJustin Hibbits *
71c9bd5beeSJustin Hibbits * XXX: This should be extracted from ofw_pcib_pci.c, and shared in a
72c9bd5beeSJustin Hibbits * header.
7327353776SJustin Hibbits */
7427353776SJustin Hibbits struct pcib_softc ops_pcib_sc;
7527353776SJustin Hibbits phandle_t ops_node;
7627353776SJustin Hibbits struct ofw_bus_iinfo ops_iinfo;
7727353776SJustin Hibbits };
7827353776SJustin Hibbits
79809923caSJustin Hibbits static int
fsl_pcib_rc_probe(device_t dev)80809923caSJustin Hibbits fsl_pcib_rc_probe(device_t dev)
81809923caSJustin Hibbits {
82fe11dfeaSJustin Hibbits
83809923caSJustin Hibbits if (pci_get_vendor(dev) != 0x1957)
84809923caSJustin Hibbits return (ENXIO);
85809923caSJustin Hibbits if (pci_get_progif(dev) != 0)
86809923caSJustin Hibbits return (ENXIO);
87809923caSJustin Hibbits if (pci_get_class(dev) != PCIC_PROCESSOR)
88809923caSJustin Hibbits return (ENXIO);
89809923caSJustin Hibbits if (pci_get_subclass(dev) != PCIS_PROCESSOR_POWERPC)
90809923caSJustin Hibbits return (ENXIO);
91809923caSJustin Hibbits
92b144826dSJustin Hibbits device_set_desc(dev, "MPC85xx Root Complex bridge");
93b144826dSJustin Hibbits
94809923caSJustin Hibbits return (BUS_PROBE_DEFAULT);
95809923caSJustin Hibbits }
96809923caSJustin Hibbits
97809923caSJustin Hibbits static device_method_t fsl_pcib_rc_methods[] = {
98809923caSJustin Hibbits DEVMETHOD(device_probe, fsl_pcib_rc_probe),
99809923caSJustin Hibbits DEVMETHOD_END
100809923caSJustin Hibbits };
101809923caSJustin Hibbits
102809923caSJustin Hibbits DEFINE_CLASS_1(pcib, fsl_pcib_rc_driver, fsl_pcib_rc_methods,
103c9bd5beeSJustin Hibbits sizeof(struct fsl_pcib_softc), ofw_pcib_pci_driver);
104*5d7d6129SJohn Baldwin EARLY_DRIVER_MODULE(rcpcib, pci, fsl_pcib_rc_driver, 0, 0, BUS_PASS_BUS);
105