1 /***********************license start***********************************
2 * Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * * Neither the name of Cavium Inc. nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
21 * permission.
22 *
23 * This Software, including technical data, may be subject to U.S. export
24 * control laws, including the U.S. Export Administration Act and its
25 * associated regulations, and may be subject to export or import
26 * regulations in other countries.
27 *
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
31 * TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
32 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
33 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
34 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
35 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
36 * QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
37 * ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
39 #include "bdk.h"
40 #include <libbdk-hal/bdk-utils.h>
41
42 /* Used for all memory reads/writes related to the test */
43 #define READ64(address) __bdk_dram_read64(address)
44 #define WRITE64(address, data) __bdk_dram_write64(address, data)
45
46 /**
47 * Fast scan test. This test is meant to find gross errors caused by read/write
48 * level failing on a single rank or dimm. The idea is to scan through all of
49 * memory in large steps. The large steps hit each rank multiple times, but not
50 * every byte. If the whole rank has errors, his should find it quickly. This test
51 * is suitable for an alive test during early boot.
52 *
53 * @param area Starting physical address
54 * @param max_address
55 * Ending physical address, exclusive
56 * @param bursts Burst to run
57 *
58 * @return Number of errors
59 */
__bdk_dram_test_fast_scan(uint64_t area,uint64_t max_address,int bursts)60 int __bdk_dram_test_fast_scan(uint64_t area, uint64_t max_address, int bursts)
61 {
62 int failures = 0;
63 const uint64_t step = 0x10008; /* The 8 is so we walk through cache lines too */
64 const uint64_t pattern1 = 0xaaaaaaaaaaaaaaaa;
65 const uint64_t pattern2 = 0x5555555555555555;
66
67 /* Walk through the region incrementing our offset by STEP */
68 uint64_t a = area;
69 while (a + 16 <= max_address)
70 {
71 WRITE64(a, pattern1);
72 WRITE64(a+8, pattern2);
73 __bdk_dram_flush_to_mem_range(a, a + 16);
74 a += step;
75 }
76
77 /* Read back, checking the writes */
78 a = area;
79 while (a + 16 <= max_address)
80 {
81 /* Prefetch 3 ahead for better performance */
82 uint64_t pre = a + step * 2;
83 if (pre + 16 < max_address)
84 BDK_PREFETCH(pre, 0);
85 /* Check pattern 1 */
86 uint64_t data1 = READ64(a);
87 if (bdk_unlikely(data1 != pattern1))
88 {
89 failures++;
90 __bdk_dram_report_error(a, data1, pattern1, 0, -1);
91 }
92 /* Check pattern 2 */
93 uint64_t data2 = READ64(a+8);
94 if (bdk_unlikely(data2 != pattern2))
95 {
96 failures++;
97 __bdk_dram_report_error(a+8, data2, pattern2, 0, -1);
98 }
99 a += step;
100 }
101
102 return failures;
103 }
104
105