cpu.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * (C) Copyright 2000 - 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <config.h>
  24. #include <mpc824x.h>
  25. #include <common.h>
  26. #include <command.h>
  27. int checkcpu (void)
  28. {
  29. DECLARE_GLOBAL_DATA_PTR;
  30. unsigned int pvr = get_pvr ();
  31. unsigned int version = pvr >> 16;
  32. unsigned char revision;
  33. ulong clock = gd->cpu_clk;
  34. char buf[32];
  35. puts ("CPU: ");
  36. switch (version) {
  37. case CPU_TYPE_8240:
  38. puts ("MPC8240");
  39. break;
  40. case CPU_TYPE_8245:
  41. puts ("MPC8245");
  42. break;
  43. default:
  44. return -1; /*not valid for this source */
  45. }
  46. CONFIG_READ_BYTE (REVID, revision);
  47. if (revision) {
  48. printf (" Revision %d.%d",
  49. (revision & 0xf0) >> 4,
  50. (revision & 0x0f));
  51. } else {
  52. return -1; /* no valid CPU revision info */
  53. }
  54. printf (" at %s MHz:", strmhz (buf, clock));
  55. printf (" %u kB I-Cache", checkicache () >> 10);
  56. printf (" %u kB D-Cache", checkdcache () >> 10);
  57. puts ("\n");
  58. return 0;
  59. }
  60. /* ------------------------------------------------------------------------- */
  61. /* L1 i-cache */
  62. int checkicache (void)
  63. {
  64. /*TODO*/
  65. return 128 * 4 * 32;
  66. };
  67. /* ------------------------------------------------------------------------- */
  68. /* L1 d-cache */
  69. int checkdcache (void)
  70. {
  71. /*TODO*/
  72. return 128 * 4 * 32;
  73. };
  74. /*------------------------------------------------------------------- */
  75. int do_reset (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc,
  76. char *argv[])
  77. {
  78. ulong msr, addr;
  79. /* Interrupts and MMU off */
  80. __asm__ ("mtspr 81, 0");
  81. /* Interrupts and MMU off */
  82. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  83. msr &= ~0x1030;
  84. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  85. /*
  86. * Trying to execute the next instruction at a non-existing address
  87. * should cause a machine check, resulting in reset
  88. */
  89. #ifdef CFG_RESET_ADDRESS
  90. addr = CFG_RESET_ADDRESS;
  91. #else
  92. /*
  93. * note: when CFG_MONITOR_BASE points to a RAM address,
  94. * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
  95. * address. Better pick an address known to be invalid on
  96. * your system and assign it to CFG_RESET_ADDRESS.
  97. * "(ulong)-1" used to be a good choice for many systems...
  98. */
  99. addr = CFG_MONITOR_BASE - sizeof (ulong);
  100. #endif
  101. ((void (*)(void)) addr) ();
  102. return 1;
  103. }
  104. /* ------------------------------------------------------------------------- */
  105. /*
  106. * Get timebase clock frequency (like cpu_clk in Hz)
  107. * This is the sys_logic_clk (memory bus) divided by 4
  108. */
  109. unsigned long get_tbclk (void)
  110. {
  111. return ((get_bus_freq (0) + 2L) / 4L);
  112. }
  113. /* ------------------------------------------------------------------------- */
  114. /*
  115. * The MPC824x has an integrated PCI controller known as the MPC107.
  116. * The following are MPC107 Bridge Controller and PCI Support functions
  117. *
  118. */
  119. /*
  120. * This procedure reads a 32-bit address MPC107 register, and returns
  121. * a 32 bit value. It swaps the address to little endian before
  122. * writing it to config address, and swaps the value to big endian
  123. * before returning to the caller.
  124. */
  125. unsigned int mpc824x_mpc107_getreg (unsigned int regNum)
  126. {
  127. unsigned int temp;
  128. /* swap the addr. to little endian */
  129. *(volatile unsigned int *) CHRP_REG_ADDR = PCISWAP (regNum);
  130. temp = *(volatile unsigned int *) CHRP_REG_DATA;
  131. return PCISWAP (temp); /* swap the data upon return */
  132. }
  133. /*
  134. * This procedure writes a 32-bit address MPC107 register. It swaps
  135. * the address to little endian before writing it to config address.
  136. */
  137. void mpc824x_mpc107_setreg (unsigned int regNum, unsigned int regVal)
  138. {
  139. /* swap the addr. to little endian */
  140. *(volatile unsigned int *) CHRP_REG_ADDR = PCISWAP (regNum);
  141. *(volatile unsigned int *) CHRP_REG_DATA = PCISWAP (regVal);
  142. return;
  143. }
  144. /*
  145. * Write a byte (8 bits) to a memory location.
  146. */
  147. void mpc824x_mpc107_write8 (unsigned int addr, unsigned char data)
  148. {
  149. *(unsigned char *) addr = data;
  150. __asm__ ("sync");
  151. }
  152. /*
  153. * Write a word (16 bits) to a memory location after the value
  154. * has been byte swapped (big to little endian or vice versa)
  155. */
  156. void mpc824x_mpc107_write16 (unsigned int address, unsigned short data)
  157. {
  158. *(volatile unsigned short *) address = BYTE_SWAP_16_BIT (data);
  159. __asm__ ("sync");
  160. }
  161. /*
  162. * Write a long word (32 bits) to a memory location after the value
  163. * has been byte swapped (big to little endian or vice versa)
  164. */
  165. void mpc824x_mpc107_write32 (unsigned int address, unsigned int data)
  166. {
  167. *(volatile unsigned int *) address = LONGSWAP (data);
  168. __asm__ ("sync");
  169. }
  170. /*
  171. * Read a byte (8 bits) from a memory location.
  172. */
  173. unsigned char mpc824x_mpc107_read8 (unsigned int addr)
  174. {
  175. return *(volatile unsigned char *) addr;
  176. }
  177. /*
  178. * Read a word (16 bits) from a memory location, and byte swap the
  179. * value before returning to the caller.
  180. */
  181. unsigned short mpc824x_mpc107_read16 (unsigned int address)
  182. {
  183. unsigned short retVal;
  184. retVal = BYTE_SWAP_16_BIT (*(unsigned short *) address);
  185. return retVal;
  186. }
  187. /*
  188. * Read a long word (32 bits) from a memory location, and byte
  189. * swap the value before returning to the caller.
  190. */
  191. unsigned int mpc824x_mpc107_read32 (unsigned int address)
  192. {
  193. unsigned int retVal;
  194. retVal = LONGSWAP (*(unsigned int *) address);
  195. return (retVal);
  196. }
  197. /*
  198. * Read a register in the Embedded Utilities Memory Block address
  199. * space.
  200. * Input: regNum - register number + utility base address. Example,
  201. * the base address of EPIC is 0x40000, the register number
  202. * being passed is 0x40000+the address of the target register.
  203. * (See epic.h for register addresses).
  204. * Output: The 32 bit little endian value of the register.
  205. */
  206. unsigned int mpc824x_eummbar_read (unsigned int regNum)
  207. {
  208. unsigned int temp;
  209. temp = *(volatile unsigned int *) (EUMBBAR_VAL + regNum);
  210. temp = PCISWAP (temp);
  211. return temp;
  212. }
  213. /*
  214. * Write a value to a register in the Embedded Utilities Memory
  215. * Block address space.
  216. * Input: regNum - register number + utility base address. Example,
  217. * the base address of EPIC is 0x40000, the register
  218. * number is 0x40000+the address of the target register.
  219. * (See epic.h for register addresses).
  220. * regVal - value to be written to the register.
  221. */
  222. void mpc824x_eummbar_write (unsigned int regNum, unsigned int regVal)
  223. {
  224. *(volatile unsigned int *) (EUMBBAR_VAL + regNum) = PCISWAP (regVal);
  225. return;
  226. }
  227. /* ------------------------------------------------------------------------- */