ofw_pcib.c revision 154079
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 154079 2006-01-06 19:22:19Z jhb $");
36153059Smarius
37117119Stmm#include "opt_ofw_pci.h"
38117119Stmm
39117119Stmm#include <sys/param.h>
40117119Stmm#include <sys/kernel.h>
41117119Stmm#include <sys/bus.h>
42117119Stmm#include <sys/module.h>
43117119Stmm
44133589Smarius#include <dev/ofw/ofw_bus.h>
45117119Stmm#include <dev/ofw/openfirm.h>
46117119Stmm
47117119Stmm#include <machine/bus.h>
48117119Stmm#include <machine/ofw_bus.h>
49117119Stmm
50117119Stmm#include <dev/pci/pcireg.h>
51117119Stmm#include <dev/pci/pcivar.h>
52117119Stmm#include <dev/pci/pcib_private.h>
53117119Stmm
54117119Stmm#include "pcib_if.h"
55117119Stmm
56117119Stmm#include <sparc64/pci/ofw_pci.h>
57117119Stmm#include <sparc64/pci/ofw_pcib_subr.h>
58117119Stmm
59117119Stmmstatic device_probe_t ofw_pcib_probe;
60117119Stmmstatic device_attach_t ofw_pcib_attach;
61117119Stmm
62117119Stmmstatic device_method_t ofw_pcib_methods[] = {
63117119Stmm	/* Device interface */
64117119Stmm	DEVMETHOD(device_probe,		ofw_pcib_probe),
65117119Stmm	DEVMETHOD(device_attach,	ofw_pcib_attach),
66117119Stmm	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
67117119Stmm	DEVMETHOD(device_suspend,	bus_generic_suspend),
68117119Stmm	DEVMETHOD(device_resume,	bus_generic_resume),
69117119Stmm
70117119Stmm	/* Bus interface */
71117119Stmm	DEVMETHOD(bus_print_child,	bus_generic_print_child),
72117119Stmm	DEVMETHOD(bus_read_ivar,	pcib_read_ivar),
73117119Stmm	DEVMETHOD(bus_write_ivar,	pcib_write_ivar),
74117119Stmm	DEVMETHOD(bus_alloc_resource,	pcib_alloc_resource),
75117119Stmm	DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
76117119Stmm	DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
77117119Stmm	DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
78117119Stmm	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
79117119Stmm	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
80117119Stmm
81117119Stmm	/* pcib interface */
82117119Stmm	DEVMETHOD(pcib_maxslots,	pcib_maxslots),
83117119Stmm	DEVMETHOD(pcib_read_config,	pcib_read_config),
84117119Stmm	DEVMETHOD(pcib_write_config,	pcib_write_config),
85117119Stmm	DEVMETHOD(pcib_route_interrupt,	ofw_pcib_gen_route_interrupt),
86117119Stmm
87133589Smarius	/* ofw_bus interface */
88133589Smarius	DEVMETHOD(ofw_bus_get_node,	ofw_pcib_gen_get_node),
89133589Smarius
90117119Stmm	/* ofw_pci interface */
91117119Stmm	DEVMETHOD(ofw_pci_adjust_busrange,	ofw_pcib_gen_adjust_busrange),
92117119Stmm
93117119Stmm	{ 0, 0 }
94117119Stmm};
95117119Stmm
96154079Sjhbstatic devclass_t pcib_devclass;
97117119Stmm
98154079SjhbDEFINE_CLASS_0(pcib, ofw_pcib_driver, ofw_pcib_methods,
99154079Sjhb    sizeof(struct ofw_pcib_gen_softc));
100117119StmmDRIVER_MODULE(ofw_pcib, pci, ofw_pcib_driver, pcib_devclass, 0, 0);
101117119Stmm
102117119Stmmstatic int
103117119Stmmofw_pcib_probe(device_t dev)
104117119Stmm{
105117119Stmm	if ((pci_get_class(dev) == PCIC_BRIDGE) &&
106117119Stmm	    (pci_get_subclass(dev) == PCIS_BRIDGE_PCI) &&
107133589Smarius	    ofw_bus_get_node(dev) != 0) {
108117119Stmm		device_set_desc(dev, "OFW PCI-PCI bridge");
109117119Stmm		return (0);
110117119Stmm	}
111117119Stmm	return (ENXIO);
112117119Stmm}
113117119Stmm
114117119Stmmstatic int
115117119Stmmofw_pcib_attach(device_t dev)
116117119Stmm{
117153059Smarius	struct ofw_pcib_gen_softc *sc;
118117119Stmm
119153059Smarius	sc = device_get_softc(dev);
120117119Stmm	ofw_pcib_gen_setup(dev);
121117119Stmm	pcib_attach_common(dev);
122117119Stmm	device_add_child(dev, "pci", sc->ops_pcib_sc.secbus);
123117119Stmm	return (bus_generic_attach(dev));
124117119Stmm}
125