cpu.c 6.4 KB

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