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