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