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