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