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