mc146818rtc.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Machine dependent access functions for RTC registers.
  3. */
  4. #ifndef _ASM_MC146818RTC_H
  5. #define _ASM_MC146818RTC_H
  6. #include <asm/io.h>
  7. #include <asm/system.h>
  8. #include <linux/mc146818rtc.h>
  9. #ifndef RTC_PORT
  10. #define RTC_PORT(x) (0x70 + (x))
  11. #define RTC_ALWAYS_BCD 1 /* RTC operates in binary mode */
  12. #endif
  13. #ifdef __HAVE_ARCH_CMPXCHG
  14. /*
  15. * This lock provides nmi access to the CMOS/RTC registers. It has some
  16. * special properties. It is owned by a CPU and stores the index register
  17. * currently being accessed (if owned). The idea here is that it works
  18. * like a normal lock (normally). However, in an NMI, the NMI code will
  19. * first check to see if its CPU owns the lock, meaning that the NMI
  20. * interrupted during the read/write of the device. If it does, it goes ahead
  21. * and performs the access and then restores the index register. If it does
  22. * not, it locks normally.
  23. *
  24. * Note that since we are working with NMIs, we need this lock even in
  25. * a non-SMP machine just to mark that the lock is owned.
  26. *
  27. * This only works with compare-and-swap. There is no other way to
  28. * atomically claim the lock and set the owner.
  29. */
  30. #include <linux/smp.h>
  31. extern volatile unsigned long cmos_lock;
  32. /*
  33. * All of these below must be called with interrupts off, preempt
  34. * disabled, etc.
  35. */
  36. static inline void lock_cmos(unsigned char reg)
  37. {
  38. unsigned long new;
  39. new = ((smp_processor_id()+1) << 8) | reg;
  40. for (;;) {
  41. if (cmos_lock)
  42. continue;
  43. if (__cmpxchg(&cmos_lock, 0, new, sizeof(cmos_lock)) == 0)
  44. return;
  45. }
  46. }
  47. static inline void unlock_cmos(void)
  48. {
  49. cmos_lock = 0;
  50. }
  51. static inline int do_i_have_lock_cmos(void)
  52. {
  53. return (cmos_lock >> 8) == (smp_processor_id()+1);
  54. }
  55. static inline unsigned char current_lock_cmos_reg(void)
  56. {
  57. return cmos_lock & 0xff;
  58. }
  59. #define lock_cmos_prefix(reg) \
  60. do { \
  61. unsigned long cmos_flags; \
  62. local_irq_save(cmos_flags); \
  63. lock_cmos(reg)
  64. #define lock_cmos_suffix(reg) \
  65. unlock_cmos(); \
  66. local_irq_restore(cmos_flags); \
  67. } while (0)
  68. #else
  69. #define lock_cmos_prefix(reg) do {} while (0)
  70. #define lock_cmos_suffix(reg) do {} while (0)
  71. #define lock_cmos(reg)
  72. #define unlock_cmos()
  73. #define do_i_have_lock_cmos() 0
  74. #define current_lock_cmos_reg() 0
  75. #endif
  76. /*
  77. * The yet supported machines all access the RTC index register via
  78. * an ISA port access but the way to access the date register differs ...
  79. */
  80. #define CMOS_READ(addr) rtc_cmos_read(addr)
  81. #define CMOS_WRITE(val, addr) rtc_cmos_write(val, addr)
  82. unsigned char rtc_cmos_read(unsigned char addr);
  83. void rtc_cmos_write(unsigned char val, unsigned char addr);
  84. #define RTC_IRQ 8
  85. #endif /* _ASM_MC146818RTC_H */