/contrib/ntp/kernel/sys/pcl720.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 95 lines · 69 code · 8 blank · 18 comment · 0 complexity · 6d2a6c8d1ff72d2638991a7b9aeab770 MD5 · raw file

  1. /* Copyright (c) 1995 Vixie Enterprises
  2. *
  3. * Permission to use, copy, modify, and distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies, and that
  6. * the name of Vixie Enterprises not be used in advertising or publicity
  7. * pertaining to distribution of the document or software without specific,
  8. * written prior permission.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND VIXIE ENTERPRISES DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  12. * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VIXIE ENTERPRISES
  13. * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
  14. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  15. * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  16. * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  17. * SOFTWARE.
  18. */
  19. #ifndef _PCL720_DEFINED
  20. #define _PCL720_DEFINED
  21. #define pcl720_data(base,bit) (base+(bit>>3))
  22. #define pcl720_data_0_7(base) (base+0)
  23. #define pcl720_data_8_15(base) (base+1)
  24. #define pcl720_data_16_23(base) (base+2)
  25. #define pcl720_data_24_31(base) (base+3)
  26. #define pcl720_cntr(base,cntr) (base+4+cntr) /* cntr: 0..2 */
  27. #define pcl720_cntr_0(base) (base+4)
  28. #define pcl720_cntr_1(base) (base+5)
  29. #define pcl720_cntr_2(base) (base+6)
  30. #define pcl720_ctrl(base) (base+7)
  31. #ifndef DEBUG_PCL720
  32. #define pcl720_inb(x) inb(x)
  33. #define pcl720_outb(x,y) outb(x,y)
  34. #else
  35. static unsigned char pcl720_inb(int addr) {
  36. unsigned char x = inb(addr);
  37. fprintf(DEBUG_PCL720, "inb(0x%x) -> 0x%x\n", addr, x);
  38. return (x);
  39. }
  40. static void pcl720_outb(int addr, unsigned char x) {
  41. outb(addr, x);
  42. fprintf(DEBUG_PCL720, "outb(0x%x, 0x%x)\n", addr, x);
  43. }
  44. #endif
  45. #define pcl720_load(Base,Cntr,Mode,Val) \
  46. ({ register unsigned int b = Base, c = Cntr, v = Val; \
  47. i8253_ctrl ctrl; \
  48. \
  49. ctrl.s.bcd = i8253_binary; \
  50. ctrl.s.mode = Mode; \
  51. ctrl.s.rl = i8253_lmb; \
  52. ctrl.s.cntr = c; \
  53. pcl720_outb(pcl720_ctrl(b), ctrl.i); \
  54. pcl720_outb(pcl720_cntr(b,c), v); \
  55. pcl720_outb(pcl720_cntr(b,c), v >> 8); \
  56. v; \
  57. })
  58. #define pcl720_read(Base,Cntr) \
  59. ({ register unsigned int b = Base, v; \
  60. i8253_ctrl ctrl; \
  61. \
  62. ctrl.s.rl = i8253_latch; \
  63. ctrl.s.cntr = i8253_cntr_0; \
  64. pcl720_outb(pcl720_ctrl(b), ctrl.i); \
  65. v = pcl720_inb(pcl720_cntr_0(b)); \
  66. v |= (pcl720_inb(pcl720_cntr_0(b)) << 8); \
  67. v; \
  68. })
  69. #define pcl720_input(Base) \
  70. ({ register unsigned int b = Base, v; \
  71. \
  72. v = pcl720_inb(pcl720_data_0_7(b)); \
  73. v |= (pcl720_inb(pcl720_data_8_15(b)) << 8); \
  74. v |= (pcl720_inb(pcl720_data_16_23(b)) << 16); \
  75. v |= (pcl720_inb(pcl720_data_24_31(b)) << 24); \
  76. v; \
  77. })
  78. #define pcl720_output(Base,Value) \
  79. ({ register unsigned int b = Base, v = Value; \
  80. \
  81. pcl720_outb(pcl720_data_0_7(b), v); \
  82. pcl720_outb(pcl720_data_8_15(b), v << 8); \
  83. pcl720_outb(pcl720_data_16_23(b), v << 16); \
  84. pcl720_outb(pcl720_data_24_31(b), v << 24); \
  85. v; \
  86. })
  87. #endif /*_PCL720_DEFINED*/