ofw_pcib_pci.c revision 183882
1109001Sbenno/*-
2109001Sbenno * Copyright (c) 2000 Michael Smith
3109001Sbenno * Copyright (c) 2000 BSDi
4109001Sbenno * All rights reserved.
5109001Sbenno *
6109001Sbenno * Redistribution and use in source and binary forms, with or without
7109001Sbenno * modification, are permitted provided that the following conditions
8109001Sbenno * are met:
9109001Sbenno * 1. Redistributions of source code must retain the above copyright
10109001Sbenno *    notice, this list of conditions and the following disclaimer.
11109001Sbenno * 2. Redistributions in binary form must reproduce the above copyright
12109001Sbenno *    notice, this list of conditions and the following disclaimer in the
13109001Sbenno *    documentation and/or other materials provided with the distribution.
14109001Sbenno *
15109001Sbenno * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16109001Sbenno * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17109001Sbenno * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18109001Sbenno * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19109001Sbenno * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20109001Sbenno * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21109001Sbenno * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22109001Sbenno * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23109001Sbenno * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24109001Sbenno * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25109001Sbenno * SUCH DAMAGE.
26109001Sbenno *
27109001Sbenno * $FreeBSD: head/sys/powerpc/ofw/ofw_pcib_pci.c 183882 2008-10-14 14:54:14Z nwhitehorn $
28109001Sbenno */
29109001Sbenno
30109001Sbenno#include <sys/param.h>
31131102Sgrehan#include <sys/module.h>
32109001Sbenno#include <sys/bus.h>
33109001Sbenno#include <sys/malloc.h>
34109001Sbenno#include <sys/kernel.h>
35109001Sbenno
36109001Sbenno#include <dev/ofw/openfirm.h>
37109001Sbenno#include <dev/ofw/ofw_pci.h>
38183882Snwhitehorn#include <dev/ofw/ofw_bus.h>
39109001Sbenno
40119291Simp#include <dev/pci/pcivar.h>
41119291Simp#include <dev/pci/pcireg.h>
42119291Simp#include <dev/pci/pcib_private.h>
43109001Sbenno
44109001Sbenno#include "pcib_if.h"
45109001Sbenno
46109001Sbennostatic int	ofw_pcib_pci_probe(device_t bus);
47109001Sbennostatic int	ofw_pcib_pci_attach(device_t bus);
48183882Snwhitehornstatic phandle_t ofw_pcib_pci_get_node(device_t bus, device_t dev);
49109001Sbenno
50109001Sbennostatic device_method_t ofw_pcib_pci_methods[] = {
51109001Sbenno	/* Device interface */
52109001Sbenno	DEVMETHOD(device_probe,		ofw_pcib_pci_probe),
53109001Sbenno	DEVMETHOD(device_attach,		ofw_pcib_pci_attach),
54109001Sbenno	DEVMETHOD(device_shutdown,		bus_generic_shutdown),
55109001Sbenno	DEVMETHOD(device_suspend,		bus_generic_suspend),
56109001Sbenno	DEVMETHOD(device_resume,		bus_generic_resume),
57109001Sbenno
58109001Sbenno	/* Bus interface */
59109001Sbenno	DEVMETHOD(bus_print_child,		bus_generic_print_child),
60109001Sbenno	DEVMETHOD(bus_read_ivar,		pcib_read_ivar),
61109001Sbenno	DEVMETHOD(bus_write_ivar,		pcib_write_ivar),
62109001Sbenno	DEVMETHOD(bus_alloc_resource,	pcib_alloc_resource),
63109001Sbenno	DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
64109001Sbenno	DEVMETHOD(bus_activate_resource,	bus_generic_activate_resource),
65109001Sbenno	DEVMETHOD(bus_deactivate_resource, 	bus_generic_deactivate_resource),
66109001Sbenno	DEVMETHOD(bus_setup_intr,		bus_generic_setup_intr),
67109001Sbenno	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
68109001Sbenno
69109001Sbenno	/* pcib interface */
70109001Sbenno	DEVMETHOD(pcib_maxslots,		pcib_maxslots),
71109001Sbenno	DEVMETHOD(pcib_read_config,		pcib_read_config),
72109001Sbenno	DEVMETHOD(pcib_write_config,	pcib_write_config),
73109001Sbenno	DEVMETHOD(pcib_route_interrupt,	pcib_route_interrupt),
74109001Sbenno
75183882Snwhitehorn	/* ofw_bus interface */
76183882Snwhitehorn	DEVMETHOD(ofw_bus_get_node,     ofw_pcib_pci_get_node),
77183882Snwhitehorn
78109001Sbenno	{0, 0}
79109001Sbenno};
80109001Sbenno
81154079Sjhbstatic devclass_t pcib_devclass;
82109001Sbenno
83154079SjhbDEFINE_CLASS_0(pcib, ofw_pcib_pci_driver, ofw_pcib_pci_methods,
84154079Sjhb    sizeof(struct pcib_softc));
85109001SbennoDRIVER_MODULE(ofw_pcib, pci, ofw_pcib_pci_driver, pcib_devclass, 0, 0);
86109001Sbenno
87109001Sbennostatic int
88109001Sbennoofw_pcib_pci_probe(device_t dev)
89109001Sbenno{
90109001Sbenno
91109001Sbenno	if ((pci_get_class(dev) != PCIC_BRIDGE) ||
92109001Sbenno	    (pci_get_subclass(dev) != PCIS_BRIDGE_PCI)) {
93109001Sbenno		return (ENXIO);
94109001Sbenno	}
95183882Snwhitehorn
96183882Snwhitehorn	if (ofw_bus_get_node(dev) == 0)
97109001Sbenno		return (ENXIO);
98109001Sbenno
99183882Snwhitehorn	device_set_desc(dev, "OFW PCI-PCI bridge");
100183882Snwhitehorn	return (0);
101109001Sbenno}
102109001Sbenno
103109001Sbennostatic int
104109001Sbennoofw_pcib_pci_attach(device_t dev)
105109001Sbenno{
106109001Sbenno	pcib_attach_common(dev);
107109001Sbenno
108109001Sbenno	device_add_child(dev, "pci", -1);
109109001Sbenno
110109001Sbenno	return (bus_generic_attach(dev));
111109001Sbenno}
112183882Snwhitehorn
113183882Snwhitehornphandle_t
114183882Snwhitehornofw_pcib_pci_get_node(device_t bridge, device_t dev)
115183882Snwhitehorn{
116183882Snwhitehorn	/* We have only one child, the PCI bus, so pass it our node */
117183882Snwhitehorn
118183882Snwhitehorn	return (ofw_bus_get_node(bridge));
119183882Snwhitehorn}
120183882Snwhitehorn
121