xilinx.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * (C) Copyright 2002
  3. * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
  4. * Keith Outwater, keith_outwater@mvis.com
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. *
  24. */
  25. /*
  26. * Xilinx FPGA support
  27. */
  28. #include <common.h>
  29. #include <virtex2.h>
  30. #include <spartan2.h>
  31. #if (CONFIG_FPGA & CFG_FPGA_XILINX)
  32. #if 0
  33. #define FPGA_DEBUG
  34. #endif
  35. /* Define FPGA_DEBUG to get debug printf's */
  36. #ifdef FPGA_DEBUG
  37. #define PRINTF(fmt,args...) printf (fmt ,##args)
  38. #else
  39. #define PRINTF(fmt,args...)
  40. #endif
  41. /* Local Static Functions */
  42. static int xilinx_validate (Xilinx_desc * desc, char *fn);
  43. /* ------------------------------------------------------------------------- */
  44. int xilinx_load (Xilinx_desc * desc, void *buf, size_t bsize)
  45. {
  46. int ret_val = FPGA_FAIL; /* assume a failure */
  47. if (!xilinx_validate (desc, __FUNCTION__)) {
  48. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  49. } else
  50. switch (desc->family) {
  51. case Xilinx_Spartan2:
  52. #if (CONFIG_FPGA & CFG_SPARTAN2)
  53. PRINTF ("%s: Launching the Spartan-II Loader...\n",
  54. __FUNCTION__);
  55. ret_val = Spartan2_load (desc, buf, bsize);
  56. #else
  57. printf ("%s: No support for Spartan-II devices.\n",
  58. __FUNCTION__);
  59. #endif
  60. break;
  61. case Xilinx_Virtex2:
  62. #if (CONFIG_FPGA & CFG_VIRTEX2)
  63. PRINTF ("%s: Launching the Virtex-II Loader...\n",
  64. __FUNCTION__);
  65. ret_val = Virtex2_load (desc, buf, bsize);
  66. #else
  67. printf ("%s: No support for Virtex-II devices.\n",
  68. __FUNCTION__);
  69. #endif
  70. break;
  71. default:
  72. printf ("%s: Unsupported family type, %d\n",
  73. __FUNCTION__, desc->family);
  74. }
  75. return ret_val;
  76. }
  77. int xilinx_dump (Xilinx_desc * desc, void *buf, size_t bsize)
  78. {
  79. int ret_val = FPGA_FAIL; /* assume a failure */
  80. if (!xilinx_validate (desc, __FUNCTION__)) {
  81. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  82. } else
  83. switch (desc->family) {
  84. case Xilinx_Spartan2:
  85. #if (CONFIG_FPGA & CFG_SPARTAN2)
  86. PRINTF ("%s: Launching the Spartan-II Reader...\n",
  87. __FUNCTION__);
  88. ret_val = Spartan2_dump (desc, buf, bsize);
  89. #else
  90. printf ("%s: No support for Spartan-II devices.\n",
  91. __FUNCTION__);
  92. #endif
  93. break;
  94. case Xilinx_Virtex2:
  95. #if (CONFIG_FPGA & CFG_VIRTEX2)
  96. PRINTF ("%s: Launching the Virtex-II Reader...\n",
  97. __FUNCTION__);
  98. ret_val = Virtex2_dump (desc, buf, bsize);
  99. #else
  100. printf ("%s: No support for Virtex-II devices.\n",
  101. __FUNCTION__);
  102. #endif
  103. break;
  104. default:
  105. printf ("%s: Unsupported family type, %d\n",
  106. __FUNCTION__, desc->family);
  107. }
  108. return ret_val;
  109. }
  110. int xilinx_info (Xilinx_desc * desc)
  111. {
  112. int ret_val = FPGA_FAIL;
  113. if (xilinx_validate (desc, __FUNCTION__)) {
  114. printf ("Family: \t");
  115. switch (desc->family) {
  116. case Xilinx_Spartan2:
  117. printf ("Spartan-II\n");
  118. break;
  119. case Xilinx_Virtex2:
  120. printf ("Virtex-II\n");
  121. break;
  122. /* Add new family types here */
  123. default:
  124. printf ("Unknown family type, %d\n", desc->family);
  125. }
  126. printf ("Interface type:\t");
  127. switch (desc->iface) {
  128. case slave_serial:
  129. printf ("Slave Serial\n");
  130. break;
  131. case master_serial: /* Not used */
  132. printf ("Master Serial\n");
  133. break;
  134. case slave_parallel:
  135. printf ("Slave Parallel\n");
  136. break;
  137. case jtag_mode: /* Not used */
  138. printf ("JTAG Mode\n");
  139. break;
  140. case slave_selectmap:
  141. printf ("Slave SelectMap Mode\n");
  142. break;
  143. case master_selectmap:
  144. printf ("Master SelectMap Mode\n");
  145. break;
  146. /* Add new interface types here */
  147. default:
  148. printf ("Unsupported interface type, %d\n", desc->iface);
  149. }
  150. printf ("Device Size: \t%d bytes\n"
  151. "Cookie: \t0x%x (%d)\n",
  152. desc->size, desc->cookie, desc->cookie);
  153. if (desc->iface_fns) {
  154. printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
  155. switch (desc->family) {
  156. case Xilinx_Spartan2:
  157. #if (CONFIG_FPGA & CFG_SPARTAN2)
  158. Spartan2_info (desc);
  159. #else
  160. /* just in case */
  161. printf ("%s: No support for Spartan-II devices.\n",
  162. __FUNCTION__);
  163. #endif
  164. break;
  165. case Xilinx_Virtex2:
  166. #if (CONFIG_FPGA & CFG_VIRTEX2)
  167. Virtex2_info (desc);
  168. #else
  169. /* just in case */
  170. printf ("%s: No support for Virtex-II devices.\n",
  171. __FUNCTION__);
  172. #endif
  173. break;
  174. /* Add new family types here */
  175. default:
  176. /* we don't need a message here - we give one up above */
  177. ;
  178. }
  179. } else
  180. printf ("No Device Function Table.\n");
  181. ret_val = FPGA_SUCCESS;
  182. } else {
  183. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  184. }
  185. return ret_val;
  186. }
  187. int xilinx_reloc (Xilinx_desc * desc, ulong reloc_offset)
  188. {
  189. int ret_val = FPGA_FAIL; /* assume a failure */
  190. if (!xilinx_validate (desc, __FUNCTION__)) {
  191. printf ("%s: Invalid device descriptor\n", __FUNCTION__);
  192. } else
  193. switch (desc->family) {
  194. case Xilinx_Spartan2:
  195. #if (CONFIG_FPGA & CFG_SPARTAN2)
  196. ret_val = Spartan2_reloc (desc, reloc_offset);
  197. #else
  198. printf ("%s: No support for Spartan-II devices.\n",
  199. __FUNCTION__);
  200. #endif
  201. break;
  202. case Xilinx_Virtex2:
  203. #if (CONFIG_FPGA & CFG_VIRTEX2)
  204. ret_val = Virtex2_reloc (desc, reloc_offset);
  205. #else
  206. printf ("%s: No support for Virtex-II devices.\n",
  207. __FUNCTION__);
  208. #endif
  209. break;
  210. /* Add new family types here */
  211. default:
  212. printf ("%s: Unsupported family type, %d\n",
  213. __FUNCTION__, desc->family);
  214. }
  215. return ret_val;
  216. }
  217. /* ------------------------------------------------------------------------- */
  218. static int xilinx_validate (Xilinx_desc * desc, char *fn)
  219. {
  220. int ret_val = FALSE;
  221. if (desc) {
  222. if ((desc->family > min_xilinx_type) &&
  223. (desc->family < max_xilinx_type)) {
  224. if ((desc->iface > min_xilinx_iface_type) &&
  225. (desc->iface < max_xilinx_iface_type)) {
  226. if (desc->size) {
  227. ret_val = TRUE;
  228. } else
  229. printf ("%s: NULL part size\n", fn);
  230. } else
  231. printf ("%s: Invalid Interface type, %d\n",
  232. fn, desc->iface);
  233. } else
  234. printf ("%s: Invalid family type, %d\n", fn, desc->family);
  235. } else
  236. printf ("%s: NULL descriptor!\n", fn);
  237. return ret_val;
  238. }
  239. #endif /* CONFIG_FPGA & CFG_FPGA_XILINX */