xref: /freebsd/sys/powerpc/mpc85xx/pci_mpc85xx_pcib.c (revision 02e9120893770924227138ba49df1edb3896112a)
1 /*-
2  * Copyright 2015 Justin Hibbits
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  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * From: FreeBSD: src/sys/powerpc/mpc85xx/pci_ocp.c,v 1.9 2010/03/23 23:46:28 marcel
29  */
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/ktr.h>
34 #include <sys/sockio.h>
35 #include <sys/mbuf.h>
36 #include <sys/malloc.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/socket.h>
40 #include <sys/queue.h>
41 #include <sys/bus.h>
42 #include <sys/lock.h>
43 #include <sys/mutex.h>
44 #include <sys/rman.h>
45 #include <sys/endian.h>
46 
47 #include <vm/vm.h>
48 #include <vm/pmap.h>
49 
50 #include <dev/ofw/openfirm.h>
51 #include <dev/ofw/ofw_pci.h>
52 #include <dev/ofw/ofw_bus.h>
53 #include <dev/ofw/ofw_bus_subr.h>
54 
55 #include <dev/pci/pcivar.h>
56 #include <dev/pci/pcireg.h>
57 #include <dev/pci/pcib_private.h>
58 
59 #include <machine/intr_machdep.h>
60 
61 #include "pcib_if.h"
62 
63 DECLARE_CLASS(ofw_pcib_pci_driver);
64 
65 struct fsl_pcib_softc {
66         /*
67          * This is here so that we can use pci bridge methods, too - the
68          * generic routines only need the dev, secbus and subbus members
69          * filled.
70          *
71          * XXX: This should be extracted from ofw_pcib_pci.c, and shared in a
72          * header.
73          */
74         struct pcib_softc       ops_pcib_sc;
75 	phandle_t		ops_node;
76         struct ofw_bus_iinfo    ops_iinfo;
77 };
78 
79 static int
80 fsl_pcib_rc_probe(device_t dev)
81 {
82 
83 	if (pci_get_vendor(dev) != 0x1957)
84 		return (ENXIO);
85 	if (pci_get_progif(dev) != 0)
86 		return (ENXIO);
87 	if (pci_get_class(dev) != PCIC_PROCESSOR)
88 		return (ENXIO);
89 	if (pci_get_subclass(dev) != PCIS_PROCESSOR_POWERPC)
90 		return (ENXIO);
91 
92 	device_set_desc(dev, "MPC85xx Root Complex bridge");
93 
94 	return (BUS_PROBE_DEFAULT);
95 }
96 
97 static device_method_t fsl_pcib_rc_methods[] = {
98 	DEVMETHOD(device_probe,		fsl_pcib_rc_probe),
99 	DEVMETHOD_END
100 };
101 
102 DEFINE_CLASS_1(pcib, fsl_pcib_rc_driver, fsl_pcib_rc_methods,
103     sizeof(struct fsl_pcib_softc), ofw_pcib_pci_driver);
104 EARLY_DRIVER_MODULE(rcpcib, pci, fsl_pcib_rc_driver, 0, 0, BUS_PASS_BUS);
105