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
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include "opt_acpi.h"
32 #include <sys/param.h>
33 #include <sys/bus.h>
34 #include <sys/malloc.h>
35 #include <sys/kernel.h>
36
37 #include "acpi.h"
38 #include <dev/acpica/acpivar.h>
39 #include <dev/acpica/acpi_pcibvar.h>
40
41 #include <dev/pci/pcivar.h>
42 #include "pcib_if.h"
43
44 /* Hooks for the ACPI CA debugging infrastructure. */
45 #define _COMPONENT ACPI_BUS
46 ACPI_MODULE_NAME("PCI")
47
48 ACPI_SERIAL_DECL(pcib, "ACPI PCI bus methods");
49
50 /*
51 * For locking, we assume the caller is not concurrent since this is
52 * triggered by newbus methods.
53 */
54 int
55 acpi_pcib_attach(device_t dev, ACPI_BUFFER *prt, int busno)
56 {
57 device_t child;
58 ACPI_STATUS status;
59
60 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
61
62 /*
63 * Don't attach if we're not really there.
64 *
65 * XXX: This isn't entirely correct since we may be a PCI bus
66 * on a hot-plug docking station, etc.
67 */
68 if (!acpi_DeviceIsPresent(dev))
69 return_VALUE(ENXIO);
70
71 /*
72 * Get the PCI interrupt routing table for this bus. If we can't
73 * get it, this is not an error but may reduce functionality. There
74 * are several valid bridges in the field that do not have a _PRT, so
75 * only warn about missing tables if bootverbose is set.
76 */
77 prt->Length = ACPI_ALLOCATE_BUFFER;
78 status = AcpiGetIrqRoutingTable(acpi_get_handle(dev), prt);
79 if (ACPI_FAILURE(status) && (bootverbose || status != AE_NOT_FOUND))
80 device_printf(dev,
81 "could not get PCI interrupt routing table for %s - %s\n",
82 acpi_name(acpi_get_handle(dev)), AcpiFormatException(status));
83
84 /*
85 * Attach the PCI bus proper.
86 */
87 if ((child = device_add_child(dev, "pci", busno)) == NULL) {
88 device_printf(device_get_parent(dev), "couldn't attach pci bus\n");
89 return_VALUE(ENXIO);
90 }
91
92 /*
93 * Now go scan the bus.
94 */
95 acpi_pci_link_config(dev, prt, busno);
96
97 return_VALUE (bus_generic_attach(dev));
98 }
99
100 int
101 acpi_pcib_resume(device_t dev)
102 {
103 acpi_pci_link_resume(dev);
104 return (bus_generic_resume(dev));
105 }
106
107 /*
108 * Route an interrupt for a child of the bridge.
109 */
110 int
111 acpi_pcib_route_interrupt(device_t pcib, device_t dev, int pin)
112 {
113 struct acpi_prt_entry *entry;
114 int i, interrupt;
115 struct acpi_pci_link_entry *link;
116 ACPI_PCI_ROUTING_TABLE *prt;
117
118 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
119
120 interrupt = PCI_INVALID_IRQ;
121
122 /* ACPI numbers pins 0-3, not 1-4 like the BIOS. */
123 pin--;
124
125 ACPI_SERIAL_BEGIN(pcib);
126
127 /* Look up the PRT entry for this device. */
128 entry = acpi_pci_find_prt(pcib, dev, pin);
129 if (entry == NULL) {
130 device_printf(pcib, "no PRT entry for %d.%d.INT%c\n", pci_get_bus(dev),
131 pci_get_slot(dev), 'A' + pin);
132 goto out;
133 }
134 prt = &entry->prt;
135 link = entry->pci_link;
136 if (bootverbose) {
137 device_printf(pcib, "matched entry for %d.%d.INT%c",
138 pci_get_bus(dev), pci_get_slot(dev), 'A' + pin);
139 if (prt->Source[0] != '\0')
140 printf(" (src %s)", acpi_name(entry->prt_source));
141 printf("\n");
142 }
143
144 /*
145 * If source is empty/NULL, the source index is a global IRQ number
146 * and it's hard-wired so we're done.
147 */
148 if (prt->Source == NULL || prt->Source[0] == '\0') {
149 if (bootverbose)
150 device_printf(pcib, "slot %d INT%c hardwired to IRQ %d\n",
151 pci_get_slot(dev), 'A' + pin, prt->SourceIndex);
152 if (prt->SourceIndex)
153 interrupt = prt->SourceIndex;
154 else
155 device_printf(pcib, "error: invalid hard-wired IRQ of 0\n");
156 goto out;
157 }
158
159 /* XXX Support for multiple resources must be added to the link code. */
160 if (prt->SourceIndex) {
161 device_printf(pcib, "src index %d not yet supported\n",
162 prt->SourceIndex);
163 goto out;
164 }
165
166 /* There has to be at least one interrupt available. */
167 if (link->number_of_interrupts == 0) {
168 device_printf(pcib, "device has no interrupts\n");
169 goto out;
170 }
171
172 /*
173 * If the current interrupt has been routed, we're done. This is the
174 * case when the BIOS initializes it and we didn't disable it.
175 */
176 if (link->flags & ACPI_LINK_ROUTED) {
177 interrupt = link->current_irq;
178 if (bootverbose)
179 device_printf(pcib, "slot %d INT%c is already routed to irq %d\n",
180 pci_get_slot(dev), 'A' + pin, interrupt);
181 goto out;
182 }
183
184 if (bootverbose) {
185 device_printf(pcib, "possible interrupts:");
186 for (i = 0; i < link->number_of_interrupts; i++)
187 printf("%3d", link->interrupts[i]);
188 printf("\n");
189 }
190
191 /*
192 * Perform the link routing. The link code will pick the best IRQ
193 * for this pin and configure it.
194 */
195 interrupt = acpi_pci_link_route(dev, entry);
196
197 if (bootverbose && PCI_INTERRUPT_VALID(interrupt))
198 device_printf(pcib, "slot %d INT%c routed to irq %d via %s\n",
199 pci_get_slot(dev), 'A' + pin, interrupt,
200 acpi_name(entry->prt_source));
201
202 out:
203 ACPI_SERIAL_END(pcib);
204
205 return_VALUE (interrupt);
206 }
Cache object: 8c9d952e9f875994cd6a27f24034d27c
|