1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <commonlib/bsd/helpers.h>
5 #include <console/console.h>
6 #include <device/device.h>
7 #include <device/pci_def.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
->upstream
->segment_group
<< 16 | dev
->upstream
->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_id
;
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:%02x.%01x",
172 dev
->upstream
->segment_group
,
173 dev
->upstream
->secondary
,
174 PCI_SLOT(dev
->path
.pci
.devfn
),
175 PCI_FUNC(dev
->path
.pci
.devfn
));
177 case DEVICE_PATH_PNP
:
178 snprintf(buffer
, sizeof(buffer
), "PNP: %04x.%01x",
179 dev
->path
.pnp
.port
, dev
->path
.pnp
.device
);
181 case DEVICE_PATH_I2C
:
182 snprintf(buffer
, sizeof(buffer
), "I2C: %02x:%02x",
183 dev
->upstream
->secondary
,
184 dev
->path
.i2c
.device
);
186 case DEVICE_PATH_APIC
:
187 snprintf(buffer
, sizeof(buffer
), "APIC: %02x",
188 dev
->path
.apic
.apic_id
);
190 case DEVICE_PATH_IOAPIC
:
191 snprintf(buffer
, sizeof(buffer
), "IOAPIC: %02x",
192 dev
->path
.ioapic
.ioapic_id
);
194 case DEVICE_PATH_DOMAIN
:
195 snprintf(buffer
, sizeof(buffer
), "DOMAIN: %08x",
196 dev
->path
.domain
.domain_id
);
198 case DEVICE_PATH_CPU_CLUSTER
:
199 snprintf(buffer
, sizeof(buffer
), "CPU_CLUSTER: %01x",
200 dev
->path
.cpu_cluster
.cluster
);
202 case DEVICE_PATH_CPU
:
203 snprintf(buffer
, sizeof(buffer
),
204 "CPU: %02x", dev
->path
.cpu
.id
);
206 case DEVICE_PATH_CPU_BUS
:
207 snprintf(buffer
, sizeof(buffer
),
208 "CPU_BUS: %02x", dev
->path
.cpu_bus
.id
);
210 case DEVICE_PATH_GENERIC
:
211 snprintf(buffer
, sizeof(buffer
),
212 "GENERIC: %d.%d", dev
->path
.generic
.id
,
213 dev
->path
.generic
.subid
);
215 case DEVICE_PATH_SPI
:
216 snprintf(buffer
, sizeof(buffer
), "SPI: %02x",
219 case DEVICE_PATH_USB
:
220 snprintf(buffer
, sizeof(buffer
), "USB%u port %u",
221 dev
->path
.usb
.port_type
, dev
->path
.usb
.port_id
);
223 case DEVICE_PATH_MMIO
:
224 snprintf(buffer
, sizeof(buffer
), "MMIO: %08lx",
225 dev
->path
.mmio
.addr
);
227 case DEVICE_PATH_GPIO
:
228 snprintf(buffer
, sizeof(buffer
), "GPIO: %d", dev
->path
.gpio
.id
);
230 case DEVICE_PATH_MDIO
:
231 snprintf(buffer
, sizeof(buffer
), "MDIO: %02x", dev
->path
.mdio
.addr
);
233 case DEVICE_PATH_GICC_V3
:
234 snprintf(buffer
, sizeof(buffer
), "GICV3: %02x", dev
->path
.gicc_v3
.mpidr
);
237 printk(BIOS_ERR
, "Unknown device path type: %d\n",
245 const char *dev_name(const struct device
*dev
)
249 else if (dev
->chip_ops
&& dev
->chip_ops
->name
)
250 return dev
->chip_ops
->name
;
255 /* Returns the domain for the given device */
256 const struct device
*dev_get_domain(const struct device
*dev
)
258 /* Walk up the tree up to the domain */
259 while (dev
&& dev
->upstream
&& !is_root_device(dev
)) {
260 if (dev
->path
.type
== DEVICE_PATH_DOMAIN
)
262 dev
= dev
->upstream
->dev
;
268 unsigned int dev_get_domain_id(const struct device
*dev
)
270 const struct device
*domain_dev
= dev_get_domain(dev
);
275 printk(BIOS_ERR
, "%s: doesn't have a domain device\n", dev_path(dev
));
279 return domain_dev
->path
.domain
.domain_id
;
282 bool is_domain0(const struct device
*dev
)
284 return dev
&& dev
->path
.type
== DEVICE_PATH_DOMAIN
&& dev
->path
.domain
.domain_id
== 0;
287 bool is_dev_on_domain0(const struct device
*dev
)
289 return is_domain0(dev_get_domain(dev
));
293 * Allocate 64 more resources to the free list.
297 static int allocate_more_resources(void)
300 struct resource
*new_res_list
;
302 new_res_list
= malloc(64 * sizeof(*new_res_list
));
304 if (new_res_list
== NULL
)
307 memset(new_res_list
, 0, 64 * sizeof(*new_res_list
));
309 for (i
= 0; i
< 64 - 1; i
++)
310 new_res_list
[i
].next
= &new_res_list
[i
+1];
312 free_resources
= new_res_list
;
317 * Remove resource res from the device's list and add it to the free list.
324 static void free_resource(struct device
*dev
, struct resource
*res
,
325 struct resource
*prev
)
328 prev
->next
= res
->next
;
330 dev
->resource_list
= res
->next
;
332 res
->next
= free_resources
;
333 free_resources
= res
;
337 * See if we have unused but allocated resource structures.
339 * If so remove the allocation.
341 * @param dev The device to find the resource on.
343 void compact_resources(struct device
*dev
)
345 struct resource
*res
, *next
, *prev
= NULL
;
347 /* Move all of the free resources to the end */
348 for (res
= dev
->resource_list
; res
; res
= next
) {
351 free_resource(dev
, res
, prev
);
358 * See if a resource structure already exists for a given index.
360 * @param dev The device to find the resource on.
361 * @param index The index of the resource on the device.
362 * @return The resource, if it already exists.
364 struct resource
*probe_resource(const struct device
*dev
, unsigned int index
)
366 struct resource
*res
;
368 /* See if there is a resource with the appropriate index */
369 for (res
= dev
->resource_list
; res
; res
= res
->next
) {
370 if (res
->index
== index
)
378 * See if a resource structure already exists for a given index and if not
381 * Then initialize the resource to default values.
383 * @param dev The device to find the resource on.
384 * @param index The index of the resource on the device.
387 struct resource
*new_resource(struct device
*dev
, unsigned int index
)
389 struct resource
*resource
, *tail
;
391 /* First move all of the free resources to the end. */
392 compact_resources(dev
);
394 /* See if there is a resource with the appropriate index. */
395 resource
= probe_resource(dev
, index
);
397 if (free_resources
== NULL
&& !allocate_more_resources())
398 die("Couldn't allocate more resources.");
400 resource
= free_resources
;
401 free_resources
= free_resources
->next
;
402 memset(resource
, 0, sizeof(*resource
));
403 resource
->next
= NULL
;
404 tail
= dev
->resource_list
;
408 tail
->next
= resource
;
410 dev
->resource_list
= resource
;
414 /* Initialize the resource values. */
415 if (!(resource
->flags
& IORESOURCE_FIXED
)) {
421 resource
->index
= index
;
429 * Return an existing resource structure for a given index.
431 * @param dev The device to find the resource on.
432 * @param index The index of the resource on the device.
435 struct resource
*find_resource(const struct device
*dev
, unsigned int index
)
437 struct resource
*resource
;
439 /* See if there is a resource with the appropriate index. */
440 resource
= probe_resource(dev
, index
);
442 die("%s missing resource: %02x\n", dev_path(dev
), index
);
447 * Round a number up to the next multiple of gran.
449 * @param val The starting value.
450 * @param gran Granularity we are aligning the number to.
451 * @return The aligned value.
453 static resource_t
align_up(resource_t val
, unsigned long gran
)
456 mask
= (1ULL << gran
) - 1ULL;
463 * Round a number up to the previous multiple of gran.
465 * @param val The starting value.
466 * @param gran Granularity we are aligning the number to.
467 * @return The aligned value.
469 static resource_t
align_down(resource_t val
, unsigned long gran
)
472 mask
= (1ULL << gran
) - 1ULL;
478 * Compute the maximum address that is part of a resource.
480 * @param resource The resource whose limit is desired.
483 resource_t
resource_end(const struct resource
*resource
)
485 resource_t base
, end
;
487 /* Get the base address. */
488 base
= resource
->base
;
491 * For a non bridge resource granularity and alignment are the same.
492 * For a bridge resource align is the largest needed alignment below
493 * the bridge. While the granularity is simply how many low bits of
494 * the address cannot be set.
497 /* Get the end (rounded up). */
498 end
= base
+ align_up(resource
->size
, resource
->gran
) - 1;
504 * Compute the maximum legal value for resource->base.
506 * @param resource The resource whose maximum is desired.
507 * @return The maximum.
509 resource_t
resource_max(const struct resource
*resource
)
513 max
= align_down(resource
->limit
- resource
->size
+ 1, resource
->align
);
519 * Return the resource type of a resource.
521 * @param resource The resource type to decode.
524 const char *resource_type(const struct resource
*resource
)
526 static char buffer
[RESOURCE_TYPE_MAX
];
527 snprintf(buffer
, sizeof(buffer
), "%s%s%s%s",
528 ((resource
->flags
& IORESOURCE_READONLY
) ? "ro" : ""),
529 ((resource
->flags
& IORESOURCE_PREFETCH
) ? "pref" : ""),
530 ((resource
->flags
== 0) ? "unused" :
531 (resource
->flags
& IORESOURCE_IO
) ? "io" :
532 (resource
->flags
& IORESOURCE_DRQ
) ? "drq" :
533 (resource
->flags
& IORESOURCE_IRQ
) ? "irq" :
534 (resource
->flags
& IORESOURCE_MEM
) ? "mem" : "??????"),
535 ((resource
->flags
& IORESOURCE_PCI64
) ? "64" : ""));
540 * Print the resource that was just stored.
542 * @param dev The device the stored resource lives on.
543 * @param resource The resource that was just stored.
544 * @param comment TODO
546 void report_resource_stored(struct device
*dev
, const struct resource
*resource
,
550 unsigned long long base
, end
;
552 if (!(resource
->flags
& IORESOURCE_STORED
))
555 base
= resource
->base
;
556 end
= resource_end(resource
);
559 if (dev
->downstream
&& (resource
->flags
& IORESOURCE_PCI_BRIDGE
)) {
560 snprintf(buf
, sizeof(buf
),
561 "seg %02x bus %02x ", dev
->downstream
->segment_group
,
562 dev
->downstream
->secondary
);
564 printk(BIOS_DEBUG
, "%s %02lx <- [0x%016llx - 0x%016llx] size 0x%08llx "
565 "gran 0x%02x %s%s%s\n", dev_path(dev
), resource
->index
,
566 base
, end
, resource
->size
, resource
->gran
, buf
,
567 resource_type(resource
), comment
);
570 void search_bus_resources(struct bus
*bus
, unsigned long type_mask
,
571 unsigned long type
, resource_search_t search
,
574 struct device
*curdev
;
576 for (curdev
= bus
->children
; curdev
; curdev
= curdev
->sibling
) {
577 struct resource
*res
;
579 /* Ignore disabled devices. */
580 if (!curdev
->enabled
)
583 for (res
= curdev
->resource_list
; res
; res
= res
->next
) {
584 /* If it isn't the right kind of resource ignore it. */
585 if ((res
->flags
& type_mask
) != type
)
588 /* If it is a subtractive resource recurse. */
589 if (res
->flags
& IORESOURCE_SUBTRACTIVE
) {
590 if (curdev
->downstream
)
591 search_bus_resources(curdev
->downstream
, type_mask
, type
,
595 search(gp
, curdev
, res
);
600 void search_global_resources(unsigned long type_mask
, unsigned long type
,
601 resource_search_t search
, void *gp
)
603 struct device
*curdev
;
605 for (curdev
= all_devices
; curdev
; curdev
= curdev
->next
) {
606 struct resource
*res
;
608 /* Ignore disabled devices. */
609 if (!curdev
->enabled
)
612 for (res
= curdev
->resource_list
; res
; res
= res
->next
) {
613 /* If it isn't the right kind of resource ignore it. */
614 if ((res
->flags
& type_mask
) != type
)
617 /* If it is a subtractive resource ignore it. */
618 if (res
->flags
& IORESOURCE_SUBTRACTIVE
)
621 /* If the resource is not assigned ignore it. */
622 if (!(res
->flags
& IORESOURCE_ASSIGNED
))
625 search(gp
, curdev
, res
);
630 void dev_set_enabled(struct device
*dev
, int enable
)
632 if (dev
->enabled
== enable
)
635 dev
->enabled
= enable
;
636 if (dev
->ops
&& dev
->ops
->enable
)
637 dev
->ops
->enable(dev
);
638 else if (dev
->chip_ops
&& dev
->chip_ops
->enable_dev
)
639 dev
->chip_ops
->enable_dev(dev
);
642 void disable_children(struct bus
*bus
)
644 struct device
*child
;
646 for (child
= bus
->children
; child
; child
= child
->sibling
) {
647 if (child
->downstream
)
648 disable_children(child
->downstream
);
649 dev_set_enabled(child
, 0);
654 * Returns true if the device is an enabled bridge that has at least
655 * one enabled device on its secondary bus that is not of type NONE.
657 bool dev_is_active_bridge(struct device
*dev
)
659 struct device
*child
;
661 if (!dev
|| !dev
->enabled
)
664 if (!dev
->downstream
|| !dev
->downstream
->children
)
667 for (child
= dev
->downstream
->children
; child
; child
= child
->sibling
) {
668 if (child
->path
.type
== DEVICE_PATH_NONE
)
677 static void resource_tree(const struct device
*root
, int debug_level
, int depth
)
680 struct device
*child
;
681 struct resource
*res
;
682 char indent
[30]; /* If your tree has more levels, it's wrong. */
684 for (i
= 0; i
< depth
+ 1 && i
< 29; i
++)
688 printk(BIOS_DEBUG
, "%s%s", indent
, dev_path(root
));
689 if (root
->downstream
&& root
->downstream
->children
)
690 printk(BIOS_DEBUG
, " child on link 0 %s",
691 dev_path(root
->downstream
->children
));
692 printk(BIOS_DEBUG
, "\n");
694 for (res
= root
->resource_list
; res
; res
= res
->next
) {
695 printk(debug_level
, "%s%s resource base %llx size %llx "
696 "align %d gran %d limit %llx flags %lx index %lx\n",
697 indent
, dev_path(root
), res
->base
, res
->size
,
698 res
->align
, res
->gran
, res
->limit
, res
->flags
,
702 if (!root
->downstream
)
705 for (child
= root
->downstream
->children
; child
; child
= child
->sibling
)
706 resource_tree(child
, debug_level
, depth
+ 1);
709 void print_resource_tree(const struct device
*root
, int debug_level
,
712 /* Bail if root is null. */
714 printk(debug_level
, "%s passed NULL for root!\n", __func__
);
718 /* Bail if not printing to screen. */
719 if (!printk(debug_level
, "Show resources in subtree (%s)...%s\n",
720 dev_path(root
), msg
))
723 resource_tree(root
, debug_level
, 0);
726 void show_devs_tree(const struct device
*dev
, int debug_level
, int depth
)
730 struct device
*sibling
;
732 for (i
= 0; i
< depth
; i
++)
736 printk(debug_level
, "%s%s: enabled %d\n",
737 depth_str
, dev_path(dev
), dev
->enabled
);
739 if (!dev
->downstream
)
742 for (sibling
= dev
->downstream
->children
; sibling
; sibling
= sibling
->sibling
)
743 show_devs_tree(sibling
, debug_level
, depth
+ 1);
746 void show_all_devs_tree(int debug_level
, const char *msg
)
748 /* Bail if not printing to screen. */
749 if (!printk(debug_level
, "Show all devs in tree form... %s\n", msg
))
751 show_devs_tree(all_devices
, debug_level
, 0);
754 void show_devs_subtree(struct device
*root
, int debug_level
, const char *msg
)
756 /* Bail if not printing to screen. */
757 if (!printk(debug_level
, "Show all devs in subtree %s... %s\n",
758 dev_path(root
), msg
))
760 printk(debug_level
, "%s\n", msg
);
761 show_devs_tree(root
, debug_level
, 0);
764 void show_all_devs(int debug_level
, const char *msg
)
768 /* Bail if not printing to screen. */
769 if (!printk(debug_level
, "Show all devs... %s\n", msg
))
771 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
772 printk(debug_level
, "%s: enabled %d\n",
773 dev_path(dev
), dev
->enabled
);
777 void show_one_resource(int debug_level
, struct device
*dev
,
778 struct resource
*resource
, const char *comment
)
781 unsigned long long base
, end
;
782 base
= resource
->base
;
783 end
= resource_end(resource
);
786 printk(debug_level
, "%s %02lx <- [0x%016llx - 0x%016llx] "
787 "size 0x%08llx gran 0x%02x %s%s%s\n", dev_path(dev
),
788 resource
->index
, base
, end
, resource
->size
, resource
->gran
,
789 buf
, resource_type(resource
), comment
);
792 void show_all_devs_resources(int debug_level
, const char *msg
)
796 if (!printk(debug_level
, "Show all devs with resources... %s\n", msg
))
799 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
800 struct resource
*res
;
801 printk(debug_level
, "%s: enabled %d\n",
802 dev_path(dev
), dev
->enabled
);
803 for (res
= dev
->resource_list
; res
; res
= res
->next
)
804 show_one_resource(debug_level
, dev
, res
, "");
808 const struct resource
*resource_range_idx(struct device
*dev
, unsigned long index
,
809 uint64_t base
, uint64_t size
, unsigned long flags
)
811 struct resource
*resource
;
815 resource
= new_resource(dev
, index
);
816 resource
->base
= base
;
818 if (flags
& IORESOURCE_FIXED
)
819 resource
->size
= size
;
820 if (flags
& IORESOURCE_BRIDGE
)
821 resource
->limit
= base
+ size
- 1;
823 resource
->flags
= IORESOURCE_ASSIGNED
;
824 resource
->flags
|= flags
;
826 printk(BIOS_SPEW
, "dev: %s, index: 0x%lx, base: 0x%llx, size: 0x%llx\n",
827 dev_path(dev
), resource
->index
, resource
->base
, resource
->size
);
832 const struct resource
*lower_ram_end(struct device
*dev
, unsigned long index
, uint64_t end
)
834 return ram_from_to(dev
, index
, 0, end
);
837 const struct resource
*upper_ram_end(struct device
*dev
, unsigned long index
, uint64_t end
)
839 if (end
<= 4ull * GiB
)
842 printk(BIOS_INFO
, "Available memory above 4GB: %lluM\n", (end
- 4ull * GiB
) / MiB
);
844 return ram_from_to(dev
, index
, 4ull * GiB
, end
);
847 void mmconf_resource(struct device
*dev
, unsigned long index
)
849 struct resource
*resource
= new_resource(dev
, index
);
850 resource
->base
= CONFIG_ECAM_MMCONF_BASE_ADDRESS
;
851 resource
->size
= CONFIG_ECAM_MMCONF_LENGTH
;
852 resource
->flags
= IORESOURCE_MEM
| IORESOURCE_RESERVE
|
853 IORESOURCE_FIXED
| IORESOURCE_STORED
| IORESOURCE_ASSIGNED
;
855 printk(BIOS_DEBUG
, "Adding PCIe enhanced config space BAR 0x%08lx-0x%08lx.\n",
856 (unsigned long)(resource
->base
),
857 (unsigned long)(resource
->base
+ resource
->size
));
860 void tolm_test(void *gp
, struct device
*dev
, struct resource
*new)
862 struct resource
**best_p
= gp
;
863 struct resource
*best
;
868 * If resource is not allocated any space i.e. size is zero,
869 * then do not consider this resource in tolm calculations.
874 if (!best
|| (best
->base
> new->base
))
880 u32
find_pci_tolm(struct bus
*bus
)
882 struct resource
*min
= NULL
;
884 unsigned long mask_match
= IORESOURCE_MEM
| IORESOURCE_ASSIGNED
;
886 search_bus_resources(bus
, mask_match
, mask_match
, tolm_test
, &min
);
890 if (min
&& tolm
> min
->base
)
896 /* Count of enabled CPUs */
897 int dev_count_cpu(void)
902 for (cpu
= all_devices
; cpu
; cpu
= cpu
->next
) {
903 if (!is_enabled_cpu(cpu
))
911 /* Get device path name */
912 const char *dev_path_name(enum device_path_type type
)
914 static const char *const type_names
[] = DEVICE_PATH_NAMES
;
915 const char *type_name
= "Unknown";
917 /* Translate the type value into a string */
918 if (type
< ARRAY_SIZE(type_names
))
919 type_name
= type_names
[type
];
923 bool dev_path_hotplug(const struct device
*dev
)
925 for (dev
= dev
->upstream
->dev
; dev
!= dev
->upstream
->dev
; dev
= dev
->upstream
->dev
) {
926 if (dev
->hotplug_port
)
932 void log_resource(const char *type
, const struct device
*dev
, const struct resource
*res
,
933 const char *srcfile
, const int line
)
935 printk(BIOS_SPEW
, "%s:%d res: %s, dev: %s, index: 0x%lx, base: 0x%llx, "
936 "end: 0x%llx, size_kb: 0x%llx\n",
937 srcfile
, line
, type
, dev_path(dev
), res
->index
, res
->base
,
938 resource_end(res
), res
->size
/ KiB
);
941 bool is_cpu(const struct device
*cpu
)
943 return cpu
->path
.type
== DEVICE_PATH_APIC
&&
944 cpu
->upstream
->dev
->path
.type
== DEVICE_PATH_CPU_CLUSTER
;
947 bool is_enabled_cpu(const struct device
*cpu
)
949 return is_cpu(cpu
) && cpu
->enabled
;
952 bool is_pci(const struct device
*pci
)
954 return pci
->path
.type
== DEVICE_PATH_PCI
;
957 bool is_enabled_pci(const struct device
*pci
)
959 return is_pci(pci
) && pci
->enabled
;
962 bool is_pci_dev_on_bus(const struct device
*pci
, unsigned int bus
)
964 return is_pci(pci
) && pci
->upstream
->segment_group
== 0
965 && pci
->upstream
->secondary
== bus
;
968 bool is_pci_bridge(const struct device
*pci
)
970 return is_pci(pci
) && ((pci
->hdr_type
& 0x7f) == PCI_HEADER_TYPE_BRIDGE
);