OsdHardware.c (126560) | OsdHardware.c (128225) |
---|---|
1/*- 2 * Copyright (c) 2000, 2001 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: --- 10 unchanged lines hidden (view full) --- 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 * | 1/*- 2 * Copyright (c) 2000, 2001 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: --- 10 unchanged lines hidden (view full) --- 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/dev/acpica/Osd/OsdHardware.c 126560 2004-03-03 18:34:42Z njl $ | 27 * $FreeBSD: head/sys/dev/acpica/Osd/OsdHardware.c 128225 2004-04-14 03:39:08Z njl $ |
28 */ 29 30/* 31 * 6.7 : Hardware Abstraction 32 */ 33 34#include "acpi.h" 35 --- 26 unchanged lines hidden (view full) --- 62#define ACPI_BUS_HANDLE 0 63#endif 64#ifdef __amd64__ 65#define ACPI_BUS_SPACE_IO AMD64_BUS_SPACE_IO 66#define ACPI_BUS_HANDLE 0 67#endif 68 69ACPI_STATUS | 28 */ 29 30/* 31 * 6.7 : Hardware Abstraction 32 */ 33 34#include "acpi.h" 35 --- 26 unchanged lines hidden (view full) --- 62#define ACPI_BUS_HANDLE 0 63#endif 64#ifdef __amd64__ 65#define ACPI_BUS_SPACE_IO AMD64_BUS_SPACE_IO 66#define ACPI_BUS_HANDLE 0 67#endif 68 69ACPI_STATUS |
70AcpiOsReadPort ( 71 ACPI_IO_ADDRESS InPort, 72 UINT32 *Value, 73 UINT32 Width) | 70AcpiOsReadPort(ACPI_IO_ADDRESS InPort, UINT32 *Value, UINT32 Width) |
74{ 75 switch (Width) { 76 case 8: | 71{ 72 switch (Width) { 73 case 8: |
77 *(u_int8_t *)Value = bus_space_read_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort); | 74 *(u_int8_t *)Value = bus_space_read_1(ACPI_BUS_SPACE_IO, 75 ACPI_BUS_HANDLE, InPort); |
78 break; 79 case 16: | 76 break; 77 case 16: |
80 *(u_int16_t *)Value = bus_space_read_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort); | 78 *(u_int16_t *)Value = bus_space_read_2(ACPI_BUS_SPACE_IO, 79 ACPI_BUS_HANDLE, InPort); |
81 break; 82 case 32: | 80 break; 81 case 32: |
83 *(u_int32_t *)Value = bus_space_read_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort); | 82 *(u_int32_t *)Value = bus_space_read_4(ACPI_BUS_SPACE_IO, 83 ACPI_BUS_HANDLE, InPort); |
84 break; 85 default: 86 /* debug trap goes here */ 87 break; 88 } 89 | 84 break; 85 default: 86 /* debug trap goes here */ 87 break; 88 } 89 |
90 return(AE_OK); | 90 return (AE_OK); |
91} 92 93ACPI_STATUS | 91} 92 93ACPI_STATUS |
94AcpiOsWritePort ( 95 ACPI_IO_ADDRESS OutPort, 96 UINT32 Value, 97 UINT32 Width) | 94AcpiOsWritePort(ACPI_IO_ADDRESS OutPort, UINT32 Value, UINT32 Width) |
98{ 99 switch (Width) { 100 case 8: 101 bus_space_write_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value); 102 break; 103 case 16: 104 bus_space_write_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value); 105 break; 106 case 32: 107 bus_space_write_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value); 108 break; 109 default: 110 /* debug trap goes here */ 111 break; 112 } 113 | 95{ 96 switch (Width) { 97 case 8: 98 bus_space_write_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value); 99 break; 100 case 16: 101 bus_space_write_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value); 102 break; 103 case 32: 104 bus_space_write_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value); 105 break; 106 default: 107 /* debug trap goes here */ 108 break; 109 } 110 |
114 return(AE_OK); | 111 return (AE_OK); |
115} 116 117ACPI_STATUS | 112} 113 114ACPI_STATUS |
118AcpiOsReadPciConfiguration ( 119 ACPI_PCI_ID *PciId, 120 UINT32 Register, 121 void *Value, 122 UINT32 Width) | 115AcpiOsReadPciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, void *Value, 116 UINT32 Width) |
123{ 124 u_int32_t byte_width = Width / 8; 125 u_int32_t val; 126 127 if (!pci_cfgregopen()) | 117{ 118 u_int32_t byte_width = Width / 8; 119 u_int32_t val; 120 121 if (!pci_cfgregopen()) |
128 return(AE_NOT_EXIST); | 122 return (AE_NOT_EXIST); |
129 | 123 |
130 val = pci_cfgregread(PciId->Bus, PciId->Device, PciId->Function, Register, byte_width); | 124 val = pci_cfgregread(PciId->Bus, PciId->Device, PciId->Function, Register, 125 byte_width); |
131 switch (Width) { 132 case 8: 133 *(u_int8_t *)Value = val & 0xff; 134 break; 135 case 16: 136 *(u_int16_t *)Value = val & 0xffff; 137 break; 138 case 32: 139 *(u_int32_t *)Value = val; 140 break; 141 default: 142 /* debug trap goes here */ 143 break; 144 } 145 | 126 switch (Width) { 127 case 8: 128 *(u_int8_t *)Value = val & 0xff; 129 break; 130 case 16: 131 *(u_int16_t *)Value = val & 0xffff; 132 break; 133 case 32: 134 *(u_int32_t *)Value = val; 135 break; 136 default: 137 /* debug trap goes here */ 138 break; 139 } 140 |
146 147 return(AE_OK); | 141 return (AE_OK); |
148} 149 150 151ACPI_STATUS | 142} 143 144 145ACPI_STATUS |
152AcpiOsWritePciConfiguration ( 153 ACPI_PCI_ID *PciId, 154 UINT32 Register, 155 ACPI_INTEGER Value, 156 UINT32 Width) | 146AcpiOsWritePciConfiguration (ACPI_PCI_ID *PciId, UINT32 Register, 147 ACPI_INTEGER Value, UINT32 Width) |
157{ 158 u_int32_t byte_width = Width / 8; 159 160 if (!pci_cfgregopen()) | 148{ 149 u_int32_t byte_width = Width / 8; 150 151 if (!pci_cfgregopen()) |
161 return(AE_NOT_EXIST); | 152 return (AE_NOT_EXIST); |
162 | 153 |
163 pci_cfgregwrite(PciId->Bus, PciId->Device, PciId->Function, Register, Value, byte_width); | 154 pci_cfgregwrite(PciId->Bus, PciId->Device, PciId->Function, Register, 155 Value, byte_width); |
164 | 156 |
165 return(AE_OK); | 157 return (AE_OK); |
166} 167 168/* XXX should use acpivar.h but too many include dependencies */ 169extern ACPI_STATUS acpi_GetInteger(ACPI_HANDLE handle, char *path, int 170 *number); 171 172/* 173 * Depth-first recursive case for finding the bus, given the slot/function. 174 */ 175static int 176acpi_bus_number(ACPI_HANDLE root, ACPI_HANDLE curr, ACPI_PCI_ID *PciId) 177{ 178 ACPI_HANDLE parent; | 158} 159 160/* XXX should use acpivar.h but too many include dependencies */ 161extern ACPI_STATUS acpi_GetInteger(ACPI_HANDLE handle, char *path, int 162 *number); 163 164/* 165 * Depth-first recursive case for finding the bus, given the slot/function. 166 */ 167static int 168acpi_bus_number(ACPI_HANDLE root, ACPI_HANDLE curr, ACPI_PCI_ID *PciId) 169{ 170 ACPI_HANDLE parent; |
171 ACPI_STATUS status; |
|
179 ACPI_OBJECT_TYPE type; 180 UINT32 adr; 181 int bus, slot, func, class, subclass, header; 182 | 172 ACPI_OBJECT_TYPE type; 173 UINT32 adr; 174 int bus, slot, func, class, subclass, header; 175 |
183 /* Try to get the _BBN object of the root, otherwise assume it is 0 */ | 176 /* Try to get the _BBN object of the root, otherwise assume it is 0. */ |
184 bus = 0; 185 if (root == curr) { | 177 bus = 0; 178 if (root == curr) { |
186 if (ACPI_FAILURE(acpi_GetInteger(root, "_BBN", &bus)) && 187 bootverbose) 188 printf("acpi_bus_number: root bus has no _BBN, assuming 0\n"); | 179 status = acpi_GetInteger(root, "_BBN", &bus); 180 if (ACPI_FAILURE(status) && bootverbose) 181 printf("acpi_bus_number: root bus has no _BBN, assuming 0\n"); |
189 return (bus); 190 } | 182 return (bus); 183 } |
191 if (ACPI_FAILURE(AcpiGetParent(curr, &parent))) 192 return (bus); | 184 status = AcpiGetParent(curr, &parent); 185 if (ACPI_FAILURE(status)) 186 return (bus); |
193 | 187 |
194 /* First, recurse up the tree until we find the host bus */ | 188 /* First, recurse up the tree until we find the host bus. */ |
195 bus = acpi_bus_number(root, parent, PciId); 196 | 189 bus = acpi_bus_number(root, parent, PciId); 190 |
197 /* Validate parent bus device type */ | 191 /* Validate parent bus device type. */ |
198 if (ACPI_FAILURE(AcpiGetType(parent, &type)) || type != ACPI_TYPE_DEVICE) { | 192 if (ACPI_FAILURE(AcpiGetType(parent, &type)) || type != ACPI_TYPE_DEVICE) { |
199 printf("acpi_bus_number: not a device, type %d\n", type); 200 return (bus); | 193 printf("acpi_bus_number: not a device, type %d\n", type); 194 return (bus); |
201 } | 195 } |
202 /* Get the parent's slot and function */ 203 if (ACPI_FAILURE(acpi_GetInteger(parent, "_ADR", &adr))) { 204 printf("acpi_bus_number: can't get _ADR\n"); 205 return (bus); | 196 197 /* Get the parent's slot and function. */ 198 status = acpi_GetInteger(parent, "_ADR", &adr); 199 if (ACPI_FAILURE(status)) { 200 printf("acpi_bus_number: can't get _ADR\n"); 201 return (bus); |
206 } 207 slot = ACPI_HIWORD(adr); 208 func = ACPI_LOWORD(adr); 209 210 /* Is this a PCI-PCI or Cardbus-PCI bridge? */ 211 class = pci_cfgregread(bus, slot, func, PCIR_CLASS, 1); 212 if (class != PCIC_BRIDGE) | 202 } 203 slot = ACPI_HIWORD(adr); 204 func = ACPI_LOWORD(adr); 205 206 /* Is this a PCI-PCI or Cardbus-PCI bridge? */ 207 class = pci_cfgregread(bus, slot, func, PCIR_CLASS, 1); 208 if (class != PCIC_BRIDGE) |
213 return (bus); | 209 return (bus); |
214 subclass = pci_cfgregread(bus, slot, func, PCIR_SUBCLASS, 1); | 210 subclass = pci_cfgregread(bus, slot, func, PCIR_SUBCLASS, 1); |
215 /* Find the header type, masking off the multifunction bit */ | 211 212 /* Find the header type, masking off the multifunction bit. */ |
216 header = pci_cfgregread(bus, slot, func, PCIR_HDRTYPE, 1) & PCIM_HDRTYPE; 217 if (header == PCIM_HDRTYPE_BRIDGE && subclass == PCIS_BRIDGE_PCI) | 213 header = pci_cfgregread(bus, slot, func, PCIR_HDRTYPE, 1) & PCIM_HDRTYPE; 214 if (header == PCIM_HDRTYPE_BRIDGE && subclass == PCIS_BRIDGE_PCI) |
218 bus = pci_cfgregread(bus, slot, func, PCIR_SECBUS_1, 1); | 215 bus = pci_cfgregread(bus, slot, func, PCIR_SECBUS_1, 1); |
219 if (header == PCIM_HDRTYPE_CARDBUS && subclass == PCIS_BRIDGE_CARDBUS) | 216 if (header == PCIM_HDRTYPE_CARDBUS && subclass == PCIS_BRIDGE_CARDBUS) |
220 bus = pci_cfgregread(bus, slot, func, PCIR_SECBUS_2, 1); | 217 bus = pci_cfgregread(bus, slot, func, PCIR_SECBUS_2, 1); |
221 return (bus); 222} 223 224/* 225 * Find the bus number for a device 226 * 227 * rhandle: handle for the root bus 228 * chandle: handle for the device 229 * PciId: pointer to device slot and function, we fill out bus 230 */ 231void | 218 return (bus); 219} 220 221/* 222 * Find the bus number for a device 223 * 224 * rhandle: handle for the root bus 225 * chandle: handle for the device 226 * PciId: pointer to device slot and function, we fill out bus 227 */ 228void |
232AcpiOsDerivePciId ( 233 ACPI_HANDLE rhandle, 234 ACPI_HANDLE chandle, 235 ACPI_PCI_ID **PciId) | 229AcpiOsDerivePciId(ACPI_HANDLE rhandle, ACPI_HANDLE chandle, ACPI_PCI_ID **PciId) |
236{ 237 ACPI_HANDLE parent; | 230{ 231 ACPI_HANDLE parent; |
232 ACPI_STATUS status; |
|
238 int bus; 239 240 if (pci_cfgregopen() == 0) | 233 int bus; 234 235 if (pci_cfgregopen() == 0) |
241 panic("AcpiOsDerivePciId unable to initialize pci bus"); | 236 panic("AcpiOsDerivePciId unable to initialize pci bus"); |
242 243 /* Try to read _BBN for bus number if we're at the root */ 244 bus = 0; 245 if (rhandle == chandle) { | 237 238 /* Try to read _BBN for bus number if we're at the root */ 239 bus = 0; 240 if (rhandle == chandle) { |
246 if (ACPI_FAILURE(acpi_GetInteger(rhandle, "_BBN", &bus)) && 247 bootverbose) 248 printf("AcpiOsDerivePciId: root bus has no _BBN, assuming 0\n"); | 241 status = acpi_GetInteger(rhandle, "_BBN", &bus); 242 if (ACPI_FAILURE(status) && bootverbose) 243 printf("AcpiOsDerivePciId: root bus has no _BBN, assuming 0\n"); |
249 } | 244 } |
245 |
|
250 /* 251 * Get the parent handle and call the recursive case. It is not 252 * clear why we seem to be getting a chandle that points to a child 253 * of the desired slot/function but passing in the parent handle 254 * here works. 255 */ 256 if (ACPI_SUCCESS(AcpiGetParent(chandle, &parent))) | 246 /* 247 * Get the parent handle and call the recursive case. It is not 248 * clear why we seem to be getting a chandle that points to a child 249 * of the desired slot/function but passing in the parent handle 250 * here works. 251 */ 252 if (ACPI_SUCCESS(AcpiGetParent(chandle, &parent))) |
257 bus = acpi_bus_number(rhandle, parent, *PciId); | 253 bus = acpi_bus_number(rhandle, parent, *PciId); |
258 (*PciId)->Bus = bus; 259 if (bootverbose) { | 254 (*PciId)->Bus = bus; 255 if (bootverbose) { |
260 printf("AcpiOsDerivePciId: bus %d dev %d func %d\n", 261 (*PciId)->Bus, (*PciId)->Device, (*PciId)->Function); | 256 printf("AcpiOsDerivePciId: bus %d dev %d func %d\n", 257 (*PciId)->Bus, (*PciId)->Device, (*PciId)->Function); |
262 } 263} | 258 } 259} |