cpu.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. DECLARE_GLOBAL_DATA_PTR;
  28. int checkcpu (void)
  29. {
  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, int flag, int argc, char *argv[])
  76. {
  77. ulong msr, addr;
  78. /* Interrupts and MMU off */
  79. __asm__ ("mtspr 81, 0");
  80. /* Interrupts and MMU off */
  81. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  82. msr &= ~0x1030;
  83. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  84. /*
  85. * Trying to execute the next instruction at a non-existing address
  86. * should cause a machine check, resulting in reset
  87. */
  88. #ifdef CONFIG_SYS_RESET_ADDRESS
  89. addr = CONFIG_SYS_RESET_ADDRESS;
  90. #else
  91. /*
  92. * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address,
  93. * CONFIG_SYS_MONITOR_BASE - sizeof (ulong) is usually a valid
  94. * address. Better pick an address known to be invalid on
  95. * your system and assign it to CONFIG_SYS_RESET_ADDRESS.
  96. * "(ulong)-1" used to be a good choice for many systems...
  97. */
  98. addr = CONFIG_SYS_MONITOR_BASE - sizeof (ulong);
  99. #endif
  100. ((void (*)(void)) addr) ();
  101. return 1;
  102. }
  103. /* ------------------------------------------------------------------------- */
  104. /*
  105. * Get timebase clock frequency (like cpu_clk in Hz)
  106. * This is the sys_logic_clk (memory bus) divided by 4
  107. */
  108. unsigned long get_tbclk (void)
  109. {
  110. return ((get_bus_freq (0) + 2L) / 4L);
  111. }
  112. /* ------------------------------------------------------------------------- */
  113. /*
  114. * The MPC824x has an integrated PCI controller known as the MPC107.
  115. * The following are MPC107 Bridge Controller and PCI Support functions
  116. *
  117. */
  118. /*
  119. * This procedure reads a 32-bit address MPC107 register, and returns
  120. * a 32 bit value. It swaps the address to little endian before
  121. * writing it to config address, and swaps the value to big endian
  122. * before returning to the caller.
  123. */
  124. unsigned int mpc824x_mpc107_getreg (unsigned int regNum)
  125. {
  126. unsigned int temp;
  127. /* swap the addr. to little endian */
  128. *(volatile unsigned int *) CHRP_REG_ADDR = PCISWAP (regNum);
  129. temp = *(volatile unsigned int *) CHRP_REG_DATA;
  130. return PCISWAP (temp); /* swap the data upon return */
  131. }
  132. /*
  133. * This procedure writes a 32-bit address MPC107 register. It swaps
  134. * the address to little endian before writing it to config address.
  135. */
  136. void mpc824x_mpc107_setreg (unsigned int regNum, unsigned int regVal)
  137. {
  138. /* swap the addr. to little endian */
  139. *(volatile unsigned int *) CHRP_REG_ADDR = PCISWAP (regNum);
  140. *(volatile unsigned int *) CHRP_REG_DATA = PCISWAP (regVal);
  141. return;
  142. }
  143. /*
  144. * Write a byte (8 bits) to a memory location.
  145. */
  146. void mpc824x_mpc107_write8 (unsigned int addr, unsigned char data)
  147. {
  148. *(unsigned char *) addr = data;
  149. __asm__ ("sync");
  150. }
  151. /*
  152. * Write a word (16 bits) to a memory location after the value
  153. * has been byte swapped (big to little endian or vice versa)
  154. */
  155. void mpc824x_mpc107_write16 (unsigned int address, unsigned short data)
  156. {
  157. *(volatile unsigned short *) address = BYTE_SWAP_16_BIT (data);
  158. __asm__ ("sync");
  159. }
  160. /*
  161. * Write a long word (32 bits) to a memory location after the value
  162. * has been byte swapped (big to little endian or vice versa)
  163. */
  164. void mpc824x_mpc107_write32 (unsigned int address, unsigned int data)
  165. {
  166. *(volatile unsigned int *) address = LONGSWAP (data);
  167. __asm__ ("sync");
  168. }
  169. /*
  170. * Read a byte (8 bits) from a memory location.
  171. */
  172. unsigned char mpc824x_mpc107_read8 (unsigned int addr)
  173. {
  174. return *(volatile unsigned char *) addr;
  175. }
  176. /*
  177. * Read a word (16 bits) from a memory location, and byte swap the
  178. * value before returning to the caller.
  179. */
  180. unsigned short mpc824x_mpc107_read16 (unsigned int address)
  181. {
  182. unsigned short retVal;
  183. retVal = BYTE_SWAP_16_BIT (*(unsigned short *) address);
  184. return retVal;
  185. }
  186. /*
  187. * Read a long word (32 bits) from a memory location, and byte
  188. * swap the value before returning to the caller.
  189. */
  190. unsigned int mpc824x_mpc107_read32 (unsigned int address)
  191. {
  192. unsigned int retVal;
  193. retVal = LONGSWAP (*(unsigned int *) address);
  194. return (retVal);
  195. }
  196. /*
  197. * Read a register in the Embedded Utilities Memory Block address
  198. * space.
  199. * Input: regNum - register number + utility base address. Example,
  200. * the base address of EPIC is 0x40000, the register number
  201. * being passed is 0x40000+the address of the target register.
  202. * (See epic.h for register addresses).
  203. * Output: The 32 bit little endian value of the register.
  204. */
  205. unsigned int mpc824x_eummbar_read (unsigned int regNum)
  206. {
  207. unsigned int temp;
  208. temp = *(volatile unsigned int *) (EUMBBAR_VAL + regNum);
  209. temp = PCISWAP (temp);
  210. return temp;
  211. }
  212. /*
  213. * Write a value to a register in the Embedded Utilities Memory
  214. * Block address space.
  215. * Input: regNum - register number + utility base address. Example,
  216. * the base address of EPIC is 0x40000, the register
  217. * number is 0x40000+the address of the target register.
  218. * (See epic.h for register addresses).
  219. * regVal - value to be written to the register.
  220. */
  221. void mpc824x_eummbar_write (unsigned int regNum, unsigned int regVal)
  222. {
  223. *(volatile unsigned int *) (EUMBBAR_VAL + regNum) = PCISWAP (regVal);
  224. return;
  225. }
  226. /* ------------------------------------------------------------------------- */