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