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