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