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 <macro@mips.com>
  9. */
  10. #include <linux/init.h>
  11. #include <asm/addrspace.h>
  12. #include <asm/bug.h>
  13. #include <asm/cacheflush.h>
  14. #ifndef CKSEG2
  15. #define CKSEG2 CKSSEG
  16. #endif
  17. #ifndef TO_PHYS_MASK
  18. #define TO_PHYS_MASK -1
  19. #endif
  20. /*
  21. * FUNC is executed in one of the uncached segments, depending on its
  22. * original address as follows:
  23. *
  24. * 1. If the original address is in CKSEG0 or CKSEG1, then the uncached
  25. * segment used is CKSEG1.
  26. * 2. If the original address is in XKPHYS, then the uncached segment
  27. * used is XKPHYS(2).
  28. * 3. Otherwise it's a bug.
  29. *
  30. * The same remapping is done with the stack pointer. Stack handling
  31. * works because we don't handle stack arguments or more complex return
  32. * values, so we can avoid sharing the same stack area between a cached
  33. * and the uncached mode.
  34. */
  35. unsigned long __cpuinit run_uncached(void *func)
  36. {
  37. register long sp __asm__("$sp");
  38. register long ret __asm__("$2");
  39. long lfunc = (long)func, ufunc;
  40. long usp;
  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. }