util.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copied from <file:arch/powerpc/kernel/misc_32.S>
  3. *
  4. * This file contains miscellaneous low-level functions.
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
  8. * and Paul Mackerras.
  9. *
  10. * kexec bits:
  11. * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
  12. * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. *
  19. */
  20. #include "ppc_asm.h"
  21. #define SPRN_PVR 0x11F /* Processor Version Register */
  22. .text
  23. /* udelay (on non-601 processors) needs to know the period of the
  24. * timebase in nanoseconds. This used to be hardcoded to be 60ns
  25. * (period of 66MHz/4). Now a variable is used that is initialized to
  26. * 60 for backward compatibility, but it can be overridden as necessary
  27. * with code something like this:
  28. * extern unsigned long timebase_period_ns;
  29. * timebase_period_ns = 1000000000 / bd->bi_tbfreq;
  30. */
  31. .data
  32. .globl timebase_period_ns
  33. timebase_period_ns:
  34. .long 60
  35. .text
  36. /*
  37. * Delay for a number of microseconds
  38. */
  39. .globl udelay
  40. udelay:
  41. mfspr r4,SPRN_PVR
  42. srwi r4,r4,16
  43. cmpwi 0,r4,1 /* 601 ? */
  44. bne .Ludelay_not_601
  45. 00: li r0,86 /* Instructions / microsecond? */
  46. mtctr r0
  47. 10: addi r0,r0,0 /* NOP */
  48. bdnz 10b
  49. subic. r3,r3,1
  50. bne 00b
  51. blr
  52. .Ludelay_not_601:
  53. mulli r4,r3,1000 /* nanoseconds */
  54. /* Change r4 to be the number of ticks using:
  55. * (nanoseconds + (timebase_period_ns - 1 )) / timebase_period_ns
  56. * timebase_period_ns defaults to 60 (16.6MHz) */
  57. mflr r5
  58. bl 0f
  59. 0: mflr r6
  60. mtlr r5
  61. lis r5,0b@ha
  62. addi r5,r5,0b@l
  63. subf r5,r5,r6 /* In case we're relocated */
  64. addis r5,r5,timebase_period_ns@ha
  65. lwz r5,timebase_period_ns@l(r5)
  66. add r4,r4,r5
  67. addi r4,r4,-1
  68. divw r4,r4,r5 /* BUS ticks */
  69. #ifdef CONFIG_8xx
  70. 1: mftbu r5
  71. mftb r6
  72. mftbu r7
  73. #else
  74. 1: mfspr r5, SPRN_TBRU
  75. mfspr r6, SPRN_TBRL
  76. mfspr r7, SPRN_TBRU
  77. #endif
  78. cmpw 0,r5,r7
  79. bne 1b /* Get [synced] base time */
  80. addc r9,r6,r4 /* Compute end time */
  81. addze r8,r5
  82. #ifdef CONFIG_8xx
  83. 2: mftbu r5
  84. #else
  85. 2: mfspr r5, SPRN_TBRU
  86. #endif
  87. cmpw 0,r5,r8
  88. blt 2b
  89. bgt 3f
  90. #ifdef CONFIG_8xx
  91. mftb r6
  92. #else
  93. mfspr r6, SPRN_TBRL
  94. #endif
  95. cmpw 0,r6,r9
  96. blt 2b
  97. 3: blr