Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ACPI PCI HotPlug glue functions to ACPI CA subsystem |
| 3 | * |
| 4 | * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com) |
| 5 | * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com) |
| 6 | * Copyright (C) 2002,2003 NEC Corporation |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 7 | * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com) |
| 8 | * Copyright (C) 2003-2005 Hewlett Packard |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 9 | * Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com) |
| 10 | * Copyright (C) 2005 Intel Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * All rights reserved. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or (at |
| 17 | * your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, but |
| 20 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 22 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 23 | * details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program; if not, write to the Free Software |
| 27 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 28 | * |
| 29 | * Send feedback to <t-kochi@bq.jp.nec.com> |
| 30 | * |
| 31 | */ |
| 32 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 33 | /* |
| 34 | * Lifetime rules for pci_dev: |
| 35 | * - The one in acpiphp_func has its refcount elevated by pci_get_slot() |
| 36 | * when the driver is loaded or when an insertion event occurs. It loses |
| 37 | * a refcount when its ejected or the driver unloads. |
| 38 | * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot() |
| 39 | * when the bridge is scanned and it loses a refcount when the bridge |
| 40 | * is removed. |
| 41 | */ |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/init.h> |
| 44 | #include <linux/module.h> |
| 45 | |
| 46 | #include <linux/kernel.h> |
| 47 | #include <linux/pci.h> |
| 48 | #include <linux/smp_lock.h> |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 49 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #include "../pci.h" |
| 52 | #include "pci_hotplug.h" |
| 53 | #include "acpiphp.h" |
| 54 | |
| 55 | static LIST_HEAD(bridge_list); |
| 56 | |
| 57 | #define MY_NAME "acpiphp_glue" |
| 58 | |
| 59 | static void handle_hotplug_event_bridge (acpi_handle, u32, void *); |
Kristen Accardi | 8e5dce3 | 2005-10-18 17:21:40 -0700 | [diff] [blame] | 60 | static void acpiphp_sanitize_bus(struct pci_bus *bus); |
| 61 | static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus); |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * initialization & terminatation routines |
| 66 | */ |
| 67 | |
| 68 | /** |
| 69 | * is_ejectable - determine if a slot is ejectable |
| 70 | * @handle: handle to acpi namespace |
| 71 | * |
| 72 | * Ejectable slot should satisfy at least these conditions: |
| 73 | * |
| 74 | * 1. has _ADR method |
| 75 | * 2. has _EJ0 method |
| 76 | * |
| 77 | * optionally |
| 78 | * |
| 79 | * 1. has _STA method |
| 80 | * 2. has _PS0 method |
| 81 | * 3. has _PS3 method |
| 82 | * 4. .. |
| 83 | * |
| 84 | */ |
| 85 | static int is_ejectable(acpi_handle handle) |
| 86 | { |
| 87 | acpi_status status; |
| 88 | acpi_handle tmp; |
| 89 | |
| 90 | status = acpi_get_handle(handle, "_ADR", &tmp); |
| 91 | if (ACPI_FAILURE(status)) { |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | status = acpi_get_handle(handle, "_EJ0", &tmp); |
| 96 | if (ACPI_FAILURE(status)) { |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | return 1; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /* callback routine to check the existence of ejectable slots */ |
| 105 | static acpi_status |
| 106 | is_ejectable_slot(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 107 | { |
| 108 | int *count = (int *)context; |
| 109 | |
| 110 | if (is_ejectable(handle)) { |
| 111 | (*count)++; |
| 112 | /* only one ejectable slot is enough */ |
| 113 | return AE_CTRL_TERMINATE; |
| 114 | } else { |
| 115 | return AE_OK; |
| 116 | } |
| 117 | } |
| 118 | |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame^] | 119 | /* callback routine to check for the existance of a pci dock device */ |
| 120 | static acpi_status |
| 121 | is_pci_dock_device(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 122 | { |
| 123 | int *count = (int *)context; |
| 124 | |
| 125 | if (is_dock_device(handle)) { |
| 126 | (*count)++; |
| 127 | return AE_CTRL_TERMINATE; |
| 128 | } else { |
| 129 | return AE_OK; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | /* |
| 137 | * the _DCK method can do funny things... and sometimes not |
| 138 | * hah-hah funny. |
| 139 | * |
| 140 | * TBD - figure out a way to only call fixups for |
| 141 | * systems that require them. |
| 142 | */ |
| 143 | static int post_dock_fixups(struct notifier_block *nb, unsigned long val, |
| 144 | void *v) |
| 145 | { |
| 146 | struct acpiphp_func *func = container_of(nb, struct acpiphp_func, nb); |
| 147 | struct pci_bus *bus = func->slot->bridge->pci_bus; |
| 148 | u32 buses; |
| 149 | |
| 150 | if (!bus->self) |
| 151 | return NOTIFY_OK; |
| 152 | |
| 153 | /* fixup bad _DCK function that rewrites |
| 154 | * secondary bridge on slot |
| 155 | */ |
| 156 | pci_read_config_dword(bus->self, |
| 157 | PCI_PRIMARY_BUS, |
| 158 | &buses); |
| 159 | |
| 160 | if (((buses >> 8) & 0xff) != bus->secondary) { |
| 161 | buses = (buses & 0xff000000) |
| 162 | | ((unsigned int)(bus->primary) << 0) |
| 163 | | ((unsigned int)(bus->secondary) << 8) |
| 164 | | ((unsigned int)(bus->subordinate) << 16); |
| 165 | pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses); |
| 166 | } |
| 167 | return NOTIFY_OK; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | /* callback routine to register each ACPI PCI slot object */ |
| 174 | static acpi_status |
| 175 | register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 176 | { |
| 177 | struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context; |
| 178 | struct acpiphp_slot *slot; |
| 179 | struct acpiphp_func *newfunc; |
| 180 | acpi_handle tmp; |
| 181 | acpi_status status = AE_OK; |
| 182 | unsigned long adr, sun; |
MUNEDA Takahiro | e27da38 | 2006-02-23 17:56:08 -0800 | [diff] [blame] | 183 | int device, function, retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); |
| 186 | |
| 187 | if (ACPI_FAILURE(status)) |
| 188 | return AE_OK; |
| 189 | |
| 190 | status = acpi_get_handle(handle, "_EJ0", &tmp); |
| 191 | |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame^] | 192 | if (ACPI_FAILURE(status) && !(is_dock_device(handle))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | return AE_OK; |
| 194 | |
| 195 | device = (adr >> 16) & 0xffff; |
| 196 | function = adr & 0xffff; |
| 197 | |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 198 | newfunc = kzalloc(sizeof(struct acpiphp_func), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (!newfunc) |
| 200 | return AE_NO_MEMORY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | INIT_LIST_HEAD(&newfunc->sibling); |
| 203 | newfunc->handle = handle; |
| 204 | newfunc->function = function; |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 205 | if (ACPI_SUCCESS(status)) |
| 206 | newfunc->flags = FUNC_HAS_EJ0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | if (ACPI_SUCCESS(acpi_get_handle(handle, "_STA", &tmp))) |
| 209 | newfunc->flags |= FUNC_HAS_STA; |
| 210 | |
| 211 | if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS0", &tmp))) |
| 212 | newfunc->flags |= FUNC_HAS_PS0; |
| 213 | |
| 214 | if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp))) |
| 215 | newfunc->flags |= FUNC_HAS_PS3; |
| 216 | |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame^] | 217 | if (ACPI_SUCCESS(acpi_get_handle(handle, "_DCK", &tmp))) |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 218 | newfunc->flags |= FUNC_HAS_DCK; |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun); |
| 221 | if (ACPI_FAILURE(status)) |
| 222 | sun = -1; |
| 223 | |
| 224 | /* search for objects that share the same slot */ |
| 225 | for (slot = bridge->slots; slot; slot = slot->next) |
| 226 | if (slot->device == device) { |
| 227 | if (slot->sun != sun) |
| 228 | warn("sibling found, but _SUN doesn't match!\n"); |
| 229 | break; |
| 230 | } |
| 231 | |
| 232 | if (!slot) { |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 233 | slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | if (!slot) { |
| 235 | kfree(newfunc); |
| 236 | return AE_NO_MEMORY; |
| 237 | } |
| 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | slot->bridge = bridge; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | slot->device = device; |
| 241 | slot->sun = sun; |
| 242 | INIT_LIST_HEAD(&slot->funcs); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 243 | mutex_init(&slot->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
| 245 | slot->next = bridge->slots; |
| 246 | bridge->slots = slot; |
| 247 | |
| 248 | bridge->nr_slots++; |
| 249 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 250 | dbg("found ACPI PCI Hotplug slot %d at PCI %04x:%02x:%02x\n", |
| 251 | slot->sun, pci_domain_nr(bridge->pci_bus), |
| 252 | bridge->pci_bus->number, slot->device); |
MUNEDA Takahiro | e27da38 | 2006-02-23 17:56:08 -0800 | [diff] [blame] | 253 | retval = acpiphp_register_hotplug_slot(slot); |
| 254 | if (retval) { |
| 255 | warn("acpiphp_register_hotplug_slot failed(err code = 0x%x)\n", retval); |
| 256 | goto err_exit; |
| 257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | newfunc->slot = slot; |
| 261 | list_add_tail(&newfunc->sibling, &slot->funcs); |
| 262 | |
| 263 | /* associate corresponding pci_dev */ |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 264 | newfunc->pci_dev = pci_get_slot(bridge->pci_bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | PCI_DEVFN(device, function)); |
| 266 | if (newfunc->pci_dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); |
| 268 | } |
| 269 | |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame^] | 270 | if (is_dock_device(handle)) { |
| 271 | /* we don't want to call this device's _EJ0 |
| 272 | * because we want the dock notify handler |
| 273 | * to call it after it calls _DCK |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 274 | */ |
| 275 | newfunc->flags &= ~FUNC_HAS_EJ0; |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame^] | 276 | if (register_hotplug_dock_device(handle, |
| 277 | handle_hotplug_event_func, newfunc)) |
| 278 | dbg("failed to register dock device\n"); |
| 279 | |
| 280 | /* we need to be notified when dock events happen |
| 281 | * outside of the hotplug operation, since we may |
| 282 | * need to do fixups before we can hotplug. |
| 283 | */ |
| 284 | newfunc->nb.notifier_call = post_dock_fixups; |
| 285 | if (register_dock_notifier(&newfunc->nb)) |
| 286 | dbg("failed to register a dock notifier"); |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 287 | } |
| 288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | /* install notify handler */ |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 290 | if (!(newfunc->flags & FUNC_HAS_DCK)) { |
| 291 | status = acpi_install_notify_handler(handle, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | ACPI_SYSTEM_NOTIFY, |
| 293 | handle_hotplug_event_func, |
| 294 | newfunc); |
| 295 | |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 296 | if (ACPI_FAILURE(status)) |
| 297 | err("failed to register interrupt notify handler\n"); |
| 298 | } else |
| 299 | status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 301 | return status; |
MUNEDA Takahiro | e27da38 | 2006-02-23 17:56:08 -0800 | [diff] [blame] | 302 | |
| 303 | err_exit: |
| 304 | bridge->nr_slots--; |
| 305 | bridge->slots = slot->next; |
| 306 | kfree(slot); |
| 307 | kfree(newfunc); |
| 308 | |
| 309 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | |
| 313 | /* see if it's worth looking at this bridge */ |
| 314 | static int detect_ejectable_slots(acpi_handle *bridge_handle) |
| 315 | { |
| 316 | acpi_status status; |
| 317 | int count; |
| 318 | |
| 319 | count = 0; |
| 320 | |
| 321 | /* only check slots defined directly below bridge object */ |
| 322 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, (u32)1, |
| 323 | is_ejectable_slot, (void *)&count, NULL); |
| 324 | |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame^] | 325 | /* |
| 326 | * we also need to add this bridge if there is a dock bridge or |
| 327 | * other pci device on a dock station (removable) |
| 328 | */ |
| 329 | if (!count) |
| 330 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, |
| 331 | (u32)1, is_pci_dock_device, (void *)&count, |
| 332 | NULL); |
| 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | return count; |
| 335 | } |
| 336 | |
| 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | /* decode ACPI 2.0 _HPP hot plug parameters */ |
| 339 | static void decode_hpp(struct acpiphp_bridge *bridge) |
| 340 | { |
| 341 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Kenji Kaneshige | 7430e34 | 2006-05-02 10:54:50 +0900 | [diff] [blame] | 343 | status = acpi_get_hp_params_from_firmware(bridge->pci_bus, &bridge->hpp); |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 344 | if (ACPI_FAILURE(status) || |
| 345 | !bridge->hpp.t0 || (bridge->hpp.t0->revision > 1)) { |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 346 | /* use default numbers */ |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 347 | printk(KERN_WARNING |
| 348 | "%s: Could not get hotplug parameters. Use defaults\n", |
| 349 | __FUNCTION__); |
| 350 | bridge->hpp.t0 = &bridge->hpp.type0_data; |
| 351 | bridge->hpp.t0->revision = 0; |
| 352 | bridge->hpp.t0->cache_line_size = 0x10; |
| 353 | bridge->hpp.t0->latency_timer = 0x40; |
| 354 | bridge->hpp.t0->enable_serr = 0; |
| 355 | bridge->hpp.t0->enable_perr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | /* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */ |
| 362 | static void init_bridge_misc(struct acpiphp_bridge *bridge) |
| 363 | { |
| 364 | acpi_status status; |
| 365 | |
| 366 | /* decode ACPI 2.0 _HPP (hot plug parameters) */ |
| 367 | decode_hpp(bridge); |
| 368 | |
MUNEDA Takahiro | e27da38 | 2006-02-23 17:56:08 -0800 | [diff] [blame] | 369 | /* must be added to the list prior to calling register_slot */ |
| 370 | list_add(&bridge->list, &bridge_list); |
| 371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | /* register all slot objects under this bridge */ |
| 373 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1, |
| 374 | register_slot, bridge, NULL); |
MUNEDA Takahiro | e27da38 | 2006-02-23 17:56:08 -0800 | [diff] [blame] | 375 | if (ACPI_FAILURE(status)) { |
| 376 | list_del(&bridge->list); |
| 377 | return; |
| 378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
| 380 | /* install notify handler */ |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 381 | if (bridge->type != BRIDGE_TYPE_HOST) { |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 382 | if ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func) { |
| 383 | status = acpi_remove_notify_handler(bridge->func->handle, |
| 384 | ACPI_SYSTEM_NOTIFY, |
| 385 | handle_hotplug_event_func); |
| 386 | if (ACPI_FAILURE(status)) |
| 387 | err("failed to remove notify handler\n"); |
| 388 | } |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 389 | status = acpi_install_notify_handler(bridge->handle, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | ACPI_SYSTEM_NOTIFY, |
| 391 | handle_hotplug_event_bridge, |
| 392 | bridge); |
| 393 | |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 394 | if (ACPI_FAILURE(status)) { |
| 395 | err("failed to register interrupt notify handler\n"); |
| 396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 401 | /* find acpiphp_func from acpiphp_bridge */ |
| 402 | static struct acpiphp_func *acpiphp_bridge_handle_to_function(acpi_handle handle) |
| 403 | { |
| 404 | struct list_head *node, *l; |
| 405 | struct acpiphp_bridge *bridge; |
| 406 | struct acpiphp_slot *slot; |
| 407 | struct acpiphp_func *func; |
| 408 | |
| 409 | list_for_each(node, &bridge_list) { |
| 410 | bridge = list_entry(node, struct acpiphp_bridge, list); |
| 411 | for (slot = bridge->slots; slot; slot = slot->next) { |
| 412 | list_for_each(l, &slot->funcs) { |
| 413 | func = list_entry(l, struct acpiphp_func, |
| 414 | sibling); |
| 415 | if (func->handle == handle) |
| 416 | return func; |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | return NULL; |
| 422 | } |
| 423 | |
| 424 | |
| 425 | static inline void config_p2p_bridge_flags(struct acpiphp_bridge *bridge) |
| 426 | { |
| 427 | acpi_handle dummy_handle; |
| 428 | |
| 429 | if (ACPI_SUCCESS(acpi_get_handle(bridge->handle, |
| 430 | "_STA", &dummy_handle))) |
| 431 | bridge->flags |= BRIDGE_HAS_STA; |
| 432 | |
| 433 | if (ACPI_SUCCESS(acpi_get_handle(bridge->handle, |
| 434 | "_EJ0", &dummy_handle))) |
| 435 | bridge->flags |= BRIDGE_HAS_EJ0; |
| 436 | |
| 437 | if (ACPI_SUCCESS(acpi_get_handle(bridge->handle, |
| 438 | "_PS0", &dummy_handle))) |
| 439 | bridge->flags |= BRIDGE_HAS_PS0; |
| 440 | |
| 441 | if (ACPI_SUCCESS(acpi_get_handle(bridge->handle, |
| 442 | "_PS3", &dummy_handle))) |
| 443 | bridge->flags |= BRIDGE_HAS_PS3; |
| 444 | |
| 445 | /* is this ejectable p2p bridge? */ |
| 446 | if (bridge->flags & BRIDGE_HAS_EJ0) { |
| 447 | struct acpiphp_func *func; |
| 448 | |
| 449 | dbg("found ejectable p2p bridge\n"); |
| 450 | |
| 451 | /* make link between PCI bridge and PCI function */ |
| 452 | func = acpiphp_bridge_handle_to_function(bridge->handle); |
| 453 | if (!func) |
| 454 | return; |
| 455 | bridge->func = func; |
| 456 | func->bridge = bridge; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | /* allocate and initialize host bridge data structure */ |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 462 | static void add_host_bridge(acpi_handle *handle, struct pci_bus *pci_bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | struct acpiphp_bridge *bridge; |
| 465 | |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 466 | bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | if (bridge == NULL) |
| 468 | return; |
| 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | bridge->type = BRIDGE_TYPE_HOST; |
| 471 | bridge->handle = handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 473 | bridge->pci_bus = pci_bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | spin_lock_init(&bridge->res_lock); |
| 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | init_bridge_misc(bridge); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | /* allocate and initialize PCI-to-PCI bridge data structure */ |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 482 | static void add_p2p_bridge(acpi_handle *handle, struct pci_dev *pci_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
| 484 | struct acpiphp_bridge *bridge; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 486 | bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | if (bridge == NULL) { |
| 488 | err("out of memory\n"); |
| 489 | return; |
| 490 | } |
| 491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | bridge->type = BRIDGE_TYPE_P2P; |
| 493 | bridge->handle = handle; |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 494 | config_p2p_bridge_flags(bridge); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 496 | bridge->pci_dev = pci_dev_get(pci_dev); |
| 497 | bridge->pci_bus = pci_dev->subordinate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | if (!bridge->pci_bus) { |
| 499 | err("This is not a PCI-to-PCI bridge!\n"); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 500 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | spin_lock_init(&bridge->res_lock); |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | init_bridge_misc(bridge); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 506 | return; |
| 507 | err: |
| 508 | pci_dev_put(pci_dev); |
| 509 | kfree(bridge); |
| 510 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | |
| 514 | /* callback routine to find P2P bridges */ |
| 515 | static acpi_status |
| 516 | find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 517 | { |
| 518 | acpi_status status; |
| 519 | acpi_handle dummy_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | unsigned long tmp; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 521 | int device, function; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | struct pci_dev *dev; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 523 | struct pci_bus *pci_bus = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | status = acpi_get_handle(handle, "_ADR", &dummy_handle); |
| 526 | if (ACPI_FAILURE(status)) |
| 527 | return AE_OK; /* continue */ |
| 528 | |
| 529 | status = acpi_evaluate_integer(handle, "_ADR", NULL, &tmp); |
| 530 | if (ACPI_FAILURE(status)) { |
| 531 | dbg("%s: _ADR evaluation failure\n", __FUNCTION__); |
| 532 | return AE_OK; |
| 533 | } |
| 534 | |
| 535 | device = (tmp >> 16) & 0xffff; |
| 536 | function = tmp & 0xffff; |
| 537 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 538 | dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 540 | if (!dev || !dev->subordinate) |
| 541 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | /* check if this bridge has ejectable slots */ |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame^] | 544 | if ((detect_ejectable_slots(handle) > 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev)); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 546 | add_p2p_bridge(handle, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Kenji Kaneshige | 7c8f25d | 2006-02-27 22:15:49 +0900 | [diff] [blame] | 549 | /* search P2P bridges under this p2p bridge */ |
| 550 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, |
| 551 | find_p2p_bridge, dev->subordinate, NULL); |
| 552 | if (ACPI_FAILURE(status)) |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 553 | warn("find_p2p_bridge failed (error code = 0x%x)\n", status); |
Kenji Kaneshige | 7c8f25d | 2006-02-27 22:15:49 +0900 | [diff] [blame] | 554 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 555 | out: |
| 556 | pci_dev_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | return AE_OK; |
| 558 | } |
| 559 | |
| 560 | |
| 561 | /* find hot-pluggable slots, and then find P2P bridge */ |
| 562 | static int add_bridge(acpi_handle handle) |
| 563 | { |
| 564 | acpi_status status; |
| 565 | unsigned long tmp; |
| 566 | int seg, bus; |
| 567 | acpi_handle dummy_handle; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 568 | struct pci_bus *pci_bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
| 570 | /* if the bridge doesn't have _STA, we assume it is always there */ |
| 571 | status = acpi_get_handle(handle, "_STA", &dummy_handle); |
| 572 | if (ACPI_SUCCESS(status)) { |
| 573 | status = acpi_evaluate_integer(handle, "_STA", NULL, &tmp); |
| 574 | if (ACPI_FAILURE(status)) { |
| 575 | dbg("%s: _STA evaluation failure\n", __FUNCTION__); |
| 576 | return 0; |
| 577 | } |
| 578 | if ((tmp & ACPI_STA_FUNCTIONING) == 0) |
| 579 | /* don't register this object */ |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | /* get PCI segment number */ |
| 584 | status = acpi_evaluate_integer(handle, "_SEG", NULL, &tmp); |
| 585 | |
| 586 | seg = ACPI_SUCCESS(status) ? tmp : 0; |
| 587 | |
| 588 | /* get PCI bus number */ |
| 589 | status = acpi_evaluate_integer(handle, "_BBN", NULL, &tmp); |
| 590 | |
| 591 | if (ACPI_SUCCESS(status)) { |
| 592 | bus = tmp; |
| 593 | } else { |
| 594 | warn("can't get bus number, assuming 0\n"); |
| 595 | bus = 0; |
| 596 | } |
| 597 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 598 | pci_bus = pci_find_bus(seg, bus); |
| 599 | if (!pci_bus) { |
| 600 | err("Can't find bus %04x:%02x\n", seg, bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | return 0; |
| 602 | } |
| 603 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 604 | /* check if this bridge has ejectable slots */ |
| 605 | if (detect_ejectable_slots(handle) > 0) { |
| 606 | dbg("found PCI host-bus bridge with hot-pluggable slots\n"); |
| 607 | add_host_bridge(handle, pci_bus); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 608 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
| 610 | /* search P2P bridges under this host bridge */ |
| 611 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 612 | find_p2p_bridge, pci_bus, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | if (ACPI_FAILURE(status)) |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 615 | warn("find_p2p_bridge failed (error code = 0x%x)\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 620 | static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) |
| 621 | { |
| 622 | struct list_head *head; |
| 623 | list_for_each(head, &bridge_list) { |
| 624 | struct acpiphp_bridge *bridge = list_entry(head, |
| 625 | struct acpiphp_bridge, list); |
| 626 | if (bridge->handle == handle) |
| 627 | return bridge; |
| 628 | } |
| 629 | |
| 630 | return NULL; |
| 631 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Rajesh Shah | 364d509 | 2005-04-28 00:25:54 -0700 | [diff] [blame] | 633 | static void cleanup_bridge(struct acpiphp_bridge *bridge) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 635 | struct list_head *list, *tmp; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 636 | struct acpiphp_slot *slot; |
| 637 | acpi_status status; |
Rajesh Shah | 364d509 | 2005-04-28 00:25:54 -0700 | [diff] [blame] | 638 | acpi_handle handle = bridge->handle; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 639 | |
| 640 | status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, |
| 641 | handle_hotplug_event_bridge); |
| 642 | if (ACPI_FAILURE(status)) |
| 643 | err("failed to remove notify handler\n"); |
| 644 | |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 645 | if ((bridge->type != BRIDGE_TYPE_HOST) && |
| 646 | ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func)) { |
| 647 | status = acpi_install_notify_handler(bridge->func->handle, |
| 648 | ACPI_SYSTEM_NOTIFY, |
| 649 | handle_hotplug_event_func, |
| 650 | bridge->func); |
| 651 | if (ACPI_FAILURE(status)) |
| 652 | err("failed to install interrupt notify handler\n"); |
| 653 | } |
| 654 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 655 | slot = bridge->slots; |
| 656 | while (slot) { |
| 657 | struct acpiphp_slot *next = slot->next; |
| 658 | list_for_each_safe (list, tmp, &slot->funcs) { |
| 659 | struct acpiphp_func *func; |
| 660 | func = list_entry(list, struct acpiphp_func, sibling); |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame^] | 661 | if (is_dock_device(func->handle)) { |
| 662 | unregister_hotplug_dock_device(func->handle); |
| 663 | unregister_dock_notifier(&func->nb); |
| 664 | } |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 665 | if (!(func->flags & FUNC_HAS_DCK)) { |
| 666 | status = acpi_remove_notify_handler(func->handle, |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 667 | ACPI_SYSTEM_NOTIFY, |
| 668 | handle_hotplug_event_func); |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 669 | if (ACPI_FAILURE(status)) |
| 670 | err("failed to remove notify handler\n"); |
| 671 | } |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 672 | pci_dev_put(func->pci_dev); |
| 673 | list_del(list); |
| 674 | kfree(func); |
| 675 | } |
MUNEDA Takahiro | e27da38 | 2006-02-23 17:56:08 -0800 | [diff] [blame] | 676 | acpiphp_unregister_hotplug_slot(slot); |
| 677 | list_del(&slot->funcs); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 678 | kfree(slot); |
| 679 | slot = next; |
| 680 | } |
| 681 | |
| 682 | pci_dev_put(bridge->pci_dev); |
| 683 | list_del(&bridge->list); |
| 684 | kfree(bridge); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Rajesh Shah | 364d509 | 2005-04-28 00:25:54 -0700 | [diff] [blame] | 687 | static acpi_status |
| 688 | cleanup_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 689 | { |
| 690 | struct acpiphp_bridge *bridge; |
| 691 | |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 692 | /* cleanup p2p bridges under this P2P bridge |
| 693 | in a depth-first manner */ |
| 694 | acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, |
| 695 | cleanup_p2p_bridge, NULL, NULL); |
| 696 | |
Rajesh Shah | 364d509 | 2005-04-28 00:25:54 -0700 | [diff] [blame] | 697 | if (!(bridge = acpiphp_handle_to_bridge(handle))) |
| 698 | return AE_OK; |
| 699 | cleanup_bridge(bridge); |
| 700 | return AE_OK; |
| 701 | } |
| 702 | |
| 703 | static void remove_bridge(acpi_handle handle) |
| 704 | { |
| 705 | struct acpiphp_bridge *bridge; |
| 706 | |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 707 | /* cleanup p2p bridges under this host bridge |
| 708 | in a depth-first manner */ |
| 709 | acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, |
| 710 | (u32)1, cleanup_p2p_bridge, NULL, NULL); |
| 711 | |
Rajesh Shah | 364d509 | 2005-04-28 00:25:54 -0700 | [diff] [blame] | 712 | bridge = acpiphp_handle_to_bridge(handle); |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 713 | if (bridge) |
Rajesh Shah | 364d509 | 2005-04-28 00:25:54 -0700 | [diff] [blame] | 714 | cleanup_bridge(bridge); |
Rajesh Shah | 364d509 | 2005-04-28 00:25:54 -0700 | [diff] [blame] | 715 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Kenji Kaneshige | a0d399a | 2005-04-28 00:25:59 -0700 | [diff] [blame] | 717 | static struct pci_dev * get_apic_pci_info(acpi_handle handle) |
| 718 | { |
| 719 | struct acpi_pci_id id; |
| 720 | struct pci_bus *bus; |
| 721 | struct pci_dev *dev; |
| 722 | |
| 723 | if (ACPI_FAILURE(acpi_get_pci_id(handle, &id))) |
| 724 | return NULL; |
| 725 | |
| 726 | bus = pci_find_bus(id.segment, id.bus); |
| 727 | if (!bus) |
| 728 | return NULL; |
| 729 | |
| 730 | dev = pci_get_slot(bus, PCI_DEVFN(id.device, id.function)); |
| 731 | if (!dev) |
| 732 | return NULL; |
| 733 | |
| 734 | if ((dev->class != PCI_CLASS_SYSTEM_PIC_IOAPIC) && |
| 735 | (dev->class != PCI_CLASS_SYSTEM_PIC_IOXAPIC)) |
| 736 | { |
| 737 | pci_dev_put(dev); |
| 738 | return NULL; |
| 739 | } |
| 740 | |
| 741 | return dev; |
| 742 | } |
| 743 | |
| 744 | static int get_gsi_base(acpi_handle handle, u32 *gsi_base) |
| 745 | { |
| 746 | acpi_status status; |
| 747 | int result = -1; |
| 748 | unsigned long gsb; |
| 749 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 750 | union acpi_object *obj; |
| 751 | void *table; |
| 752 | |
| 753 | status = acpi_evaluate_integer(handle, "_GSB", NULL, &gsb); |
| 754 | if (ACPI_SUCCESS(status)) { |
| 755 | *gsi_base = (u32)gsb; |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | status = acpi_evaluate_object(handle, "_MAT", NULL, &buffer); |
| 760 | if (ACPI_FAILURE(status) || !buffer.length || !buffer.pointer) |
| 761 | return -1; |
| 762 | |
| 763 | obj = buffer.pointer; |
| 764 | if (obj->type != ACPI_TYPE_BUFFER) |
| 765 | goto out; |
| 766 | |
| 767 | table = obj->buffer.pointer; |
| 768 | switch (((acpi_table_entry_header *)table)->type) { |
| 769 | case ACPI_MADT_IOSAPIC: |
| 770 | *gsi_base = ((struct acpi_table_iosapic *)table)->global_irq_base; |
| 771 | result = 0; |
| 772 | break; |
| 773 | case ACPI_MADT_IOAPIC: |
| 774 | *gsi_base = ((struct acpi_table_ioapic *)table)->global_irq_base; |
| 775 | result = 0; |
| 776 | break; |
| 777 | default: |
| 778 | break; |
| 779 | } |
| 780 | out: |
Kristen Accardi | 81b26bc | 2006-04-18 14:36:43 -0700 | [diff] [blame] | 781 | kfree(buffer.pointer); |
Kenji Kaneshige | a0d399a | 2005-04-28 00:25:59 -0700 | [diff] [blame] | 782 | return result; |
| 783 | } |
| 784 | |
| 785 | static acpi_status |
| 786 | ioapic_add(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 787 | { |
| 788 | acpi_status status; |
| 789 | unsigned long sta; |
| 790 | acpi_handle tmp; |
| 791 | struct pci_dev *pdev; |
| 792 | u32 gsi_base; |
| 793 | u64 phys_addr; |
| 794 | |
| 795 | /* Evaluate _STA if present */ |
| 796 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); |
| 797 | if (ACPI_SUCCESS(status) && sta != ACPI_STA_ALL) |
| 798 | return AE_CTRL_DEPTH; |
| 799 | |
| 800 | /* Scan only PCI bus scope */ |
| 801 | status = acpi_get_handle(handle, "_HID", &tmp); |
| 802 | if (ACPI_SUCCESS(status)) |
| 803 | return AE_CTRL_DEPTH; |
| 804 | |
| 805 | if (get_gsi_base(handle, &gsi_base)) |
| 806 | return AE_OK; |
| 807 | |
| 808 | pdev = get_apic_pci_info(handle); |
| 809 | if (!pdev) |
| 810 | return AE_OK; |
| 811 | |
| 812 | if (pci_enable_device(pdev)) { |
| 813 | pci_dev_put(pdev); |
| 814 | return AE_OK; |
| 815 | } |
| 816 | |
| 817 | pci_set_master(pdev); |
| 818 | |
| 819 | if (pci_request_region(pdev, 0, "I/O APIC(acpiphp)")) { |
| 820 | pci_disable_device(pdev); |
| 821 | pci_dev_put(pdev); |
| 822 | return AE_OK; |
| 823 | } |
| 824 | |
| 825 | phys_addr = pci_resource_start(pdev, 0); |
| 826 | if (acpi_register_ioapic(handle, phys_addr, gsi_base)) { |
| 827 | pci_release_region(pdev, 0); |
| 828 | pci_disable_device(pdev); |
| 829 | pci_dev_put(pdev); |
| 830 | return AE_OK; |
| 831 | } |
| 832 | |
| 833 | return AE_OK; |
| 834 | } |
| 835 | |
| 836 | static int acpiphp_configure_ioapics(acpi_handle handle) |
| 837 | { |
| 838 | acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, |
| 839 | ACPI_UINT32_MAX, ioapic_add, NULL, NULL); |
| 840 | return 0; |
| 841 | } |
| 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | static int power_on_slot(struct acpiphp_slot *slot) |
| 844 | { |
| 845 | acpi_status status; |
| 846 | struct acpiphp_func *func; |
| 847 | struct list_head *l; |
| 848 | int retval = 0; |
| 849 | |
| 850 | /* if already enabled, just skip */ |
| 851 | if (slot->flags & SLOT_POWEREDON) |
| 852 | goto err_exit; |
| 853 | |
| 854 | list_for_each (l, &slot->funcs) { |
| 855 | func = list_entry(l, struct acpiphp_func, sibling); |
| 856 | |
| 857 | if (func->flags & FUNC_HAS_PS0) { |
| 858 | dbg("%s: executing _PS0\n", __FUNCTION__); |
| 859 | status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL); |
| 860 | if (ACPI_FAILURE(status)) { |
| 861 | warn("%s: _PS0 failed\n", __FUNCTION__); |
| 862 | retval = -1; |
| 863 | goto err_exit; |
| 864 | } else |
| 865 | break; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | /* TBD: evaluate _STA to check if the slot is enabled */ |
| 870 | |
| 871 | slot->flags |= SLOT_POWEREDON; |
| 872 | |
| 873 | err_exit: |
| 874 | return retval; |
| 875 | } |
| 876 | |
| 877 | |
| 878 | static int power_off_slot(struct acpiphp_slot *slot) |
| 879 | { |
| 880 | acpi_status status; |
| 881 | struct acpiphp_func *func; |
| 882 | struct list_head *l; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
| 884 | int retval = 0; |
| 885 | |
| 886 | /* if already disabled, just skip */ |
| 887 | if ((slot->flags & SLOT_POWEREDON) == 0) |
| 888 | goto err_exit; |
| 889 | |
| 890 | list_for_each (l, &slot->funcs) { |
| 891 | func = list_entry(l, struct acpiphp_func, sibling); |
| 892 | |
Rajesh Shah | 2f523b1 | 2005-04-28 00:25:55 -0700 | [diff] [blame] | 893 | if (func->flags & FUNC_HAS_PS3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL); |
| 895 | if (ACPI_FAILURE(status)) { |
| 896 | warn("%s: _PS3 failed\n", __FUNCTION__); |
| 897 | retval = -1; |
| 898 | goto err_exit; |
| 899 | } else |
| 900 | break; |
| 901 | } |
| 902 | } |
| 903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | /* TBD: evaluate _STA to check if the slot is disabled */ |
| 905 | |
| 906 | slot->flags &= (~SLOT_POWEREDON); |
| 907 | |
| 908 | err_exit: |
| 909 | return retval; |
| 910 | } |
| 911 | |
| 912 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 913 | |
| 914 | /** |
| 915 | * acpiphp_max_busnr - return the highest reserved bus number under |
| 916 | * the given bus. |
| 917 | * @bus: bus to start search with |
| 918 | * |
| 919 | */ |
| 920 | static unsigned char acpiphp_max_busnr(struct pci_bus *bus) |
| 921 | { |
| 922 | struct list_head *tmp; |
| 923 | unsigned char max, n; |
| 924 | |
| 925 | /* |
| 926 | * pci_bus_max_busnr will return the highest |
| 927 | * reserved busnr for all these children. |
| 928 | * that is equivalent to the bus->subordinate |
| 929 | * value. We don't want to use the parent's |
| 930 | * bus->subordinate value because it could have |
| 931 | * padding in it. |
| 932 | */ |
| 933 | max = bus->secondary; |
| 934 | |
| 935 | list_for_each(tmp, &bus->children) { |
| 936 | n = pci_bus_max_busnr(pci_bus_b(tmp)); |
| 937 | if (n > max) |
| 938 | max = n; |
| 939 | } |
| 940 | return max; |
| 941 | } |
| 942 | |
| 943 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 944 | /** |
| 945 | * acpiphp_bus_add - add a new bus to acpi subsystem |
| 946 | * @func: acpiphp_func of the bridge |
| 947 | * |
| 948 | */ |
| 949 | static int acpiphp_bus_add(struct acpiphp_func *func) |
| 950 | { |
| 951 | acpi_handle phandle; |
| 952 | struct acpi_device *device, *pdevice; |
| 953 | int ret_val; |
| 954 | |
| 955 | acpi_get_parent(func->handle, &phandle); |
| 956 | if (acpi_bus_get_device(phandle, &pdevice)) { |
| 957 | dbg("no parent device, assuming NULL\n"); |
| 958 | pdevice = NULL; |
| 959 | } |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 960 | if (!acpi_bus_get_device(func->handle, &device)) { |
| 961 | dbg("bus exists... trim\n"); |
| 962 | /* this shouldn't be in here, so remove |
| 963 | * the bus then re-add it... |
| 964 | */ |
| 965 | ret_val = acpi_bus_trim(device, 1); |
| 966 | dbg("acpi_bus_trim return %x\n", ret_val); |
| 967 | } |
| 968 | |
| 969 | ret_val = acpi_bus_add(&device, pdevice, func->handle, |
| 970 | ACPI_BUS_TYPE_DEVICE); |
| 971 | if (ret_val) { |
| 972 | dbg("error adding bus, %x\n", |
| 973 | -ret_val); |
| 974 | goto acpiphp_bus_add_out; |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 975 | } |
| 976 | /* |
| 977 | * try to start anyway. We could have failed to add |
| 978 | * simply because this bus had previously been added |
| 979 | * on another add. Don't bother with the return value |
| 980 | * we just keep going. |
| 981 | */ |
| 982 | ret_val = acpi_bus_start(device); |
| 983 | |
| 984 | acpiphp_bus_add_out: |
| 985 | return ret_val; |
| 986 | } |
| 987 | |
| 988 | |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 989 | /** |
| 990 | * acpiphp_bus_trim - trim a bus from acpi subsystem |
| 991 | * @handle: handle to acpi namespace |
| 992 | * |
| 993 | */ |
| 994 | int acpiphp_bus_trim(acpi_handle handle) |
| 995 | { |
| 996 | struct acpi_device *device; |
| 997 | int retval; |
| 998 | |
| 999 | retval = acpi_bus_get_device(handle, &device); |
| 1000 | if (retval) { |
| 1001 | dbg("acpi_device not found\n"); |
| 1002 | return retval; |
| 1003 | } |
| 1004 | |
| 1005 | retval = acpi_bus_trim(device, 1); |
| 1006 | if (retval) |
| 1007 | err("cannot remove from acpi list\n"); |
| 1008 | |
| 1009 | return retval; |
| 1010 | } |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 1011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | /** |
| 1013 | * enable_device - enable, configure a slot |
| 1014 | * @slot: slot to be enabled |
| 1015 | * |
| 1016 | * This function should be called per *physical slot*, |
| 1017 | * not per each slot object in ACPI namespace. |
| 1018 | * |
| 1019 | */ |
| 1020 | static int enable_device(struct acpiphp_slot *slot) |
| 1021 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | struct pci_dev *dev; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1023 | struct pci_bus *bus = slot->bridge->pci_bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | struct list_head *l; |
| 1025 | struct acpiphp_func *func; |
| 1026 | int retval = 0; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1027 | int num, max, pass; |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 1028 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | |
| 1030 | if (slot->flags & SLOT_ENABLED) |
| 1031 | goto err_exit; |
| 1032 | |
| 1033 | /* sanity check: dev should be NULL when hot-plugged in */ |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1034 | dev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | if (dev) { |
| 1036 | /* This case shouldn't happen */ |
| 1037 | err("pci_dev structure already exists.\n"); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1038 | pci_dev_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | retval = -1; |
| 1040 | goto err_exit; |
| 1041 | } |
| 1042 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1043 | num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0)); |
| 1044 | if (num == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | err("No new device found\n"); |
| 1046 | retval = -1; |
| 1047 | goto err_exit; |
| 1048 | } |
| 1049 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 1050 | max = acpiphp_max_busnr(bus); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1051 | for (pass = 0; pass < 2; pass++) { |
| 1052 | list_for_each_entry(dev, &bus->devices, bus_list) { |
| 1053 | if (PCI_SLOT(dev->devfn) != slot->device) |
| 1054 | continue; |
| 1055 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || |
Kristen Accardi | c64b5ee | 2005-12-14 09:37:26 -0800 | [diff] [blame] | 1056 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1057 | max = pci_scan_bridge(bus, dev, max, pass); |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 1058 | if (pass && dev->subordinate) |
Kristen Accardi | c64b5ee | 2005-12-14 09:37:26 -0800 | [diff] [blame] | 1059 | pci_bus_size_bridges(dev->subordinate); |
| 1060 | } |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1061 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 1064 | list_for_each (l, &slot->funcs) { |
| 1065 | func = list_entry(l, struct acpiphp_func, sibling); |
| 1066 | acpiphp_bus_add(func); |
| 1067 | } |
| 1068 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1069 | pci_bus_assign_resources(bus); |
Kristen Accardi | 8e5dce3 | 2005-10-18 17:21:40 -0700 | [diff] [blame] | 1070 | acpiphp_sanitize_bus(bus); |
| 1071 | pci_enable_bridges(bus); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1072 | pci_bus_add_devices(bus); |
MUNEDA Takahiro | 0cccd0c | 2006-02-24 17:46:04 +0900 | [diff] [blame] | 1073 | acpiphp_set_hpp_values(slot->bridge->handle, bus); |
| 1074 | acpiphp_configure_ioapics(slot->bridge->handle); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | /* associate pci_dev to our representation */ |
| 1077 | list_for_each (l, &slot->funcs) { |
| 1078 | func = list_entry(l, struct acpiphp_func, sibling); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1079 | func->pci_dev = pci_get_slot(bus, PCI_DEVFN(slot->device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | func->function)); |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 1081 | if (!func->pci_dev) |
| 1082 | continue; |
| 1083 | |
| 1084 | if (func->pci_dev->hdr_type != PCI_HEADER_TYPE_BRIDGE && |
| 1085 | func->pci_dev->hdr_type != PCI_HEADER_TYPE_CARDBUS) |
| 1086 | continue; |
| 1087 | |
| 1088 | status = find_p2p_bridge(func->handle, (u32)1, bus, NULL); |
| 1089 | if (ACPI_FAILURE(status)) |
| 1090 | warn("find_p2p_bridge failed (error code = 0x%x)\n", |
| 1091 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | slot->flags |= SLOT_ENABLED; |
| 1095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | err_exit: |
| 1097 | return retval; |
| 1098 | } |
| 1099 | |
| 1100 | |
| 1101 | /** |
| 1102 | * disable_device - disable a slot |
| 1103 | */ |
| 1104 | static int disable_device(struct acpiphp_slot *slot) |
| 1105 | { |
| 1106 | int retval = 0; |
| 1107 | struct acpiphp_func *func; |
| 1108 | struct list_head *l; |
| 1109 | |
| 1110 | /* is this slot already disabled? */ |
| 1111 | if (!(slot->flags & SLOT_ENABLED)) |
| 1112 | goto err_exit; |
| 1113 | |
| 1114 | list_for_each (l, &slot->funcs) { |
| 1115 | func = list_entry(l, struct acpiphp_func, sibling); |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 1116 | |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 1117 | if (func->bridge) { |
| 1118 | /* cleanup p2p bridges under this P2P bridge */ |
| 1119 | cleanup_p2p_bridge(func->bridge->handle, |
| 1120 | (u32)1, NULL, NULL); |
| 1121 | func->bridge = NULL; |
| 1122 | } |
| 1123 | |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 1124 | acpiphp_bus_trim(func->handle); |
| 1125 | /* try to remove anyway. |
| 1126 | * acpiphp_bus_add might have been failed */ |
| 1127 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1128 | if (!func->pci_dev) |
| 1129 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1131 | pci_remove_bus_device(func->pci_dev); |
| 1132 | pci_dev_put(func->pci_dev); |
| 1133 | func->pci_dev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | slot->flags &= (~SLOT_ENABLED); |
| 1137 | |
| 1138 | err_exit: |
| 1139 | return retval; |
| 1140 | } |
| 1141 | |
| 1142 | |
| 1143 | /** |
| 1144 | * get_slot_status - get ACPI slot status |
| 1145 | * |
| 1146 | * if a slot has _STA for each function and if any one of them |
| 1147 | * returned non-zero status, return it |
| 1148 | * |
| 1149 | * if a slot doesn't have _STA and if any one of its functions' |
| 1150 | * configuration space is configured, return 0x0f as a _STA |
| 1151 | * |
| 1152 | * otherwise return 0 |
| 1153 | */ |
| 1154 | static unsigned int get_slot_status(struct acpiphp_slot *slot) |
| 1155 | { |
| 1156 | acpi_status status; |
| 1157 | unsigned long sta = 0; |
| 1158 | u32 dvid; |
| 1159 | struct list_head *l; |
| 1160 | struct acpiphp_func *func; |
| 1161 | |
| 1162 | list_for_each (l, &slot->funcs) { |
| 1163 | func = list_entry(l, struct acpiphp_func, sibling); |
| 1164 | |
| 1165 | if (func->flags & FUNC_HAS_STA) { |
| 1166 | status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta); |
| 1167 | if (ACPI_SUCCESS(status) && sta) |
| 1168 | break; |
| 1169 | } else { |
| 1170 | pci_bus_read_config_dword(slot->bridge->pci_bus, |
| 1171 | PCI_DEVFN(slot->device, |
| 1172 | func->function), |
| 1173 | PCI_VENDOR_ID, &dvid); |
| 1174 | if (dvid != 0xffffffff) { |
| 1175 | sta = ACPI_STA_ALL; |
| 1176 | break; |
| 1177 | } |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | return (unsigned int)sta; |
| 1182 | } |
| 1183 | |
| 1184 | /** |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 1185 | * acpiphp_eject_slot - physically eject the slot |
| 1186 | */ |
| 1187 | static int acpiphp_eject_slot(struct acpiphp_slot *slot) |
| 1188 | { |
| 1189 | acpi_status status; |
| 1190 | struct acpiphp_func *func; |
| 1191 | struct list_head *l; |
| 1192 | struct acpi_object_list arg_list; |
| 1193 | union acpi_object arg; |
| 1194 | |
| 1195 | list_for_each (l, &slot->funcs) { |
| 1196 | func = list_entry(l, struct acpiphp_func, sibling); |
| 1197 | |
| 1198 | /* We don't want to call _EJ0 on non-existing functions. */ |
| 1199 | if ((func->flags & FUNC_HAS_EJ0)) { |
| 1200 | /* _EJ0 method take one argument */ |
| 1201 | arg_list.count = 1; |
| 1202 | arg_list.pointer = &arg; |
| 1203 | arg.type = ACPI_TYPE_INTEGER; |
| 1204 | arg.integer.value = 1; |
| 1205 | |
| 1206 | status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL); |
| 1207 | if (ACPI_FAILURE(status)) { |
| 1208 | warn("%s: _EJ0 failed\n", __FUNCTION__); |
| 1209 | return -1; |
| 1210 | } else |
| 1211 | break; |
| 1212 | } |
| 1213 | } |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | * acpiphp_check_bridge - re-enumerate devices |
| 1219 | * |
| 1220 | * Iterate over all slots under this bridge and make sure that if a |
| 1221 | * card is present they are enabled, and if not they are disabled. |
| 1222 | */ |
| 1223 | static int acpiphp_check_bridge(struct acpiphp_bridge *bridge) |
| 1224 | { |
| 1225 | struct acpiphp_slot *slot; |
| 1226 | int retval = 0; |
| 1227 | int enabled, disabled; |
| 1228 | |
| 1229 | enabled = disabled = 0; |
| 1230 | |
| 1231 | for (slot = bridge->slots; slot; slot = slot->next) { |
| 1232 | unsigned int status = get_slot_status(slot); |
| 1233 | if (slot->flags & SLOT_ENABLED) { |
| 1234 | if (status == ACPI_STA_ALL) |
| 1235 | continue; |
| 1236 | retval = acpiphp_disable_slot(slot); |
| 1237 | if (retval) { |
| 1238 | err("Error occurred in disabling\n"); |
| 1239 | goto err_exit; |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 1240 | } else { |
| 1241 | acpiphp_eject_slot(slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | } |
| 1243 | disabled++; |
| 1244 | } else { |
| 1245 | if (status != ACPI_STA_ALL) |
| 1246 | continue; |
| 1247 | retval = acpiphp_enable_slot(slot); |
| 1248 | if (retval) { |
| 1249 | err("Error occurred in enabling\n"); |
| 1250 | goto err_exit; |
| 1251 | } |
| 1252 | enabled++; |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | dbg("%s: %d enabled, %d disabled\n", __FUNCTION__, enabled, disabled); |
| 1257 | |
| 1258 | err_exit: |
| 1259 | return retval; |
| 1260 | } |
| 1261 | |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1262 | static void program_hpp(struct pci_dev *dev, struct acpiphp_bridge *bridge) |
| 1263 | { |
| 1264 | u16 pci_cmd, pci_bctl; |
| 1265 | struct pci_dev *cdev; |
| 1266 | |
| 1267 | /* Program hpp values for this device */ |
| 1268 | if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL || |
| 1269 | (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE && |
| 1270 | (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI))) |
| 1271 | return; |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 1272 | |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1273 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 1274 | bridge->hpp.t0->cache_line_size); |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1275 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 1276 | bridge->hpp.t0->latency_timer); |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1277 | pci_read_config_word(dev, PCI_COMMAND, &pci_cmd); |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 1278 | if (bridge->hpp.t0->enable_serr) |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1279 | pci_cmd |= PCI_COMMAND_SERR; |
| 1280 | else |
| 1281 | pci_cmd &= ~PCI_COMMAND_SERR; |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 1282 | if (bridge->hpp.t0->enable_perr) |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1283 | pci_cmd |= PCI_COMMAND_PARITY; |
| 1284 | else |
| 1285 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 1286 | pci_write_config_word(dev, PCI_COMMAND, pci_cmd); |
| 1287 | |
| 1288 | /* Program bridge control value and child devices */ |
| 1289 | if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) { |
| 1290 | pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 1291 | bridge->hpp.t0->latency_timer); |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1292 | pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl); |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 1293 | if (bridge->hpp.t0->enable_serr) |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1294 | pci_bctl |= PCI_BRIDGE_CTL_SERR; |
| 1295 | else |
| 1296 | pci_bctl &= ~PCI_BRIDGE_CTL_SERR; |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 1297 | if (bridge->hpp.t0->enable_perr) |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1298 | pci_bctl |= PCI_BRIDGE_CTL_PARITY; |
| 1299 | else |
| 1300 | pci_bctl &= ~PCI_BRIDGE_CTL_PARITY; |
| 1301 | pci_write_config_word(dev, PCI_BRIDGE_CONTROL, pci_bctl); |
| 1302 | if (dev->subordinate) { |
| 1303 | list_for_each_entry(cdev, &dev->subordinate->devices, |
| 1304 | bus_list) |
| 1305 | program_hpp(cdev, bridge); |
| 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus) |
| 1311 | { |
| 1312 | struct acpiphp_bridge bridge; |
| 1313 | struct pci_dev *dev; |
| 1314 | |
| 1315 | memset(&bridge, 0, sizeof(bridge)); |
| 1316 | bridge.handle = handle; |
Kenji Kaneshige | 7430e34 | 2006-05-02 10:54:50 +0900 | [diff] [blame] | 1317 | bridge.pci_bus = bus; |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 1318 | bridge.pci_dev = bus->self; |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1319 | decode_hpp(&bridge); |
| 1320 | list_for_each_entry(dev, &bus->devices, bus_list) |
| 1321 | program_hpp(dev, &bridge); |
| 1322 | |
| 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | * Remove devices for which we could not assign resources, call |
| 1327 | * arch specific code to fix-up the bus |
| 1328 | */ |
| 1329 | static void acpiphp_sanitize_bus(struct pci_bus *bus) |
| 1330 | { |
| 1331 | struct pci_dev *dev; |
| 1332 | int i; |
| 1333 | unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM; |
| 1334 | |
| 1335 | list_for_each_entry(dev, &bus->devices, bus_list) { |
| 1336 | for (i=0; i<PCI_BRIDGE_RESOURCES; i++) { |
| 1337 | struct resource *res = &dev->resource[i]; |
| 1338 | if ((res->flags & type_mask) && !res->start && |
| 1339 | res->end) { |
| 1340 | /* Could not assign a required resources |
| 1341 | * for this device, remove it */ |
| 1342 | pci_remove_bus_device(dev); |
| 1343 | break; |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | /* Program resources in newly inserted bridge */ |
| 1350 | static int acpiphp_configure_bridge (acpi_handle handle) |
| 1351 | { |
| 1352 | struct acpi_pci_id pci_id; |
| 1353 | struct pci_bus *bus; |
| 1354 | |
| 1355 | if (ACPI_FAILURE(acpi_get_pci_id(handle, &pci_id))) { |
| 1356 | err("cannot get PCI domain and bus number for bridge\n"); |
| 1357 | return -EINVAL; |
| 1358 | } |
| 1359 | bus = pci_find_bus(pci_id.segment, pci_id.bus); |
| 1360 | if (!bus) { |
| 1361 | err("cannot find bus %d:%d\n", |
| 1362 | pci_id.segment, pci_id.bus); |
| 1363 | return -EINVAL; |
| 1364 | } |
| 1365 | |
| 1366 | pci_bus_size_bridges(bus); |
| 1367 | pci_bus_assign_resources(bus); |
| 1368 | acpiphp_sanitize_bus(bus); |
| 1369 | acpiphp_set_hpp_values(handle, bus); |
| 1370 | pci_enable_bridges(bus); |
Kenji Kaneshige | a0d399a | 2005-04-28 00:25:59 -0700 | [diff] [blame] | 1371 | acpiphp_configure_ioapics(handle); |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1372 | return 0; |
| 1373 | } |
| 1374 | |
| 1375 | static void handle_bridge_insertion(acpi_handle handle, u32 type) |
| 1376 | { |
| 1377 | struct acpi_device *device, *pdevice; |
| 1378 | acpi_handle phandle; |
| 1379 | |
| 1380 | if ((type != ACPI_NOTIFY_BUS_CHECK) && |
| 1381 | (type != ACPI_NOTIFY_DEVICE_CHECK)) { |
| 1382 | err("unexpected notification type %d\n", type); |
| 1383 | return; |
| 1384 | } |
| 1385 | |
| 1386 | acpi_get_parent(handle, &phandle); |
| 1387 | if (acpi_bus_get_device(phandle, &pdevice)) { |
| 1388 | dbg("no parent device, assuming NULL\n"); |
| 1389 | pdevice = NULL; |
| 1390 | } |
| 1391 | if (acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE)) { |
| 1392 | err("cannot add bridge to acpi list\n"); |
| 1393 | return; |
| 1394 | } |
| 1395 | if (!acpiphp_configure_bridge(handle) && |
| 1396 | !acpi_bus_start(device)) |
| 1397 | add_bridge(handle); |
| 1398 | else |
| 1399 | err("cannot configure and start bridge\n"); |
| 1400 | |
| 1401 | } |
| 1402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | /* |
| 1404 | * ACPI event handlers |
| 1405 | */ |
| 1406 | |
| 1407 | /** |
| 1408 | * handle_hotplug_event_bridge - handle ACPI event on bridges |
| 1409 | * |
| 1410 | * @handle: Notify()'ed acpi_handle |
| 1411 | * @type: Notify code |
| 1412 | * @context: pointer to acpiphp_bridge structure |
| 1413 | * |
| 1414 | * handles ACPI event notification on {host,p2p} bridges |
| 1415 | * |
| 1416 | */ |
| 1417 | static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *context) |
| 1418 | { |
| 1419 | struct acpiphp_bridge *bridge; |
| 1420 | char objname[64]; |
| 1421 | struct acpi_buffer buffer = { .length = sizeof(objname), |
| 1422 | .pointer = objname }; |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1423 | struct acpi_device *device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1425 | if (acpi_bus_get_device(handle, &device)) { |
| 1426 | /* This bridge must have just been physically inserted */ |
| 1427 | handle_bridge_insertion(handle, type); |
| 1428 | return; |
| 1429 | } |
| 1430 | |
| 1431 | bridge = acpiphp_handle_to_bridge(handle); |
| 1432 | if (!bridge) { |
| 1433 | err("cannot get bridge info\n"); |
| 1434 | return; |
| 1435 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | |
| 1437 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 1438 | |
| 1439 | switch (type) { |
| 1440 | case ACPI_NOTIFY_BUS_CHECK: |
| 1441 | /* bus re-enumerate */ |
| 1442 | dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname); |
| 1443 | acpiphp_check_bridge(bridge); |
| 1444 | break; |
| 1445 | |
| 1446 | case ACPI_NOTIFY_DEVICE_CHECK: |
| 1447 | /* device check */ |
| 1448 | dbg("%s: Device check notify on %s\n", __FUNCTION__, objname); |
| 1449 | acpiphp_check_bridge(bridge); |
| 1450 | break; |
| 1451 | |
| 1452 | case ACPI_NOTIFY_DEVICE_WAKE: |
| 1453 | /* wake event */ |
| 1454 | dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname); |
| 1455 | break; |
| 1456 | |
| 1457 | case ACPI_NOTIFY_EJECT_REQUEST: |
| 1458 | /* request device eject */ |
| 1459 | dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname); |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 1460 | if ((bridge->type != BRIDGE_TYPE_HOST) && |
| 1461 | (bridge->flags & BRIDGE_HAS_EJ0)) { |
| 1462 | struct acpiphp_slot *slot; |
| 1463 | slot = bridge->func->slot; |
| 1464 | if (!acpiphp_disable_slot(slot)) |
| 1465 | acpiphp_eject_slot(slot); |
| 1466 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | break; |
| 1468 | |
| 1469 | case ACPI_NOTIFY_FREQUENCY_MISMATCH: |
| 1470 | printk(KERN_ERR "Device %s cannot be configured due" |
| 1471 | " to a frequency mismatch\n", objname); |
| 1472 | break; |
| 1473 | |
| 1474 | case ACPI_NOTIFY_BUS_MODE_MISMATCH: |
| 1475 | printk(KERN_ERR "Device %s cannot be configured due" |
| 1476 | " to a bus mode mismatch\n", objname); |
| 1477 | break; |
| 1478 | |
| 1479 | case ACPI_NOTIFY_POWER_FAULT: |
| 1480 | printk(KERN_ERR "Device %s has suffered a power fault\n", |
| 1481 | objname); |
| 1482 | break; |
| 1483 | |
| 1484 | default: |
| 1485 | warn("notify_handler: unknown event type 0x%x for %s\n", type, objname); |
| 1486 | break; |
| 1487 | } |
| 1488 | } |
| 1489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | /** |
| 1491 | * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots) |
| 1492 | * |
| 1493 | * @handle: Notify()'ed acpi_handle |
| 1494 | * @type: Notify code |
| 1495 | * @context: pointer to acpiphp_func structure |
| 1496 | * |
| 1497 | * handles ACPI event notification on slots |
| 1498 | * |
| 1499 | */ |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 1500 | void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | { |
| 1502 | struct acpiphp_func *func; |
| 1503 | char objname[64]; |
| 1504 | struct acpi_buffer buffer = { .length = sizeof(objname), |
| 1505 | .pointer = objname }; |
| 1506 | |
| 1507 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 1508 | |
| 1509 | func = (struct acpiphp_func *)context; |
| 1510 | |
| 1511 | switch (type) { |
| 1512 | case ACPI_NOTIFY_BUS_CHECK: |
| 1513 | /* bus re-enumerate */ |
| 1514 | dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname); |
| 1515 | acpiphp_enable_slot(func->slot); |
| 1516 | break; |
| 1517 | |
| 1518 | case ACPI_NOTIFY_DEVICE_CHECK: |
| 1519 | /* device check : re-enumerate from parent bus */ |
| 1520 | dbg("%s: Device check notify on %s\n", __FUNCTION__, objname); |
| 1521 | acpiphp_check_bridge(func->slot->bridge); |
| 1522 | break; |
| 1523 | |
| 1524 | case ACPI_NOTIFY_DEVICE_WAKE: |
| 1525 | /* wake event */ |
| 1526 | dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname); |
| 1527 | break; |
| 1528 | |
| 1529 | case ACPI_NOTIFY_EJECT_REQUEST: |
| 1530 | /* request device eject */ |
| 1531 | dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname); |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 1532 | if (!(acpiphp_disable_slot(func->slot))) |
| 1533 | acpiphp_eject_slot(func->slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | break; |
| 1535 | |
| 1536 | default: |
| 1537 | warn("notify_handler: unknown event type 0x%x for %s\n", type, objname); |
| 1538 | break; |
| 1539 | } |
| 1540 | } |
| 1541 | |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1542 | |
| 1543 | static acpi_status |
| 1544 | find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 1545 | { |
| 1546 | int *count = (int *)context; |
| 1547 | |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 1548 | if (acpi_root_bridge(handle)) { |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1549 | acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, |
| 1550 | handle_hotplug_event_bridge, NULL); |
| 1551 | (*count)++; |
| 1552 | } |
| 1553 | return AE_OK ; |
| 1554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | |
| 1556 | static struct acpi_pci_driver acpi_pci_hp_driver = { |
| 1557 | .add = add_bridge, |
| 1558 | .remove = remove_bridge, |
| 1559 | }; |
| 1560 | |
| 1561 | /** |
| 1562 | * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures |
| 1563 | * |
| 1564 | */ |
| 1565 | int __init acpiphp_glue_init(void) |
| 1566 | { |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1567 | int num = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1569 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
| 1570 | ACPI_UINT32_MAX, find_root_bridges, &num, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
| 1572 | if (num <= 0) |
| 1573 | return -1; |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1574 | else |
| 1575 | acpi_pci_register_driver(&acpi_pci_hp_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
| 1580 | |
| 1581 | /** |
| 1582 | * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures |
| 1583 | * |
| 1584 | * This function frees all data allocated in acpiphp_glue_init() |
| 1585 | */ |
| 1586 | void __exit acpiphp_glue_exit(void) |
| 1587 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | acpi_pci_unregister_driver(&acpi_pci_hp_driver); |
| 1589 | } |
| 1590 | |
| 1591 | |
| 1592 | /** |
| 1593 | * acpiphp_get_num_slots - count number of slots in a system |
| 1594 | */ |
| 1595 | int __init acpiphp_get_num_slots(void) |
| 1596 | { |
| 1597 | struct list_head *node; |
| 1598 | struct acpiphp_bridge *bridge; |
| 1599 | int num_slots; |
| 1600 | |
| 1601 | num_slots = 0; |
| 1602 | |
| 1603 | list_for_each (node, &bridge_list) { |
| 1604 | bridge = (struct acpiphp_bridge *)node; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1605 | dbg("Bus %04x:%02x has %d slot%s\n", |
| 1606 | pci_domain_nr(bridge->pci_bus), |
| 1607 | bridge->pci_bus->number, bridge->nr_slots, |
| 1608 | bridge->nr_slots == 1 ? "" : "s"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | num_slots += bridge->nr_slots; |
| 1610 | } |
| 1611 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1612 | dbg("Total %d slots\n", num_slots); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | return num_slots; |
| 1614 | } |
| 1615 | |
| 1616 | |
| 1617 | #if 0 |
| 1618 | /** |
| 1619 | * acpiphp_for_each_slot - call function for each slot |
| 1620 | * @fn: callback function |
| 1621 | * @data: context to be passed to callback function |
| 1622 | * |
| 1623 | */ |
| 1624 | static int acpiphp_for_each_slot(acpiphp_callback fn, void *data) |
| 1625 | { |
| 1626 | struct list_head *node; |
| 1627 | struct acpiphp_bridge *bridge; |
| 1628 | struct acpiphp_slot *slot; |
| 1629 | int retval = 0; |
| 1630 | |
| 1631 | list_for_each (node, &bridge_list) { |
| 1632 | bridge = (struct acpiphp_bridge *)node; |
| 1633 | for (slot = bridge->slots; slot; slot = slot->next) { |
| 1634 | retval = fn(slot, data); |
| 1635 | if (!retval) |
| 1636 | goto err_exit; |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | err_exit: |
| 1641 | return retval; |
| 1642 | } |
| 1643 | #endif |
| 1644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | |
| 1646 | /** |
| 1647 | * acpiphp_enable_slot - power on slot |
| 1648 | */ |
| 1649 | int acpiphp_enable_slot(struct acpiphp_slot *slot) |
| 1650 | { |
| 1651 | int retval; |
| 1652 | |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1653 | mutex_lock(&slot->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | |
| 1655 | /* wake up all functions */ |
| 1656 | retval = power_on_slot(slot); |
| 1657 | if (retval) |
| 1658 | goto err_exit; |
| 1659 | |
MUNEDA Takahiro | cde0e5d | 2006-03-22 14:49:33 +0900 | [diff] [blame] | 1660 | if (get_slot_status(slot) == ACPI_STA_ALL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | /* configure all functions */ |
| 1662 | retval = enable_device(slot); |
MUNEDA Takahiro | cde0e5d | 2006-03-22 14:49:33 +0900 | [diff] [blame] | 1663 | if (retval) |
| 1664 | power_off_slot(slot); |
| 1665 | } else { |
| 1666 | dbg("%s: Slot status is not ACPI_STA_ALL\n", __FUNCTION__); |
| 1667 | power_off_slot(slot); |
| 1668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | |
| 1670 | err_exit: |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1671 | mutex_unlock(&slot->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | return retval; |
| 1673 | } |
| 1674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | /** |
| 1676 | * acpiphp_disable_slot - power off slot |
| 1677 | */ |
| 1678 | int acpiphp_disable_slot(struct acpiphp_slot *slot) |
| 1679 | { |
| 1680 | int retval = 0; |
| 1681 | |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1682 | mutex_lock(&slot->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | |
| 1684 | /* unconfigure all functions */ |
| 1685 | retval = disable_device(slot); |
| 1686 | if (retval) |
| 1687 | goto err_exit; |
| 1688 | |
| 1689 | /* power off all functions */ |
| 1690 | retval = power_off_slot(slot); |
| 1691 | if (retval) |
| 1692 | goto err_exit; |
| 1693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | err_exit: |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1695 | mutex_unlock(&slot->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | return retval; |
| 1697 | } |
| 1698 | |
| 1699 | |
| 1700 | /* |
| 1701 | * slot enabled: 1 |
| 1702 | * slot disabled: 0 |
| 1703 | */ |
| 1704 | u8 acpiphp_get_power_status(struct acpiphp_slot *slot) |
| 1705 | { |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 1706 | return (slot->flags & SLOT_POWEREDON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | |
| 1710 | /* |
| 1711 | * latch closed: 1 |
| 1712 | * latch open: 0 |
| 1713 | */ |
| 1714 | u8 acpiphp_get_latch_status(struct acpiphp_slot *slot) |
| 1715 | { |
| 1716 | unsigned int sta; |
| 1717 | |
| 1718 | sta = get_slot_status(slot); |
| 1719 | |
| 1720 | return (sta & ACPI_STA_SHOW_IN_UI) ? 1 : 0; |
| 1721 | } |
| 1722 | |
| 1723 | |
| 1724 | /* |
| 1725 | * adapter presence : 1 |
| 1726 | * absence : 0 |
| 1727 | */ |
| 1728 | u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot) |
| 1729 | { |
| 1730 | unsigned int sta; |
| 1731 | |
| 1732 | sta = get_slot_status(slot); |
| 1733 | |
| 1734 | return (sta == 0) ? 0 : 1; |
| 1735 | } |
| 1736 | |
| 1737 | |
| 1738 | /* |
| 1739 | * pci address (seg/bus/dev) |
| 1740 | */ |
| 1741 | u32 acpiphp_get_address(struct acpiphp_slot *slot) |
| 1742 | { |
| 1743 | u32 address; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1744 | struct pci_bus *pci_bus = slot->bridge->pci_bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 1746 | address = (pci_domain_nr(pci_bus) << 16) | |
| 1747 | (pci_bus->number << 8) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | slot->device; |
| 1749 | |
| 1750 | return address; |
| 1751 | } |