1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
9 #include <linux/log2.h>
10 #include "stm32mp1_tests.h"
12 #define ADDR_INVALID 0xFFFFFFFF
14 DECLARE_GLOBAL_DATA_PTR;
16 static int get_bufsize(char *string, int argc, char *argv[], int arg_nb,
17 size_t *bufsize, size_t default_size)
22 if (strict_strtoul(argv[arg_nb], 0, &value) < 0) {
23 sprintf(string, "invalid %d parameter %s",
24 arg_nb, argv[arg_nb]);
27 if (value > STM32_DDR_SIZE || value == 0) {
28 sprintf(string, "invalid size %s", argv[arg_nb]);
32 sprintf(string, "unaligned size %s",
38 if (default_size != STM32_DDR_SIZE)
39 *bufsize = default_size;
41 *bufsize = get_ram_size((long *)STM32_DDR_BASE,
47 static int get_nb_loop(char *string, int argc, char *argv[], int arg_nb,
48 u32 *nb_loop, u32 default_nb_loop)
53 if (strict_strtoul(argv[arg_nb], 0, &value) < 0) {
54 sprintf(string, "invalid %d parameter %s",
55 arg_nb, argv[arg_nb]);
59 printf("WARNING: infinite loop requested\n");
62 *nb_loop = default_nb_loop;
68 static int get_addr(char *string, int argc, char *argv[], int arg_nb,
74 if (strict_strtoul(argv[arg_nb], 16, &value) < 0) {
75 sprintf(string, "invalid %d parameter %s",
76 arg_nb, argv[arg_nb]);
79 if (value < STM32_DDR_BASE) {
80 sprintf(string, "too low address %s", argv[arg_nb]);
83 if (value & 0x3 && value != ADDR_INVALID) {
84 sprintf(string, "unaligned address %s",
90 *addr = STM32_DDR_BASE;
96 static int get_pattern(char *string, int argc, char *argv[], int arg_nb,
97 u32 *pattern, u32 default_pattern)
102 if (strict_strtoul(argv[arg_nb], 16, &value) < 0) {
103 sprintf(string, "invalid %d parameter %s",
104 arg_nb, argv[arg_nb]);
109 *pattern = default_pattern;
115 static u32 check_addr(u32 addr, u32 value)
117 u32 data = readl(addr);
120 printf("0x%08x: 0x%08x <=> 0x%08x", addr, data, value);
122 printf("(2nd read: 0x%08x)", data);
124 printf("- read error");
126 printf("- write error");
133 static int progress(u32 offset)
135 if (!(offset & 0xFFFFFF)) {
138 printf("\ntest interrupted!\n");
145 static int test_loop_end(u32 *loop, u32 nb_loop, u32 progress)
148 if (nb_loop && *loop >= nb_loop)
150 if ((*loop) % progress)
152 /* allow to interrupt the test only for progress step */
154 printf("test interrupted!\n");
157 printf("loop #%d\n", *loop);
163 /**********************************************************************
165 * Function: memTestDataBus()
167 * Description: Test the data bus wiring in a memory region by
168 * performing a walking 1's test at a fixed address
169 * within that region. The address is selected
174 * Returns: 0 if the test succeeds.
175 * A non-zero result is the first pattern that failed.
177 **********************************************************************/
178 static u32 databus(u32 *address)
183 /* Perform a walking 1's test at the given address. */
184 for (pattern = 1; pattern != 0; pattern <<= 1) {
185 /* Write the test pattern. */
186 writel(pattern, address);
188 /* Read it back (immediately is okay for this test). */
189 read_value = readl(address);
190 debug("%x: %x <=> %x\n",
191 (u32)address, read_value, pattern);
193 if (read_value != pattern)
200 /**********************************************************************
202 * Function: memTestAddressBus()
204 * Description: Test the address bus wiring in a memory region by
205 * performing a walking 1's test on the relevant bits
206 * of the address and checking for aliasing. This test
207 * will find single-bit address failures such as stuck
208 * -high, stuck-low, and shorted pins. The base address
209 * and size of the region are selected by the caller.
211 * Notes: For best results, the selected base address should
212 * have enough LSB 0's to guarantee single address bit
213 * changes. For example, to test a 64-Kbyte region,
214 * select a base address on a 64-Kbyte boundary. Also,
215 * select the region size as a power-of-two--if at all
218 * Returns: NULL if the test succeeds.
219 * A non-zero result is the first address at which an
220 * aliasing problem was uncovered. By examining the
221 * contents of memory, it may be possible to gather
222 * additional information about the problem.
224 **********************************************************************/
225 static u32 *addressbus(u32 *address, u32 nb_bytes)
227 u32 mask = (nb_bytes / sizeof(u32) - 1);
232 u32 pattern = 0xAAAAAAAA;
233 u32 antipattern = 0x55555555;
235 /* Write the default pattern at each of the power-of-two offsets. */
236 for (offset = 1; (offset & mask) != 0; offset <<= 1)
237 writel(pattern, &address[offset]);
239 /* Check for address bits stuck high. */
241 writel(antipattern, &address[test_offset]);
243 for (offset = 1; (offset & mask) != 0; offset <<= 1) {
244 read_value = readl(&address[offset]);
245 debug("%x: %x <=> %x\n",
246 (u32)&address[offset], read_value, pattern);
247 if (read_value != pattern)
248 return &address[offset];
251 writel(pattern, &address[test_offset]);
253 /* Check for address bits stuck low or shorted. */
254 for (test_offset = 1; (test_offset & mask) != 0; test_offset <<= 1) {
255 writel(antipattern, &address[test_offset]);
256 if (readl(&address[0]) != pattern)
257 return &address[test_offset];
259 for (offset = 1; (offset & mask) != 0; offset <<= 1) {
260 if (readl(&address[offset]) != pattern &&
261 offset != test_offset)
262 return &address[test_offset];
264 writel(pattern, &address[test_offset]);
270 /**********************************************************************
272 * Function: memTestDevice()
274 * Description: Test the integrity of a physical memory device by
275 * performing an increment/decrement test over the
276 * entire region. In the process every storage bit
277 * in the device is tested as a zero and a one. The
278 * base address and the size of the region are
279 * selected by the caller.
283 * Returns: NULL if the test succeeds.
285 * A non-zero result is the first address at which an
286 * incorrect value was read back. By examining the
287 * contents of memory, it may be possible to gather
288 * additional information about the problem.
290 **********************************************************************/
291 static u32 *memdevice(u32 *address, u32 nb_bytes)
294 u32 nb_words = nb_bytes / sizeof(u32);
299 puts("Fill with pattern");
300 /* Fill memory with a known pattern. */
301 for (pattern = 1, offset = 0; offset < nb_words; pattern++, offset++) {
302 writel(pattern, &address[offset]);
303 if (progress(offset))
307 puts("\nCheck and invert pattern");
308 /* Check each location and invert it for the second pass. */
309 for (pattern = 1, offset = 0; offset < nb_words; pattern++, offset++) {
310 if (readl(&address[offset]) != pattern)
311 return &address[offset];
313 antipattern = ~pattern;
314 writel(antipattern, &address[offset]);
315 if (progress(offset))
319 puts("\nCheck inverted pattern");
320 /* Check each location for the inverted pattern and zero it. */
321 for (pattern = 1, offset = 0; offset < nb_words; pattern++, offset++) {
322 antipattern = ~pattern;
323 if (readl(&address[offset]) != antipattern)
324 return &address[offset];
325 if (progress(offset))
333 static enum test_result databuswalk0(struct stm32mp1_ddrctl *ctl,
334 struct stm32mp1_ddrphy *phy,
335 char *string, int argc, char *argv[])
338 u32 loop = 0, nb_loop;
343 if (get_nb_loop(string, argc, argv, 0, &nb_loop, 100))
345 if (get_addr(string, argc, argv, 1, &addr))
348 printf("running %d loops at 0x%x\n", nb_loop, addr);
350 for (i = 0; i < 32; i++)
351 writel(~(1 << i), addr + 4 * i);
352 for (i = 0; i < 32; i++) {
353 data = readl(addr + 4 * i);
354 if (~(1 << i) != data) {
356 debug("%x: error %x expected %x => error:%x\n",
357 addr + 4 * i, data, ~(1 << i), error);
360 if (test_loop_end(&loop, nb_loop, 1000))
362 for (i = 0; i < 32; i++)
363 writel(0, addr + 4 * i);
366 sprintf(string, "loop %d: error for bits 0x%x",
370 sprintf(string, "no error for %d loops", loop);
374 static enum test_result databuswalk1(struct stm32mp1_ddrctl *ctl,
375 struct stm32mp1_ddrphy *phy,
376 char *string, int argc, char *argv[])
379 u32 loop = 0, nb_loop;
384 if (get_nb_loop(string, argc, argv, 0, &nb_loop, 100))
386 if (get_addr(string, argc, argv, 1, &addr))
388 printf("running %d loops at 0x%x\n", nb_loop, addr);
390 for (i = 0; i < 32; i++)
391 writel(1 << i, addr + 4 * i);
392 for (i = 0; i < 32; i++) {
393 data = readl(addr + 4 * i);
394 if ((1 << i) != data) {
396 debug("%x: error %x expected %x => error:%x\n",
397 addr + 4 * i, data, (1 << i), error);
400 if (test_loop_end(&loop, nb_loop, 1000))
402 for (i = 0; i < 32; i++)
403 writel(0, addr + 4 * i);
406 sprintf(string, "loop %d: error for bits 0x%x",
410 sprintf(string, "no error for %d loops", loop);
414 static enum test_result test_databus(struct stm32mp1_ddrctl *ctl,
415 struct stm32mp1_ddrphy *phy,
416 char *string, int argc, char *argv[])
421 if (get_addr(string, argc, argv, 0, &addr))
423 error = databus((u32 *)addr);
425 sprintf(string, "0x%x: error for bits 0x%x",
429 sprintf(string, "address 0x%x", addr);
433 static enum test_result test_addressbus(struct stm32mp1_ddrctl *ctl,
434 struct stm32mp1_ddrphy *phy,
435 char *string, int argc, char *argv[])
441 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
443 if (!is_power_of_2(bufsize)) {
444 sprintf(string, "size 0x%x is not a power of 2",
448 if (get_addr(string, argc, argv, 1, &addr))
451 error = (u32)addressbus((u32 *)addr, bufsize);
453 sprintf(string, "0x%x: error for address 0x%x",
457 sprintf(string, "address 0x%x, size 0x%x",
462 static enum test_result test_memdevice(struct stm32mp1_ddrctl *ctl,
463 struct stm32mp1_ddrphy *phy,
464 char *string, int argc, char *argv[])
470 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
472 if (get_addr(string, argc, argv, 1, &addr))
474 error = (u32)memdevice((u32 *)addr, (unsigned long)bufsize);
476 sprintf(string, "0x%x: error for address 0x%x",
480 sprintf(string, "address 0x%x, size 0x%x",
485 /**********************************************************************
489 * Description: Test the Simultaneous Switching Output.
490 * Verifies succes sive reads and writes to the same memory word,
491 * holding one bit constant while toggling all other data bits
493 * => stress the data bus over an address range
495 * The CPU writes to each address in the given range.
496 * For each bit, first the CPU holds the bit at 1 while
497 * toggling the other bits, and then the CPU holds the bit at 0
498 * while toggling the other bits.
499 * After each write, the CPU reads the address that was written
500 * to verify that it contains the correct data
502 **********************************************************************/
503 static enum test_result test_sso(struct stm32mp1_ddrctl *ctl,
504 struct stm32mp1_ddrphy *phy,
505 char *string, int argc, char *argv[])
508 u32 addr, bufsize, remaining, offset;
512 if (get_bufsize(string, argc, argv, 0, &bufsize, 4))
514 if (get_addr(string, argc, argv, 1, &addr))
517 printf("running sso at 0x%x length 0x%x", addr, bufsize);
521 for (i = 0; i < 32; i++) {
523 for (j = 0; j < 6; j++) {
541 writel(data, offset);
542 error = check_addr(offset, data);
549 if (progress(offset << 7))
556 sprintf(string, "error for pattern 0x%x @0x%x",
560 sprintf(string, "no error for sso at 0x%x length 0x%x", addr, bufsize);
564 /**********************************************************************
568 * Description: Verifies r/w with pseudo-ramdom value on one region
569 * + write the region (individual access)
570 * + memcopy to the 2nd region (try to use burst)
571 * + verify the 2 regions
573 **********************************************************************/
574 static enum test_result test_random(struct stm32mp1_ddrctl *ctl,
575 struct stm32mp1_ddrphy *phy,
576 char *string, int argc, char *argv[])
578 u32 addr, offset, value = 0;
580 u32 loop = 0, nb_loop;
584 if (get_bufsize(string, argc, argv, 0, &bufsize, 8 * 1024))
586 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
588 if (get_addr(string, argc, argv, 2, &addr))
592 printf("running %d loops copy from 0x%x to 0x%x (buffer size=0x%x)\n",
593 nb_loop, addr, addr + bufsize, bufsize);
596 for (offset = 0; offset < bufsize; offset += 4)
597 writel(rand(), addr + offset);
599 memcpy((void *)addr + bufsize, (void *)addr, bufsize);
602 for (offset = 0; offset < 2 * bufsize; offset += 4) {
603 if (offset == bufsize)
606 error = check_addr(addr + offset, value);
609 if (progress(offset))
612 if (test_loop_end(&loop, nb_loop, 100))
619 "loop %d: error for address 0x%x: 0x%x expected 0x%x",
620 loop, offset, readl(offset), value);
623 sprintf(string, "no error for %d loops, size 0x%x",
628 /**********************************************************************
632 * Description: Verifies r/w while forcing switching of all data bus lines.
633 * optimised 4 iteration write/read/write/read cycles...
634 * for pattern and inversed pattern
636 **********************************************************************/
637 void do_noise(u32 addr, u32 pattern, u32 *result)
639 __asm__("push {R0-R11}");
640 __asm__("mov r0, %0" : : "r" (addr));
641 __asm__("mov r1, %0" : : "r" (pattern));
642 __asm__("mov r11, %0" : : "r" (result));
644 __asm__("mvn r2, r1");
646 __asm__("str r1, [r0]");
647 __asm__("ldr r3, [r0]");
648 __asm__("str r2, [r0]");
649 __asm__("ldr r4, [r0]");
651 __asm__("str r1, [r0]");
652 __asm__("ldr r5, [r0]");
653 __asm__("str r2, [r0]");
654 __asm__("ldr r6, [r0]");
656 __asm__("str r1, [r0]");
657 __asm__("ldr r7, [r0]");
658 __asm__("str r2, [r0]");
659 __asm__("ldr r8, [r0]");
661 __asm__("str r1, [r0]");
662 __asm__("ldr r9, [r0]");
663 __asm__("str r2, [r0]");
664 __asm__("ldr r10, [r0]");
666 __asm__("stmia R11!, {R3-R10}");
668 __asm__("pop {R0-R11}");
671 static enum test_result test_noise(struct stm32mp1_ddrctl *ctl,
672 struct stm32mp1_ddrphy *phy,
673 char *string, int argc, char *argv[])
678 enum test_result res = TEST_PASSED;
680 if (get_pattern(string, argc, argv, 0, &pattern, 0xFFFFFFFF))
682 if (get_addr(string, argc, argv, 1, &addr))
685 printf("running noise for 0x%x at 0x%x\n", pattern, addr);
687 do_noise(addr, pattern, result);
689 for (i = 0; i < 0x8;) {
690 if (check_addr((u32)&result[i++], pattern))
692 if (check_addr((u32)&result[i++], ~pattern))
699 /**********************************************************************
701 * Function: noise_burst
703 * Description: Verifies r/w while forcing switching of all data bus lines.
704 * optimised write loop witrh store multiple to use burst
705 * for pattern and inversed pattern
707 **********************************************************************/
708 void do_noise_burst(u32 addr, u32 pattern, size_t bufsize)
710 __asm__("push {R0-R9}");
711 __asm__("mov r0, %0" : : "r" (addr));
712 __asm__("mov r1, %0" : : "r" (pattern));
713 __asm__("mov r9, %0" : : "r" (bufsize));
715 __asm__("mvn r2, r1");
716 __asm__("mov r3, r1");
717 __asm__("mov r4, r2");
718 __asm__("mov r5, r1");
719 __asm__("mov r6, r2");
720 __asm__("mov r7, r1");
721 __asm__("mov r8, r2");
724 __asm__("stmia R0!, {R1-R8}");
725 __asm__("stmia R0!, {R1-R8}");
726 __asm__("stmia R0!, {R1-R8}");
727 __asm__("stmia R0!, {R1-R8}");
728 __asm__("subs r9, r9, #128");
729 __asm__("bge loop1");
730 __asm__("pop {R0-R9}");
733 /* chunk size enough to allow interruption with Ctrl-C*/
734 #define CHUNK_SIZE 0x8000000
735 static enum test_result test_noise_burst(struct stm32mp1_ddrctl *ctl,
736 struct stm32mp1_ddrphy *phy,
737 char *string, int argc, char *argv[])
739 u32 addr, offset, pattern;
740 size_t bufsize, remaining, size;
742 enum test_result res = TEST_PASSED;
744 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
746 if (get_pattern(string, argc, argv, 1, &pattern, 0xFFFFFFFF))
748 if (get_addr(string, argc, argv, 2, &addr))
751 printf("running noise burst for 0x%x at 0x%x + 0x%x",
752 pattern, addr, bufsize);
758 if (remaining < size)
760 do_noise_burst(offset, pattern, size);
763 if (progress(offset)) {
768 puts("\ncheck buffer");
769 for (i = 0; i < bufsize;) {
770 if (check_addr(addr + i, pattern))
773 if (check_addr(addr + i, ~pattern))
786 /**********************************************************************
788 * Function: pattern test
790 * Description: optimized loop for read/write pattern (array of 8 u32)
792 **********************************************************************/
793 #define PATTERN_SIZE 8
794 static enum test_result test_loop(const u32 *pattern, u32 *address,
799 enum test_result res = TEST_PASSED;
800 u32 offset, testsize, remaining;
802 offset = (u32)address;
805 testsize = bufsize > 0x1000000 ? 0x1000000 : bufsize;
807 __asm__("push {R0-R10}");
808 __asm__("mov r0, %0" : : "r" (pattern));
809 __asm__("mov r1, %0" : : "r" (offset));
810 __asm__("mov r2, %0" : : "r" (testsize));
811 __asm__("ldmia r0!, {R3-R10}");
814 __asm__("stmia r1!, {R3-R10}");
815 __asm__("stmia r1!, {R3-R10}");
816 __asm__("stmia r1!, {R3-R10}");
817 __asm__("stmia r1!, {R3-R10}");
818 __asm__("subs r2, r2, #128");
819 __asm__("bge loop2");
820 __asm__("pop {R0-R10}");
823 remaining -= testsize;
824 if (progress((u32)offset)) {
830 puts("\ncheck buffer");
831 for (i = 0; i < bufsize; i += PATTERN_SIZE * 4) {
832 for (j = 0; j < PATTERN_SIZE; j++, address++)
833 if (check_addr((u32)address, pattern[j])) {
848 const u32 pattern_div1_x16[PATTERN_SIZE] = {
849 0x0000FFFF, 0x0000FFFF, 0x0000FFFF, 0x0000FFFF,
850 0x0000FFFF, 0x0000FFFF, 0x0000FFFF, 0x0000FFFF
853 const u32 pattern_div2_x16[PATTERN_SIZE] = {
854 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000,
855 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000
858 const u32 pattern_div4_x16[PATTERN_SIZE] = {
859 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
860 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000
863 const u32 pattern_div4_x32[PATTERN_SIZE] = {
864 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
865 0x00000000, 0x00000000, 0x00000000, 0x00000000
868 const u32 pattern_mostly_zero_x16[PATTERN_SIZE] = {
869 0x00000000, 0x00000000, 0x00000000, 0x0000FFFF,
870 0x00000000, 0x00000000, 0x00000000, 0x00000000
873 const u32 pattern_mostly_zero_x32[PATTERN_SIZE] = {
874 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF,
875 0x00000000, 0x00000000, 0x00000000, 0x00000000
878 const u32 pattern_mostly_one_x16[PATTERN_SIZE] = {
879 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000FFFF,
880 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
883 const u32 pattern_mostly_one_x32[PATTERN_SIZE] = {
884 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
885 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
889 static enum test_result test_freq_pattern(struct stm32mp1_ddrctl *ctl,
890 struct stm32mp1_ddrphy *phy,
891 char *string, int argc, char *argv[])
893 const u32 * const patterns_x16[NB_PATTERN] = {
897 pattern_mostly_zero_x16,
898 pattern_mostly_one_x16,
900 const u32 * const patterns_x32[NB_PATTERN] = {
904 pattern_mostly_zero_x32,
905 pattern_mostly_one_x32
907 const char *patterns_comments[NB_PATTERN] = {
908 "switching at frequency F/1",
909 "switching at frequency F/2",
910 "switching at frequency F/4",
915 enum test_result res = TEST_PASSED, pattern_res;
917 const u32 **patterns;
920 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
923 switch (readl(&ctl->mstr) & DDRCTRL_MSTR_DATA_BUS_WIDTH_MASK) {
924 case DDRCTRL_MSTR_DATA_BUS_WIDTH_HALF:
925 case DDRCTRL_MSTR_DATA_BUS_WIDTH_QUARTER:
933 printf("running test pattern at 0x%08x length 0x%x width = %d\n",
934 STM32_DDR_BASE, bufsize, bus_width);
937 (const u32 **)(bus_width == 16 ? patterns_x16 : patterns_x32);
939 for (i = 0; i < NB_PATTERN; i++) {
940 printf("test data pattern %s:", patterns_comments[i]);
941 pattern_res = test_loop(patterns[i], (u32 *)STM32_DDR_BASE,
943 if (pattern_res != TEST_PASSED) {
953 /**********************************************************************
955 * Function: pattern test with size
957 * Description: loop for write pattern
959 **********************************************************************/
961 static enum test_result test_loop_size(const u32 *pattern, u32 size,
966 enum test_result res = TEST_PASSED;
969 for (i = 0; i < bufsize; i += size * 4) {
970 for (j = 0; j < size ; j++, p++)
978 puts("\ncheck buffer");
980 for (i = 0; i < bufsize; i += size * 4) {
981 for (j = 0; j < size; j++, p++)
982 if (check_addr((u32)p, pattern[j])) {
997 static enum test_result test_checkboard(struct stm32mp1_ddrctl *ctl,
998 struct stm32mp1_ddrphy *phy,
999 char *string, int argc, char *argv[])
1001 enum test_result res = TEST_PASSED;
1002 u32 bufsize, nb_loop, loop = 0, addr;
1005 u32 checkboard[2] = {0x55555555, 0xAAAAAAAA};
1007 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1009 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1011 if (get_addr(string, argc, argv, 2, &addr))
1014 printf("running %d loops at 0x%08x length 0x%x\n",
1015 nb_loop, addr, bufsize);
1017 for (i = 0; i < 2; i++) {
1018 res = test_loop_size(checkboard, 2, (u32 *)addr,
1022 checkboard[0] = ~checkboard[0];
1023 checkboard[1] = ~checkboard[1];
1025 if (test_loop_end(&loop, nb_loop, 1))
1028 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1029 loop, addr, bufsize);
1034 static enum test_result test_blockseq(struct stm32mp1_ddrctl *ctl,
1035 struct stm32mp1_ddrphy *phy,
1036 char *string, int argc, char *argv[])
1038 enum test_result res = TEST_PASSED;
1039 u32 bufsize, nb_loop, loop = 0, addr, value;
1042 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1044 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1046 if (get_addr(string, argc, argv, 2, &addr))
1049 printf("running %d loops at 0x%08x length 0x%x\n",
1050 nb_loop, addr, bufsize);
1052 for (i = 0; i < 256; i++) {
1053 value = i | i << 8 | i << 16 | i << 24;
1054 printf("pattern = %08x", value);
1055 res = test_loop_size(&value, 1, (u32 *)addr, bufsize);
1056 if (res != TEST_PASSED)
1059 if (test_loop_end(&loop, nb_loop, 1))
1062 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1063 loop, addr, bufsize);
1068 static enum test_result test_walkbit0(struct stm32mp1_ddrctl *ctl,
1069 struct stm32mp1_ddrphy *phy,
1070 char *string, int argc, char *argv[])
1072 enum test_result res = TEST_PASSED;
1073 u32 bufsize, nb_loop, loop = 0, addr, value;
1076 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1078 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1080 if (get_addr(string, argc, argv, 2, &addr))
1083 printf("running %d loops at 0x%08x length 0x%x\n",
1084 nb_loop, addr, bufsize);
1086 for (i = 0; i < 64; i++) {
1090 value = 1 << (63 - i);
1092 printf("pattern = %08x", value);
1093 res = test_loop_size(&value, 1, (u32 *)addr, bufsize);
1094 if (res != TEST_PASSED)
1097 if (test_loop_end(&loop, nb_loop, 1))
1100 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1101 loop, addr, bufsize);
1106 static enum test_result test_walkbit1(struct stm32mp1_ddrctl *ctl,
1107 struct stm32mp1_ddrphy *phy,
1108 char *string, int argc, char *argv[])
1110 enum test_result res = TEST_PASSED;
1111 u32 bufsize, nb_loop, loop = 0, addr, value;
1114 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1116 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1118 if (get_addr(string, argc, argv, 2, &addr))
1121 printf("running %d loops at 0x%08x length 0x%x\n",
1122 nb_loop, addr, bufsize);
1124 for (i = 0; i < 64; i++) {
1128 value = ~(1 << (63 - i));
1130 printf("pattern = %08x", value);
1131 res = test_loop_size(&value, 1, (u32 *)addr, bufsize);
1132 if (res != TEST_PASSED)
1135 if (test_loop_end(&loop, nb_loop, 1))
1138 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1139 loop, addr, bufsize);
1145 * try to catch bad bits which are dependent on the current values of
1146 * surrounding bits in either the same word32
1148 static enum test_result test_bitspread(struct stm32mp1_ddrctl *ctl,
1149 struct stm32mp1_ddrphy *phy,
1150 char *string, int argc, char *argv[])
1152 enum test_result res = TEST_PASSED;
1153 u32 bufsize, nb_loop, loop = 0, addr, bitspread[4];
1156 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1158 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1160 if (get_addr(string, argc, argv, 2, &addr))
1163 printf("running %d loops at 0x%08x length 0x%x\n",
1164 nb_loop, addr, bufsize);
1166 for (i = 1; i < 32; i++) {
1167 for (j = 0; j < i; j++) {
1169 bitspread[0] = (1 << i) | (1 << j);
1171 bitspread[0] = (1 << (63 - i)) |
1173 bitspread[1] = bitspread[0];
1174 bitspread[2] = ~bitspread[0];
1175 bitspread[3] = ~bitspread[0];
1176 printf("pattern = %08x", bitspread[0]);
1178 res = test_loop_size(bitspread, 4, (u32 *)addr,
1180 if (res != TEST_PASSED)
1184 if (test_loop_end(&loop, nb_loop, 1))
1187 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1188 loop, addr, bufsize);
1193 static enum test_result test_bitflip(struct stm32mp1_ddrctl *ctl,
1194 struct stm32mp1_ddrphy *phy,
1195 char *string, int argc, char *argv[])
1197 enum test_result res = TEST_PASSED;
1198 u32 bufsize, nb_loop, loop = 0, addr;
1203 if (get_bufsize(string, argc, argv, 0, &bufsize, 4 * 1024))
1205 if (get_nb_loop(string, argc, argv, 1, &nb_loop, 1))
1207 if (get_addr(string, argc, argv, 2, &addr))
1210 printf("running %d loops at 0x%08x length 0x%x\n",
1211 nb_loop, addr, bufsize);
1213 for (i = 0; i < 32; i++) {
1214 bitflip[0] = 1 << i;
1215 bitflip[1] = bitflip[0];
1216 bitflip[2] = ~bitflip[0];
1217 bitflip[3] = bitflip[2];
1218 printf("pattern = %08x", bitflip[0]);
1220 res = test_loop_size(bitflip, 4, (u32 *)addr, bufsize);
1221 if (res != TEST_PASSED)
1224 if (test_loop_end(&loop, nb_loop, 1))
1227 sprintf(string, "no error for %d loops at 0x%08x length 0x%x",
1228 loop, addr, bufsize);
1233 /**********************************************************************
1235 * Function: infinite read access to DDR
1237 * Description: continuous read the same pattern at the same address
1239 **********************************************************************/
1240 static enum test_result test_read(struct stm32mp1_ddrctl *ctl,
1241 struct stm32mp1_ddrphy *phy,
1242 char *string, int argc, char *argv[])
1247 int i, size = 1024 * 1024;
1248 bool random = false;
1250 if (get_addr(string, argc, argv, 0, (u32 *)&addr))
1253 if (get_pattern(string, argc, argv, 1, &data, 0xA5A5AA55))
1256 if ((u32)addr == ADDR_INVALID) {
1257 printf("running random\n");
1260 printf("running at 0x%08x with pattern=0x%08x\n",
1266 for (i = 0; i < size; i++) {
1268 addr = (u32 *)(STM32_DDR_BASE +
1269 (rand() & (STM32_DDR_SIZE - 1) & ~0x3));
1272 if (test_loop_end(&loop, 0, 1))
1276 sprintf(string, "%d loops random", loop);
1278 sprintf(string, "%d loops at 0x%x: %x", loop, (u32)addr, data);
1283 /**********************************************************************
1285 * Function: infinite write access to DDR
1287 * Description: continuous write the same pattern at the same address
1289 **********************************************************************/
1290 static enum test_result test_write(struct stm32mp1_ddrctl *ctl,
1291 struct stm32mp1_ddrphy *phy,
1292 char *string, int argc, char *argv[])
1297 int i, size = 1024 * 1024;
1298 bool random = false;
1300 if (get_addr(string, argc, argv, 0, (u32 *)&addr))
1303 if (get_pattern(string, argc, argv, 1, &data, 0xA5A5AA55))
1306 if ((u32)addr == ADDR_INVALID) {
1307 printf("running random\n");
1310 printf("running at 0x%08x with pattern 0x%08x\n",
1315 for (i = 0; i < size; i++) {
1317 addr = (u32 *)(STM32_DDR_BASE +
1318 (rand() & (STM32_DDR_SIZE - 1) & ~0x3));
1323 if (test_loop_end(&loop, 0, 1))
1327 sprintf(string, "%d loops random", loop);
1329 sprintf(string, "%d loops at 0x%x: %x", loop, (u32)addr, data);
1334 #define NB_TEST_INFINITE 2
1335 static enum test_result test_all(struct stm32mp1_ddrctl *ctl,
1336 struct stm32mp1_ddrphy *phy,
1337 char *string, int argc, char *argv[])
1339 enum test_result res = TEST_PASSED, result;
1340 int i, nb_error = 0;
1341 u32 loop = 0, nb_loop;
1343 if (get_nb_loop(string, argc, argv, 0, &nb_loop, 1))
1347 /* execute all the test except the lasts which are infinite */
1348 for (i = 1; i < test_nb - NB_TEST_INFINITE; i++) {
1349 printf("execute %d:%s\n", (int)i, test[i].name);
1350 result = test[i].fct(ctl, phy, string, 0, NULL);
1351 printf("result %d:%s = ", (int)i, test[i].name);
1352 if (result != TEST_PASSED) {
1361 printf("loop %d: %d/%d test failed\n\n\n",
1362 loop + 1, nb_error, test_nb - NB_TEST_INFINITE);
1363 if (test_loop_end(&loop, nb_loop, 1))
1366 if (res != TEST_PASSED) {
1367 sprintf(string, "loop %d: %d/%d test failed", loop, nb_error,
1368 test_nb - NB_TEST_INFINITE);
1370 sprintf(string, "loop %d: %d tests passed", loop,
1371 test_nb - NB_TEST_INFINITE);
1376 /****************************************************************
1378 ****************************************************************/
1380 const struct test_desc test[] = {
1381 {test_all, "All", "[loop]", "Execute all tests", 1 },
1382 {test_databus, "Simple DataBus", "[addr]",
1383 "Verifies each data line by walking 1 on fixed address",
1386 {databuswalk0, "DataBusWalking0", "[loop] [addr]",
1387 "Verifies each data bus signal can be driven low (32 word burst)",
1390 {databuswalk1, "DataBusWalking1", "[loop] [addr]",
1391 "Verifies each data bus signal can be driven high (32 word burst)",
1394 {test_addressbus, "AddressBus", "[size] [addr]",
1395 "Verifies each relevant bits of the address and checking for aliasing",
1398 {test_memdevice, "MemDevice", "[size] [addr]",
1399 "Test the integrity of a physical memory (test every storage bit in the region)",
1402 {test_sso, "SimultaneousSwitchingOutput", "[size] [addr] ",
1403 "Stress the data bus over an address range",
1406 {test_noise, "Noise", "[pattern] [addr]",
1407 "Verifies r/w while forcing switching of all data bus lines.",
1410 {test_noise_burst, "NoiseBurst", "[size] [pattern] [addr]",
1411 "burst transfers while forcing switching of the data bus lines",
1414 {test_random, "Random", "[size] [loop] [addr]",
1415 "Verifies r/w and memcopy(burst for pseudo random value.",
1418 {test_freq_pattern, "FrequencySelectivePattern", "[size]",
1419 "write & test patterns: Mostly Zero, Mostly One and F/n",
1422 {test_blockseq, "BlockSequential", "[size] [loop] [addr]",
1423 "test incremental pattern",
1426 {test_checkboard, "Checkerboard", "[size] [loop] [addr]",
1427 "test checker pattern",
1430 {test_bitspread, "BitSpread", "[size] [loop] [addr]",
1431 "test Bit Spread pattern",
1434 {test_bitflip, "BitFlip", "[size] [loop] [addr]",
1435 "test Bit Flip pattern",
1438 {test_walkbit0, "WalkingOnes", "[size] [loop] [addr]",
1439 "test Walking Ones pattern",
1442 {test_walkbit1, "WalkingZeroes", "[size] [loop] [addr]",
1443 "test Walking Zeroes pattern",
1446 /* need to the the 2 last one (infinite) : skipped for test all */
1447 {test_read, "infinite read", "[addr] [pattern]",
1448 "basic test : infinite read access (random: addr=0xFFFFFFFF)", 2},
1449 {test_write, "infinite write", "[addr] [pattern]",
1450 "basic test : infinite write access (random: addr=0xFFFFFFFF)", 2},
1453 const int test_nb = ARRAY_SIZE(test);