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