2020-05-02 00:09:42 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2020-05-20 16:54:58 +02:00
|
|
|
#include <limits.h>
|
|
|
|
#include "pci.h"
|
|
|
|
|
|
|
|
char pci_path[PATH_MAX] = ".";
|
2020-05-02 00:09:42 +02:00
|
|
|
|
|
|
|
__attribute__((stdcall)) uint32_t pci_read(uint32_t bus, uint32_t dev, uint32_t fun, uint32_t offset, size_t len) {
|
2020-05-20 16:54:58 +02:00
|
|
|
char path[PATH_MAX*2];
|
2020-05-02 00:09:42 +02:00
|
|
|
uint32_t value = 0;
|
2020-05-20 16:54:58 +02:00
|
|
|
sprintf(path, "%s/%4.4u:%2.2u:%2.2u.%u/config", pci_path, 0, bus, dev, fun);
|
2020-05-02 00:09:42 +02:00
|
|
|
int fd = open(path, O_RDONLY);
|
2020-05-20 16:54:58 +02:00
|
|
|
if (!fd) {
|
|
|
|
// TODO: report an error
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
2020-05-02 00:09:42 +02:00
|
|
|
lseek(fd, offset, SEEK_SET);
|
|
|
|
read(fd, &value, len);
|
|
|
|
close(fd);
|
|
|
|
return value;
|
|
|
|
}
|