1 /*
2 * Copyright © 2009 CNRS
3 * Copyright © 2009-2019 Inria. All rights reserved.
4 * Copyright © Université Bordeaux
5 * See COPYING in top-level directory.
6 */
7
8 #include "private/autogen/config.h"
9 #include "hwloc.h"
10
11 #include <assert.h>
12
13 /* check misc i/O device related stuff */
14
main(void)15 int main(void)
16 {
17 hwloc_topology_t topology;
18 hwloc_obj_t obj;
19
20 hwloc_topology_init(&topology);
21 hwloc_topology_set_io_types_filter(topology, HWLOC_TYPE_FILTER_KEEP_ALL);
22 hwloc_topology_load(topology);
23
24 printf("Found %d bridges\n", hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_BRIDGE));
25 obj = NULL;
26 while ((obj = hwloc_get_next_bridge(topology, obj)) != NULL) {
27 assert(obj->type == HWLOC_OBJ_BRIDGE);
28 /* only host->pci and pci->pci bridge supported so far */
29 if (obj->attr->bridge.upstream_type == HWLOC_OBJ_BRIDGE_HOST) {
30 assert(obj->attr->bridge.downstream_type == HWLOC_OBJ_BRIDGE_PCI);
31 printf(" Found host->PCI bridge for domain %04x bus %02x-%02x\n",
32 obj->attr->bridge.downstream.pci.domain,
33 obj->attr->bridge.downstream.pci.secondary_bus,
34 obj->attr->bridge.downstream.pci.subordinate_bus);
35 } else {
36 assert(obj->attr->bridge.upstream_type == HWLOC_OBJ_BRIDGE_PCI);
37 assert(obj->attr->bridge.downstream_type == HWLOC_OBJ_BRIDGE_PCI);
38 printf(" Found PCI->PCI bridge [%04x:%04x] for domain %04x bus %02x-%02x\n",
39 obj->attr->bridge.upstream.pci.vendor_id,
40 obj->attr->bridge.upstream.pci.device_id,
41 obj->attr->bridge.downstream.pci.domain,
42 obj->attr->bridge.downstream.pci.secondary_bus,
43 obj->attr->bridge.downstream.pci.subordinate_bus);
44 }
45 }
46
47 printf("Found %d PCI devices\n", hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PCI_DEVICE));
48 obj = NULL;
49 while ((obj = hwloc_get_next_pcidev(topology, obj)) != NULL) {
50 assert(obj->type == HWLOC_OBJ_PCI_DEVICE);
51 printf(" Found PCI device class %04x vendor %04x model %04x\n",
52 obj->attr->pcidev.class_id, obj->attr->pcidev.vendor_id, obj->attr->pcidev.device_id);
53 }
54
55 printf("Found %d OS devices\n", hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_OS_DEVICE));
56 obj = NULL;
57 while ((obj = hwloc_get_next_osdev(topology, obj)) != NULL) {
58 assert(obj->type == HWLOC_OBJ_OS_DEVICE);
59 printf(" Found OS device %s subtype %d\n", obj->name, (int) obj->attr->osdev.type);
60 }
61
62 assert(HWLOC_TYPE_DEPTH_BRIDGE == hwloc_get_type_depth(topology, HWLOC_OBJ_BRIDGE));
63 assert(HWLOC_TYPE_DEPTH_PCI_DEVICE == hwloc_get_type_depth(topology, HWLOC_OBJ_PCI_DEVICE));
64 assert(HWLOC_TYPE_DEPTH_OS_DEVICE == hwloc_get_type_depth(topology, HWLOC_OBJ_OS_DEVICE));
65 assert(hwloc_compare_types(HWLOC_OBJ_BRIDGE, HWLOC_OBJ_PCI_DEVICE) < 0);
66 assert(hwloc_compare_types(HWLOC_OBJ_BRIDGE, HWLOC_OBJ_OS_DEVICE) < 0);
67 assert(hwloc_compare_types(HWLOC_OBJ_PCI_DEVICE, HWLOC_OBJ_OS_DEVICE) < 0);
68
69 hwloc_topology_destroy(topology);
70
71 return 0;
72 }
73