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