From 7d48ac5c7dfb52fc470bbad1013b4d460bc6a1e0 Mon Sep 17 00:00:00 2001 From: David Hendricks Date: Fri, 9 Mar 2018 14:30:38 -0800 Subject: soc/cavium: Integrate BDK files into coreboot * Make it compile. * Fix whitespace errors. * Fix printf formats. * Add missing headers includes * Guard headers with ifdefs Compile DRAM init code in romstage. Compile QLM, PCIe, RNG, PHY, GPIO, MDIO init code in ramstage. Change-Id: I0a93219a14bfb6ebe41103a825d5032b11e7f2c6 Signed-off-by: David Hendricks Reviewed-on: https://review.coreboot.org/25089 Reviewed-by: Philipp Deppenwiese Tested-by: build bot (Jenkins) --- .../cavium/bdk/libbdk-dram/bdk-dram-test.c | 188 ++++++++++----------- 1 file changed, 91 insertions(+), 97 deletions(-) (limited to 'src/vendorcode/cavium/bdk/libbdk-dram/bdk-dram-test.c') diff --git a/src/vendorcode/cavium/bdk/libbdk-dram/bdk-dram-test.c b/src/vendorcode/cavium/bdk/libbdk-dram/bdk-dram-test.c index 53137502fc..4f54b69516 100644 --- a/src/vendorcode/cavium/bdk/libbdk-dram/bdk-dram-test.c +++ b/src/vendorcode/cavium/bdk/libbdk-dram/bdk-dram-test.c @@ -40,6 +40,14 @@ #include "libbdk-arch/bdk-csrs-gti.h" #include "libbdk-arch/bdk-csrs-ocx.h" +#include /* for printf --> printk */ +#include +#include +#include +#include +#include +#include + /* This code is an optional part of the BDK. It is only linked in if BDK_REQUIRE() needs it */ BDK_REQUIRE_DEFINE(DRAM_TEST); @@ -170,7 +178,7 @@ static void dram_test_thread(int arg, void *arg1) start_address = bdk_numa_get_address(test_node, start_address); end_address = bdk_numa_get_address(test_node, end_address); /* Test the region */ - BDK_TRACE(DRAM_TEST, " Node %d, core %d, Testing [0x%011lx:0x%011lx]\n", + BDK_TRACE(DRAM_TEST, " Node %d, core %d, Testing [0x%011llx:0x%011llx]\n", bdk_numa_local(), bdk_get_core_num() & 127, start_address, end_address - 1); test_info->test_func(start_address, end_address, bursts); @@ -197,7 +205,7 @@ static int __bdk_dram_run_test(const dram_test_info_t *test_info, uint64_t start { /* Figure out the addess of the byte one off the top of memory */ uint64_t max_address = bdk_dram_get_size_mbytes(bdk_numa_local()); - BDK_TRACE(DRAM_TEST, "DRAM available per node: %lu MB\n", max_address); + BDK_TRACE(DRAM_TEST, "DRAM available per node: %llu MB\n", max_address); max_address <<= 20; /* Make sure we have enough */ @@ -218,13 +226,13 @@ static int __bdk_dram_run_test(const dram_test_info_t *test_info, uint64_t start if (max_address > (1ull << 43)) /* 43 bits in CN9XXX */ max_address = 1ull << 43; } - BDK_TRACE(DRAM_TEST, "DRAM max address: 0x%011lx\n", max_address-1); + BDK_TRACE(DRAM_TEST, "DRAM max address: 0x%011llx\n", max_address-1); /* Make sure the start address is lower than the top of memory */ if (start_address >= max_address) { - bdk_error("Start address is larger than the amount of memory: 0x%011lx versus 0x%011lx\n", - start_address, max_address); + bdk_error("Start address is larger than the amount of memory: 0x%011llx versus 0x%011llx\n", + start_address, max_address); return -1; } if (length == (uint64_t)-1) @@ -260,8 +268,8 @@ static int __bdk_dram_run_test(const dram_test_info_t *test_info, uint64_t start } } if (!(flags & BDK_DRAM_TEST_NO_BANNERS)) - printf("Starting Test \"%s\" for [0x%011lx:0x%011lx] using %d core(s)\n", - test_info->name, start_address, end_address - 1, total_cores_all_nodes); + printf("Starting Test \"%s\" for [0x%011llx:0x%011llx] using %d core(s)\n", + test_info->name, start_address, end_address - 1, total_cores_all_nodes); /* Remember the LMC perf counters for stats after the test */ uint64_t start_dram_dclk[BDK_NUMA_MAX_NODES][4]; @@ -332,15 +340,15 @@ static int __bdk_dram_run_test(const dram_test_info_t *test_info, uint64_t start /* Poke the watchdog */ BDK_CSR_WRITE(bdk_numa_local(), BDK_GTI_CWD_POKEX(0), 0); - /* disable progress output when batch mode is ON */ + /* disable progress output when batch mode is ON */ if (!(flags & BDK_DRAM_TEST_NO_PROGRESS)) { /* Report progress percentage */ int percent_x10 = (work_address - start_address) * 1000 / (end_address - start_address); - printf(" %3d.%d%% complete, testing [0x%011lx:0x%011lx]\r", + printf(" %3d.%d%% complete, testing [0x%011llx:0x%011llx]\r", percent_x10 / 10, percent_x10 % 10, work_address, work_address + size - 1); fflush(stdout); - } + } work_address += size; @@ -357,17 +365,8 @@ static int __bdk_dram_run_test(const dram_test_info_t *test_info, uint64_t start { if (per_node >= max_cores) break; - int run_node = (flags & BDK_DRAM_TEST_USE_CCPI) ? node ^ 1 : node; BDK_TRACE(DRAM_TEST, "Starting thread %d on node %d for memory test\n", per_node, node); - if (bdk_thread_create(run_node, 0, dram_test_thread, per_node, (void *)test_info, 0)) - { - bdk_error("Failed to create thread %d for memory test on node %d\n", per_node, node); - } - else - { - per_node++; - total_count++; - } + dram_test_thread(per_node, (void *)test_info); } } } @@ -384,7 +383,6 @@ static int __bdk_dram_run_test(const dram_test_info_t *test_info, uint64_t start uint64_t period = bdk_clock_get_rate(bdk_numa_local(), BDK_CLOCK_TIME) * TIMEOUT_SECS; // FIXME? uint64_t timeout = bdk_clock_get_count(BDK_CLOCK_TIME) + period; do { - bdk_thread_yield(); cur_count = bdk_atomic_get64(&dram_test_thread_done); cur_time = bdk_clock_get_count(BDK_CLOCK_TIME); if (cur_time >= timeout) { @@ -430,7 +428,7 @@ static int __bdk_dram_run_test(const dram_test_info_t *test_info, uint64_t start if (!(flags & BDK_DRAM_TEST_NO_PROGRESS)) { /* Report progress percentage as complete */ - printf(" %3d.%d%% complete, testing [0x%011lx:0x%011lx]\n", + printf(" %3d.%d%% complete, testing [0x%011llx:0x%011llx]\n", 100, 0, start_address, end_address - 1); fflush(stdout); } @@ -450,7 +448,7 @@ static int __bdk_dram_run_test(const dram_test_info_t *test_info, uint64_t start if (dclk == 0) dclk = 1; uint64_t percent_x10 = ops * 1000 / dclk; - printf(" Node %d, LMC%d: ops %lu, cycles %lu, used %lu.%lu%%\n", + printf(" Node %d, LMC%d: ops %llu, cycles %llu, used %llu.%llu%%\n", node, i, ops, dclk, percent_x10 / 10, percent_x10 % 10); } } @@ -471,7 +469,7 @@ static int __bdk_dram_run_test(const dram_test_info_t *test_info, uint64_t start if (total == 0) continue; uint64_t percent_x10 = busy * 1000 / total; - printf(" Node %d, CCPI%d: busy %lu, total %lu, used %lu.%lu%%\n", + printf(" Node %d, CCPI%d: busy %llu, total %llu, used %llu.%llu%%\n", node, link, busy, total, percent_x10 / 10, percent_x10 % 10); } } @@ -543,11 +541,13 @@ int bdk_dram_test(int test, uint64_t start_address, uint64_t length, bdk_dram_te /* Clear ECC error counters before starting the test */ for (int chan = 0; chan < BDK_MAX_MEM_CHANS; chan++) { - bdk_atomic_set64(&__bdk_dram_ecc_single_bit_errors[chan], 0); - bdk_atomic_set64(&__bdk_dram_ecc_double_bit_errors[chan], 0); + bdk_atomic_set64(&__bdk_dram_ecc_single_bit_errors[chan], 0); + bdk_atomic_set64(&__bdk_dram_ecc_double_bit_errors[chan], 0); } /* Make sure at least one core from each node is running */ + /* FIXME(dhendrix): we only care about core0 on node0 for now */ +#if 0 for (bdk_node_t node = BDK_NODE_0; node < BDK_NUMA_MAX_NODES; node++) { if (flags & (1<>= 8; - if (bits) { - if (byte != 8) { - byte = 9; // means more than 1 byte-lane was present + if (bits) { + if (byte != 8) { + byte = 9; // means more than 1 byte-lane was present print_bits = orig_xor; // print the full original - break; // quit now - } else { - byte = i; // keep checking + break; // quit now + } else { + byte = i; // keep checking print_bits = bits; - } - } + } + } } - + bdk_dram_address_extract_info(address, &node, &lmc, &dimm, &prank, &lrank, &bank, &row, &col); snprintf(buffer, len, "N%d.LMC%d: CMP byte %d xor 0x%02lx (DIMM%d,Rank%d/%d,Bank%02d,Row 0x%05x,Col 0x%04x)[0x%011lx]", - node, lmc, byte, print_bits, dimm, prank, lrank, bank, row, col, address); + node, lmc, byte, print_bits, dimm, prank, lrank, bank, row, col, address); } /** @@ -671,15 +665,15 @@ void __bdk_dram_report_error(uint64_t address, uint64_t data, uint64_t correct, if (errors < MAX_ERRORS_TO_REPORT) { - if (fails < 0) { - snprintf(failbuf, sizeof(failbuf), " "); - } else { + if (fails < 0) { + snprintf(failbuf, sizeof(failbuf), " "); + } else { int percent_x10 = fails * 1000 / RETRY_LIMIT; - snprintf(failbuf, sizeof(failbuf), ", retries failed %3d.%d%%", + snprintf(failbuf, sizeof(failbuf), ", retries failed %3d.%d%%", percent_x10 / 10, percent_x10 % 10); - } + } - __bdk_dram_report_address_decode_new(address, xor, buffer, sizeof(buffer)); + __bdk_dram_report_address_decode_new(address, xor, buffer, sizeof(buffer)); bdk_error("%s%s\n", buffer, failbuf); if (errors == MAX_ERRORS_TO_REPORT-1) @@ -702,26 +696,26 @@ void __bdk_dram_report_error(uint64_t address, uint64_t data, uint64_t correct, * @return Zero if a message was logged, non-zero if the error limit has been reached */ void __bdk_dram_report_error2(uint64_t address1, uint64_t data1, uint64_t address2, uint64_t data2, - int burst, int fails) + int burst, int fails) { int64_t errors = bdk_atomic_fetch_and_add64(&dram_test_thread_errors, 1); if (errors < MAX_ERRORS_TO_REPORT) { - char buffer1[80], buffer2[80]; - char failbuf[32]; - - if (fails < 0) { - snprintf(failbuf, sizeof(failbuf), " "); - } else { - snprintf(failbuf, sizeof(failbuf), ", retried %d failed %d", RETRY_LIMIT, fails); - } - __bdk_dram_report_address_decode(address1, buffer1, sizeof(buffer1)); - __bdk_dram_report_address_decode(address2, buffer2, sizeof(buffer2)); - - bdk_error("compare: data1: 0x%016lx, xor: 0x%016lx%s\n" - " %s\n %s\n", - data1, data1 ^ data2, failbuf, - buffer1, buffer2); + char buffer1[80], buffer2[80]; + char failbuf[32]; + + if (fails < 0) { + snprintf(failbuf, sizeof(failbuf), " "); + } else { + snprintf(failbuf, sizeof(failbuf), ", retried %d failed %d", RETRY_LIMIT, fails); + } + __bdk_dram_report_address_decode(address1, buffer1, sizeof(buffer1)); + __bdk_dram_report_address_decode(address2, buffer2, sizeof(buffer2)); + + bdk_error("compare: data1: 0x%016llx, xor: 0x%016llx%s\n" + " %s\n %s\n", + data1, data1 ^ data2, failbuf, + buffer1, buffer2); if (errors == MAX_ERRORS_TO_REPORT-1) bdk_error("No further DRAM errors will be reported\n"); @@ -741,23 +735,23 @@ int __bdk_dram_retry_failure(int burst, uint64_t address, uint64_t data, uint64_ // bypass the retries if we are already over the limit... if (bdk_atomic_get64(&dram_test_thread_errors) < MAX_ERRORS_TO_REPORT) { - /* Try re-reading the memory location. A transient error may fail - * on one read and work on another. Keep on retrying even when a - * read succeeds. - */ - for (int i = 0; i < RETRY_LIMIT; i++) { + /* Try re-reading the memory location. A transient error may fail + * on one read and work on another. Keep on retrying even when a + * read succeeds. + */ + for (int i = 0; i < RETRY_LIMIT; i++) { - __bdk_dram_flush_to_mem(address); - BDK_DCACHE_INVALIDATE; + __bdk_dram_flush_to_mem(address); + BDK_DCACHE_INVALIDATE; - uint64_t new = __bdk_dram_read64(address); + uint64_t new = __bdk_dram_read64(address); - if (new != expected) { - refail++; - } - } + if (new != expected) { + refail++; + } + } } else - refail = -1; + refail = -1; // this will increment the errors always, but maybe not print... __bdk_dram_report_error(address, data, expected, burst, refail); @@ -779,20 +773,20 @@ int __bdk_dram_retry_failure2(int burst, uint64_t address1, uint64_t data1, uint // bypass the retries if we are already over the limit... if (bdk_atomic_get64(&dram_test_thread_errors) < MAX_ERRORS_TO_REPORT) { - for (int i = 0; i < RETRY_LIMIT; i++) { - __bdk_dram_flush_to_mem(address1); - __bdk_dram_flush_to_mem(address2); - BDK_DCACHE_INVALIDATE; + for (int i = 0; i < RETRY_LIMIT; i++) { + __bdk_dram_flush_to_mem(address1); + __bdk_dram_flush_to_mem(address2); + BDK_DCACHE_INVALIDATE; - uint64_t d1 = __bdk_dram_read64(address1); - uint64_t d2 = __bdk_dram_read64(address2); + uint64_t d1 = __bdk_dram_read64(address1); + uint64_t d2 = __bdk_dram_read64(address2); - if (d1 != d2) { - refail++; - } - } + if (d1 != d2) { + refail++; + } + } } else - refail = -1; + refail = -1; // this will increment the errors always, but maybe not print... __bdk_dram_report_error2(address1, data1, address2, data2, burst, refail); @@ -854,7 +848,7 @@ void bdk_dram_test_inject_error(uint64_t address, int bit) BDK_CSR_WRITE(node, BDK_LMCX_CHAR_MASK2(lmc), 0); /* Read back the data, which should now cause an error */ - printf("Loading the injected error address 0x%lx, node=%d, lmc=%d, dimm=%d, rank=%d/%d, bank=%d, row=%d, col=%d\n", + printf("Loading the injected error address 0x%llx, node=%d, lmc=%d, dimm=%d, rank=%d/%d, bank=%d, row=%d, col=%d\n", address, node, lmc, dimm, prank, lrank, bank, row, col); __bdk_dram_read64(aligned_address); } -- cgit v1.2.3