ofw_pcib_pci.c revision 119291
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: head/sys/powerpc/ofw/ofw_pcib_pci.c 119291 2003-08-22 07:39:05Z imp $
28 */
29
30#include <sys/param.h>
31#include <sys/bus.h>
32#include <sys/malloc.h>
33#include <sys/kernel.h>
34
35#include <dev/ofw/openfirm.h>
36#include <dev/ofw/ofw_pci.h>
37
38#include <powerpc/ofw/ofw_pci.h>
39
40#include <dev/pci/pcivar.h>
41#include <dev/pci/pcireg.h>
42#include <dev/pci/pcib_private.h>
43
44#include "pcib_if.h"
45
46static int	ofw_pcib_pci_probe(device_t bus);
47static int	ofw_pcib_pci_attach(device_t bus);
48
49static device_method_t ofw_pcib_pci_methods[] = {
50	/* Device interface */
51	DEVMETHOD(device_probe,		ofw_pcib_pci_probe),
52	DEVMETHOD(device_attach,		ofw_pcib_pci_attach),
53	DEVMETHOD(device_shutdown,		bus_generic_shutdown),
54	DEVMETHOD(device_suspend,		bus_generic_suspend),
55	DEVMETHOD(device_resume,		bus_generic_resume),
56
57	/* Bus interface */
58	DEVMETHOD(bus_print_child,		bus_generic_print_child),
59	DEVMETHOD(bus_read_ivar,		pcib_read_ivar),
60	DEVMETHOD(bus_write_ivar,		pcib_write_ivar),
61	DEVMETHOD(bus_alloc_resource,	pcib_alloc_resource),
62	DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
63	DEVMETHOD(bus_activate_resource,	bus_generic_activate_resource),
64	DEVMETHOD(bus_deactivate_resource, 	bus_generic_deactivate_resource),
65	DEVMETHOD(bus_setup_intr,		bus_generic_setup_intr),
66	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
67
68	/* pcib interface */
69	DEVMETHOD(pcib_maxslots,		pcib_maxslots),
70	DEVMETHOD(pcib_read_config,		pcib_read_config),
71	DEVMETHOD(pcib_write_config,	pcib_write_config),
72	DEVMETHOD(pcib_route_interrupt,	pcib_route_interrupt),
73
74	{0, 0}
75};
76
77static driver_t ofw_pcib_pci_driver = {
78	"pcib",
79	ofw_pcib_pci_methods,
80	sizeof(struct pcib_softc),
81};
82
83DRIVER_MODULE(ofw_pcib, pci, ofw_pcib_pci_driver, pcib_devclass, 0, 0);
84
85static int
86ofw_pcib_pci_probe(device_t dev)
87{
88
89	if ((pci_get_class(dev) != PCIC_BRIDGE) ||
90	    (pci_get_subclass(dev) != PCIS_BRIDGE_PCI)) {
91		return (ENXIO);
92	}
93	if (ofw_pci_find_node(dev) == 0) {
94		return (ENXIO);
95	}
96
97	device_set_desc(dev, "OpenFirmware PCI-PCI bridge");
98	return (-1000);
99}
100
101static int
102ofw_pcib_pci_attach(device_t dev)
103{
104	phandle_t	node;
105	uint32_t	busrange[2];
106
107	node = ofw_pci_find_node(dev);
108	if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8)
109		return (ENXIO);
110
111	pcib_attach_common(dev);
112
113	ofw_pci_fixup(dev, busrange[0], node);
114
115	device_add_child(dev, "pci", -1);
116
117	return (bus_generic_attach(dev));
118}
119