summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-ast2500/recipes-bsp/u-boot/files/0051-Add-Aspeed-DRAM-stress-test-command.patch
blob: 377be5e538a64982ae034bdc4e2c155016f65f23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
From 6ccd771297fdfc4dbb0571001e787a72f9348df9 Mon Sep 17 00:00:00 2001
From: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
Date: Wed, 16 Sep 2020 15:14:26 -0700
Subject: [PATCH] Add Aspeed DRAM stress test command

This commit adds DRAM stress test command. Also, it enables
SoC UART debug feature.

Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
---
 board/aspeed/ast-g5/ast-g5-intel.c |   8 ++
 cmd/Kconfig                        |   4 +
 cmd/Makefile                       |   2 +
 cmd/dramtest.c                     | 219 +++++++++++++++++++++++++++++
 4 files changed, 233 insertions(+)
 create mode 100644 cmd/dramtest.c

diff --git a/board/aspeed/ast-g5/ast-g5-intel.c b/board/aspeed/ast-g5/ast-g5-intel.c
index c46bd70b71b2..91dae91d02e4 100644
--- a/board/aspeed/ast-g5/ast-g5-intel.c
+++ b/board/aspeed/ast-g5/ast-g5-intel.c
@@ -140,6 +140,8 @@ static const GPIOValue gpio_table[] = {

 #define COOPER_CITY_BOARD_ID 40
 
+#define USE_SOC_UART_DEBUG
+
 static int get_boot_failures(void)
 {
        return getenv_ulong("bootfailures", 10, 0);
@@ -660,9 +662,15 @@ extern void espi_init(void);
 extern void kcs_init(void);
 void ast_g5_intel(void)
 {
+#ifdef USE_SOC_UART_DEBUG
+	/* Enable uart port debug function */
+	ast_scu_write(ast_scu_read(AST_SCU_MISC1_CTRL) &
+		      ~SCU_MISC_UART_DEBUG_DIS, AST_SCU_MISC1_CTRL);
+#else
 	/* Disable uart port debug function */
 	ast_scu_write(ast_scu_read(AST_SCU_MISC1_CTRL) |
 		      SCU_MISC_UART_DEBUG_DIS, AST_SCU_MISC1_CTRL);
+#endif
 
 	uart_init();
 	mailbox_init();
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 33be2407d2ba..e7c7c4b67cef 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -605,6 +605,10 @@ config CMD_QFW
 	  This provides access to the QEMU firmware interface.  The main
 	  feature is to allow easy loading of files passed to qemu-system
 	  via -kernel / -initrd
+
+config CMD_DRAMTEST
+        bool "ASPEED DRAM controller stress test"
+        default y
 endmenu
 
 config CMD_BOOTSTAGE
diff --git a/cmd/Makefile b/cmd/Makefile
index c8ac0af55c05..eda5f91338ce 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -152,6 +152,8 @@ obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-$(CONFIG_CMD_GPT) += gpt.o
 obj-$(CONFIG_CMD_ETHSW) += ethsw.o
 
+obj-$(CONFIG_CMD_DRAMTEST) += dramtest.o
+
 # Power
 obj-$(CONFIG_CMD_PMIC) += pmic.o
 obj-$(CONFIG_CMD_REGULATOR) += regulator.o
diff --git a/cmd/dramtest.c b/cmd/dramtest.c
new file mode 100644
index 000000000000..cb2f0ea5ac35
--- /dev/null
+++ b/cmd/dramtest.c
@@ -0,0 +1,219 @@
+/*
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <common.h>
+#include <console.h>
+#include <bootretry.h>
+#include <cli.h>
+#include <command.h>
+#include <console.h>
+
+#include <inttypes.h>
+#include <mapmem.h>
+#include <asm/io.h>
+#include <linux/compiler.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define DRAM_BASE	0x80000000
+#define TIMEOUT_DRAM	5000000
+
+#ifdef CONFIG_ASPEED_AST2600
+#define BLK_SIZE_MB				64
+#define N_BLK					32
+#define MCR74_BLK_OFFSET		26
+#define MCR74_LEN_OFFSET		4
+#define MCR74_BLK_LEN_MASK		GENMASK(30, 4)
+#else
+#define BLK_SIZE_MB				16
+#define N_BLK					64
+#define MCR74_BLK_OFFSET		24
+#define MCR74_LEN_OFFSET		4
+#define MCR74_BLK_LEN_MASK		GENMASK(29, 4)
+#endif
+#define BLK_SIZE				(BLK_SIZE_MB * 1024 * 1024)
+#define N_16B_IN_BLK			(BLK_SIZE / 16)
+
+/* ------------------------------------------------------------------------- */
+int MMCTestBurst(unsigned int datagen)
+{
+	unsigned int data;
+	unsigned int timeout = 0;
+
+	writel(0x00000000, 0x1E6E0070);
+	writel((0x000000C1 | (datagen << 3)), 0x1E6E0070);
+
+	do {
+		data = readl(0x1E6E0070) & 0x3000;
+
+		if( data & 0x2000 )
+			return(0);
+
+		if( ++timeout > TIMEOUT_DRAM ) {
+			printf("Timeout!!\n");
+			writel(0x00000000, 0x1E6E0070);
+			return(0);
+		}
+	} while (!data);
+
+	writel(0x00000000, 0x1E6E0070);
+
+	return(1);
+}
+
+/* ------------------------------------------------------------------------- */
+int MMCTestSingle(unsigned int datagen)
+{
+	unsigned int data;
+	unsigned int timeout = 0;
+
+	writel(0x00000000, 0x1E6E0070);
+	writel((0x00000085 | (datagen << 3)), 0x1E6E0070);
+
+	do {
+		data = readl(0x1E6E0070) & 0x3000;
+
+		if( data & 0x2000 )
+			return(0);
+
+		if( ++timeout > TIMEOUT_DRAM ){
+			printf("Timeout!!\n");
+			writel(0x00000000, 0x1E6E0070);
+
+			return(0);
+		}
+	} while ( !data );
+
+	writel(0x00000000, 0x1E6E0070);
+
+	return(1);
+}
+
+/* ------------------------------------------------------------------------- */
+int MMCTest(void)
+{
+	unsigned int pattern;
+
+	pattern = rand();
+	writel(pattern, 0x1E6E007C);
+	printf("Pattern = %08X : ",pattern);
+
+	if(!MMCTestBurst(0))    return(0);
+	if(!MMCTestBurst(1))    return(0);
+	if(!MMCTestBurst(2))    return(0);
+	if(!MMCTestBurst(3))    return(0);
+	if(!MMCTestBurst(4))    return(0);
+	if(!MMCTestBurst(5))    return(0);
+	if(!MMCTestBurst(6))    return(0);
+	if(!MMCTestBurst(7))    return(0);
+	if(!MMCTestSingle(0))   return(0);
+	if(!MMCTestSingle(1))   return(0);
+	if(!MMCTestSingle(2))   return(0);
+	if(!MMCTestSingle(3))   return(0);
+	if(!MMCTestSingle(4))   return(0);
+	if(!MMCTestSingle(5))   return(0);
+	if(!MMCTestSingle(6))   return(0);
+	if(!MMCTestSingle(7))   return(0);
+
+	return(1);
+}
+
+/* ------------------------------------------------------------------------- */
+static void print_usage(void)
+{
+	printf("\nASPEED DRAM BIST\n\n");
+	printf("Usage: dramtest <count> <block> <length>\n\n");
+	printf("count:  how many iterations to run (mandatory, in decimal)\n");
+	printf("        0: infinite loop.\n");
+	printf("block:  index of the address block to test "
+			"(optional, in decimal, default: 0)\n");
+	printf("        0: [%08x, %08x)\n", DRAM_BASE + BLK_SIZE * 0, DRAM_BASE + BLK_SIZE * 1);
+	printf("        1: [%08x, %08x)\n", DRAM_BASE + BLK_SIZE * 1, DRAM_BASE + BLK_SIZE * 2);
+	printf("        2: [%08x, %08x)\n", DRAM_BASE + BLK_SIZE * 2, DRAM_BASE + BLK_SIZE * 3);
+	printf("        n: [80000000 + n*%dMB, 80000000 + (n+1)*%dMB)\n", BLK_SIZE_MB, BLK_SIZE_MB);
+	printf("           where n = [0, %d]\n", N_BLK - 1);
+	printf("length: size to test (optional, in hex, default: 0x10000)\n");
+	printf("        0x0: test the whole memory block %dMB\n", BLK_SIZE_MB);
+	printf("        0x1: test the first 16 Bytes of the memory block\n");
+	printf("        0x2: test the first 2*16 Bytes of the memory block\n");
+	printf("        n  : test the first n*16 Bytes of the memory block\n");
+	printf("             where n = [0x00000001, 0x%08x]\n", N_16B_IN_BLK - 1);
+	printf("\n\n");
+}
+
+static int
+do_ast_dramtest(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+	u32 PassCnt = 0;
+	unsigned long Testcounter = 0;
+	unsigned long block = 0;
+	unsigned long length = 0x10000;
+	int ret;
+
+	if (argc < 2) {
+		ret = 0;
+		goto cmd_err;
+	}
+
+	ret = CMD_RET_USAGE;
+	switch (argc) {
+	case 4:
+		if (strict_strtoul(argv[3], 16, &length) < 0 ||
+		    length > N_16B_IN_BLK - 1)
+			goto cmd_err;
+		if (length == 0)
+		    length = N_16B_IN_BLK - 1;
+		/* fall through */
+	case 3:
+		if (strict_strtoul(argv[2], 10, &block) < 0 ||
+		    block > N_BLK - 1)
+			goto cmd_err;
+		/* fall through */
+	case 2:
+		if (strict_strtoul(argv[1], 10, &Testcounter) < 0)
+			goto cmd_err;
+		break;
+	default:
+		goto cmd_err;
+	}
+
+	printf("Test range: 0x%08lx - 0x%08lx\n", DRAM_BASE + (block << MCR74_BLK_OFFSET),
+	       DRAM_BASE + (block << MCR74_BLK_OFFSET) + (length << 4) + 15);
+
+	ret = 1;
+	writel(0xFC600309, 0x1E6E0000);
+	while ((Testcounter > PassCnt) || (Testcounter == 0)) {
+		clrsetbits_le32(0x1E6E0074, MCR74_BLK_LEN_MASK,
+				(block << MCR74_BLK_OFFSET) | (length << MCR74_LEN_OFFSET));
+
+		if (!MMCTest()) {
+			printf("FAIL %d/%ld (fail DQ 0x%08x)\n", PassCnt,
+			       Testcounter, readl(0x1E6E0078));
+			ret = 0;
+			break;
+		} else {
+			PassCnt++;
+			printf("Pass %d/%ld\n", PassCnt, Testcounter);
+		}
+	}
+
+	return (ret);
+
+cmd_err:
+	print_usage();
+	return (ret);
+}
+
+U_BOOT_CMD(
+	dramtest,   5, 0,  do_ast_dramtest,
+	"ASPEED DRAM BIST",
+	""
+);
-- 
2.17.1