zuma_pbb.c 5.1 KB

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