cpu.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. /*
  28. * CPU specific code
  29. */
  30. #include <common.h>
  31. #include <command.h>
  32. #include <arm926ejs.h>
  33. #include <asm/system.h>
  34. #ifdef CONFIG_USE_IRQ
  35. DECLARE_GLOBAL_DATA_PTR;
  36. #endif
  37. static void cp_delay (void)
  38. {
  39. volatile int i;
  40. /* copro seems to need some delay between reading and writing */
  41. for (i = 0; i < 100; i++);
  42. }
  43. int cpu_init (void)
  44. {
  45. /*
  46. * setup up stacks if necessary
  47. */
  48. #ifdef CONFIG_USE_IRQ
  49. IRQ_STACK_START = _armboot_start - CONFIG_SYS_MALLOC_LEN - CONFIG_SYS_GBL_DATA_SIZE - 4;
  50. FIQ_STACK_START = IRQ_STACK_START - CONFIG_STACKSIZE_IRQ;
  51. #endif
  52. return 0;
  53. }
  54. int cleanup_before_linux (void)
  55. {
  56. /*
  57. * this function is called just before we call linux
  58. * it prepares the processor for linux
  59. *
  60. * we turn off caches etc ...
  61. */
  62. unsigned long i;
  63. disable_interrupts ();
  64. /* turn off I/D-cache */
  65. asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));
  66. i &= ~(CR_C | CR_I);
  67. asm ("mcr p15, 0, %0, c1, c0, 0": :"r" (i));
  68. /* flush I/D-cache */
  69. i = 0;
  70. asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i));
  71. return (0);
  72. }
  73. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  74. {
  75. disable_interrupts ();
  76. reset_cpu (0);
  77. /*NOTREACHED*/
  78. return (0);
  79. }
  80. /* cache_bit must be either CR_I or CR_C */
  81. static void cache_enable(uint32_t cache_bit)
  82. {
  83. uint32_t reg;
  84. reg = get_cr(); /* get control reg. */
  85. cp_delay();
  86. set_cr(reg | cache_bit);
  87. }
  88. /* cache_bit must be either CR_I or CR_C */
  89. static void cache_disable(uint32_t cache_bit)
  90. {
  91. uint32_t reg;
  92. reg = get_cr();
  93. cp_delay();
  94. set_cr(reg & ~cache_bit);
  95. }
  96. void icache_enable(void)
  97. {
  98. cache_enable(CR_I);
  99. }
  100. void icache_disable(void)
  101. {
  102. cache_disable(CR_I);
  103. }
  104. int icache_status(void)
  105. {
  106. return (get_cr() & CR_I) != 0;
  107. }
  108. void dcache_enable(void)
  109. {
  110. cache_enable(CR_C);
  111. }
  112. void dcache_disable(void)
  113. {
  114. cache_disable(CR_C);
  115. }
  116. int dcache_status(void)
  117. {
  118. return (get_cr() & CR_C) != 0;
  119. }