1
0

patch-src_linux_sysfs_c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. --- libpciaccess-0.13.2.orig/src/linux_sysfs.c 2013-07-21 00:54:34.000000000 +0200
  2. +++ libpciaccess-0.13.2/src/linux_sysfs.c 2014-03-24 21:01:44.000000000 +0100
  3. @@ -41,11 +41,12 @@
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. +#include <limits.h>
  8. #include <sys/mman.h>
  9. #include <dirent.h>
  10. #include <errno.h>
  11. -#if defined(__i386__) || defined(__x86_64__) || defined(__arm__)
  12. +#if defined(__i386__) || defined(__x86_64__)
  13. #include <sys/io.h>
  14. #else
  15. #define inb(x) -1
  16. @@ -759,6 +760,7 @@ pci_device_linux_sysfs_open_device_io(st
  17. ret->base = base;
  18. ret->size = size;
  19. + ret->is_legacy = 0;
  20. return ret;
  21. }
  22. @@ -796,6 +798,7 @@ pci_device_linux_sysfs_open_legacy_io(st
  23. ret->base = base;
  24. ret->size = size;
  25. + ret->is_legacy = 1;
  26. return ret;
  27. }
  28. @@ -813,10 +816,14 @@ pci_device_linux_sysfs_read32(struct pci
  29. {
  30. uint32_t ret;
  31. - if (handle->fd > -1)
  32. - pread(handle->fd, &ret, 4, port + handle->base);
  33. - else
  34. + if (handle->fd > -1) {
  35. + if (handle->is_legacy)
  36. + pread(handle->fd, &ret, 4, port + handle->base);
  37. + else
  38. + pread(handle->fd, &ret, 4, port);
  39. + } else {
  40. ret = inl(port + handle->base);
  41. + }
  42. return ret;
  43. }
  44. @@ -826,10 +833,14 @@ pci_device_linux_sysfs_read16(struct pci
  45. {
  46. uint16_t ret;
  47. - if (handle->fd > -1)
  48. - pread(handle->fd, &ret, 2, port + handle->base);
  49. - else
  50. + if (handle->fd > -1) {
  51. + if (handle->is_legacy)
  52. + pread(handle->fd, &ret, 2, port + handle->base);
  53. + else
  54. + pread(handle->fd, &ret, 2, port);
  55. + } else {
  56. ret = inw(port + handle->base);
  57. + }
  58. return ret;
  59. }
  60. @@ -839,10 +850,14 @@ pci_device_linux_sysfs_read8(struct pci_
  61. {
  62. uint8_t ret;
  63. - if (handle->fd > -1)
  64. - pread(handle->fd, &ret, 1, port + handle->base);
  65. - else
  66. + if (handle->fd > -1) {
  67. + if (handle->is_legacy)
  68. + pread(handle->fd, &ret, 1, port + handle->base);
  69. + else
  70. + pread(handle->fd, &ret, 1, port);
  71. + } else {
  72. ret = inb(port + handle->base);
  73. + }
  74. return ret;
  75. }
  76. @@ -851,30 +866,42 @@ static void
  77. pci_device_linux_sysfs_write32(struct pci_io_handle *handle, uint32_t port,
  78. uint32_t data)
  79. {
  80. - if (handle->fd > -1)
  81. - pwrite(handle->fd, &data, 4, port + handle->base);
  82. - else
  83. + if (handle->fd > -1) {
  84. + if (handle->is_legacy)
  85. + pwrite(handle->fd, &data, 4, port + handle->base);
  86. + else
  87. + pwrite(handle->fd, &data, 4, port);
  88. + } else {
  89. outl(data, port + handle->base);
  90. + }
  91. }
  92. static void
  93. pci_device_linux_sysfs_write16(struct pci_io_handle *handle, uint32_t port,
  94. uint16_t data)
  95. {
  96. - if (handle->fd > -1)
  97. - pwrite(handle->fd, &data, 2, port + handle->base);
  98. - else
  99. + if (handle->fd > -1) {
  100. + if (handle->is_legacy)
  101. + pwrite(handle->fd, &data, 2, port + handle->base);
  102. + else
  103. + pwrite(handle->fd, &data, 2, port);
  104. + } else {
  105. outw(data, port + handle->base);
  106. + }
  107. }
  108. static void
  109. pci_device_linux_sysfs_write8(struct pci_io_handle *handle, uint32_t port,
  110. uint8_t data)
  111. {
  112. - if (handle->fd > -1)
  113. - pwrite(handle->fd, &data, 1, port + handle->base);
  114. - else
  115. + if (handle->fd > -1) {
  116. + if (handle->is_legacy)
  117. + pwrite(handle->fd, &data, 1, port + handle->base);
  118. + else
  119. + pwrite(handle->fd, &data, 1, port);
  120. + } else {
  121. outb(data, port + handle->base);
  122. + }
  123. }
  124. static int