diff options
Diffstat (limited to 'drivers/pci/hotplug/shpchp_ctrl.c')
-rw-r--r-- | drivers/pci/hotplug/shpchp_ctrl.c | 2034 |
1 files changed, 84 insertions, 1950 deletions
diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c index 91c9903e621f..58619359ad08 100644 --- a/drivers/pci/hotplug/shpchp_ctrl.c +++ b/drivers/pci/hotplug/shpchp_ctrl.c | |||
@@ -27,24 +27,14 @@ | |||
27 | * | 27 | * |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <linux/config.h> | ||
31 | #include <linux/module.h> | 30 | #include <linux/module.h> |
32 | #include <linux/kernel.h> | 31 | #include <linux/kernel.h> |
33 | #include <linux/types.h> | 32 | #include <linux/types.h> |
34 | #include <linux/slab.h> | ||
35 | #include <linux/workqueue.h> | ||
36 | #include <linux/interrupt.h> | ||
37 | #include <linux/delay.h> | ||
38 | #include <linux/wait.h> | ||
39 | #include <linux/smp_lock.h> | 33 | #include <linux/smp_lock.h> |
40 | #include <linux/pci.h> | 34 | #include <linux/pci.h> |
35 | #include "../pci.h" | ||
41 | #include "shpchp.h" | 36 | #include "shpchp.h" |
42 | #include "shpchprm.h" | ||
43 | 37 | ||
44 | static u32 configure_new_device(struct controller *ctrl, struct pci_func *func, | ||
45 | u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev); | ||
46 | static int configure_new_function( struct controller *ctrl, struct pci_func *func, | ||
47 | u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev); | ||
48 | static void interrupt_event_handler(struct controller *ctrl); | 38 | static void interrupt_event_handler(struct controller *ctrl); |
49 | 39 | ||
50 | static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */ | 40 | static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */ |
@@ -52,28 +42,22 @@ static struct semaphore event_exit; /* guard ensure thread has exited before ca | |||
52 | static int event_finished; | 42 | static int event_finished; |
53 | static unsigned long pushbutton_pending; /* = 0 */ | 43 | static unsigned long pushbutton_pending; /* = 0 */ |
54 | 44 | ||
55 | u8 shpchp_disk_irq; | ||
56 | u8 shpchp_nic_irq; | ||
57 | |||
58 | u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id) | 45 | u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id) |
59 | { | 46 | { |
60 | struct controller *ctrl = (struct controller *) inst_id; | 47 | struct controller *ctrl = (struct controller *) inst_id; |
61 | struct slot *p_slot; | 48 | struct slot *p_slot; |
62 | u8 rc = 0; | 49 | u8 rc = 0; |
63 | u8 getstatus; | 50 | u8 getstatus; |
64 | struct pci_func *func; | ||
65 | struct event_info *taskInfo; | 51 | struct event_info *taskInfo; |
66 | 52 | ||
67 | /* Attention Button Change */ | 53 | /* Attention Button Change */ |
68 | dbg("shpchp: Attention button interrupt received.\n"); | 54 | dbg("shpchp: Attention button interrupt received.\n"); |
69 | 55 | ||
70 | func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0); | ||
71 | |||
72 | /* This is the structure that tells the worker thread what to do */ | 56 | /* This is the structure that tells the worker thread what to do */ |
73 | taskInfo = &(ctrl->event_queue[ctrl->next_event]); | 57 | taskInfo = &(ctrl->event_queue[ctrl->next_event]); |
74 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); | 58 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); |
75 | 59 | ||
76 | p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save)); | 60 | p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); |
77 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); | 61 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
78 | 62 | ||
79 | ctrl->next_event = (ctrl->next_event + 1) % 10; | 63 | ctrl->next_event = (ctrl->next_event + 1) % 10; |
@@ -118,14 +102,11 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id) | |||
118 | struct slot *p_slot; | 102 | struct slot *p_slot; |
119 | u8 rc = 0; | 103 | u8 rc = 0; |
120 | u8 getstatus; | 104 | u8 getstatus; |
121 | struct pci_func *func; | ||
122 | struct event_info *taskInfo; | 105 | struct event_info *taskInfo; |
123 | 106 | ||
124 | /* Switch Change */ | 107 | /* Switch Change */ |
125 | dbg("shpchp: Switch interrupt received.\n"); | 108 | dbg("shpchp: Switch interrupt received.\n"); |
126 | 109 | ||
127 | func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0); | ||
128 | |||
129 | /* This is the structure that tells the worker thread | 110 | /* This is the structure that tells the worker thread |
130 | * what to do | 111 | * what to do |
131 | */ | 112 | */ |
@@ -135,19 +116,18 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id) | |||
135 | 116 | ||
136 | rc++; | 117 | rc++; |
137 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); | 118 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); |
138 | p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save)); | 119 | p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); |
139 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); | 120 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
140 | dbg("%s: Card present %x Power status %x\n", __FUNCTION__, | 121 | dbg("%s: Card present %x Power status %x\n", __FUNCTION__, |
141 | func->presence_save, func->pwr_save); | 122 | p_slot->presence_save, p_slot->pwr_save); |
142 | 123 | ||
143 | if (getstatus) { | 124 | if (getstatus) { |
144 | /* | 125 | /* |
145 | * Switch opened | 126 | * Switch opened |
146 | */ | 127 | */ |
147 | info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot); | 128 | info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot); |
148 | func->switch_save = 0; | ||
149 | taskInfo->event_type = INT_SWITCH_OPEN; | 129 | taskInfo->event_type = INT_SWITCH_OPEN; |
150 | if (func->pwr_save && func->presence_save) { | 130 | if (p_slot->pwr_save && p_slot->presence_save) { |
151 | taskInfo->event_type = INT_POWER_FAULT; | 131 | taskInfo->event_type = INT_POWER_FAULT; |
152 | err("Surprise Removal of card\n"); | 132 | err("Surprise Removal of card\n"); |
153 | } | 133 | } |
@@ -156,7 +136,6 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id) | |||
156 | * Switch closed | 136 | * Switch closed |
157 | */ | 137 | */ |
158 | info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot); | 138 | info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot); |
159 | func->switch_save = 0x10; | ||
160 | taskInfo->event_type = INT_SWITCH_CLOSE; | 139 | taskInfo->event_type = INT_SWITCH_CLOSE; |
161 | } | 140 | } |
162 | 141 | ||
@@ -172,14 +151,11 @@ u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id) | |||
172 | struct slot *p_slot; | 151 | struct slot *p_slot; |
173 | u8 rc = 0; | 152 | u8 rc = 0; |
174 | /*u8 temp_byte;*/ | 153 | /*u8 temp_byte;*/ |
175 | struct pci_func *func; | ||
176 | struct event_info *taskInfo; | 154 | struct event_info *taskInfo; |
177 | 155 | ||
178 | /* Presence Change */ | 156 | /* Presence Change */ |
179 | dbg("shpchp: Presence/Notify input change.\n"); | 157 | dbg("shpchp: Presence/Notify input change.\n"); |
180 | 158 | ||
181 | func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0); | ||
182 | |||
183 | /* This is the structure that tells the worker thread | 159 | /* This is the structure that tells the worker thread |
184 | * what to do | 160 | * what to do |
185 | */ | 161 | */ |
@@ -193,8 +169,8 @@ u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id) | |||
193 | /* | 169 | /* |
194 | * Save the presence state | 170 | * Save the presence state |
195 | */ | 171 | */ |
196 | p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save)); | 172 | p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); |
197 | if (func->presence_save) { | 173 | if (p_slot->presence_save) { |
198 | /* | 174 | /* |
199 | * Card Present | 175 | * Card Present |
200 | */ | 176 | */ |
@@ -219,14 +195,11 @@ u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id) | |||
219 | struct controller *ctrl = (struct controller *) inst_id; | 195 | struct controller *ctrl = (struct controller *) inst_id; |
220 | struct slot *p_slot; | 196 | struct slot *p_slot; |
221 | u8 rc = 0; | 197 | u8 rc = 0; |
222 | struct pci_func *func; | ||
223 | struct event_info *taskInfo; | 198 | struct event_info *taskInfo; |
224 | 199 | ||
225 | /* Power fault */ | 200 | /* Power fault */ |
226 | dbg("shpchp: Power fault interrupt received.\n"); | 201 | dbg("shpchp: Power fault interrupt received.\n"); |
227 | 202 | ||
228 | func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0); | ||
229 | |||
230 | /* This is the structure that tells the worker thread | 203 | /* This is the structure that tells the worker thread |
231 | * what to do | 204 | * what to do |
232 | */ | 205 | */ |
@@ -242,7 +215,7 @@ u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id) | |||
242 | * Power fault Cleared | 215 | * Power fault Cleared |
243 | */ | 216 | */ |
244 | info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot); | 217 | info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot); |
245 | func->status = 0x00; | 218 | p_slot->status = 0x00; |
246 | taskInfo->event_type = INT_POWER_FAULT_CLEAR; | 219 | taskInfo->event_type = INT_POWER_FAULT_CLEAR; |
247 | } else { | 220 | } else { |
248 | /* | 221 | /* |
@@ -251,7 +224,7 @@ u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id) | |||
251 | info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot); | 224 | info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot); |
252 | taskInfo->event_type = INT_POWER_FAULT; | 225 | taskInfo->event_type = INT_POWER_FAULT; |
253 | /* set power fault status for this board */ | 226 | /* set power fault status for this board */ |
254 | func->status = 0xFF; | 227 | p_slot->status = 0xFF; |
255 | info("power fault bit %x set\n", hp_slot); | 228 | info("power fault bit %x set\n", hp_slot); |
256 | } | 229 | } |
257 | if (rc) | 230 | if (rc) |
@@ -260,799 +233,13 @@ u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id) | |||
260 | return rc; | 233 | return rc; |
261 | } | 234 | } |
262 | 235 | ||
263 | |||
264 | /* | ||
265 | * sort_by_size | ||
266 | * | ||
267 | * Sorts nodes on the list by their length. | ||
268 | * Smallest first. | ||
269 | * | ||
270 | */ | ||
271 | static int sort_by_size(struct pci_resource **head) | ||
272 | { | ||
273 | struct pci_resource *current_res; | ||
274 | struct pci_resource *next_res; | ||
275 | int out_of_order = 1; | ||
276 | |||
277 | if (!(*head)) | ||
278 | return(1); | ||
279 | |||
280 | if (!((*head)->next)) | ||
281 | return(0); | ||
282 | |||
283 | while (out_of_order) { | ||
284 | out_of_order = 0; | ||
285 | |||
286 | /* Special case for swapping list head */ | ||
287 | if (((*head)->next) && | ||
288 | ((*head)->length > (*head)->next->length)) { | ||
289 | out_of_order++; | ||
290 | current_res = *head; | ||
291 | *head = (*head)->next; | ||
292 | current_res->next = (*head)->next; | ||
293 | (*head)->next = current_res; | ||
294 | } | ||
295 | |||
296 | current_res = *head; | ||
297 | |||
298 | while (current_res->next && current_res->next->next) { | ||
299 | if (current_res->next->length > current_res->next->next->length) { | ||
300 | out_of_order++; | ||
301 | next_res = current_res->next; | ||
302 | current_res->next = current_res->next->next; | ||
303 | current_res = current_res->next; | ||
304 | next_res->next = current_res->next; | ||
305 | current_res->next = next_res; | ||
306 | } else | ||
307 | current_res = current_res->next; | ||
308 | } | ||
309 | } /* End of out_of_order loop */ | ||
310 | |||
311 | return(0); | ||
312 | } | ||
313 | |||
314 | |||
315 | /* | ||
316 | * sort_by_max_size | ||
317 | * | ||
318 | * Sorts nodes on the list by their length. | ||
319 | * Largest first. | ||
320 | * | ||
321 | */ | ||
322 | static int sort_by_max_size(struct pci_resource **head) | ||
323 | { | ||
324 | struct pci_resource *current_res; | ||
325 | struct pci_resource *next_res; | ||
326 | int out_of_order = 1; | ||
327 | |||
328 | if (!(*head)) | ||
329 | return(1); | ||
330 | |||
331 | if (!((*head)->next)) | ||
332 | return(0); | ||
333 | |||
334 | while (out_of_order) { | ||
335 | out_of_order = 0; | ||
336 | |||
337 | /* Special case for swapping list head */ | ||
338 | if (((*head)->next) && | ||
339 | ((*head)->length < (*head)->next->length)) { | ||
340 | out_of_order++; | ||
341 | current_res = *head; | ||
342 | *head = (*head)->next; | ||
343 | current_res->next = (*head)->next; | ||
344 | (*head)->next = current_res; | ||
345 | } | ||
346 | |||
347 | current_res = *head; | ||
348 | |||
349 | while (current_res->next && current_res->next->next) { | ||
350 | if (current_res->next->length < current_res->next->next->length) { | ||
351 | out_of_order++; | ||
352 | next_res = current_res->next; | ||
353 | current_res->next = current_res->next->next; | ||
354 | current_res = current_res->next; | ||
355 | next_res->next = current_res->next; | ||
356 | current_res->next = next_res; | ||
357 | } else | ||
358 | current_res = current_res->next; | ||
359 | } | ||
360 | } /* End of out_of_order loop */ | ||
361 | |||
362 | return(0); | ||
363 | } | ||
364 | |||
365 | |||
366 | /* | ||
367 | * do_pre_bridge_resource_split | ||
368 | * | ||
369 | * Returns zero or one node of resources that aren't in use | ||
370 | * | ||
371 | */ | ||
372 | static struct pci_resource *do_pre_bridge_resource_split (struct pci_resource **head, struct pci_resource **orig_head, u32 alignment) | ||
373 | { | ||
374 | struct pci_resource *prevnode = NULL; | ||
375 | struct pci_resource *node; | ||
376 | struct pci_resource *split_node; | ||
377 | u32 rc; | ||
378 | u32 temp_dword; | ||
379 | dbg("do_pre_bridge_resource_split\n"); | ||
380 | |||
381 | if (!(*head) || !(*orig_head)) | ||
382 | return(NULL); | ||
383 | |||
384 | rc = shpchp_resource_sort_and_combine(head); | ||
385 | |||
386 | if (rc) | ||
387 | return(NULL); | ||
388 | |||
389 | if ((*head)->base != (*orig_head)->base) | ||
390 | return(NULL); | ||
391 | |||
392 | if ((*head)->length == (*orig_head)->length) | ||
393 | return(NULL); | ||
394 | |||
395 | |||
396 | /* If we got here, there the bridge requires some of the resource, but | ||
397 | * we may be able to split some off of the front | ||
398 | */ | ||
399 | node = *head; | ||
400 | |||
401 | if (node->length & (alignment -1)) { | ||
402 | /* This one isn't an aligned length, so we'll make a new entry | ||
403 | * and split it up. | ||
404 | */ | ||
405 | split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); | ||
406 | |||
407 | if (!split_node) | ||
408 | return(NULL); | ||
409 | |||
410 | temp_dword = (node->length | (alignment-1)) + 1 - alignment; | ||
411 | |||
412 | split_node->base = node->base; | ||
413 | split_node->length = temp_dword; | ||
414 | |||
415 | node->length -= temp_dword; | ||
416 | node->base += split_node->length; | ||
417 | |||
418 | /* Put it in the list */ | ||
419 | *head = split_node; | ||
420 | split_node->next = node; | ||
421 | } | ||
422 | |||
423 | if (node->length < alignment) { | ||
424 | return(NULL); | ||
425 | } | ||
426 | |||
427 | /* Now unlink it */ | ||
428 | if (*head == node) { | ||
429 | *head = node->next; | ||
430 | node->next = NULL; | ||
431 | } else { | ||
432 | prevnode = *head; | ||
433 | while (prevnode->next != node) | ||
434 | prevnode = prevnode->next; | ||
435 | |||
436 | prevnode->next = node->next; | ||
437 | node->next = NULL; | ||
438 | } | ||
439 | |||
440 | return(node); | ||
441 | } | ||
442 | |||
443 | |||
444 | /* | ||
445 | * do_bridge_resource_split | ||
446 | * | ||
447 | * Returns zero or one node of resources that aren't in use | ||
448 | * | ||
449 | */ | ||
450 | static struct pci_resource *do_bridge_resource_split (struct pci_resource **head, u32 alignment) | ||
451 | { | ||
452 | struct pci_resource *prevnode = NULL; | ||
453 | struct pci_resource *node; | ||
454 | u32 rc; | ||
455 | u32 temp_dword; | ||
456 | |||
457 | if (!(*head)) | ||
458 | return(NULL); | ||
459 | |||
460 | rc = shpchp_resource_sort_and_combine(head); | ||
461 | |||
462 | if (rc) | ||
463 | return(NULL); | ||
464 | |||
465 | node = *head; | ||
466 | |||
467 | while (node->next) { | ||
468 | prevnode = node; | ||
469 | node = node->next; | ||
470 | kfree(prevnode); | ||
471 | } | ||
472 | |||
473 | if (node->length < alignment) { | ||
474 | kfree(node); | ||
475 | return(NULL); | ||
476 | } | ||
477 | |||
478 | if (node->base & (alignment - 1)) { | ||
479 | /* Short circuit if adjusted size is too small */ | ||
480 | temp_dword = (node->base | (alignment-1)) + 1; | ||
481 | if ((node->length - (temp_dword - node->base)) < alignment) { | ||
482 | kfree(node); | ||
483 | return(NULL); | ||
484 | } | ||
485 | |||
486 | node->length -= (temp_dword - node->base); | ||
487 | node->base = temp_dword; | ||
488 | } | ||
489 | |||
490 | if (node->length & (alignment - 1)) { | ||
491 | /* There's stuff in use after this node */ | ||
492 | kfree(node); | ||
493 | return(NULL); | ||
494 | } | ||
495 | |||
496 | return(node); | ||
497 | } | ||
498 | |||
499 | |||
500 | /* | ||
501 | * get_io_resource | ||
502 | * | ||
503 | * this function sorts the resource list by size and then | ||
504 | * returns the first node of "size" length that is not in the | ||
505 | * ISA aliasing window. If it finds a node larger than "size" | ||
506 | * it will split it up. | ||
507 | * | ||
508 | * size must be a power of two. | ||
509 | */ | ||
510 | static struct pci_resource *get_io_resource (struct pci_resource **head, u32 size) | ||
511 | { | ||
512 | struct pci_resource *prevnode; | ||
513 | struct pci_resource *node; | ||
514 | struct pci_resource *split_node = NULL; | ||
515 | u32 temp_dword; | ||
516 | |||
517 | if (!(*head)) | ||
518 | return(NULL); | ||
519 | |||
520 | if ( shpchp_resource_sort_and_combine(head) ) | ||
521 | return(NULL); | ||
522 | |||
523 | if ( sort_by_size(head) ) | ||
524 | return(NULL); | ||
525 | |||
526 | for (node = *head; node; node = node->next) { | ||
527 | if (node->length < size) | ||
528 | continue; | ||
529 | |||
530 | if (node->base & (size - 1)) { | ||
531 | /* This one isn't base aligned properly | ||
532 | so we'll make a new entry and split it up */ | ||
533 | temp_dword = (node->base | (size-1)) + 1; | ||
534 | |||
535 | /*/ Short circuit if adjusted size is too small */ | ||
536 | if ((node->length - (temp_dword - node->base)) < size) | ||
537 | continue; | ||
538 | |||
539 | split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); | ||
540 | |||
541 | if (!split_node) | ||
542 | return(NULL); | ||
543 | |||
544 | split_node->base = node->base; | ||
545 | split_node->length = temp_dword - node->base; | ||
546 | node->base = temp_dword; | ||
547 | node->length -= split_node->length; | ||
548 | |||
549 | /* Put it in the list */ | ||
550 | split_node->next = node->next; | ||
551 | node->next = split_node; | ||
552 | } /* End of non-aligned base */ | ||
553 | |||
554 | /* Don't need to check if too small since we already did */ | ||
555 | if (node->length > size) { | ||
556 | /* This one is longer than we need | ||
557 | so we'll make a new entry and split it up */ | ||
558 | split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); | ||
559 | |||
560 | if (!split_node) | ||
561 | return(NULL); | ||
562 | |||
563 | split_node->base = node->base + size; | ||
564 | split_node->length = node->length - size; | ||
565 | node->length = size; | ||
566 | |||
567 | /* Put it in the list */ | ||
568 | split_node->next = node->next; | ||
569 | node->next = split_node; | ||
570 | } /* End of too big on top end */ | ||
571 | |||
572 | /* For IO make sure it's not in the ISA aliasing space */ | ||
573 | if (node->base & 0x300L) | ||
574 | continue; | ||
575 | |||
576 | /* If we got here, then it is the right size | ||
577 | Now take it out of the list */ | ||
578 | if (*head == node) { | ||
579 | *head = node->next; | ||
580 | } else { | ||
581 | prevnode = *head; | ||
582 | while (prevnode->next != node) | ||
583 | prevnode = prevnode->next; | ||
584 | |||
585 | prevnode->next = node->next; | ||
586 | } | ||
587 | node->next = NULL; | ||
588 | /* Stop looping */ | ||
589 | break; | ||
590 | } | ||
591 | |||
592 | return(node); | ||
593 | } | ||
594 | |||
595 | |||
596 | /* | ||
597 | * get_max_resource | ||
598 | * | ||
599 | * Gets the largest node that is at least "size" big from the | ||
600 | * list pointed to by head. It aligns the node on top and bottom | ||
601 | * to "size" alignment before returning it. | ||
602 | * J.I. modified to put max size limits of; 64M->32M->16M->8M->4M->1M | ||
603 | * This is needed to avoid allocating entire ACPI _CRS res to one child bridge/slot. | ||
604 | */ | ||
605 | static struct pci_resource *get_max_resource (struct pci_resource **head, u32 size) | ||
606 | { | ||
607 | struct pci_resource *max; | ||
608 | struct pci_resource *temp; | ||
609 | struct pci_resource *split_node; | ||
610 | u32 temp_dword; | ||
611 | u32 max_size[] = { 0x4000000, 0x2000000, 0x1000000, 0x0800000, 0x0400000, 0x0200000, 0x0100000, 0x00 }; | ||
612 | int i; | ||
613 | |||
614 | if (!(*head)) | ||
615 | return(NULL); | ||
616 | |||
617 | if (shpchp_resource_sort_and_combine(head)) | ||
618 | return(NULL); | ||
619 | |||
620 | if (sort_by_max_size(head)) | ||
621 | return(NULL); | ||
622 | |||
623 | for (max = *head;max; max = max->next) { | ||
624 | |||
625 | /* If not big enough we could probably just bail, | ||
626 | instead we'll continue to the next. */ | ||
627 | if (max->length < size) | ||
628 | continue; | ||
629 | |||
630 | if (max->base & (size - 1)) { | ||
631 | /* This one isn't base aligned properly | ||
632 | so we'll make a new entry and split it up */ | ||
633 | temp_dword = (max->base | (size-1)) + 1; | ||
634 | |||
635 | /* Short circuit if adjusted size is too small */ | ||
636 | if ((max->length - (temp_dword - max->base)) < size) | ||
637 | continue; | ||
638 | |||
639 | split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); | ||
640 | |||
641 | if (!split_node) | ||
642 | return(NULL); | ||
643 | |||
644 | split_node->base = max->base; | ||
645 | split_node->length = temp_dword - max->base; | ||
646 | max->base = temp_dword; | ||
647 | max->length -= split_node->length; | ||
648 | |||
649 | /* Put it next in the list */ | ||
650 | split_node->next = max->next; | ||
651 | max->next = split_node; | ||
652 | } | ||
653 | |||
654 | if ((max->base + max->length) & (size - 1)) { | ||
655 | /* This one isn't end aligned properly at the top | ||
656 | so we'll make a new entry and split it up */ | ||
657 | split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); | ||
658 | |||
659 | if (!split_node) | ||
660 | return(NULL); | ||
661 | temp_dword = ((max->base + max->length) & ~(size - 1)); | ||
662 | split_node->base = temp_dword; | ||
663 | split_node->length = max->length + max->base | ||
664 | - split_node->base; | ||
665 | max->length -= split_node->length; | ||
666 | |||
667 | /* Put it in the list */ | ||
668 | split_node->next = max->next; | ||
669 | max->next = split_node; | ||
670 | } | ||
671 | |||
672 | /* Make sure it didn't shrink too much when we aligned it */ | ||
673 | if (max->length < size) | ||
674 | continue; | ||
675 | |||
676 | for ( i = 0; max_size[i] > size; i++) { | ||
677 | if (max->length > max_size[i]) { | ||
678 | split_node = kmalloc(sizeof(*split_node), | ||
679 | GFP_KERNEL); | ||
680 | if (!split_node) | ||
681 | break; /* return (NULL); */ | ||
682 | split_node->base = max->base + max_size[i]; | ||
683 | split_node->length = max->length - max_size[i]; | ||
684 | max->length = max_size[i]; | ||
685 | /* Put it next in the list */ | ||
686 | split_node->next = max->next; | ||
687 | max->next = split_node; | ||
688 | break; | ||
689 | } | ||
690 | } | ||
691 | |||
692 | /* Now take it out of the list */ | ||
693 | temp = (struct pci_resource*) *head; | ||
694 | if (temp == max) { | ||
695 | *head = max->next; | ||
696 | } else { | ||
697 | while (temp && temp->next != max) { | ||
698 | temp = temp->next; | ||
699 | } | ||
700 | |||
701 | temp->next = max->next; | ||
702 | } | ||
703 | |||
704 | max->next = NULL; | ||
705 | return(max); | ||
706 | } | ||
707 | |||
708 | /* If we get here, we couldn't find one */ | ||
709 | return(NULL); | ||
710 | } | ||
711 | |||
712 | |||
713 | /* | ||
714 | * get_resource | ||
715 | * | ||
716 | * this function sorts the resource list by size and then | ||
717 | * returns the first node of "size" length. If it finds a node | ||
718 | * larger than "size" it will split it up. | ||
719 | * | ||
720 | * size must be a power of two. | ||
721 | */ | ||
722 | static struct pci_resource *get_resource (struct pci_resource **head, u32 size) | ||
723 | { | ||
724 | struct pci_resource *prevnode; | ||
725 | struct pci_resource *node; | ||
726 | struct pci_resource *split_node; | ||
727 | u32 temp_dword; | ||
728 | |||
729 | if (!(*head)) | ||
730 | return(NULL); | ||
731 | |||
732 | if ( shpchp_resource_sort_and_combine(head) ) | ||
733 | return(NULL); | ||
734 | |||
735 | if ( sort_by_size(head) ) | ||
736 | return(NULL); | ||
737 | |||
738 | for (node = *head; node; node = node->next) { | ||
739 | dbg("%s: req_size =0x%x node=%p, base=0x%x, length=0x%x\n", | ||
740 | __FUNCTION__, size, node, node->base, node->length); | ||
741 | if (node->length < size) | ||
742 | continue; | ||
743 | |||
744 | if (node->base & (size - 1)) { | ||
745 | dbg("%s: not aligned\n", __FUNCTION__); | ||
746 | /* this one isn't base aligned properly | ||
747 | so we'll make a new entry and split it up */ | ||
748 | temp_dword = (node->base | (size-1)) + 1; | ||
749 | |||
750 | /* Short circuit if adjusted size is too small */ | ||
751 | if ((node->length - (temp_dword - node->base)) < size) | ||
752 | continue; | ||
753 | |||
754 | split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); | ||
755 | |||
756 | if (!split_node) | ||
757 | return(NULL); | ||
758 | |||
759 | split_node->base = node->base; | ||
760 | split_node->length = temp_dword - node->base; | ||
761 | node->base = temp_dword; | ||
762 | node->length -= split_node->length; | ||
763 | |||
764 | /* Put it in the list */ | ||
765 | split_node->next = node->next; | ||
766 | node->next = split_node; | ||
767 | } /* End of non-aligned base */ | ||
768 | |||
769 | /* Don't need to check if too small since we already did */ | ||
770 | if (node->length > size) { | ||
771 | dbg("%s: too big\n", __FUNCTION__); | ||
772 | /* this one is longer than we need | ||
773 | so we'll make a new entry and split it up */ | ||
774 | split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); | ||
775 | |||
776 | if (!split_node) | ||
777 | return(NULL); | ||
778 | |||
779 | split_node->base = node->base + size; | ||
780 | split_node->length = node->length - size; | ||
781 | node->length = size; | ||
782 | |||
783 | /* Put it in the list */ | ||
784 | split_node->next = node->next; | ||
785 | node->next = split_node; | ||
786 | } /* End of too big on top end */ | ||
787 | |||
788 | dbg("%s: got one!!!\n", __FUNCTION__); | ||
789 | /* If we got here, then it is the right size | ||
790 | Now take it out of the list */ | ||
791 | if (*head == node) { | ||
792 | *head = node->next; | ||
793 | } else { | ||
794 | prevnode = *head; | ||
795 | while (prevnode->next != node) | ||
796 | prevnode = prevnode->next; | ||
797 | |||
798 | prevnode->next = node->next; | ||
799 | } | ||
800 | node->next = NULL; | ||
801 | /* Stop looping */ | ||
802 | break; | ||
803 | } | ||
804 | return(node); | ||
805 | } | ||
806 | |||
807 | |||
808 | /* | ||
809 | * shpchp_resource_sort_and_combine | ||
810 | * | ||
811 | * Sorts all of the nodes in the list in ascending order by | ||
812 | * their base addresses. Also does garbage collection by | ||
813 | * combining adjacent nodes. | ||
814 | * | ||
815 | * returns 0 if success | ||
816 | */ | ||
817 | int shpchp_resource_sort_and_combine(struct pci_resource **head) | ||
818 | { | ||
819 | struct pci_resource *node1; | ||
820 | struct pci_resource *node2; | ||
821 | int out_of_order = 1; | ||
822 | |||
823 | dbg("%s: head = %p, *head = %p\n", __FUNCTION__, head, *head); | ||
824 | |||
825 | if (!(*head)) | ||
826 | return(1); | ||
827 | |||
828 | dbg("*head->next = %p\n",(*head)->next); | ||
829 | |||
830 | if (!(*head)->next) | ||
831 | return(0); /* only one item on the list, already sorted! */ | ||
832 | |||
833 | dbg("*head->base = 0x%x\n",(*head)->base); | ||
834 | dbg("*head->next->base = 0x%x\n",(*head)->next->base); | ||
835 | while (out_of_order) { | ||
836 | out_of_order = 0; | ||
837 | |||
838 | /* Special case for swapping list head */ | ||
839 | if (((*head)->next) && | ||
840 | ((*head)->base > (*head)->next->base)) { | ||
841 | node1 = *head; | ||
842 | (*head) = (*head)->next; | ||
843 | node1->next = (*head)->next; | ||
844 | (*head)->next = node1; | ||
845 | out_of_order++; | ||
846 | } | ||
847 | |||
848 | node1 = (*head); | ||
849 | |||
850 | while (node1->next && node1->next->next) { | ||
851 | if (node1->next->base > node1->next->next->base) { | ||
852 | out_of_order++; | ||
853 | node2 = node1->next; | ||
854 | node1->next = node1->next->next; | ||
855 | node1 = node1->next; | ||
856 | node2->next = node1->next; | ||
857 | node1->next = node2; | ||
858 | } else | ||
859 | node1 = node1->next; | ||
860 | } | ||
861 | } /* End of out_of_order loop */ | ||
862 | |||
863 | node1 = *head; | ||
864 | |||
865 | while (node1 && node1->next) { | ||
866 | if ((node1->base + node1->length) == node1->next->base) { | ||
867 | /* Combine */ | ||
868 | dbg("8..\n"); | ||
869 | node1->length += node1->next->length; | ||
870 | node2 = node1->next; | ||
871 | node1->next = node1->next->next; | ||
872 | kfree(node2); | ||
873 | } else | ||
874 | node1 = node1->next; | ||
875 | } | ||
876 | |||
877 | return(0); | ||
878 | } | ||
879 | |||
880 | |||
881 | /** | ||
882 | * shpchp_slot_create - Creates a node and adds it to the proper bus. | ||
883 | * @busnumber - bus where new node is to be located | ||
884 | * | ||
885 | * Returns pointer to the new node or NULL if unsuccessful | ||
886 | */ | ||
887 | struct pci_func *shpchp_slot_create(u8 busnumber) | ||
888 | { | ||
889 | struct pci_func *new_slot; | ||
890 | struct pci_func *next; | ||
891 | |||
892 | new_slot = kmalloc(sizeof(*new_slot), GFP_KERNEL); | ||
893 | |||
894 | if (new_slot == NULL) { | ||
895 | return(new_slot); | ||
896 | } | ||
897 | |||
898 | memset(new_slot, 0, sizeof(struct pci_func)); | ||
899 | |||
900 | new_slot->next = NULL; | ||
901 | new_slot->configured = 1; | ||
902 | |||
903 | if (shpchp_slot_list[busnumber] == NULL) { | ||
904 | shpchp_slot_list[busnumber] = new_slot; | ||
905 | } else { | ||
906 | next = shpchp_slot_list[busnumber]; | ||
907 | while (next->next != NULL) | ||
908 | next = next->next; | ||
909 | next->next = new_slot; | ||
910 | } | ||
911 | return(new_slot); | ||
912 | } | ||
913 | |||
914 | |||
915 | /* | ||
916 | * slot_remove - Removes a node from the linked list of slots. | ||
917 | * @old_slot: slot to remove | ||
918 | * | ||
919 | * Returns 0 if successful, !0 otherwise. | ||
920 | */ | ||
921 | static int slot_remove(struct pci_func * old_slot) | ||
922 | { | ||
923 | struct pci_func *next; | ||
924 | |||
925 | if (old_slot == NULL) | ||
926 | return(1); | ||
927 | |||
928 | next = shpchp_slot_list[old_slot->bus]; | ||
929 | |||
930 | if (next == NULL) { | ||
931 | return(1); | ||
932 | } | ||
933 | |||
934 | if (next == old_slot) { | ||
935 | shpchp_slot_list[old_slot->bus] = old_slot->next; | ||
936 | shpchp_destroy_board_resources(old_slot); | ||
937 | kfree(old_slot); | ||
938 | return(0); | ||
939 | } | ||
940 | |||
941 | while ((next->next != old_slot) && (next->next != NULL)) { | ||
942 | next = next->next; | ||
943 | } | ||
944 | |||
945 | if (next->next == old_slot) { | ||
946 | next->next = old_slot->next; | ||
947 | shpchp_destroy_board_resources(old_slot); | ||
948 | kfree(old_slot); | ||
949 | return(0); | ||
950 | } else | ||
951 | return(2); | ||
952 | } | ||
953 | |||
954 | |||
955 | /** | ||
956 | * bridge_slot_remove - Removes a node from the linked list of slots. | ||
957 | * @bridge: bridge to remove | ||
958 | * | ||
959 | * Returns 0 if successful, !0 otherwise. | ||
960 | */ | ||
961 | static int bridge_slot_remove(struct pci_func *bridge) | ||
962 | { | ||
963 | u8 subordinateBus, secondaryBus; | ||
964 | u8 tempBus; | ||
965 | struct pci_func *next; | ||
966 | |||
967 | if (bridge == NULL) | ||
968 | return(1); | ||
969 | |||
970 | secondaryBus = (bridge->config_space[0x06] >> 8) & 0xFF; | ||
971 | subordinateBus = (bridge->config_space[0x06] >> 16) & 0xFF; | ||
972 | |||
973 | for (tempBus = secondaryBus; tempBus <= subordinateBus; tempBus++) { | ||
974 | next = shpchp_slot_list[tempBus]; | ||
975 | |||
976 | while (!slot_remove(next)) { | ||
977 | next = shpchp_slot_list[tempBus]; | ||
978 | } | ||
979 | } | ||
980 | |||
981 | next = shpchp_slot_list[bridge->bus]; | ||
982 | |||
983 | if (next == NULL) { | ||
984 | return(1); | ||
985 | } | ||
986 | |||
987 | if (next == bridge) { | ||
988 | shpchp_slot_list[bridge->bus] = bridge->next; | ||
989 | kfree(bridge); | ||
990 | return(0); | ||
991 | } | ||
992 | |||
993 | while ((next->next != bridge) && (next->next != NULL)) { | ||
994 | next = next->next; | ||
995 | } | ||
996 | |||
997 | if (next->next == bridge) { | ||
998 | next->next = bridge->next; | ||
999 | kfree(bridge); | ||
1000 | return(0); | ||
1001 | } else | ||
1002 | return(2); | ||
1003 | } | ||
1004 | |||
1005 | |||
1006 | /** | ||
1007 | * shpchp_slot_find - Looks for a node by bus, and device, multiple functions accessed | ||
1008 | * @bus: bus to find | ||
1009 | * @device: device to find | ||
1010 | * @index: is 0 for first function found, 1 for the second... | ||
1011 | * | ||
1012 | * Returns pointer to the node if successful, %NULL otherwise. | ||
1013 | */ | ||
1014 | struct pci_func *shpchp_slot_find(u8 bus, u8 device, u8 index) | ||
1015 | { | ||
1016 | int found = -1; | ||
1017 | struct pci_func *func; | ||
1018 | |||
1019 | func = shpchp_slot_list[bus]; | ||
1020 | |||
1021 | if ((func == NULL) || ((func->device == device) && (index == 0))) | ||
1022 | return(func); | ||
1023 | |||
1024 | if (func->device == device) | ||
1025 | found++; | ||
1026 | |||
1027 | while (func->next != NULL) { | ||
1028 | func = func->next; | ||
1029 | |||
1030 | if (func->device == device) | ||
1031 | found++; | ||
1032 | |||
1033 | if (found == index) | ||
1034 | return(func); | ||
1035 | } | ||
1036 | |||
1037 | return(NULL); | ||
1038 | } | ||
1039 | |||
1040 | static int is_bridge(struct pci_func * func) | ||
1041 | { | ||
1042 | /* Check the header type */ | ||
1043 | if (((func->config_space[0x03] >> 16) & 0xFF) == 0x01) | ||
1044 | return 1; | ||
1045 | else | ||
1046 | return 0; | ||
1047 | } | ||
1048 | |||
1049 | |||
1050 | /* The following routines constitute the bulk of the | 236 | /* The following routines constitute the bulk of the |
1051 | hotplug controller logic | 237 | hotplug controller logic |
1052 | */ | 238 | */ |
1053 | static u32 change_bus_speed(struct controller *ctrl, struct slot *p_slot, enum pci_bus_speed speed) | 239 | static int change_bus_speed(struct controller *ctrl, struct slot *p_slot, |
240 | enum pci_bus_speed speed) | ||
1054 | { | 241 | { |
1055 | u32 rc = 0; | 242 | int rc = 0; |
1056 | 243 | ||
1057 | dbg("%s: change to speed %d\n", __FUNCTION__, speed); | 244 | dbg("%s: change to speed %d\n", __FUNCTION__, speed); |
1058 | down(&ctrl->crit_sect); | 245 | down(&ctrl->crit_sect); |
@@ -1074,10 +261,11 @@ static u32 change_bus_speed(struct controller *ctrl, struct slot *p_slot, enum p | |||
1074 | return rc; | 261 | return rc; |
1075 | } | 262 | } |
1076 | 263 | ||
1077 | static u32 fix_bus_speed(struct controller *ctrl, struct slot *pslot, u8 flag, | 264 | static int fix_bus_speed(struct controller *ctrl, struct slot *pslot, |
1078 | enum pci_bus_speed asp, enum pci_bus_speed bsp, enum pci_bus_speed msp) | 265 | u8 flag, enum pci_bus_speed asp, enum pci_bus_speed bsp, |
266 | enum pci_bus_speed msp) | ||
1079 | { | 267 | { |
1080 | u32 rc = 0; | 268 | int rc = 0; |
1081 | 269 | ||
1082 | if (flag != 0) { /* Other slots on the same bus are occupied */ | 270 | if (flag != 0) { /* Other slots on the same bus are occupied */ |
1083 | if ( asp < bsp ) { | 271 | if ( asp < bsp ) { |
@@ -1116,23 +304,20 @@ enum pci_bus_speed asp, enum pci_bus_speed bsp, enum pci_bus_speed msp) | |||
1116 | * Configures board | 304 | * Configures board |
1117 | * | 305 | * |
1118 | */ | 306 | */ |
1119 | static u32 board_added(struct pci_func * func, struct controller * ctrl) | 307 | static int board_added(struct slot *p_slot) |
1120 | { | 308 | { |
1121 | u8 hp_slot; | 309 | u8 hp_slot; |
1122 | u8 slots_not_empty = 0; | 310 | u8 slots_not_empty = 0; |
1123 | int index; | 311 | int rc = 0; |
1124 | u32 temp_register = 0xFFFFFFFF; | ||
1125 | u32 retval, rc = 0; | ||
1126 | struct pci_func *new_func = NULL; | ||
1127 | struct slot *p_slot; | ||
1128 | struct resource_lists res_lists; | ||
1129 | enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed; | 312 | enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed; |
1130 | u8 pi, mode; | 313 | u8 pi, mode; |
314 | struct controller *ctrl = p_slot->ctrl; | ||
1131 | 315 | ||
1132 | p_slot = shpchp_find_slot(ctrl, func->device); | 316 | hp_slot = p_slot->device - ctrl->slot_device_offset; |
1133 | hp_slot = func->device - ctrl->slot_device_offset; | ||
1134 | 317 | ||
1135 | dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n", __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot); | 318 | dbg("%s: p_slot->device, slot_offset, hp_slot = %d, %d ,%d\n", |
319 | __FUNCTION__, p_slot->device, | ||
320 | ctrl->slot_device_offset, hp_slot); | ||
1136 | 321 | ||
1137 | /* Wait for exclusive access to hardware */ | 322 | /* Wait for exclusive access to hardware */ |
1138 | down(&ctrl->crit_sect); | 323 | down(&ctrl->crit_sect); |
@@ -1320,143 +505,68 @@ static u32 board_added(struct pci_func * func, struct controller * ctrl) | |||
1320 | up(&ctrl->crit_sect); | 505 | up(&ctrl->crit_sect); |
1321 | 506 | ||
1322 | /* Wait for ~1 second */ | 507 | /* Wait for ~1 second */ |
1323 | dbg("%s: before long_delay\n", __FUNCTION__); | ||
1324 | wait_for_ctrl_irq (ctrl); | 508 | wait_for_ctrl_irq (ctrl); |
1325 | dbg("%s: after long_delay\n", __FUNCTION__); | ||
1326 | 509 | ||
1327 | dbg("%s: func status = %x\n", __FUNCTION__, func->status); | 510 | dbg("%s: slot status = %x\n", __FUNCTION__, p_slot->status); |
1328 | /* Check for a power fault */ | 511 | /* Check for a power fault */ |
1329 | if (func->status == 0xFF) { | 512 | if (p_slot->status == 0xFF) { |
1330 | /* power fault occurred, but it was benign */ | 513 | /* power fault occurred, but it was benign */ |
1331 | temp_register = 0xFFFFFFFF; | 514 | dbg("%s: power fault\n", __FUNCTION__); |
1332 | dbg("%s: temp register set to %x by power fault\n", __FUNCTION__, temp_register); | ||
1333 | rc = POWER_FAILURE; | 515 | rc = POWER_FAILURE; |
1334 | func->status = 0; | 516 | p_slot->status = 0; |
1335 | } else { | 517 | goto err_exit; |
1336 | /* Get vendor/device ID u32 */ | ||
1337 | rc = pci_bus_read_config_dword (ctrl->pci_dev->subordinate, PCI_DEVFN(func->device, func->function), | ||
1338 | PCI_VENDOR_ID, &temp_register); | ||
1339 | dbg("%s: pci_bus_read_config_dword returns %d\n", __FUNCTION__, rc); | ||
1340 | dbg("%s: temp_register is %x\n", __FUNCTION__, temp_register); | ||
1341 | |||
1342 | if (rc != 0) { | ||
1343 | /* Something's wrong here */ | ||
1344 | temp_register = 0xFFFFFFFF; | ||
1345 | dbg("%s: temp register set to %x by error\n", __FUNCTION__, temp_register); | ||
1346 | } | ||
1347 | /* Preset return code. It will be changed later if things go okay. */ | ||
1348 | rc = NO_ADAPTER_PRESENT; | ||
1349 | } | 518 | } |
1350 | 519 | ||
1351 | /* All F's is an empty slot or an invalid board */ | 520 | if (shpchp_configure_device(p_slot)) { |
1352 | if (temp_register != 0xFFFFFFFF) { /* Check for a board in the slot */ | 521 | err("Cannot add device at 0x%x:0x%x\n", p_slot->bus, |
1353 | res_lists.io_head = ctrl->io_head; | 522 | p_slot->device); |
1354 | res_lists.mem_head = ctrl->mem_head; | 523 | goto err_exit; |
1355 | res_lists.p_mem_head = ctrl->p_mem_head; | 524 | } |
1356 | res_lists.bus_head = ctrl->bus_head; | ||
1357 | res_lists.irqs = NULL; | ||
1358 | |||
1359 | rc = configure_new_device(ctrl, func, 0, &res_lists, 0, 0); | ||
1360 | dbg("%s: back from configure_new_device\n", __FUNCTION__); | ||
1361 | |||
1362 | ctrl->io_head = res_lists.io_head; | ||
1363 | ctrl->mem_head = res_lists.mem_head; | ||
1364 | ctrl->p_mem_head = res_lists.p_mem_head; | ||
1365 | ctrl->bus_head = res_lists.bus_head; | ||
1366 | |||
1367 | shpchp_resource_sort_and_combine(&(ctrl->mem_head)); | ||
1368 | shpchp_resource_sort_and_combine(&(ctrl->p_mem_head)); | ||
1369 | shpchp_resource_sort_and_combine(&(ctrl->io_head)); | ||
1370 | shpchp_resource_sort_and_combine(&(ctrl->bus_head)); | ||
1371 | |||
1372 | if (rc) { | ||
1373 | /* Wait for exclusive access to hardware */ | ||
1374 | down(&ctrl->crit_sect); | ||
1375 | |||
1376 | /* turn off slot, turn on Amber LED, turn off Green LED */ | ||
1377 | retval = p_slot->hpc_ops->slot_disable(p_slot); | ||
1378 | if (retval) { | ||
1379 | err("%s: Issue of Slot Enable command failed\n", __FUNCTION__); | ||
1380 | /* Done with exclusive hardware access */ | ||
1381 | up(&ctrl->crit_sect); | ||
1382 | return retval; | ||
1383 | } | ||
1384 | /* Wait for the command to complete */ | ||
1385 | wait_for_ctrl_irq (ctrl); | ||
1386 | |||
1387 | retval = p_slot->hpc_ops->check_cmd_status(ctrl); | ||
1388 | if (retval) { | ||
1389 | err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, retval); | ||
1390 | /* Done with exclusive hardware access */ | ||
1391 | up(&ctrl->crit_sect); | ||
1392 | return retval; | ||
1393 | } | ||
1394 | |||
1395 | /* Done with exclusive hardware access */ | ||
1396 | up(&ctrl->crit_sect); | ||
1397 | 525 | ||
1398 | return(rc); | 526 | p_slot->status = 0; |
1399 | } | 527 | p_slot->is_a_board = 0x01; |
1400 | shpchp_save_slot_config(ctrl, func); | 528 | p_slot->pwr_save = 1; |
1401 | 529 | ||
1402 | func->status = 0; | 530 | /* Wait for exclusive access to hardware */ |
1403 | func->switch_save = 0x10; | 531 | down(&ctrl->crit_sect); |
1404 | func->is_a_board = 0x01; | ||
1405 | func->pwr_save = 1; | ||
1406 | 532 | ||
1407 | /* Next, we will instantiate the linux pci_dev structures | 533 | p_slot->hpc_ops->green_led_on(p_slot); |
1408 | * (with appropriate driver notification, if already present) | ||
1409 | */ | ||
1410 | index = 0; | ||
1411 | do { | ||
1412 | new_func = shpchp_slot_find(ctrl->slot_bus, func->device, index++); | ||
1413 | if (new_func && !new_func->pci_dev) { | ||
1414 | dbg("%s:call pci_hp_configure_dev\n", __FUNCTION__); | ||
1415 | shpchp_configure_device(ctrl, new_func); | ||
1416 | } | ||
1417 | } while (new_func); | ||
1418 | 534 | ||
1419 | /* Wait for exclusive access to hardware */ | 535 | /* Wait for the command to complete */ |
1420 | down(&ctrl->crit_sect); | 536 | wait_for_ctrl_irq (ctrl); |
1421 | 537 | ||
1422 | p_slot->hpc_ops->green_led_on(p_slot); | 538 | /* Done with exclusive hardware access */ |
539 | up(&ctrl->crit_sect); | ||
1423 | 540 | ||
1424 | /* Wait for the command to complete */ | 541 | return 0; |
1425 | wait_for_ctrl_irq (ctrl); | ||
1426 | 542 | ||
543 | err_exit: | ||
544 | /* Wait for exclusive access to hardware */ | ||
545 | down(&ctrl->crit_sect); | ||
1427 | 546 | ||
547 | /* turn off slot, turn on Amber LED, turn off Green LED */ | ||
548 | rc = p_slot->hpc_ops->slot_disable(p_slot); | ||
549 | if (rc) { | ||
550 | err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); | ||
1428 | /* Done with exclusive hardware access */ | 551 | /* Done with exclusive hardware access */ |
1429 | up(&ctrl->crit_sect); | 552 | up(&ctrl->crit_sect); |
553 | return rc; | ||
554 | } | ||
555 | /* Wait for the command to complete */ | ||
556 | wait_for_ctrl_irq (ctrl); | ||
1430 | 557 | ||
1431 | } else { | 558 | rc = p_slot->hpc_ops->check_cmd_status(ctrl); |
1432 | /* Wait for exclusive access to hardware */ | 559 | if (rc) { |
1433 | down(&ctrl->crit_sect); | 560 | err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc); |
1434 | |||
1435 | /* turn off slot, turn on Amber LED, turn off Green LED */ | ||
1436 | rc = p_slot->hpc_ops->slot_disable(p_slot); | ||
1437 | if (rc) { | ||
1438 | err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); | ||
1439 | /* Done with exclusive hardware access */ | ||
1440 | up(&ctrl->crit_sect); | ||
1441 | return rc; | ||
1442 | } | ||
1443 | /* Wait for the command to complete */ | ||
1444 | wait_for_ctrl_irq (ctrl); | ||
1445 | |||
1446 | rc = p_slot->hpc_ops->check_cmd_status(ctrl); | ||
1447 | if (rc) { | ||
1448 | err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc); | ||
1449 | /* Done with exclusive hardware access */ | ||
1450 | up(&ctrl->crit_sect); | ||
1451 | return rc; | ||
1452 | } | ||
1453 | |||
1454 | /* Done with exclusive hardware access */ | 561 | /* Done with exclusive hardware access */ |
1455 | up(&ctrl->crit_sect); | 562 | up(&ctrl->crit_sect); |
1456 | 563 | return rc; | |
1457 | return(rc); | ||
1458 | } | 564 | } |
1459 | return 0; | 565 | |
566 | /* Done with exclusive hardware access */ | ||
567 | up(&ctrl->crit_sect); | ||
568 | |||
569 | return(rc); | ||
1460 | } | 570 | } |
1461 | 571 | ||
1462 | 572 | ||
@@ -1464,55 +574,23 @@ static u32 board_added(struct pci_func * func, struct controller * ctrl) | |||
1464 | * remove_board - Turns off slot and LED's | 574 | * remove_board - Turns off slot and LED's |
1465 | * | 575 | * |
1466 | */ | 576 | */ |
1467 | static u32 remove_board(struct pci_func *func, struct controller *ctrl) | 577 | static int remove_board(struct slot *p_slot) |
1468 | { | 578 | { |
1469 | int index; | 579 | struct controller *ctrl = p_slot->ctrl; |
1470 | u8 skip = 0; | ||
1471 | u8 device; | ||
1472 | u8 hp_slot; | 580 | u8 hp_slot; |
1473 | u32 rc; | 581 | int rc; |
1474 | struct resource_lists res_lists; | ||
1475 | struct pci_func *temp_func; | ||
1476 | struct slot *p_slot; | ||
1477 | |||
1478 | if (func == NULL) | ||
1479 | return(1); | ||
1480 | 582 | ||
1481 | if (shpchp_unconfigure_device(func)) | 583 | if (shpchp_unconfigure_device(p_slot)) |
1482 | return(1); | 584 | return(1); |
1483 | 585 | ||
1484 | device = func->device; | 586 | hp_slot = p_slot->device - ctrl->slot_device_offset; |
1485 | |||
1486 | hp_slot = func->device - ctrl->slot_device_offset; | ||
1487 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); | 587 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); |
1488 | 588 | ||
1489 | dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot); | 589 | dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot); |
1490 | 590 | ||
1491 | if ((ctrl->add_support) && | ||
1492 | !(func->bus_head || func->mem_head || func->p_mem_head || func->io_head)) { | ||
1493 | /* Here we check to see if we've saved any of the board's | ||
1494 | * resources already. If so, we'll skip the attempt to | ||
1495 | * determine what's being used. | ||
1496 | */ | ||
1497 | index = 0; | ||
1498 | |||
1499 | temp_func = func; | ||
1500 | |||
1501 | while ((temp_func = shpchp_slot_find(temp_func->bus, temp_func->device, index++))) { | ||
1502 | if (temp_func->bus_head || temp_func->mem_head | ||
1503 | || temp_func->p_mem_head || temp_func->io_head) { | ||
1504 | skip = 1; | ||
1505 | break; | ||
1506 | } | ||
1507 | } | ||
1508 | |||
1509 | if (!skip) | ||
1510 | rc = shpchp_save_used_resources(ctrl, func, DISABLE_CARD); | ||
1511 | } | ||
1512 | /* Change status to shutdown */ | 591 | /* Change status to shutdown */ |
1513 | if (func->is_a_board) | 592 | if (p_slot->is_a_board) |
1514 | func->status = 0x01; | 593 | p_slot->status = 0x01; |
1515 | func->configured = 0; | ||
1516 | 594 | ||
1517 | /* Wait for exclusive access to hardware */ | 595 | /* Wait for exclusive access to hardware */ |
1518 | down(&ctrl->crit_sect); | 596 | down(&ctrl->crit_sect); |
@@ -1549,55 +627,8 @@ static u32 remove_board(struct pci_func *func, struct controller *ctrl) | |||
1549 | /* Done with exclusive hardware access */ | 627 | /* Done with exclusive hardware access */ |
1550 | up(&ctrl->crit_sect); | 628 | up(&ctrl->crit_sect); |
1551 | 629 | ||
1552 | if (ctrl->add_support) { | 630 | p_slot->pwr_save = 0; |
1553 | while (func) { | 631 | p_slot->is_a_board = 0; |
1554 | res_lists.io_head = ctrl->io_head; | ||
1555 | res_lists.mem_head = ctrl->mem_head; | ||
1556 | res_lists.p_mem_head = ctrl->p_mem_head; | ||
1557 | res_lists.bus_head = ctrl->bus_head; | ||
1558 | |||
1559 | dbg("Returning resources to ctlr lists for (B/D/F) = (%#x/%#x/%#x)\n", func->bus, | ||
1560 | func->device, func->function); | ||
1561 | |||
1562 | shpchp_return_board_resources(func, &res_lists); | ||
1563 | |||
1564 | ctrl->io_head = res_lists.io_head; | ||
1565 | ctrl->mem_head = res_lists.mem_head; | ||
1566 | ctrl->p_mem_head = res_lists.p_mem_head; | ||
1567 | ctrl->bus_head = res_lists.bus_head; | ||
1568 | |||
1569 | shpchp_resource_sort_and_combine(&(ctrl->mem_head)); | ||
1570 | shpchp_resource_sort_and_combine(&(ctrl->p_mem_head)); | ||
1571 | shpchp_resource_sort_and_combine(&(ctrl->io_head)); | ||
1572 | shpchp_resource_sort_and_combine(&(ctrl->bus_head)); | ||
1573 | |||
1574 | if (is_bridge(func)) { | ||
1575 | dbg("PCI Bridge Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, | ||
1576 | func->device, func->function); | ||
1577 | bridge_slot_remove(func); | ||
1578 | } else | ||
1579 | dbg("PCI Function Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, | ||
1580 | func->device, func->function); | ||
1581 | slot_remove(func); | ||
1582 | |||
1583 | func = shpchp_slot_find(ctrl->slot_bus, device, 0); | ||
1584 | } | ||
1585 | |||
1586 | /* Setup slot structure with entry for empty slot */ | ||
1587 | func = shpchp_slot_create(ctrl->slot_bus); | ||
1588 | |||
1589 | if (func == NULL) { | ||
1590 | return(1); | ||
1591 | } | ||
1592 | |||
1593 | func->bus = ctrl->slot_bus; | ||
1594 | func->device = device; | ||
1595 | func->function = 0; | ||
1596 | func->configured = 0; | ||
1597 | func->switch_save = 0x10; | ||
1598 | func->pwr_save = 0; | ||
1599 | func->is_a_board = 0; | ||
1600 | } | ||
1601 | 632 | ||
1602 | return 0; | 633 | return 0; |
1603 | } | 634 | } |
@@ -1633,13 +664,11 @@ static void shpchp_pushbutton_thread (unsigned long slot) | |||
1633 | p_slot->hpc_ops->get_power_status(p_slot, &getstatus); | 664 | p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
1634 | if (getstatus) { | 665 | if (getstatus) { |
1635 | p_slot->state = POWEROFF_STATE; | 666 | p_slot->state = POWEROFF_STATE; |
1636 | dbg("In power_down_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device); | ||
1637 | 667 | ||
1638 | shpchp_disable_slot(p_slot); | 668 | shpchp_disable_slot(p_slot); |
1639 | p_slot->state = STATIC_STATE; | 669 | p_slot->state = STATIC_STATE; |
1640 | } else { | 670 | } else { |
1641 | p_slot->state = POWERON_STATE; | 671 | p_slot->state = POWERON_STATE; |
1642 | dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device); | ||
1643 | 672 | ||
1644 | if (shpchp_enable_slot(p_slot)) { | 673 | if (shpchp_enable_slot(p_slot)) { |
1645 | /* Wait for exclusive access to hardware */ | 674 | /* Wait for exclusive access to hardware */ |
@@ -1701,7 +730,6 @@ int shpchp_event_start_thread (void) | |||
1701 | err ("Can't start up our event thread\n"); | 730 | err ("Can't start up our event thread\n"); |
1702 | return -1; | 731 | return -1; |
1703 | } | 732 | } |
1704 | dbg("Our event thread pid = %d\n", pid); | ||
1705 | return 0; | 733 | return 0; |
1706 | } | 734 | } |
1707 | 735 | ||
@@ -1709,9 +737,7 @@ int shpchp_event_start_thread (void) | |||
1709 | void shpchp_event_stop_thread (void) | 737 | void shpchp_event_stop_thread (void) |
1710 | { | 738 | { |
1711 | event_finished = 1; | 739 | event_finished = 1; |
1712 | dbg("event_thread finish command given\n"); | ||
1713 | up(&event_semaphore); | 740 | up(&event_semaphore); |
1714 | dbg("wait for event_thread to exit\n"); | ||
1715 | down(&event_exit); | 741 | down(&event_exit); |
1716 | } | 742 | } |
1717 | 743 | ||
@@ -1739,12 +765,10 @@ static void interrupt_event_handler(struct controller *ctrl) | |||
1739 | { | 765 | { |
1740 | int loop = 0; | 766 | int loop = 0; |
1741 | int change = 1; | 767 | int change = 1; |
1742 | struct pci_func *func; | ||
1743 | u8 hp_slot; | 768 | u8 hp_slot; |
1744 | u8 getstatus; | 769 | u8 getstatus; |
1745 | struct slot *p_slot; | 770 | struct slot *p_slot; |
1746 | 771 | ||
1747 | dbg("%s:\n", __FUNCTION__); | ||
1748 | while (change) { | 772 | while (change) { |
1749 | change = 0; | 773 | change = 0; |
1750 | 774 | ||
@@ -1754,12 +778,8 @@ static void interrupt_event_handler(struct controller *ctrl) | |||
1754 | ctrl->event_queue[loop].event_type); | 778 | ctrl->event_queue[loop].event_type); |
1755 | hp_slot = ctrl->event_queue[loop].hp_slot; | 779 | hp_slot = ctrl->event_queue[loop].hp_slot; |
1756 | 780 | ||
1757 | func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0); | ||
1758 | |||
1759 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); | 781 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); |
1760 | 782 | ||
1761 | dbg("%s: hp_slot %d, func %p, p_slot %p\n", __FUNCTION__, hp_slot, func, p_slot); | ||
1762 | |||
1763 | if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) { | 783 | if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) { |
1764 | dbg("%s: button cancel\n", __FUNCTION__); | 784 | dbg("%s: button cancel\n", __FUNCTION__); |
1765 | del_timer(&p_slot->task_event); | 785 | del_timer(&p_slot->task_event); |
@@ -1880,13 +900,6 @@ int shpchp_enable_slot (struct slot *p_slot) | |||
1880 | { | 900 | { |
1881 | u8 getstatus = 0; | 901 | u8 getstatus = 0; |
1882 | int rc; | 902 | int rc; |
1883 | struct pci_func *func; | ||
1884 | |||
1885 | func = shpchp_slot_find(p_slot->bus, p_slot->device, 0); | ||
1886 | if (!func) { | ||
1887 | dbg("%s: Error! slot NULL\n", __FUNCTION__); | ||
1888 | return -ENODEV; | ||
1889 | } | ||
1890 | 903 | ||
1891 | /* Check to see if (latch closed, card present, power off) */ | 904 | /* Check to see if (latch closed, card present, power off) */ |
1892 | down(&p_slot->ctrl->crit_sect); | 905 | down(&p_slot->ctrl->crit_sect); |
@@ -1910,72 +923,34 @@ int shpchp_enable_slot (struct slot *p_slot) | |||
1910 | } | 923 | } |
1911 | up(&p_slot->ctrl->crit_sect); | 924 | up(&p_slot->ctrl->crit_sect); |
1912 | 925 | ||
1913 | slot_remove(func); | 926 | p_slot->is_a_board = 1; |
1914 | |||
1915 | func = shpchp_slot_create(p_slot->bus); | ||
1916 | if (func == NULL) | ||
1917 | return -ENOMEM; | ||
1918 | |||
1919 | func->bus = p_slot->bus; | ||
1920 | func->device = p_slot->device; | ||
1921 | func->function = 0; | ||
1922 | func->configured = 0; | ||
1923 | func->is_a_board = 1; | ||
1924 | 927 | ||
1925 | /* We have to save the presence info for these slots */ | 928 | /* We have to save the presence info for these slots */ |
1926 | p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save)); | 929 | p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); |
1927 | p_slot->hpc_ops->get_power_status(p_slot, &(func->pwr_save)); | 930 | p_slot->hpc_ops->get_power_status(p_slot, &(p_slot->pwr_save)); |
1928 | dbg("%s: func->pwr_save %x\n", __FUNCTION__, func->pwr_save); | 931 | dbg("%s: p_slot->pwr_save %x\n", __FUNCTION__, p_slot->pwr_save); |
1929 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); | 932 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
1930 | func->switch_save = !getstatus? 0x10:0; | ||
1931 | 933 | ||
1932 | rc = board_added(func, p_slot->ctrl); | 934 | rc = board_added(p_slot); |
1933 | if (rc) { | 935 | if (rc) { |
1934 | if (is_bridge(func)) | 936 | p_slot->hpc_ops->get_adapter_status(p_slot, |
1935 | bridge_slot_remove(func); | 937 | &(p_slot->presence_save)); |
1936 | else | ||
1937 | slot_remove(func); | ||
1938 | |||
1939 | /* Setup slot structure with entry for empty slot */ | ||
1940 | func = shpchp_slot_create(p_slot->bus); | ||
1941 | if (func == NULL) | ||
1942 | return -ENOMEM; /* Out of memory */ | ||
1943 | |||
1944 | func->bus = p_slot->bus; | ||
1945 | func->device = p_slot->device; | ||
1946 | func->function = 0; | ||
1947 | func->configured = 0; | ||
1948 | func->is_a_board = 1; | ||
1949 | |||
1950 | /* We have to save the presence info for these slots */ | ||
1951 | p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save)); | ||
1952 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); | 938 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
1953 | func->switch_save = !getstatus? 0x10:0; | ||
1954 | } | 939 | } |
1955 | 940 | ||
1956 | if (p_slot) | 941 | update_slot_info(p_slot); |
1957 | update_slot_info(p_slot); | ||
1958 | |||
1959 | return rc; | 942 | return rc; |
1960 | } | 943 | } |
1961 | 944 | ||
1962 | 945 | ||
1963 | int shpchp_disable_slot (struct slot *p_slot) | 946 | int shpchp_disable_slot (struct slot *p_slot) |
1964 | { | 947 | { |
1965 | u8 class_code, header_type, BCR; | ||
1966 | u8 index = 0; | ||
1967 | u8 getstatus = 0; | 948 | u8 getstatus = 0; |
1968 | u32 rc = 0; | ||
1969 | int ret = 0; | 949 | int ret = 0; |
1970 | unsigned int devfn; | ||
1971 | struct pci_bus *pci_bus; | ||
1972 | struct pci_func *func; | ||
1973 | 950 | ||
1974 | if (!p_slot->ctrl) | 951 | if (!p_slot->ctrl) |
1975 | return -ENODEV; | 952 | return -ENODEV; |
1976 | 953 | ||
1977 | pci_bus = p_slot->ctrl->pci_dev->subordinate; | ||
1978 | |||
1979 | /* Check to see if (latch closed, card present, power on) */ | 954 | /* Check to see if (latch closed, card present, power on) */ |
1980 | down(&p_slot->ctrl->crit_sect); | 955 | down(&p_slot->ctrl->crit_sect); |
1981 | 956 | ||
@@ -1999,849 +974,8 @@ int shpchp_disable_slot (struct slot *p_slot) | |||
1999 | } | 974 | } |
2000 | up(&p_slot->ctrl->crit_sect); | 975 | up(&p_slot->ctrl->crit_sect); |
2001 | 976 | ||
2002 | func = shpchp_slot_find(p_slot->bus, p_slot->device, index++); | 977 | ret = remove_board(p_slot); |
2003 | 978 | update_slot_info(p_slot); | |
2004 | /* Make sure there are no video controllers here | 979 | return ret; |
2005 | * for all func of p_slot | ||
2006 | */ | ||
2007 | while (func && !rc) { | ||
2008 | pci_bus->number = func->bus; | ||
2009 | devfn = PCI_DEVFN(func->device, func->function); | ||
2010 | |||
2011 | /* Check the Class Code */ | ||
2012 | rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code); | ||
2013 | if (rc) | ||
2014 | return -ENODEV; | ||
2015 | |||
2016 | if (class_code == PCI_BASE_CLASS_DISPLAY) { | ||
2017 | /* Display/Video adapter (not supported) */ | ||
2018 | rc = REMOVE_NOT_SUPPORTED; | ||
2019 | } else { | ||
2020 | /* See if it's a bridge */ | ||
2021 | rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &header_type); | ||
2022 | if (rc) | ||
2023 | return -ENODEV; | ||
2024 | |||
2025 | /* If it's a bridge, check the VGA Enable bit */ | ||
2026 | if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { | ||
2027 | rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_BRIDGE_CONTROL, &BCR); | ||
2028 | if (rc) | ||
2029 | return -ENODEV; | ||
2030 | |||
2031 | /* If the VGA Enable bit is set, remove isn't supported */ | ||
2032 | if (BCR & PCI_BRIDGE_CTL_VGA) { | ||
2033 | rc = REMOVE_NOT_SUPPORTED; | ||
2034 | } | ||
2035 | } | ||
2036 | } | ||
2037 | |||
2038 | func = shpchp_slot_find(p_slot->bus, p_slot->device, index++); | ||
2039 | } | ||
2040 | |||
2041 | func = shpchp_slot_find(p_slot->bus, p_slot->device, 0); | ||
2042 | if ((func != NULL) && !rc) { | ||
2043 | rc = remove_board(func, p_slot->ctrl); | ||
2044 | } else if (!rc) | ||
2045 | rc = -ENODEV; | ||
2046 | |||
2047 | if (p_slot) | ||
2048 | update_slot_info(p_slot); | ||
2049 | |||
2050 | return rc; | ||
2051 | } | ||
2052 | |||
2053 | |||
2054 | /** | ||
2055 | * configure_new_device - Configures the PCI header information of one board. | ||
2056 | * | ||
2057 | * @ctrl: pointer to controller structure | ||
2058 | * @func: pointer to function structure | ||
2059 | * @behind_bridge: 1 if this is a recursive call, 0 if not | ||
2060 | * @resources: pointer to set of resource lists | ||
2061 | * | ||
2062 | * Returns 0 if success | ||
2063 | * | ||
2064 | */ | ||
2065 | static u32 configure_new_device (struct controller * ctrl, struct pci_func * func, | ||
2066 | u8 behind_bridge, struct resource_lists * resources, u8 bridge_bus, u8 bridge_dev) | ||
2067 | { | ||
2068 | u8 temp_byte, function, max_functions, stop_it; | ||
2069 | int rc; | ||
2070 | u32 ID; | ||
2071 | struct pci_func *new_slot; | ||
2072 | struct pci_bus lpci_bus, *pci_bus; | ||
2073 | int index; | ||
2074 | |||
2075 | new_slot = func; | ||
2076 | |||
2077 | dbg("%s\n", __FUNCTION__); | ||
2078 | memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus)); | ||
2079 | pci_bus = &lpci_bus; | ||
2080 | pci_bus->number = func->bus; | ||
2081 | |||
2082 | /* Check for Multi-function device */ | ||
2083 | rc = pci_bus_read_config_byte(pci_bus, PCI_DEVFN(func->device, func->function), 0x0E, &temp_byte); | ||
2084 | if (rc) { | ||
2085 | dbg("%s: rc = %d\n", __FUNCTION__, rc); | ||
2086 | return rc; | ||
2087 | } | ||
2088 | |||
2089 | if (temp_byte & 0x80) /* Multi-function device */ | ||
2090 | max_functions = 8; | ||
2091 | else | ||
2092 | max_functions = 1; | ||
2093 | |||
2094 | function = 0; | ||
2095 | |||
2096 | do { | ||
2097 | rc = configure_new_function(ctrl, new_slot, behind_bridge, resources, bridge_bus, bridge_dev); | ||
2098 | |||
2099 | if (rc) { | ||
2100 | dbg("configure_new_function failed %d\n",rc); | ||
2101 | index = 0; | ||
2102 | |||
2103 | while (new_slot) { | ||
2104 | new_slot = shpchp_slot_find(new_slot->bus, new_slot->device, index++); | ||
2105 | |||
2106 | if (new_slot) | ||
2107 | shpchp_return_board_resources(new_slot, resources); | ||
2108 | } | ||
2109 | |||
2110 | return(rc); | ||
2111 | } | ||
2112 | |||
2113 | function++; | ||
2114 | |||
2115 | stop_it = 0; | ||
2116 | |||
2117 | /* The following loop skips to the next present function | ||
2118 | * and creates a board structure | ||
2119 | */ | ||
2120 | |||
2121 | while ((function < max_functions) && (!stop_it)) { | ||
2122 | pci_bus_read_config_dword(pci_bus, PCI_DEVFN(func->device, function), 0x00, &ID); | ||
2123 | |||
2124 | if (ID == 0xFFFFFFFF) { /* There's nothing there. */ | ||
2125 | function++; | ||
2126 | } else { /* There's something there */ | ||
2127 | /* Setup slot structure. */ | ||
2128 | new_slot = shpchp_slot_create(func->bus); | ||
2129 | |||
2130 | if (new_slot == NULL) { | ||
2131 | /* Out of memory */ | ||
2132 | return(1); | ||
2133 | } | ||
2134 | |||
2135 | new_slot->bus = func->bus; | ||
2136 | new_slot->device = func->device; | ||
2137 | new_slot->function = function; | ||
2138 | new_slot->is_a_board = 1; | ||
2139 | new_slot->status = 0; | ||
2140 | |||
2141 | stop_it++; | ||
2142 | } | ||
2143 | } | ||
2144 | |||
2145 | } while (function < max_functions); | ||
2146 | dbg("returning from configure_new_device\n"); | ||
2147 | |||
2148 | return 0; | ||
2149 | } | ||
2150 | |||
2151 | |||
2152 | /* | ||
2153 | * Configuration logic that involves the hotplug data structures and | ||
2154 | * their bookkeeping | ||
2155 | */ | ||
2156 | |||
2157 | |||
2158 | /** | ||
2159 | * configure_new_function - Configures the PCI header information of one device | ||
2160 | * | ||
2161 | * @ctrl: pointer to controller structure | ||
2162 | * @func: pointer to function structure | ||
2163 | * @behind_bridge: 1 if this is a recursive call, 0 if not | ||
2164 | * @resources: pointer to set of resource lists | ||
2165 | * | ||
2166 | * Calls itself recursively for bridged devices. | ||
2167 | * Returns 0 if success | ||
2168 | * | ||
2169 | */ | ||
2170 | static int configure_new_function (struct controller * ctrl, struct pci_func * func, | ||
2171 | u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev) | ||
2172 | { | ||
2173 | int cloop; | ||
2174 | u8 temp_byte; | ||
2175 | u8 device; | ||
2176 | u8 class_code; | ||
2177 | u16 temp_word; | ||
2178 | u32 rc; | ||
2179 | u32 temp_register; | ||
2180 | u32 base; | ||
2181 | u32 ID; | ||
2182 | unsigned int devfn; | ||
2183 | struct pci_resource *mem_node; | ||
2184 | struct pci_resource *p_mem_node; | ||
2185 | struct pci_resource *io_node; | ||
2186 | struct pci_resource *bus_node; | ||
2187 | struct pci_resource *hold_mem_node; | ||
2188 | struct pci_resource *hold_p_mem_node; | ||
2189 | struct pci_resource *hold_IO_node; | ||
2190 | struct pci_resource *hold_bus_node; | ||
2191 | struct irq_mapping irqs; | ||
2192 | struct pci_func *new_slot; | ||
2193 | struct pci_bus lpci_bus, *pci_bus; | ||
2194 | struct resource_lists temp_resources; | ||
2195 | #if defined(CONFIG_X86_64) | ||
2196 | u8 IRQ=0; | ||
2197 | #endif | ||
2198 | |||
2199 | memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus)); | ||
2200 | pci_bus = &lpci_bus; | ||
2201 | pci_bus->number = func->bus; | ||
2202 | devfn = PCI_DEVFN(func->device, func->function); | ||
2203 | |||
2204 | /* Check for Bridge */ | ||
2205 | rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &temp_byte); | ||
2206 | if (rc) | ||
2207 | return rc; | ||
2208 | |||
2209 | if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { /* PCI-PCI Bridge */ | ||
2210 | /* set Primary bus */ | ||
2211 | dbg("set Primary bus = 0x%x\n", func->bus); | ||
2212 | rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_PRIMARY_BUS, func->bus); | ||
2213 | if (rc) | ||
2214 | return rc; | ||
2215 | |||
2216 | /* find range of busses to use */ | ||
2217 | bus_node = get_max_resource(&resources->bus_head, 1L); | ||
2218 | |||
2219 | /* If we don't have any busses to allocate, we can't continue */ | ||
2220 | if (!bus_node) { | ||
2221 | err("Got NO bus resource to use\n"); | ||
2222 | return -ENOMEM; | ||
2223 | } | ||
2224 | dbg("Got ranges of buses to use: base:len=0x%x:%x\n", bus_node->base, bus_node->length); | ||
2225 | |||
2226 | /* set Secondary bus */ | ||
2227 | temp_byte = (u8)bus_node->base; | ||
2228 | dbg("set Secondary bus = 0x%x\n", temp_byte); | ||
2229 | rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SECONDARY_BUS, temp_byte); | ||
2230 | if (rc) | ||
2231 | return rc; | ||
2232 | |||
2233 | /* set subordinate bus */ | ||
2234 | temp_byte = (u8)(bus_node->base + bus_node->length - 1); | ||
2235 | dbg("set subordinate bus = 0x%x\n", temp_byte); | ||
2236 | rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte); | ||
2237 | if (rc) | ||
2238 | return rc; | ||
2239 | |||
2240 | /* Set HP parameters (Cache Line Size, Latency Timer) */ | ||
2241 | rc = shpchprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_BRIDGE); | ||
2242 | if (rc) | ||
2243 | return rc; | ||
2244 | |||
2245 | /* Setup the IO, memory, and prefetchable windows */ | ||
2246 | |||
2247 | io_node = get_max_resource(&(resources->io_head), 0x1000L); | ||
2248 | if (io_node) { | ||
2249 | dbg("io_node(base, len, next) (%x, %x, %p)\n", io_node->base, io_node->length, io_node->next); | ||
2250 | } | ||
2251 | |||
2252 | mem_node = get_max_resource(&(resources->mem_head), 0x100000L); | ||
2253 | if (mem_node) { | ||
2254 | dbg("mem_node(base, len, next) (%x, %x, %p)\n", mem_node->base, mem_node->length, mem_node->next); | ||
2255 | } | ||
2256 | |||
2257 | if (resources->p_mem_head) | ||
2258 | p_mem_node = get_max_resource(&(resources->p_mem_head), 0x100000L); | ||
2259 | else { | ||
2260 | /* | ||
2261 | * In some platform implementation, MEM and PMEM are not | ||
2262 | * distinguished, and hence ACPI _CRS has only MEM entries | ||
2263 | * for both MEM and PMEM. | ||
2264 | */ | ||
2265 | dbg("using MEM for PMEM\n"); | ||
2266 | p_mem_node = get_max_resource(&(resources->mem_head), 0x100000L); | ||
2267 | } | ||
2268 | if (p_mem_node) { | ||
2269 | dbg("p_mem_node(base, len, next) (%x, %x, %p)\n", p_mem_node->base, p_mem_node->length, p_mem_node->next); | ||
2270 | } | ||
2271 | |||
2272 | /* set up the IRQ info */ | ||
2273 | if (!resources->irqs) { | ||
2274 | irqs.barber_pole = 0; | ||
2275 | irqs.interrupt[0] = 0; | ||
2276 | irqs.interrupt[1] = 0; | ||
2277 | irqs.interrupt[2] = 0; | ||
2278 | irqs.interrupt[3] = 0; | ||
2279 | irqs.valid_INT = 0; | ||
2280 | } else { | ||
2281 | irqs.barber_pole = resources->irqs->barber_pole; | ||
2282 | irqs.interrupt[0] = resources->irqs->interrupt[0]; | ||
2283 | irqs.interrupt[1] = resources->irqs->interrupt[1]; | ||
2284 | irqs.interrupt[2] = resources->irqs->interrupt[2]; | ||
2285 | irqs.interrupt[3] = resources->irqs->interrupt[3]; | ||
2286 | irqs.valid_INT = resources->irqs->valid_INT; | ||
2287 | } | ||
2288 | |||
2289 | /* set up resource lists that are now aligned on top and bottom | ||
2290 | * for anything behind the bridge. | ||
2291 | */ | ||
2292 | temp_resources.bus_head = bus_node; | ||
2293 | temp_resources.io_head = io_node; | ||
2294 | temp_resources.mem_head = mem_node; | ||
2295 | temp_resources.p_mem_head = p_mem_node; | ||
2296 | temp_resources.irqs = &irqs; | ||
2297 | |||
2298 | /* Make copies of the nodes we are going to pass down so that | ||
2299 | * if there is a problem,we can just use these to free resources | ||
2300 | */ | ||
2301 | hold_bus_node = kmalloc(sizeof(*hold_bus_node), GFP_KERNEL); | ||
2302 | hold_IO_node = kmalloc(sizeof(*hold_IO_node), GFP_KERNEL); | ||
2303 | hold_mem_node = kmalloc(sizeof(*hold_mem_node), GFP_KERNEL); | ||
2304 | hold_p_mem_node = kmalloc(sizeof(*hold_p_mem_node), GFP_KERNEL); | ||
2305 | |||
2306 | if (!hold_bus_node || !hold_IO_node || !hold_mem_node || !hold_p_mem_node) { | ||
2307 | kfree(hold_bus_node); | ||
2308 | kfree(hold_IO_node); | ||
2309 | kfree(hold_mem_node); | ||
2310 | kfree(hold_p_mem_node); | ||
2311 | |||
2312 | return 1; | ||
2313 | } | ||
2314 | |||
2315 | memcpy(hold_bus_node, bus_node, sizeof(struct pci_resource)); | ||
2316 | |||
2317 | bus_node->base += 1; | ||
2318 | bus_node->length -= 1; | ||
2319 | bus_node->next = NULL; | ||
2320 | |||
2321 | /* If we have IO resources copy them and fill in the bridge's | ||
2322 | * IO range registers | ||
2323 | */ | ||
2324 | if (io_node) { | ||
2325 | memcpy(hold_IO_node, io_node, sizeof(struct pci_resource)); | ||
2326 | io_node->next = NULL; | ||
2327 | |||
2328 | /* set IO base and Limit registers */ | ||
2329 | RES_CHECK(io_node->base, 8); | ||
2330 | temp_byte = (u8)(io_node->base >> 8); | ||
2331 | rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_BASE, temp_byte); | ||
2332 | |||
2333 | RES_CHECK(io_node->base + io_node->length - 1, 8); | ||
2334 | temp_byte = (u8)((io_node->base + io_node->length - 1) >> 8); | ||
2335 | rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_LIMIT, temp_byte); | ||
2336 | } else { | ||
2337 | kfree(hold_IO_node); | ||
2338 | hold_IO_node = NULL; | ||
2339 | } | ||
2340 | |||
2341 | /* If we have memory resources copy them and fill in the bridge's | ||
2342 | * memory range registers. Otherwise, fill in the range | ||
2343 | * registers with values that disable them. | ||
2344 | */ | ||
2345 | if (mem_node) { | ||
2346 | memcpy(hold_mem_node, mem_node, sizeof(struct pci_resource)); | ||
2347 | mem_node->next = NULL; | ||
2348 | |||
2349 | /* set Mem base and Limit registers */ | ||
2350 | RES_CHECK(mem_node->base, 16); | ||
2351 | temp_word = (u32)(mem_node->base >> 16); | ||
2352 | rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_BASE, temp_word); | ||
2353 | |||
2354 | RES_CHECK(mem_node->base + mem_node->length - 1, 16); | ||
2355 | temp_word = (u32)((mem_node->base + mem_node->length - 1) >> 16); | ||
2356 | rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word); | ||
2357 | } else { | ||
2358 | temp_word = 0xFFFF; | ||
2359 | rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_BASE, temp_word); | ||
2360 | |||
2361 | temp_word = 0x0000; | ||
2362 | rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word); | ||
2363 | |||
2364 | kfree(hold_mem_node); | ||
2365 | hold_mem_node = NULL; | ||
2366 | } | ||
2367 | |||
2368 | /* If we have prefetchable memory resources copy them and | ||
2369 | * fill in the bridge's memory range registers. Otherwise, | ||
2370 | * fill in the range registers with values that disable them. | ||
2371 | */ | ||
2372 | if (p_mem_node) { | ||
2373 | memcpy(hold_p_mem_node, p_mem_node, sizeof(struct pci_resource)); | ||
2374 | p_mem_node->next = NULL; | ||
2375 | |||
2376 | /* set Pre Mem base and Limit registers */ | ||
2377 | RES_CHECK(p_mem_node->base, 16); | ||
2378 | temp_word = (u32)(p_mem_node->base >> 16); | ||
2379 | rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word); | ||
2380 | |||
2381 | RES_CHECK(p_mem_node->base + p_mem_node->length - 1, 16); | ||
2382 | temp_word = (u32)((p_mem_node->base + p_mem_node->length - 1) >> 16); | ||
2383 | rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word); | ||
2384 | } else { | ||
2385 | temp_word = 0xFFFF; | ||
2386 | rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word); | ||
2387 | |||
2388 | temp_word = 0x0000; | ||
2389 | rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word); | ||
2390 | |||
2391 | kfree(hold_p_mem_node); | ||
2392 | hold_p_mem_node = NULL; | ||
2393 | } | ||
2394 | |||
2395 | /* Adjust this to compensate for extra adjustment in first loop */ | ||
2396 | irqs.barber_pole--; | ||
2397 | |||
2398 | rc = 0; | ||
2399 | |||
2400 | /* Here we actually find the devices and configure them */ | ||
2401 | for (device = 0; (device <= 0x1F) && !rc; device++) { | ||
2402 | irqs.barber_pole = (irqs.barber_pole + 1) & 0x03; | ||
2403 | |||
2404 | ID = 0xFFFFFFFF; | ||
2405 | pci_bus->number = hold_bus_node->base; | ||
2406 | pci_bus_read_config_dword(pci_bus, PCI_DEVFN(device, 0), | ||
2407 | PCI_VENDOR_ID, &ID); | ||
2408 | pci_bus->number = func->bus; | ||
2409 | |||
2410 | if (ID != 0xFFFFFFFF) { /* device Present */ | ||
2411 | /* Setup slot structure. */ | ||
2412 | new_slot = shpchp_slot_create(hold_bus_node->base); | ||
2413 | |||
2414 | if (new_slot == NULL) { | ||
2415 | /* Out of memory */ | ||
2416 | rc = -ENOMEM; | ||
2417 | continue; | ||
2418 | } | ||
2419 | |||
2420 | new_slot->bus = hold_bus_node->base; | ||
2421 | new_slot->device = device; | ||
2422 | new_slot->function = 0; | ||
2423 | new_slot->is_a_board = 1; | ||
2424 | new_slot->status = 0; | ||
2425 | |||
2426 | rc = configure_new_device(ctrl, new_slot, 1, &temp_resources, func->bus, func->device); | ||
2427 | dbg("configure_new_device rc=0x%x\n",rc); | ||
2428 | } /* End of IF (device in slot?) */ | ||
2429 | } /* End of FOR loop */ | ||
2430 | |||
2431 | if (rc) { | ||
2432 | shpchp_destroy_resource_list(&temp_resources); | ||
2433 | |||
2434 | return_resource(&(resources->bus_head), hold_bus_node); | ||
2435 | return_resource(&(resources->io_head), hold_IO_node); | ||
2436 | return_resource(&(resources->mem_head), hold_mem_node); | ||
2437 | return_resource(&(resources->p_mem_head), hold_p_mem_node); | ||
2438 | return(rc); | ||
2439 | } | ||
2440 | |||
2441 | /* save the interrupt routing information */ | ||
2442 | if (resources->irqs) { | ||
2443 | resources->irqs->interrupt[0] = irqs.interrupt[0]; | ||
2444 | resources->irqs->interrupt[1] = irqs.interrupt[1]; | ||
2445 | resources->irqs->interrupt[2] = irqs.interrupt[2]; | ||
2446 | resources->irqs->interrupt[3] = irqs.interrupt[3]; | ||
2447 | resources->irqs->valid_INT = irqs.valid_INT; | ||
2448 | } else if (!behind_bridge) { | ||
2449 | /* We need to hook up the interrupts here */ | ||
2450 | for (cloop = 0; cloop < 4; cloop++) { | ||
2451 | if (irqs.valid_INT & (0x01 << cloop)) { | ||
2452 | rc = shpchp_set_irq(func->bus, func->device, | ||
2453 | 0x0A + cloop, irqs.interrupt[cloop]); | ||
2454 | if (rc) { | ||
2455 | shpchp_destroy_resource_list (&temp_resources); | ||
2456 | return_resource(&(resources->bus_head), hold_bus_node); | ||
2457 | return_resource(&(resources->io_head), hold_IO_node); | ||
2458 | return_resource(&(resources->mem_head), hold_mem_node); | ||
2459 | return_resource(&(resources->p_mem_head), hold_p_mem_node); | ||
2460 | return rc; | ||
2461 | } | ||
2462 | } | ||
2463 | } /* end of for loop */ | ||
2464 | } | ||
2465 | |||
2466 | /* Return unused bus resources | ||
2467 | * First use the temporary node to store information for the board | ||
2468 | */ | ||
2469 | if (hold_bus_node && bus_node && temp_resources.bus_head) { | ||
2470 | hold_bus_node->length = bus_node->base - hold_bus_node->base; | ||
2471 | |||
2472 | hold_bus_node->next = func->bus_head; | ||
2473 | func->bus_head = hold_bus_node; | ||
2474 | |||
2475 | temp_byte = (u8)(temp_resources.bus_head->base - 1); | ||
2476 | |||
2477 | /* set subordinate bus */ | ||
2478 | dbg("re-set subordinate bus = 0x%x\n", temp_byte); | ||
2479 | rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte); | ||
2480 | |||
2481 | if (temp_resources.bus_head->length == 0) { | ||
2482 | kfree(temp_resources.bus_head); | ||
2483 | temp_resources.bus_head = NULL; | ||
2484 | } else { | ||
2485 | dbg("return bus res of b:d(0x%x:%x) base:len(0x%x:%x)\n", | ||
2486 | func->bus, func->device, temp_resources.bus_head->base, temp_resources.bus_head->length); | ||
2487 | return_resource(&(resources->bus_head), temp_resources.bus_head); | ||
2488 | } | ||
2489 | } | ||
2490 | |||
2491 | /* If we have IO space available and there is some left, | ||
2492 | * return the unused portion | ||
2493 | */ | ||
2494 | if (hold_IO_node && temp_resources.io_head) { | ||
2495 | io_node = do_pre_bridge_resource_split(&(temp_resources.io_head), | ||
2496 | &hold_IO_node, 0x1000); | ||
2497 | |||
2498 | /* Check if we were able to split something off */ | ||
2499 | if (io_node) { | ||
2500 | hold_IO_node->base = io_node->base + io_node->length; | ||
2501 | |||
2502 | RES_CHECK(hold_IO_node->base, 8); | ||
2503 | temp_byte = (u8)((hold_IO_node->base) >> 8); | ||
2504 | rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_BASE, temp_byte); | ||
2505 | |||
2506 | return_resource(&(resources->io_head), io_node); | ||
2507 | } | ||
2508 | |||
2509 | io_node = do_bridge_resource_split(&(temp_resources.io_head), 0x1000); | ||
2510 | |||
2511 | /* Check if we were able to split something off */ | ||
2512 | if (io_node) { | ||
2513 | /* First use the temporary node to store information for the board */ | ||
2514 | hold_IO_node->length = io_node->base - hold_IO_node->base; | ||
2515 | |||
2516 | /* If we used any, add it to the board's list */ | ||
2517 | if (hold_IO_node->length) { | ||
2518 | hold_IO_node->next = func->io_head; | ||
2519 | func->io_head = hold_IO_node; | ||
2520 | |||
2521 | RES_CHECK(io_node->base - 1, 8); | ||
2522 | temp_byte = (u8)((io_node->base - 1) >> 8); | ||
2523 | rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_LIMIT, temp_byte); | ||
2524 | |||
2525 | return_resource(&(resources->io_head), io_node); | ||
2526 | } else { | ||
2527 | /* it doesn't need any IO */ | ||
2528 | temp_byte = 0x00; | ||
2529 | rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_LIMIT, temp_byte); | ||
2530 | |||
2531 | return_resource(&(resources->io_head), io_node); | ||
2532 | kfree(hold_IO_node); | ||
2533 | } | ||
2534 | } else { | ||
2535 | /* it used most of the range */ | ||
2536 | hold_IO_node->next = func->io_head; | ||
2537 | func->io_head = hold_IO_node; | ||
2538 | } | ||
2539 | } else if (hold_IO_node) { | ||
2540 | /* it used the whole range */ | ||
2541 | hold_IO_node->next = func->io_head; | ||
2542 | func->io_head = hold_IO_node; | ||
2543 | } | ||
2544 | |||
2545 | /* If we have memory space available and there is some left, | ||
2546 | * return the unused portion | ||
2547 | */ | ||
2548 | if (hold_mem_node && temp_resources.mem_head) { | ||
2549 | mem_node = do_pre_bridge_resource_split(&(temp_resources.mem_head), &hold_mem_node, 0x100000L); | ||
2550 | |||
2551 | /* Check if we were able to split something off */ | ||
2552 | if (mem_node) { | ||
2553 | hold_mem_node->base = mem_node->base + mem_node->length; | ||
2554 | |||
2555 | RES_CHECK(hold_mem_node->base, 16); | ||
2556 | temp_word = (u32)((hold_mem_node->base) >> 16); | ||
2557 | rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_BASE, temp_word); | ||
2558 | |||
2559 | return_resource(&(resources->mem_head), mem_node); | ||
2560 | } | ||
2561 | |||
2562 | mem_node = do_bridge_resource_split(&(temp_resources.mem_head), 0x100000L); | ||
2563 | |||
2564 | /* Check if we were able to split something off */ | ||
2565 | if (mem_node) { | ||
2566 | /* First use the temporary node to store information for the board */ | ||
2567 | hold_mem_node->length = mem_node->base - hold_mem_node->base; | ||
2568 | |||
2569 | if (hold_mem_node->length) { | ||
2570 | hold_mem_node->next = func->mem_head; | ||
2571 | func->mem_head = hold_mem_node; | ||
2572 | |||
2573 | /* configure end address */ | ||
2574 | RES_CHECK(mem_node->base - 1, 16); | ||
2575 | temp_word = (u32)((mem_node->base - 1) >> 16); | ||
2576 | rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word); | ||
2577 | |||
2578 | /* Return unused resources to the pool */ | ||
2579 | return_resource(&(resources->mem_head), mem_node); | ||
2580 | } else { | ||
2581 | /* it doesn't need any Mem */ | ||
2582 | temp_word = 0x0000; | ||
2583 | rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word); | ||
2584 | |||
2585 | return_resource(&(resources->mem_head), mem_node); | ||
2586 | kfree(hold_mem_node); | ||
2587 | } | ||
2588 | } else { | ||
2589 | /* it used most of the range */ | ||
2590 | hold_mem_node->next = func->mem_head; | ||
2591 | func->mem_head = hold_mem_node; | ||
2592 | } | ||
2593 | } else if (hold_mem_node) { | ||
2594 | /* it used the whole range */ | ||
2595 | hold_mem_node->next = func->mem_head; | ||
2596 | func->mem_head = hold_mem_node; | ||
2597 | } | ||
2598 | |||
2599 | /* If we have prefetchable memory space available and there is some | ||
2600 | * left at the end, return the unused portion | ||
2601 | */ | ||
2602 | if (hold_p_mem_node && temp_resources.p_mem_head) { | ||
2603 | p_mem_node = do_pre_bridge_resource_split(&(temp_resources.p_mem_head), | ||
2604 | &hold_p_mem_node, 0x100000L); | ||
2605 | |||
2606 | /* Check if we were able to split something off */ | ||
2607 | if (p_mem_node) { | ||
2608 | hold_p_mem_node->base = p_mem_node->base + p_mem_node->length; | ||
2609 | |||
2610 | RES_CHECK(hold_p_mem_node->base, 16); | ||
2611 | temp_word = (u32)((hold_p_mem_node->base) >> 16); | ||
2612 | rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word); | ||
2613 | |||
2614 | return_resource(&(resources->p_mem_head), p_mem_node); | ||
2615 | } | ||
2616 | |||
2617 | p_mem_node = do_bridge_resource_split(&(temp_resources.p_mem_head), 0x100000L); | ||
2618 | |||
2619 | /* Check if we were able to split something off */ | ||
2620 | if (p_mem_node) { | ||
2621 | /* First use the temporary node to store information for the board */ | ||
2622 | hold_p_mem_node->length = p_mem_node->base - hold_p_mem_node->base; | ||
2623 | |||
2624 | /* If we used any, add it to the board's list */ | ||
2625 | if (hold_p_mem_node->length) { | ||
2626 | hold_p_mem_node->next = func->p_mem_head; | ||
2627 | func->p_mem_head = hold_p_mem_node; | ||
2628 | |||
2629 | RES_CHECK(p_mem_node->base - 1, 16); | ||
2630 | temp_word = (u32)((p_mem_node->base - 1) >> 16); | ||
2631 | rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word); | ||
2632 | |||
2633 | return_resource(&(resources->p_mem_head), p_mem_node); | ||
2634 | } else { | ||
2635 | /* it doesn't need any PMem */ | ||
2636 | temp_word = 0x0000; | ||
2637 | rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word); | ||
2638 | |||
2639 | return_resource(&(resources->p_mem_head), p_mem_node); | ||
2640 | kfree(hold_p_mem_node); | ||
2641 | } | ||
2642 | } else { | ||
2643 | /* it used the most of the range */ | ||
2644 | hold_p_mem_node->next = func->p_mem_head; | ||
2645 | func->p_mem_head = hold_p_mem_node; | ||
2646 | } | ||
2647 | } else if (hold_p_mem_node) { | ||
2648 | /* it used the whole range */ | ||
2649 | hold_p_mem_node->next = func->p_mem_head; | ||
2650 | func->p_mem_head = hold_p_mem_node; | ||
2651 | } | ||
2652 | |||
2653 | /* We should be configuring an IRQ and the bridge's base address | ||
2654 | * registers if it needs them. Although we have never seen such | ||
2655 | * a device | ||
2656 | */ | ||
2657 | |||
2658 | shpchprm_enable_card(ctrl, func, PCI_HEADER_TYPE_BRIDGE); | ||
2659 | |||
2660 | dbg("PCI Bridge Hot-Added s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, func->device, func->function); | ||
2661 | } else if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_NORMAL) { | ||
2662 | /* Standard device */ | ||
2663 | u64 base64; | ||
2664 | rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code); | ||
2665 | |||
2666 | if (class_code == PCI_BASE_CLASS_DISPLAY) | ||
2667 | return (DEVICE_TYPE_NOT_SUPPORTED); | ||
2668 | |||
2669 | /* Figure out IO and memory needs */ | ||
2670 | for (cloop = PCI_BASE_ADDRESS_0; cloop <= PCI_BASE_ADDRESS_5; cloop += 4) { | ||
2671 | temp_register = 0xFFFFFFFF; | ||
2672 | |||
2673 | rc = pci_bus_write_config_dword (pci_bus, devfn, cloop, temp_register); | ||
2674 | rc = pci_bus_read_config_dword(pci_bus, devfn, cloop, &temp_register); | ||
2675 | dbg("Bar[%x]=0x%x on bus:dev:func(0x%x:%x:%x)\n", cloop, temp_register, func->bus, func->device, | ||
2676 | func->function); | ||
2677 | |||
2678 | if (!temp_register) | ||
2679 | continue; | ||
2680 | |||
2681 | base64 = 0L; | ||
2682 | if (temp_register & PCI_BASE_ADDRESS_SPACE_IO) { | ||
2683 | /* Map IO */ | ||
2684 | |||
2685 | /* set base = amount of IO space */ | ||
2686 | base = temp_register & 0xFFFFFFFC; | ||
2687 | base = ~base + 1; | ||
2688 | |||
2689 | dbg("NEED IO length(0x%x)\n", base); | ||
2690 | io_node = get_io_resource(&(resources->io_head),(ulong)base); | ||
2691 | |||
2692 | /* allocate the resource to the board */ | ||
2693 | if (io_node) { | ||
2694 | dbg("Got IO base=0x%x(length=0x%x)\n", io_node->base, io_node->length); | ||
2695 | base = (u32)io_node->base; | ||
2696 | io_node->next = func->io_head; | ||
2697 | func->io_head = io_node; | ||
2698 | } else { | ||
2699 | err("Got NO IO resource(length=0x%x)\n", base); | ||
2700 | return -ENOMEM; | ||
2701 | } | ||
2702 | } else { /* map MEM */ | ||
2703 | int prefetchable = 1; | ||
2704 | struct pci_resource **res_node = &func->p_mem_head; | ||
2705 | char *res_type_str = "PMEM"; | ||
2706 | u32 temp_register2; | ||
2707 | |||
2708 | if (!(temp_register & PCI_BASE_ADDRESS_MEM_PREFETCH)) { | ||
2709 | prefetchable = 0; | ||
2710 | res_node = &func->mem_head; | ||
2711 | res_type_str++; | ||
2712 | } | ||
2713 | |||
2714 | base = temp_register & 0xFFFFFFF0; | ||
2715 | base = ~base + 1; | ||
2716 | |||
2717 | switch (temp_register & PCI_BASE_ADDRESS_MEM_TYPE_MASK) { | ||
2718 | case PCI_BASE_ADDRESS_MEM_TYPE_32: | ||
2719 | dbg("NEED 32 %s bar=0x%x(length=0x%x)\n", res_type_str, temp_register, base); | ||
2720 | |||
2721 | if (prefetchable && resources->p_mem_head) | ||
2722 | mem_node=get_resource(&(resources->p_mem_head), (ulong)base); | ||
2723 | else { | ||
2724 | if (prefetchable) | ||
2725 | dbg("using MEM for PMEM\n"); | ||
2726 | mem_node=get_resource(&(resources->mem_head), (ulong)base); | ||
2727 | } | ||
2728 | |||
2729 | /* allocate the resource to the board */ | ||
2730 | if (mem_node) { | ||
2731 | base = (u32)mem_node->base; | ||
2732 | mem_node->next = *res_node; | ||
2733 | *res_node = mem_node; | ||
2734 | dbg("Got 32 %s base=0x%x(length=0x%x)\n", res_type_str, mem_node->base, | ||
2735 | mem_node->length); | ||
2736 | } else { | ||
2737 | err("Got NO 32 %s resource(length=0x%x)\n", res_type_str, base); | ||
2738 | return -ENOMEM; | ||
2739 | } | ||
2740 | break; | ||
2741 | case PCI_BASE_ADDRESS_MEM_TYPE_64: | ||
2742 | rc = pci_bus_read_config_dword(pci_bus, devfn, cloop+4, &temp_register2); | ||
2743 | dbg("NEED 64 %s bar=0x%x:%x(length=0x%x)\n", res_type_str, temp_register2, | ||
2744 | temp_register, base); | ||
2745 | |||
2746 | if (prefetchable && resources->p_mem_head) | ||
2747 | mem_node = get_resource(&(resources->p_mem_head), (ulong)base); | ||
2748 | else { | ||
2749 | if (prefetchable) | ||
2750 | dbg("using MEM for PMEM\n"); | ||
2751 | mem_node = get_resource(&(resources->mem_head), (ulong)base); | ||
2752 | } | ||
2753 | |||
2754 | /* allocate the resource to the board */ | ||
2755 | if (mem_node) { | ||
2756 | base64 = mem_node->base; | ||
2757 | mem_node->next = *res_node; | ||
2758 | *res_node = mem_node; | ||
2759 | dbg("Got 64 %s base=0x%x:%x(length=%x)\n", res_type_str, (u32)(base64 >> 32), | ||
2760 | (u32)base64, mem_node->length); | ||
2761 | } else { | ||
2762 | err("Got NO 64 %s resource(length=0x%x)\n", res_type_str, base); | ||
2763 | return -ENOMEM; | ||
2764 | } | ||
2765 | break; | ||
2766 | default: | ||
2767 | dbg("reserved BAR type=0x%x\n", temp_register); | ||
2768 | break; | ||
2769 | } | ||
2770 | |||
2771 | } | ||
2772 | |||
2773 | if (base64) { | ||
2774 | rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, (u32)base64); | ||
2775 | cloop += 4; | ||
2776 | base64 >>= 32; | ||
2777 | |||
2778 | if (base64) { | ||
2779 | dbg("%s: high dword of base64(0x%x) set to 0\n", __FUNCTION__, (u32)base64); | ||
2780 | base64 = 0x0L; | ||
2781 | } | ||
2782 | |||
2783 | rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, (u32)base64); | ||
2784 | } else { | ||
2785 | rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, base); | ||
2786 | } | ||
2787 | } /* End of base register loop */ | ||
2788 | |||
2789 | #if defined(CONFIG_X86_64) | ||
2790 | /* Figure out which interrupt pin this function uses */ | ||
2791 | rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_INTERRUPT_PIN, &temp_byte); | ||
2792 | |||
2793 | /* If this function needs an interrupt and we are behind a bridge | ||
2794 | and the pin is tied to something that's alread mapped, | ||
2795 | set this one the same | ||
2796 | */ | ||
2797 | if (temp_byte && resources->irqs && | ||
2798 | (resources->irqs->valid_INT & | ||
2799 | (0x01 << ((temp_byte + resources->irqs->barber_pole - 1) & 0x03)))) { | ||
2800 | /* We have to share with something already set up */ | ||
2801 | IRQ = resources->irqs->interrupt[(temp_byte + resources->irqs->barber_pole - 1) & 0x03]; | ||
2802 | } else { | ||
2803 | /* Program IRQ based on card type */ | ||
2804 | rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code); | ||
2805 | |||
2806 | if (class_code == PCI_BASE_CLASS_STORAGE) { | ||
2807 | IRQ = shpchp_disk_irq; | ||
2808 | } else { | ||
2809 | IRQ = shpchp_nic_irq; | ||
2810 | } | ||
2811 | } | ||
2812 | |||
2813 | /* IRQ Line */ | ||
2814 | rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_INTERRUPT_LINE, IRQ); | ||
2815 | |||
2816 | if (!behind_bridge) { | ||
2817 | rc = shpchp_set_irq(func->bus, func->device, temp_byte + 0x09, IRQ); | ||
2818 | if (rc) | ||
2819 | return(1); | ||
2820 | } else { | ||
2821 | /* TBD - this code may also belong in the other clause of this If statement */ | ||
2822 | resources->irqs->interrupt[(temp_byte + resources->irqs->barber_pole - 1) & 0x03] = IRQ; | ||
2823 | resources->irqs->valid_INT |= 0x01 << (temp_byte + resources->irqs->barber_pole - 1) & 0x03; | ||
2824 | } | ||
2825 | #endif | ||
2826 | /* Disable ROM base Address */ | ||
2827 | rc = pci_bus_write_config_dword (pci_bus, devfn, PCI_ROM_ADDRESS, 0x00); | ||
2828 | |||
2829 | /* Set HP parameters (Cache Line Size, Latency Timer) */ | ||
2830 | rc = shpchprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_NORMAL); | ||
2831 | if (rc) | ||
2832 | return rc; | ||
2833 | |||
2834 | shpchprm_enable_card(ctrl, func, PCI_HEADER_TYPE_NORMAL); | ||
2835 | |||
2836 | dbg("PCI function Hot-Added s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, func->device, func->function); | ||
2837 | } /* End of Not-A-Bridge else */ | ||
2838 | else { | ||
2839 | /* It's some strange type of PCI adapter (Cardbus?) */ | ||
2840 | return(DEVICE_TYPE_NOT_SUPPORTED); | ||
2841 | } | ||
2842 | |||
2843 | func->configured = 1; | ||
2844 | |||
2845 | return 0; | ||
2846 | } | 980 | } |
2847 | 981 | ||