1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
10 #include <linux/log2.h>
11 #include "stm32mp1_tests.h"
13 #define ADDR_INVALID 0xFFFFFFFF
15 DECLARE_GLOBAL_DATA_PTR;
17 static int get_bufsize(char *string, int argc, char *argv[], int arg_nb,
18 size_t *bufsize, size_t default_size)
23 if (strict_strtoul(argv[arg_nb], 0, &value) < 0) {
24 sprintf(string, "invalid %d parameter %s",
25 arg_nb, argv[arg_nb]);
28 if (value > STM32_DDR_SIZE || value == 0) {
29 sprintf(string, "invalid size %s", argv[arg_nb]);
33 sprintf(string, "unaligned size %s",
39 if (default_size != STM32_DDR_SIZE)
40 *bufsize = default_size;
42 *bufsize = get_ram_size((long *)STM32_DDR_BASE,
48 static int get_nb_loop(char *string, int argc, char *argv[], int arg_nb,
49 u32 *nb_loop, u32 default_nb_loop)
54 if (strict_strtoul(argv[arg_nb], 0, &value) < 0) {
55 sprintf(string, "invalid %d parameter %s",
56 arg_nb, argv[arg_nb]);
60 printf("WARNING: infinite loop requested\n");
63 *nb_loop = default_nb_loop;
69 static int get_addr(char *string, int argc, char *argv[], int arg_nb,
75 if (strict_strtoul(argv[arg_nb], 16, &value) < 0) {
76 sprintf(string, "invalid %d parameter %s",
77 arg_nb, argv[arg_nb]);
80 if (value < STM32_DDR_BASE) {
81 sprintf(string, "too low address %s", argv[arg_nb]);
84 if (value & 0x3 && value != ADDR_INVALID) {
85 sprintf(string, "unaligned address %s",
91 *addr = STM32_DDR_BASE;
97 static int get_pattern(char *string, int argc, char *argv[], int arg_nb,
98 u32 *pattern, u32 default_pattern)
103 if (strict_strtoul(argv[arg_nb], 16, &value) < 0) {
104 sprintf(string, "invalid %d parameter %s",
105 arg_nb, argv[arg_nb]);
110 *pattern = default_pattern;
116 static u32 check_addr(u32 addr, u32 value)
118 u32 data = readl(addr);
121 printf("0x%08x: 0x%08x <=> 0x%08x", addr, data, value);
123 printf("(2nd read: 0x%08x)", data);
125 printf("- read error");
127 printf("- write error");
134 static int progress(u32 offset)
136 if (!(offset & 0xFFFFFF)) {
139 printf("\ntest interrupted!\n");
146 static int test_loop_end(u32 *loop, u32 nb_loop, u32 progress)
149 if (nb_loop && *loop >= nb_loop)
151 if ((*loop) % progress)
153 /* allow to interrupt the test only for progress step */
155 printf("test interrupted!\n");
158 printf("loop #%d\n", *loop);
164 /**********************************************************************
166 * Function: memTestDataBus()
168 * Description: Test the data bus wiring in a memory region by
169 * performing a walking 1's test at a fixed address
170 * within that region. The address is selected
175 * Returns: 0 if the test succeeds.
176 * A non-zero result is the first pattern that failed.
178 **********************************************************************/
179 static u32 databus(u32 *address)
184 /* Perform a walking 1's test at the given address. */
185 for (pattern = 1; pattern != 0; pattern <<= 1) {
186 /* Write the test pattern. */
187 writel(pattern, address);
189 /* Read it back (immediately is okay for this test). */
190 read_value = readl(address);
191 debug("%x: %x <=> %x\n",
192 (u32)address, read_value, pattern);
194 if (read_value != pattern)
201 /**********************************************************************
203 * Function: memTestAddressBus()
205 * Description: Test the address bus wiring in a memory region by
206 * performing a walking 1's test on the relevant bits
207 * of the address and checking for aliasing. This test
208 * will find single-bit address failures such as stuck
209 * -high, stuck-low, and shorted pins. The base address
210 * and size of the region are selected by the caller.
212 * Notes: For best results, the selected base address should
213 * have enough LSB 0's to guarantee single address bit
214 * changes. For example, to test a 64-Kbyte region,
215 * select a base address on a 64-Kbyte boundary. Also,
216 * select the region size as a power-of-two--if at all
219 * Returns: NULL if the test succeeds.
220 * A non-zero result is the first address at which an
221 * aliasing problem was uncovered. By examining the
222 * contents of memory, it may be possible to gather
223 * additional information about the problem.
225 **********************************************************************/
226 static u32 *addressbus(u32 *address, u32 nb_bytes)
228 u32 mask = (nb_bytes / sizeof(u32) - 1);
233 u32 pattern = 0xAAAAAAAA;
234 u32 antipattern = 0x55555555;
236 /* Write the default pattern at each of the power-of-two offsets. */
237 for (offset = 1; (offset & mask) != 0; offset <<= 1)
238 writel(pattern, &address[offset]);
240 /* Check for address bits stuck high. */
242 writel(antipattern, &address[test_offset]);
244 for (offset = 1; (offset & mask) != 0; offset <<= 1) {
245 read_value = readl(&address[offset]);
246 debug("%x: %x <=> %x\n",
247 (u32)&address[offset], read_value, pattern);
248 if (read_value != pattern)
249 return &address[offset];
252 writel(pattern, &address[test_offset]);
254 /* Check for address bits stuck low or shorted. */
255 for (test_offset = 1; (test_offset & mask) != 0; test_offset <<= 1) {
256 writel(antipattern, &address[test_offset]);
257 if (readl(&address[0]) != pattern)
258 return &address[test_offset];
260 for (offset = 1; (offset & mask) != 0; offset <<= 1) {
261 if (readl(&address[offset]) != pattern &&
262 offset != test_offset)
263 return &address[test_offset];
265 writel(pattern, &address[test_offset]);
271 /**********************************************************************
273 * Function: memTestDevice()
275 * Description: Test the integrity of a physical memory device by
276 * performing an increment/decrement test over the
277 * entire region. In the process every storage bit
278 * in the device is tested as a zero and a one. The
279 * base address and the size of the region are
280 * selected by the caller.
284 * Returns: NULL if the test succeeds.
286 * A non-zero result is the first address at which an
287 * incorrect value was read back. By examining the
288 * contents of memory, it may be possible to gather
289 * additional information about the problem.
291 **********************************************************************/
292 static u32 *memdevice(u32 *address, u32 nb_bytes)
295 u32 nb_words = nb_bytes / sizeof(u32);
300 puts("Fill with pattern");
301 /* Fill memory with a known pattern. */
302 for (pattern = 1, offset = 0; offset < nb_words; pattern++, offset++) {
303 writel(pattern, &address[offset]);
304 if (progress(offset))
308 puts("\nCheck and invert pattern");
309 /* Check each location and invert it for the second pass. */
310 for (pattern = 1, offset = 0; offset < nb_words; pattern++, offset++) {
311 if (readl(&address[offset]) != pattern)
312 return &address[offset];
314 antipattern = ~pattern;
315 writel(antipattern, &address[offset]);
316 if (progress(offset))
320 puts("\nCheck inverted pattern");
321 /* Check each location for the inverted pattern and zero it. */
322 for (pattern = 1, offset = 0; offset < nb_words; pattern++, offset++) {
323 antipattern = ~pattern;
324 if (readl(&address[offset]) != antipattern)
325 return &address[offset];
326 if (progress(offset))
334 static enum test_result databuswalk0(struct stm32mp1_ddrctl *ctl,
335 struct stm32mp1_ddrphy *phy,
336 char *string, int argc, char *argv[])
339 u32 loop = 0, nb_loop;
344 if (get_nb_loop(string, argc, argv, 0, &nb_loop, 100))
346 if (get_addr(string, argc, argv, 1, &addr))
349 printf("running %d loops at 0x%x\n", nb_loop, addr);
351 for (i = 0; i < 32; i++)
352 writel(~(1 << i), addr + 4 * i);
353 for (i = 0; i < 32; i++) {
354 data = readl(addr + 4 * i);
355 if (~(1 << i) != data) {
357 debug("%x: error %x expected %x => error:%x\n",
358 addr + 4 * i, data, ~(1 << i), error);
361 if (test_loop_end(&loop, nb_loop, 1000))
363 for (i = 0; i < 32; i++)
364 writel(0, addr + 4 * i);
367 sprintf(string, "loop %d: error for bits 0x%x",
371 sprintf(string, "no error for %d loops", loop);
375 static enum test_result databuswalk1(struct stm32mp1_ddrctl *ctl,
376 struct stm32mp1_ddrphy *phy,
377 char *string, int argc, char *argv[])
380 u32 loop = 0, nb_loop;
385 if (get_nb_loop(string, argc, argv, 0, &nb_loop, 100))
387 if (get_addr(string, argc, argv, 1, &addr))
389 printf("running %d loops at 0x%x\n", nb_loop, addr);
391 for (i = 0; i < 32; i++)
392 writel(1 << i, addr + 4 * i);
393 for (i = 0; i < 32; i++) {
394 data = readl(addr + 4 * i);
395 if ((1 << i) != data) {
397 debug("%x: error %x expected %x => error:%x\n",
398 addr + 4 * i, data, (1 << i), error);
401 if (test_loop_end(&loop, nb_loop, 1000))
403 for (i = 0; i < 32; i++)
404 writel(0, addr + 4 * i);
407 sprintf(string, "loop %d: error for bits 0x%x",
411 sprintf(string, "no error for %d loops", loop);
415 static enum test_result test_databus(struct stm32mp1_ddrctl *ctl,
416 struct stm32mp1_ddrphy *phy,
417 char *string, int argc, char *argv[])
422 if (get_addr(string, argc, argv, 0, &addr))
424 error = databus((u32 *)addr);
426 sprintf(string, "0x%x: error for bits 0x%x",
430 sprintf(string, "address 0x%x", addr);
434 static enum test_result test_addressbus(struct stm32mp1_ddrctl *ctl,
435 struct stm32mp1_ddrphy *phy,
436 char *string, int argc, char *argv[])
442 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
444 if (!is_power_of_2(bufsize)) {
445 sprintf(string, "size 0x%x is not a power of 2",
449 if (get_addr(string, argc, argv, 1, &addr))
452 error = (u32)addressbus((u32 *)addr, bufsize);
454 sprintf(string, "0x%x: error for address 0x%x",
458 sprintf(string, "address 0x%x, size 0x%x",
463 static enum test_result test_memdevice(struct stm32mp1_ddrctl *ctl,
464 struct stm32mp1_ddrphy *phy,
465 char *string, int argc, char *argv[])
471 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
473 if (get_addr(string, argc, argv, 1, &addr))
475 error = (u32)memdevice((u32 *)addr, (unsigned long)bufsize);
477 sprintf(string, "0x%x: error for address 0x%x",
481 sprintf(string, "address 0x%x, size 0x%x",
486 /**********************************************************************
490 * Description: Test the Simultaneous Switching Output.
491 * Verifies succes sive reads and writes to the same memory word,
492 * holding one bit constant while toggling all other data bits
494 * => stress the data bus over an address range
496 * The CPU writes to each address in the given range.
497 * For each bit, first the CPU holds the bit at 1 while
498 * toggling the other bits, and then the CPU holds the bit at 0
499 * while toggling the other bits.
500 * After each write, the CPU reads the address that was written
501 * to verify that it contains the correct data
503 **********************************************************************/
504 static enum test_result test_sso(struct stm32mp1_ddrctl *ctl,
505 struct stm32mp1_ddrphy *phy,
506 char *string, int argc, char *argv[])
509 u32 addr, bufsize, remaining, offset;
513 if (get_bufsize(string, argc, argv, 0, &bufsize, 4))
515 if (get_addr(string, argc, argv, 1, &addr))
518 printf("running sso at 0x%x length 0x%x", addr, bufsize);
522 for (i = 0; i < 32; i++) {
524 for (j = 0; j < 6; j++) {
542 writel(data, offset);
543 error = check_addr(offset, data);
550 if (progress(offset << 7))
557 sprintf(string, "error for pattern 0x%x @0x%x",
561 sprintf(string, "no error for sso at 0x%x length 0x%x", addr, bufsize);
565 /**********************************************************************
569 * Description: Verifies r/w with pseudo-ramdom value on one region
570 * + write the region (individual access)
571 * + memcopy to the 2nd region (try to use burst)
572 * + verify the 2 regions
574 **********************************************************************/
575 static enum test_result test_random(struct stm32mp1_ddrctl *ctl,
576 struct stm32mp1_ddrphy *phy,
577 char *string, int argc, char *argv[])
579 u32 addr, offset, value = 0;
581 u32 loop = 0, nb_loop;
585 if (get_bufsize(string, argc, argv, 0, &bufsize, 8 * 1024))
587 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
589 if (get_addr(string, argc, argv, 2, &addr))
593 printf("running %d loops copy from 0x%x to 0x%x (buffer size=0x%x)\n",
594 nb_loop, addr, addr + bufsize, bufsize);
597 for (offset = 0; offset < bufsize; offset += 4)
598 writel(rand(), addr + offset);
600 memcpy((void *)addr + bufsize, (void *)addr, bufsize);
603 for (offset = 0; offset < 2 * bufsize; offset += 4) {
604 if (offset == bufsize)
607 error = check_addr(addr + offset, value);
610 if (progress(offset))
613 if (test_loop_end(&loop, nb_loop, 100))
620 "loop %d: error for address 0x%x: 0x%x expected 0x%x",
621 loop, offset, readl(offset), value);
624 sprintf(string, "no error for %d loops, size 0x%x",
629 /**********************************************************************
633 * Description: Verifies r/w while forcing switching of all data bus lines.
634 * optimised 4 iteration write/read/write/read cycles...
635 * for pattern and inversed pattern
637 **********************************************************************/
638 void do_noise(u32 addr, u32 pattern, u32 *result)
640 __asm__("push {R0-R11}");
641 __asm__("mov r0, %0" : : "r" (addr));
642 __asm__("mov r1, %0" : : "r" (pattern));
643 __asm__("mov r11, %0" : : "r" (result));
645 __asm__("mvn r2, r1");
647 __asm__("str r1, [r0]");
648 __asm__("ldr r3, [r0]");
649 __asm__("str r2, [r0]");
650 __asm__("ldr r4, [r0]");
652 __asm__("str r1, [r0]");
653 __asm__("ldr r5, [r0]");
654 __asm__("str r2, [r0]");
655 __asm__("ldr r6, [r0]");
657 __asm__("str r1, [r0]");
658 __asm__("ldr r7, [r0]");
659 __asm__("str r2, [r0]");
660 __asm__("ldr r8, [r0]");
662 __asm__("str r1, [r0]");
663 __asm__("ldr r9, [r0]");
664 __asm__("str r2, [r0]");
665 __asm__("ldr r10, [r0]");
667 __asm__("stmia R11!, {R3-R10}");
669 __asm__("pop {R0-R11}");
672 static enum test_result test_noise(struct stm32mp1_ddrctl *ctl,
673 struct stm32mp1_ddrphy *phy,
674 char *string, int argc, char *argv[])
679 enum test_result res = TEST_PASSED;
681 if (get_pattern(string, argc, argv, 0, &pattern, 0xFFFFFFFF))
683 if (get_addr(string, argc, argv, 1, &addr))
686 printf("running noise for 0x%x at 0x%x\n", pattern, addr);
688 do_noise(addr, pattern, result);
690 for (i = 0; i < 0x8;) {
691 if (check_addr((u32)&result[i++], pattern))
693 if (check_addr((u32)&result[i++], ~pattern))
700 /**********************************************************************
702 * Function: noise_burst
704 * Description: Verifies r/w while forcing switching of all data bus lines.
705 * optimised write loop witrh store multiple to use burst
706 * for pattern and inversed pattern
708 **********************************************************************/
709 void do_noise_burst(u32 addr, u32 pattern, size_t bufsize)
711 __asm__("push {R0-R9}");
712 __asm__("mov r0, %0" : : "r" (addr));
713 __asm__("mov r1, %0" : : "r" (pattern));
714 __asm__("mov r9, %0" : : "r" (bufsize));
716 __asm__("mvn r2, r1");
717 __asm__("mov r3, r1");
718 __asm__("mov r4, r2");
719 __asm__("mov r5, r1");
720 __asm__("mov r6, r2");
721 __asm__("mov r7, r1");
722 __asm__("mov r8, r2");
725 __asm__("stmia R0!, {R1-R8}");
726 __asm__("stmia R0!, {R1-R8}");
727 __asm__("stmia R0!, {R1-R8}");
728 __asm__("stmia R0!, {R1-R8}");
729 __asm__("subs r9, r9, #128");
730 __asm__("bge loop1");
731 __asm__("pop {R0-R9}");
734 /* chunk size enough to allow interruption with Ctrl-C*/
735 #define CHUNK_SIZE 0x8000000
736 static enum test_result test_noise_burst(struct stm32mp1_ddrctl *ctl,
737 struct stm32mp1_ddrphy *phy,
738 char *string, int argc, char *argv[])
740 u32 addr, offset, pattern;
741 size_t bufsize, remaining, size;
743 enum test_result res = TEST_PASSED;
745 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
747 if (get_pattern(string, argc, argv, 1, &pattern, 0xFFFFFFFF))
749 if (get_addr(string, argc, argv, 2, &addr))
752 printf("running noise burst for 0x%x at 0x%x + 0x%x",
753 pattern, addr, bufsize);
759 if (remaining < size)
761 do_noise_burst(offset, pattern, size);
764 if (progress(offset)) {
769 puts("\ncheck buffer");
770 for (i = 0; i < bufsize;) {
771 if (check_addr(addr + i, pattern))
774 if (check_addr(addr + i, ~pattern))
787 /**********************************************************************
789 * Function: pattern test
791 * Description: optimized loop for read/write pattern (array of 8 u32)
793 **********************************************************************/
794 #define PATTERN_SIZE 8
795 static enum test_result test_loop(const u32 *pattern, u32 *address,
800 enum test_result res = TEST_PASSED;
801 u32 offset, testsize, remaining;
803 offset = (u32)address;
806 testsize = bufsize > 0x1000000 ? 0x1000000 : bufsize;
808 __asm__("push {R0-R10}");
809 __asm__("mov r0, %0" : : "r" (pattern));
810 __asm__("mov r1, %0" : : "r" (offset));
811 __asm__("mov r2, %0" : : "r" (testsize));
812 __asm__("ldmia r0!, {R3-R10}");
815 __asm__("stmia r1!, {R3-R10}");
816 __asm__("stmia r1!, {R3-R10}");
817 __asm__("stmia r1!, {R3-R10}");
818 __asm__("stmia r1!, {R3-R10}");
819 __asm__("subs r2, r2, #128");
820 __asm__("bge loop2");
821 __asm__("pop {R0-R10}");
824 remaining -= testsize;
825 if (progress((u32)offset)) {
831 puts("\ncheck buffer");
832 for (i = 0; i < bufsize; i += PATTERN_SIZE * 4) {
833 for (j = 0; j < PATTERN_SIZE; j++, address++)
834 if (check_addr((u32)address, pattern[j])) {
849 const u32 pattern_div1_x16[PATTERN_SIZE] = {
850 0x0000FFFF, 0x0000FFFF, 0x0000FFFF, 0x0000FFFF,
851 0x0000FFFF, 0x0000FFFF, 0x0000FFFF, 0x0000FFFF
854 const u32 pattern_div2_x16[PATTERN_SIZE] = {
855 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000,
856 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000
859 const u32 pattern_div4_x16[PATTERN_SIZE] = {
860 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
861 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000
864 const u32 pattern_div4_x32[PATTERN_SIZE] = {
865 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
866 0x00000000, 0x00000000, 0x00000000, 0x00000000
869 const u32 pattern_mostly_zero_x16[PATTERN_SIZE] = {
870 0x00000000, 0x00000000, 0x00000000, 0x0000FFFF,
871 0x00000000, 0x00000000, 0x00000000, 0x00000000
874 const u32 pattern_mostly_zero_x32[PATTERN_SIZE] = {
875 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF,
876 0x00000000, 0x00000000, 0x00000000, 0x00000000
879 const u32 pattern_mostly_one_x16[PATTERN_SIZE] = {
880 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000FFFF,
881 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
884 const u32 pattern_mostly_one_x32[PATTERN_SIZE] = {
885 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
886 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
890 static enum test_result test_freq_pattern(struct stm32mp1_ddrctl *ctl,
891 struct stm32mp1_ddrphy *phy,
892 char *string, int argc, char *argv[])
894 const u32 * const patterns_x16[NB_PATTERN] = {
898 pattern_mostly_zero_x16,
899 pattern_mostly_one_x16,
901 const u32 * const patterns_x32[NB_PATTERN] = {
905 pattern_mostly_zero_x32,
906 pattern_mostly_one_x32
908 const char *patterns_comments[NB_PATTERN] = {
909 "switching at frequency F/1",
910 "switching at frequency F/2",
911 "switching at frequency F/4",
916 enum test_result res = TEST_PASSED, pattern_res;
918 const u32 **patterns;
921 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
924 switch (readl(&ctl->mstr) & DDRCTRL_MSTR_DATA_BUS_WIDTH_MASK) {
925 case DDRCTRL_MSTR_DATA_BUS_WIDTH_HALF:
926 case DDRCTRL_MSTR_DATA_BUS_WIDTH_QUARTER:
934 printf("running test pattern at 0x%08x length 0x%x width = %d\n",
935 STM32_DDR_BASE, bufsize, bus_width);
938 (const u32 **)(bus_width == 16 ? patterns_x16 : patterns_x32);
940 for (i = 0; i < NB_PATTERN; i++) {
941 printf("test data pattern %s:", patterns_comments[i]);
942 pattern_res = test_loop(patterns[i], (u32 *)STM32_DDR_BASE,
944 if (pattern_res != TEST_PASSED) {
954 /**********************************************************************
956 * Function: pattern test with size
958 * Description: loop for write pattern
960 **********************************************************************/
962 static enum test_result test_loop_size(const u32 *pattern, u32 size,
967 enum test_result res = TEST_PASSED;
970 for (i = 0; i < bufsize; i += size * 4) {
971 for (j = 0; j < size ; j++, p++)
979 puts("\ncheck buffer");
981 for (i = 0; i < bufsize; i += size * 4) {
982 for (j = 0; j < size; j++, p++)
983 if (check_addr((u32)p, pattern[j])) {
998 static enum test_result test_checkboard(struct stm32mp1_ddrctl *ctl,
999 struct stm32mp1_ddrphy *phy,
1000 char *string, int argc, char *argv[])
1002 enum test_result res = TEST_PASSED;
1003 u32 bufsize, nb_loop, loop = 0, addr;
1006 u32 checkboard[2] = {0x55555555, 0xAAAAAAAA};
1008 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1010 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1012 if (get_addr(string, argc, argv, 2, &addr))
1015 printf("running %d loops at 0x%08x length 0x%x\n",
1016 nb_loop, addr, bufsize);
1018 for (i = 0; i < 2; i++) {
1019 res = test_loop_size(checkboard, 2, (u32 *)addr,
1023 checkboard[0] = ~checkboard[0];
1024 checkboard[1] = ~checkboard[1];
1026 if (test_loop_end(&loop, nb_loop, 1))
1029 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1030 loop, addr, bufsize);
1035 static enum test_result test_blockseq(struct stm32mp1_ddrctl *ctl,
1036 struct stm32mp1_ddrphy *phy,
1037 char *string, int argc, char *argv[])
1039 enum test_result res = TEST_PASSED;
1040 u32 bufsize, nb_loop, loop = 0, addr, value;
1043 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1045 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1047 if (get_addr(string, argc, argv, 2, &addr))
1050 printf("running %d loops at 0x%08x length 0x%x\n",
1051 nb_loop, addr, bufsize);
1053 for (i = 0; i < 256; i++) {
1054 value = i | i << 8 | i << 16 | i << 24;
1055 printf("pattern = %08x", value);
1056 res = test_loop_size(&value, 1, (u32 *)addr, bufsize);
1057 if (res != TEST_PASSED)
1060 if (test_loop_end(&loop, nb_loop, 1))
1063 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1064 loop, addr, bufsize);
1069 static enum test_result test_walkbit0(struct stm32mp1_ddrctl *ctl,
1070 struct stm32mp1_ddrphy *phy,
1071 char *string, int argc, char *argv[])
1073 enum test_result res = TEST_PASSED;
1074 u32 bufsize, nb_loop, loop = 0, addr, value;
1077 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1079 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1081 if (get_addr(string, argc, argv, 2, &addr))
1084 printf("running %d loops at 0x%08x length 0x%x\n",
1085 nb_loop, addr, bufsize);
1087 for (i = 0; i < 64; i++) {
1091 value = 1 << (63 - i);
1093 printf("pattern = %08x", value);
1094 res = test_loop_size(&value, 1, (u32 *)addr, bufsize);
1095 if (res != TEST_PASSED)
1098 if (test_loop_end(&loop, nb_loop, 1))
1101 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1102 loop, addr, bufsize);
1107 static enum test_result test_walkbit1(struct stm32mp1_ddrctl *ctl,
1108 struct stm32mp1_ddrphy *phy,
1109 char *string, int argc, char *argv[])
1111 enum test_result res = TEST_PASSED;
1112 u32 bufsize, nb_loop, loop = 0, addr, value;
1115 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1117 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1119 if (get_addr(string, argc, argv, 2, &addr))
1122 printf("running %d loops at 0x%08x length 0x%x\n",
1123 nb_loop, addr, bufsize);
1125 for (i = 0; i < 64; i++) {
1129 value = ~(1 << (63 - i));
1131 printf("pattern = %08x", value);
1132 res = test_loop_size(&value, 1, (u32 *)addr, bufsize);
1133 if (res != TEST_PASSED)
1136 if (test_loop_end(&loop, nb_loop, 1))
1139 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1140 loop, addr, bufsize);
1146 * try to catch bad bits which are dependent on the current values of
1147 * surrounding bits in either the same word32
1149 static enum test_result test_bitspread(struct stm32mp1_ddrctl *ctl,
1150 struct stm32mp1_ddrphy *phy,
1151 char *string, int argc, char *argv[])
1153 enum test_result res = TEST_PASSED;
1154 u32 bufsize, nb_loop, loop = 0, addr, bitspread[4];
1157 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1159 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1161 if (get_addr(string, argc, argv, 2, &addr))
1164 printf("running %d loops at 0x%08x length 0x%x\n",
1165 nb_loop, addr, bufsize);
1167 for (i = 1; i < 32; i++) {
1168 for (j = 0; j < i; j++) {
1170 bitspread[0] = (1 << i) | (1 << j);
1172 bitspread[0] = (1 << (63 - i)) |
1174 bitspread[1] = bitspread[0];
1175 bitspread[2] = ~bitspread[0];
1176 bitspread[3] = ~bitspread[0];
1177 printf("pattern = %08x", bitspread[0]);
1179 res = test_loop_size(bitspread, 4, (u32 *)addr,
1181 if (res != TEST_PASSED)
1185 if (test_loop_end(&loop, nb_loop, 1))
1188 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1189 loop, addr, bufsize);
1194 static enum test_result test_bitflip(struct stm32mp1_ddrctl *ctl,
1195 struct stm32mp1_ddrphy *phy,
1196 char *string, int argc, char *argv[])
1198 enum test_result res = TEST_PASSED;
1199 u32 bufsize, nb_loop, loop = 0, addr;
1204 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1206 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1208 if (get_addr(string, argc, argv, 2, &addr))
1211 printf("running %d loops at 0x%08x length 0x%x\n",
1212 nb_loop, addr, bufsize);
1214 for (i = 0; i < 32; i++) {
1215 bitflip[0] = 1 << i;
1216 bitflip[1] = bitflip[0];
1217 bitflip[2] = ~bitflip[0];
1218 bitflip[3] = bitflip[2];
1219 printf("pattern = %08x", bitflip[0]);
1221 res = test_loop_size(bitflip, 4, (u32 *)addr, bufsize);
1222 if (res != TEST_PASSED)
1225 if (test_loop_end(&loop, nb_loop, 1))
1228 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1229 loop, addr, bufsize);
1234 /**********************************************************************
1236 * Function: infinite read access to DDR
1238 * Description: continuous read the same pattern at the same address
1240 **********************************************************************/
1241 static enum test_result test_read(struct stm32mp1_ddrctl *ctl,
1242 struct stm32mp1_ddrphy *phy,
1243 char *string, int argc, char *argv[])
1248 int i, size = 1024 * 1024;
1249 bool random = false;
1251 if (get_addr(string, argc, argv, 0, (u32 *)&addr))
1254 if (get_pattern(string, argc, argv, 1, &data, 0xA5A5AA55))
1257 if ((u32)addr == ADDR_INVALID) {
1258 printf("running random\n");
1261 printf("running at 0x%08x with pattern=0x%08x\n",
1267 for (i = 0; i < size; i++) {
1269 addr = (u32 *)(STM32_DDR_BASE +
1270 (rand() & (STM32_DDR_SIZE - 1) & ~0x3));
1273 if (test_loop_end(&loop, 0, 1))
1277 sprintf(string, "%d loops random", loop);
1279 sprintf(string, "%d loops at 0x%x: %x", loop, (u32)addr, data);
1284 /**********************************************************************
1286 * Function: infinite write access to DDR
1288 * Description: continuous write the same pattern at the same address
1290 **********************************************************************/
1291 static enum test_result test_write(struct stm32mp1_ddrctl *ctl,
1292 struct stm32mp1_ddrphy *phy,
1293 char *string, int argc, char *argv[])
1298 int i, size = 1024 * 1024;
1299 bool random = false;
1301 if (get_addr(string, argc, argv, 0, (u32 *)&addr))
1304 if (get_pattern(string, argc, argv, 1, &data, 0xA5A5AA55))
1307 if ((u32)addr == ADDR_INVALID) {
1308 printf("running random\n");
1311 printf("running at 0x%08x with pattern 0x%08x\n",
1316 for (i = 0; i < size; i++) {
1318 addr = (u32 *)(STM32_DDR_BASE +
1319 (rand() & (STM32_DDR_SIZE - 1) & ~0x3));
1324 if (test_loop_end(&loop, 0, 1))
1328 sprintf(string, "%d loops random", loop);
1330 sprintf(string, "%d loops at 0x%x: %x", loop, (u32)addr, data);
1335 #define NB_TEST_INFINITE 2
1336 static enum test_result test_all(struct stm32mp1_ddrctl *ctl,
1337 struct stm32mp1_ddrphy *phy,
1338 char *string, int argc, char *argv[])
1340 enum test_result res = TEST_PASSED, result;
1341 int i, nb_error = 0;
1342 u32 loop = 0, nb_loop;
1344 if (get_nb_loop(string, argc, argv, 0, &nb_loop, 1))
1348 /* execute all the test except the lasts which are infinite */
1349 for (i = 1; i < test_nb - NB_TEST_INFINITE; i++) {
1350 printf("execute %d:%s\n", (int)i, test[i].name);
1351 result = test[i].fct(ctl, phy, string, 0, NULL);
1352 printf("result %d:%s = ", (int)i, test[i].name);
1353 if (result != TEST_PASSED) {
1362 printf("loop %d: %d/%d test failed\n\n\n",
1363 loop + 1, nb_error, test_nb - NB_TEST_INFINITE);
1364 if (test_loop_end(&loop, nb_loop, 1))
1367 if (res != TEST_PASSED) {
1368 sprintf(string, "loop %d: %d/%d test failed", loop, nb_error,
1369 test_nb - NB_TEST_INFINITE);
1371 sprintf(string, "loop %d: %d tests passed", loop,
1372 test_nb - NB_TEST_INFINITE);
1377 /****************************************************************
1379 ****************************************************************/
1381 const struct test_desc test[] = {
1382 {test_all, "All", "[loop]", "Execute all tests", 1 },
1383 {test_databus, "Simple DataBus", "[addr]",
1384 "Verifies each data line by walking 1 on fixed address",
1387 {databuswalk0, "DataBusWalking0", "[loop] [addr]",
1388 "Verifies each data bus signal can be driven low (32 word burst)",
1391 {databuswalk1, "DataBusWalking1", "[loop] [addr]",
1392 "Verifies each data bus signal can be driven high (32 word burst)",
1395 {test_addressbus, "AddressBus", "[size] [addr]",
1396 "Verifies each relevant bits of the address and checking for aliasing",
1399 {test_memdevice, "MemDevice", "[size] [addr]",
1400 "Test the integrity of a physical memory (test every storage bit in the region)",
1403 {test_sso, "SimultaneousSwitchingOutput", "[size] [addr] ",
1404 "Stress the data bus over an address range",
1407 {test_noise, "Noise", "[pattern] [addr]",
1408 "Verifies r/w while forcing switching of all data bus lines.",
1411 {test_noise_burst, "NoiseBurst", "[size] [pattern] [addr]",
1412 "burst transfers while forcing switching of the data bus lines",
1415 {test_random, "Random", "[size] [loop] [addr]",
1416 "Verifies r/w and memcopy(burst for pseudo random value.",
1419 {test_freq_pattern, "FrequencySelectivePattern", "[size]",
1420 "write & test patterns: Mostly Zero, Mostly One and F/n",
1423 {test_blockseq, "BlockSequential", "[size] [loop] [addr]",
1424 "test incremental pattern",
1427 {test_checkboard, "Checkerboard", "[size] [loop] [addr]",
1428 "test checker pattern",
1431 {test_bitspread, "BitSpread", "[size] [loop] [addr]",
1432 "test Bit Spread pattern",
1435 {test_bitflip, "BitFlip", "[size] [loop] [addr]",
1436 "test Bit Flip pattern",
1439 {test_walkbit0, "WalkingOnes", "[size] [loop] [addr]",
1440 "test Walking Ones pattern",
1443 {test_walkbit1, "WalkingZeroes", "[size] [loop] [addr]",
1444 "test Walking Zeroes pattern",
1447 /* need to the the 2 last one (infinite) : skipped for test all */
1448 {test_read, "infinite read", "[addr] [pattern]",
1449 "basic test : infinite read access (random: addr=0xFFFFFFFF)", 2},
1450 {test_write, "infinite write", "[addr] [pattern]",
1451 "basic test : infinite write access (random: addr=0xFFFFFFFF)", 2},
1454 const int test_nb = ARRAY_SIZE(test);