ramtest.c 1.4 KB

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