2 * IBM Hot Plug Controller Driver
4 * Written By: Irene Zubarev, IBM Corporation
6 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
7 * Copyright (C) 2001,2002 IBM Corp.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Send feedback to <gregkh@us.ibm.com>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/pci.h>
33 #include <linux/list.h>
34 #include <linux/init.h>
37 static int flags = 0; /* for testing */
39 static void update_resources (struct bus_node *bus_cur, int type, int rangeno);
40 static int once_over (void);
41 static int remove_ranges (struct bus_node *, struct bus_node *);
42 static int update_bridge_ranges (struct bus_node **);
43 static int add_range (int type, struct range_node *, struct bus_node *);
44 static void fix_resources (struct bus_node *);
45 static struct bus_node *find_bus_wprev (u8, struct bus_node **, u8);
47 static LIST_HEAD(gbuses);
48 LIST_HEAD(ibmphp_res_head);
50 static struct bus_node * __init alloc_error_bus (struct ebda_pci_rsrc * curr, u8 busno, int flag)
52 struct bus_node * newbus;
54 if (!(curr) && !(flag)) {
55 err ("NULL pointer passed\n");
59 newbus = kmalloc (sizeof (struct bus_node), GFP_KERNEL);
61 err ("out of system memory\n");
65 memset (newbus, 0, sizeof (struct bus_node));
67 newbus->busno = busno;
69 newbus->busno = curr->bus_num;
70 list_add_tail (&newbus->bus_list, &gbuses);
74 static struct resource_node * __init alloc_resources (struct ebda_pci_rsrc * curr)
76 struct resource_node *rs;
79 err ("NULL passed to allocate\n");
83 rs = kmalloc (sizeof (struct resource_node), GFP_KERNEL);
85 err ("out of system memory\n");
88 memset (rs, 0, sizeof (struct resource_node));
89 rs->busno = curr->bus_num;
90 rs->devfunc = curr->dev_fun;
91 rs->start = curr->start_addr;
92 rs->end = curr->end_addr;
93 rs->len = curr->end_addr - curr->start_addr + 1;
97 static int __init alloc_bus_range (struct bus_node **new_bus, struct range_node **new_range, struct ebda_pci_rsrc *curr, int flag, u8 first_bus)
99 struct bus_node * newbus;
100 struct range_node *newrange;
104 newbus = kmalloc (sizeof (struct bus_node), GFP_KERNEL);
106 err ("out of system memory.\n");
109 memset (newbus, 0, sizeof (struct bus_node));
110 newbus->busno = curr->bus_num;
115 num_ranges = newbus->noMemRanges;
118 num_ranges = newbus->noPFMemRanges;
121 num_ranges = newbus->noIORanges;
126 newrange = kmalloc (sizeof (struct range_node), GFP_KERNEL);
130 err ("out of system memory\n");
133 memset (newrange, 0, sizeof (struct range_node));
134 newrange->start = curr->start_addr;
135 newrange->end = curr->end_addr;
137 if (first_bus || (!num_ranges))
138 newrange->rangeno = 1;
140 /* need to insert our range */
141 add_range (flag, newrange, newbus);
142 debug ("%d resource Primary Bus inserted on bus %x [%x - %x]\n", flag, newbus->busno, newrange->start, newrange->end);
147 newbus->rangeMem = newrange;
149 newbus->noMemRanges = 1;
151 debug ("First Memory Primary on bus %x, [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
152 ++newbus->noMemRanges;
153 fix_resources (newbus);
157 newbus->rangeIO = newrange;
159 newbus->noIORanges = 1;
161 debug ("First IO Primary on bus %x, [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
162 ++newbus->noIORanges;
163 fix_resources (newbus);
167 newbus->rangePFMem = newrange;
169 newbus->noPFMemRanges = 1;
171 debug ("1st PFMemory Primary on Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
172 ++newbus->noPFMemRanges;
173 fix_resources (newbus);
180 *new_range = newrange;
186 * 1. The ranges are ordered. The buses are not ordered. (First come)
188 * 2. If cannot allocate out of PFMem range, allocate from Mem ranges. PFmemFromMem
189 * are not sorted. (no need since use mem node). To not change the entire code, we
190 * also add mem node whenever this case happens so as not to change
191 * ibmphp_check_mem_resource etc (and since it really is taking Mem resource)
194 /*****************************************************************************
195 * This is the Resource Management initialization function. It will go through
196 * the Resource list taken from EBDA and fill in this module's data structures
198 * THIS IS NOT TAKING INTO CONSIDERATION IO RESTRICTIONS OF PRIMARY BUSES,
199 * SINCE WE'RE GOING TO ASSUME FOR NOW WE DON'T HAVE THOSE ON OUR BUSES FOR NOW
201 * Input: ptr to the head of the resource list from EBDA
202 * Output: 0, -1 or error codes
203 ***************************************************************************/
204 int __init ibmphp_rsrc_init (void)
206 struct ebda_pci_rsrc *curr;
207 struct range_node *newrange = NULL;
208 struct bus_node *newbus = NULL;
209 struct bus_node *bus_cur;
210 struct bus_node *bus_prev;
211 struct list_head *tmp;
212 struct resource_node *new_io = NULL;
213 struct resource_node *new_mem = NULL;
214 struct resource_node *new_pfmem = NULL;
216 struct list_head *tmp_ebda;
218 list_for_each (tmp_ebda, &ibmphp_ebda_pci_rsrc_head) {
219 curr = list_entry (tmp_ebda, struct ebda_pci_rsrc, ebda_pci_rsrc_list);
220 if (!(curr->rsrc_type & PCIDEVMASK)) {
221 /* EBDA still lists non PCI devices, so ignore... */
222 debug ("this is not a PCI DEVICE in rsrc_init, please take care\n");
226 /* this is a primary bus resource */
227 if (curr->rsrc_type & PRIMARYBUSMASK) {
229 if ((curr->rsrc_type & RESTYPE) == MMASK) {
230 /* no bus structure exists in place yet */
231 if (list_empty (&gbuses)) {
232 if ((rc = alloc_bus_range (&newbus, &newrange, curr, MEM, 1)))
234 list_add_tail (&newbus->bus_list, &gbuses);
235 debug ("gbuses = NULL, Memory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
237 bus_cur = find_bus_wprev (curr->bus_num, &bus_prev, 1);
240 rc = alloc_bus_range (&bus_cur, &newrange, curr, MEM, 0);
244 /* went through all the buses and didn't find ours, need to create a new bus node */
245 if ((rc = alloc_bus_range (&newbus, &newrange, curr, MEM, 1)))
248 list_add_tail (&newbus->bus_list, &gbuses);
249 debug ("New Bus, Memory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
252 } else if ((curr->rsrc_type & RESTYPE) == PFMASK) {
253 /* prefetchable memory */
254 if (list_empty (&gbuses)) {
255 /* no bus structure exists in place yet */
256 if ((rc = alloc_bus_range (&newbus, &newrange, curr, PFMEM, 1)))
258 list_add_tail (&newbus->bus_list, &gbuses);
259 debug ("gbuses = NULL, PFMemory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
261 bus_cur = find_bus_wprev (curr->bus_num, &bus_prev, 1);
264 rc = alloc_bus_range (&bus_cur, &newrange, curr, PFMEM, 0);
268 /* went through all the buses and didn't find ours, need to create a new bus node */
269 if ((rc = alloc_bus_range (&newbus, &newrange, curr, PFMEM, 1)))
271 list_add_tail (&newbus->bus_list, &gbuses);
272 debug ("1st Bus, PFMemory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
275 } else if ((curr->rsrc_type & RESTYPE) == IOMASK) {
277 if (list_empty (&gbuses)) {
278 /* no bus structure exists in place yet */
279 if ((rc = alloc_bus_range (&newbus, &newrange, curr, IO, 1)))
281 list_add_tail (&newbus->bus_list, &gbuses);
282 debug ("gbuses = NULL, IO Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
284 bus_cur = find_bus_wprev (curr->bus_num, &bus_prev, 1);
286 rc = alloc_bus_range (&bus_cur, &newrange, curr, IO, 0);
290 /* went through all the buses and didn't find ours, need to create a new bus node */
291 if ((rc = alloc_bus_range (&newbus, &newrange, curr, IO, 1)))
293 list_add_tail (&newbus->bus_list, &gbuses);
294 debug ("1st Bus, IO Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
299 ; /* type is reserved WHAT TO DO IN THIS CASE???
303 /* regular pci device resource */
304 if ((curr->rsrc_type & RESTYPE) == MMASK) {
305 /* Memory resource */
306 new_mem = alloc_resources (curr);
311 * if it didn't find the bus, means PCI dev
312 * came b4 the Primary Bus info, so need to
313 * create a bus rangeno becomes a problem...
314 * assign a -1 and then update once the range
315 * actually appears...
317 if (ibmphp_add_resource (new_mem) < 0) {
318 newbus = alloc_error_bus (curr, 0, 0);
321 newbus->firstMem = new_mem;
322 ++newbus->needMemUpdate;
323 new_mem->rangeno = -1;
325 debug ("Memory resource for device %x, bus %x, [%x - %x]\n", new_mem->devfunc, new_mem->busno, new_mem->start, new_mem->end);
327 } else if ((curr->rsrc_type & RESTYPE) == PFMASK) {
328 /* PFMemory resource */
329 new_pfmem = alloc_resources (curr);
332 new_pfmem->type = PFMEM;
333 new_pfmem->fromMem = FALSE;
334 if (ibmphp_add_resource (new_pfmem) < 0) {
335 newbus = alloc_error_bus (curr, 0, 0);
338 newbus->firstPFMem = new_pfmem;
339 ++newbus->needPFMemUpdate;
340 new_pfmem->rangeno = -1;
343 debug ("PFMemory resource for device %x, bus %x, [%x - %x]\n", new_pfmem->devfunc, new_pfmem->busno, new_pfmem->start, new_pfmem->end);
344 } else if ((curr->rsrc_type & RESTYPE) == IOMASK) {
346 new_io = alloc_resources (curr);
352 * if it didn't find the bus, means PCI dev
353 * came b4 the Primary Bus info, so need to
354 * create a bus rangeno becomes a problem...
355 * Can assign a -1 and then update once the
356 * range actually appears...
358 if (ibmphp_add_resource (new_io) < 0) {
359 newbus = alloc_error_bus (curr, 0, 0);
362 newbus->firstIO = new_io;
363 ++newbus->needIOUpdate;
364 new_io->rangeno = -1;
366 debug ("IO resource for device %x, bus %x, [%x - %x]\n", new_io->devfunc, new_io->busno, new_io->start, new_io->end);
371 list_for_each (tmp, &gbuses) {
372 bus_cur = list_entry (tmp, struct bus_node, bus_list);
373 /* This is to get info about PPB resources, since EBDA doesn't put this info into the primary bus info */
374 rc = update_bridge_ranges (&bus_cur);
378 rc = once_over (); /* This is to align ranges (so no -1) */
384 /********************************************************************************
385 * This function adds a range into a sorted list of ranges per bus for a particular
386 * range type, it then calls another routine to update the range numbers on the
387 * pci devices' resources for the appropriate resource
389 * Input: type of the resource, range to add, current bus
390 * Output: 0 or -1, bus and range ptrs
391 ********************************************************************************/
392 static int add_range (int type, struct range_node *range, struct bus_node *bus_cur)
394 struct range_node *range_cur = NULL;
395 struct range_node *range_prev;
396 int count = 0, i_init;
401 range_cur = bus_cur->rangeMem;
402 noRanges = bus_cur->noMemRanges;
405 range_cur = bus_cur->rangePFMem;
406 noRanges = bus_cur->noPFMemRanges;
409 range_cur = bus_cur->rangeIO;
410 noRanges = bus_cur->noIORanges;
416 if (range->start < range_cur->start)
418 range_prev = range_cur;
419 range_cur = range_cur->next;
423 /* our range will go at the beginning of the list */
426 bus_cur->rangeMem = range;
429 bus_cur->rangePFMem = range;
432 bus_cur->rangeIO = range;
435 range->next = range_cur;
438 } else if (!range_cur) {
439 /* our range will go at the end of the list */
441 range_prev->next = range;
442 range->rangeno = range_prev->rangeno + 1;
445 /* the range is in the middle */
446 range_prev->next = range;
447 range->next = range_cur;
448 range->rangeno = range_cur->rangeno;
449 i_init = range_prev->rangeno;
452 for (count = i_init; count < noRanges; ++count) {
453 ++range_cur->rangeno;
454 range_cur = range_cur->next;
457 update_resources (bus_cur, type, i_init + 1);
461 /*******************************************************************************
462 * This routine goes through the list of resources of type 'type' and updates
463 * the range numbers that they correspond to. It was called from add_range fnc
465 * Input: bus, type of the resource, the rangeno starting from which to update
466 ******************************************************************************/
467 static void update_resources (struct bus_node *bus_cur, int type, int rangeno)
469 struct resource_node *res = NULL;
470 u8 eol = FALSE; /* end of list indicator */
474 if (bus_cur->firstMem)
475 res = bus_cur->firstMem;
478 if (bus_cur->firstPFMem)
479 res = bus_cur->firstPFMem;
482 if (bus_cur->firstIO)
483 res = bus_cur->firstIO;
489 if (res->rangeno == rangeno)
493 else if (res->nextRange)
494 res = res->nextRange;
502 /* found the range */
511 static void fix_me (struct resource_node *res, struct bus_node *bus_cur, struct range_node *range)
527 if (res->rangeno == -1) {
529 if ((res->start >= range->start) && (res->end <= range->end)) {
530 res->rangeno = range->rangeno;
531 debug ("%s->rangeno in fix_resources is %d\n", str, res->rangeno);
534 --bus_cur->needIOUpdate;
537 --bus_cur->needMemUpdate;
540 --bus_cur->needPFMemUpdate;
551 res = res->nextRange;
556 /*****************************************************************************
557 * This routine reassigns the range numbers to the resources that had a -1
558 * This case can happen only if upon initialization, resources taken by pci dev
559 * appear in EBDA before the resources allocated for that bus, since we don't
560 * know the range, we assign -1, and this routine is called after a new range
561 * is assigned to see the resources with unknown range belong to the added range
564 * Output: none, list of resources for that bus are fixed if can be
565 *******************************************************************************/
566 static void fix_resources (struct bus_node *bus_cur)
568 struct range_node *range;
569 struct resource_node *res;
571 debug ("%s - bus_cur->busno = %d\n", __FUNCTION__, bus_cur->busno);
573 if (bus_cur->needIOUpdate) {
574 res = bus_cur->firstIO;
575 range = bus_cur->rangeIO;
576 fix_me (res, bus_cur, range);
578 if (bus_cur->needMemUpdate) {
579 res = bus_cur->firstMem;
580 range = bus_cur->rangeMem;
581 fix_me (res, bus_cur, range);
583 if (bus_cur->needPFMemUpdate) {
584 res = bus_cur->firstPFMem;
585 range = bus_cur->rangePFMem;
586 fix_me (res, bus_cur, range);
590 /*******************************************************************************
591 * This routine adds a resource to the list of resources to the appropriate bus
592 * based on their resource type and sorted by their starting addresses. It assigns
593 * the ptrs to next and nextRange if needed.
595 * Input: resource ptr
596 * Output: ptrs assigned (to the node)
598 *******************************************************************************/
599 int ibmphp_add_resource (struct resource_node *res)
601 struct resource_node *res_cur;
602 struct resource_node *res_prev;
603 struct bus_node *bus_cur;
604 struct range_node *range_cur = NULL;
605 struct resource_node *res_start = NULL;
607 debug ("%s - enter\n", __FUNCTION__);
610 err ("NULL passed to add\n");
614 bus_cur = find_bus_wprev (res->busno, NULL, 0);
617 /* didn't find a bus, smth's wrong!!! */
618 debug ("no bus in the system, either pci_dev's wrong or allocation failed\n");
625 range_cur = bus_cur->rangeIO;
626 res_start = bus_cur->firstIO;
629 range_cur = bus_cur->rangeMem;
630 res_start = bus_cur->firstMem;
633 range_cur = bus_cur->rangePFMem;
634 res_start = bus_cur->firstPFMem;
637 err ("cannot read the type of the resource to add... problem\n");
641 if ((res->start >= range_cur->start) && (res->end <= range_cur->end)) {
642 res->rangeno = range_cur->rangeno;
645 range_cur = range_cur->next;
648 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
649 * this is again the case of rangeno = -1
650 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
656 ++bus_cur->needIOUpdate;
659 ++bus_cur->needMemUpdate;
662 ++bus_cur->needPFMemUpdate;
668 debug ("The range is %d\n", res->rangeno);
670 /* no first{IO,Mem,Pfmem} on the bus, 1st IO/Mem/Pfmem resource ever */
673 bus_cur->firstIO = res;
676 bus_cur->firstMem = res;
679 bus_cur->firstPFMem = res;
683 res->nextRange = NULL;
688 debug ("res_cur->rangeno is %d\n", res_cur->rangeno);
691 if (res_cur->rangeno >= res->rangeno)
695 res_cur = res_cur->next;
697 res_cur = res_cur->nextRange;
701 /* at the end of the resource list */
702 debug ("i should be here, [%x - %x]\n", res->start, res->end);
703 res_prev->nextRange = res;
705 res->nextRange = NULL;
706 } else if (res_cur->rangeno == res->rangeno) {
707 /* in the same range */
709 if (res->start < res_cur->start)
712 res_cur = res_cur->next;
715 /* the last resource in this range */
716 res_prev->next = res;
718 res->nextRange = res_prev->nextRange;
719 res_prev->nextRange = NULL;
720 } else if (res->start < res_cur->start) {
721 /* at the beginning or middle of the range */
725 bus_cur->firstIO = res;
728 bus_cur->firstMem = res;
731 bus_cur->firstPFMem = res;
734 } else if (res_prev->rangeno == res_cur->rangeno)
735 res_prev->next = res;
737 res_prev->nextRange = res;
740 res->nextRange = NULL;
743 /* this is the case where it is 1st occurrence of the range */
745 /* at the beginning of the resource list */
749 res->nextRange = bus_cur->firstIO;
750 bus_cur->firstIO = res;
753 res->nextRange = bus_cur->firstMem;
754 bus_cur->firstMem = res;
757 res->nextRange = bus_cur->firstPFMem;
758 bus_cur->firstPFMem = res;
761 } else if (res_cur->rangeno > res->rangeno) {
762 /* in the middle of the resource list */
763 res_prev->nextRange = res;
765 res->nextRange = res_cur;
770 debug ("%s - exit\n", __FUNCTION__);
774 /****************************************************************************
775 * This routine will remove the resource from the list of resources
777 * Input: io, mem, and/or pfmem resource to be deleted
778 * Ouput: modified resource list
780 ****************************************************************************/
781 int ibmphp_remove_resource (struct resource_node *res)
783 struct bus_node *bus_cur;
784 struct resource_node *res_cur = NULL;
785 struct resource_node *res_prev;
786 struct resource_node *mem_cur;
790 err ("resource to remove is NULL\n");
794 bus_cur = find_bus_wprev (res->busno, NULL, 0);
797 err ("cannot find corresponding bus of the io resource to remove "
804 res_cur = bus_cur->firstIO;
808 res_cur = bus_cur->firstMem;
812 res_cur = bus_cur->firstPFMem;
816 err ("unknown type for resource to remove\n");
822 if ((res_cur->start == res->start) && (res_cur->end == res->end))
826 res_cur = res_cur->next;
828 res_cur = res_cur->nextRange;
832 if (res->type == PFMEM) {
834 * case where pfmem might be in the PFMemFromMem list
835 * so will also need to remove the corresponding mem
838 res_cur = bus_cur->firstPFMemFromMem;
842 if ((res_cur->start == res->start) && (res_cur->end == res->end)) {
843 mem_cur = bus_cur->firstMem;
845 if ((mem_cur->start == res_cur->start)
846 && (mem_cur->end == res_cur->end))
849 mem_cur = mem_cur->next;
851 mem_cur = mem_cur->nextRange;
854 err ("cannot find corresponding mem node for pfmem...\n");
858 ibmphp_remove_resource (mem_cur);
860 bus_cur->firstPFMemFromMem = res_cur->next;
862 res_prev->next = res_cur->next;
868 res_cur = res_cur->next;
870 res_cur = res_cur->nextRange;
873 err ("cannot find pfmem to delete...\n");
877 err ("the %s resource is not in the list to be deleted...\n", type);
882 /* first device to be deleted */
886 bus_cur->firstIO = res_cur->next;
889 bus_cur->firstMem = res_cur->next;
892 bus_cur->firstPFMem = res_cur->next;
895 } else if (res_cur->nextRange) {
898 bus_cur->firstIO = res_cur->nextRange;
901 bus_cur->firstMem = res_cur->nextRange;
904 bus_cur->firstPFMem = res_cur->nextRange;
910 bus_cur->firstIO = NULL;
913 bus_cur->firstMem = NULL;
916 bus_cur->firstPFMem = NULL;
924 if (res_prev->rangeno == res_cur->rangeno)
925 res_prev->next = res_cur->next;
927 res_prev->nextRange = res_cur->next;
928 } else if (res_cur->nextRange) {
929 res_prev->next = NULL;
930 res_prev->nextRange = res_cur->nextRange;
932 res_prev->next = NULL;
933 res_prev->nextRange = NULL;
942 static struct range_node * find_range (struct bus_node *bus_cur, struct resource_node * res)
944 struct range_node * range = NULL;
948 range = bus_cur->rangeIO;
951 range = bus_cur->rangeMem;
954 range = bus_cur->rangePFMem;
957 err ("cannot read resource type in find_range\n");
961 if (res->rangeno == range->rangeno)
968 /*****************************************************************************
969 * This routine will check to make sure the io/mem/pfmem->len that the device asked for
970 * can fit w/i our list of available IO/MEM/PFMEM resources. If cannot, returns -EINVAL,
971 * otherwise, returns 0
974 * Ouput: the correct start and end address are inputted into the resource node,
976 *****************************************************************************/
977 int ibmphp_check_resource (struct resource_node *res, u8 bridge)
979 struct bus_node *bus_cur;
980 struct range_node *range = NULL;
981 struct resource_node *res_prev;
982 struct resource_node *res_cur = NULL;
983 u32 len_cur = 0, start_cur = 0, len_tmp = 0;
985 u32 tmp_start; /* this is to make sure start address is divisible by the length needed */
993 /* The rules for bridges are different, 4K divisible for IO, 1M for (pf)mem*/
995 tmp_divide = IOBRIDGE;
997 tmp_divide = MEMBRIDGE;
999 tmp_divide = res->len;
1001 bus_cur = find_bus_wprev (res->busno, NULL, 0);
1004 /* didn't find a bus, smth's wrong!!! */
1005 debug ("no bus in the system, either pci_dev's wrong or allocation failed\n");
1009 debug ("%s - enter\n", __FUNCTION__);
1010 debug ("bus_cur->busno is %d\n", bus_cur->busno);
1012 /* This is a quick fix to not mess up with the code very much. i.e.,
1013 * 2000-2fff, len = 1000, but when we compare, we need it to be fff */
1016 switch (res->type) {
1018 res_cur = bus_cur->firstIO;
1019 noranges = bus_cur->noIORanges;
1022 res_cur = bus_cur->firstMem;
1023 noranges = bus_cur->noMemRanges;
1026 res_cur = bus_cur->firstPFMem;
1027 noranges = bus_cur->noPFMemRanges;
1030 err ("wrong type of resource to check\n");
1036 range = find_range (bus_cur, res_cur);
1037 debug ("%s - rangeno = %d\n", __FUNCTION__, res_cur->rangeno);
1040 err ("no range for the device exists... bailing out...\n");
1044 /* found our range */
1046 /* first time in the loop */
1047 if ((res_cur->start != range->start) && ((len_tmp = res_cur->start - 1 - range->start) >= res->len)) {
1048 debug ("len_tmp = %x\n", len_tmp);
1050 if ((len_tmp < len_cur) || (len_cur == 0)) {
1052 if ((range->start % tmp_divide) == 0) {
1053 /* just perfect, starting address is divisible by length */
1056 start_cur = range->start;
1058 /* Needs adjusting */
1059 tmp_start = range->start;
1062 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) {
1063 if ((tmp_start % tmp_divide) == 0) {
1066 start_cur = tmp_start;
1069 tmp_start += tmp_divide - tmp_start % tmp_divide;
1070 if (tmp_start >= res_cur->start - 1)
1075 if (flag && len_cur == res->len) {
1076 debug ("but we are not here, right?\n");
1077 res->start = start_cur;
1078 res->len += 1; /* To restore the balance */
1079 res->end = res->start + res->len - 1;
1085 if (!res_cur->next) {
1086 /* last device on the range */
1087 if ((range->end != res_cur->end) && ((len_tmp = range->end - (res_cur->end + 1)) >= res->len)) {
1088 debug ("len_tmp = %x\n", len_tmp);
1089 if ((len_tmp < len_cur) || (len_cur == 0)) {
1091 if (((res_cur->end + 1) % tmp_divide) == 0) {
1092 /* just perfect, starting address is divisible by length */
1095 start_cur = res_cur->end + 1;
1097 /* Needs adjusting */
1098 tmp_start = res_cur->end + 1;
1101 while ((len_tmp = range->end - tmp_start) >= res->len) {
1102 if ((tmp_start % tmp_divide) == 0) {
1105 start_cur = tmp_start;
1108 tmp_start += tmp_divide - tmp_start % tmp_divide;
1109 if (tmp_start >= range->end)
1113 if (flag && len_cur == res->len) {
1114 res->start = start_cur;
1115 res->len += 1; /* To restore the balance */
1116 res->end = res->start + res->len - 1;
1124 if (res_prev->rangeno != res_cur->rangeno) {
1125 /* 1st device on this range */
1126 if ((res_cur->start != range->start) &&
1127 ((len_tmp = res_cur->start - 1 - range->start) >= res->len)) {
1128 if ((len_tmp < len_cur) || (len_cur == 0)) {
1129 if ((range->start % tmp_divide) == 0) {
1130 /* just perfect, starting address is divisible by length */
1133 start_cur = range->start;
1135 /* Needs adjusting */
1136 tmp_start = range->start;
1139 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) {
1140 if ((tmp_start % tmp_divide) == 0) {
1143 start_cur = tmp_start;
1146 tmp_start += tmp_divide - tmp_start % tmp_divide;
1147 if (tmp_start >= res_cur->start - 1)
1152 if (flag && len_cur == res->len) {
1153 res->start = start_cur;
1154 res->len += 1; /* To restore the balance */
1155 res->end = res->start + res->len - 1;
1161 /* in the same range */
1162 if ((len_tmp = res_cur->start - 1 - res_prev->end - 1) >= res->len) {
1163 if ((len_tmp < len_cur) || (len_cur == 0)) {
1164 if (((res_prev->end + 1) % tmp_divide) == 0) {
1165 /* just perfect, starting address's divisible by length */
1168 start_cur = res_prev->end + 1;
1170 /* Needs adjusting */
1171 tmp_start = res_prev->end + 1;
1174 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) {
1175 if ((tmp_start % tmp_divide) == 0) {
1178 start_cur = tmp_start;
1181 tmp_start += tmp_divide - tmp_start % tmp_divide;
1182 if (tmp_start >= res_cur->start - 1)
1187 if (flag && len_cur == res->len) {
1188 res->start = start_cur;
1189 res->len += 1; /* To restore the balance */
1190 res->end = res->start + res->len - 1;
1197 /* end if (res_prev) */
1200 res_cur = res_cur->next;
1202 res_cur = res_cur->nextRange;
1203 } /* end of while */
1207 /* 1st device ever */
1208 /* need to find appropriate range */
1209 switch (res->type) {
1211 range = bus_cur->rangeIO;
1214 range = bus_cur->rangeMem;
1217 range = bus_cur->rangePFMem;
1221 if ((len_tmp = range->end - range->start) >= res->len) {
1222 if ((len_tmp < len_cur) || (len_cur == 0)) {
1223 if ((range->start % tmp_divide) == 0) {
1224 /* just perfect, starting address's divisible by length */
1227 start_cur = range->start;
1229 /* Needs adjusting */
1230 tmp_start = range->start;
1233 while ((len_tmp = range->end - tmp_start) >= res->len) {
1234 if ((tmp_start % tmp_divide) == 0) {
1237 start_cur = tmp_start;
1240 tmp_start += tmp_divide - tmp_start % tmp_divide;
1241 if (tmp_start >= range->end)
1246 if (flag && len_cur == res->len) {
1247 res->start = start_cur;
1248 res->len += 1; /* To restore the balance */
1249 res->end = res->start + res->len - 1;
1254 range = range->next;
1255 } /* end of while */
1257 if ((!range) && (len_cur == 0)) {
1258 /* have gone through the list of devices and ranges and haven't found n.e.thing */
1259 err ("no appropriate range.. bailing out...\n");
1261 } else if (len_cur) {
1262 res->start = start_cur;
1263 res->len += 1; /* To restore the balance */
1264 res->end = res->start + res->len - 1;
1270 debug ("prev->rangeno = %d, noranges = %d\n", res_prev->rangeno, noranges);
1271 if (res_prev->rangeno < noranges) {
1272 /* if there're more ranges out there to check */
1273 switch (res->type) {
1275 range = bus_cur->rangeIO;
1278 range = bus_cur->rangeMem;
1281 range = bus_cur->rangePFMem;
1285 if ((len_tmp = range->end - range->start) >= res->len) {
1286 if ((len_tmp < len_cur) || (len_cur == 0)) {
1287 if ((range->start % tmp_divide) == 0) {
1288 /* just perfect, starting address's divisible by length */
1291 start_cur = range->start;
1293 /* Needs adjusting */
1294 tmp_start = range->start;
1297 while ((len_tmp = range->end - tmp_start) >= res->len) {
1298 if ((tmp_start % tmp_divide) == 0) {
1301 start_cur = tmp_start;
1304 tmp_start += tmp_divide - tmp_start % tmp_divide;
1305 if (tmp_start >= range->end)
1310 if (flag && len_cur == res->len) {
1311 res->start = start_cur;
1312 res->len += 1; /* To restore the balance */
1313 res->end = res->start + res->len - 1;
1318 range = range->next;
1319 } /* end of while */
1321 if ((!range) && (len_cur == 0)) {
1322 /* have gone through the list of devices and ranges and haven't found n.e.thing */
1323 err ("no appropriate range.. bailing out...\n");
1325 } else if (len_cur) {
1326 res->start = start_cur;
1327 res->len += 1; /* To restore the balance */
1328 res->end = res->start + res->len - 1;
1332 /* no more ranges to check on */
1334 res->start = start_cur;
1335 res->len += 1; /* To restore the balance */
1336 res->end = res->start + res->len - 1;
1339 /* have gone through the list of devices and haven't found n.e.thing */
1340 err ("no appropriate range.. bailing out...\n");
1344 } /* end if(!res_cur) */
1348 /********************************************************************************
1349 * This routine is called from remove_card if the card contained PPB.
1350 * It will remove all the resources on the bus as well as the bus itself
1353 ********************************************************************************/
1354 int ibmphp_remove_bus (struct bus_node *bus, u8 parent_busno)
1356 struct resource_node *res_cur;
1357 struct resource_node *res_tmp;
1358 struct bus_node *prev_bus;
1361 prev_bus = find_bus_wprev (parent_busno, NULL, 0);
1364 debug ("something terribly wrong. Cannot find parent bus to the one to remove\n");
1368 debug ("In ibmphp_remove_bus... prev_bus->busno is %x\n", prev_bus->busno);
1370 rc = remove_ranges (bus, prev_bus);
1375 res_cur = bus->firstIO;
1379 res_cur = res_cur->next;
1381 res_cur = res_cur->nextRange;
1385 bus->firstIO = NULL;
1387 if (bus->firstMem) {
1388 res_cur = bus->firstMem;
1392 res_cur = res_cur->next;
1394 res_cur = res_cur->nextRange;
1398 bus->firstMem = NULL;
1400 if (bus->firstPFMem) {
1401 res_cur = bus->firstPFMem;
1405 res_cur = res_cur->next;
1407 res_cur = res_cur->nextRange;
1411 bus->firstPFMem = NULL;
1414 if (bus->firstPFMemFromMem) {
1415 res_cur = bus->firstPFMemFromMem;
1418 res_cur = res_cur->next;
1423 bus->firstPFMemFromMem = NULL;
1426 list_del (&bus->bus_list);
1431 /******************************************************************************
1432 * This routine deletes the ranges from a given bus, and the entries from the
1433 * parent's bus in the resources
1434 * Input: current bus, previous bus
1435 * Output: 0, -EINVAL
1436 ******************************************************************************/
1437 static int remove_ranges (struct bus_node *bus_cur, struct bus_node *bus_prev)
1439 struct range_node *range_cur;
1440 struct range_node *range_tmp;
1442 struct resource_node *res = NULL;
1444 if (bus_cur->noIORanges) {
1445 range_cur = bus_cur->rangeIO;
1446 for (i = 0; i < bus_cur->noIORanges; i++) {
1447 if (ibmphp_find_resource (bus_prev, range_cur->start, &res, IO) < 0)
1449 ibmphp_remove_resource (res);
1451 range_tmp = range_cur;
1452 range_cur = range_cur->next;
1456 bus_cur->rangeIO = NULL;
1458 if (bus_cur->noMemRanges) {
1459 range_cur = bus_cur->rangeMem;
1460 for (i = 0; i < bus_cur->noMemRanges; i++) {
1461 if (ibmphp_find_resource (bus_prev, range_cur->start, &res, MEM) < 0)
1464 ibmphp_remove_resource (res);
1465 range_tmp = range_cur;
1466 range_cur = range_cur->next;
1470 bus_cur->rangeMem = NULL;
1472 if (bus_cur->noPFMemRanges) {
1473 range_cur = bus_cur->rangePFMem;
1474 for (i = 0; i < bus_cur->noPFMemRanges; i++) {
1475 if (ibmphp_find_resource (bus_prev, range_cur->start, &res, PFMEM) < 0)
1478 ibmphp_remove_resource (res);
1479 range_tmp = range_cur;
1480 range_cur = range_cur->next;
1484 bus_cur->rangePFMem = NULL;
1490 * find the resource node in the bus
1491 * Input: Resource needed, start address of the resource, type of resource
1493 int ibmphp_find_resource (struct bus_node *bus, u32 start_address, struct resource_node **res, int flag)
1495 struct resource_node *res_cur = NULL;
1499 err ("The bus passed in NULL to find resource\n");
1505 res_cur = bus->firstIO;
1509 res_cur = bus->firstMem;
1513 res_cur = bus->firstPFMem;
1517 err ("wrong type of flag\n");
1522 if (res_cur->start == start_address) {
1527 res_cur = res_cur->next;
1529 res_cur = res_cur->nextRange;
1533 if (flag == PFMEM) {
1534 res_cur = bus->firstPFMemFromMem;
1536 if (res_cur->start == start_address) {
1540 res_cur = res_cur->next;
1543 debug ("SOS...cannot find %s resource in the bus.\n", type);
1547 debug ("SOS... cannot find %s resource in the bus.\n", type);
1553 debug ("*res->start = %x\n", (*res)->start);
1558 /***********************************************************************
1559 * This routine will free the resource structures used by the
1560 * system. It is called from cleanup routine for the module
1563 ***********************************************************************/
1564 void ibmphp_free_resources (void)
1566 struct bus_node *bus_cur = NULL;
1567 struct bus_node *bus_tmp;
1568 struct range_node *range_cur;
1569 struct range_node *range_tmp;
1570 struct resource_node *res_cur;
1571 struct resource_node *res_tmp;
1572 struct list_head *tmp;
1573 struct list_head *next;
1577 list_for_each_safe (tmp, next, &gbuses) {
1578 bus_cur = list_entry (tmp, struct bus_node, bus_list);
1579 if (bus_cur->noIORanges) {
1580 range_cur = bus_cur->rangeIO;
1581 for (i = 0; i < bus_cur->noIORanges; i++) {
1584 range_tmp = range_cur;
1585 range_cur = range_cur->next;
1590 if (bus_cur->noMemRanges) {
1591 range_cur = bus_cur->rangeMem;
1592 for (i = 0; i < bus_cur->noMemRanges; i++) {
1595 range_tmp = range_cur;
1596 range_cur = range_cur->next;
1601 if (bus_cur->noPFMemRanges) {
1602 range_cur = bus_cur->rangePFMem;
1603 for (i = 0; i < bus_cur->noPFMemRanges; i++) {
1606 range_tmp = range_cur;
1607 range_cur = range_cur->next;
1613 if (bus_cur->firstIO) {
1614 res_cur = bus_cur->firstIO;
1618 res_cur = res_cur->next;
1620 res_cur = res_cur->nextRange;
1624 bus_cur->firstIO = NULL;
1626 if (bus_cur->firstMem) {
1627 res_cur = bus_cur->firstMem;
1631 res_cur = res_cur->next;
1633 res_cur = res_cur->nextRange;
1637 bus_cur->firstMem = NULL;
1639 if (bus_cur->firstPFMem) {
1640 res_cur = bus_cur->firstPFMem;
1644 res_cur = res_cur->next;
1646 res_cur = res_cur->nextRange;
1650 bus_cur->firstPFMem = NULL;
1653 if (bus_cur->firstPFMemFromMem) {
1654 res_cur = bus_cur->firstPFMemFromMem;
1657 res_cur = res_cur->next;
1662 bus_cur->firstPFMemFromMem = NULL;
1666 list_del (&bus_cur->bus_list);
1672 /*********************************************************************************
1673 * This function will go over the PFmem resources to check if the EBDA allocated
1674 * pfmem out of memory buckets of the bus. If so, it will change the range numbers
1675 * and a flag to indicate that this resource is out of memory. It will also move the
1676 * Pfmem out of the pfmem resource list to the PFMemFromMem list, and will create
1678 * This routine is called right after initialization
1679 *******************************************************************************/
1680 static int __init once_over (void)
1682 struct resource_node *pfmem_cur;
1683 struct resource_node *pfmem_prev;
1684 struct resource_node *mem;
1685 struct bus_node *bus_cur;
1686 struct list_head *tmp;
1688 list_for_each (tmp, &gbuses) {
1689 bus_cur = list_entry (tmp, struct bus_node, bus_list);
1690 if ((!bus_cur->rangePFMem) && (bus_cur->firstPFMem)) {
1691 for (pfmem_cur = bus_cur->firstPFMem, pfmem_prev = NULL; pfmem_cur; pfmem_prev = pfmem_cur, pfmem_cur = pfmem_cur->next) {
1692 pfmem_cur->fromMem = TRUE;
1694 pfmem_prev->next = pfmem_cur->next;
1696 bus_cur->firstPFMem = pfmem_cur->next;
1698 if (!bus_cur->firstPFMemFromMem)
1699 pfmem_cur->next = NULL;
1701 /* we don't need to sort PFMemFromMem since we're using mem node for
1702 all the real work anyways, so just insert at the beginning of the
1705 pfmem_cur->next = bus_cur->firstPFMemFromMem;
1707 bus_cur->firstPFMemFromMem = pfmem_cur;
1709 mem = kmalloc (sizeof (struct resource_node), GFP_KERNEL);
1711 err ("out of system memory\n");
1714 memset (mem, 0, sizeof (struct resource_node));
1716 mem->busno = pfmem_cur->busno;
1717 mem->devfunc = pfmem_cur->devfunc;
1718 mem->start = pfmem_cur->start;
1719 mem->end = pfmem_cur->end;
1720 mem->len = pfmem_cur->len;
1721 if (ibmphp_add_resource (mem) < 0)
1722 err ("Trouble...trouble... EBDA allocated pfmem from mem, but system doesn't display it has this space... unless not PCI device...\n");
1723 pfmem_cur->rangeno = mem->rangeno;
1724 } /* end for pfmem */
1726 } /* end list_for_each bus */
1730 int ibmphp_add_pfmem_from_mem (struct resource_node *pfmem)
1732 struct bus_node *bus_cur = find_bus_wprev (pfmem->busno, NULL, 0);
1735 err ("cannot find bus of pfmem to add...\n");
1739 if (bus_cur->firstPFMemFromMem)
1740 pfmem->next = bus_cur->firstPFMemFromMem;
1744 bus_cur->firstPFMemFromMem = pfmem;
1749 /* This routine just goes through the buses to see if the bus already exists.
1750 * It is called from ibmphp_find_sec_number, to find out a secondary bus number for
1752 * Parameters: bus_number
1753 * Returns: Bus pointer or NULL
1755 struct bus_node *ibmphp_find_res_bus (u8 bus_number)
1757 return find_bus_wprev (bus_number, NULL, 0);
1760 static struct bus_node *find_bus_wprev (u8 bus_number, struct bus_node **prev, u8 flag)
1762 struct bus_node *bus_cur;
1763 struct list_head *tmp;
1764 struct list_head *tmp_prev;
1766 list_for_each (tmp, &gbuses) {
1767 tmp_prev = tmp->prev;
1768 bus_cur = list_entry (tmp, struct bus_node, bus_list);
1770 *prev = list_entry (tmp_prev, struct bus_node, bus_list);
1771 if (bus_cur->busno == bus_number)
1778 void ibmphp_print_test (void)
1781 struct bus_node *bus_cur = NULL;
1782 struct range_node *range;
1783 struct resource_node *res;
1784 struct list_head *tmp;
1786 debug_pci ("*****************START**********************\n");
1788 if ((!list_empty(&gbuses)) && flags) {
1789 err ("The GBUSES is not NULL?!?!?!?!?\n");
1793 list_for_each (tmp, &gbuses) {
1794 bus_cur = list_entry (tmp, struct bus_node, bus_list);
1795 debug_pci ("This is bus # %d. There are\n", bus_cur->busno);
1796 debug_pci ("IORanges = %d\t", bus_cur->noIORanges);
1797 debug_pci ("MemRanges = %d\t", bus_cur->noMemRanges);
1798 debug_pci ("PFMemRanges = %d\n", bus_cur->noPFMemRanges);
1799 debug_pci ("The IO Ranges are as follows:\n");
1800 if (bus_cur->rangeIO) {
1801 range = bus_cur->rangeIO;
1802 for (i = 0; i < bus_cur->noIORanges; i++) {
1803 debug_pci ("rangeno is %d\n", range->rangeno);
1804 debug_pci ("[%x - %x]\n", range->start, range->end);
1805 range = range->next;
1809 debug_pci ("The Mem Ranges are as follows:\n");
1810 if (bus_cur->rangeMem) {
1811 range = bus_cur->rangeMem;
1812 for (i = 0; i < bus_cur->noMemRanges; i++) {
1813 debug_pci ("rangeno is %d\n", range->rangeno);
1814 debug_pci ("[%x - %x]\n", range->start, range->end);
1815 range = range->next;
1819 debug_pci ("The PFMem Ranges are as follows:\n");
1821 if (bus_cur->rangePFMem) {
1822 range = bus_cur->rangePFMem;
1823 for (i = 0; i < bus_cur->noPFMemRanges; i++) {
1824 debug_pci ("rangeno is %d\n", range->rangeno);
1825 debug_pci ("[%x - %x]\n", range->start, range->end);
1826 range = range->next;
1830 debug_pci ("The resources on this bus are as follows\n");
1832 debug_pci ("IO...\n");
1833 if (bus_cur->firstIO) {
1834 res = bus_cur->firstIO;
1836 debug_pci ("The range # is %d\n", res->rangeno);
1837 debug_pci ("The bus, devfnc is %d, %x\n", res->busno, res->devfunc);
1838 debug_pci ("[%x - %x], len=%x\n", res->start, res->end, res->len);
1841 else if (res->nextRange)
1842 res = res->nextRange;
1847 debug_pci ("Mem...\n");
1848 if (bus_cur->firstMem) {
1849 res = bus_cur->firstMem;
1851 debug_pci ("The range # is %d\n", res->rangeno);
1852 debug_pci ("The bus, devfnc is %d, %x\n", res->busno, res->devfunc);
1853 debug_pci ("[%x - %x], len=%x\n", res->start, res->end, res->len);
1856 else if (res->nextRange)
1857 res = res->nextRange;
1862 debug_pci ("PFMem...\n");
1863 if (bus_cur->firstPFMem) {
1864 res = bus_cur->firstPFMem;
1866 debug_pci ("The range # is %d\n", res->rangeno);
1867 debug_pci ("The bus, devfnc is %d, %x\n", res->busno, res->devfunc);
1868 debug_pci ("[%x - %x], len=%x\n", res->start, res->end, res->len);
1871 else if (res->nextRange)
1872 res = res->nextRange;
1878 debug_pci ("PFMemFromMem...\n");
1879 if (bus_cur->firstPFMemFromMem) {
1880 res = bus_cur->firstPFMemFromMem;
1882 debug_pci ("The range # is %d\n", res->rangeno);
1883 debug_pci ("The bus, devfnc is %d, %x\n", res->busno, res->devfunc);
1884 debug_pci ("[%x - %x], len=%x\n", res->start, res->end, res->len);
1889 debug_pci ("***********************END***********************\n");
1892 static int range_exists_already (struct range_node * range, struct bus_node * bus_cur, u8 type)
1894 struct range_node * range_cur = NULL;
1897 range_cur = bus_cur->rangeIO;
1900 range_cur = bus_cur->rangeMem;
1903 range_cur = bus_cur->rangePFMem;
1906 err ("wrong type passed to find out if range already exists\n");
1911 if ((range_cur->start == range->start) && (range_cur->end == range->end))
1913 range_cur = range_cur->next;
1919 /* This routine will read the windows for any PPB we have and update the
1920 * range info for the secondary bus, and will also input this info into
1921 * primary bus, since BIOS doesn't. This is for PPB that are in the system
1922 * on bootup. For bridged cards that were added during previous load of the
1923 * driver, only the ranges and the bus structure are added, the devices are
1925 * Input: primary busno
1927 * Note: this function doesn't take into account IO restrictions etc,
1928 * so will only work for bridges with no video/ISA devices behind them It
1929 * also will not work for onboard PPB's that can have more than 1 *bus
1930 * behind them All these are TO DO.
1931 * Also need to add more error checkings... (from fnc returns etc)
1933 static int __init update_bridge_ranges (struct bus_node **bus)
1935 u8 sec_busno, device, function, hdr_type, start_io_address, end_io_address;
1936 u16 vendor_id, upper_io_start, upper_io_end, start_mem_address, end_mem_address;
1937 u32 start_address, end_address, upper_start, upper_end;
1938 struct bus_node *bus_sec;
1939 struct bus_node *bus_cur;
1940 struct resource_node *io;
1941 struct resource_node *mem;
1942 struct resource_node *pfmem;
1943 struct range_node *range;
1949 ibmphp_pci_bus->number = bus_cur->busno;
1951 debug ("inside %s\n", __FUNCTION__);
1952 debug ("bus_cur->busno = %x\n", bus_cur->busno);
1954 for (device = 0; device < 32; device++) {
1955 for (function = 0x00; function < 0x08; function++) {
1956 devfn = PCI_DEVFN(device, function);
1957 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_VENDOR_ID, &vendor_id);
1959 if (vendor_id != PCI_VENDOR_ID_NOTVALID) {
1960 /* found correct device!!! */
1961 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_HEADER_TYPE, &hdr_type);
1964 case PCI_HEADER_TYPE_NORMAL:
1967 case PCI_HEADER_TYPE_MULTIDEVICE:
1969 case PCI_HEADER_TYPE_BRIDGE:
1971 case PCI_HEADER_TYPE_MULTIBRIDGE:
1972 /* We assume here that only 1 bus behind the bridge
1973 TO DO: add functionality for several:
1975 while (temp < subordinate) {
1980 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_SECONDARY_BUS, &sec_busno);
1981 bus_sec = find_bus_wprev (sec_busno, NULL, 0);
1982 /* this bus structure doesn't exist yet, PPB was configured during previous loading of ibmphp */
1984 bus_sec = alloc_error_bus (NULL, sec_busno, 1);
1985 /* the rest will be populated during NVRAM call */
1988 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_IO_BASE, &start_io_address);
1989 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_IO_LIMIT, &end_io_address);
1990 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_IO_BASE_UPPER16, &upper_io_start);
1991 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_IO_LIMIT_UPPER16, &upper_io_end);
1992 start_address = (start_io_address & PCI_IO_RANGE_MASK) << 8;
1993 start_address |= (upper_io_start << 16);
1994 end_address = (end_io_address & PCI_IO_RANGE_MASK) << 8;
1995 end_address |= (upper_io_end << 16);
1997 if ((start_address) && (start_address <= end_address)) {
1998 range = kmalloc (sizeof (struct range_node), GFP_KERNEL);
2000 err ("out of system memory\n");
2003 memset (range, 0, sizeof (struct range_node));
2004 range->start = start_address;
2005 range->end = end_address + 0xfff;
2007 if (bus_sec->noIORanges > 0) {
2008 if (!range_exists_already (range, bus_sec, IO)) {
2009 add_range (IO, range, bus_sec);
2010 ++bus_sec->noIORanges;
2016 /* 1st IO Range on the bus */
2018 bus_sec->rangeIO = range;
2019 ++bus_sec->noIORanges;
2021 fix_resources (bus_sec);
2023 if (ibmphp_find_resource (bus_cur, start_address, &io, IO)) {
2024 io = kmalloc (sizeof (struct resource_node), GFP_KERNEL);
2027 err ("out of system memory\n");
2030 memset (io, 0, sizeof (struct resource_node));
2032 io->busno = bus_cur->busno;
2033 io->devfunc = ((device << 3) | (function & 0x7));
2034 io->start = start_address;
2035 io->end = end_address + 0xfff;
2036 io->len = io->end - io->start + 1;
2037 ibmphp_add_resource (io);
2041 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_MEMORY_BASE, &start_mem_address);
2042 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_MEMORY_LIMIT, &end_mem_address);
2044 start_address = 0x00000000 | (start_mem_address & PCI_MEMORY_RANGE_MASK) << 16;
2045 end_address = 0x00000000 | (end_mem_address & PCI_MEMORY_RANGE_MASK) << 16;
2047 if ((start_address) && (start_address <= end_address)) {
2049 range = kmalloc (sizeof (struct range_node), GFP_KERNEL);
2051 err ("out of system memory\n");
2054 memset (range, 0, sizeof (struct range_node));
2055 range->start = start_address;
2056 range->end = end_address + 0xfffff;
2058 if (bus_sec->noMemRanges > 0) {
2059 if (!range_exists_already (range, bus_sec, MEM)) {
2060 add_range (MEM, range, bus_sec);
2061 ++bus_sec->noMemRanges;
2067 /* 1st Mem Range on the bus */
2069 bus_sec->rangeMem = range;
2070 ++bus_sec->noMemRanges;
2073 fix_resources (bus_sec);
2075 if (ibmphp_find_resource (bus_cur, start_address, &mem, MEM)) {
2076 mem = kmalloc (sizeof (struct resource_node), GFP_KERNEL);
2079 err ("out of system memory\n");
2082 memset (mem, 0, sizeof (struct resource_node));
2084 mem->busno = bus_cur->busno;
2085 mem->devfunc = ((device << 3) | (function & 0x7));
2086 mem->start = start_address;
2087 mem->end = end_address + 0xfffff;
2088 mem->len = mem->end - mem->start + 1;
2089 ibmphp_add_resource (mem);
2092 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_PREF_MEMORY_BASE, &start_mem_address);
2093 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, &end_mem_address);
2094 pci_bus_read_config_dword (ibmphp_pci_bus, devfn, PCI_PREF_BASE_UPPER32, &upper_start);
2095 pci_bus_read_config_dword (ibmphp_pci_bus, devfn, PCI_PREF_LIMIT_UPPER32, &upper_end);
2096 start_address = 0x00000000 | (start_mem_address & PCI_MEMORY_RANGE_MASK) << 16;
2097 end_address = 0x00000000 | (end_mem_address & PCI_MEMORY_RANGE_MASK) << 16;
2098 #if BITS_PER_LONG == 64
2099 start_address |= ((long) upper_start) << 32;
2100 end_address |= ((long) upper_end) << 32;
2103 if ((start_address) && (start_address <= end_address)) {
2105 range = kmalloc (sizeof (struct range_node), GFP_KERNEL);
2107 err ("out of system memory\n");
2110 memset (range, 0, sizeof (struct range_node));
2111 range->start = start_address;
2112 range->end = end_address + 0xfffff;
2114 if (bus_sec->noPFMemRanges > 0) {
2115 if (!range_exists_already (range, bus_sec, PFMEM)) {
2116 add_range (PFMEM, range, bus_sec);
2117 ++bus_sec->noPFMemRanges;
2123 /* 1st PFMem Range on the bus */
2125 bus_sec->rangePFMem = range;
2126 ++bus_sec->noPFMemRanges;
2129 fix_resources (bus_sec);
2130 if (ibmphp_find_resource (bus_cur, start_address, &pfmem, PFMEM)) {
2131 pfmem = kmalloc (sizeof (struct resource_node), GFP_KERNEL);
2134 err ("out of system memory\n");
2137 memset (pfmem, 0, sizeof (struct resource_node));
2138 pfmem->type = PFMEM;
2139 pfmem->busno = bus_cur->busno;
2140 pfmem->devfunc = ((device << 3) | (function & 0x7));
2141 pfmem->start = start_address;
2142 pfmem->end = end_address + 0xfffff;
2143 pfmem->len = pfmem->end - pfmem->start + 1;
2144 pfmem->fromMem = FALSE;
2146 ibmphp_add_resource (pfmem);
2150 } /* end of switch */
2151 } /* end if vendor */
2152 } /* end for function */
2153 } /* end for device */