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