wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | #include <common.h> |
| 2 | #include <malloc.h> |
| 3 | |
Jon Loeliger | b930726 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 4 | #if defined(CONFIG_CMD_BSP) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 5 | #include <command.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 6 | #endif |
| 7 | |
| 8 | #include <pci.h> |
| 9 | #include <galileo/pci.h> |
| 10 | #include "zuma_pbb.h" |
| 11 | |
| 12 | #undef DEBUG |
| 13 | |
| 14 | #define PAT_LO 0x00010203 |
| 15 | #define PAT_HI 0x04050607 |
| 16 | |
| 17 | static PBB_DMA_REG_MAP *zuma_pbb_reg = NULL; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 18 | static char test_buf1[2048]; |
| 19 | static char test_buf2[2048]; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 20 | void zuma_init_pbb(void); |
| 21 | int zuma_mbox_init(void); |
| 22 | int zuma_test_dma(int cmd, int size); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 23 | |
| 24 | int zuma_test_dma (int cmd, int size) |
| 25 | { |
| 26 | static const char *const test_legend[] = { |
| 27 | "write", "verify", |
| 28 | "copy", "compare", |
| 29 | "write inc", "verify inc" |
| 30 | }; |
| 31 | register int i, j; |
| 32 | unsigned int p1 = ((unsigned int) test_buf1 + 0xff) & (~0xff); |
| 33 | unsigned int p2 = ((unsigned int) test_buf2 + 0xff) & (~0xff); |
| 34 | volatile unsigned int *ps = (unsigned int *) p1; |
| 35 | volatile unsigned int *pd = (unsigned int *) p2; |
| 36 | unsigned int funct, pat_lo = PAT_LO, pat_hi = PAT_HI; |
| 37 | DMA_INT_STATUS stat; |
| 38 | int ret = 0; |
| 39 | |
| 40 | if (!zuma_pbb_reg) { |
| 41 | printf ("not initted\n"); |
| 42 | return -1; |
| 43 | } |
| 44 | |
| 45 | if (cmd < 0 || cmd > 5) { |
| 46 | printf ("inv cmd %d\n", cmd); |
| 47 | return -1; |
| 48 | } |
| 49 | |
| 50 | if (cmd == 2 || cmd == 3) { |
| 51 | /* not implemented */ |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | if (size <= 0 || size > 1024) |
| 56 | size = 1024; |
| 57 | |
| 58 | size &= (~7); /* throw away bottom 3 bits */ |
| 59 | |
| 60 | p1 = ((unsigned int) test_buf1 + 0xff) & (~0xff); |
| 61 | p2 = ((unsigned int) test_buf2 + 0xff) & (~0xff); |
| 62 | |
| 63 | memset ((void *) p1, 0, size); |
| 64 | memset ((void *) p2, 0, size); |
| 65 | |
| 66 | for (i = 0; i < size / 4; i += 2) { |
| 67 | ps[i] = pat_lo; |
| 68 | ps[i + 1] = pat_hi; |
| 69 | if (cmd == 4 || cmd == 5) { |
| 70 | unsigned char *pl = (unsigned char *) &pat_lo; |
| 71 | unsigned char *ph = (unsigned char *) &pat_hi; |
| 72 | |
| 73 | for (j = 0; j < 4; j++) { |
| 74 | pl[j] += 8; |
| 75 | ph[j] += 8; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | funct = (1 << 31) | (cmd << 24) | (size); |
| 81 | |
| 82 | zuma_pbb_reg->int_mask.pci_bits.chan0 = |
| 83 | EOF_RX_FLAG | EOF_TX_FLAG | EOB_TX_FLAG; |
| 84 | |
| 85 | zuma_pbb_reg->debug_57 = PAT_LO; /* patl */ |
| 86 | zuma_pbb_reg->debug_58 = PAT_HI; /* path */ |
| 87 | |
| 88 | zuma_pbb_reg->debug_54 = cpu_to_le32 (p1); /* src 0x01b0 */ |
| 89 | zuma_pbb_reg->debug_55 = cpu_to_le32 (p2); /* dst 0x01b8 */ |
| 90 | zuma_pbb_reg->debug_56 = cpu_to_le32 (funct); /* func, 0x01c0 */ |
| 91 | |
| 92 | /* give DMA time to chew on things.. dont use DRAM or PCI */ |
| 93 | /* if you can avoid it. */ |
| 94 | do { |
| 95 | for (i = 0; i < 1000 * 10; i++); |
| 96 | } while (le32_to_cpu (zuma_pbb_reg->debug_56) & (1 << 31)); |
| 97 | |
| 98 | stat.word = zuma_pbb_reg->status.word; |
| 99 | zuma_pbb_reg->int_mask.word = 0; |
| 100 | |
| 101 | printf ("stat: %08x (%x)\n", stat.word, stat.pci_bits.chan0); |
| 102 | |
| 103 | printf ("func: %08x\n", le32_to_cpu (zuma_pbb_reg->debug_56)); |
| 104 | printf ("src @%08x: %08x %08x %08x %08x\n", p1, ps[0], ps[1], ps[2], |
| 105 | ps[3]); |
| 106 | printf ("dst @%08x: %08x %08x %08x %08x\n", p2, pd[0], pd[1], pd[2], |
| 107 | pd[3]); |
| 108 | printf ("func: %08x\n", le32_to_cpu (zuma_pbb_reg->debug_56)); |
| 109 | |
| 110 | |
| 111 | if (cmd == 0 || cmd == 4) { |
| 112 | /* this is a write */ |
| 113 | if (!(stat.pci_bits.chan0 & EOF_RX_FLAG) || /* not done */ |
| 114 | (memcmp ((void *) ps, (void *) pd, size) != 0)) { /* cmp error */ |
| 115 | for (i = 0; i < size / 4; i += 2) { |
| 116 | if ((ps[i] != pd[i]) || (ps[i + 1] != pd[i + 1])) { |
| 117 | printf ("s @%p:%08x %08x\n", &ps[i], ps[i], ps[i + 1]); |
| 118 | printf ("d @%p:%08x %08x\n", &pd[i], pd[i], pd[i + 1]); |
| 119 | } |
| 120 | } |
| 121 | ret = -1; |
| 122 | } |
| 123 | } else { |
| 124 | /* this is a verify */ |
| 125 | if (!(stat.pci_bits.chan0 & EOF_TX_FLAG) || /* not done */ |
| 126 | (stat.pci_bits.chan0 & EOB_TX_FLAG)) { /* cmp error */ |
| 127 | printf ("%08x: %08x %08x\n", |
| 128 | le32_to_cpu (zuma_pbb_reg->debug_63), |
| 129 | zuma_pbb_reg->debug_61, zuma_pbb_reg->debug_62); |
| 130 | ret = -1; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | printf ("%s cmd %d, %d bytes: %s!\n", test_legend[cmd], cmd, size, |
| 135 | (ret == 0) ? "PASSED" : "FAILED"); |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | void zuma_init_pbb (void) |
| 140 | { |
| 141 | unsigned int iobase; |
| 142 | pci_dev_t dev = |
| 143 | pci_find_device (VENDOR_ID_ZUMA, DEVICE_ID_ZUMA_PBB, 0); |
| 144 | |
| 145 | if (dev == -1) { |
| 146 | printf ("no zuma pbb\n"); |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | pci_read_config_dword (dev, PCI_BASE_ADDRESS_0, &iobase); |
| 151 | |
Wolfgang Denk | 1113cb7 | 2008-12-09 23:13:51 +0100 | [diff] [blame] | 152 | iobase &= PCI_BASE_ADDRESS_MEM_MASK; |
| 153 | |
| 154 | zuma_pbb_reg = (PBB_DMA_REG_MAP *)iobase; |
| 155 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 156 | |
| 157 | if (!zuma_pbb_reg) { |
| 158 | printf ("zuma pbb bar none! (hah hah, get it?)\n"); |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | zuma_pbb_reg->int_mask.word = 0; |
| 163 | |
| 164 | printf ("pbb @ %p v%d.%d, timestamp %08x\n", zuma_pbb_reg, |
| 165 | zuma_pbb_reg->version.pci_bits.rev_major, |
| 166 | zuma_pbb_reg->version.pci_bits.rev_minor, |
| 167 | zuma_pbb_reg->timestamp); |
| 168 | |
| 169 | } |
| 170 | |
Jon Loeliger | b930726 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 171 | #if defined(CONFIG_CMD_BSP) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 172 | |
| 173 | static int last_cmd = 4; /* write increment */ |
| 174 | static int last_size = 64; |
| 175 | |
| 176 | int |
| 177 | do_zuma_init_pbb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 178 | { |
| 179 | zuma_init_pbb (); |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | int |
| 184 | do_zuma_test_dma (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 185 | { |
| 186 | if (argc > 1) { |
| 187 | last_cmd = simple_strtoul (argv[1], NULL, 10); |
| 188 | } |
| 189 | if (argc > 2) { |
| 190 | last_size = simple_strtoul (argv[2], NULL, 10); |
| 191 | } |
| 192 | zuma_test_dma (last_cmd, last_size); |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | int |
| 197 | do_zuma_init_mbox (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 198 | { |
| 199 | zuma_mbox_init (); |
| 200 | return 0; |
| 201 | } |
| 202 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 203 | U_BOOT_CMD( |
| 204 | zinit, 1, 0, do_zuma_init_pbb, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 205 | "init zuma pbb", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 206 | "\n" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 207 | ); |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 208 | U_BOOT_CMD( |
| 209 | zdtest, 3, 1, do_zuma_test_dma, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 210 | "run dma test", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 211 | "[cmd [count]]\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 212 | " - run dma cmd (w=0,v=1,cp=2,cmp=3,wi=4,vi=5), count bytes" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 213 | ); |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 214 | U_BOOT_CMD( |
| 215 | zminit, 1, 0, do_zuma_init_mbox, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 216 | "init zuma mbox", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 217 | "\n" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 218 | ); |
| 219 | |
Jon Loeliger | 77a3185 | 2007-07-10 10:39:10 -0500 | [diff] [blame] | 220 | #endif |