PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/hw/xfree86/os-support/misc/SlowBcopy.c

#
C | 117 lines | 84 code | 20 blank | 13 comment | 7 complexity | 579abf3fa5532a5d25fc65bf19dc034f MD5 | raw file
Possible License(s): MIT
  1. /*******************************************************************************
  2. for Alpha Linux
  3. *******************************************************************************/
  4. /*
  5. * Create a dependency that should be immune from the effect of register
  6. * renaming as is commonly seen in superscalar processors. This should
  7. * insert a minimum of 100-ns delays between reads/writes at clock rates
  8. * up to 100 MHz---GGL
  9. *
  10. * Slowbcopy(char *src, char *dst, int count)
  11. *
  12. */
  13. #ifdef HAVE_XORG_CONFIG_H
  14. #include <xorg-config.h>
  15. #endif
  16. #include <X11/X.h>
  17. #include "xf86.h"
  18. #include "xf86Priv.h"
  19. #include "xf86_OSlib.h"
  20. #include "compiler.h"
  21. static int really_slow_bcopy;
  22. void
  23. xf86SetReallySlowBcopy(void)
  24. {
  25. really_slow_bcopy = 1;
  26. }
  27. #if defined(__i386__) || defined(__amd64__)
  28. static void xf86_really_slow_bcopy(unsigned char *src, unsigned char *dst, int len)
  29. {
  30. while(len--)
  31. {
  32. *dst++ = *src++;
  33. outb(0x80, 0x00);
  34. }
  35. }
  36. #endif
  37. /* The outb() isn't needed on my machine, but who knows ... -- ost */
  38. void
  39. xf86SlowBcopy(unsigned char *src, unsigned char *dst, int len)
  40. {
  41. #if defined(__i386__) || defined(__amd64__)
  42. if (really_slow_bcopy) {
  43. xf86_really_slow_bcopy(src, dst, len);
  44. return;
  45. }
  46. #endif
  47. while(len--)
  48. *dst++ = *src++;
  49. }
  50. #ifdef __alpha__
  51. #ifdef linux
  52. unsigned long _bus_base(void);
  53. #define useSparse() (!_bus_base())
  54. #define SPARSE (7)
  55. #else
  56. #define useSparse() 0
  57. #define SPARSE 0
  58. #endif
  59. void
  60. xf86SlowBCopyFromBus(unsigned char *src, unsigned char *dst, int count)
  61. {
  62. if (useSparse())
  63. {
  64. unsigned long addr;
  65. long result;
  66. addr = (unsigned long) src;
  67. while (count) {
  68. result = *(volatile int *) addr;
  69. result >>= ((addr>>SPARSE) & 3) * 8;
  70. *dst++ = (unsigned char) (0xffUL & result);
  71. addr += 1<<SPARSE;
  72. count--;
  73. outb(0x80, 0x00);
  74. }
  75. }
  76. else
  77. xf86SlowBcopy(src, dst, count);
  78. }
  79. void
  80. xf86SlowBCopyToBus(unsigned char *src, unsigned char *dst, int count)
  81. {
  82. if (useSparse())
  83. {
  84. unsigned long addr;
  85. addr = (unsigned long) dst;
  86. while (count) {
  87. *(volatile unsigned int *) addr = (unsigned short)(*src) * 0x01010101;
  88. src++;
  89. addr += 1<<SPARSE;
  90. count--;
  91. outb(0x80, 0x00);
  92. }
  93. }
  94. else
  95. xf86SlowBcopy(src, dst, count);
  96. }
  97. #endif