upc.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * File: upc.h
  20. *
  21. * Purpose: Macros to access device
  22. *
  23. * Author: Tevin Chen
  24. *
  25. * Date: Mar 17, 1997
  26. *
  27. */
  28. #ifndef __UPC_H__
  29. #define __UPC_H__
  30. #include "device.h"
  31. #include "ttype.h"
  32. /*--------------------- Export Definitions -------------------------*/
  33. //
  34. // For IO mapped
  35. //
  36. #ifdef IO_MAP
  37. #define VNSvInPortB(dwIOAddress, pbyData) { \
  38. *(pbyData) = inb(dwIOAddress); \
  39. }
  40. #define VNSvInPortW(dwIOAddress, pwData) { \
  41. *(pwData) = inw(dwIOAddress); \
  42. }
  43. #define VNSvInPortD(dwIOAddress, pdwData) { \
  44. *(pdwData) = inl(dwIOAddress); \
  45. }
  46. #define VNSvOutPortB(dwIOAddress, byData) { \
  47. outb(byData, dwIOAddress); \
  48. }
  49. #define VNSvOutPortW(dwIOAddress, wData) { \
  50. outw(wData, dwIOAddress); \
  51. }
  52. #define VNSvOutPortD(dwIOAddress, dwData) { \
  53. outl(dwData, dwIOAddress); \
  54. }
  55. #else
  56. //
  57. // For memory mapped IO
  58. //
  59. #define VNSvInPortB(dwIOAddress, pbyData) { \
  60. volatile unsigned char * pbyAddr = ((unsigned char *)(dwIOAddress)); \
  61. *(pbyData) = readb(pbyAddr); \
  62. }
  63. #define VNSvInPortW(dwIOAddress, pwData) { \
  64. volatile unsigned short *pwAddr = ((unsigned short *)(dwIOAddress)); \
  65. *(pwData) = readw(pwAddr); \
  66. }
  67. #define VNSvInPortD(dwIOAddress, pdwData) { \
  68. volatile unsigned long *pdwAddr = ((unsigned long *)(dwIOAddress)); \
  69. *(pdwData) = readl(pdwAddr); \
  70. }
  71. #define VNSvOutPortB(dwIOAddress, byData) { \
  72. volatile unsigned char * pbyAddr = ((unsigned char *)(dwIOAddress)); \
  73. writeb((unsigned char)byData, pbyAddr); \
  74. }
  75. #define VNSvOutPortW(dwIOAddress, wData) { \
  76. volatile unsigned short *pwAddr = ((unsigned short *)(dwIOAddress)); \
  77. writew((unsigned short)wData, pwAddr); \
  78. }
  79. #define VNSvOutPortD(dwIOAddress, dwData) { \
  80. volatile unsigned long *pdwAddr = ((unsigned long *)(dwIOAddress)); \
  81. writel((unsigned long)dwData, pdwAddr); \
  82. }
  83. #endif
  84. //
  85. // ALWAYS IO-Mapped IO when in 16-bit/32-bit environment
  86. //
  87. #define PCBvInPortB(dwIOAddress, pbyData) { \
  88. *(pbyData) = inb(dwIOAddress); \
  89. }
  90. #define PCBvInPortW(dwIOAddress, pwData) { \
  91. *(pwData) = inw(dwIOAddress); \
  92. }
  93. #define PCBvInPortD(dwIOAddress, pdwData) { \
  94. *(pdwData) = inl(dwIOAddress); \
  95. }
  96. #define PCBvOutPortB(dwIOAddress, byData) { \
  97. outb(byData, dwIOAddress); \
  98. }
  99. #define PCBvOutPortW(dwIOAddress, wData) { \
  100. outw(wData, dwIOAddress); \
  101. }
  102. #define PCBvOutPortD(dwIOAddress, dwData) { \
  103. outl(dwData, dwIOAddress); \
  104. }
  105. #define PCAvDelayByIO(uDelayUnit) { \
  106. unsigned char byData; \
  107. unsigned long ii; \
  108. \
  109. if (uDelayUnit <= 50) { \
  110. udelay(uDelayUnit); \
  111. } \
  112. else { \
  113. for (ii = 0; ii < (uDelayUnit); ii++) \
  114. byData = inb(0x61); \
  115. } \
  116. }
  117. /*--------------------- Export Classes ----------------------------*/
  118. /*--------------------- Export Variables --------------------------*/
  119. /*--------------------- Export Functions --------------------------*/
  120. #endif // __UPC_H__