1/* 2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org> 3 * Copyright (c) 2000, Michael Smith <msmith@freebsd.org> 4 * Copyright (c) 2000, BSDi 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 unmodified, this list of conditions, and the following 12 * disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h>
|
91 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 92 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 93 94 DEVMETHOD(bus_get_resource_list,pci_get_resource_list), 95 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource), 96 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), 97 DEVMETHOD(bus_delete_resource, pci_delete_resource), 98 DEVMETHOD(bus_alloc_resource, pci_alloc_resource), 99 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource), 100 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 101 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 102 DEVMETHOD(bus_child_pnpinfo_str, pci_child_pnpinfo_str_method), 103 DEVMETHOD(bus_child_location_str, acpi_pci_child_location_str_method), 104 105 /* PCI interface */ 106 DEVMETHOD(pci_read_config, pci_read_config_method), 107 DEVMETHOD(pci_write_config, pci_write_config_method), 108 DEVMETHOD(pci_enable_busmaster, pci_enable_busmaster_method), 109 DEVMETHOD(pci_disable_busmaster, pci_disable_busmaster_method), 110 DEVMETHOD(pci_enable_io, pci_enable_io_method), 111 DEVMETHOD(pci_disable_io, pci_disable_io_method), 112 DEVMETHOD(pci_get_powerstate, pci_get_powerstate_method), 113 DEVMETHOD(pci_set_powerstate, acpi_pci_set_powerstate_method), 114 DEVMETHOD(pci_assign_interrupt, pci_assign_interrupt_method), 115 116 { 0, 0 } 117}; 118 119static driver_t acpi_pci_driver = { 120 "pci", 121 acpi_pci_methods, 122 0, /* no softc */ 123}; 124 125DRIVER_MODULE(acpi_pci, pcib, acpi_pci_driver, pci_devclass, 0, 0); 126MODULE_VERSION(acpi_pci, 1); 127MODULE_DEPEND(acpi_pci, pci, 1, 1, 1); 128 129static int 130acpi_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) 131{ 132 struct acpi_pci_devinfo *dinfo; 133 134 switch (which) { 135 case ACPI_IVAR_HANDLE: 136 dinfo = device_get_ivars(child); 137 *result = (uintptr_t)dinfo->ap_handle; 138 return (0); 139 } 140 return (pci_read_ivar(dev, child, which, result)); 141} 142 143static int 144acpi_pci_child_location_str_method(device_t cbdev, device_t child, char *buf, 145 size_t buflen) 146{ 147 struct acpi_pci_devinfo *dinfo = device_get_ivars(child); 148 149 pci_child_location_str_method(cbdev, child, buf, buflen); 150 151 if (dinfo->ap_handle) { 152 strlcat(buf, " path=", buflen); 153 strlcat(buf, acpi_name(dinfo->ap_handle), buflen); 154 } 155 return (0); 156} 157 158/* 159 * PCI power manangement 160 */ 161static int 162acpi_pci_set_powerstate_method(device_t dev, device_t child, int state) 163{ 164 ACPI_STATUS status; 165 int acpi_state, old_state, error; 166 167 switch (state) { 168 case PCI_POWERSTATE_D0: 169 acpi_state = ACPI_STATE_D0; 170 break; 171 case PCI_POWERSTATE_D1: 172 acpi_state = ACPI_STATE_D1; 173 break; 174 case PCI_POWERSTATE_D2: 175 acpi_state = ACPI_STATE_D2; 176 break; 177 case PCI_POWERSTATE_D3: 178 acpi_state = ACPI_STATE_D3; 179 break; 180 default: 181 return (EINVAL); 182 } 183 184 /* 185 * We set the state using PCI Power Management outside of setting 186 * the ACPI state. This means that when powering down a device, we 187 * first shut it down using PCI, and then using ACPI, which lets ACPI 188 * try to power down any Power Resources that are now no longer used. 189 * When powering up a device, we let ACPI set the state first so that 190 * it can enable any needed Power Resources before changing the PCI 191 * power state. 192 */ 193 old_state = pci_get_powerstate(child); 194 if (old_state < state) { 195 error = pci_set_powerstate_method(dev, child, state); 196 if (error) 197 return (error); 198 } 199 status = acpi_pwr_switch_consumer(acpi_get_handle(child), acpi_state); 200 if (ACPI_FAILURE(status)) 201 device_printf(dev, 202 "Failed to set ACPI power state D%d on %s: %s\n", 203 acpi_state, device_get_nameunit(child), 204 AcpiFormatException(status)); 205 if (state > old_state) 206 return (pci_set_powerstate_method(dev, child, state)); 207 else 208 return (0); 209} 210 211static ACPI_STATUS 212acpi_pci_save_handle(ACPI_HANDLE handle, UINT32 level, void *context, 213 void **status) 214{ 215 struct acpi_pci_devinfo *dinfo; 216 device_t *devlist; 217 int devcount, i, func, slot; 218 UINT32 address; 219 220 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 221 222 if (ACPI_FAILURE(acpi_GetInteger(handle, "_ADR", &address))) 223 return_ACPI_STATUS(AE_OK); 224 slot = address >> 16; 225 func = address & 0xffff; 226 if (device_get_children((device_t)context, &devlist, &devcount) != 0) 227 return_ACPI_STATUS(AE_OK); 228 for (i = 0; i < devcount; i++) { 229 dinfo = device_get_ivars(devlist[i]); 230 if (dinfo->ap_dinfo.cfg.func == func && 231 dinfo->ap_dinfo.cfg.slot == slot) { 232 dinfo->ap_handle = handle; 233 free(devlist, M_TEMP); 234 return_ACPI_STATUS(AE_OK); 235 } 236 } 237 free(devlist, M_TEMP); 238 return_ACPI_STATUS(AE_OK); 239} 240 241static int 242acpi_pci_probe(device_t dev) 243{ 244 245 if (pcib_get_bus(dev) < 0) 246 return (ENXIO); 247 248 device_set_desc(dev, "ACPI PCI bus"); 249 250 if (acpi_get_handle(dev) == NULL) 251 return (ENXIO); 252 return (0); 253} 254 255static int 256acpi_pci_attach(device_t dev) 257{ 258 int busno; 259 260 /* 261 * Since there can be multiple independantly numbered PCI 262 * busses on some large alpha systems, we can't use the unit 263 * number to decide what bus we are probing. We ask the parent 264 * pcib what our bus number is. 265 */ 266 busno = pcib_get_bus(dev); 267 if (bootverbose) 268 device_printf(dev, "physical bus=%d\n", busno); 269 270 /* 271 * First, PCI devices are added as in the normal PCI bus driver. 272 * Afterwards, the ACPI namespace under the bridge driver is 273 * walked to save ACPI handles to all the devices that appear in 274 * the ACPI namespace as immediate descendants of the bridge. 275 * 276 * XXX: Sometimes PCI devices show up in the ACPI namespace that 277 * pci_add_children() doesn't find. We currently just ignore 278 * these devices. 279 */ 280 pci_add_children(dev, busno, sizeof(struct acpi_pci_devinfo)); 281 (void) AcpiWalkNamespace(ACPI_TYPE_DEVICE, acpi_get_handle(dev), 1, 282 acpi_pci_save_handle, dev, NULL); 283 284 return (bus_generic_attach(dev)); 285}
|