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>
8 #include <device/pci_ids.h>
15 * Given a Local APIC ID, find the device structure.
17 * @param apic_id The Local APIC ID number.
18 * @return Pointer to the device structure (if found), 0 otherwise.
20 struct device
*dev_find_lapic(unsigned int apic_id
)
23 struct device
*result
= NULL
;
25 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
26 if (dev
->path
.type
== DEVICE_PATH_APIC
&&
27 dev
->path
.apic
.apic_id
== apic_id
) {
36 * Find a device of a given vendor and type.
38 * @param vendor A PCI vendor ID (e.g. 0x8086 for Intel).
39 * @param device A PCI device ID.
40 * @param from Pointer to the device structure, used as a starting point in
41 * the linked list of all_devices, which can be 0 to start at the
42 * head of the list (i.e. all_devices).
43 * @return Pointer to the device struct.
45 struct device
*dev_find_device(u16 vendor
, u16 device
, struct device
*from
)
52 while (from
&& (from
->vendor
!= vendor
|| from
->device
!= device
))
59 * Find a device of a given class.
61 * @param class Class of the device.
62 * @param from Pointer to the device structure, used as a starting point in
63 * the linked list of all_devices, which can be 0 to start at the
64 * head of the list (i.e. all_devices).
65 * @return Pointer to the device struct.
67 struct device
*dev_find_class(unsigned int class, struct device
*from
)
74 while (from
&& (from
->class & 0xffffff00) != class)
81 * Encode the device path into 3 bytes for logging to CMOS.
83 * @param dev The device path to encode.
84 * @return Device path encoded into lower 3 bytes of dword.
86 u32
dev_path_encode(const struct device
*dev
)
93 /* Store the device type in 3rd byte. */
94 ret
= dev
->path
.type
<< 16;
96 /* Encode the device specific path in the low word. */
97 switch (dev
->path
.type
) {
98 case DEVICE_PATH_ROOT
:
100 case DEVICE_PATH_PCI
:
101 ret
|= dev
->upstream
->segment_group
<< 16 | dev
->upstream
->secondary
<< 8 | dev
->path
.pci
.devfn
;
103 case DEVICE_PATH_PNP
:
104 ret
|= dev
->path
.pnp
.port
<< 8 | dev
->path
.pnp
.device
;
106 case DEVICE_PATH_I2C
:
107 ret
|= dev
->path
.i2c
.mode_10bit
<< 8 | dev
->path
.i2c
.device
;
109 case DEVICE_PATH_APIC
:
110 ret
|= dev
->path
.apic
.apic_id
;
112 case DEVICE_PATH_DOMAIN
:
113 ret
|= dev
->path
.domain
.domain_id
;
115 case DEVICE_PATH_CPU_CLUSTER
:
116 ret
|= dev
->path
.cpu_cluster
.cluster
;
118 case DEVICE_PATH_CPU
:
119 ret
|= dev
->path
.cpu
.id
;
121 case DEVICE_PATH_CPU_BUS
:
122 ret
|= dev
->path
.cpu_bus
.id
;
124 case DEVICE_PATH_IOAPIC
:
125 ret
|= dev
->path
.ioapic
.ioapic_id
;
127 case DEVICE_PATH_GENERIC
:
128 ret
|= dev
->path
.generic
.subid
<< 8 | dev
->path
.generic
.id
;
130 case DEVICE_PATH_SPI
:
131 ret
|= dev
->path
.spi
.cs
;
133 case DEVICE_PATH_USB
:
134 ret
|= dev
->path
.usb
.port_type
<< 8 | dev
->path
.usb
.port_id
;
136 case DEVICE_PATH_GPIO
:
137 ret
|= dev
->path
.gpio
.id
;
139 case DEVICE_PATH_MDIO
:
140 ret
|= dev
->path
.mdio
.addr
;
142 case DEVICE_PATH_NONE
:
143 case DEVICE_PATH_MMIO
: /* don't care */
152 * Warning: This function uses a static buffer. Don't call it more than once
153 * from the same print statement!
155 const char *dev_path(const struct device
*dev
)
157 static char buffer
[DEVICE_PATH_MAX
];
161 strcpy(buffer
, "<null>");
163 switch (dev
->path
.type
) {
164 case DEVICE_PATH_NONE
:
165 strcpy(buffer
, "NONE");
167 case DEVICE_PATH_ROOT
:
168 strcpy(buffer
, "Root Device");
170 case DEVICE_PATH_PCI
:
171 snprintf(buffer
, sizeof(buffer
),
172 "PCI: %02x:%02x:%02x.%01x",
173 dev
->upstream
->segment_group
,
174 dev
->upstream
->secondary
,
175 PCI_SLOT(dev
->path
.pci
.devfn
),
176 PCI_FUNC(dev
->path
.pci
.devfn
));
178 case DEVICE_PATH_PNP
:
179 snprintf(buffer
, sizeof(buffer
), "PNP: %04x.%01x",
180 dev
->path
.pnp
.port
, dev
->path
.pnp
.device
);
182 case DEVICE_PATH_I2C
:
183 snprintf(buffer
, sizeof(buffer
), "I2C: %02x:%02x",
184 dev
->upstream
->secondary
,
185 dev
->path
.i2c
.device
);
187 case DEVICE_PATH_APIC
:
188 snprintf(buffer
, sizeof(buffer
), "APIC: %02x",
189 dev
->path
.apic
.apic_id
);
191 case DEVICE_PATH_IOAPIC
:
192 snprintf(buffer
, sizeof(buffer
), "IOAPIC: %02x",
193 dev
->path
.ioapic
.ioapic_id
);
195 case DEVICE_PATH_DOMAIN
:
196 snprintf(buffer
, sizeof(buffer
), "DOMAIN: %08x",
197 dev
->path
.domain
.domain_id
);
199 case DEVICE_PATH_CPU_CLUSTER
:
200 snprintf(buffer
, sizeof(buffer
), "CPU_CLUSTER: %01x",
201 dev
->path
.cpu_cluster
.cluster
);
203 case DEVICE_PATH_CPU
:
204 snprintf(buffer
, sizeof(buffer
),
205 "CPU: %02x", dev
->path
.cpu
.id
);
207 case DEVICE_PATH_CPU_BUS
:
208 snprintf(buffer
, sizeof(buffer
),
209 "CPU_BUS: %02x", dev
->path
.cpu_bus
.id
);
211 case DEVICE_PATH_GENERIC
:
212 snprintf(buffer
, sizeof(buffer
),
213 "GENERIC: %d.%d", dev
->path
.generic
.id
,
214 dev
->path
.generic
.subid
);
216 case DEVICE_PATH_SPI
:
217 snprintf(buffer
, sizeof(buffer
), "SPI: %02x",
220 case DEVICE_PATH_USB
:
221 snprintf(buffer
, sizeof(buffer
), "USB%u port %u",
222 dev
->path
.usb
.port_type
, dev
->path
.usb
.port_id
);
224 case DEVICE_PATH_MMIO
:
225 snprintf(buffer
, sizeof(buffer
), "MMIO: %08lx",
226 dev
->path
.mmio
.addr
);
228 case DEVICE_PATH_GPIO
:
229 snprintf(buffer
, sizeof(buffer
), "GPIO: %d", dev
->path
.gpio
.id
);
231 case DEVICE_PATH_MDIO
:
232 snprintf(buffer
, sizeof(buffer
), "MDIO: %02x", dev
->path
.mdio
.addr
);
234 case DEVICE_PATH_GICC_V3
:
235 snprintf(buffer
, sizeof(buffer
), "GICV3: %02x", dev
->path
.gicc_v3
.mpidr
);
238 printk(BIOS_ERR
, "Unknown device path type: %d\n",
246 const char *dev_name(const struct device
*dev
)
250 else if (dev
->chip_ops
&& dev
->chip_ops
->name
)
251 return dev
->chip_ops
->name
;
256 /* Returns the domain for the given device */
257 const struct device
*dev_get_domain(const struct device
*dev
)
259 /* Walk up the tree up to the domain */
260 while (dev
&& dev
->upstream
&& !is_root_device(dev
)) {
261 if (dev
->path
.type
== DEVICE_PATH_DOMAIN
)
263 dev
= dev
->upstream
->dev
;
269 unsigned int dev_get_domain_id(const struct device
*dev
)
271 const struct device
*domain_dev
= dev_get_domain(dev
);
276 printk(BIOS_ERR
, "%s: doesn't have a domain device\n", dev_path(dev
));
280 return domain_dev
->path
.domain
.domain_id
;
283 bool is_domain0(const struct device
*dev
)
285 return dev
&& dev
->path
.type
== DEVICE_PATH_DOMAIN
&& dev
->path
.domain
.domain_id
== 0;
288 bool is_dev_on_domain0(const struct device
*dev
)
290 return is_domain0(dev_get_domain(dev
));
294 * Allocate 64 more resources to the free list.
298 static int allocate_more_resources(void)
301 struct resource
*new_res_list
;
303 new_res_list
= malloc(64 * sizeof(*new_res_list
));
305 if (new_res_list
== NULL
)
308 memset(new_res_list
, 0, 64 * sizeof(*new_res_list
));
310 for (i
= 0; i
< 64 - 1; i
++)
311 new_res_list
[i
].next
= &new_res_list
[i
+1];
313 free_resources
= new_res_list
;
318 * Remove resource res from the device's list and add it to the free list.
325 static void free_resource(struct device
*dev
, struct resource
*res
,
326 struct resource
*prev
)
329 prev
->next
= res
->next
;
331 dev
->resource_list
= res
->next
;
333 res
->next
= free_resources
;
334 free_resources
= res
;
338 * See if we have unused but allocated resource structures.
340 * If so remove the allocation.
342 * @param dev The device to find the resource on.
344 void compact_resources(struct device
*dev
)
346 struct resource
*res
, *next
, *prev
= NULL
;
348 /* Move all of the free resources to the end */
349 for (res
= dev
->resource_list
; res
; res
= next
) {
352 free_resource(dev
, res
, prev
);
359 * See if a resource structure already exists for a given index.
361 * @param dev The device to find the resource on.
362 * @param index The index of the resource on the device.
363 * @return The resource, if it already exists.
365 struct resource
*probe_resource(const struct device
*dev
, unsigned int index
)
367 struct resource
*res
;
369 /* See if there is a resource with the appropriate index */
370 for (res
= dev
->resource_list
; res
; res
= res
->next
) {
371 if (res
->index
== index
)
379 * See if a resource structure already exists for a given index and if not
382 * Then initialize the resource to default values.
384 * @param dev The device to find the resource on.
385 * @param index The index of the resource on the device.
388 struct resource
*new_resource(struct device
*dev
, unsigned int index
)
390 struct resource
*resource
, *tail
;
392 /* First move all of the free resources to the end. */
393 compact_resources(dev
);
395 /* See if there is a resource with the appropriate index. */
396 resource
= probe_resource(dev
, index
);
398 if (free_resources
== NULL
&& !allocate_more_resources())
399 die("Couldn't allocate more resources.");
401 resource
= free_resources
;
402 free_resources
= free_resources
->next
;
403 memset(resource
, 0, sizeof(*resource
));
404 resource
->next
= NULL
;
405 tail
= dev
->resource_list
;
409 tail
->next
= resource
;
411 dev
->resource_list
= resource
;
415 /* Initialize the resource values. */
416 if (!(resource
->flags
& IORESOURCE_FIXED
)) {
422 resource
->index
= index
;
430 * Return an existing resource structure for a given index.
432 * @param dev The device to find the resource on.
433 * @param index The index of the resource on the device.
436 struct resource
*find_resource(const struct device
*dev
, unsigned int index
)
438 struct resource
*resource
;
440 /* See if there is a resource with the appropriate index. */
441 resource
= probe_resource(dev
, index
);
443 die("%s missing resource: %02x\n", dev_path(dev
), index
);
448 * Round a number up to the next multiple of gran.
450 * @param val The starting value.
451 * @param gran Granularity we are aligning the number to.
452 * @return The aligned value.
454 static resource_t
align_up(resource_t val
, unsigned long gran
)
457 mask
= (1ULL << gran
) - 1ULL;
464 * Round a number up to the previous multiple of gran.
466 * @param val The starting value.
467 * @param gran Granularity we are aligning the number to.
468 * @return The aligned value.
470 static resource_t
align_down(resource_t val
, unsigned long gran
)
473 mask
= (1ULL << gran
) - 1ULL;
479 * Compute the maximum address that is part of a resource.
481 * @param resource The resource whose limit is desired.
484 resource_t
resource_end(const struct resource
*resource
)
486 resource_t base
, end
;
488 /* Get the base address. */
489 base
= resource
->base
;
492 * For a non bridge resource granularity and alignment are the same.
493 * For a bridge resource align is the largest needed alignment below
494 * the bridge. While the granularity is simply how many low bits of
495 * the address cannot be set.
498 /* Get the end (rounded up). */
499 end
= base
+ align_up(resource
->size
, resource
->gran
) - 1;
505 * Compute the maximum legal value for resource->base.
507 * @param resource The resource whose maximum is desired.
508 * @return The maximum.
510 resource_t
resource_max(const struct resource
*resource
)
514 max
= align_down(resource
->limit
- resource
->size
+ 1, resource
->align
);
520 * Return the resource type of a resource.
522 * @param resource The resource type to decode.
525 const char *resource_type(const struct resource
*resource
)
527 static char buffer
[RESOURCE_TYPE_MAX
];
528 snprintf(buffer
, sizeof(buffer
), "%s%s%s%s",
529 ((resource
->flags
& IORESOURCE_READONLY
) ? "ro" : ""),
530 ((resource
->flags
& IORESOURCE_PREFETCH
) ? "pref" : ""),
531 ((resource
->flags
== 0) ? "unused" :
532 (resource
->flags
& IORESOURCE_IO
) ? "io" :
533 (resource
->flags
& IORESOURCE_DRQ
) ? "drq" :
534 (resource
->flags
& IORESOURCE_IRQ
) ? "irq" :
535 (resource
->flags
& IORESOURCE_MEM
) ? "mem" : "??????"),
536 ((resource
->flags
& IORESOURCE_PCI64
) ? "64" : ""));
541 * Print the resource that was just stored.
543 * @param dev The device the stored resource lives on.
544 * @param resource The resource that was just stored.
545 * @param comment TODO
547 void report_resource_stored(struct device
*dev
, const struct resource
*resource
,
551 unsigned long long base
, end
;
553 if (!(resource
->flags
& IORESOURCE_STORED
))
556 base
= resource
->base
;
557 end
= resource_end(resource
);
560 if (dev
->downstream
&& (resource
->flags
& IORESOURCE_PCI_BRIDGE
)) {
561 snprintf(buf
, sizeof(buf
),
562 "seg %02x bus %02x ", dev
->downstream
->segment_group
,
563 dev
->downstream
->secondary
);
565 printk(BIOS_DEBUG
, "%s %02lx <- [0x%016llx - 0x%016llx] size 0x%08llx "
566 "gran 0x%02x %s%s%s\n", dev_path(dev
), resource
->index
,
567 base
, end
, resource
->size
, resource
->gran
, buf
,
568 resource_type(resource
), comment
);
571 void search_bus_resources(struct bus
*bus
, unsigned long type_mask
,
572 unsigned long type
, resource_search_t search
,
575 struct device
*curdev
;
577 for (curdev
= bus
->children
; curdev
; curdev
= curdev
->sibling
) {
578 struct resource
*res
;
580 /* Ignore disabled devices. */
581 if (!curdev
->enabled
)
584 for (res
= curdev
->resource_list
; res
; res
= res
->next
) {
585 /* If it isn't the right kind of resource ignore it. */
586 if ((res
->flags
& type_mask
) != type
)
589 /* If it is a subtractive resource recurse. */
590 if (res
->flags
& IORESOURCE_SUBTRACTIVE
) {
591 if (curdev
->downstream
)
592 search_bus_resources(curdev
->downstream
, type_mask
, type
,
596 search(gp
, curdev
, res
);
601 void search_global_resources(unsigned long type_mask
, unsigned long type
,
602 resource_search_t search
, void *gp
)
604 struct device
*curdev
;
606 for (curdev
= all_devices
; curdev
; curdev
= curdev
->next
) {
607 struct resource
*res
;
609 /* Ignore disabled devices. */
610 if (!curdev
->enabled
)
613 for (res
= curdev
->resource_list
; res
; res
= res
->next
) {
614 /* If it isn't the right kind of resource ignore it. */
615 if ((res
->flags
& type_mask
) != type
)
618 /* If it is a subtractive resource ignore it. */
619 if (res
->flags
& IORESOURCE_SUBTRACTIVE
)
622 /* If the resource is not assigned ignore it. */
623 if (!(res
->flags
& IORESOURCE_ASSIGNED
))
626 search(gp
, curdev
, res
);
631 void dev_set_enabled(struct device
*dev
, int enable
)
633 if (dev
->enabled
== enable
)
636 dev
->enabled
= enable
;
637 if (dev
->ops
&& dev
->ops
->enable
)
638 dev
->ops
->enable(dev
);
639 else if (dev
->chip_ops
&& dev
->chip_ops
->enable_dev
)
640 dev
->chip_ops
->enable_dev(dev
);
643 void disable_children(struct bus
*bus
)
645 struct device
*child
;
647 for (child
= bus
->children
; child
; child
= child
->sibling
) {
648 if (child
->downstream
)
649 disable_children(child
->downstream
);
650 dev_set_enabled(child
, 0);
655 * Returns true if the device is an enabled bridge that has at least
656 * one enabled device on its secondary bus that is not of type NONE.
658 bool dev_is_active_bridge(struct device
*dev
)
660 struct device
*child
;
662 if (!dev
|| !dev
->enabled
)
665 if (!dev
->downstream
|| !dev
->downstream
->children
)
668 for (child
= dev
->downstream
->children
; child
; child
= child
->sibling
) {
669 if (child
->path
.type
== DEVICE_PATH_NONE
)
678 static void resource_tree(const struct device
*root
, int debug_level
, int depth
)
681 struct device
*child
;
682 struct resource
*res
;
683 char indent
[30]; /* If your tree has more levels, it's wrong. */
685 for (i
= 0; i
< depth
+ 1 && i
< 29; i
++)
689 printk(BIOS_DEBUG
, "%s%s", indent
, dev_path(root
));
690 if (root
->downstream
&& root
->downstream
->children
)
691 printk(BIOS_DEBUG
, " child on link 0 %s",
692 dev_path(root
->downstream
->children
));
693 printk(BIOS_DEBUG
, "\n");
695 for (res
= root
->resource_list
; res
; res
= res
->next
) {
696 printk(debug_level
, "%s%s resource base %llx size %llx "
697 "align %d gran %d limit %llx flags %lx index %lx\n",
698 indent
, dev_path(root
), res
->base
, res
->size
,
699 res
->align
, res
->gran
, res
->limit
, res
->flags
,
703 if (!root
->downstream
)
706 for (child
= root
->downstream
->children
; child
; child
= child
->sibling
)
707 resource_tree(child
, debug_level
, depth
+ 1);
710 void print_resource_tree(const struct device
*root
, int debug_level
,
713 /* Bail if root is null. */
715 printk(debug_level
, "%s passed NULL for root!\n", __func__
);
719 /* Bail if not printing to screen. */
720 if (!printk(debug_level
, "Show resources in subtree (%s)...%s\n",
721 dev_path(root
), msg
))
724 resource_tree(root
, debug_level
, 0);
727 void show_devs_tree(const struct device
*dev
, int debug_level
, int depth
)
731 struct device
*sibling
;
733 for (i
= 0; i
< depth
; i
++)
737 printk(debug_level
, "%s%s: enabled %d\n",
738 depth_str
, dev_path(dev
), dev
->enabled
);
740 if (!dev
->downstream
)
743 for (sibling
= dev
->downstream
->children
; sibling
; sibling
= sibling
->sibling
)
744 show_devs_tree(sibling
, debug_level
, depth
+ 1);
747 void show_all_devs_tree(int debug_level
, const char *msg
)
749 /* Bail if not printing to screen. */
750 if (!printk(debug_level
, "Show all devs in tree form... %s\n", msg
))
752 show_devs_tree(all_devices
, debug_level
, 0);
755 void show_devs_subtree(struct device
*root
, int debug_level
, const char *msg
)
757 /* Bail if not printing to screen. */
758 if (!printk(debug_level
, "Show all devs in subtree %s... %s\n",
759 dev_path(root
), msg
))
761 printk(debug_level
, "%s\n", msg
);
762 show_devs_tree(root
, debug_level
, 0);
765 void show_all_devs(int debug_level
, const char *msg
)
769 /* Bail if not printing to screen. */
770 if (!printk(debug_level
, "Show all devs... %s\n", msg
))
772 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
773 printk(debug_level
, "%s: enabled %d\n",
774 dev_path(dev
), dev
->enabled
);
778 void show_one_resource(int debug_level
, struct device
*dev
,
779 struct resource
*resource
, const char *comment
)
782 unsigned long long base
, end
;
783 base
= resource
->base
;
784 end
= resource_end(resource
);
787 printk(debug_level
, "%s %02lx <- [0x%016llx - 0x%016llx] "
788 "size 0x%08llx gran 0x%02x %s%s%s\n", dev_path(dev
),
789 resource
->index
, base
, end
, resource
->size
, resource
->gran
,
790 buf
, resource_type(resource
), comment
);
793 void show_all_devs_resources(int debug_level
, const char *msg
)
797 if (!printk(debug_level
, "Show all devs with resources... %s\n", msg
))
800 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
801 struct resource
*res
;
802 printk(debug_level
, "%s: enabled %d\n",
803 dev_path(dev
), dev
->enabled
);
804 for (res
= dev
->resource_list
; res
; res
= res
->next
)
805 show_one_resource(debug_level
, dev
, res
, "");
809 const struct resource
*resource_range_idx(struct device
*dev
, unsigned long index
,
810 uint64_t base
, uint64_t size
, unsigned long flags
)
812 struct resource
*resource
;
816 resource
= new_resource(dev
, index
);
817 resource
->base
= base
;
819 if (flags
& IORESOURCE_FIXED
)
820 resource
->size
= size
;
821 if (flags
& IORESOURCE_BRIDGE
)
822 resource
->limit
= base
+ size
- 1;
824 resource
->flags
= IORESOURCE_ASSIGNED
;
825 resource
->flags
|= flags
;
827 printk(BIOS_SPEW
, "dev: %s, index: 0x%lx, base: 0x%llx, size: 0x%llx\n",
828 dev_path(dev
), resource
->index
, resource
->base
, resource
->size
);
833 const struct resource
*lower_ram_end(struct device
*dev
, unsigned long index
, uint64_t end
)
835 return ram_from_to(dev
, index
, 0, end
);
838 const struct resource
*upper_ram_end(struct device
*dev
, unsigned long index
, uint64_t end
)
840 if (end
<= 4ull * GiB
)
843 printk(BIOS_INFO
, "Available memory above 4GB: %lluM\n", (end
- 4ull * GiB
) / MiB
);
845 return ram_from_to(dev
, index
, 4ull * GiB
, end
);
848 void mmconf_resource(struct device
*dev
, unsigned long index
)
850 struct resource
*resource
= new_resource(dev
, index
);
851 resource
->base
= CONFIG_ECAM_MMCONF_BASE_ADDRESS
;
852 resource
->size
= CONFIG_ECAM_MMCONF_LENGTH
;
853 resource
->flags
= IORESOURCE_MEM
| IORESOURCE_RESERVE
|
854 IORESOURCE_FIXED
| IORESOURCE_STORED
| IORESOURCE_ASSIGNED
;
856 printk(BIOS_DEBUG
, "Adding PCIe enhanced config space BAR 0x%08lx-0x%08lx.\n",
857 (unsigned long)(resource
->base
),
858 (unsigned long)(resource
->base
+ resource
->size
));
861 void tolm_test(void *gp
, struct device
*dev
, struct resource
*new)
863 struct resource
**best_p
= gp
;
864 struct resource
*best
;
869 * If resource is not allocated any space i.e. size is zero,
870 * then do not consider this resource in tolm calculations.
875 if (!best
|| (best
->base
> new->base
))
881 u32
find_pci_tolm(struct bus
*bus
)
883 struct resource
*min
= NULL
;
885 unsigned long mask_match
= IORESOURCE_MEM
| IORESOURCE_ASSIGNED
;
887 search_bus_resources(bus
, mask_match
, mask_match
, tolm_test
, &min
);
891 if (min
&& tolm
> min
->base
)
897 /* Count of enabled CPUs */
898 int dev_count_cpu(void)
903 for (cpu
= all_devices
; cpu
; cpu
= cpu
->next
) {
904 if (!is_enabled_cpu(cpu
))
912 /* Get device path name */
913 const char *dev_path_name(enum device_path_type type
)
915 static const char *const type_names
[] = DEVICE_PATH_NAMES
;
916 const char *type_name
= "Unknown";
918 /* Translate the type value into a string */
919 if (type
< ARRAY_SIZE(type_names
))
920 type_name
= type_names
[type
];
924 bool dev_path_hotplug(const struct device
*dev
)
926 for (dev
= dev
->upstream
->dev
; dev
!= dev
->upstream
->dev
; dev
= dev
->upstream
->dev
) {
927 if (dev
->hotplug_port
)
933 void log_resource(const char *type
, const struct device
*dev
, const struct resource
*res
,
934 const char *srcfile
, const int line
)
936 printk(BIOS_SPEW
, "%s:%d res: %s, dev: %s, index: 0x%lx, base: 0x%llx, "
937 "end: 0x%llx, size_kb: 0x%llx\n",
938 srcfile
, line
, type
, dev_path(dev
), res
->index
, res
->base
,
939 resource_end(res
), res
->size
/ KiB
);
942 bool is_cpu(const struct device
*cpu
)
944 return cpu
->path
.type
== DEVICE_PATH_APIC
&&
945 cpu
->upstream
->dev
->path
.type
== DEVICE_PATH_CPU_CLUSTER
;
948 bool is_enabled_cpu(const struct device
*cpu
)
950 return is_cpu(cpu
) && cpu
->enabled
;
953 bool is_pci(const struct device
*pci
)
955 return pci
->path
.type
== DEVICE_PATH_PCI
;
958 bool is_enabled_pci(const struct device
*pci
)
960 return is_pci(pci
) && pci
->enabled
;
963 bool is_pci_dev_on_bus(const struct device
*pci
, unsigned int bus
)
965 return is_pci(pci
) && pci
->upstream
->segment_group
== 0
966 && pci
->upstream
->secondary
== bus
;
969 bool is_pci_bridge(const struct device
*pci
)
971 return is_pci(pci
) && ((pci
->hdr_type
& 0x7f) == PCI_HEADER_TYPE_BRIDGE
);
974 bool is_pci_ioapic(const struct device
*pci
)
976 return is_pci(pci
) && ((pci
->class >> 16) == PCI_BASE_CLASS_SYSTEM
) &&
977 ((pci
->class >> 8) == PCI_CLASS_SYSTEM_PIC
) &&
978 ((pci
->class & 0xff) >= 0x10);