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);
49 static struct bus_node * __init alloc_error_bus (struct ebda_pci_rsrc * curr, u8 busno, int flag)
51 struct bus_node * newbus;
53 if (!(curr) && !(flag)) {
54 err ("NULL pointer passed\n");
58 newbus = kmalloc (sizeof (struct bus_node), GFP_KERNEL);
60 err ("out of system memory\n");
64 memset (newbus, 0, sizeof (struct bus_node));
66 newbus->busno = busno;
68 newbus->busno = curr->bus_num;
69 list_add_tail (&newbus->bus_list, &gbuses);
73 static struct resource_node * __init alloc_resources (struct ebda_pci_rsrc * curr)
75 struct resource_node *rs;
78 err ("NULL passed to allocate\n");
82 rs = kmalloc (sizeof (struct resource_node), GFP_KERNEL);
84 err ("out of system memory\n");
87 memset (rs, 0, sizeof (struct resource_node));
88 rs->busno = curr->bus_num;
89 rs->devfunc = curr->dev_fun;
90 rs->start = curr->start_addr;
91 rs->end = curr->end_addr;
92 rs->len = curr->end_addr - curr->start_addr + 1;
96 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)
98 struct bus_node * newbus;
99 struct range_node *newrange;
103 newbus = kmalloc (sizeof (struct bus_node), GFP_KERNEL);
105 err ("out of system memory.\n");
108 memset (newbus, 0, sizeof (struct bus_node));
109 newbus->busno = curr->bus_num;
114 num_ranges = newbus->noMemRanges;
117 num_ranges = newbus->noPFMemRanges;
120 num_ranges = newbus->noIORanges;
125 newrange = kmalloc (sizeof (struct range_node), GFP_KERNEL);
129 err ("out of system memory\n");
132 memset (newrange, 0, sizeof (struct range_node));
133 newrange->start = curr->start_addr;
134 newrange->end = curr->end_addr;
136 if (first_bus || (!num_ranges))
137 newrange->rangeno = 1;
139 /* need to insert our range */
140 add_range (flag, newrange, newbus);
141 debug ("%d resource Primary Bus inserted on bus %x [%x - %x]\n", flag, newbus->busno, newrange->start, newrange->end);
146 newbus->rangeMem = newrange;
148 newbus->noMemRanges = 1;
150 debug ("First Memory Primary on bus %x, [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
151 ++newbus->noMemRanges;
152 fix_resources (newbus);
156 newbus->rangeIO = newrange;
158 newbus->noIORanges = 1;
160 debug ("First IO Primary on bus %x, [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
161 ++newbus->noIORanges;
162 fix_resources (newbus);
166 newbus->rangePFMem = newrange;
168 newbus->noPFMemRanges = 1;
170 debug ("1st PFMemory Primary on Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
171 ++newbus->noPFMemRanges;
172 fix_resources (newbus);
179 *new_range = newrange;
185 * 1. The ranges are ordered. The buses are not ordered. (First come)
187 * 2. If cannot allocate out of PFMem range, allocate from Mem ranges. PFmemFromMem
188 * are not sorted. (no need since use mem node). To not change the entire code, we
189 * also add mem node whenever this case happens so as not to change
190 * ibmphp_check_mem_resource etc (and since it really is taking Mem resource)
193 /*****************************************************************************
194 * This is the Resource Management initialization function. It will go through
195 * the Resource list taken from EBDA and fill in this module's data structures
197 * THIS IS NOT TAKING INTO CONSIDERATION IO RESTRICTIONS OF PRIMARY BUSES,
198 * SINCE WE'RE GOING TO ASSUME FOR NOW WE DON'T HAVE THOSE ON OUR BUSES FOR NOW
200 * Input: ptr to the head of the resource list from EBDA
201 * Output: 0, -1 or error codes
202 ***************************************************************************/
203 int __init ibmphp_rsrc_init (void)
205 struct ebda_pci_rsrc *curr;
206 struct range_node *newrange = NULL;
207 struct bus_node *newbus = NULL;
208 struct bus_node *bus_cur;
209 struct bus_node *bus_prev;
210 struct list_head *tmp;
211 struct resource_node *new_io = NULL;
212 struct resource_node *new_mem = NULL;
213 struct resource_node *new_pfmem = NULL;
215 struct list_head *tmp_ebda;
217 list_for_each (tmp_ebda, &ibmphp_ebda_pci_rsrc_head) {
218 curr = list_entry (tmp_ebda, struct ebda_pci_rsrc, ebda_pci_rsrc_list);
219 if (!(curr->rsrc_type & PCIDEVMASK)) {
220 /* EBDA still lists non PCI devices, so ignore... */
221 debug ("this is not a PCI DEVICE in rsrc_init, please take care\n");
225 /* this is a primary bus resource */
226 if (curr->rsrc_type & PRIMARYBUSMASK) {
228 if ((curr->rsrc_type & RESTYPE) == MMASK) {
229 /* no bus structure exists in place yet */
230 if (list_empty (&gbuses)) {
231 if ((rc = alloc_bus_range (&newbus, &newrange, curr, MEM, 1)))
233 list_add_tail (&newbus->bus_list, &gbuses);
234 debug ("gbuses = NULL, Memory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
236 bus_cur = find_bus_wprev (curr->bus_num, &bus_prev, 1);
239 rc = alloc_bus_range (&bus_cur, &newrange, curr, MEM, 0);
243 /* went through all the buses and didn't find ours, need to create a new bus node */
244 if ((rc = alloc_bus_range (&newbus, &newrange, curr, MEM, 1)))
247 list_add_tail (&newbus->bus_list, &gbuses);
248 debug ("New Bus, Memory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
251 } else if ((curr->rsrc_type & RESTYPE) == PFMASK) {
252 /* prefetchable memory */
253 if (list_empty (&gbuses)) {
254 /* no bus structure exists in place yet */
255 if ((rc = alloc_bus_range (&newbus, &newrange, curr, PFMEM, 1)))
257 list_add_tail (&newbus->bus_list, &gbuses);
258 debug ("gbuses = NULL, PFMemory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
260 bus_cur = find_bus_wprev (curr->bus_num, &bus_prev, 1);
263 rc = alloc_bus_range (&bus_cur, &newrange, curr, PFMEM, 0);
267 /* went through all the buses and didn't find ours, need to create a new bus node */
268 if ((rc = alloc_bus_range (&newbus, &newrange, curr, PFMEM, 1)))
270 list_add_tail (&newbus->bus_list, &gbuses);
271 debug ("1st Bus, PFMemory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
274 } else if ((curr->rsrc_type & RESTYPE) == IOMASK) {
276 if (list_empty (&gbuses)) {
277 /* no bus structure exists in place yet */
278 if ((rc = alloc_bus_range (&newbus, &newrange, curr, IO, 1)))
280 list_add_tail (&newbus->bus_list, &gbuses);
281 debug ("gbuses = NULL, IO Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
283 bus_cur = find_bus_wprev (curr->bus_num, &bus_prev, 1);
285 rc = alloc_bus_range (&bus_cur, &newrange, curr, IO, 0);
289 /* went through all the buses and didn't find ours, need to create a new bus node */
290 if ((rc = alloc_bus_range (&newbus, &newrange, curr, IO, 1)))
292 list_add_tail (&newbus->bus_list, &gbuses);
293 debug ("1st Bus, IO Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
298 ; /* type is reserved WHAT TO DO IN THIS CASE???
302 /* regular pci device resource */
303 if ((curr->rsrc_type & RESTYPE) == MMASK) {
304 /* Memory resource */
305 new_mem = alloc_resources (curr);
310 * if it didn't find the bus, means PCI dev
311 * came b4 the Primary Bus info, so need to
312 * create a bus rangeno becomes a problem...
313 * assign a -1 and then update once the range
314 * actually appears...
316 if (ibmphp_add_resource (new_mem) < 0) {
317 newbus = alloc_error_bus (curr, 0, 0);
320 newbus->firstMem = new_mem;
321 ++newbus->needMemUpdate;
322 new_mem->rangeno = -1;
324 debug ("Memory resource for device %x, bus %x, [%x - %x]\n", new_mem->devfunc, new_mem->busno, new_mem->start, new_mem->end);
326 } else if ((curr->rsrc_type & RESTYPE) == PFMASK) {
327 /* PFMemory resource */
328 new_pfmem = alloc_resources (curr);
331 new_pfmem->type = PFMEM;
332 new_pfmem->fromMem = FALSE;
333 if (ibmphp_add_resource (new_pfmem) < 0) {
334 newbus = alloc_error_bus (curr, 0, 0);
337 newbus->firstPFMem = new_pfmem;
338 ++newbus->needPFMemUpdate;
339 new_pfmem->rangeno = -1;
342 debug ("PFMemory resource for device %x, bus %x, [%x - %x]\n", new_pfmem->devfunc, new_pfmem->busno, new_pfmem->start, new_pfmem->end);
343 } else if ((curr->rsrc_type & RESTYPE) == IOMASK) {
345 new_io = alloc_resources (curr);
351 * if it didn't find the bus, means PCI dev
352 * came b4 the Primary Bus info, so need to
353 * create a bus rangeno becomes a problem...
354 * Can assign a -1 and then update once the
355 * range actually appears...
357 if (ibmphp_add_resource (new_io) < 0) {
358 newbus = alloc_error_bus (curr, 0, 0);
361 newbus->firstIO = new_io;
362 ++newbus->needIOUpdate;
363 new_io->rangeno = -1;
365 debug ("IO resource for device %x, bus %x, [%x - %x]\n", new_io->devfunc, new_io->busno, new_io->start, new_io->end);
370 list_for_each (tmp, &gbuses) {
371 bus_cur = list_entry (tmp, struct bus_node, bus_list);
372 /* This is to get info about PPB resources, since EBDA doesn't put this info into the primary bus info */
373 rc = update_bridge_ranges (&bus_cur);
377 rc = once_over (); /* This is to align ranges (so no -1) */
383 /********************************************************************************
384 * This function adds a range into a sorted list of ranges per bus for a particular
385 * range type, it then calls another routine to update the range numbers on the
386 * pci devices' resources for the appropriate resource
388 * Input: type of the resource, range to add, current bus
389 * Output: 0 or -1, bus and range ptrs
390 ********************************************************************************/
391 static int add_range (int type, struct range_node *range, struct bus_node *bus_cur)
393 struct range_node *range_cur = NULL;
394 struct range_node *range_prev;
395 int count = 0, i_init;
400 range_cur = bus_cur->rangeMem;
401 noRanges = bus_cur->noMemRanges;
404 range_cur = bus_cur->rangePFMem;
405 noRanges = bus_cur->noPFMemRanges;
408 range_cur = bus_cur->rangeIO;
409 noRanges = bus_cur->noIORanges;
415 if (range->start < range_cur->start)
417 range_prev = range_cur;
418 range_cur = range_cur->next;
422 /* our range will go at the beginning of the list */
425 bus_cur->rangeMem = range;
428 bus_cur->rangePFMem = range;
431 bus_cur->rangeIO = range;
434 range->next = range_cur;
437 } else if (!range_cur) {
438 /* our range will go at the end of the list */
440 range_prev->next = range;
441 range->rangeno = range_prev->rangeno + 1;
444 /* the range is in the middle */
445 range_prev->next = range;
446 range->next = range_cur;
447 range->rangeno = range_cur->rangeno;
448 i_init = range_prev->rangeno;
451 for (count = i_init; count < noRanges; ++count) {
452 ++range_cur->rangeno;
453 range_cur = range_cur->next;
456 update_resources (bus_cur, type, i_init + 1);
460 /*******************************************************************************
461 * This routine goes through the list of resources of type 'type' and updates
462 * the range numbers that they correspond to. It was called from add_range fnc
464 * Input: bus, type of the resource, the rangeno starting from which to update
465 ******************************************************************************/
466 static void update_resources (struct bus_node *bus_cur, int type, int rangeno)
468 struct resource_node *res = NULL;
469 u8 eol = FALSE; /* end of list indicator */
473 if (bus_cur->firstMem)
474 res = bus_cur->firstMem;
477 if (bus_cur->firstPFMem)
478 res = bus_cur->firstPFMem;
481 if (bus_cur->firstIO)
482 res = bus_cur->firstIO;
488 if (res->rangeno == rangeno)
492 else if (res->nextRange)
493 res = res->nextRange;
501 /* found the range */
510 static void fix_me (struct resource_node *res, struct bus_node *bus_cur, struct range_node *range)
526 if (res->rangeno == -1) {
528 if ((res->start >= range->start) && (res->end <= range->end)) {
529 res->rangeno = range->rangeno;
530 debug ("%s->rangeno in fix_resources is %d\n", str, res->rangeno);
533 --bus_cur->needIOUpdate;
536 --bus_cur->needMemUpdate;
539 --bus_cur->needPFMemUpdate;
550 res = res->nextRange;
555 /*****************************************************************************
556 * This routine reassigns the range numbers to the resources that had a -1
557 * This case can happen only if upon initialization, resources taken by pci dev
558 * appear in EBDA before the resources allocated for that bus, since we don't
559 * know the range, we assign -1, and this routine is called after a new range
560 * is assigned to see the resources with unknown range belong to the added range
563 * Output: none, list of resources for that bus are fixed if can be
564 *******************************************************************************/
565 static void fix_resources (struct bus_node *bus_cur)
567 struct range_node *range;
568 struct resource_node *res;
570 debug ("%s - bus_cur->busno = %d\n", __FUNCTION__, bus_cur->busno);
572 if (bus_cur->needIOUpdate) {
573 res = bus_cur->firstIO;
574 range = bus_cur->rangeIO;
575 fix_me (res, bus_cur, range);
577 if (bus_cur->needMemUpdate) {
578 res = bus_cur->firstMem;
579 range = bus_cur->rangeMem;
580 fix_me (res, bus_cur, range);
582 if (bus_cur->needPFMemUpdate) {
583 res = bus_cur->firstPFMem;
584 range = bus_cur->rangePFMem;
585 fix_me (res, bus_cur, range);
589 /*******************************************************************************
590 * This routine adds a resource to the list of resources to the appropriate bus
591 * based on their resource type and sorted by their starting addresses. It assigns
592 * the ptrs to next and nextRange if needed.
594 * Input: resource ptr
595 * Output: ptrs assigned (to the node)
597 *******************************************************************************/
598 int ibmphp_add_resource (struct resource_node *res)
600 struct resource_node *res_cur;
601 struct resource_node *res_prev;
602 struct bus_node *bus_cur;
603 struct range_node *range_cur = NULL;
604 struct resource_node *res_start = NULL;
606 debug ("%s - enter\n", __FUNCTION__);
609 err ("NULL passed to add\n");
613 bus_cur = find_bus_wprev (res->busno, NULL, 0);
616 /* didn't find a bus, smth's wrong!!! */
617 debug ("no bus in the system, either pci_dev's wrong or allocation failed\n");
624 range_cur = bus_cur->rangeIO;
625 res_start = bus_cur->firstIO;
628 range_cur = bus_cur->rangeMem;
629 res_start = bus_cur->firstMem;
632 range_cur = bus_cur->rangePFMem;
633 res_start = bus_cur->firstPFMem;
636 err ("cannot read the type of the resource to add... problem\n");
640 if ((res->start >= range_cur->start) && (res->end <= range_cur->end)) {
641 res->rangeno = range_cur->rangeno;
644 range_cur = range_cur->next;
647 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
648 * this is again the case of rangeno = -1
649 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
655 ++bus_cur->needIOUpdate;
658 ++bus_cur->needMemUpdate;
661 ++bus_cur->needPFMemUpdate;
667 debug ("The range is %d\n", res->rangeno);
669 /* no first{IO,Mem,Pfmem} on the bus, 1st IO/Mem/Pfmem resource ever */
672 bus_cur->firstIO = res;
675 bus_cur->firstMem = res;
678 bus_cur->firstPFMem = res;
682 res->nextRange = NULL;
687 debug ("res_cur->rangeno is %d\n", res_cur->rangeno);
690 if (res_cur->rangeno >= res->rangeno)
694 res_cur = res_cur->next;
696 res_cur = res_cur->nextRange;
700 /* at the end of the resource list */
701 debug ("i should be here, [%x - %x]\n", res->start, res->end);
702 res_prev->nextRange = res;
704 res->nextRange = NULL;
705 } else if (res_cur->rangeno == res->rangeno) {
706 /* in the same range */
708 if (res->start < res_cur->start)
711 res_cur = res_cur->next;
714 /* the last resource in this range */
715 res_prev->next = res;
717 res->nextRange = res_prev->nextRange;
718 res_prev->nextRange = NULL;
719 } else if (res->start < res_cur->start) {
720 /* at the beginning or middle of the range */
724 bus_cur->firstIO = res;
727 bus_cur->firstMem = res;
730 bus_cur->firstPFMem = res;
733 } else if (res_prev->rangeno == res_cur->rangeno)
734 res_prev->next = res;
736 res_prev->nextRange = res;
739 res->nextRange = NULL;
742 /* this is the case where it is 1st occurrence of the range */
744 /* at the beginning of the resource list */
748 res->nextRange = bus_cur->firstIO;
749 bus_cur->firstIO = res;
752 res->nextRange = bus_cur->firstMem;
753 bus_cur->firstMem = res;
756 res->nextRange = bus_cur->firstPFMem;
757 bus_cur->firstPFMem = res;
760 } else if (res_cur->rangeno > res->rangeno) {
761 /* in the middle of the resource list */
762 res_prev->nextRange = res;
764 res->nextRange = res_cur;
769 debug ("%s - exit\n", __FUNCTION__);
773 /****************************************************************************
774 * This routine will remove the resource from the list of resources
776 * Input: io, mem, and/or pfmem resource to be deleted
777 * Ouput: modified resource list
779 ****************************************************************************/
780 int ibmphp_remove_resource (struct resource_node *res)
782 struct bus_node *bus_cur;
783 struct resource_node *res_cur = NULL;
784 struct resource_node *res_prev;
785 struct resource_node *mem_cur;
789 err ("resource to remove is NULL\n");
793 bus_cur = find_bus_wprev (res->busno, NULL, 0);
796 err ("cannot find corresponding bus of the io resource to remove "
803 res_cur = bus_cur->firstIO;
807 res_cur = bus_cur->firstMem;
811 res_cur = bus_cur->firstPFMem;
815 err ("unknown type for resource to remove\n");
821 if ((res_cur->start == res->start) && (res_cur->end == res->end))
825 res_cur = res_cur->next;
827 res_cur = res_cur->nextRange;
831 if (res->type == PFMEM) {
833 * case where pfmem might be in the PFMemFromMem list
834 * so will also need to remove the corresponding mem
837 res_cur = bus_cur->firstPFMemFromMem;
841 if ((res_cur->start == res->start) && (res_cur->end == res->end)) {
842 mem_cur = bus_cur->firstMem;
844 if ((mem_cur->start == res_cur->start)
845 && (mem_cur->end == res_cur->end))
848 mem_cur = mem_cur->next;
850 mem_cur = mem_cur->nextRange;
853 err ("cannot find corresponding mem node for pfmem...\n");
857 ibmphp_remove_resource (mem_cur);
859 bus_cur->firstPFMemFromMem = res_cur->next;
861 res_prev->next = res_cur->next;
867 res_cur = res_cur->next;
869 res_cur = res_cur->nextRange;
872 err ("cannot find pfmem to delete...\n");
876 err ("the %s resource is not in the list to be deleted...\n", type);
881 /* first device to be deleted */
885 bus_cur->firstIO = res_cur->next;
888 bus_cur->firstMem = res_cur->next;
891 bus_cur->firstPFMem = res_cur->next;
894 } else if (res_cur->nextRange) {
897 bus_cur->firstIO = res_cur->nextRange;
900 bus_cur->firstMem = res_cur->nextRange;
903 bus_cur->firstPFMem = res_cur->nextRange;
909 bus_cur->firstIO = NULL;
912 bus_cur->firstMem = NULL;
915 bus_cur->firstPFMem = NULL;
923 if (res_prev->rangeno == res_cur->rangeno)
924 res_prev->next = res_cur->next;
926 res_prev->nextRange = res_cur->next;
927 } else if (res_cur->nextRange) {
928 res_prev->next = NULL;
929 res_prev->nextRange = res_cur->nextRange;
931 res_prev->next = NULL;
932 res_prev->nextRange = NULL;
941 static struct range_node * find_range (struct bus_node *bus_cur, struct resource_node * res)
943 struct range_node * range = NULL;
947 range = bus_cur->rangeIO;
950 range = bus_cur->rangeMem;
953 range = bus_cur->rangePFMem;
956 err ("cannot read resource type in find_range\n");
960 if (res->rangeno == range->rangeno)
967 /*****************************************************************************
968 * This routine will check to make sure the io/mem/pfmem->len that the device asked for
969 * can fit w/i our list of available IO/MEM/PFMEM resources. If cannot, returns -EINVAL,
970 * otherwise, returns 0
973 * Ouput: the correct start and end address are inputted into the resource node,
975 *****************************************************************************/
976 int ibmphp_check_resource (struct resource_node *res, u8 bridge)
978 struct bus_node *bus_cur;
979 struct range_node *range = NULL;
980 struct resource_node *res_prev;
981 struct resource_node *res_cur = NULL;
982 u32 len_cur = 0, start_cur = 0, len_tmp = 0;
984 u32 tmp_start; /* this is to make sure start address is divisible by the length needed */
992 /* The rules for bridges are different, 4K divisible for IO, 1M for (pf)mem*/
994 tmp_divide = IOBRIDGE;
996 tmp_divide = MEMBRIDGE;
998 tmp_divide = res->len;
1000 bus_cur = find_bus_wprev (res->busno, NULL, 0);
1003 /* didn't find a bus, smth's wrong!!! */
1004 debug ("no bus in the system, either pci_dev's wrong or allocation failed\n");
1008 debug ("%s - enter\n", __FUNCTION__);
1009 debug ("bus_cur->busno is %d\n", bus_cur->busno);
1011 /* This is a quick fix to not mess up with the code very much. i.e.,
1012 * 2000-2fff, len = 1000, but when we compare, we need it to be fff */
1015 switch (res->type) {
1017 res_cur = bus_cur->firstIO;
1018 noranges = bus_cur->noIORanges;
1021 res_cur = bus_cur->firstMem;
1022 noranges = bus_cur->noMemRanges;
1025 res_cur = bus_cur->firstPFMem;
1026 noranges = bus_cur->noPFMemRanges;
1029 err ("wrong type of resource to check\n");
1035 range = find_range (bus_cur, res_cur);
1036 debug ("%s - rangeno = %d\n", __FUNCTION__, res_cur->rangeno);
1039 err ("no range for the device exists... bailing out...\n");
1043 /* found our range */
1045 /* first time in the loop */
1046 if ((res_cur->start != range->start) && ((len_tmp = res_cur->start - 1 - range->start) >= res->len)) {
1047 debug ("len_tmp = %x\n", len_tmp);
1049 if ((len_tmp < len_cur) || (len_cur == 0)) {
1051 if ((range->start % tmp_divide) == 0) {
1052 /* just perfect, starting address is divisible by length */
1055 start_cur = range->start;
1057 /* Needs adjusting */
1058 tmp_start = range->start;
1061 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) {
1062 if ((tmp_start % tmp_divide) == 0) {
1065 start_cur = tmp_start;
1068 tmp_start += tmp_divide - tmp_start % tmp_divide;
1069 if (tmp_start >= res_cur->start - 1)
1074 if (flag && len_cur == res->len) {
1075 debug ("but we are not here, right?\n");
1076 res->start = start_cur;
1077 res->len += 1; /* To restore the balance */
1078 res->end = res->start + res->len - 1;
1084 if (!res_cur->next) {
1085 /* last device on the range */
1086 if ((range->end != res_cur->end) && ((len_tmp = range->end - (res_cur->end + 1)) >= res->len)) {
1087 debug ("len_tmp = %x\n", len_tmp);
1088 if ((len_tmp < len_cur) || (len_cur == 0)) {
1090 if (((res_cur->end + 1) % tmp_divide) == 0) {
1091 /* just perfect, starting address is divisible by length */
1094 start_cur = res_cur->end + 1;
1096 /* Needs adjusting */
1097 tmp_start = res_cur->end + 1;
1100 while ((len_tmp = range->end - tmp_start) >= res->len) {
1101 if ((tmp_start % tmp_divide) == 0) {
1104 start_cur = tmp_start;
1107 tmp_start += tmp_divide - tmp_start % tmp_divide;
1108 if (tmp_start >= range->end)
1112 if (flag && len_cur == res->len) {
1113 res->start = start_cur;
1114 res->len += 1; /* To restore the balance */
1115 res->end = res->start + res->len - 1;
1123 if (res_prev->rangeno != res_cur->rangeno) {
1124 /* 1st device on this range */
1125 if ((res_cur->start != range->start) &&
1126 ((len_tmp = res_cur->start - 1 - range->start) >= res->len)) {
1127 if ((len_tmp < len_cur) || (len_cur == 0)) {
1128 if ((range->start % tmp_divide) == 0) {
1129 /* just perfect, starting address is divisible by length */
1132 start_cur = range->start;
1134 /* Needs adjusting */
1135 tmp_start = range->start;
1138 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) {
1139 if ((tmp_start % tmp_divide) == 0) {
1142 start_cur = tmp_start;
1145 tmp_start += tmp_divide - tmp_start % tmp_divide;
1146 if (tmp_start >= res_cur->start - 1)
1151 if (flag && len_cur == res->len) {
1152 res->start = start_cur;
1153 res->len += 1; /* To restore the balance */
1154 res->end = res->start + res->len - 1;
1160 /* in the same range */
1161 if ((len_tmp = res_cur->start - 1 - res_prev->end - 1) >= res->len) {
1162 if ((len_tmp < len_cur) || (len_cur == 0)) {
1163 if (((res_prev->end + 1) % tmp_divide) == 0) {
1164 /* just perfect, starting address's divisible by length */
1167 start_cur = res_prev->end + 1;
1169 /* Needs adjusting */
1170 tmp_start = res_prev->end + 1;
1173 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) {
1174 if ((tmp_start % tmp_divide) == 0) {
1177 start_cur = tmp_start;
1180 tmp_start += tmp_divide - tmp_start % tmp_divide;
1181 if (tmp_start >= res_cur->start - 1)
1186 if (flag && len_cur == res->len) {
1187 res->start = start_cur;
1188 res->len += 1; /* To restore the balance */
1189 res->end = res->start + res->len - 1;
1196 /* end if (res_prev) */
1199 res_cur = res_cur->next;
1201 res_cur = res_cur->nextRange;
1202 } /* end of while */
1206 /* 1st device ever */
1207 /* need to find appropriate range */
1208 switch (res->type) {
1210 range = bus_cur->rangeIO;
1213 range = bus_cur->rangeMem;
1216 range = bus_cur->rangePFMem;
1220 if ((len_tmp = range->end - range->start) >= res->len) {
1221 if ((len_tmp < len_cur) || (len_cur == 0)) {
1222 if ((range->start % tmp_divide) == 0) {
1223 /* just perfect, starting address's divisible by length */
1226 start_cur = range->start;
1228 /* Needs adjusting */
1229 tmp_start = range->start;
1232 while ((len_tmp = range->end - tmp_start) >= res->len) {
1233 if ((tmp_start % tmp_divide) == 0) {
1236 start_cur = tmp_start;
1239 tmp_start += tmp_divide - tmp_start % tmp_divide;
1240 if (tmp_start >= range->end)
1245 if (flag && len_cur == res->len) {
1246 res->start = start_cur;
1247 res->len += 1; /* To restore the balance */
1248 res->end = res->start + res->len - 1;
1253 range = range->next;
1254 } /* end of while */
1256 if ((!range) && (len_cur == 0)) {
1257 /* have gone through the list of devices and ranges and haven't found n.e.thing */
1258 err ("no appropriate range.. bailing out...\n");
1260 } else if (len_cur) {
1261 res->start = start_cur;
1262 res->len += 1; /* To restore the balance */
1263 res->end = res->start + res->len - 1;
1269 debug ("prev->rangeno = %d, noranges = %d\n", res_prev->rangeno, noranges);
1270 if (res_prev->rangeno < noranges) {
1271 /* if there're more ranges out there to check */
1272 switch (res->type) {
1274 range = bus_cur->rangeIO;
1277 range = bus_cur->rangeMem;
1280 range = bus_cur->rangePFMem;
1284 if ((len_tmp = range->end - range->start) >= res->len) {
1285 if ((len_tmp < len_cur) || (len_cur == 0)) {
1286 if ((range->start % tmp_divide) == 0) {
1287 /* just perfect, starting address's divisible by length */
1290 start_cur = range->start;
1292 /* Needs adjusting */
1293 tmp_start = range->start;
1296 while ((len_tmp = range->end - tmp_start) >= res->len) {
1297 if ((tmp_start % tmp_divide) == 0) {
1300 start_cur = tmp_start;
1303 tmp_start += tmp_divide - tmp_start % tmp_divide;
1304 if (tmp_start >= range->end)
1309 if (flag && len_cur == res->len) {
1310 res->start = start_cur;
1311 res->len += 1; /* To restore the balance */
1312 res->end = res->start + res->len - 1;
1317 range = range->next;
1318 } /* end of while */
1320 if ((!range) && (len_cur == 0)) {
1321 /* have gone through the list of devices and ranges and haven't found n.e.thing */
1322 err ("no appropriate range.. bailing out...\n");
1324 } else if (len_cur) {
1325 res->start = start_cur;
1326 res->len += 1; /* To restore the balance */
1327 res->end = res->start + res->len - 1;
1331 /* no more ranges to check on */
1333 res->start = start_cur;
1334 res->len += 1; /* To restore the balance */
1335 res->end = res->start + res->len - 1;
1338 /* have gone through the list of devices and haven't found n.e.thing */
1339 err ("no appropriate range.. bailing out...\n");
1343 } /* end if(!res_cur) */
1347 /********************************************************************************
1348 * This routine is called from remove_card if the card contained PPB.
1349 * It will remove all the resources on the bus as well as the bus itself
1352 ********************************************************************************/
1353 int ibmphp_remove_bus (struct bus_node *bus, u8 parent_busno)
1355 struct resource_node *res_cur;
1356 struct resource_node *res_tmp;
1357 struct bus_node *prev_bus;
1360 prev_bus = find_bus_wprev (parent_busno, NULL, 0);
1363 debug ("something terribly wrong. Cannot find parent bus to the one to remove\n");
1367 debug ("In ibmphp_remove_bus... prev_bus->busno is %x\n", prev_bus->busno);
1369 rc = remove_ranges (bus, prev_bus);
1374 res_cur = bus->firstIO;
1378 res_cur = res_cur->next;
1380 res_cur = res_cur->nextRange;
1384 bus->firstIO = NULL;
1386 if (bus->firstMem) {
1387 res_cur = bus->firstMem;
1391 res_cur = res_cur->next;
1393 res_cur = res_cur->nextRange;
1397 bus->firstMem = NULL;
1399 if (bus->firstPFMem) {
1400 res_cur = bus->firstPFMem;
1404 res_cur = res_cur->next;
1406 res_cur = res_cur->nextRange;
1410 bus->firstPFMem = NULL;
1413 if (bus->firstPFMemFromMem) {
1414 res_cur = bus->firstPFMemFromMem;
1417 res_cur = res_cur->next;
1422 bus->firstPFMemFromMem = NULL;
1425 list_del (&bus->bus_list);
1430 /******************************************************************************
1431 * This routine deletes the ranges from a given bus, and the entries from the
1432 * parent's bus in the resources
1433 * Input: current bus, previous bus
1434 * Output: 0, -EINVAL
1435 ******************************************************************************/
1436 static int remove_ranges (struct bus_node *bus_cur, struct bus_node *bus_prev)
1438 struct range_node *range_cur;
1439 struct range_node *range_tmp;
1441 struct resource_node *res = NULL;
1443 if (bus_cur->noIORanges) {
1444 range_cur = bus_cur->rangeIO;
1445 for (i = 0; i < bus_cur->noIORanges; i++) {
1446 if (ibmphp_find_resource (bus_prev, range_cur->start, &res, IO) < 0)
1448 ibmphp_remove_resource (res);
1450 range_tmp = range_cur;
1451 range_cur = range_cur->next;
1455 bus_cur->rangeIO = NULL;
1457 if (bus_cur->noMemRanges) {
1458 range_cur = bus_cur->rangeMem;
1459 for (i = 0; i < bus_cur->noMemRanges; i++) {
1460 if (ibmphp_find_resource (bus_prev, range_cur->start, &res, MEM) < 0)
1463 ibmphp_remove_resource (res);
1464 range_tmp = range_cur;
1465 range_cur = range_cur->next;
1469 bus_cur->rangeMem = NULL;
1471 if (bus_cur->noPFMemRanges) {
1472 range_cur = bus_cur->rangePFMem;
1473 for (i = 0; i < bus_cur->noPFMemRanges; i++) {
1474 if (ibmphp_find_resource (bus_prev, range_cur->start, &res, PFMEM) < 0)
1477 ibmphp_remove_resource (res);
1478 range_tmp = range_cur;
1479 range_cur = range_cur->next;
1483 bus_cur->rangePFMem = NULL;
1489 * find the resource node in the bus
1490 * Input: Resource needed, start address of the resource, type of resource
1492 int ibmphp_find_resource (struct bus_node *bus, u32 start_address, struct resource_node **res, int flag)
1494 struct resource_node *res_cur = NULL;
1498 err ("The bus passed in NULL to find resource\n");
1504 res_cur = bus->firstIO;
1508 res_cur = bus->firstMem;
1512 res_cur = bus->firstPFMem;
1516 err ("wrong type of flag\n");
1521 if (res_cur->start == start_address) {
1526 res_cur = res_cur->next;
1528 res_cur = res_cur->nextRange;
1532 if (flag == PFMEM) {
1533 res_cur = bus->firstPFMemFromMem;
1535 if (res_cur->start == start_address) {
1539 res_cur = res_cur->next;
1542 debug ("SOS...cannot find %s resource in the bus.\n", type);
1546 debug ("SOS... cannot find %s resource in the bus.\n", type);
1552 debug ("*res->start = %x\n", (*res)->start);
1557 /***********************************************************************
1558 * This routine will free the resource structures used by the
1559 * system. It is called from cleanup routine for the module
1562 ***********************************************************************/
1563 void ibmphp_free_resources (void)
1565 struct bus_node *bus_cur = NULL;
1566 struct bus_node *bus_tmp;
1567 struct range_node *range_cur;
1568 struct range_node *range_tmp;
1569 struct resource_node *res_cur;
1570 struct resource_node *res_tmp;
1571 struct list_head *tmp;
1572 struct list_head *next;
1576 list_for_each_safe (tmp, next, &gbuses) {
1577 bus_cur = list_entry (tmp, struct bus_node, bus_list);
1578 if (bus_cur->noIORanges) {
1579 range_cur = bus_cur->rangeIO;
1580 for (i = 0; i < bus_cur->noIORanges; i++) {
1583 range_tmp = range_cur;
1584 range_cur = range_cur->next;
1589 if (bus_cur->noMemRanges) {
1590 range_cur = bus_cur->rangeMem;
1591 for (i = 0; i < bus_cur->noMemRanges; i++) {
1594 range_tmp = range_cur;
1595 range_cur = range_cur->next;
1600 if (bus_cur->noPFMemRanges) {
1601 range_cur = bus_cur->rangePFMem;
1602 for (i = 0; i < bus_cur->noPFMemRanges; i++) {
1605 range_tmp = range_cur;
1606 range_cur = range_cur->next;
1612 if (bus_cur->firstIO) {
1613 res_cur = bus_cur->firstIO;
1617 res_cur = res_cur->next;
1619 res_cur = res_cur->nextRange;
1623 bus_cur->firstIO = NULL;
1625 if (bus_cur->firstMem) {
1626 res_cur = bus_cur->firstMem;
1630 res_cur = res_cur->next;
1632 res_cur = res_cur->nextRange;
1636 bus_cur->firstMem = NULL;
1638 if (bus_cur->firstPFMem) {
1639 res_cur = bus_cur->firstPFMem;
1643 res_cur = res_cur->next;
1645 res_cur = res_cur->nextRange;
1649 bus_cur->firstPFMem = NULL;
1652 if (bus_cur->firstPFMemFromMem) {
1653 res_cur = bus_cur->firstPFMemFromMem;
1656 res_cur = res_cur->next;
1661 bus_cur->firstPFMemFromMem = NULL;
1665 list_del (&bus_cur->bus_list);
1671 /*********************************************************************************
1672 * This function will go over the PFmem resources to check if the EBDA allocated
1673 * pfmem out of memory buckets of the bus. If so, it will change the range numbers
1674 * and a flag to indicate that this resource is out of memory. It will also move the
1675 * Pfmem out of the pfmem resource list to the PFMemFromMem list, and will create
1677 * This routine is called right after initialization
1678 *******************************************************************************/
1679 static int __init once_over (void)
1681 struct resource_node *pfmem_cur;
1682 struct resource_node *pfmem_prev;
1683 struct resource_node *mem;
1684 struct bus_node *bus_cur;
1685 struct list_head *tmp;
1687 list_for_each (tmp, &gbuses) {
1688 bus_cur = list_entry (tmp, struct bus_node, bus_list);
1689 if ((!bus_cur->rangePFMem) && (bus_cur->firstPFMem)) {
1690 for (pfmem_cur = bus_cur->firstPFMem, pfmem_prev = NULL; pfmem_cur; pfmem_prev = pfmem_cur, pfmem_cur = pfmem_cur->next) {
1691 pfmem_cur->fromMem = TRUE;
1693 pfmem_prev->next = pfmem_cur->next;
1695 bus_cur->firstPFMem = pfmem_cur->next;
1697 if (!bus_cur->firstPFMemFromMem)
1698 pfmem_cur->next = NULL;
1700 /* we don't need to sort PFMemFromMem since we're using mem node for
1701 all the real work anyways, so just insert at the beginning of the
1704 pfmem_cur->next = bus_cur->firstPFMemFromMem;
1706 bus_cur->firstPFMemFromMem = pfmem_cur;
1708 mem = kmalloc (sizeof (struct resource_node), GFP_KERNEL);
1710 err ("out of system memory\n");
1713 memset (mem, 0, sizeof (struct resource_node));
1715 mem->busno = pfmem_cur->busno;
1716 mem->devfunc = pfmem_cur->devfunc;
1717 mem->start = pfmem_cur->start;
1718 mem->end = pfmem_cur->end;
1719 mem->len = pfmem_cur->len;
1720 if (ibmphp_add_resource (mem) < 0)
1721 err ("Trouble...trouble... EBDA allocated pfmem from mem, but system doesn't display it has this space... unless not PCI device...\n");
1722 pfmem_cur->rangeno = mem->rangeno;
1723 } /* end for pfmem */
1725 } /* end list_for_each bus */
1729 int ibmphp_add_pfmem_from_mem (struct resource_node *pfmem)
1731 struct bus_node *bus_cur = find_bus_wprev (pfmem->busno, NULL, 0);
1734 err ("cannot find bus of pfmem to add...\n");
1738 if (bus_cur->firstPFMemFromMem)
1739 pfmem->next = bus_cur->firstPFMemFromMem;
1743 bus_cur->firstPFMemFromMem = pfmem;
1748 /* This routine just goes through the buses to see if the bus already exists.
1749 * It is called from ibmphp_find_sec_number, to find out a secondary bus number for
1751 * Parameters: bus_number
1752 * Returns: Bus pointer or NULL
1754 struct bus_node *ibmphp_find_res_bus (u8 bus_number)
1756 return find_bus_wprev (bus_number, NULL, 0);
1759 static struct bus_node *find_bus_wprev (u8 bus_number, struct bus_node **prev, u8 flag)
1761 struct bus_node *bus_cur;
1762 struct list_head *tmp;
1763 struct list_head *tmp_prev;
1765 list_for_each (tmp, &gbuses) {
1766 tmp_prev = tmp->prev;
1767 bus_cur = list_entry (tmp, struct bus_node, bus_list);
1769 *prev = list_entry (tmp_prev, struct bus_node, bus_list);
1770 if (bus_cur->busno == bus_number)
1777 void ibmphp_print_test (void)
1780 struct bus_node *bus_cur = NULL;
1781 struct range_node *range;
1782 struct resource_node *res;
1783 struct list_head *tmp;
1785 debug_pci ("*****************START**********************\n");
1787 if ((!list_empty(&gbuses)) && flags) {
1788 err ("The GBUSES is not NULL?!?!?!?!?\n");
1792 list_for_each (tmp, &gbuses) {
1793 bus_cur = list_entry (tmp, struct bus_node, bus_list);
1794 debug_pci ("This is bus # %d. There are\n", bus_cur->busno);
1795 debug_pci ("IORanges = %d\t", bus_cur->noIORanges);
1796 debug_pci ("MemRanges = %d\t", bus_cur->noMemRanges);
1797 debug_pci ("PFMemRanges = %d\n", bus_cur->noPFMemRanges);
1798 debug_pci ("The IO Ranges are as follows:\n");
1799 if (bus_cur->rangeIO) {
1800 range = bus_cur->rangeIO;
1801 for (i = 0; i < bus_cur->noIORanges; i++) {
1802 debug_pci ("rangeno is %d\n", range->rangeno);
1803 debug_pci ("[%x - %x]\n", range->start, range->end);
1804 range = range->next;
1808 debug_pci ("The Mem Ranges are as follows:\n");
1809 if (bus_cur->rangeMem) {
1810 range = bus_cur->rangeMem;
1811 for (i = 0; i < bus_cur->noMemRanges; i++) {
1812 debug_pci ("rangeno is %d\n", range->rangeno);
1813 debug_pci ("[%x - %x]\n", range->start, range->end);
1814 range = range->next;
1818 debug_pci ("The PFMem Ranges are as follows:\n");
1820 if (bus_cur->rangePFMem) {
1821 range = bus_cur->rangePFMem;
1822 for (i = 0; i < bus_cur->noPFMemRanges; i++) {
1823 debug_pci ("rangeno is %d\n", range->rangeno);
1824 debug_pci ("[%x - %x]\n", range->start, range->end);
1825 range = range->next;
1829 debug_pci ("The resources on this bus are as follows\n");
1831 debug_pci ("IO...\n");
1832 if (bus_cur->firstIO) {
1833 res = bus_cur->firstIO;
1835 debug_pci ("The range # is %d\n", res->rangeno);
1836 debug_pci ("The bus, devfnc is %d, %x\n", res->busno, res->devfunc);
1837 debug_pci ("[%x - %x], len=%x\n", res->start, res->end, res->len);
1840 else if (res->nextRange)
1841 res = res->nextRange;
1846 debug_pci ("Mem...\n");
1847 if (bus_cur->firstMem) {
1848 res = bus_cur->firstMem;
1850 debug_pci ("The range # is %d\n", res->rangeno);
1851 debug_pci ("The bus, devfnc is %d, %x\n", res->busno, res->devfunc);
1852 debug_pci ("[%x - %x], len=%x\n", res->start, res->end, res->len);
1855 else if (res->nextRange)
1856 res = res->nextRange;
1861 debug_pci ("PFMem...\n");
1862 if (bus_cur->firstPFMem) {
1863 res = bus_cur->firstPFMem;
1865 debug_pci ("The range # is %d\n", res->rangeno);
1866 debug_pci ("The bus, devfnc is %d, %x\n", res->busno, res->devfunc);
1867 debug_pci ("[%x - %x], len=%x\n", res->start, res->end, res->len);
1870 else if (res->nextRange)
1871 res = res->nextRange;
1877 debug_pci ("PFMemFromMem...\n");
1878 if (bus_cur->firstPFMemFromMem) {
1879 res = bus_cur->firstPFMemFromMem;
1881 debug_pci ("The range # is %d\n", res->rangeno);
1882 debug_pci ("The bus, devfnc is %d, %x\n", res->busno, res->devfunc);
1883 debug_pci ("[%x - %x], len=%x\n", res->start, res->end, res->len);
1888 debug_pci ("***********************END***********************\n");
1891 static int range_exists_already (struct range_node * range, struct bus_node * bus_cur, u8 type)
1893 struct range_node * range_cur = NULL;
1896 range_cur = bus_cur->rangeIO;
1899 range_cur = bus_cur->rangeMem;
1902 range_cur = bus_cur->rangePFMem;
1905 err ("wrong type passed to find out if range already exists\n");
1910 if ((range_cur->start == range->start) && (range_cur->end == range->end))
1912 range_cur = range_cur->next;
1918 /* This routine will read the windows for any PPB we have and update the
1919 * range info for the secondary bus, and will also input this info into
1920 * primary bus, since BIOS doesn't. This is for PPB that are in the system
1921 * on bootup. For bridged cards that were added during previous load of the
1922 * driver, only the ranges and the bus structure are added, the devices are
1924 * Input: primary busno
1926 * Note: this function doesn't take into account IO restrictions etc,
1927 * so will only work for bridges with no video/ISA devices behind them It
1928 * also will not work for onboard PPB's that can have more than 1 *bus
1929 * behind them All these are TO DO.
1930 * Also need to add more error checkings... (from fnc returns etc)
1932 static int __init update_bridge_ranges (struct bus_node **bus)
1934 u8 sec_busno, device, function, hdr_type, start_io_address, end_io_address;
1935 u16 vendor_id, upper_io_start, upper_io_end, start_mem_address, end_mem_address;
1936 u32 start_address, end_address, upper_start, upper_end;
1937 struct bus_node *bus_sec;
1938 struct bus_node *bus_cur;
1939 struct resource_node *io;
1940 struct resource_node *mem;
1941 struct resource_node *pfmem;
1942 struct range_node *range;
1948 ibmphp_pci_bus->number = bus_cur->busno;
1950 debug ("inside %s\n", __FUNCTION__);
1951 debug ("bus_cur->busno = %x\n", bus_cur->busno);
1953 for (device = 0; device < 32; device++) {
1954 for (function = 0x00; function < 0x08; function++) {
1955 devfn = PCI_DEVFN(device, function);
1956 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_VENDOR_ID, &vendor_id);
1958 if (vendor_id != PCI_VENDOR_ID_NOTVALID) {
1959 /* found correct device!!! */
1960 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_HEADER_TYPE, &hdr_type);
1963 case PCI_HEADER_TYPE_NORMAL:
1966 case PCI_HEADER_TYPE_MULTIDEVICE:
1968 case PCI_HEADER_TYPE_BRIDGE:
1970 case PCI_HEADER_TYPE_MULTIBRIDGE:
1971 /* We assume here that only 1 bus behind the bridge
1972 TO DO: add functionality for several:
1974 while (temp < subordinate) {
1979 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_SECONDARY_BUS, &sec_busno);
1980 bus_sec = find_bus_wprev (sec_busno, NULL, 0);
1981 /* this bus structure doesn't exist yet, PPB was configured during previous loading of ibmphp */
1983 bus_sec = alloc_error_bus (NULL, sec_busno, 1);
1984 /* the rest will be populated during NVRAM call */
1987 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_IO_BASE, &start_io_address);
1988 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_IO_LIMIT, &end_io_address);
1989 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_IO_BASE_UPPER16, &upper_io_start);
1990 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_IO_LIMIT_UPPER16, &upper_io_end);
1991 start_address = (start_io_address & PCI_IO_RANGE_MASK) << 8;
1992 start_address |= (upper_io_start << 16);
1993 end_address = (end_io_address & PCI_IO_RANGE_MASK) << 8;
1994 end_address |= (upper_io_end << 16);
1996 if ((start_address) && (start_address <= end_address)) {
1997 range = kmalloc (sizeof (struct range_node), GFP_KERNEL);
1999 err ("out of system memory\n");
2002 memset (range, 0, sizeof (struct range_node));
2003 range->start = start_address;
2004 range->end = end_address + 0xfff;
2006 if (bus_sec->noIORanges > 0) {
2007 if (!range_exists_already (range, bus_sec, IO)) {
2008 add_range (IO, range, bus_sec);
2009 ++bus_sec->noIORanges;
2015 /* 1st IO Range on the bus */
2017 bus_sec->rangeIO = range;
2018 ++bus_sec->noIORanges;
2020 fix_resources (bus_sec);
2022 if (ibmphp_find_resource (bus_cur, start_address, &io, IO)) {
2023 io = kmalloc (sizeof (struct resource_node), GFP_KERNEL);
2026 err ("out of system memory\n");
2029 memset (io, 0, sizeof (struct resource_node));
2031 io->busno = bus_cur->busno;
2032 io->devfunc = ((device << 3) | (function & 0x7));
2033 io->start = start_address;
2034 io->end = end_address + 0xfff;
2035 io->len = io->end - io->start + 1;
2036 ibmphp_add_resource (io);
2040 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_MEMORY_BASE, &start_mem_address);
2041 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_MEMORY_LIMIT, &end_mem_address);
2043 start_address = 0x00000000 | (start_mem_address & PCI_MEMORY_RANGE_MASK) << 16;
2044 end_address = 0x00000000 | (end_mem_address & PCI_MEMORY_RANGE_MASK) << 16;
2046 if ((start_address) && (start_address <= end_address)) {
2048 range = kmalloc (sizeof (struct range_node), GFP_KERNEL);
2050 err ("out of system memory\n");
2053 memset (range, 0, sizeof (struct range_node));
2054 range->start = start_address;
2055 range->end = end_address + 0xfffff;
2057 if (bus_sec->noMemRanges > 0) {
2058 if (!range_exists_already (range, bus_sec, MEM)) {
2059 add_range (MEM, range, bus_sec);
2060 ++bus_sec->noMemRanges;
2066 /* 1st Mem Range on the bus */
2068 bus_sec->rangeMem = range;
2069 ++bus_sec->noMemRanges;
2072 fix_resources (bus_sec);
2074 if (ibmphp_find_resource (bus_cur, start_address, &mem, MEM)) {
2075 mem = kmalloc (sizeof (struct resource_node), GFP_KERNEL);
2078 err ("out of system memory\n");
2081 memset (mem, 0, sizeof (struct resource_node));
2083 mem->busno = bus_cur->busno;
2084 mem->devfunc = ((device << 3) | (function & 0x7));
2085 mem->start = start_address;
2086 mem->end = end_address + 0xfffff;
2087 mem->len = mem->end - mem->start + 1;
2088 ibmphp_add_resource (mem);
2091 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_PREF_MEMORY_BASE, &start_mem_address);
2092 pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, &end_mem_address);
2093 pci_bus_read_config_dword (ibmphp_pci_bus, devfn, PCI_PREF_BASE_UPPER32, &upper_start);
2094 pci_bus_read_config_dword (ibmphp_pci_bus, devfn, PCI_PREF_LIMIT_UPPER32, &upper_end);
2095 start_address = 0x00000000 | (start_mem_address & PCI_MEMORY_RANGE_MASK) << 16;
2096 end_address = 0x00000000 | (end_mem_address & PCI_MEMORY_RANGE_MASK) << 16;
2097 #if BITS_PER_LONG == 64
2098 start_address |= ((long) upper_start) << 32;
2099 end_address |= ((long) upper_end) << 32;
2102 if ((start_address) && (start_address <= end_address)) {
2104 range = kmalloc (sizeof (struct range_node), GFP_KERNEL);
2106 err ("out of system memory\n");
2109 memset (range, 0, sizeof (struct range_node));
2110 range->start = start_address;
2111 range->end = end_address + 0xfffff;
2113 if (bus_sec->noPFMemRanges > 0) {
2114 if (!range_exists_already (range, bus_sec, PFMEM)) {
2115 add_range (PFMEM, range, bus_sec);
2116 ++bus_sec->noPFMemRanges;
2122 /* 1st PFMem Range on the bus */
2124 bus_sec->rangePFMem = range;
2125 ++bus_sec->noPFMemRanges;
2128 fix_resources (bus_sec);
2129 if (ibmphp_find_resource (bus_cur, start_address, &pfmem, PFMEM)) {
2130 pfmem = kmalloc (sizeof (struct resource_node), GFP_KERNEL);
2133 err ("out of system memory\n");
2136 memset (pfmem, 0, sizeof (struct resource_node));
2137 pfmem->type = PFMEM;
2138 pfmem->busno = bus_cur->busno;
2139 pfmem->devfunc = ((device << 3) | (function & 0x7));
2140 pfmem->start = start_address;
2141 pfmem->end = end_address + 0xfffff;
2142 pfmem->len = pfmem->end - pfmem->start + 1;
2143 pfmem->fromMem = FALSE;
2145 ibmphp_add_resource (pfmem);
2149 } /* end of switch */
2150 } /* end if vendor */
2151 } /* end for function */
2152 } /* end for device */