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