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