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