Parse PCI devices in DBDF form.

This commit is contained in:
Adam Madsen
2020-11-03 18:00:40 -06:00
parent d0b17b2bb5
commit 91ad547e08
4 changed files with 125 additions and 20 deletions
+24 -18
View File
@@ -1,6 +1,7 @@
/*
Vendor Reset - Vendor Specific Reset
Copyright (C) 2020 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2020 Adam Madsen <adam@ajmadsen.com>
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -22,24 +23,30 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <fcntl.h>
#include <sys/ioctl.h>
#include "vendor-reset.h"
#include "ucommon.h"
int main(int argc, char * argv[])
void help_(const char *prog);
void help_(const char *prog)
{
fprintf(stderr,
"Usage:\n"
" %s [domain:]bus:dev.fn\n",
prog);
exit(1);
}
#define help() help_(argv[0])
int main(int argc, char *argv[])
{
int ret;
struct dbdf devref;
if (argc < 4)
{
fprintf(stderr,
"Usage:\n"
" %s <domain> <bus> <devfn>\n",
argv[0]
);
return -1;
}
if (argc < 2)
help();
int domain = atoi(argv[1]);
int bus = atoi(argv[2]);
int devfn = atoi(argv[3]);
if (parse_dbdf(argv[1], &devref))
help();
int fd = open("/dev/vendor_reset", O_RDWR);
if (fd < 0)
@@ -48,11 +55,10 @@ int main(int argc, char * argv[])
return fd;
}
struct vendor_reset_ioctl dev =
{
.domain = domain,
.bus = bus,
.devfn = devfn
struct vendor_reset_ioctl dev = {
.domain = devref.domain,
.bus = devref.bus,
.devfn = ((devref.device & 0x1f) << 3) | (devref.function & 0x07),
};
ret = ioctl(fd, VENDOR_RESET_RESET, &dev);