Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Paste
P644
PCIOCGETCONF Test
Active
Public
Actions
Authored by
jfree
on Jul 29 2024, 10:36 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Flag For Later
Award Token
Tags
None
Referenced Files
F89600673: PCIOCGETCONF Test
Jul 29 2024, 10:36 PM
2024-07-29 22:36:42 (UTC+0)
Subscribers
None
#include
<sys/types.h>
#include
<sys/ioctl.h>
#include
<sys/pciio.h>
#include
<err.h>
#include
<fcntl.h>
#include
<stdio.h>
#define PCI_CHARDEV "/dev/pci"
#define PCI_VENDOR_INTEL 0x8086
/* Find all intel devices on the PCI bus and report info about them. */
int
main
(
void
)
{
struct
pci_conf_io
pcio
=
{
};
struct
pci_conf
devs
[
16
];
struct
pci_match_conf
pmc
;
int
pcifd
;
pcifd
=
open
(
PCI_CHARDEV
,
O_RDWR
);
if
(
pcifd
<
0
)
err
(
1
,
"Failed to open "
PCI_CHARDEV
);
pmc
.
pc_vendor
=
0x8086
;
/* Intel */
pmc
.
flags
=
PCI_GETCONF_MATCH_VENDOR
;
pcio
.
pat_buf_len
=
sizeof
(
pmc
);
pcio
.
num_patterns
=
1
;
pcio
.
patterns
=
&
pmc
;
pcio
.
match_buf_len
=
sizeof
(
devs
);
pcio
.
matches
=
devs
;
restart
:
pcio
.
offset
=
0
;
pcio
.
generation
=
0
;
do
{
if
(
ioctl
(
pcifd
,
PCIOCGETCONF
,
&
pcio
)
<
0
)
err
(
1
,
"PCIOCGETCONF ioctl failed"
);
if
(
pcio
.
status
==
PCI_GETCONF_LIST_CHANGED
)
goto
restart
;
else
if
(
pcio
.
status
==
PCI_GETCONF_ERROR
)
errx
(
1
,
"PCI_GETCONF_ERROR detected"
);
for
(
int
i
=
0
;
i
<
pcio
.
num_matches
;
++
i
)
{
struct
pci_conf
*
dev
=
devs
+
i
;
printf
(
"--- Device %d ---
\n
"
,
i
);
printf
(
"DBDF: %u:%u:%u.%u
\n
"
,
dev
->
pc_sel
.
pc_domain
,
dev
->
pc_sel
.
pc_bus
,
dev
->
pc_sel
.
pc_dev
,
dev
->
pc_sel
.
pc_func
);
printf
(
"header type: %u
\n
"
,
dev
->
pc_hdr
);
printf
(
"subvendor: %u
\n
"
,
dev
->
pc_subvendor
);
printf
(
"subdevice: %u
\n
"
,
dev
->
pc_subdevice
);
printf
(
"vendor: %u
\n
"
,
dev
->
pc_vendor
);
printf
(
"device: %u
\n
"
,
dev
->
pc_device
);
printf
(
"class: %u
\n
"
,
dev
->
pc_class
);
printf
(
"subclass: %u
\n
"
,
dev
->
pc_subclass
);
printf
(
"progif: %u
\n
"
,
dev
->
pc_progif
);
printf
(
"revid: %u
\n
"
,
dev
->
pc_revid
);
printf
(
"driver: %s
\n
"
,
dev
->
pd_name
);
printf
(
"unit: %lu
\n
"
,
dev
->
pd_unit
);
printf
(
"NUMA node: %d
\n\n
"
,
dev
->
pd_numa_domain
);
}
}
while
(
pcio
.
status
==
PCI_GETCONF_MORE_DEVS
);
return
0
;
}
Event Timeline
jfree
created this paste.
Jul 29 2024, 10:36 PM
2024-07-29 22:36:42 (UTC+0)
jfree
created this object in space
S1 Global
.
jfree
created this object with edit policy "Administrators".
jfree
mentioned this in
D44289: pci_user: Report NUMA domain
.
Jul 29 2024, 10:44 PM
2024-07-29 22:44:29 (UTC+0)
Log In to Comment