1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2003 by Thomas Moestl <tmm@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
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 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include "opt_ofw_pci.h"
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/bus.h>
36 #include <sys/rman.h>
37
38 #include <dev/ofw/ofw_bus.h>
39 #include <dev/ofw/ofw_pci.h>
40 #include <dev/ofw/openfirm.h>
41
42 #include <machine/bus.h>
43
44 #include <dev/pci/pcireg.h>
45 #include <dev/pci/pcivar.h>
46 #include <dev/pci/pcib_private.h>
47
48 #include "pcib_if.h"
49
50 #include <sparc64/pci/ofw_pci.h>
51 #include <sparc64/pci/ofw_pcib_subr.h>
52
53 void
54 ofw_pcib_gen_setup(device_t bridge)
55 {
56 struct ofw_pcib_gen_softc *sc;
57
58 sc = device_get_softc(bridge);
59 sc->ops_pcib_sc.dev = bridge;
60 sc->ops_node = ofw_bus_get_node(bridge);
61 KASSERT(sc->ops_node != 0,
62 ("ofw_pcib_gen_setup: no ofw pci parent bus!"));
63
64 ofw_bus_setup_iinfo(sc->ops_node, &sc->ops_iinfo,
65 sizeof(ofw_pci_intr_t));
66 }
67
68 int
69 ofw_pcib_gen_route_interrupt(device_t bridge, device_t dev, int intpin)
70 {
71 struct ofw_pcib_gen_softc *sc;
72 struct ofw_bus_iinfo *ii;
73 struct ofw_pci_register reg;
74 ofw_pci_intr_t pintr, mintr;
75
76 sc = device_get_softc(bridge);
77 ii = &sc->ops_iinfo;
78 if (ii->opi_imapsz > 0) {
79 pintr = intpin;
80 if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), ii, ®,
81 sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr),
82 NULL)) {
83 /*
84 * If we've found a mapping, return it and don't map
85 * it again on higher levels - that causes problems
86 * in some cases, and never seems to be required.
87 */
88 return (mintr);
89 }
90 } else if (intpin >= 1 && intpin <= 4) {
91 /*
92 * When an interrupt map is missing, we need to do the
93 * standard PCI swizzle and continue mapping at the parent.
94 */
95 return (pcib_route_interrupt(bridge, dev, intpin));
96 }
97 /* Try at the parent. */
98 return (PCIB_ROUTE_INTERRUPT(device_get_parent(device_get_parent(
99 bridge)), bridge, intpin));
100 }
101
102 phandle_t
103 ofw_pcib_gen_get_node(device_t bridge, device_t dev)
104 {
105 struct ofw_pcib_gen_softc *sc;
106
107 sc = device_get_softc(bridge);
108 return (sc->ops_node);
109 }
Cache object: 922aa1449ab56c39106732c83210628d
|