cpu.c 6.4 KB

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