ofw_pcib.c revision 163260
1117119Stmm/*-
2117119Stmm * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier
3117119Stmm * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
4117119Stmm * Copyright (c) 2000 BSDi
5117119Stmm * Copyright (c) 2001 - 2003 Thomas Moestl <tmm@FreeBSD.org>
6117119Stmm * All rights reserved.
7117119Stmm *
8117119Stmm * Redistribution and use in source and binary forms, with or without
9117119Stmm * modification, are permitted provided that the following conditions
10117119Stmm * are met:
11117119Stmm * 1. Redistributions of source code must retain the above copyright
12117119Stmm *    notice, this list of conditions and the following disclaimer.
13117119Stmm * 2. Redistributions in binary form must reproduce the above copyright
14117119Stmm *    notice, this list of conditions and the following disclaimer in the
15117119Stmm *    documentation and/or other materials provided with the distribution.
16117119Stmm * 3. The name of the author may not be used to endorse or promote products
17117119Stmm *    derived from this software without specific prior written permission.
18117119Stmm *
19117119Stmm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20117119Stmm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21117119Stmm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22117119Stmm * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23117119Stmm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24117119Stmm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25117119Stmm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26117119Stmm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27117119Stmm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28117119Stmm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29117119Stmm * SUCH DAMAGE.
30117119Stmm *
31117119Stmm *	from: FreeBSD: src/sys/dev/pci/pci_pci.c,v 1.3 2000/12/13
32117119Stmm */
33117119Stmm
34153059Smarius#include <sys/cdefs.h>
35153059Smarius__FBSDID("$FreeBSD: head/sys/sparc64/pci/ofw_pcib.c 163260 2006-10-12 04:44:01Z kmacy $");
36153059Smarius
37117119Stmm#include "opt_ofw_pci.h"
38163260Skmacy#include "opt_global.h"
39117119Stmm
40117119Stmm#include <sys/param.h>
41117119Stmm#include <sys/kernel.h>
42117119Stmm#include <sys/bus.h>
43117119Stmm#include <sys/module.h>
44117119Stmm
45133589Smarius#include <dev/ofw/ofw_bus.h>
46117119Stmm#include <dev/ofw/openfirm.h>
47117119Stmm
48117119Stmm#include <machine/bus.h>
49117119Stmm#include <machine/ofw_bus.h>
50117119Stmm
51117119Stmm#include <dev/pci/pcireg.h>
52117119Stmm#include <dev/pci/pcivar.h>
53117119Stmm#include <dev/pci/pcib_private.h>
54117119Stmm
55117119Stmm#include "pcib_if.h"
56117119Stmm
57117119Stmm#include <sparc64/pci/ofw_pci.h>
58117119Stmm#include <sparc64/pci/ofw_pcib_subr.h>
59117119Stmm
60117119Stmmstatic device_probe_t ofw_pcib_probe;
61117119Stmmstatic device_attach_t ofw_pcib_attach;
62117119Stmm
63117119Stmmstatic device_method_t ofw_pcib_methods[] = {
64117119Stmm	/* Device interface */
65117119Stmm	DEVMETHOD(device_probe,		ofw_pcib_probe),
66117119Stmm	DEVMETHOD(device_attach,	ofw_pcib_attach),
67117119Stmm	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
68117119Stmm	DEVMETHOD(device_suspend,	bus_generic_suspend),
69117119Stmm	DEVMETHOD(device_resume,	bus_generic_resume),
70117119Stmm
71117119Stmm	/* Bus interface */
72117119Stmm	DEVMETHOD(bus_print_child,	bus_generic_print_child),
73117119Stmm	DEVMETHOD(bus_read_ivar,	pcib_read_ivar),
74117119Stmm	DEVMETHOD(bus_write_ivar,	pcib_write_ivar),
75117119Stmm	DEVMETHOD(bus_alloc_resource,	pcib_alloc_resource),
76117119Stmm	DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
77117119Stmm	DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
78117119Stmm	DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
79117119Stmm	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
80117119Stmm	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
81117119Stmm
82117119Stmm	/* pcib interface */
83117119Stmm	DEVMETHOD(pcib_maxslots,	pcib_maxslots),
84117119Stmm	DEVMETHOD(pcib_read_config,	pcib_read_config),
85117119Stmm	DEVMETHOD(pcib_write_config,	pcib_write_config),
86117119Stmm	DEVMETHOD(pcib_route_interrupt,	ofw_pcib_gen_route_interrupt),
87117119Stmm
88133589Smarius	/* ofw_bus interface */
89133589Smarius	DEVMETHOD(ofw_bus_get_node,	ofw_pcib_gen_get_node),
90133589Smarius
91117119Stmm	/* ofw_pci interface */
92117119Stmm	DEVMETHOD(ofw_pci_adjust_busrange,	ofw_pcib_gen_adjust_busrange),
93117119Stmm
94117119Stmm	{ 0, 0 }
95117119Stmm};
96117119Stmm
97154079Sjhbstatic devclass_t pcib_devclass;
98117119Stmm
99154079SjhbDEFINE_CLASS_0(pcib, ofw_pcib_driver, ofw_pcib_methods,
100154079Sjhb    sizeof(struct ofw_pcib_gen_softc));
101117119StmmDRIVER_MODULE(ofw_pcib, pci, ofw_pcib_driver, pcib_devclass, 0, 0);
102117119Stmm
103117119Stmmstatic int
104117119Stmmofw_pcib_probe(device_t dev)
105117119Stmm{
106117119Stmm	if ((pci_get_class(dev) == PCIC_BRIDGE) &&
107117119Stmm	    (pci_get_subclass(dev) == PCIS_BRIDGE_PCI) &&
108133589Smarius	    ofw_bus_get_node(dev) != 0) {
109117119Stmm		device_set_desc(dev, "OFW PCI-PCI bridge");
110117119Stmm		return (0);
111117119Stmm	}
112117119Stmm	return (ENXIO);
113117119Stmm}
114117119Stmm
115117119Stmmstatic int
116117119Stmmofw_pcib_attach(device_t dev)
117117119Stmm{
118153059Smarius	struct ofw_pcib_gen_softc *sc;
119117119Stmm
120153059Smarius	sc = device_get_softc(dev);
121117119Stmm	ofw_pcib_gen_setup(dev);
122117119Stmm	pcib_attach_common(dev);
123163260Skmacy#ifdef SUN4V
124163260Skmacy	device_add_child(dev, "pci", -1);
125163260Skmacy#else
126117119Stmm	device_add_child(dev, "pci", sc->ops_pcib_sc.secbus);
127163260Skmacy#endif
128163260Skmacy
129117119Stmm	return (bus_generic_attach(dev));
130117119Stmm}
131