Various cosmetic and coding style fixes in src/devices.
[coreboot.git] / src / devices / device_util.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2003-2004 Linux Networx
5  * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
6  * Copyright (C) 2003 Greg Watson <jarrah@users.sourceforge.net>
7  * Copyright (C) 2004 Li-Ta Lo <ollie@lanl.gov>
8  * Copyright (C) 2005-2006 Tyan
9  * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
10  *
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; version 2 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23  */
24
25 #include <console/console.h>
26 #include <device/device.h>
27 #include <device/path.h>
28 #include <device/pci.h>
29 #include <device/resource.h>
30 #include <string.h>
31
32 /**
33  * See if a device structure exists for path.
34  *
35  * @param parent The bus to find the device on.
36  * @param path The relative path from the bus to the appropriate device.
37  * @return Pointer to a device structure for the device on bus at path
38  *         or 0/NULL if no device is found.
39  */
40 device_t find_dev_path(struct bus *parent, struct device_path *path)
41 {
42         device_t child;
43         for (child = parent->children; child; child = child->sibling) {
44                 if (path_eq(path, &child->path))
45                         break;
46         }
47         return child;
48 }
49
50 /**
51  * See if a device structure already exists and if not allocate it.
52  *
53  * @param parent The bus to find the device on.
54  * @param path The relative path from the bus to the appropriate device.
55  * @return Pointer to a device structure for the device on bus at path.
56  */
57 device_t alloc_find_dev(struct bus *parent, struct device_path *path)
58 {
59         device_t child;
60         child = find_dev_path(parent, path);
61         if (!child)
62                 child = alloc_dev(parent, path);
63         return child;
64 }
65
66 /**
67  * Given a PCI bus and a devfn number, find the device structure.
68  *
69  * @param bus The bus number.
70  * @param devfn A device/function number.
71  * @return Pointer to the device structure (if found), 0 otherwise.
72  */
73 struct device *dev_find_slot(unsigned int bus, unsigned int devfn)
74 {
75         struct device *dev, *result;
76
77         result = 0;
78         for (dev = all_devices; dev; dev = dev->next) {
79                 if ((dev->path.type == DEVICE_PATH_PCI) &&
80                     (dev->bus->secondary == bus) &&
81                     (dev->path.pci.devfn == devfn)) {
82                         result = dev;
83                         break;
84                 }
85         }
86         return result;
87 }
88
89 /**
90  * Given an SMBus bus and a device number, find the device structure.
91  *
92  * @param bus The bus number.
93  * @param addr A device number.
94  * @return Pointer to the device structure (if found), 0 otherwise.
95  */
96 struct device *dev_find_slot_on_smbus(unsigned int bus, unsigned int addr)
97 {
98         struct device *dev, *result;
99
100         result = 0;
101         for (dev = all_devices; dev; dev = dev->next) {
102                 if ((dev->path.type == DEVICE_PATH_I2C) &&
103                     (dev->bus->secondary == bus) &&
104                     (dev->path.i2c.device == addr)) {
105                         result = dev;
106                         break;
107                 }
108         }
109         return result;
110 }
111
112 /**
113  * Find a device of a given vendor and type.
114  *
115  * @param vendor A PCI vendor ID (e.g. 0x8086 for Intel).
116  * @param device A PCI device ID.
117  * @param from Pointer to the device structure, used as a starting point in
118  *             the linked list of all_devices, which can be 0 to start at the
119  *             head of the list (i.e. all_devices).
120  * @return Pointer to the device struct.
121  */
122 struct device *dev_find_device(u16 vendor, u16 device, struct device *from)
123 {
124         if (!from)
125                 from = all_devices;
126         else
127                 from = from->next;
128
129         while (from && (from->vendor != vendor || from->device != device))
130                 from = from->next;
131
132         return from;
133 }
134
135 /**
136  * Find a device of a given class.
137  *
138  * @param class Class of the device.
139  * @param from Pointer to the device structure, used as a starting point in
140  *             the linked list of all_devices, which can be 0 to start at the
141  *             head of the list (i.e. all_devices).
142  * @return Pointer to the device struct.
143  */
144 struct device *dev_find_class(unsigned int class, struct device *from)
145 {
146         if (!from)
147                 from = all_devices;
148         else
149                 from = from->next;
150
151         while (from && (from->class & 0xffffff00) != class)
152                 from = from->next;
153
154         return from;
155 }
156
157 /*
158  * Warning: This function uses a static buffer. Don't call it more than once
159  * from the same print statement!
160  */
161 const char *dev_path(device_t dev)
162 {
163         static char buffer[DEVICE_PATH_MAX];
164
165         buffer[0] = '\0';
166         if (!dev) {
167                 memcpy(buffer, "<null>", 7);
168         } else {
169                 switch(dev->path.type) {
170                 case DEVICE_PATH_ROOT:
171                         memcpy(buffer, "Root Device", 12);
172                         break;
173                 case DEVICE_PATH_PCI:
174 #if CONFIG_PCI_BUS_SEGN_BITS
175                         sprintf(buffer, "PCI: %04x:%02x:%02x.%01x",
176                                 dev->bus->secondary >> 8,
177                                 dev->bus->secondary & 0xff,
178                                 PCI_SLOT(dev->path.pci.devfn),
179                                 PCI_FUNC(dev->path.pci.devfn));
180 #else
181                         sprintf(buffer, "PCI: %02x:%02x.%01x",
182                                 dev->bus->secondary,
183                                 PCI_SLOT(dev->path.pci.devfn),
184                                 PCI_FUNC(dev->path.pci.devfn));
185 #endif
186                         break;
187                 case DEVICE_PATH_PNP:
188                         sprintf(buffer, "PNP: %04x.%01x",
189                                 dev->path.pnp.port, dev->path.pnp.device);
190                         break;
191                 case DEVICE_PATH_I2C:
192                         sprintf(buffer, "I2C: %02x:%02x",
193                                 dev->bus->secondary,
194                                 dev->path.i2c.device);
195                         break;
196                 case DEVICE_PATH_APIC:
197                         sprintf(buffer, "APIC: %02x",
198                                 dev->path.apic.apic_id);
199                         break;
200                 case DEVICE_PATH_PCI_DOMAIN:
201                         sprintf(buffer, "PCI_DOMAIN: %04x",
202                                 dev->path.pci_domain.domain);
203                         break;
204                 case DEVICE_PATH_APIC_CLUSTER:
205                         sprintf(buffer, "APIC_CLUSTER: %01x",
206                                 dev->path.apic_cluster.cluster);
207                         break;
208                 case DEVICE_PATH_CPU:
209                         sprintf(buffer, "CPU: %02x", dev->path.cpu.id);
210                         break;
211                 case DEVICE_PATH_CPU_BUS:
212                         sprintf(buffer, "CPU_BUS: %02x", dev->path.cpu_bus.id);
213                         break;
214                 default:
215                         printk(BIOS_ERR, "Unknown device path type: %d\n",
216                                dev->path.type);
217                         break;
218                 }
219         }
220         return buffer;
221 }
222
223 const char *bus_path(struct bus *bus)
224 {
225         static char buffer[BUS_PATH_MAX];
226         sprintf(buffer, "%s,%d", dev_path(bus->dev), bus->link_num);
227         return buffer;
228 }
229
230 int path_eq(struct device_path *path1, struct device_path *path2)
231 {
232         int equal = 0;
233
234         if (path1->type != path2->type)
235                 return 0;
236
237         switch (path1->type) {
238         case DEVICE_PATH_NONE:
239                 break;
240         case DEVICE_PATH_ROOT:
241                 equal = 1;
242                 break;
243         case DEVICE_PATH_PCI:
244                 equal = (path1->pci.devfn == path2->pci.devfn);
245                 break;
246         case DEVICE_PATH_PNP:
247                 equal = (path1->pnp.port == path2->pnp.port) &&
248                         (path1->pnp.device == path2->pnp.device);
249                 break;
250         case DEVICE_PATH_I2C:
251                 equal = (path1->i2c.device == path2->i2c.device);
252                 break;
253         case DEVICE_PATH_APIC:
254                 equal = (path1->apic.apic_id == path2->apic.apic_id);
255                 break;
256         case DEVICE_PATH_PCI_DOMAIN:
257                 equal = (path1->pci_domain.domain == path2->pci_domain.domain);
258                 break;
259         case DEVICE_PATH_APIC_CLUSTER:
260                 equal = (path1->apic_cluster.cluster
261                          == path2->apic_cluster.cluster);
262                 break;
263         case DEVICE_PATH_CPU:
264                 equal = (path1->cpu.id == path2->cpu.id);
265                 break;
266         case DEVICE_PATH_CPU_BUS:
267                 equal = (path1->cpu_bus.id == path2->cpu_bus.id);
268                 break;
269         default:
270                 printk(BIOS_ERR, "Uknown device type: %d\n", path1->type);
271                 break;
272         }
273
274         return equal;
275 }
276
277 /**
278  * Allocate 64 more resources to the free list.
279  *
280  * @return TODO.
281  */
282 static int allocate_more_resources(void)
283 {
284         int i;
285         struct resource *new_res_list;
286
287         new_res_list = malloc(64 * sizeof(*new_res_list));
288
289         if (new_res_list == NULL)
290                 return 0;
291
292         memset(new_res_list, 0, 64 * sizeof(*new_res_list));
293
294         for (i = 0; i < 64 - 1; i++)
295                 new_res_list[i].next = &new_res_list[i+1];
296
297         free_resources = new_res_list;
298         return 1;
299 }
300
301 /**
302  * Remove resource res from the device's list and add it to the free list.
303  *
304  * @param dev TODO
305  * @param res TODO
306  * @param prev TODO
307  * @return TODO.
308  */
309 static void free_resource(device_t dev, struct resource *res,
310                           struct resource *prev)
311 {
312         if (prev)
313                 prev->next = res->next;
314         else
315                 dev->resource_list = res->next;
316
317         res->next = free_resources;
318         free_resources = res;
319 }
320
321 /**
322  * See if we have unused but allocated resource structures.
323  *
324  * If so remove the allocation.
325  *
326  * @param dev The device to find the resource on.
327  */
328 void compact_resources(device_t dev)
329 {
330         struct resource *res, *next, *prev = NULL;
331
332         /* Move all of the free resources to the end */
333         for (res = dev->resource_list; res; res = next) {
334                 next = res->next;
335                 if (!res->flags)
336                         free_resource(dev, res, prev);
337                 else
338                         prev = res;
339         }
340 }
341
342 /**
343  * See if a resource structure already exists for a given index.
344  *
345  * @param dev The device to find the resource on.
346  * @param index The index of the resource on the device.
347  * @return The resource, if it already exists.
348  */
349 struct resource *probe_resource(device_t dev, unsigned index)
350 {
351         struct resource *res;
352
353         /* See if there is a resource with the appropriate index */
354         for (res = dev->resource_list; res; res = res->next) {
355                 if (res->index == index)
356                         break;
357         }
358
359         return res;
360 }
361
362 /**
363  * See if a resource structure already exists for a given index and if not
364  * allocate one.
365  *
366  * Then initialize the initialize the resource to default values.
367  *
368  * @param dev The device to find the resource on.
369  * @param index The index of the resource on the device.
370  * @return TODO.
371  */
372 struct resource *new_resource(device_t dev, unsigned index)
373 {
374         struct resource *resource, *tail;
375
376         /* First move all of the free resources to the end. */
377         compact_resources(dev);
378
379         /* See if there is a resource with the appropriate index. */
380         resource = probe_resource(dev, index);
381         if (!resource) {
382                 if (free_resources == NULL && !allocate_more_resources())
383                         die("Couldn't allocate more resources.");
384
385                 resource = free_resources;
386                 free_resources = free_resources->next;
387                 memset(resource, 0, sizeof(*resource));
388                 resource->next = NULL;
389                 tail = dev->resource_list;
390                 if (tail) {
391                         while (tail->next) tail = tail->next;
392                         tail->next = resource;
393                 } else {
394                         dev->resource_list = resource;
395                 }
396         }
397
398         /* Initialize the resource values. */
399         if (!(resource->flags & IORESOURCE_FIXED)) {
400                 resource->flags = 0;
401                 resource->base = 0;
402         }
403         resource->size  = 0;
404         resource->limit = 0;
405         resource->index = index;
406         resource->align = 0;
407         resource->gran  = 0;
408
409         return resource;
410 }
411
412 /**
413  * Return an existing resource structure for a given index.
414  *
415  * @param dev The device to find the resource on.
416  * @param index The index of the resource on the device.
417  * return TODO.
418  */
419 struct resource *find_resource(device_t dev, unsigned index)
420 {
421         struct resource *resource;
422
423         /* See if there is a resource with the appropriate index. */
424         resource = probe_resource(dev, index);
425         if (!resource) {
426                 printk(BIOS_EMERG, "%s missing resource: %02x\n",
427                        dev_path(dev), index);
428                 die("");
429         }
430         return resource;
431 }
432
433 /**
434  * Round a number up to the next multiple of gran.
435  *
436  * @param val The starting value.
437  * @param gran Granularity we are aligning the number to.
438  * @return The aligned value.
439  */
440 static resource_t align_up(resource_t val, unsigned long gran)
441 {
442         resource_t mask;
443         mask = (1ULL << gran) - 1ULL;
444         val += mask;
445         val &= ~mask;
446         return val;
447 }
448
449 /**
450  * Round a number up to the previous multiple of gran.
451  *
452  * @param val The starting value.
453  * @param gran Granularity we are aligning the number to.
454  * @return The aligned value.
455  */
456 static resource_t align_down(resource_t val, unsigned long gran)
457 {
458         resource_t mask;
459         mask = (1ULL << gran) - 1ULL;
460         val &= ~mask;
461         return val;
462 }
463
464 /**
465  * Compute the maximum address that is part of a resource.
466  *
467  * @param resource The resource whose limit is desired.
468  * @return The end.
469  */
470 resource_t resource_end(struct resource *resource)
471 {
472         resource_t base, end;
473
474         /* Get the base address. */
475         base = resource->base;
476
477         /*
478          * For a non bridge resource granularity and alignment are the same.
479          * For a bridge resource align is the largest needed alignment below
480          * the bridge. While the granularity is simply how many low bits of
481          * the address cannot be set.
482          */
483
484         /* Get the end (rounded up). */
485         end = base + align_up(resource->size, resource->gran) - 1;
486
487         return end;
488 }
489
490 /**
491  * Compute the maximum legal value for resource->base.
492  *
493  * @param resource The resource whose maximum is desired.
494  * @return The maximum.
495  */
496 resource_t resource_max(struct resource *resource)
497 {
498         resource_t max;
499
500         max = align_down(resource->limit - resource->size + 1, resource->align);
501
502         return max;
503 }
504
505 /**
506  * Return the resource type of a resource.
507  *
508  * @param resource The resource type to decode.
509  * @return TODO.
510  */
511 const char *resource_type(struct resource *resource)
512 {
513         static char buffer[RESOURCE_TYPE_MAX];
514         sprintf(buffer, "%s%s%s%s",
515                 ((resource->flags & IORESOURCE_READONLY) ? "ro" : ""),
516                 ((resource->flags & IORESOURCE_PREFETCH) ? "pref" : ""),
517                 ((resource->flags == 0) ? "unused" :
518                 (resource->flags & IORESOURCE_IO) ? "io" :
519                 (resource->flags & IORESOURCE_DRQ) ? "drq" :
520                 (resource->flags & IORESOURCE_IRQ) ? "irq" :
521                 (resource->flags & IORESOURCE_MEM) ? "mem" : "??????"),
522                 ((resource->flags & IORESOURCE_PCI64) ? "64" : ""));
523         return buffer;
524 }
525
526 /**
527  * Print the resource that was just stored.
528  *
529  * @param dev The device the stored resorce lives on.
530  * @param resource The resource that was just stored.
531  * @param comment TODO
532  */
533 void report_resource_stored(device_t dev, struct resource *resource,
534                             const char *comment)
535 {
536         char buf[10];
537         unsigned long long base, end;
538
539         if (!(resource->flags & IORESOURCE_STORED))
540                 return;
541
542         base = resource->base;
543         end = resource_end(resource);
544         buf[0] = '\0';
545
546         if (resource->flags & IORESOURCE_PCI_BRIDGE) {
547 #if CONFIG_PCI_BUS_SEGN_BITS
548                 sprintf(buf, "bus %04x:%02x ", dev->bus->secondary >> 8,
549                         dev->link_list->secondary & 0xff);
550 #else
551                 sprintf(buf, "bus %02x ", dev->link_list->secondary);
552 #endif
553         }
554         printk(BIOS_DEBUG, "%s %02lx <- [0x%010Lx - 0x%010Lx] size 0x%08Lx "
555                "gran 0x%02x %s%s%s\n", dev_path(dev), resource->index,
556                 base, end, resource->size, resource->gran, buf,
557                 resource_type(resource), comment);
558 }
559
560 void search_bus_resources(struct bus *bus, unsigned long type_mask,
561                           unsigned long type, resource_search_t search,
562                           void *gp)
563 {
564         struct device *curdev;
565
566         for (curdev = bus->children; curdev; curdev = curdev->sibling) {
567                 struct resource *res;
568
569                 /* Ignore disabled devices. */
570                 if (!curdev->enabled)
571                         continue;
572
573                 for (res = curdev->resource_list; res; res = res->next) {
574                         /* If it isn't the right kind of resource ignore it. */
575                         if ((res->flags & type_mask) != type)
576                                 continue;
577
578                         /* If it is a subtractive resource recurse. */
579                         if (res->flags & IORESOURCE_SUBTRACTIVE) {
580                                 struct bus * subbus;
581                                 for (subbus = curdev->link_list; subbus;
582                                      subbus = subbus->next)
583                                         if (subbus->link_num
584                                         == IOINDEX_SUBTRACTIVE_LINK(res->index))
585                                                 break;
586                                 search_bus_resources(subbus, type_mask, type,
587                                                      search, gp);
588                                 continue;
589                         }
590                         search(gp, curdev, res);
591                 }
592         }
593 }
594
595 void search_global_resources(unsigned long type_mask, unsigned long type,
596                              resource_search_t search, void *gp)
597 {
598         struct device *curdev;
599
600         for (curdev = all_devices; curdev; curdev = curdev->next) {
601                 struct resource *res;
602
603                 /* Ignore disabled devices. */
604                 if (!curdev->enabled)
605                         continue;
606
607                 for (res = curdev->resource_list; res; res = res->next) {
608                         /* If it isn't the right kind of resource ignore it. */
609                         if ((res->flags & type_mask) != type)
610                                 continue;
611
612                         /* If it is a subtractive resource ignore it. */
613                         if (res->flags & IORESOURCE_SUBTRACTIVE)
614                                 continue;
615
616                         search(gp, curdev, res);
617                 }
618         }
619 }
620
621 void dev_set_enabled(device_t dev, int enable)
622 {
623         if (dev->enabled == enable)
624                 return;
625
626         dev->enabled = enable;
627         if (dev->ops && dev->ops->enable) {
628                 dev->ops->enable(dev);
629         } else if (dev->chip_ops && dev->chip_ops->enable_dev) {
630                 dev->chip_ops->enable_dev(dev);
631         }
632 }
633
634 void disable_children(struct bus *bus)
635 {
636         device_t child;
637
638         for (child = bus->children; child; child = child->sibling) {
639                 struct bus *link;
640                 for (link = child->link_list; link; link = link->next)
641                         disable_children(link);
642                 dev_set_enabled(child, 0);
643         }
644 }
645
646 static void resource_tree(struct device *root, int debug_level, int depth)
647 {
648         int i = 0;
649         struct device *child;
650         struct bus *link;
651         struct resource *res;
652         char indent[30];        /* If your tree has more levels, it's wrong. */
653
654         for (i = 0; i < depth + 1 && i < 29; i++)
655                 indent[i] = ' ';
656         indent[i] = '\0';
657
658         do_printk(BIOS_DEBUG, "%s%s", indent, dev_path(root));
659         if (root->link_list && root->link_list->children)
660                 do_printk(BIOS_DEBUG, " child on link 0 %s",
661                           dev_path(root->link_list->children));
662         do_printk(BIOS_DEBUG, "\n");
663
664         for (res = root->resource_list; res; res = res->next) {
665                 do_printk(debug_level, "%s%s resource base %llx size %llx "
666                           "align %d gran %d limit %llx flags %lx index %lx\n",
667                           indent, dev_path(root), res->base, res->size,
668                           res->align, res->gran, res->limit, res->flags,
669                           res->index);
670         }
671
672         for (link = root->link_list; link; link = link->next) {
673                 for (child = link->children; child; child = child->sibling)
674                         resource_tree(child, debug_level, depth + 1);
675         }
676 }
677
678 void print_resource_tree(struct device *root, int debug_level, const char *msg)
679 {
680         /* Bail if root is null. */
681         if (!root) {
682                 do_printk(debug_level, "%s passed NULL for root!\n", __func__);
683                 return;
684         }
685
686         /* Bail if not printing to screen. */
687         if (!do_printk(debug_level, "Show resources in subtree (%s)...%s\n",
688                        dev_path(root), msg))
689                 return;
690
691         resource_tree(root, debug_level, 0);
692 }
693
694 void show_devs_tree(struct device *dev, int debug_level, int depth, int linknum)
695 {
696         char depth_str[20] = "";
697         int i;
698         struct device *sibling;
699         struct bus *link;
700
701         for (i = 0; i < depth; i++)
702                 depth_str[i] = ' ';
703         depth_str[i] = '\0';
704
705         do_printk(debug_level, "%s%s: enabled %d\n",
706                   depth_str, dev_path(dev), dev->enabled);
707
708         for (link = dev->link_list; link; link = link->next) {
709                 for (sibling = link->children; sibling;
710                      sibling = sibling->sibling)
711                         show_devs_tree(sibling, debug_level, depth + 1, i);
712         }
713 }
714
715 void show_all_devs_tree(int debug_level, const char *msg)
716 {
717         /* Bail if not printing to screen. */
718         if (!do_printk(debug_level, "Show all devs in tree form...%s\n", msg))
719                 return;
720         show_devs_tree(all_devices, debug_level, 0, -1);
721 }
722
723 void show_devs_subtree(struct device *root, int debug_level, const char *msg)
724 {
725         /* Bail if not printing to screen. */
726         if (!do_printk(debug_level, "Show all devs in subtree %s...%s\n",
727                        dev_path(root), msg))
728                 return;
729         do_printk(debug_level, "%s\n", msg);
730         show_devs_tree(root, debug_level, 0, -1);
731 }
732
733 void show_all_devs(int debug_level, const char *msg)
734 {
735         struct device *dev;
736
737         /* Bail if not printing to screen. */
738         if (!do_printk(debug_level, "Show all devs...%s\n", msg))
739                 return;
740         for (dev = all_devices; dev; dev = dev->next) {
741                 do_printk(debug_level, "%s: enabled %d\n",
742                           dev_path(dev), dev->enabled);
743         }
744 }
745
746 void show_one_resource(int debug_level, struct device *dev,
747                        struct resource *resource, const char *comment)
748 {
749         char buf[10];
750         unsigned long long base, end;
751         base = resource->base;
752         end = resource_end(resource);
753         buf[0] = '\0';
754
755 /*
756         if (resource->flags & IORESOURCE_BRIDGE) {
757 #if CONFIG_PCI_BUS_SEGN_BITS
758                 sprintf(buf, "bus %04x:%02x ", dev->bus->secondary >> 8,
759                         dev->link[0].secondary & 0xff);
760 #else
761                 sprintf(buf, "bus %02x ", dev->link[0].secondary);
762 #endif
763         }
764 */
765
766         do_printk(debug_level, "%s %02lx <- [0x%010llx - 0x%010llx] "
767                   "size 0x%08Lx gran 0x%02x %s%s%s\n", dev_path(dev),
768                   resource->index, base, end, resource->size, resource->gran,
769                   buf, resource_type(resource), comment);
770 }
771
772 void show_all_devs_resources(int debug_level, const char* msg)
773 {
774         struct device *dev;
775
776         if (!do_printk(debug_level, "Show all devs with resources...%s\n", msg))
777                 return;
778
779         for (dev = all_devices; dev; dev = dev->next) {
780                 struct resource *res;
781                 do_printk(debug_level, "%s: enabled %d\n",
782                           dev_path(dev), dev->enabled);
783                 for (res = dev->resource_list; res; res = res->next)
784                         show_one_resource(debug_level, dev, res, "");
785         }
786 }
787
788 void ram_resource(device_t dev, unsigned long index,
789                   unsigned long basek, unsigned long sizek)
790 {
791         struct resource *resource;
792
793         if (!sizek)
794                 return;
795
796         resource = new_resource(dev, index);
797         resource->base = ((resource_t)basek) << 10;
798         resource->size = ((resource_t)sizek) << 10;
799         resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
800                 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
801 }
802
803 void tolm_test(void *gp, struct device *dev, struct resource *new)
804 {
805         struct resource **best_p = gp;
806         struct resource *best;
807
808         best = *best_p;
809
810         if (!best || (best->base > new->base))
811                 best = new;
812
813         *best_p = best;
814 }
815
816 u32 find_pci_tolm(struct bus *bus)
817 {
818         struct resource *min = NULL;
819         u32 tolm;
820
821         search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM,
822                              tolm_test, &min);
823
824         tolm = 0xffffffffUL;
825
826         if (min && tolm > min->base)
827                 tolm = min->base;
828
829         return tolm;
830 }