xref: /freebsd/sys/powerpc/mpc85xx/pci_mpc85xx_pcib.c (revision da7d7b9c861cf98e912c0bd1e549752d2dae4fb6)
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/cdefs.h>
32 __FBSDID("$FreeBSD$");
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/ktr.h>
37 #include <sys/sockio.h>
38 #include <sys/mbuf.h>
39 #include <sys/malloc.h>
40 #include <sys/kernel.h>
41 #include <sys/module.h>
42 #include <sys/socket.h>
43 #include <sys/queue.h>
44 #include <sys/bus.h>
45 #include <sys/lock.h>
46 #include <sys/mutex.h>
47 #include <sys/rman.h>
48 #include <sys/endian.h>
49 
50 #include <vm/vm.h>
51 #include <vm/pmap.h>
52 
53 #include <dev/pci/pcivar.h>
54 #include <dev/pci/pcireg.h>
55 #include <dev/pci/pcib_private.h>
56 
57 #include "pcib_if.h"
58 
59 static int
60 fsl_pcib_rc_probe(device_t dev)
61 {
62 	printf("Probe called\n");
63 	if (pci_get_vendor(dev) != 0x1957)
64 		return (ENXIO);
65 	if (pci_get_progif(dev) != 0)
66 		return (ENXIO);
67 	if (pci_get_class(dev) != PCIC_PROCESSOR)
68 		return (ENXIO);
69 	if (pci_get_subclass(dev) != PCIS_PROCESSOR_POWERPC)
70 		return (ENXIO);
71 
72 	return (BUS_PROBE_DEFAULT);
73 }
74 
75 static int
76 fsl_pcib_rc_attach(device_t dev)
77 {
78 	struct pcib_softc *sc;
79 	device_t child;
80 
81 	pcib_bridge_init(dev);
82 	pcib_attach_common(dev);
83 
84 	sc = device_get_softc(dev);
85 	if (sc->bus.sec != 0) {
86 		child = device_add_child(dev, "pci", -1);
87 		if (child != NULL)
88 			return (bus_generic_attach(dev));
89 	}
90 
91 	return (0);
92 }
93 
94 static device_method_t fsl_pcib_rc_methods[] = {
95 	DEVMETHOD(device_probe,		fsl_pcib_rc_probe),
96 	DEVMETHOD(device_attach,	fsl_pcib_rc_attach),
97 	DEVMETHOD_END
98 };
99 
100 static devclass_t fsl_pcib_rc_devclass;
101 DEFINE_CLASS_1(pcib, fsl_pcib_rc_driver, fsl_pcib_rc_methods,
102     sizeof(struct pcib_softc), pcib_driver);
103 DRIVER_MODULE(rcpcib, pci, fsl_pcib_rc_driver, fsl_pcib_rc_devclass, 0, 0);
104 
105