9 #define pr_fmt(fmt) "isram: " fmt
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/types.h>
14 #include <linux/slab.h>
16 #include <linux/sched.h>
44 #define IADDR2DTEST(x) \
45 ({ unsigned long __addr = (unsigned long)(x); \
46 ((__addr & (1 << 11)) << (26 - 11)) | \
48 ((__addr & (1 << 15)) << (23 - 15)) | \
49 ((__addr & (3 << 12)) << (16 - 12)) | \
55 #define ADDR2OFFSET(x) ((((unsigned long)(x)) & 0x7) * 8)
58 #define ADDR2LAST(x) ((((unsigned long)x) & 0x7) == 0x7)
80 __builtin_bfin_csync();
82 __builtin_bfin_csync();
85 __builtin_bfin_csync();
87 spin_unlock_irqrestore(&dtest_lock, flags);
107 __builtin_bfin_csync();
109 __builtin_bfin_csync();
113 __builtin_bfin_csync();
114 spin_unlock_irqrestore(&dtest_lock, flags);
119 static bool isram_check_addr(
const void *addr,
size_t n)
125 pr_err(
"copy involving %p length (%zu) too long\n", addr, n);
141 bool dest_in_l1, src_in_l1, need_data, put_data;
142 unsigned char byte, *src_byte, *dest_byte;
144 src_byte = (
unsigned char *)src;
145 dest_byte = (
unsigned char *)dest;
147 dest_in_l1 = isram_check_addr(dest, n);
148 src_in_l1 = isram_check_addr(src, n);
152 for (count = 0; count <
n; count++) {
155 data_in = isram_read(src + count);
166 byte = src_byte[
count];
171 data_out = isram_read(dest + count);
180 isram_write(dest + count,
data_out);
189 if (dest_in_l1 && !put_data)
190 isram_write(dest + count,
data_out);
196 #ifdef CONFIG_BFIN_ISRAM_SELF_TEST
198 static int test_len = 0x20000;
200 static __init void hex_dump(
unsigned char *
buf,
int len)
206 static __init int isram_read_test(
char *sdram,
void *l1inst)
211 pr_info(
"INFO: running isram_read tests\n");
214 for (i = 0; i < test_len; ++
i)
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 (data1 != data2) {
223 pr_err(
"FAIL: isram_read(%p) returned %#llx but wanted %#llx\n",
224 l1inst + i, data1, data2);
232 static __init int isram_write_test(
char *sdram,
void *l1inst)
237 pr_info(
"INFO: running isram_write tests\n");
240 memset(sdram, 0, test_len * 2);
242 for (i = 0; i < test_len; ++
i)
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 (data1 != data2) {
251 pr_err(
"FAIL: isram_write(%p, %#llx) != %#llx\n",
252 l1inst + i, data1, data2);
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");
267 _isram_memcpy_test(
char pattern,
void *sdram,
void *l1inst,
const char *smemcpy,
268 void *(*fmemcpy)(
void *,
const void *,
size_t))
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);
280 #define _isram_memcpy_test(a, b, c, d) _isram_memcpy_test(a, b, c, #d, d)
282 static __init int isram_memcpy_test(
char *sdram,
void *l1inst)
284 int i,
j, thisret, ret = 0;
287 pr_info(
"INFO: running broad isram_memcpy tests\n");
288 for (i = 0xf; i >= 0; --
i)
289 ret += _isram_memcpy_test(i, sdram, l1inst,
isram_memcpy);
292 pr_info(
"INFO: running isram_memcpy (read) tests\n");
295 for (i = 0; i < test_len; ++
i)
300 for (i = 0; i < test_len - 32; ++
i) {
301 unsigned char cmp[32];
302 for (j = 1; j <= 32; ++
j) {
303 memset(cmp, 0,
sizeof(cmp));
305 if (
memcmp(cmp, sdram + i, j)) {
306 pr_err(
"FAIL: %p:", l1inst + 1);
309 hex_dump(sdram + i, j);
311 if (++thisret > 20) {
312 pr_err(
"FAIL: skipping remaining series\n");
322 pr_info(
"INFO: running isram_memcpy (write) tests\n");
324 memset(sdram + test_len, 0, test_len);
325 dma_memcpy(l1inst, sdram + test_len, test_len);
328 for (i = 0; i < test_len - 32; ++
i) {
329 unsigned char cmp[32];
330 for (j = 1; j <= 32; ++
j) {
333 if (
memcmp(cmp, sdram + i, j)) {
334 pr_err(
"FAIL: %p:", l1inst + i);
337 hex_dump(sdram + i, j);
339 if (++thisret > 20) {
340 pr_err(
"FAIL: skipping remaining series\n");
352 static __init int isram_test_init(
void)
366 pr_warning(
"SKIP: could not allocate L1 inst\n");
369 pr_info(
"INFO: testing %#x bytes (%p - %p)\n",
370 test_len, l1inst, l1inst + test_len);
375 pr_warning(
"SKIP: could not allocate sdram\n");
381 pr_info(
"INFO: running initial dma_memcpy checks %p\n", sdram);
382 if (_isram_memcpy_test(0xa, sdram, l1inst,
dma_memcpy))
384 if (_isram_memcpy_test(0x5, sdram, l1inst,
dma_memcpy))
388 ret += isram_read_test(sdram, l1inst);
389 ret += isram_write_test(sdram, l1inst);
390 ret += isram_memcpy_test(sdram, l1inst);
399 pr_info(
"PASS: all tests worked !\n");
404 static __exit void isram_test_exit(
void)