Blackfin: isram: clean up ITEST_COMMAND macro and improve the selftests

The IADDR2DTEST() macro had some duplicated logic with bit 11 and some
incorrect comments, so scrub all of that.

In order to verify these aren't a problem (and won't be in the future),
extend the self tests to operate on as much L1 SRAM as possible.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

+51 -43
+51 -43
arch/blackfin/mm/isram-driver.c
··· 43 /* Takes a void pointer */ 44 #define IADDR2DTEST(x) \ 45 ({ unsigned long __addr = (unsigned long)(x); \ 46 - (__addr & 0x47F8) | /* address bits 14 & 10:3 */ \ 47 - (__addr & 0x8000) << 23 | /* Bank A/B */ \ 48 - (__addr & 0x0800) << 15 | /* address bit 11 */ \ 49 - (__addr & 0x3000) << 4 | /* address bits 13:12 */ \ 50 - (__addr & 0x8000) << 8 | /* address bit 15 */ \ 51 - (0x1000000) | /* instruction access = 1 */ \ 52 - (0x4); /* data array = 1 */ \ 53 }) 54 55 /* Takes a pointer, and returns the offset (in bits) which things should be shifted */ ··· 195 196 #ifdef CONFIG_BFIN_ISRAM_SELF_TEST 197 198 - #define TEST_LEN 0x100 199 200 static __init void hex_dump(unsigned char *buf, int len) 201 { ··· 211 pr_info("INFO: running isram_read tests\n"); 212 213 /* setup some different data to play with */ 214 - for (i = 0; i < TEST_LEN; ++i) 215 - sdram[i] = i; 216 - dma_memcpy(l1inst, sdram, TEST_LEN); 217 218 /* make sure we can read the L1 inst */ 219 - for (i = 0; i < TEST_LEN; i += sizeof(uint64_t)) { 220 data1 = isram_read(l1inst + i); 221 memcpy(&data2, sdram + i, sizeof(data2)); 222 - if (memcmp(&data1, &data2, sizeof(uint64_t))) { 223 pr_err("FAIL: isram_read(%p) returned %#llx but wanted %#llx\n", 224 l1inst + i, data1, data2); 225 ++ret; ··· 237 pr_info("INFO: running isram_write tests\n"); 238 239 /* setup some different data to play with */ 240 - memset(sdram, 0, TEST_LEN * 2); 241 - dma_memcpy(l1inst, sdram, TEST_LEN); 242 - for (i = 0; i < TEST_LEN; ++i) 243 - sdram[i] = i; 244 245 /* make sure we can write the L1 inst */ 246 - for (i = 0; i < TEST_LEN; i += sizeof(uint64_t)) { 247 memcpy(&data1, sdram + i, sizeof(data1)); 248 isram_write(l1inst + i, data1); 249 data2 = isram_read(l1inst + i); 250 - if (memcmp(&data1, &data2, sizeof(uint64_t))) { 251 pr_err("FAIL: isram_write(%p, %#llx) != %#llx\n", 252 l1inst + i, data1, data2); 253 ++ret; 254 } 255 } 256 257 - dma_memcpy(sdram + TEST_LEN, l1inst, TEST_LEN); 258 - if (memcmp(sdram, sdram + TEST_LEN, TEST_LEN)) { 259 pr_err("FAIL: isram_write() did not work properly\n"); 260 ++ret; 261 } ··· 267 _isram_memcpy_test(char pattern, void *sdram, void *l1inst, const char *smemcpy, 268 void *(*fmemcpy)(void *, const void *, size_t)) 269 { 270 - memset(sdram, pattern, TEST_LEN); 271 - fmemcpy(l1inst, sdram, TEST_LEN); 272 - fmemcpy(sdram + TEST_LEN, l1inst, TEST_LEN); 273 - if (memcmp(sdram, sdram + TEST_LEN, TEST_LEN)) { 274 pr_err("FAIL: %s(%p <=> %p, %#x) failed (data is %#x)\n", 275 - smemcpy, l1inst, sdram, TEST_LEN, pattern); 276 return 1; 277 } 278 return 0; ··· 291 /* check read of small, unaligned, and hardware 64bit limits */ 292 pr_info("INFO: running isram_memcpy (read) tests\n"); 293 294 - for (i = 0; i < TEST_LEN; ++i) 295 - sdram[i] = i; 296 - dma_memcpy(l1inst, sdram, TEST_LEN); 297 298 thisret = 0; 299 - for (i = 0; i < TEST_LEN - 32; ++i) { 300 unsigned char cmp[32]; 301 for (j = 1; j <= 32; ++j) { 302 memset(cmp, 0, sizeof(cmp)); ··· 310 pr_cont("\n"); 311 if (++thisret > 20) { 312 pr_err("FAIL: skipping remaining series\n"); 313 - i = TEST_LEN; 314 break; 315 } 316 } ··· 321 /* check write of small, unaligned, and hardware 64bit limits */ 322 pr_info("INFO: running isram_memcpy (write) tests\n"); 323 324 - memset(sdram + TEST_LEN, 0, TEST_LEN); 325 - dma_memcpy(l1inst, sdram + TEST_LEN, TEST_LEN); 326 327 thisret = 0; 328 - for (i = 0; i < TEST_LEN - 32; ++i) { 329 unsigned char cmp[32]; 330 for (j = 1; j <= 32; ++j) { 331 isram_memcpy(l1inst + i, sdram + i, j); ··· 338 pr_cont("\n"); 339 if (++thisret > 20) { 340 pr_err("FAIL: skipping remaining series\n"); 341 - i = TEST_LEN; 342 break; 343 } 344 } ··· 355 char *sdram; 356 void *l1inst; 357 358 - sdram = kmalloc(TEST_LEN * 2, GFP_KERNEL); 359 - if (!sdram) { 360 - pr_warning("SKIP: could not allocate sdram\n"); 361 return 0; 362 } 363 364 - l1inst = l1_inst_sram_alloc(TEST_LEN); 365 - if (!l1inst) { 366 - kfree(sdram); 367 - pr_warning("SKIP: could not allocate L1 inst\n"); 368 return 0; 369 } 370 371 /* sanity check initial L1 inst state */ 372 ret = 1; 373 - pr_info("INFO: running initial dma_memcpy checks\n"); 374 if (_isram_memcpy_test(0xa, sdram, l1inst, dma_memcpy)) 375 goto abort; 376 if (_isram_memcpy_test(0x5, sdram, l1inst, dma_memcpy))
··· 43 /* Takes a void pointer */ 44 #define IADDR2DTEST(x) \ 45 ({ unsigned long __addr = (unsigned long)(x); \ 46 + ((__addr & (1 << 11)) << (26 - 11)) | /* addr bit 11 (Way0/Way1) */ \ 47 + (1 << 24) | /* instruction access = 1 */ \ 48 + ((__addr & (1 << 15)) << (23 - 15)) | /* addr bit 15 (Data Bank) */ \ 49 + ((__addr & (3 << 12)) << (16 - 12)) | /* addr bits 13:12 (Subbank) */ \ 50 + (__addr & 0x47F8) | /* addr bits 14 & 10:3 */ \ 51 + (1 << 2); /* data array = 1 */ \ 52 }) 53 54 /* Takes a pointer, and returns the offset (in bits) which things should be shifted */ ··· 196 197 #ifdef CONFIG_BFIN_ISRAM_SELF_TEST 198 199 + static int test_len = 0x20000; 200 201 static __init void hex_dump(unsigned char *buf, int len) 202 { ··· 212 pr_info("INFO: running isram_read tests\n"); 213 214 /* setup some different data to play with */ 215 + for (i = 0; i < test_len; ++i) 216 + sdram[i] = i % 255; 217 + dma_memcpy(l1inst, sdram, test_len); 218 219 /* make sure we can read the L1 inst */ 220 + for (i = 0; i < test_len; i += sizeof(uint64_t)) { 221 data1 = isram_read(l1inst + i); 222 memcpy(&data2, sdram + i, sizeof(data2)); 223 + if (data1 != data2) { 224 pr_err("FAIL: isram_read(%p) returned %#llx but wanted %#llx\n", 225 l1inst + i, data1, data2); 226 ++ret; ··· 238 pr_info("INFO: running isram_write tests\n"); 239 240 /* setup some different data to play with */ 241 + memset(sdram, 0, test_len * 2); 242 + dma_memcpy(l1inst, sdram, test_len); 243 + for (i = 0; i < test_len; ++i) 244 + sdram[i] = i % 255; 245 246 /* make sure we can write the L1 inst */ 247 + for (i = 0; i < test_len; i += sizeof(uint64_t)) { 248 memcpy(&data1, sdram + i, sizeof(data1)); 249 isram_write(l1inst + i, data1); 250 data2 = isram_read(l1inst + i); 251 + if (data1 != data2) { 252 pr_err("FAIL: isram_write(%p, %#llx) != %#llx\n", 253 l1inst + i, data1, data2); 254 ++ret; 255 } 256 } 257 258 + dma_memcpy(sdram + test_len, l1inst, test_len); 259 + if (memcmp(sdram, sdram + test_len, test_len)) { 260 pr_err("FAIL: isram_write() did not work properly\n"); 261 ++ret; 262 } ··· 268 _isram_memcpy_test(char pattern, void *sdram, void *l1inst, const char *smemcpy, 269 void *(*fmemcpy)(void *, const void *, size_t)) 270 { 271 + memset(sdram, pattern, test_len); 272 + fmemcpy(l1inst, sdram, test_len); 273 + fmemcpy(sdram + test_len, l1inst, test_len); 274 + if (memcmp(sdram, sdram + test_len, test_len)) { 275 pr_err("FAIL: %s(%p <=> %p, %#x) failed (data is %#x)\n", 276 + smemcpy, l1inst, sdram, test_len, pattern); 277 return 1; 278 } 279 return 0; ··· 292 /* check read of small, unaligned, and hardware 64bit limits */ 293 pr_info("INFO: running isram_memcpy (read) tests\n"); 294 295 + /* setup some different data to play with */ 296 + for (i = 0; i < test_len; ++i) 297 + sdram[i] = i % 255; 298 + dma_memcpy(l1inst, sdram, test_len); 299 300 thisret = 0; 301 + for (i = 0; i < test_len - 32; ++i) { 302 unsigned char cmp[32]; 303 for (j = 1; j <= 32; ++j) { 304 memset(cmp, 0, sizeof(cmp)); ··· 310 pr_cont("\n"); 311 if (++thisret > 20) { 312 pr_err("FAIL: skipping remaining series\n"); 313 + i = test_len; 314 break; 315 } 316 } ··· 321 /* check write of small, unaligned, and hardware 64bit limits */ 322 pr_info("INFO: running isram_memcpy (write) tests\n"); 323 324 + memset(sdram + test_len, 0, test_len); 325 + dma_memcpy(l1inst, sdram + test_len, test_len); 326 327 thisret = 0; 328 + for (i = 0; i < test_len - 32; ++i) { 329 unsigned char cmp[32]; 330 for (j = 1; j <= 32; ++j) { 331 isram_memcpy(l1inst + i, sdram + i, j); ··· 338 pr_cont("\n"); 339 if (++thisret > 20) { 340 pr_err("FAIL: skipping remaining series\n"); 341 + i = test_len; 342 break; 343 } 344 } ··· 355 char *sdram; 356 void *l1inst; 357 358 + /* Try to test as much of L1SRAM as possible */ 359 + while (test_len) { 360 + test_len >>= 1; 361 + l1inst = l1_inst_sram_alloc(test_len); 362 + if (l1inst) 363 + break; 364 + } 365 + if (!l1inst) { 366 + pr_warning("SKIP: could not allocate L1 inst\n"); 367 return 0; 368 } 369 + pr_info("INFO: testing %#x bytes (%p - %p)\n", 370 + test_len, l1inst, l1inst + test_len); 371 372 + sdram = kmalloc(test_len * 2, GFP_KERNEL); 373 + if (!sdram) { 374 + sram_free(l1inst); 375 + pr_warning("SKIP: could not allocate sdram\n"); 376 return 0; 377 } 378 379 /* sanity check initial L1 inst state */ 380 ret = 1; 381 + pr_info("INFO: running initial dma_memcpy checks %p\n", sdram); 382 if (_isram_memcpy_test(0xa, sdram, l1inst, dma_memcpy)) 383 goto abort; 384 if (_isram_memcpy_test(0x5, sdram, l1inst, dma_memcpy))