From: Jean THOMAS Date: Fri, 19 Jun 2020 13:51:10 +0000 (+0200) Subject: Update memtest code in libgram X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=35474016eb6aa7974c131d87f78430657d552e3d;p=gram.git Update memtest code in libgram --- diff --git a/libgram/include/gram.h b/libgram/include/gram.h index 438c68c..31c7796 100644 --- a/libgram/include/gram.h +++ b/libgram/include/gram.h @@ -9,6 +9,11 @@ enum GramError { GRAM_ERR_MEMTEST, }; +enum GramWidth { + GRAM_8B, + GRAM_32B, +} + struct gramCoreRegs; struct gramPHYRegs; struct gramCtx { diff --git a/libgram/src/memtest.c b/libgram/src/memtest.c index c5e0bee..8dd28c2 100644 --- a/libgram/src/memtest.c +++ b/libgram/src/memtest.c @@ -1,5 +1,45 @@ #include -int gram_memtest(struct gramCtx *ctx) { +static int memtest8(struct gramCtx *ctx, size_t length) { + volatile uint8_t *ram = (volatile uint8_t*)ctx->ddr_base; + size_t i; + + for (i = 0; i < length; i++) { + ram[i] = 0xDE; + } + + for (i = 0; i < length; i++) { + if (ram[i] != 0xDE) { + return GRAM_ERR_MEMTEST; + } + } + + return GRAM_ERR_NONE; +} + +static int memtest32(struct gramCtx *ctx, size_t length) { + volatile uint32_t *ram = (volatile uint32_t*)ctx->ddr_base; + size_t i; + + for (i = 0; i < length; i++) { + ram[i] = 0xFEEDFACE; + } + + for (i = 0; i < length; i++) { + if (ram[i] != 0xFEEDFACE) { + return GRAM_ERR_MEMTEST; + } + } + return GRAM_ERR_NONE; } + +int gram_memtest(struct gramCtx *ctx, size_t length, enum GramWidth width) { + if (width == GRAM_8B) { + return memtest8(ctx, length); + } else if (width == GRAM_32B) { + return memtest32(ctx, length); + } + + return GRAM_ERR_UNDOCUMENTED; +}