Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include <errno.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <inttypes.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <limits.h>
  10. #include "pci.h"
  11.  
  12. char pci_path[PATH_MAX] = ".";
  13.  
  14. __attribute__((stdcall)) uint32_t pci_read(uint32_t bus, uint32_t dev,
  15.                                            uint32_t fun, uint32_t offset,
  16.                                            size_t len) {
  17.     char path[PATH_MAX*2];
  18.     uint32_t value = 0;
  19.     sprintf(path, "%s/%4.4x:%2.2x:%2.2x.%u/config", pci_path, 0, bus, dev, fun);
  20.     int fd = open(path, O_RDONLY);
  21.     if (fd == -1) {
  22. //        fprintf(stderr, "[pci] error: failed to open config file '%s': %s\n",
  23. //                path, strerror(errno));
  24.         return UINT32_MAX;
  25.     }
  26.     lseek(fd, offset, SEEK_SET);
  27.     read(fd, &value, len);
  28.     close(fd);
  29.     return value;
  30. }
  31.