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