ramtest.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2014 Google, Inc
  3. *
  4. * From Coreboot src/lib/ramtest.c
  5. *
  6. * SPDX-License-Identifier: GPL-2.0
  7. */
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <asm/post.h>
  11. static void write_phys(unsigned long addr, u32 value)
  12. {
  13. #if CONFIG_SSE2
  14. asm volatile(
  15. "movnti %1, (%0)"
  16. : /* outputs */
  17. : "r" (addr), "r" (value) /* inputs */
  18. : /* clobbers */
  19. );
  20. #else
  21. writel(value, addr);
  22. #endif
  23. }
  24. static u32 read_phys(unsigned long addr)
  25. {
  26. return readl(addr);
  27. }
  28. static void phys_memory_barrier(void)
  29. {
  30. #if CONFIG_SSE2
  31. /* Needed for movnti */
  32. asm volatile(
  33. "sfence"
  34. :
  35. :
  36. : "memory"
  37. );
  38. #else
  39. asm volatile(""
  40. :
  41. :
  42. : "memory");
  43. #endif
  44. }
  45. void quick_ram_check(void)
  46. {
  47. int fail = 0;
  48. u32 backup;
  49. backup = read_phys(CONFIG_RAMBASE);
  50. write_phys(CONFIG_RAMBASE, 0x55555555);
  51. phys_memory_barrier();
  52. if (read_phys(CONFIG_RAMBASE) != 0x55555555)
  53. fail = 1;
  54. write_phys(CONFIG_RAMBASE, 0xaaaaaaaa);
  55. phys_memory_barrier();
  56. if (read_phys(CONFIG_RAMBASE) != 0xaaaaaaaa)
  57. fail = 1;
  58. write_phys(CONFIG_RAMBASE, 0x00000000);
  59. phys_memory_barrier();
  60. if (read_phys(CONFIG_RAMBASE) != 0x00000000)
  61. fail = 1;
  62. write_phys(CONFIG_RAMBASE, 0xffffffff);
  63. phys_memory_barrier();
  64. if (read_phys(CONFIG_RAMBASE) != 0xffffffff)
  65. fail = 1;
  66. write_phys(CONFIG_RAMBASE, backup);
  67. if (fail) {
  68. post_code(POST_RAM_FAILURE);
  69. panic("RAM INIT FAILURE!\n");
  70. }
  71. phys_memory_barrier();
  72. }