1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
12 #include <linux/log2.h>
13 #include "stm32mp1_tests.h"
15 #define ADDR_INVALID 0xFFFFFFFF
17 DECLARE_GLOBAL_DATA_PTR;
19 static int get_bufsize(char *string, int argc, char *argv[], int arg_nb,
20 size_t *bufsize, size_t default_size, size_t min_size)
25 if (strict_strtoul(argv[arg_nb], 0, &value) < 0) {
26 sprintf(string, "invalid %d parameter %s",
27 arg_nb, argv[arg_nb]);
30 if (value > STM32_DDR_SIZE || value < min_size) {
31 sprintf(string, "invalid size %s (min=%d)",
32 argv[arg_nb], min_size);
35 if (value & (min_size - 1)) {
36 sprintf(string, "unaligned size %s (min=%d)",
37 argv[arg_nb], min_size);
42 if (default_size != STM32_DDR_SIZE)
43 *bufsize = default_size;
45 *bufsize = get_ram_size((long *)STM32_DDR_BASE,
51 static int get_nb_loop(char *string, int argc, char *argv[], int arg_nb,
52 u32 *nb_loop, u32 default_nb_loop)
57 if (strict_strtoul(argv[arg_nb], 0, &value) < 0) {
58 sprintf(string, "invalid %d parameter %s",
59 arg_nb, argv[arg_nb]);
63 printf("WARNING: infinite loop requested\n");
66 *nb_loop = default_nb_loop;
72 static int get_addr(char *string, int argc, char *argv[], int arg_nb,
78 if (strict_strtoul(argv[arg_nb], 16, &value) < 0) {
79 sprintf(string, "invalid %d parameter %s",
80 arg_nb, argv[arg_nb]);
83 if (value < STM32_DDR_BASE) {
84 sprintf(string, "too low address %s", argv[arg_nb]);
87 if (value & 0x3 && value != ADDR_INVALID) {
88 sprintf(string, "unaligned address %s",
94 *addr = STM32_DDR_BASE;
100 static int get_pattern(char *string, int argc, char *argv[], int arg_nb,
101 u32 *pattern, u32 default_pattern)
106 if (strict_strtoul(argv[arg_nb], 16, &value) < 0) {
107 sprintf(string, "invalid %d parameter %s",
108 arg_nb, argv[arg_nb]);
113 *pattern = default_pattern;
119 static u32 check_addr(u32 addr, u32 value)
121 u32 data = readl(addr);
124 printf("0x%08x: 0x%08x <=> 0x%08x", addr, data, value);
126 printf("(2nd read: 0x%08x)", data);
128 printf("- read error");
130 printf("- write error");
137 static int progress(u32 offset)
139 if (!(offset & 0xFFFFFF)) {
142 printf("\ntest interrupted!\n");
149 static int test_loop_end(u32 *loop, u32 nb_loop, u32 progress)
152 if (nb_loop && *loop >= nb_loop)
154 if ((*loop) % progress)
156 /* allow to interrupt the test only for progress step */
158 printf("test interrupted!\n");
161 printf("loop #%d\n", *loop);
167 /**********************************************************************
169 * Function: memTestDataBus()
171 * Description: Test the data bus wiring in a memory region by
172 * performing a walking 1's test at a fixed address
173 * within that region. The address is selected
178 * Returns: 0 if the test succeeds.
179 * A non-zero result is the first pattern that failed.
181 **********************************************************************/
182 static u32 databus(u32 *address)
187 /* Perform a walking 1's test at the given address. */
188 for (pattern = 1; pattern != 0; pattern <<= 1) {
189 /* Write the test pattern. */
190 writel(pattern, address);
192 /* Read it back (immediately is okay for this test). */
193 read_value = readl(address);
194 debug("%x: %x <=> %x\n",
195 (u32)address, read_value, pattern);
197 if (read_value != pattern)
204 /**********************************************************************
206 * Function: memTestAddressBus()
208 * Description: Test the address bus wiring in a memory region by
209 * performing a walking 1's test on the relevant bits
210 * of the address and checking for aliasing. This test
211 * will find single-bit address failures such as stuck
212 * -high, stuck-low, and shorted pins. The base address
213 * and size of the region are selected by the caller.
215 * Notes: For best results, the selected base address should
216 * have enough LSB 0's to guarantee single address bit
217 * changes. For example, to test a 64-Kbyte region,
218 * select a base address on a 64-Kbyte boundary. Also,
219 * select the region size as a power-of-two--if at all
222 * Returns: NULL if the test succeeds.
223 * A non-zero result is the first address at which an
224 * aliasing problem was uncovered. By examining the
225 * contents of memory, it may be possible to gather
226 * additional information about the problem.
228 **********************************************************************/
229 static u32 *addressbus(u32 *address, u32 nb_bytes)
231 u32 mask = (nb_bytes / sizeof(u32) - 1);
236 u32 pattern = 0xAAAAAAAA;
237 u32 antipattern = 0x55555555;
239 /* Write the default pattern at each of the power-of-two offsets. */
240 for (offset = 1; (offset & mask) != 0; offset <<= 1)
241 writel(pattern, &address[offset]);
243 /* Check for address bits stuck high. */
245 writel(antipattern, &address[test_offset]);
247 for (offset = 1; (offset & mask) != 0; offset <<= 1) {
248 read_value = readl(&address[offset]);
249 debug("%x: %x <=> %x\n",
250 (u32)&address[offset], read_value, pattern);
251 if (read_value != pattern)
252 return &address[offset];
255 writel(pattern, &address[test_offset]);
257 /* Check for address bits stuck low or shorted. */
258 for (test_offset = 1; (test_offset & mask) != 0; test_offset <<= 1) {
259 writel(antipattern, &address[test_offset]);
260 if (readl(&address[0]) != pattern)
261 return &address[test_offset];
263 for (offset = 1; (offset & mask) != 0; offset <<= 1) {
264 if (readl(&address[offset]) != pattern &&
265 offset != test_offset)
266 return &address[test_offset];
268 writel(pattern, &address[test_offset]);
274 /**********************************************************************
276 * Function: memTestDevice()
278 * Description: Test the integrity of a physical memory device by
279 * performing an increment/decrement test over the
280 * entire region. In the process every storage bit
281 * in the device is tested as a zero and a one. The
282 * base address and the size of the region are
283 * selected by the caller.
287 * Returns: NULL if the test succeeds.
289 * A non-zero result is the first address at which an
290 * incorrect value was read back. By examining the
291 * contents of memory, it may be possible to gather
292 * additional information about the problem.
294 **********************************************************************/
295 static u32 *memdevice(u32 *address, u32 nb_bytes)
298 u32 nb_words = nb_bytes / sizeof(u32);
303 puts("Fill with pattern");
304 /* Fill memory with a known pattern. */
305 for (pattern = 1, offset = 0; offset < nb_words; pattern++, offset++) {
306 writel(pattern, &address[offset]);
307 if (progress(offset))
311 puts("\nCheck and invert pattern");
312 /* Check each location and invert it for the second pass. */
313 for (pattern = 1, offset = 0; offset < nb_words; pattern++, offset++) {
314 if (readl(&address[offset]) != pattern)
315 return &address[offset];
317 antipattern = ~pattern;
318 writel(antipattern, &address[offset]);
319 if (progress(offset))
323 puts("\nCheck inverted pattern");
324 /* Check each location for the inverted pattern and zero it. */
325 for (pattern = 1, offset = 0; offset < nb_words; pattern++, offset++) {
326 antipattern = ~pattern;
327 if (readl(&address[offset]) != antipattern)
328 return &address[offset];
329 if (progress(offset))
337 static enum test_result databuswalk0(struct stm32mp1_ddrctl *ctl,
338 struct stm32mp1_ddrphy *phy,
339 char *string, int argc, char *argv[])
342 u32 loop = 0, nb_loop;
347 if (get_nb_loop(string, argc, argv, 0, &nb_loop, 100))
349 if (get_addr(string, argc, argv, 1, &addr))
352 printf("running %d loops at 0x%x\n", nb_loop, addr);
354 for (i = 0; i < 32; i++)
355 writel(~(1 << i), addr + 4 * i);
356 for (i = 0; i < 32; i++) {
357 data = readl(addr + 4 * i);
358 if (~(1 << i) != data) {
360 debug("%x: error %x expected %x => error:%x\n",
361 addr + 4 * i, data, ~(1 << i), error);
364 if (test_loop_end(&loop, nb_loop, 1000))
366 for (i = 0; i < 32; i++)
367 writel(0, addr + 4 * i);
370 sprintf(string, "loop %d: error for bits 0x%x",
374 sprintf(string, "no error for %d loops", loop);
378 static enum test_result databuswalk1(struct stm32mp1_ddrctl *ctl,
379 struct stm32mp1_ddrphy *phy,
380 char *string, int argc, char *argv[])
383 u32 loop = 0, nb_loop;
388 if (get_nb_loop(string, argc, argv, 0, &nb_loop, 100))
390 if (get_addr(string, argc, argv, 1, &addr))
392 printf("running %d loops at 0x%x\n", nb_loop, addr);
394 for (i = 0; i < 32; i++)
395 writel(1 << i, addr + 4 * i);
396 for (i = 0; i < 32; i++) {
397 data = readl(addr + 4 * i);
398 if ((1 << i) != data) {
400 debug("%x: error %x expected %x => error:%x\n",
401 addr + 4 * i, data, (1 << i), error);
404 if (test_loop_end(&loop, nb_loop, 1000))
406 for (i = 0; i < 32; i++)
407 writel(0, addr + 4 * i);
410 sprintf(string, "loop %d: error for bits 0x%x",
414 sprintf(string, "no error for %d loops", loop);
418 static enum test_result test_databus(struct stm32mp1_ddrctl *ctl,
419 struct stm32mp1_ddrphy *phy,
420 char *string, int argc, char *argv[])
425 if (get_addr(string, argc, argv, 0, &addr))
427 error = databus((u32 *)addr);
429 sprintf(string, "0x%x: error for bits 0x%x",
433 sprintf(string, "address 0x%x", addr);
437 static enum test_result test_addressbus(struct stm32mp1_ddrctl *ctl,
438 struct stm32mp1_ddrphy *phy,
439 char *string, int argc, char *argv[])
445 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 4))
447 if (!is_power_of_2(bufsize)) {
448 sprintf(string, "size 0x%x is not a power of 2",
452 if (get_addr(string, argc, argv, 1, &addr))
455 error = (u32)addressbus((u32 *)addr, bufsize);
457 sprintf(string, "0x%x: error for address 0x%x",
461 sprintf(string, "address 0x%x, size 0x%x",
466 static enum test_result test_memdevice(struct stm32mp1_ddrctl *ctl,
467 struct stm32mp1_ddrphy *phy,
468 char *string, int argc, char *argv[])
474 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 4))
476 if (get_addr(string, argc, argv, 1, &addr))
478 error = (u32)memdevice((u32 *)addr, (unsigned long)bufsize);
480 sprintf(string, "0x%x: error for address 0x%x",
484 sprintf(string, "address 0x%x, size 0x%x",
489 /**********************************************************************
493 * Description: Test the Simultaneous Switching Output.
494 * Verifies succes sive reads and writes to the same memory word,
495 * holding one bit constant while toggling all other data bits
497 * => stress the data bus over an address range
499 * The CPU writes to each address in the given range.
500 * For each bit, first the CPU holds the bit at 1 while
501 * toggling the other bits, and then the CPU holds the bit at 0
502 * while toggling the other bits.
503 * After each write, the CPU reads the address that was written
504 * to verify that it contains the correct data
506 **********************************************************************/
507 static enum test_result test_sso(struct stm32mp1_ddrctl *ctl,
508 struct stm32mp1_ddrphy *phy,
509 char *string, int argc, char *argv[])
512 u32 addr, bufsize, remaining, offset;
516 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 4))
518 if (get_addr(string, argc, argv, 1, &addr))
521 printf("running sso at 0x%x length 0x%x", addr, bufsize);
525 for (i = 0; i < 32; i++) {
527 for (j = 0; j < 6; j++) {
545 writel(data, offset);
546 error = check_addr(offset, data);
553 if (progress(offset << 7))
560 sprintf(string, "error for pattern 0x%x @0x%x",
564 sprintf(string, "no error for sso at 0x%x length 0x%x", addr, bufsize);
568 /**********************************************************************
572 * Description: Verifies r/w with pseudo-ramdom value on one region
573 * + write the region (individual access)
574 * + memcopy to the 2nd region (try to use burst)
575 * + verify the 2 regions
577 **********************************************************************/
578 static enum test_result test_random(struct stm32mp1_ddrctl *ctl,
579 struct stm32mp1_ddrphy *phy,
580 char *string, int argc, char *argv[])
582 u32 addr, offset, value = 0;
584 u32 loop = 0, nb_loop;
588 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 8))
590 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
592 if (get_addr(string, argc, argv, 2, &addr))
596 printf("running %d loops copy from 0x%x to 0x%x (buffer size=0x%x)\n",
597 nb_loop, addr, addr + bufsize, bufsize);
600 for (offset = 0; offset < bufsize; offset += 4)
601 writel(rand(), addr + offset);
603 memcpy((void *)addr + bufsize, (void *)addr, bufsize);
606 for (offset = 0; offset < 2 * bufsize; offset += 4) {
607 if (offset == bufsize)
610 error = check_addr(addr + offset, value);
613 if (progress(offset))
616 if (test_loop_end(&loop, nb_loop, 100))
623 "loop %d: error for address 0x%x: 0x%x expected 0x%x",
624 loop, offset, readl(offset), value);
627 sprintf(string, "no error for %d loops, size 0x%x",
632 /**********************************************************************
636 * Description: Verifies r/w while forcing switching of all data bus lines.
637 * optimised 4 iteration write/read/write/read cycles...
638 * for pattern and inversed pattern
640 **********************************************************************/
641 void do_noise(u32 addr, u32 pattern, u32 *result)
643 __asm__("push {R0-R11}");
644 __asm__("mov r0, %0" : : "r" (addr));
645 __asm__("mov r1, %0" : : "r" (pattern));
646 __asm__("mov r11, %0" : : "r" (result));
648 __asm__("mvn r2, r1");
650 __asm__("str r1, [r0]");
651 __asm__("ldr r3, [r0]");
652 __asm__("str r2, [r0]");
653 __asm__("ldr r4, [r0]");
655 __asm__("str r1, [r0]");
656 __asm__("ldr r5, [r0]");
657 __asm__("str r2, [r0]");
658 __asm__("ldr r6, [r0]");
660 __asm__("str r1, [r0]");
661 __asm__("ldr r7, [r0]");
662 __asm__("str r2, [r0]");
663 __asm__("ldr r8, [r0]");
665 __asm__("str r1, [r0]");
666 __asm__("ldr r9, [r0]");
667 __asm__("str r2, [r0]");
668 __asm__("ldr r10, [r0]");
670 __asm__("stmia R11!, {R3-R10}");
672 __asm__("pop {R0-R11}");
675 static enum test_result test_noise(struct stm32mp1_ddrctl *ctl,
676 struct stm32mp1_ddrphy *phy,
677 char *string, int argc, char *argv[])
682 enum test_result res = TEST_PASSED;
684 if (get_pattern(string, argc, argv, 0, &pattern, 0xFFFFFFFF))
686 if (get_addr(string, argc, argv, 1, &addr))
689 printf("running noise for 0x%x at 0x%x\n", pattern, addr);
691 do_noise(addr, pattern, result);
693 for (i = 0; i < 0x8;) {
694 if (check_addr((u32)&result[i++], pattern))
696 if (check_addr((u32)&result[i++], ~pattern))
703 /**********************************************************************
705 * Function: noise_burst
707 * Description: Verifies r/w while forcing switching of all data bus lines.
708 * optimised write loop witrh store multiple to use burst
709 * for pattern and inversed pattern
711 **********************************************************************/
712 void do_noise_burst(u32 addr, u32 pattern, size_t bufsize)
714 __asm__("push {R0-R9}");
715 __asm__("mov r0, %0" : : "r" (addr));
716 __asm__("mov r1, %0" : : "r" (pattern));
717 __asm__("mov r9, %0" : : "r" (bufsize));
719 __asm__("mvn r2, r1");
720 __asm__("mov r3, r1");
721 __asm__("mov r4, r2");
722 __asm__("mov r5, r1");
723 __asm__("mov r6, r2");
724 __asm__("mov r7, r1");
725 __asm__("mov r8, r2");
728 __asm__("stmia R0!, {R1-R8}");
729 __asm__("stmia R0!, {R1-R8}");
730 __asm__("stmia R0!, {R1-R8}");
731 __asm__("stmia R0!, {R1-R8}");
732 __asm__("subs r9, r9, #128");
733 __asm__("bge loop1");
734 __asm__("pop {R0-R9}");
737 /* chunk size enough to allow interruption with Ctrl-C*/
738 #define CHUNK_SIZE 0x8000000
739 static enum test_result test_noise_burst(struct stm32mp1_ddrctl *ctl,
740 struct stm32mp1_ddrphy *phy,
741 char *string, int argc, char *argv[])
743 u32 addr, offset, pattern;
744 size_t bufsize, remaining, size;
746 enum test_result res = TEST_PASSED;
748 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 128))
750 if (get_pattern(string, argc, argv, 1, &pattern, 0xFFFFFFFF))
752 if (get_addr(string, argc, argv, 2, &addr))
755 printf("running noise burst for 0x%x at 0x%x + 0x%x",
756 pattern, addr, bufsize);
762 if (remaining < size)
764 do_noise_burst(offset, pattern, size);
767 if (progress(offset)) {
772 puts("\ncheck buffer");
773 for (i = 0; i < bufsize;) {
774 if (check_addr(addr + i, pattern))
777 if (check_addr(addr + i, ~pattern))
790 /**********************************************************************
792 * Function: pattern test
794 * Description: optimized loop for read/write pattern (array of 8 u32)
796 **********************************************************************/
797 #define PATTERN_SIZE 8
798 static enum test_result test_loop(const u32 *pattern, u32 *address,
803 enum test_result res = TEST_PASSED;
804 u32 offset, testsize, remaining;
806 offset = (u32)address;
809 testsize = bufsize > 0x1000000 ? 0x1000000 : bufsize;
811 __asm__("push {R0-R10}");
812 __asm__("mov r0, %0" : : "r" (pattern));
813 __asm__("mov r1, %0" : : "r" (offset));
814 __asm__("mov r2, %0" : : "r" (testsize));
815 __asm__("ldmia r0!, {R3-R10}");
818 __asm__("stmia r1!, {R3-R10}");
819 __asm__("stmia r1!, {R3-R10}");
820 __asm__("stmia r1!, {R3-R10}");
821 __asm__("stmia r1!, {R3-R10}");
822 __asm__("subs r2, r2, #128");
823 __asm__("bge loop2");
824 __asm__("pop {R0-R10}");
827 remaining -= testsize;
828 if (progress((u32)offset)) {
834 puts("\ncheck buffer");
835 for (i = 0; i < bufsize; i += PATTERN_SIZE * 4) {
836 for (j = 0; j < PATTERN_SIZE; j++, address++)
837 if (check_addr((u32)address, pattern[j])) {
852 const u32 pattern_div1_x16[PATTERN_SIZE] = {
853 0x0000FFFF, 0x0000FFFF, 0x0000FFFF, 0x0000FFFF,
854 0x0000FFFF, 0x0000FFFF, 0x0000FFFF, 0x0000FFFF
857 const u32 pattern_div2_x16[PATTERN_SIZE] = {
858 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000,
859 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000
862 const u32 pattern_div4_x16[PATTERN_SIZE] = {
863 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
864 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000
867 const u32 pattern_div4_x32[PATTERN_SIZE] = {
868 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
869 0x00000000, 0x00000000, 0x00000000, 0x00000000
872 const u32 pattern_mostly_zero_x16[PATTERN_SIZE] = {
873 0x00000000, 0x00000000, 0x00000000, 0x0000FFFF,
874 0x00000000, 0x00000000, 0x00000000, 0x00000000
877 const u32 pattern_mostly_zero_x32[PATTERN_SIZE] = {
878 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF,
879 0x00000000, 0x00000000, 0x00000000, 0x00000000
882 const u32 pattern_mostly_one_x16[PATTERN_SIZE] = {
883 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000FFFF,
884 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
887 const u32 pattern_mostly_one_x32[PATTERN_SIZE] = {
888 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
889 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
893 static enum test_result test_freq_pattern(struct stm32mp1_ddrctl *ctl,
894 struct stm32mp1_ddrphy *phy,
895 char *string, int argc, char *argv[])
897 const u32 * const patterns_x16[NB_PATTERN] = {
901 pattern_mostly_zero_x16,
902 pattern_mostly_one_x16,
904 const u32 * const patterns_x32[NB_PATTERN] = {
908 pattern_mostly_zero_x32,
909 pattern_mostly_one_x32
911 const char *patterns_comments[NB_PATTERN] = {
912 "switching at frequency F/1",
913 "switching at frequency F/2",
914 "switching at frequency F/4",
919 enum test_result res = TEST_PASSED, pattern_res;
921 const u32 **patterns;
924 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 128))
927 switch (readl(&ctl->mstr) & DDRCTRL_MSTR_DATA_BUS_WIDTH_MASK) {
928 case DDRCTRL_MSTR_DATA_BUS_WIDTH_HALF:
929 case DDRCTRL_MSTR_DATA_BUS_WIDTH_QUARTER:
937 printf("running test pattern at 0x%08x length 0x%x width = %d\n",
938 STM32_DDR_BASE, bufsize, bus_width);
941 (const u32 **)(bus_width == 16 ? patterns_x16 : patterns_x32);
943 for (i = 0; i < NB_PATTERN; i++) {
944 printf("test data pattern %s:", patterns_comments[i]);
945 pattern_res = test_loop(patterns[i], (u32 *)STM32_DDR_BASE,
947 if (pattern_res != TEST_PASSED) {
957 /**********************************************************************
959 * Function: pattern test with size
961 * Description: loop for write pattern
963 **********************************************************************/
965 static enum test_result test_loop_size(const u32 *pattern, u32 size,
970 enum test_result res = TEST_PASSED;
973 for (i = 0; i < bufsize; i += size * 4) {
974 for (j = 0; j < size ; j++, p++)
982 puts("\ncheck buffer");
984 for (i = 0; i < bufsize; i += size * 4) {
985 for (j = 0; j < size; j++, p++)
986 if (check_addr((u32)p, pattern[j])) {
1001 static enum test_result test_checkboard(struct stm32mp1_ddrctl *ctl,
1002 struct stm32mp1_ddrphy *phy,
1003 char *string, int argc, char *argv[])
1005 enum test_result res = TEST_PASSED;
1006 u32 bufsize, nb_loop, loop = 0, addr;
1009 u32 checkboard[2] = {0x55555555, 0xAAAAAAAA};
1011 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 8))
1013 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1015 if (get_addr(string, argc, argv, 2, &addr))
1018 printf("running %d loops at 0x%08x length 0x%x\n",
1019 nb_loop, addr, bufsize);
1021 for (i = 0; i < 2; i++) {
1022 res = test_loop_size(checkboard, 2, (u32 *)addr,
1026 checkboard[0] = ~checkboard[0];
1027 checkboard[1] = ~checkboard[1];
1029 if (test_loop_end(&loop, nb_loop, 1))
1032 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1033 loop, addr, bufsize);
1038 static enum test_result test_blockseq(struct stm32mp1_ddrctl *ctl,
1039 struct stm32mp1_ddrphy *phy,
1040 char *string, int argc, char *argv[])
1042 enum test_result res = TEST_PASSED;
1043 u32 bufsize, nb_loop, loop = 0, addr, value;
1046 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 4))
1048 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1050 if (get_addr(string, argc, argv, 2, &addr))
1053 printf("running %d loops at 0x%08x length 0x%x\n",
1054 nb_loop, addr, bufsize);
1056 for (i = 0; i < 256; i++) {
1057 value = i | i << 8 | i << 16 | i << 24;
1058 printf("pattern = %08x", value);
1059 res = test_loop_size(&value, 1, (u32 *)addr, bufsize);
1060 if (res != TEST_PASSED)
1063 if (test_loop_end(&loop, nb_loop, 1))
1066 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1067 loop, addr, bufsize);
1072 static enum test_result test_walkbit0(struct stm32mp1_ddrctl *ctl,
1073 struct stm32mp1_ddrphy *phy,
1074 char *string, int argc, char *argv[])
1076 enum test_result res = TEST_PASSED;
1077 u32 bufsize, nb_loop, loop = 0, addr, value;
1080 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 4))
1082 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1084 if (get_addr(string, argc, argv, 2, &addr))
1087 printf("running %d loops at 0x%08x length 0x%x\n",
1088 nb_loop, addr, bufsize);
1090 for (i = 0; i < 64; i++) {
1094 value = 1 << (63 - i);
1096 printf("pattern = %08x", value);
1097 res = test_loop_size(&value, 1, (u32 *)addr, bufsize);
1098 if (res != TEST_PASSED)
1101 if (test_loop_end(&loop, nb_loop, 1))
1104 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1105 loop, addr, bufsize);
1110 static enum test_result test_walkbit1(struct stm32mp1_ddrctl *ctl,
1111 struct stm32mp1_ddrphy *phy,
1112 char *string, int argc, char *argv[])
1114 enum test_result res = TEST_PASSED;
1115 u32 bufsize, nb_loop, loop = 0, addr, value;
1118 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 4))
1120 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1122 if (get_addr(string, argc, argv, 2, &addr))
1125 printf("running %d loops at 0x%08x length 0x%x\n",
1126 nb_loop, addr, bufsize);
1128 for (i = 0; i < 64; i++) {
1132 value = ~(1 << (63 - i));
1134 printf("pattern = %08x", value);
1135 res = test_loop_size(&value, 1, (u32 *)addr, bufsize);
1136 if (res != TEST_PASSED)
1139 if (test_loop_end(&loop, nb_loop, 1))
1142 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1143 loop, addr, bufsize);
1149 * try to catch bad bits which are dependent on the current values of
1150 * surrounding bits in either the same word32
1152 static enum test_result test_bitspread(struct stm32mp1_ddrctl *ctl,
1153 struct stm32mp1_ddrphy *phy,
1154 char *string, int argc, char *argv[])
1156 enum test_result res = TEST_PASSED;
1157 u32 bufsize, nb_loop, loop = 0, addr, bitspread[4];
1160 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 32))
1162 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1164 if (get_addr(string, argc, argv, 2, &addr))
1167 printf("running %d loops at 0x%08x length 0x%x\n",
1168 nb_loop, addr, bufsize);
1170 for (i = 1; i < 32; i++) {
1171 for (j = 0; j < i; j++) {
1173 bitspread[0] = (1 << i) | (1 << j);
1175 bitspread[0] = (1 << (63 - i)) |
1177 bitspread[1] = bitspread[0];
1178 bitspread[2] = ~bitspread[0];
1179 bitspread[3] = ~bitspread[0];
1180 printf("pattern = %08x", bitspread[0]);
1182 res = test_loop_size(bitspread, 4, (u32 *)addr,
1184 if (res != TEST_PASSED)
1188 if (test_loop_end(&loop, nb_loop, 1))
1191 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1192 loop, addr, bufsize);
1197 static enum test_result test_bitflip(struct stm32mp1_ddrctl *ctl,
1198 struct stm32mp1_ddrphy *phy,
1199 char *string, int argc, char *argv[])
1201 enum test_result res = TEST_PASSED;
1202 u32 bufsize, nb_loop, loop = 0, addr;
1207 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024, 32))
1209 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1211 if (get_addr(string, argc, argv, 2, &addr))
1214 printf("running %d loops at 0x%08x length 0x%x\n",
1215 nb_loop, addr, bufsize);
1217 for (i = 0; i < 32; i++) {
1218 bitflip[0] = 1 << i;
1219 bitflip[1] = bitflip[0];
1220 bitflip[2] = ~bitflip[0];
1221 bitflip[3] = bitflip[2];
1222 printf("pattern = %08x", bitflip[0]);
1224 res = test_loop_size(bitflip, 4, (u32 *)addr, bufsize);
1225 if (res != TEST_PASSED)
1228 if (test_loop_end(&loop, nb_loop, 1))
1231 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1232 loop, addr, bufsize);
1237 /**********************************************************************
1239 * Function: infinite read access to DDR
1241 * Description: continuous read the same pattern at the same address
1243 **********************************************************************/
1244 static enum test_result test_read(struct stm32mp1_ddrctl *ctl,
1245 struct stm32mp1_ddrphy *phy,
1246 char *string, int argc, char *argv[])
1251 int i, size = 1024 * 1024;
1252 bool random = false;
1254 if (get_addr(string, argc, argv, 0, (u32 *)&addr))
1257 if (get_pattern(string, argc, argv, 1, &data, 0xA5A5AA55))
1260 if ((u32)addr == ADDR_INVALID) {
1261 printf("running random\n");
1264 printf("running at 0x%08x with pattern=0x%08x\n",
1270 for (i = 0; i < size; i++) {
1272 addr = (u32 *)(STM32_DDR_BASE +
1273 (rand() & (STM32_DDR_SIZE - 1) & ~0x3));
1276 if (test_loop_end(&loop, 0, 1))
1280 sprintf(string, "%d loops random", loop);
1282 sprintf(string, "%d loops at 0x%x: %x", loop, (u32)addr, data);
1287 /**********************************************************************
1289 * Function: infinite write access to DDR
1291 * Description: continuous write the same pattern at the same address
1293 **********************************************************************/
1294 static enum test_result test_write(struct stm32mp1_ddrctl *ctl,
1295 struct stm32mp1_ddrphy *phy,
1296 char *string, int argc, char *argv[])
1301 int i, size = 1024 * 1024;
1302 bool random = false;
1304 if (get_addr(string, argc, argv, 0, (u32 *)&addr))
1307 if (get_pattern(string, argc, argv, 1, &data, 0xA5A5AA55))
1310 if ((u32)addr == ADDR_INVALID) {
1311 printf("running random\n");
1314 printf("running at 0x%08x with pattern 0x%08x\n",
1319 for (i = 0; i < size; i++) {
1321 addr = (u32 *)(STM32_DDR_BASE +
1322 (rand() & (STM32_DDR_SIZE - 1) & ~0x3));
1327 if (test_loop_end(&loop, 0, 1))
1331 sprintf(string, "%d loops random", loop);
1333 sprintf(string, "%d loops at 0x%x: %x", loop, (u32)addr, data);
1338 #define NB_TEST_INFINITE 2
1339 static enum test_result test_all(struct stm32mp1_ddrctl *ctl,
1340 struct stm32mp1_ddrphy *phy,
1341 char *string, int argc, char *argv[])
1343 enum test_result res = TEST_PASSED, result;
1344 int i, nb_error = 0;
1345 u32 loop = 0, nb_loop;
1347 if (get_nb_loop(string, argc, argv, 0, &nb_loop, 1))
1351 /* execute all the test except the lasts which are infinite */
1352 for (i = 1; i < test_nb - NB_TEST_INFINITE; i++) {
1353 printf("execute %d:%s\n", (int)i, test[i].name);
1354 result = test[i].fct(ctl, phy, string, 0, NULL);
1355 printf("result %d:%s = ", (int)i, test[i].name);
1356 if (result != TEST_PASSED) {
1365 printf("loop %d: %d/%d test failed\n\n\n",
1366 loop + 1, nb_error, test_nb - NB_TEST_INFINITE);
1367 if (test_loop_end(&loop, nb_loop, 1))
1370 if (res != TEST_PASSED) {
1371 sprintf(string, "loop %d: %d/%d test failed", loop, nb_error,
1372 test_nb - NB_TEST_INFINITE);
1374 sprintf(string, "loop %d: %d tests passed", loop,
1375 test_nb - NB_TEST_INFINITE);
1380 /****************************************************************
1382 ****************************************************************/
1384 const struct test_desc test[] = {
1385 {test_all, "All", "[loop]", "Execute all tests", 1 },
1386 {test_databus, "Simple DataBus", "[addr]",
1387 "Verifies each data line by walking 1 on fixed address",
1390 {databuswalk0, "DataBusWalking0", "[loop] [addr]",
1391 "Verifies each data bus signal can be driven low (32 word burst)",
1394 {databuswalk1, "DataBusWalking1", "[loop] [addr]",
1395 "Verifies each data bus signal can be driven high (32 word burst)",
1398 {test_addressbus, "AddressBus", "[size] [addr]",
1399 "Verifies each relevant bits of the address and checking for aliasing",
1402 {test_memdevice, "MemDevice", "[size] [addr]",
1403 "Test the integrity of a physical memory (test every storage bit in the region)",
1406 {test_sso, "SimultaneousSwitchingOutput", "[size] [addr] ",
1407 "Stress the data bus over an address range",
1410 {test_noise, "Noise", "[pattern] [addr]",
1411 "Verifies r/w while forcing switching of all data bus lines.",
1414 {test_noise_burst, "NoiseBurst", "[size] [pattern] [addr]",
1415 "burst transfers while forcing switching of the data bus lines",
1418 {test_random, "Random", "[size] [loop] [addr]",
1419 "Verifies r/w and memcopy(burst for pseudo random value.",
1422 {test_freq_pattern, "FrequencySelectivePattern", "[size]",
1423 "write & test patterns: Mostly Zero, Mostly One and F/n",
1426 {test_blockseq, "BlockSequential", "[size] [loop] [addr]",
1427 "test incremental pattern",
1430 {test_checkboard, "Checkerboard", "[size] [loop] [addr]",
1431 "test checker pattern",
1434 {test_bitspread, "BitSpread", "[size] [loop] [addr]",
1435 "test Bit Spread pattern",
1438 {test_bitflip, "BitFlip", "[size] [loop] [addr]",
1439 "test Bit Flip pattern",
1442 {test_walkbit0, "WalkingOnes", "[size] [loop] [addr]",
1443 "test Walking Ones pattern",
1446 {test_walkbit1, "WalkingZeroes", "[size] [loop] [addr]",
1447 "test Walking Zeroes pattern",
1450 /* need to the the 2 last one (infinite) : skipped for test all */
1451 {test_read, "infinite read", "[addr] [pattern]",
1452 "basic test : infinite read access (random: addr=0xFFFFFFFF)", 2},
1453 {test_write, "infinite write", "[addr] [pattern]",
1454 "basic test : infinite write access (random: addr=0xFFFFFFFF)", 2},
1457 const int test_nb = ARRAY_SIZE(test);