diff options
Diffstat (limited to 'drivers/pci/hotplug')
| -rw-r--r-- | drivers/pci/hotplug/Makefile | 3 | ||||
| -rw-r--r-- | drivers/pci/hotplug/acpiphp.h | 36 | ||||
| -rw-r--r-- | drivers/pci/hotplug/acpiphp_core.c | 19 | ||||
| -rw-r--r-- | drivers/pci/hotplug/acpiphp_dock.c | 438 | ||||
| -rw-r--r-- | drivers/pci/hotplug/acpiphp_glue.c | 123 |
5 files changed, 96 insertions, 523 deletions
diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile index 421cfffb1756..34a1891191fd 100644 --- a/drivers/pci/hotplug/Makefile +++ b/drivers/pci/hotplug/Makefile | |||
| @@ -40,8 +40,7 @@ ibmphp-objs := ibmphp_core.o \ | |||
| 40 | ibmphp_hpc.o | 40 | ibmphp_hpc.o |
| 41 | 41 | ||
| 42 | acpiphp-objs := acpiphp_core.o \ | 42 | acpiphp-objs := acpiphp_core.o \ |
| 43 | acpiphp_glue.o \ | 43 | acpiphp_glue.o |
| 44 | acpiphp_dock.o | ||
| 45 | 44 | ||
| 46 | rpaphp-objs := rpaphp_core.o \ | 45 | rpaphp-objs := rpaphp_core.o \ |
| 47 | rpaphp_pci.o \ | 46 | rpaphp_pci.o \ |
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h index 17a93f890dba..be104eced34c 100644 --- a/drivers/pci/hotplug/acpiphp.h +++ b/drivers/pci/hotplug/acpiphp.h | |||
| @@ -130,7 +130,7 @@ struct acpiphp_func { | |||
| 130 | 130 | ||
| 131 | struct list_head sibling; | 131 | struct list_head sibling; |
| 132 | struct pci_dev *pci_dev; | 132 | struct pci_dev *pci_dev; |
| 133 | 133 | struct notifier_block nb; | |
| 134 | acpi_handle handle; | 134 | acpi_handle handle; |
| 135 | 135 | ||
| 136 | u8 function; /* pci function# */ | 136 | u8 function; /* pci function# */ |
| @@ -151,24 +151,6 @@ struct acpiphp_attention_info | |||
| 151 | }; | 151 | }; |
| 152 | 152 | ||
| 153 | 153 | ||
| 154 | struct dependent_device { | ||
| 155 | struct list_head device_list; | ||
| 156 | struct list_head pci_list; | ||
| 157 | acpi_handle handle; | ||
| 158 | struct acpiphp_func *func; | ||
| 159 | }; | ||
| 160 | |||
| 161 | |||
| 162 | struct acpiphp_dock_station { | ||
| 163 | acpi_handle handle; | ||
| 164 | u32 last_dock_time; | ||
| 165 | u32 flags; | ||
| 166 | struct acpiphp_func *dock_bridge; | ||
| 167 | struct list_head dependent_devices; | ||
| 168 | struct list_head pci_dependent_devices; | ||
| 169 | }; | ||
| 170 | |||
| 171 | |||
| 172 | /* PCI bus bridge HID */ | 154 | /* PCI bus bridge HID */ |
| 173 | #define ACPI_PCI_HOST_HID "PNP0A03" | 155 | #define ACPI_PCI_HOST_HID "PNP0A03" |
| 174 | 156 | ||
| @@ -207,11 +189,6 @@ struct acpiphp_dock_station { | |||
| 207 | #define FUNC_HAS_PS2 (0x00000040) | 189 | #define FUNC_HAS_PS2 (0x00000040) |
| 208 | #define FUNC_HAS_PS3 (0x00000080) | 190 | #define FUNC_HAS_PS3 (0x00000080) |
| 209 | #define FUNC_HAS_DCK (0x00000100) | 191 | #define FUNC_HAS_DCK (0x00000100) |
| 210 | #define FUNC_IS_DD (0x00000200) | ||
| 211 | |||
| 212 | /* dock station flags */ | ||
| 213 | #define DOCK_DOCKING (0x00000001) | ||
| 214 | #define DOCK_HAS_BRIDGE (0x00000002) | ||
| 215 | 192 | ||
| 216 | /* function prototypes */ | 193 | /* function prototypes */ |
| 217 | 194 | ||
| @@ -226,7 +203,6 @@ extern int acpiphp_glue_init (void); | |||
| 226 | extern void acpiphp_glue_exit (void); | 203 | extern void acpiphp_glue_exit (void); |
| 227 | extern int acpiphp_get_num_slots (void); | 204 | extern int acpiphp_get_num_slots (void); |
| 228 | typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data); | 205 | typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data); |
| 229 | void handle_hotplug_event_func(acpi_handle, u32, void*); | ||
| 230 | 206 | ||
| 231 | extern int acpiphp_enable_slot (struct acpiphp_slot *slot); | 207 | extern int acpiphp_enable_slot (struct acpiphp_slot *slot); |
| 232 | extern int acpiphp_disable_slot (struct acpiphp_slot *slot); | 208 | extern int acpiphp_disable_slot (struct acpiphp_slot *slot); |
| @@ -236,16 +212,6 @@ extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot); | |||
| 236 | extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); | 212 | extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); |
| 237 | extern u32 acpiphp_get_address (struct acpiphp_slot *slot); | 213 | extern u32 acpiphp_get_address (struct acpiphp_slot *slot); |
| 238 | 214 | ||
| 239 | /* acpiphp_dock.c */ | ||
| 240 | extern int find_dock_station(void); | ||
| 241 | extern void remove_dock_station(void); | ||
| 242 | extern void add_dependent_device(struct dependent_device *new_dd); | ||
| 243 | extern void add_pci_dependent_device(struct dependent_device *new_dd); | ||
| 244 | extern struct dependent_device *get_dependent_device(acpi_handle handle); | ||
| 245 | extern int is_dependent_device(acpi_handle handle); | ||
| 246 | extern int detect_dependent_devices(acpi_handle *bridge_handle); | ||
| 247 | extern struct dependent_device *alloc_dependent_device(acpi_handle handle); | ||
| 248 | |||
| 249 | /* variables */ | 215 | /* variables */ |
| 250 | extern int acpiphp_debug; | 216 | extern int acpiphp_debug; |
| 251 | 217 | ||
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c index 4f1b0da8e47e..34de5697983d 100644 --- a/drivers/pci/hotplug/acpiphp_core.c +++ b/drivers/pci/hotplug/acpiphp_core.c | |||
| @@ -416,27 +416,12 @@ void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *acpiphp_slot) | |||
| 416 | 416 | ||
| 417 | static int __init acpiphp_init(void) | 417 | static int __init acpiphp_init(void) |
| 418 | { | 418 | { |
| 419 | int retval; | ||
| 420 | int docking_station; | ||
| 421 | |||
| 422 | info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); | 419 | info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); |
| 423 | 420 | ||
| 424 | acpiphp_debug = debug; | 421 | acpiphp_debug = debug; |
| 425 | 422 | ||
| 426 | docking_station = find_dock_station(); | ||
| 427 | |||
| 428 | /* read all the ACPI info from the system */ | 423 | /* read all the ACPI info from the system */ |
| 429 | retval = init_acpi(); | 424 | return init_acpi(); |
| 430 | |||
| 431 | /* if we have found a docking station, we should | ||
| 432 | * go ahead and load even if init_acpi has found | ||
| 433 | * no slots. This handles the case when the _DCK | ||
| 434 | * method not defined under the actual dock bridge | ||
| 435 | */ | ||
| 436 | if (docking_station) | ||
| 437 | return 0; | ||
| 438 | else | ||
| 439 | return retval; | ||
| 440 | } | 425 | } |
| 441 | 426 | ||
| 442 | 427 | ||
| @@ -444,8 +429,6 @@ static void __exit acpiphp_exit(void) | |||
| 444 | { | 429 | { |
| 445 | /* deallocate internal data structures etc. */ | 430 | /* deallocate internal data structures etc. */ |
| 446 | acpiphp_glue_exit(); | 431 | acpiphp_glue_exit(); |
| 447 | |||
| 448 | remove_dock_station(); | ||
| 449 | } | 432 | } |
| 450 | 433 | ||
| 451 | module_init(acpiphp_init); | 434 | module_init(acpiphp_init); |
diff --git a/drivers/pci/hotplug/acpiphp_dock.c b/drivers/pci/hotplug/acpiphp_dock.c deleted file mode 100644 index 4f1aaf128312..000000000000 --- a/drivers/pci/hotplug/acpiphp_dock.c +++ /dev/null | |||
| @@ -1,438 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * ACPI PCI HotPlug dock functions to ACPI CA subsystem | ||
| 3 | * | ||
| 4 | * Copyright (C) 2006 Kristen Carlson Accardi (kristen.c.accardi@intel.com) | ||
| 5 | * Copyright (C) 2006 Intel Corporation | ||
| 6 | * | ||
| 7 | * All rights reserved. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License as published by | ||
| 11 | * the Free Software Foundation; either version 2 of the License, or (at | ||
| 12 | * your option) any later version. | ||
| 13 | * | ||
| 14 | * This program is distributed in the hope that it will be useful, but | ||
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | ||
| 17 | * NON INFRINGEMENT. See the GNU General Public License for more | ||
| 18 | * details. | ||
| 19 | * | ||
| 20 | * You should have received a copy of the GNU General Public License | ||
| 21 | * along with this program; if not, write to the Free Software | ||
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 23 | * | ||
| 24 | * Send feedback to <kristen.c.accardi@intel.com> | ||
| 25 | * | ||
| 26 | */ | ||
| 27 | #include <linux/init.h> | ||
| 28 | #include <linux/module.h> | ||
| 29 | |||
| 30 | #include <linux/kernel.h> | ||
| 31 | #include <linux/pci.h> | ||
| 32 | #include <linux/smp_lock.h> | ||
| 33 | #include <linux/mutex.h> | ||
| 34 | |||
| 35 | #include "../pci.h" | ||
| 36 | #include "pci_hotplug.h" | ||
| 37 | #include "acpiphp.h" | ||
| 38 | |||
| 39 | static struct acpiphp_dock_station *ds; | ||
| 40 | #define MY_NAME "acpiphp_dock" | ||
| 41 | |||
| 42 | |||
| 43 | int is_dependent_device(acpi_handle handle) | ||
| 44 | { | ||
| 45 | return (get_dependent_device(handle) ? 1 : 0); | ||
| 46 | } | ||
| 47 | |||
| 48 | |||
| 49 | static acpi_status | ||
| 50 | find_dependent_device(acpi_handle handle, u32 lvl, void *context, void **rv) | ||
| 51 | { | ||
| 52 | int *count = (int *)context; | ||
| 53 | |||
| 54 | if (is_dependent_device(handle)) { | ||
| 55 | (*count)++; | ||
| 56 | return AE_CTRL_TERMINATE; | ||
| 57 | } else { | ||
| 58 | return AE_OK; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | void add_dependent_device(struct dependent_device *new_dd) | ||
| 66 | { | ||
| 67 | list_add_tail(&new_dd->device_list, &ds->dependent_devices); | ||
| 68 | } | ||
| 69 | |||
| 70 | |||
| 71 | void add_pci_dependent_device(struct dependent_device *new_dd) | ||
| 72 | { | ||
| 73 | list_add_tail(&new_dd->pci_list, &ds->pci_dependent_devices); | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | |||
| 78 | struct dependent_device * get_dependent_device(acpi_handle handle) | ||
| 79 | { | ||
| 80 | struct dependent_device *dd; | ||
| 81 | |||
| 82 | if (!ds) | ||
| 83 | return NULL; | ||
| 84 | |||
| 85 | list_for_each_entry(dd, &ds->dependent_devices, device_list) { | ||
| 86 | if (handle == dd->handle) | ||
| 87 | return dd; | ||
| 88 | } | ||
| 89 | return NULL; | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
| 93 | |||
| 94 | struct dependent_device *alloc_dependent_device(acpi_handle handle) | ||
| 95 | { | ||
| 96 | struct dependent_device *dd; | ||
| 97 | |||
| 98 | dd = kzalloc(sizeof(*dd), GFP_KERNEL); | ||
| 99 | if (dd) { | ||
| 100 | INIT_LIST_HEAD(&dd->pci_list); | ||
| 101 | INIT_LIST_HEAD(&dd->device_list); | ||
| 102 | dd->handle = handle; | ||
| 103 | } | ||
| 104 | return dd; | ||
| 105 | } | ||
| 106 | |||
| 107 | |||
| 108 | |||
| 109 | static int is_dock(acpi_handle handle) | ||
| 110 | { | ||
| 111 | acpi_status status; | ||
| 112 | acpi_handle tmp; | ||
| 113 | |||
| 114 | status = acpi_get_handle(handle, "_DCK", &tmp); | ||
| 115 | if (ACPI_FAILURE(status)) { | ||
| 116 | return 0; | ||
| 117 | } | ||
| 118 | return 1; | ||
| 119 | } | ||
| 120 | |||
| 121 | |||
| 122 | |||
| 123 | static int dock_present(void) | ||
| 124 | { | ||
| 125 | unsigned long sta; | ||
| 126 | acpi_status status; | ||
| 127 | |||
| 128 | if (ds) { | ||
| 129 | status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta); | ||
| 130 | if (ACPI_SUCCESS(status) && sta) | ||
| 131 | return 1; | ||
| 132 | } | ||
| 133 | return 0; | ||
| 134 | } | ||
| 135 | |||
| 136 | |||
| 137 | |||
| 138 | static void eject_dock(void) | ||
| 139 | { | ||
| 140 | struct acpi_object_list arg_list; | ||
| 141 | union acpi_object arg; | ||
| 142 | |||
| 143 | arg_list.count = 1; | ||
| 144 | arg_list.pointer = &arg; | ||
| 145 | arg.type = ACPI_TYPE_INTEGER; | ||
| 146 | arg.integer.value = 1; | ||
| 147 | |||
| 148 | if (ACPI_FAILURE(acpi_evaluate_object(ds->handle, "_EJ0", | ||
| 149 | &arg_list, NULL)) || dock_present()) | ||
| 150 | warn("%s: failed to eject dock!\n", __FUNCTION__); | ||
| 151 | |||
| 152 | return; | ||
| 153 | } | ||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | |||
| 158 | static acpi_status handle_dock(int dock) | ||
| 159 | { | ||
| 160 | acpi_status status; | ||
| 161 | struct acpi_object_list arg_list; | ||
| 162 | union acpi_object arg; | ||
| 163 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
| 164 | |||
| 165 | dbg("%s: %s\n", __FUNCTION__, dock ? "docking" : "undocking"); | ||
| 166 | |||
| 167 | /* _DCK method has one argument */ | ||
| 168 | arg_list.count = 1; | ||
| 169 | arg_list.pointer = &arg; | ||
| 170 | arg.type = ACPI_TYPE_INTEGER; | ||
| 171 | arg.integer.value = dock; | ||
| 172 | status = acpi_evaluate_object(ds->handle, "_DCK", | ||
| 173 | &arg_list, &buffer); | ||
| 174 | if (ACPI_FAILURE(status)) | ||
| 175 | err("%s: failed to execute _DCK\n", __FUNCTION__); | ||
| 176 | acpi_os_free(buffer.pointer); | ||
| 177 | |||
| 178 | return status; | ||
| 179 | } | ||
| 180 | |||
| 181 | |||
| 182 | |||
| 183 | static inline void dock(void) | ||
| 184 | { | ||
| 185 | handle_dock(1); | ||
| 186 | } | ||
| 187 | |||
| 188 | |||
| 189 | |||
| 190 | static inline void undock(void) | ||
| 191 | { | ||
| 192 | handle_dock(0); | ||
| 193 | } | ||
| 194 | |||
| 195 | |||
| 196 | |||
| 197 | /* | ||
| 198 | * the _DCK method can do funny things... and sometimes not | ||
| 199 | * hah-hah funny. | ||
| 200 | * | ||
| 201 | * TBD - figure out a way to only call fixups for | ||
| 202 | * systems that require them. | ||
| 203 | */ | ||
| 204 | static void post_dock_fixups(void) | ||
| 205 | { | ||
| 206 | struct pci_bus *bus; | ||
| 207 | u32 buses; | ||
| 208 | struct dependent_device *dd; | ||
| 209 | |||
| 210 | list_for_each_entry(dd, &ds->pci_dependent_devices, pci_list) { | ||
| 211 | bus = dd->func->slot->bridge->pci_bus; | ||
| 212 | |||
| 213 | /* fixup bad _DCK function that rewrites | ||
| 214 | * secondary bridge on slot | ||
| 215 | */ | ||
| 216 | pci_read_config_dword(bus->self, | ||
| 217 | PCI_PRIMARY_BUS, | ||
| 218 | &buses); | ||
| 219 | |||
| 220 | if (((buses >> 8) & 0xff) != bus->secondary) { | ||
| 221 | buses = (buses & 0xff000000) | ||
| 222 | | ((unsigned int)(bus->primary) << 0) | ||
| 223 | | ((unsigned int)(bus->secondary) << 8) | ||
| 224 | | ((unsigned int)(bus->subordinate) << 16); | ||
| 225 | pci_write_config_dword(bus->self, | ||
| 226 | PCI_PRIMARY_BUS, | ||
| 227 | buses); | ||
| 228 | } | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | |||
| 233 | |||
| 234 | static void hotplug_pci(u32 type) | ||
| 235 | { | ||
| 236 | struct dependent_device *dd; | ||
| 237 | |||
| 238 | list_for_each_entry(dd, &ds->pci_dependent_devices, pci_list) | ||
| 239 | handle_hotplug_event_func(dd->handle, type, dd->func); | ||
| 240 | } | ||
| 241 | |||
| 242 | |||
| 243 | |||
| 244 | static inline void begin_dock(void) | ||
| 245 | { | ||
| 246 | ds->flags |= DOCK_DOCKING; | ||
| 247 | } | ||
| 248 | |||
| 249 | |||
| 250 | static inline void complete_dock(void) | ||
| 251 | { | ||
| 252 | ds->flags &= ~(DOCK_DOCKING); | ||
| 253 | ds->last_dock_time = jiffies; | ||
| 254 | } | ||
| 255 | |||
| 256 | |||
| 257 | static int dock_in_progress(void) | ||
| 258 | { | ||
| 259 | if (ds->flags & DOCK_DOCKING || | ||
| 260 | ds->last_dock_time == jiffies) { | ||
| 261 | dbg("dock in progress\n"); | ||
| 262 | return 1; | ||
| 263 | } | ||
| 264 | return 0; | ||
| 265 | } | ||
| 266 | |||
| 267 | |||
| 268 | |||
| 269 | static void | ||
| 270 | handle_hotplug_event_dock(acpi_handle handle, u32 type, void *context) | ||
| 271 | { | ||
| 272 | dbg("%s: enter\n", __FUNCTION__); | ||
| 273 | |||
| 274 | switch (type) { | ||
| 275 | case ACPI_NOTIFY_BUS_CHECK: | ||
| 276 | dbg("BUS Check\n"); | ||
| 277 | if (!dock_in_progress() && dock_present()) { | ||
| 278 | begin_dock(); | ||
| 279 | dock(); | ||
| 280 | if (!dock_present()) { | ||
| 281 | err("Unable to dock!\n"); | ||
| 282 | break; | ||
| 283 | } | ||
| 284 | post_dock_fixups(); | ||
| 285 | hotplug_pci(type); | ||
| 286 | complete_dock(); | ||
| 287 | } | ||
| 288 | break; | ||
| 289 | case ACPI_NOTIFY_EJECT_REQUEST: | ||
| 290 | dbg("EJECT request\n"); | ||
| 291 | if (!dock_in_progress() && dock_present()) { | ||
| 292 | hotplug_pci(type); | ||
| 293 | undock(); | ||
| 294 | eject_dock(); | ||
| 295 | if (dock_present()) | ||
| 296 | err("Unable to undock!\n"); | ||
| 297 | } | ||
| 298 | break; | ||
| 299 | } | ||
| 300 | } | ||
| 301 | |||
| 302 | |||
| 303 | |||
| 304 | |||
| 305 | static acpi_status | ||
| 306 | find_dock_ejd(acpi_handle handle, u32 lvl, void *context, void **rv) | ||
| 307 | { | ||
| 308 | acpi_status status; | ||
| 309 | acpi_handle tmp; | ||
| 310 | acpi_handle dck_handle = (acpi_handle) context; | ||
| 311 | char objname[64]; | ||
| 312 | struct acpi_buffer buffer = { .length = sizeof(objname), | ||
| 313 | .pointer = objname }; | ||
| 314 | struct acpi_buffer ejd_buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
| 315 | union acpi_object *ejd_obj; | ||
| 316 | |||
| 317 | status = acpi_get_handle(handle, "_EJD", &tmp); | ||
| 318 | if (ACPI_FAILURE(status)) | ||
| 319 | return AE_OK; | ||
| 320 | |||
| 321 | /* make sure we are dependent on the dock device, | ||
| 322 | * by executing the _EJD method, then getting a handle | ||
| 323 | * to the device referenced by that name. If that | ||
| 324 | * device handle is the same handle as the dock station | ||
| 325 | * handle, then we are a device dependent on the dock station | ||
| 326 | */ | ||
| 327 | acpi_get_name(dck_handle, ACPI_FULL_PATHNAME, &buffer); | ||
| 328 | status = acpi_evaluate_object(handle, "_EJD", NULL, &ejd_buffer); | ||
| 329 | if (ACPI_FAILURE(status)) { | ||
| 330 | err("Unable to execute _EJD!\n"); | ||
| 331 | goto find_ejd_out; | ||
| 332 | } | ||
| 333 | ejd_obj = ejd_buffer.pointer; | ||
| 334 | status = acpi_get_handle(NULL, ejd_obj->string.pointer, &tmp); | ||
| 335 | if (ACPI_FAILURE(status)) | ||
| 336 | goto find_ejd_out; | ||
| 337 | |||
| 338 | if (tmp == dck_handle) { | ||
| 339 | struct dependent_device *dd; | ||
| 340 | dbg("%s: found device dependent on dock\n", __FUNCTION__); | ||
| 341 | dd = alloc_dependent_device(handle); | ||
| 342 | if (!dd) { | ||
| 343 | err("Can't allocate memory for dependent device!\n"); | ||
| 344 | goto find_ejd_out; | ||
| 345 | } | ||
| 346 | add_dependent_device(dd); | ||
| 347 | } | ||
| 348 | |||
| 349 | find_ejd_out: | ||
| 350 | acpi_os_free(ejd_buffer.pointer); | ||
| 351 | return AE_OK; | ||
| 352 | } | ||
| 353 | |||
| 354 | |||
| 355 | |||
| 356 | int detect_dependent_devices(acpi_handle *bridge_handle) | ||
| 357 | { | ||
| 358 | acpi_status status; | ||
| 359 | int count; | ||
| 360 | |||
| 361 | count = 0; | ||
| 362 | |||
| 363 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, | ||
| 364 | (u32)1, find_dependent_device, | ||
| 365 | (void *)&count, NULL); | ||
| 366 | |||
| 367 | return count; | ||
| 368 | } | ||
| 369 | |||
| 370 | |||
| 371 | |||
| 372 | |||
| 373 | |||
| 374 | static acpi_status | ||
| 375 | find_dock(acpi_handle handle, u32 lvl, void *context, void **rv) | ||
| 376 | { | ||
| 377 | int *count = (int *)context; | ||
| 378 | |||
| 379 | if (is_dock(handle)) { | ||
| 380 | dbg("%s: found dock\n", __FUNCTION__); | ||
| 381 | ds = kzalloc(sizeof(*ds), GFP_KERNEL); | ||
| 382 | ds->handle = handle; | ||
| 383 | INIT_LIST_HEAD(&ds->dependent_devices); | ||
| 384 | INIT_LIST_HEAD(&ds->pci_dependent_devices); | ||
| 385 | |||
| 386 | /* look for devices dependent on dock station */ | ||
| 387 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, | ||
| 388 | ACPI_UINT32_MAX, find_dock_ejd, handle, NULL); | ||
| 389 | |||
| 390 | acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, | ||
| 391 | handle_hotplug_event_dock, ds); | ||
| 392 | (*count)++; | ||
| 393 | } | ||
| 394 | |||
| 395 | return AE_OK; | ||
| 396 | } | ||
| 397 | |||
| 398 | |||
| 399 | |||
| 400 | |||
| 401 | int find_dock_station(void) | ||
| 402 | { | ||
| 403 | int num = 0; | ||
| 404 | |||
| 405 | ds = NULL; | ||
| 406 | |||
| 407 | /* start from the root object, because some laptops define | ||
| 408 | * _DCK methods outside the scope of PCI (IBM x-series laptop) | ||
| 409 | */ | ||
| 410 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, | ||
| 411 | ACPI_UINT32_MAX, find_dock, &num, NULL); | ||
| 412 | |||
| 413 | return num; | ||
| 414 | } | ||
| 415 | |||
| 416 | |||
| 417 | |||
| 418 | void remove_dock_station(void) | ||
| 419 | { | ||
| 420 | struct dependent_device *dd, *tmp; | ||
| 421 | if (ds) { | ||
| 422 | if (ACPI_FAILURE(acpi_remove_notify_handler(ds->handle, | ||
| 423 | ACPI_SYSTEM_NOTIFY, handle_hotplug_event_dock))) | ||
| 424 | err("failed to remove dock notify handler\n"); | ||
| 425 | |||
| 426 | /* free all dependent devices */ | ||
| 427 | list_for_each_entry_safe(dd, tmp, &ds->dependent_devices, | ||
| 428 | device_list) | ||
| 429 | kfree(dd); | ||
| 430 | |||
| 431 | /* no need to touch the pci_dependent_device list, | ||
| 432 | * cause all memory was freed above | ||
| 433 | */ | ||
| 434 | kfree(ds); | ||
| 435 | } | ||
| 436 | } | ||
| 437 | |||
| 438 | |||
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index d370f999782e..ef95d12fb32c 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c | |||
| @@ -59,6 +59,7 @@ static LIST_HEAD(bridge_list); | |||
| 59 | static void handle_hotplug_event_bridge (acpi_handle, u32, void *); | 59 | static void handle_hotplug_event_bridge (acpi_handle, u32, void *); |
| 60 | static void acpiphp_sanitize_bus(struct pci_bus *bus); | 60 | static void acpiphp_sanitize_bus(struct pci_bus *bus); |
| 61 | static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus); | 61 | static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus); |
| 62 | static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context); | ||
| 62 | 63 | ||
| 63 | 64 | ||
| 64 | /* | 65 | /* |
| @@ -116,6 +117,59 @@ is_ejectable_slot(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
| 116 | } | 117 | } |
| 117 | } | 118 | } |
| 118 | 119 | ||
| 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 | |||
| 119 | 173 | ||
| 120 | /* callback routine to register each ACPI PCI slot object */ | 174 | /* callback routine to register each ACPI PCI slot object */ |
| 121 | static acpi_status | 175 | static acpi_status |
| @@ -124,7 +178,6 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
| 124 | struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context; | 178 | struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context; |
| 125 | struct acpiphp_slot *slot; | 179 | struct acpiphp_slot *slot; |
| 126 | struct acpiphp_func *newfunc; | 180 | struct acpiphp_func *newfunc; |
| 127 | struct dependent_device *dd; | ||
| 128 | acpi_handle tmp; | 181 | acpi_handle tmp; |
| 129 | acpi_status status = AE_OK; | 182 | acpi_status status = AE_OK; |
| 130 | unsigned long adr, sun; | 183 | unsigned long adr, sun; |
| @@ -137,7 +190,7 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
| 137 | 190 | ||
| 138 | status = acpi_get_handle(handle, "_EJ0", &tmp); | 191 | status = acpi_get_handle(handle, "_EJ0", &tmp); |
| 139 | 192 | ||
| 140 | if (ACPI_FAILURE(status) && !(is_dependent_device(handle))) | 193 | if (ACPI_FAILURE(status) && !(is_dock_device(handle))) |
| 141 | return AE_OK; | 194 | return AE_OK; |
| 142 | 195 | ||
| 143 | device = (adr >> 16) & 0xffff; | 196 | device = (adr >> 16) & 0xffff; |
| @@ -162,22 +215,17 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
| 162 | if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp))) | 215 | if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp))) |
| 163 | newfunc->flags |= FUNC_HAS_PS3; | 216 | newfunc->flags |= FUNC_HAS_PS3; |
| 164 | 217 | ||
| 165 | if (ACPI_SUCCESS(acpi_get_handle(handle, "_DCK", &tmp))) { | 218 | if (ACPI_SUCCESS(acpi_get_handle(handle, "_DCK", &tmp))) |
| 166 | newfunc->flags |= FUNC_HAS_DCK; | 219 | newfunc->flags |= FUNC_HAS_DCK; |
| 167 | /* add to devices dependent on dock station, | ||
| 168 | * because this may actually be the dock bridge | ||
| 169 | */ | ||
| 170 | dd = alloc_dependent_device(handle); | ||
| 171 | if (!dd) | ||
| 172 | err("Can't allocate memory for " | ||
| 173 | "new dependent device!\n"); | ||
| 174 | else | ||
| 175 | add_dependent_device(dd); | ||
| 176 | } | ||
| 177 | 220 | ||
| 178 | status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun); | 221 | status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun); |
| 179 | if (ACPI_FAILURE(status)) | 222 | if (ACPI_FAILURE(status)) { |
| 180 | sun = -1; | 223 | /* |
| 224 | * use the count of the number of slots we've found | ||
| 225 | * for the number of the slot | ||
| 226 | */ | ||
| 227 | sun = bridge->nr_slots+1; | ||
| 228 | } | ||
| 181 | 229 | ||
| 182 | /* search for objects that share the same slot */ | 230 | /* search for objects that share the same slot */ |
| 183 | for (slot = bridge->slots; slot; slot = slot->next) | 231 | for (slot = bridge->slots; slot; slot = slot->next) |
| @@ -225,20 +273,23 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
| 225 | slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); | 273 | slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); |
| 226 | } | 274 | } |
| 227 | 275 | ||
| 228 | /* if this is a device dependent on a dock station, | 276 | if (is_dock_device(handle)) { |
| 229 | * associate the acpiphp_func to the dependent_device | 277 | /* we don't want to call this device's _EJ0 |
| 230 | * struct. | 278 | * because we want the dock notify handler |
| 231 | */ | 279 | * to call it after it calls _DCK |
| 232 | if ((dd = get_dependent_device(handle))) { | ||
| 233 | newfunc->flags |= FUNC_IS_DD; | ||
| 234 | /* | ||
| 235 | * we don't want any devices which is dependent | ||
| 236 | * on the dock to have it's _EJ0 method executed. | ||
| 237 | * because we need to run _DCK first. | ||
| 238 | */ | 280 | */ |
| 239 | newfunc->flags &= ~FUNC_HAS_EJ0; | 281 | newfunc->flags &= ~FUNC_HAS_EJ0; |
| 240 | dd->func = newfunc; | 282 | if (register_hotplug_dock_device(handle, |
| 241 | add_pci_dependent_device(dd); | 283 | handle_hotplug_event_func, newfunc)) |
| 284 | dbg("failed to register dock device\n"); | ||
| 285 | |||
| 286 | /* we need to be notified when dock events happen | ||
| 287 | * outside of the hotplug operation, since we may | ||
| 288 | * need to do fixups before we can hotplug. | ||
| 289 | */ | ||
| 290 | newfunc->nb.notifier_call = post_dock_fixups; | ||
| 291 | if (register_dock_notifier(&newfunc->nb)) | ||
| 292 | dbg("failed to register a dock notifier"); | ||
| 242 | } | 293 | } |
| 243 | 294 | ||
| 244 | /* install notify handler */ | 295 | /* install notify handler */ |
| @@ -277,6 +328,15 @@ static int detect_ejectable_slots(acpi_handle *bridge_handle) | |||
| 277 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, (u32)1, | 328 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, (u32)1, |
| 278 | is_ejectable_slot, (void *)&count, NULL); | 329 | is_ejectable_slot, (void *)&count, NULL); |
| 279 | 330 | ||
| 331 | /* | ||
| 332 | * we also need to add this bridge if there is a dock bridge or | ||
| 333 | * other pci device on a dock station (removable) | ||
| 334 | */ | ||
| 335 | if (!count) | ||
| 336 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, | ||
| 337 | (u32)1, is_pci_dock_device, (void *)&count, | ||
| 338 | NULL); | ||
| 339 | |||
| 280 | return count; | 340 | return count; |
| 281 | } | 341 | } |
| 282 | 342 | ||
| @@ -487,8 +547,7 @@ find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
| 487 | goto out; | 547 | goto out; |
| 488 | 548 | ||
| 489 | /* check if this bridge has ejectable slots */ | 549 | /* check if this bridge has ejectable slots */ |
| 490 | if ((detect_ejectable_slots(handle) > 0) || | 550 | if ((detect_ejectable_slots(handle) > 0)) { |
| 491 | (detect_dependent_devices(handle) > 0)) { | ||
| 492 | dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev)); | 551 | dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev)); |
| 493 | add_p2p_bridge(handle, dev); | 552 | add_p2p_bridge(handle, dev); |
| 494 | } | 553 | } |
| @@ -605,6 +664,10 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge) | |||
| 605 | list_for_each_safe (list, tmp, &slot->funcs) { | 664 | list_for_each_safe (list, tmp, &slot->funcs) { |
| 606 | struct acpiphp_func *func; | 665 | struct acpiphp_func *func; |
| 607 | func = list_entry(list, struct acpiphp_func, sibling); | 666 | func = list_entry(list, struct acpiphp_func, sibling); |
| 667 | if (is_dock_device(func->handle)) { | ||
| 668 | unregister_hotplug_dock_device(func->handle); | ||
| 669 | unregister_dock_notifier(&func->nb); | ||
| 670 | } | ||
| 608 | if (!(func->flags & FUNC_HAS_DCK)) { | 671 | if (!(func->flags & FUNC_HAS_DCK)) { |
| 609 | status = acpi_remove_notify_handler(func->handle, | 672 | status = acpi_remove_notify_handler(func->handle, |
| 610 | ACPI_SYSTEM_NOTIFY, | 673 | ACPI_SYSTEM_NOTIFY, |
| @@ -1440,7 +1503,7 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *cont | |||
| 1440 | * handles ACPI event notification on slots | 1503 | * handles ACPI event notification on slots |
| 1441 | * | 1504 | * |
| 1442 | */ | 1505 | */ |
| 1443 | void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context) | 1506 | static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context) |
| 1444 | { | 1507 | { |
| 1445 | struct acpiphp_func *func; | 1508 | struct acpiphp_func *func; |
| 1446 | char objname[64]; | 1509 | char objname[64]; |
