xref: /aosp_15_r20/external/coreboot/src/vendorcode/cavium/include/bdk/libbdk-dram/bdk-dram-test.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 #ifndef __CB_BDK_DRAM_TEST_H__
2 #define __CB_BDK_DRAM_TEST_H__
3 
4 /***********************license start***********************************
5 * Copyright (c) 2003-2017  Cavium Inc. ([email protected]). All rights
6 * reserved.
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met:
12 *
13 *   * Redistributions of source code must retain the above copyright
14 *     notice, this list of conditions and the following disclaimer.
15 *
16 *   * Redistributions in binary form must reproduce the above
17 *     copyright notice, this list of conditions and the following
18 *     disclaimer in the documentation and/or other materials provided
19 *     with the distribution.
20 *
21 *   * Neither the name of Cavium Inc. nor the names of
22 *     its contributors may be used to endorse or promote products
23 *     derived from this software without specific prior written
24 *     permission.
25 *
26 * This Software, including technical data, may be subject to U.S. export
27 * control laws, including the U.S. Export Administration Act and its
28 * associated regulations, and may be subject to export or import
29 * regulations in other countries.
30 *
31 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
32 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
33 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
34 * TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
35 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
36 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
37 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
38 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
39 * QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK
40 * ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
41 ***********************license end**************************************/
42 
43 /**
44  * @file
45  *
46  * Functions for configuring DRAM.
47  *
48  * <hr>$Revision: 49448 $<hr>
49  *
50  * @defgroup dram DRAM related functions
51  * @{
52  */
53 
54 /**
55  * Flags to pass to DRAM tests to control behavior
56  */
57 typedef enum
58 {
59     /* Which nodes to check. If none are specified, default to all */
60     BDK_DRAM_TEST_NODE0         = 1 << BDK_NODE_0,
61     BDK_DRAM_TEST_NODE1         = 1 << BDK_NODE_1,
62     BDK_DRAM_TEST_NODE2         = 1 << BDK_NODE_2,
63     BDK_DRAM_TEST_NODE3         = 1 << BDK_NODE_3,
64     BDK_DRAM_TEST_NO_STOP_ERROR = 1 << 8,  /**< Don't stop running tests on errors, continue counting all errors */
65     BDK_DRAM_TEST_NO_PROGRESS   = 1 << 9,  /**< Don't report progress percentage during run, for batch runs */
66     BDK_DRAM_TEST_NO_STATS      = 1 << 10, /**< Don't report usage status for LMC, or CCPI with USE_CCPI */
67     BDK_DRAM_TEST_NO_BANNERS    = 1 << 11,  /**< Don't display banenrs at beginning of test */
68     BDK_DRAM_TEST_USE_CCPI      = 1 << 12, /**< Test using other node across CCPI. Use to verify CCPI. This
69                                             automatically enables CCPI usage reporting unless NO_STATS is
70                                             also specified */
71 } bdk_dram_test_flags_t;
72 
73 /**
74  * Convert a test enumeration into a string
75  *
76  * @param test   Test to convert
77  *
78  * @return String for display
79  */
80 extern const char* bdk_dram_get_test_name(int test);
81 
82 /**
83  * Perform a memory test.
84  *
85  * @param test   Test type to run
86  * @param start_address
87  *               Physical address to start at
88  * @param length Length of memory block
89  * @param flags  Flags to control memory test options. Zero defaults to testing all
90  *               node with statistics and progress output.
91  *
92  * @return Number of errors found. Zero is success. Negative means the test
93  *         did not run due to some other failure.
94  */
95 extern int
96 bdk_dram_test(int test, uint64_t start_address, uint64_t length,
97               bdk_dram_test_flags_t flags);
98 
99 /**
100  * Given a physical DRAM address, extract information about the node, LMC, DIMM,
101  * rank, bank, row, and column that was accessed.
102  *
103  * @param address Physical address to decode
104  * @param node    Node the address was for
105  * @param lmc     LMC controller the address was for
106  * @param dimm    DIMM the address was for
107  * @param prank   Physical RANK on the DIMM
108  * @param lrank   Logical RANK on the DIMM
109  * @param bank    BANK on the DIMM
110  * @param row     Row on the DIMM
111  * @param col     Column on the DIMM
112  */
113 extern void
114 bdk_dram_address_extract_info(uint64_t address, int *node, int *lmc, int *dimm,
115                               int *prank, int *lrank, int *bank, int *row, int *col);
116 
117 /**
118  * Construct a physical address given the node, LMC, DIMM, rank, bank, row, and column.
119  *
120  * @param node    Node the address was for
121  * @param lmc     LMC controller the address was for
122  * @param dimm    DIMM the address was for
123  * @param prank   Physical RANK on the DIMM
124  * @param lrank   Logical RANK on the DIMM
125  * @param bank    BANK on the DIMM
126  * @param row     Row on the DIMM
127  * @param col     Column on the DIMM
128  */
129 extern uint64_t
130 bdk_dram_address_construct_info(bdk_node_t node, int lmc, int dimm,
131                                 int prank, int lrank, int bank, int row, int col);
132 
133 /**
134  * Inject a DRAM error at a specific address in memory. The injection can either
135  * be a single bit inside the byte, or a double bit error in the ECC byte. Double
136  * bit errors may corrupt memory, causing software to crash. The corruption is
137  * written to memory and will continue to exist until the cache line is written
138  * again. After a call to this function, the BDK should report a ECC error. Double
139  * bit errors corrupt bits 0-1.
140  *
141  * @param address Physical address to corrupt. Any byte alignment is supported
142  * @param bit     Bit to corrupt in the byte (0-7), or -1 to create a double bit fault in the ECC
143  *                byte.
144  */
145 extern void bdk_dram_test_inject_error(uint64_t address, int bit);
146 
147 /* These variables count the number of ECC errors. They should only be accessed atomically */
148 /* Keep the counts per memory channel (LMC) for more detail. */
149 #define BDK_MAX_MEM_CHANS 4
150 extern int64_t __bdk_dram_ecc_single_bit_errors[BDK_MAX_MEM_CHANS];
151 /* FIXME(dhendrix): redundant declaration in original BDK */
152 //extern int64_t __bdk_dram_ecc_double_bit_errors[BDK_MAX_MEM_CHANS];
153 
154 /* These are internal support functions */
155 extern void __bdk_dram_flush_to_mem(uint64_t address);
156 extern void __bdk_dram_flush_to_mem_range(uint64_t area, uint64_t max_address);
157 extern void __bdk_dram_report_error(uint64_t address, uint64_t data, uint64_t correct, int burst, int fails);
158 extern void __bdk_dram_report_error2(uint64_t address1, uint64_t data1, uint64_t address2, uint64_t data2, int burst, int fails);
159 extern int  __bdk_dram_retry_failure(int burst, uint64_t address, uint64_t data, uint64_t expected);
160 extern int  __bdk_dram_retry_failure2(int burst, uint64_t address1, uint64_t data1, uint64_t address2, uint64_t data2);
161 
__bdk_dram_write64(uint64_t address,uint64_t data)162 static inline void __bdk_dram_write64(uint64_t address, uint64_t data)
163 {
164     volatile uint64_t *ptr = bdk_phys_to_ptr(address);
165     *ptr = data;
166 }
167 
__bdk_dram_read64(uint64_t address)168 static inline uint64_t __bdk_dram_read64(uint64_t address)
169 {
170     volatile uint64_t *ptr = bdk_phys_to_ptr(address);
171     return *ptr;
172 }
173 
174 /* This is the function prototype that all test must use. "start_address" is
175    the first byte to be tested (inclusive), "end_address" is the address right
176    after the region (exclusive). For example, if start_address equals
177    end_address, no memory will be tested */
178 typedef int (*__bdk_dram_test_t)(uint64_t start_address, uint64_t end_address, int bursts);
179 
180 /* These are the actual tests that get run. Each test is meant to be run with
181    a small range and repeated on lots of cores and large ranges. The return
182    value is the number of errors found */
183 extern int __bdk_dram_test_mem_address_bus(uint64_t start_address, uint64_t end_address, int bursts);
184 extern int __bdk_dram_test_mem_checkerboard(uint64_t start_address, uint64_t end_address, int bursts);
185 extern int __bdk_dram_test_mem_data_bus(uint64_t start_address, uint64_t end_address, int bursts);
186 extern int __bdk_dram_test_mem_leftwalk0(uint64_t start_address, uint64_t end_address, int bursts);
187 extern int __bdk_dram_test_mem_leftwalk1(uint64_t start_address, uint64_t end_address, int bursts);
188 extern int __bdk_dram_test_mem_random(uint64_t start_address, uint64_t end_address, int bursts);
189 extern int __bdk_dram_test_mem_rightwalk0(uint64_t start_address, uint64_t end_address, int bursts);
190 extern int __bdk_dram_test_mem_rightwalk1(uint64_t start_address, uint64_t end_address, int bursts);
191 extern int __bdk_dram_test_mem_rows(uint64_t start_address, uint64_t end_address, int bursts);
192 extern int __bdk_dram_test_mem_self_addr(uint64_t start_address, uint64_t end_address, int bursts);
193 extern int __bdk_dram_test_mem_solid(uint64_t start_address, uint64_t end_address, int bursts);
194 extern int __bdk_dram_test_mem_xor(uint64_t start_address, uint64_t end_address, int bursts);
195 extern int __bdk_dram_test_fast_scan(uint64_t area, uint64_t max_address, int bursts);
196 
197 /** @} */
198 
199 
200 #endif	/* !__CB_BDK_DRAM_TEST_H__ */
201