Add commands pci_{set,get}_path, add pci config files.

This commit is contained in:
2020-05-20 17:54:58 +03:00
parent 6cc26c6f55
commit b3020947af
69 changed files with 2372 additions and 5042 deletions

View File

@@ -4,12 +4,20 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include "pci.h"
char pci_path[PATH_MAX] = ".";
__attribute__((stdcall)) uint32_t pci_read(uint32_t bus, uint32_t dev, uint32_t fun, uint32_t offset, size_t len) {
char path[128];
char path[PATH_MAX*2];
uint32_t value = 0;
sprintf(path, "/sys/bus/pci/devices/%4.4u:%2.2u:%2.2u.%u/config", 0, bus, dev, fun);
sprintf(path, "%s/%4.4u:%2.2u:%2.2u.%u/config", pci_path, 0, bus, dev, fun);
int fd = open(path, O_RDONLY);
if (!fd) {
// TODO: report an error
return UINT32_MAX;
}
lseek(fd, offset, SEEK_SET);
read(fd, &value, len);
close(fd);