uncached.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2005 Thiemo Seufer
  7. * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
  8. * Author: Maciej W. Rozycki <[email protected]>
  9. */
  10. #include <asm/addrspace.h>
  11. #include <asm/bug.h>
  12. #include <asm/cacheflush.h>
  13. #ifndef CKSEG2
  14. #define CKSEG2 CKSSEG
  15. #endif
  16. #ifndef TO_PHYS_MASK
  17. #define TO_PHYS_MASK -1
  18. #endif
  19. /*
  20. * FUNC is executed in one of the uncached segments, depending on its
  21. * original address as follows:
  22. *
  23. * 1. If the original address is in CKSEG0 or CKSEG1, then the uncached
  24. * segment used is CKSEG1.
  25. * 2. If the original address is in XKPHYS, then the uncached segment
  26. * used is XKPHYS(2).
  27. * 3. Otherwise it's a bug.
  28. *
  29. * The same remapping is done with the stack pointer. Stack handling
  30. * works because we don't handle stack arguments or more complex return
  31. * values, so we can avoid sharing the same stack area between a cached
  32. * and the uncached mode.
  33. */
  34. unsigned long run_uncached(void *func)
  35. {
  36. register long ret __asm__("$2");
  37. long lfunc = (long)func, ufunc;
  38. long usp;
  39. long sp;
  40. __asm__("move %0, $sp" : "=r" (sp));
  41. if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
  42. usp = CKSEG1ADDR(sp);
  43. #ifdef CONFIG_64BIT
  44. else if ((long long)sp >= (long long)PHYS_TO_XKPHYS(0, 0) &&
  45. (long long)sp < (long long)PHYS_TO_XKPHYS(8, 0))
  46. usp = PHYS_TO_XKPHYS(K_CALG_UNCACHED,
  47. XKPHYS_TO_PHYS((long long)sp));
  48. #endif
  49. else {
  50. BUG();
  51. usp = sp;
  52. }
  53. if (lfunc >= (long)CKSEG0 && lfunc < (long)CKSEG2)
  54. ufunc = CKSEG1ADDR(lfunc);
  55. #ifdef CONFIG_64BIT
  56. else if ((long long)lfunc >= (long long)PHYS_TO_XKPHYS(0, 0) &&
  57. (long long)lfunc < (long long)PHYS_TO_XKPHYS(8, 0))
  58. ufunc = PHYS_TO_XKPHYS(K_CALG_UNCACHED,
  59. XKPHYS_TO_PHYS((long long)lfunc));
  60. #endif
  61. else {
  62. BUG();
  63. ufunc = lfunc;
  64. }
  65. __asm__ __volatile__ (
  66. " move $16, $sp\n"
  67. " move $sp, %1\n"
  68. " jalr %2\n"
  69. " move $sp, $16"
  70. : "=r" (ret)
  71. : "r" (usp), "r" (ufunc)
  72. : "$16", "$31");
  73. return ret;
  74. }