1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <commonlib/bsd/helpers.h>
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/path.h>
7 #include <device/pci_def.h>
8 #include <device/resource.h>
14 * Given a Local APIC ID, find the device structure.
16 * @param apic_id The Local APIC ID number.
17 * @return Pointer to the device structure (if found), 0 otherwise.
19 struct device
*dev_find_lapic(unsigned int apic_id
)
22 struct device
*result
= NULL
;
24 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
25 if (dev
->path
.type
== DEVICE_PATH_APIC
&&
26 dev
->path
.apic
.apic_id
== apic_id
) {
35 * Find a device of a given vendor and type.
37 * @param vendor A PCI vendor ID (e.g. 0x8086 for Intel).
38 * @param device A PCI device ID.
39 * @param from Pointer to the device structure, used as a starting point in
40 * the linked list of all_devices, which can be 0 to start at the
41 * head of the list (i.e. all_devices).
42 * @return Pointer to the device struct.
44 struct device
*dev_find_device(u16 vendor
, u16 device
, struct device
*from
)
51 while (from
&& (from
->vendor
!= vendor
|| from
->device
!= device
))
58 * Find a device of a given class.
60 * @param class Class of the device.
61 * @param from Pointer to the device structure, used as a starting point in
62 * the linked list of all_devices, which can be 0 to start at the
63 * head of the list (i.e. all_devices).
64 * @return Pointer to the device struct.
66 struct device
*dev_find_class(unsigned int class, struct device
*from
)
73 while (from
&& (from
->class & 0xffffff00) != class)
80 * Encode the device path into 3 bytes for logging to CMOS.
82 * @param dev The device path to encode.
83 * @return Device path encoded into lower 3 bytes of dword.
85 u32
dev_path_encode(const struct device
*dev
)
92 /* Store the device type in 3rd byte. */
93 ret
= dev
->path
.type
<< 16;
95 /* Encode the device specific path in the low word. */
96 switch (dev
->path
.type
) {
97 case DEVICE_PATH_ROOT
:
100 ret
|= dev
->bus
->secondary
<< 8 | dev
->path
.pci
.devfn
;
102 case DEVICE_PATH_PNP
:
103 ret
|= dev
->path
.pnp
.port
<< 8 | dev
->path
.pnp
.device
;
105 case DEVICE_PATH_I2C
:
106 ret
|= dev
->path
.i2c
.mode_10bit
<< 8 | dev
->path
.i2c
.device
;
108 case DEVICE_PATH_APIC
:
109 ret
|= dev
->path
.apic
.apic_id
;
111 case DEVICE_PATH_DOMAIN
:
112 ret
|= dev
->path
.domain
.domain
;
114 case DEVICE_PATH_CPU_CLUSTER
:
115 ret
|= dev
->path
.cpu_cluster
.cluster
;
117 case DEVICE_PATH_CPU
:
118 ret
|= dev
->path
.cpu
.id
;
120 case DEVICE_PATH_CPU_BUS
:
121 ret
|= dev
->path
.cpu_bus
.id
;
123 case DEVICE_PATH_IOAPIC
:
124 ret
|= dev
->path
.ioapic
.ioapic_id
;
126 case DEVICE_PATH_GENERIC
:
127 ret
|= dev
->path
.generic
.subid
<< 8 | dev
->path
.generic
.id
;
129 case DEVICE_PATH_SPI
:
130 ret
|= dev
->path
.spi
.cs
;
132 case DEVICE_PATH_USB
:
133 ret
|= dev
->path
.usb
.port_type
<< 8 | dev
->path
.usb
.port_id
;
135 case DEVICE_PATH_GPIO
:
136 ret
|= dev
->path
.gpio
.id
;
138 case DEVICE_PATH_MDIO
:
139 ret
|= dev
->path
.mdio
.addr
;
141 case DEVICE_PATH_NONE
:
142 case DEVICE_PATH_MMIO
: /* don't care */
151 * Warning: This function uses a static buffer. Don't call it more than once
152 * from the same print statement!
154 const char *dev_path(const struct device
*dev
)
156 static char buffer
[DEVICE_PATH_MAX
];
160 strcpy(buffer
, "<null>");
162 switch (dev
->path
.type
) {
163 case DEVICE_PATH_NONE
:
164 strcpy(buffer
, "NONE");
166 case DEVICE_PATH_ROOT
:
167 strcpy(buffer
, "Root Device");
169 case DEVICE_PATH_PCI
:
170 snprintf(buffer
, sizeof(buffer
),
171 "PCI: %02x:%02x.%01x",
173 PCI_SLOT(dev
->path
.pci
.devfn
),
174 PCI_FUNC(dev
->path
.pci
.devfn
));
176 case DEVICE_PATH_PNP
:
177 snprintf(buffer
, sizeof(buffer
), "PNP: %04x.%01x",
178 dev
->path
.pnp
.port
, dev
->path
.pnp
.device
);
180 case DEVICE_PATH_I2C
:
181 snprintf(buffer
, sizeof(buffer
), "I2C: %02x:%02x",
183 dev
->path
.i2c
.device
);
185 case DEVICE_PATH_APIC
:
186 snprintf(buffer
, sizeof(buffer
), "APIC: %02x",
187 dev
->path
.apic
.apic_id
);
189 case DEVICE_PATH_IOAPIC
:
190 snprintf(buffer
, sizeof(buffer
), "IOAPIC: %02x",
191 dev
->path
.ioapic
.ioapic_id
);
193 case DEVICE_PATH_DOMAIN
:
194 snprintf(buffer
, sizeof(buffer
), "DOMAIN: %04x",
195 dev
->path
.domain
.domain
);
197 case DEVICE_PATH_CPU_CLUSTER
:
198 snprintf(buffer
, sizeof(buffer
), "CPU_CLUSTER: %01x",
199 dev
->path
.cpu_cluster
.cluster
);
201 case DEVICE_PATH_CPU
:
202 snprintf(buffer
, sizeof(buffer
),
203 "CPU: %02x", dev
->path
.cpu
.id
);
205 case DEVICE_PATH_CPU_BUS
:
206 snprintf(buffer
, sizeof(buffer
),
207 "CPU_BUS: %02x", dev
->path
.cpu_bus
.id
);
209 case DEVICE_PATH_GENERIC
:
210 snprintf(buffer
, sizeof(buffer
),
211 "GENERIC: %d.%d", dev
->path
.generic
.id
,
212 dev
->path
.generic
.subid
);
214 case DEVICE_PATH_SPI
:
215 snprintf(buffer
, sizeof(buffer
), "SPI: %02x",
218 case DEVICE_PATH_USB
:
219 snprintf(buffer
, sizeof(buffer
), "USB%u port %u",
220 dev
->path
.usb
.port_type
, dev
->path
.usb
.port_id
);
222 case DEVICE_PATH_MMIO
:
223 snprintf(buffer
, sizeof(buffer
), "MMIO: %08lx",
224 dev
->path
.mmio
.addr
);
226 case DEVICE_PATH_GPIO
:
227 snprintf(buffer
, sizeof(buffer
), "GPIO: %d", dev
->path
.gpio
.id
);
229 case DEVICE_PATH_MDIO
:
230 snprintf(buffer
, sizeof(buffer
), "MDIO: %02x", dev
->path
.mdio
.addr
);
233 printk(BIOS_ERR
, "Unknown device path type: %d\n",
241 const char *dev_name(const struct device
*dev
)
245 else if (dev
->chip_ops
&& dev
->chip_ops
->name
)
246 return dev
->chip_ops
->name
;
251 const char *bus_path(struct bus
*bus
)
253 static char buffer
[BUS_PATH_MAX
];
254 snprintf(buffer
, sizeof(buffer
),
255 "%s,%d", dev_path(bus
->dev
), bus
->link_num
);
260 * Allocate 64 more resources to the free list.
264 static int allocate_more_resources(void)
267 struct resource
*new_res_list
;
269 new_res_list
= malloc(64 * sizeof(*new_res_list
));
271 if (new_res_list
== NULL
)
274 memset(new_res_list
, 0, 64 * sizeof(*new_res_list
));
276 for (i
= 0; i
< 64 - 1; i
++)
277 new_res_list
[i
].next
= &new_res_list
[i
+1];
279 free_resources
= new_res_list
;
284 * Remove resource res from the device's list and add it to the free list.
291 static void free_resource(struct device
*dev
, struct resource
*res
,
292 struct resource
*prev
)
295 prev
->next
= res
->next
;
297 dev
->resource_list
= res
->next
;
299 res
->next
= free_resources
;
300 free_resources
= res
;
304 * See if we have unused but allocated resource structures.
306 * If so remove the allocation.
308 * @param dev The device to find the resource on.
310 void compact_resources(struct device
*dev
)
312 struct resource
*res
, *next
, *prev
= NULL
;
314 /* Move all of the free resources to the end */
315 for (res
= dev
->resource_list
; res
; res
= next
) {
318 free_resource(dev
, res
, prev
);
325 * See if a resource structure already exists for a given index.
327 * @param dev The device to find the resource on.
328 * @param index The index of the resource on the device.
329 * @return The resource, if it already exists.
331 struct resource
*probe_resource(const struct device
*dev
, unsigned int index
)
333 struct resource
*res
;
335 /* See if there is a resource with the appropriate index */
336 for (res
= dev
->resource_list
; res
; res
= res
->next
) {
337 if (res
->index
== index
)
345 * See if a resource structure already exists for a given index and if not
348 * Then initialize the resource to default values.
350 * @param dev The device to find the resource on.
351 * @param index The index of the resource on the device.
354 struct resource
*new_resource(struct device
*dev
, unsigned int index
)
356 struct resource
*resource
, *tail
;
358 /* First move all of the free resources to the end. */
359 compact_resources(dev
);
361 /* See if there is a resource with the appropriate index. */
362 resource
= probe_resource(dev
, index
);
364 if (free_resources
== NULL
&& !allocate_more_resources())
365 die("Couldn't allocate more resources.");
367 resource
= free_resources
;
368 free_resources
= free_resources
->next
;
369 memset(resource
, 0, sizeof(*resource
));
370 resource
->next
= NULL
;
371 tail
= dev
->resource_list
;
375 tail
->next
= resource
;
377 dev
->resource_list
= resource
;
381 /* Initialize the resource values. */
382 if (!(resource
->flags
& IORESOURCE_FIXED
)) {
388 resource
->index
= index
;
396 * Return an existing resource structure for a given index.
398 * @param dev The device to find the resource on.
399 * @param index The index of the resource on the device.
402 struct resource
*find_resource(const struct device
*dev
, unsigned int index
)
404 struct resource
*resource
;
406 /* See if there is a resource with the appropriate index. */
407 resource
= probe_resource(dev
, index
);
409 printk(BIOS_EMERG
, "%s missing resource: %02x\n",
410 dev_path(dev
), index
);
417 * Round a number up to the next multiple of gran.
419 * @param val The starting value.
420 * @param gran Granularity we are aligning the number to.
421 * @return The aligned value.
423 static resource_t
align_up(resource_t val
, unsigned long gran
)
426 mask
= (1ULL << gran
) - 1ULL;
433 * Round a number up to the previous multiple of gran.
435 * @param val The starting value.
436 * @param gran Granularity we are aligning the number to.
437 * @return The aligned value.
439 static resource_t
align_down(resource_t val
, unsigned long gran
)
442 mask
= (1ULL << gran
) - 1ULL;
448 * Compute the maximum address that is part of a resource.
450 * @param resource The resource whose limit is desired.
453 resource_t
resource_end(const struct resource
*resource
)
455 resource_t base
, end
;
457 /* Get the base address. */
458 base
= resource
->base
;
461 * For a non bridge resource granularity and alignment are the same.
462 * For a bridge resource align is the largest needed alignment below
463 * the bridge. While the granularity is simply how many low bits of
464 * the address cannot be set.
467 /* Get the end (rounded up). */
468 end
= base
+ align_up(resource
->size
, resource
->gran
) - 1;
474 * Compute the maximum legal value for resource->base.
476 * @param resource The resource whose maximum is desired.
477 * @return The maximum.
479 resource_t
resource_max(const struct resource
*resource
)
483 max
= align_down(resource
->limit
- resource
->size
+ 1, resource
->align
);
489 * Return the resource type of a resource.
491 * @param resource The resource type to decode.
494 const char *resource_type(const struct resource
*resource
)
496 static char buffer
[RESOURCE_TYPE_MAX
];
497 snprintf(buffer
, sizeof(buffer
), "%s%s%s%s",
498 ((resource
->flags
& IORESOURCE_READONLY
) ? "ro" : ""),
499 ((resource
->flags
& IORESOURCE_PREFETCH
) ? "pref" : ""),
500 ((resource
->flags
== 0) ? "unused" :
501 (resource
->flags
& IORESOURCE_IO
) ? "io" :
502 (resource
->flags
& IORESOURCE_DRQ
) ? "drq" :
503 (resource
->flags
& IORESOURCE_IRQ
) ? "irq" :
504 (resource
->flags
& IORESOURCE_MEM
) ? "mem" : "??????"),
505 ((resource
->flags
& IORESOURCE_PCI64
) ? "64" : ""));
510 * Print the resource that was just stored.
512 * @param dev The device the stored resource lives on.
513 * @param resource The resource that was just stored.
514 * @param comment TODO
516 void report_resource_stored(struct device
*dev
, const struct resource
*resource
,
520 unsigned long long base
, end
;
522 if (!(resource
->flags
& IORESOURCE_STORED
))
525 base
= resource
->base
;
526 end
= resource_end(resource
);
529 if (dev
->link_list
&& (resource
->flags
& IORESOURCE_PCI_BRIDGE
)) {
530 snprintf(buf
, sizeof(buf
),
531 "bus %02x ", dev
->link_list
->secondary
);
533 printk(BIOS_DEBUG
, "%s %02lx <- [0x%016llx - 0x%016llx] size 0x%08llx "
534 "gran 0x%02x %s%s%s\n", dev_path(dev
), resource
->index
,
535 base
, end
, resource
->size
, resource
->gran
, buf
,
536 resource_type(resource
), comment
);
539 void search_bus_resources(struct bus
*bus
, unsigned long type_mask
,
540 unsigned long type
, resource_search_t search
,
543 struct device
*curdev
;
545 for (curdev
= bus
->children
; curdev
; curdev
= curdev
->sibling
) {
546 struct resource
*res
;
548 /* Ignore disabled devices. */
549 if (!curdev
->enabled
)
552 for (res
= curdev
->resource_list
; res
; res
= res
->next
) {
553 /* If it isn't the right kind of resource ignore it. */
554 if ((res
->flags
& type_mask
) != type
)
557 /* If it is a subtractive resource recurse. */
558 if (res
->flags
& IORESOURCE_SUBTRACTIVE
) {
560 for (subbus
= curdev
->link_list
; subbus
;
561 subbus
= subbus
->next
)
563 == IOINDEX_SUBTRACTIVE_LINK(res
->index
))
565 if (!subbus
) /* Why can subbus be NULL? */
567 search_bus_resources(subbus
, type_mask
, type
,
571 search(gp
, curdev
, res
);
576 void search_global_resources(unsigned long type_mask
, unsigned long type
,
577 resource_search_t search
, void *gp
)
579 struct device
*curdev
;
581 for (curdev
= all_devices
; curdev
; curdev
= curdev
->next
) {
582 struct resource
*res
;
584 /* Ignore disabled devices. */
585 if (!curdev
->enabled
)
588 for (res
= curdev
->resource_list
; res
; res
= res
->next
) {
589 /* If it isn't the right kind of resource ignore it. */
590 if ((res
->flags
& type_mask
) != type
)
593 /* If it is a subtractive resource ignore it. */
594 if (res
->flags
& IORESOURCE_SUBTRACTIVE
)
597 /* If the resource is not assigned ignore it. */
598 if (!(res
->flags
& IORESOURCE_ASSIGNED
))
601 search(gp
, curdev
, res
);
606 void dev_set_enabled(struct device
*dev
, int enable
)
608 if (dev
->enabled
== enable
)
611 dev
->enabled
= enable
;
612 if (dev
->ops
&& dev
->ops
->enable
)
613 dev
->ops
->enable(dev
);
614 else if (dev
->chip_ops
&& dev
->chip_ops
->enable_dev
)
615 dev
->chip_ops
->enable_dev(dev
);
618 void disable_children(struct bus
*bus
)
620 struct device
*child
;
622 for (child
= bus
->children
; child
; child
= child
->sibling
) {
624 for (link
= child
->link_list
; link
; link
= link
->next
)
625 disable_children(link
);
626 dev_set_enabled(child
, 0);
631 * Returns true if the device is an enabled bridge that has at least
632 * one enabled device on its secondary bus that is not of type NONE.
634 bool dev_is_active_bridge(struct device
*dev
)
637 struct device
*child
;
639 if (!dev
|| !dev
->enabled
)
642 if (!dev
->link_list
|| !dev
->link_list
->children
)
645 for (link
= dev
->link_list
; link
; link
= link
->next
) {
646 for (child
= link
->children
; child
; child
= child
->sibling
) {
647 if (child
->path
.type
== DEVICE_PATH_NONE
)
659 * Ensure the device has a minimum number of bus links.
661 * @param dev The device to add links to.
662 * @param total_links The minimum number of links to have.
664 void add_more_links(struct device
*dev
, unsigned int total_links
)
666 struct bus
*link
, *last
= NULL
;
669 for (link
= dev
->link_list
; link
; link
= link
->next
) {
670 if (link_num
< link
->link_num
)
671 link_num
= link
->link_num
;
676 int links
= total_links
- (link_num
+ 1);
678 link
= malloc(links
* sizeof(*link
));
680 die("Couldn't allocate more links!\n");
681 memset(link
, 0, links
* sizeof(*link
));
684 /* No more links to add */
688 link
= malloc(total_links
* sizeof(*link
));
690 die("Couldn't allocate more links!\n");
691 memset(link
, 0, total_links
* sizeof(*link
));
692 dev
->link_list
= link
;
695 for (link_num
= link_num
+ 1; link_num
< total_links
; link_num
++) {
696 link
->link_num
= link_num
;
698 link
->next
= link
+ 1;
705 static void resource_tree(const struct device
*root
, int debug_level
, int depth
)
708 struct device
*child
;
710 struct resource
*res
;
711 char indent
[30]; /* If your tree has more levels, it's wrong. */
713 for (i
= 0; i
< depth
+ 1 && i
< 29; i
++)
717 printk(BIOS_DEBUG
, "%s%s", indent
, dev_path(root
));
718 if (root
->link_list
&& root
->link_list
->children
)
719 printk(BIOS_DEBUG
, " child on link 0 %s",
720 dev_path(root
->link_list
->children
));
721 printk(BIOS_DEBUG
, "\n");
723 for (res
= root
->resource_list
; res
; res
= res
->next
) {
724 printk(debug_level
, "%s%s resource base %llx size %llx "
725 "align %d gran %d limit %llx flags %lx index %lx\n",
726 indent
, dev_path(root
), res
->base
, res
->size
,
727 res
->align
, res
->gran
, res
->limit
, res
->flags
,
731 for (link
= root
->link_list
; link
; link
= link
->next
) {
732 for (child
= link
->children
; child
; child
= child
->sibling
)
733 resource_tree(child
, debug_level
, depth
+ 1);
737 void print_resource_tree(const struct device
*root
, int debug_level
,
740 /* Bail if root is null. */
742 printk(debug_level
, "%s passed NULL for root!\n", __func__
);
746 /* Bail if not printing to screen. */
747 if (!printk(debug_level
, "Show resources in subtree (%s)...%s\n",
748 dev_path(root
), msg
))
751 resource_tree(root
, debug_level
, 0);
754 void show_devs_tree(const struct device
*dev
, int debug_level
, int depth
)
758 struct device
*sibling
;
761 for (i
= 0; i
< depth
; i
++)
765 printk(debug_level
, "%s%s: enabled %d\n",
766 depth_str
, dev_path(dev
), dev
->enabled
);
768 for (link
= dev
->link_list
; link
; link
= link
->next
) {
769 for (sibling
= link
->children
; sibling
;
770 sibling
= sibling
->sibling
)
771 show_devs_tree(sibling
, debug_level
, depth
+ 1);
775 void show_all_devs_tree(int debug_level
, const char *msg
)
777 /* Bail if not printing to screen. */
778 if (!printk(debug_level
, "Show all devs in tree form... %s\n", msg
))
780 show_devs_tree(all_devices
, debug_level
, 0);
783 void show_devs_subtree(struct device
*root
, int debug_level
, const char *msg
)
785 /* Bail if not printing to screen. */
786 if (!printk(debug_level
, "Show all devs in subtree %s... %s\n",
787 dev_path(root
), msg
))
789 printk(debug_level
, "%s\n", msg
);
790 show_devs_tree(root
, debug_level
, 0);
793 void show_all_devs(int debug_level
, const char *msg
)
797 /* Bail if not printing to screen. */
798 if (!printk(debug_level
, "Show all devs... %s\n", msg
))
800 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
801 printk(debug_level
, "%s: enabled %d\n",
802 dev_path(dev
), dev
->enabled
);
806 void show_one_resource(int debug_level
, struct device
*dev
,
807 struct resource
*resource
, const char *comment
)
810 unsigned long long base
, end
;
811 base
= resource
->base
;
812 end
= resource_end(resource
);
815 printk(debug_level
, "%s %02lx <- [0x%016llx - 0x%016llx] "
816 "size 0x%08llx gran 0x%02x %s%s%s\n", dev_path(dev
),
817 resource
->index
, base
, end
, resource
->size
, resource
->gran
,
818 buf
, resource_type(resource
), comment
);
821 void show_all_devs_resources(int debug_level
, const char *msg
)
825 if (!printk(debug_level
, "Show all devs with resources... %s\n", msg
))
828 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
829 struct resource
*res
;
830 printk(debug_level
, "%s: enabled %d\n",
831 dev_path(dev
), dev
->enabled
);
832 for (res
= dev
->resource_list
; res
; res
= res
->next
)
833 show_one_resource(debug_level
, dev
, res
, "");
837 const struct resource
*fixed_resource_range_idx(struct device
*dev
, unsigned long index
,
838 uint64_t base
, uint64_t size
, unsigned long flags
)
840 struct resource
*resource
;
844 resource
= new_resource(dev
, index
);
845 resource
->base
= base
;
846 resource
->size
= size
;
847 resource
->flags
= IORESOURCE_FIXED
| IORESOURCE_ASSIGNED
;
848 resource
->flags
|= flags
;
850 printk(BIOS_SPEW
, "dev: %s, index: 0x%lx, base: 0x%llx, size: 0x%llx\n",
851 dev_path(dev
), resource
->index
, resource
->base
, resource
->size
);
856 const struct resource
*lower_ram_end(struct device
*dev
, unsigned long index
, uint64_t end
)
858 return ram_from_to(dev
, index
, 0, end
);
861 const struct resource
*upper_ram_end(struct device
*dev
, unsigned long index
, uint64_t end
)
863 if (end
<= 4ull * GiB
)
866 printk(BIOS_INFO
, "Available memory above 4GB: %lluM\n", (end
- 4ull * GiB
) / MiB
);
868 return ram_from_to(dev
, index
, 4ull * GiB
, end
);
871 void mmconf_resource(struct device
*dev
, unsigned long index
)
873 struct resource
*resource
= new_resource(dev
, index
);
874 resource
->base
= CONFIG_ECAM_MMCONF_BASE_ADDRESS
;
875 resource
->size
= CONFIG_ECAM_MMCONF_LENGTH
;
876 resource
->flags
= IORESOURCE_MEM
| IORESOURCE_RESERVE
|
877 IORESOURCE_FIXED
| IORESOURCE_STORED
| IORESOURCE_ASSIGNED
;
879 printk(BIOS_DEBUG
, "Adding PCIe enhanced config space BAR 0x%08lx-0x%08lx.\n",
880 (unsigned long)(resource
->base
),
881 (unsigned long)(resource
->base
+ resource
->size
));
884 void tolm_test(void *gp
, struct device
*dev
, struct resource
*new)
886 struct resource
**best_p
= gp
;
887 struct resource
*best
;
892 * If resource is not allocated any space i.e. size is zero,
893 * then do not consider this resource in tolm calculations.
898 if (!best
|| (best
->base
> new->base
))
904 u32
find_pci_tolm(struct bus
*bus
)
906 struct resource
*min
= NULL
;
908 unsigned long mask_match
= IORESOURCE_MEM
| IORESOURCE_ASSIGNED
;
910 search_bus_resources(bus
, mask_match
, mask_match
, tolm_test
, &min
);
914 if (min
&& tolm
> min
->base
)
920 /* Count of enabled CPUs */
921 int dev_count_cpu(void)
926 for (cpu
= all_devices
; cpu
; cpu
= cpu
->next
) {
927 if (!is_enabled_cpu(cpu
))
935 /* Get device path name */
936 const char *dev_path_name(enum device_path_type type
)
938 static const char *const type_names
[] = DEVICE_PATH_NAMES
;
939 const char *type_name
= "Unknown";
941 /* Translate the type value into a string */
942 if (type
< ARRAY_SIZE(type_names
))
943 type_name
= type_names
[type
];
947 bool dev_path_hotplug(const struct device
*dev
)
949 for (dev
= dev
->bus
->dev
; dev
!= dev
->bus
->dev
; dev
= dev
->bus
->dev
) {
950 if (dev
->hotplug_port
)
956 void log_resource(const char *type
, const struct device
*dev
, const struct resource
*res
,
957 const char *srcfile
, const int line
)
959 printk(BIOS_SPEW
, "%s:%d res: %s, dev: %s, index: 0x%lx, base: 0x%llx, "
960 "end: 0x%llx, size_kb: 0x%llx\n",
961 srcfile
, line
, type
, dev_path(dev
), res
->index
, res
->base
,
962 resource_end(res
), res
->size
/ KiB
);
965 bool is_cpu(const struct device
*cpu
)
967 return cpu
->path
.type
== DEVICE_PATH_APIC
&&
968 cpu
->bus
->dev
->path
.type
== DEVICE_PATH_CPU_CLUSTER
;
971 bool is_enabled_cpu(const struct device
*cpu
)
973 return is_cpu(cpu
) && cpu
->enabled
;
976 bool is_pci(const struct device
*pci
)
978 return pci
->path
.type
== DEVICE_PATH_PCI
;
981 bool is_enabled_pci(const struct device
*pci
)
983 return is_pci(pci
) && pci
->enabled
;
986 bool is_pci_dev_on_bus(const struct device
*pci
, unsigned int bus
)
988 return is_pci(pci
) && pci
->bus
->secondary
== bus
;