Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 7 | /* Generic FPGA support */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 8 | #include <common.h> /* core U-Boot definitions */ |
| 9 | #include <xilinx.h> /* xilinx specific definitions */ |
| 10 | #include <altera.h> /* altera specific definitions */ |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 11 | #include <lattice.h> |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 12 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 13 | /* Local definitions */ |
| 14 | #ifndef CONFIG_MAX_FPGA_DEVICES |
| 15 | #define CONFIG_MAX_FPGA_DEVICES 5 |
| 16 | #endif |
| 17 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 18 | /* Local static data */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 19 | static int next_desc = FPGA_INVALID_DEVICE; |
| 20 | static fpga_desc desc_table[CONFIG_MAX_FPGA_DEVICES]; |
| 21 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 22 | /* |
| 23 | * fpga_no_sup |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 24 | * 'no support' message function |
| 25 | */ |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 26 | static void fpga_no_sup(char *fn, char *msg) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 27 | { |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 28 | if (fn && msg) |
| 29 | printf("%s: No support for %s.\n", fn, msg); |
| 30 | else if (msg) |
| 31 | printf("No support for %s.\n", msg); |
| 32 | else |
Robert P. J. Day | 8d56db9 | 2016-07-15 13:44:45 -0400 | [diff] [blame] | 33 | printf("No FPGA support!\n"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | |
| 37 | /* fpga_get_desc |
| 38 | * map a device number to a descriptor |
| 39 | */ |
Michal Simek | fbadb76 | 2015-01-13 16:09:53 +0100 | [diff] [blame] | 40 | const fpga_desc *const fpga_get_desc(int devnum) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 41 | { |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 42 | fpga_desc *desc = (fpga_desc *)NULL; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 43 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 44 | if ((devnum >= 0) && (devnum < next_desc)) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 45 | desc = &desc_table[devnum]; |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 46 | debug("%s: found fpga descriptor #%d @ 0x%p\n", |
| 47 | __func__, devnum, desc); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | return desc; |
| 51 | } |
| 52 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 53 | /* |
| 54 | * fpga_validate |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 55 | * generic parameter checking code |
| 56 | */ |
Michal Simek | 6ff890d | 2013-04-26 15:04:48 +0200 | [diff] [blame] | 57 | const fpga_desc *const fpga_validate(int devnum, const void *buf, |
| 58 | size_t bsize, char *fn) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 59 | { |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 60 | const fpga_desc *desc = fpga_get_desc(devnum); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 61 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 62 | if (!desc) |
| 63 | printf("%s: Invalid device number %d\n", fn, devnum); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 64 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 65 | if (!buf) { |
| 66 | printf("%s: Null buffer.\n", fn); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 67 | return (fpga_desc * const)NULL; |
| 68 | } |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 69 | return desc; |
| 70 | } |
| 71 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 72 | /* |
| 73 | * fpga_dev_info |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 74 | * generic multiplexing code |
| 75 | */ |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 76 | static int fpga_dev_info(int devnum) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 77 | { |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 78 | int ret_val = FPGA_FAIL; /* assume failure */ |
| 79 | const fpga_desc * const desc = fpga_get_desc(devnum); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 80 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 81 | if (desc) { |
| 82 | debug("%s: Device Descriptor @ 0x%p\n", |
| 83 | __func__, desc->devdesc); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 84 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 85 | switch (desc->devtype) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 86 | case fpga_xilinx: |
Matthias Fuchs | a440087 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 87 | #if defined(CONFIG_FPGA_XILINX) |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 88 | printf("Xilinx Device\nDescriptor @ 0x%p\n", desc); |
| 89 | ret_val = xilinx_info(desc->devdesc); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 90 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 91 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 92 | #endif |
| 93 | break; |
| 94 | case fpga_altera: |
Matthias Fuchs | a440087 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 95 | #if defined(CONFIG_FPGA_ALTERA) |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 96 | printf("Altera Device\nDescriptor @ 0x%p\n", desc); |
| 97 | ret_val = altera_info(desc->devdesc); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 98 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 99 | fpga_no_sup((char *)__func__, "Altera devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 100 | #endif |
| 101 | break; |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 102 | case fpga_lattice: |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 103 | #if defined(CONFIG_FPGA_LATTICE) |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 104 | printf("Lattice Device\nDescriptor @ 0x%p\n", desc); |
| 105 | ret_val = lattice_info(desc->devdesc); |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 106 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 107 | fpga_no_sup((char *)__func__, "Lattice devices"); |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 108 | #endif |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 109 | break; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 110 | default: |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 111 | printf("%s: Invalid or unsupported device type %d\n", |
| 112 | __func__, desc->devtype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 113 | } |
| 114 | } else { |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 115 | printf("%s: Invalid device number %d\n", __func__, devnum); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | return ret_val; |
| 119 | } |
| 120 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 121 | /* |
Michal Simek | b563a6b | 2016-05-17 14:32:00 +0200 | [diff] [blame] | 122 | * fpga_init is usually called from misc_init_r() and MUST be called |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 123 | * before any of the other fpga functions are used. |
| 124 | */ |
Peter Tyser | cf8582c | 2009-09-21 11:20:32 -0500 | [diff] [blame] | 125 | void fpga_init(void) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 126 | { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 127 | next_desc = 0; |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 128 | memset(desc_table, 0, sizeof(desc_table)); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 129 | |
Michal Simek | aefbf8f | 2013-04-26 09:38:26 +0200 | [diff] [blame] | 130 | debug("%s\n", __func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 133 | /* |
| 134 | * fpga_count |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 135 | * Basic interface function to get the current number of devices available. |
| 136 | */ |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 137 | int fpga_count(void) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 138 | { |
| 139 | return next_desc; |
| 140 | } |
| 141 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 142 | /* |
| 143 | * fpga_add |
Peter Tyser | cf8582c | 2009-09-21 11:20:32 -0500 | [diff] [blame] | 144 | * Add the device descriptor to the device table. |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 145 | */ |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 146 | int fpga_add(fpga_type devtype, void *desc) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 147 | { |
| 148 | int devnum = FPGA_INVALID_DEVICE; |
| 149 | |
Michal Simek | 3529c11 | 2018-01-26 13:17:04 +0100 | [diff] [blame] | 150 | if (!desc) { |
| 151 | printf("%s: NULL device descriptor\n", __func__); |
| 152 | return devnum; |
| 153 | } |
| 154 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 155 | if (next_desc < 0) { |
| 156 | printf("%s: FPGA support not initialized!\n", __func__); |
| 157 | } else if ((devtype > fpga_min_type) && (devtype < fpga_undefined)) { |
Michal Simek | 3529c11 | 2018-01-26 13:17:04 +0100 | [diff] [blame] | 158 | if (next_desc < CONFIG_MAX_FPGA_DEVICES) { |
| 159 | devnum = next_desc; |
| 160 | desc_table[next_desc].devtype = devtype; |
| 161 | desc_table[next_desc++].devdesc = desc; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 162 | } else { |
Michal Simek | 3529c11 | 2018-01-26 13:17:04 +0100 | [diff] [blame] | 163 | printf("%s: Exceeded Max FPGA device count\n", |
| 164 | __func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 165 | } |
| 166 | } else { |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 167 | printf("%s: Unsupported FPGA type %d\n", __func__, devtype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | return devnum; |
| 171 | } |
| 172 | |
| 173 | /* |
Goldschmidt Simon | 9179c81 | 2017-11-10 14:17:41 +0000 | [diff] [blame] | 174 | * Return 1 if the fpga data is partial. |
| 175 | * This is only required for fpga drivers that support bitstream_type. |
| 176 | */ |
| 177 | int __weak fpga_is_partial_data(int devnum, size_t img_len) |
| 178 | { |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | /* |
Michal Simek | cd5a1cf | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 183 | * Convert bitstream data and load into the fpga |
| 184 | */ |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 185 | int __weak fpga_loadbitstream(int devnum, char *fpgadata, size_t size, |
| 186 | bitstream_type bstype) |
Michal Simek | cd5a1cf | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 187 | { |
| 188 | printf("Bitstream support not implemented for this FPGA device\n"); |
| 189 | return FPGA_FAIL; |
| 190 | } |
| 191 | |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 192 | #if defined(CONFIG_CMD_FPGA_LOADFS) |
| 193 | int fpga_fsload(int devnum, const void *buf, size_t size, |
| 194 | fpga_fs_info *fpga_fsinfo) |
| 195 | { |
| 196 | int ret_val = FPGA_FAIL; /* assume failure */ |
| 197 | const fpga_desc *desc = fpga_validate(devnum, buf, size, |
| 198 | (char *)__func__); |
| 199 | |
| 200 | if (desc) { |
| 201 | switch (desc->devtype) { |
| 202 | case fpga_xilinx: |
| 203 | #if defined(CONFIG_FPGA_XILINX) |
| 204 | ret_val = xilinx_loadfs(desc->devdesc, buf, size, |
| 205 | fpga_fsinfo); |
| 206 | #else |
| 207 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
| 208 | #endif |
| 209 | break; |
| 210 | default: |
| 211 | printf("%s: Invalid or unsupported device type %d\n", |
| 212 | __func__, desc->devtype); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return ret_val; |
| 217 | } |
| 218 | #endif |
| 219 | |
Siva Durga Prasad Paladugu | cce0cb0 | 2018-05-31 15:10:22 +0530 | [diff] [blame] | 220 | #if defined(CONFIG_CMD_FPGA_LOAD_SECURE) |
| 221 | int fpga_loads(int devnum, const void *buf, size_t size, |
| 222 | struct fpga_secure_info *fpga_sec_info) |
| 223 | { |
| 224 | int ret_val = FPGA_FAIL; |
| 225 | |
| 226 | const fpga_desc *desc = fpga_validate(devnum, buf, size, |
| 227 | (char *)__func__); |
| 228 | |
| 229 | if (desc) { |
| 230 | switch (desc->devtype) { |
| 231 | case fpga_xilinx: |
| 232 | #if defined(CONFIG_FPGA_XILINX) |
| 233 | ret_val = xilinx_loads(desc->devdesc, buf, size, |
| 234 | fpga_sec_info); |
| 235 | #else |
| 236 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
| 237 | #endif |
| 238 | break; |
| 239 | default: |
| 240 | printf("%s: Invalid or unsupported device type %d\n", |
| 241 | __func__, desc->devtype); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return ret_val; |
| 246 | } |
| 247 | #endif |
| 248 | |
Michal Simek | cd5a1cf | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 249 | /* |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 250 | * Generic multiplexing code |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 251 | */ |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 252 | int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 253 | { |
| 254 | int ret_val = FPGA_FAIL; /* assume failure */ |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 255 | const fpga_desc *desc = fpga_validate(devnum, buf, bsize, |
| 256 | (char *)__func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 257 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 258 | if (desc) { |
| 259 | switch (desc->devtype) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 260 | case fpga_xilinx: |
Matthias Fuchs | a440087 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 261 | #if defined(CONFIG_FPGA_XILINX) |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 262 | ret_val = xilinx_load(desc->devdesc, buf, bsize, |
| 263 | bstype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 264 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 265 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 266 | #endif |
| 267 | break; |
| 268 | case fpga_altera: |
Matthias Fuchs | a440087 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 269 | #if defined(CONFIG_FPGA_ALTERA) |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 270 | ret_val = altera_load(desc->devdesc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 271 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 272 | fpga_no_sup((char *)__func__, "Altera devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 273 | #endif |
| 274 | break; |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 275 | case fpga_lattice: |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 276 | #if defined(CONFIG_FPGA_LATTICE) |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 277 | ret_val = lattice_load(desc->devdesc, buf, bsize); |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 278 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 279 | fpga_no_sup((char *)__func__, "Lattice devices"); |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 280 | #endif |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 281 | break; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 282 | default: |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 283 | printf("%s: Invalid or unsupported device type %d\n", |
| 284 | __func__, desc->devtype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | return ret_val; |
| 289 | } |
| 290 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 291 | /* |
| 292 | * fpga_dump |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 293 | * generic multiplexing code |
| 294 | */ |
Wolfgang Denk | 74f9b38 | 2011-07-30 13:33:49 +0000 | [diff] [blame] | 295 | int fpga_dump(int devnum, const void *buf, size_t bsize) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 296 | { |
| 297 | int ret_val = FPGA_FAIL; /* assume failure */ |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 298 | const fpga_desc *desc = fpga_validate(devnum, buf, bsize, |
| 299 | (char *)__func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 300 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 301 | if (desc) { |
| 302 | switch (desc->devtype) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 303 | case fpga_xilinx: |
Matthias Fuchs | a440087 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 304 | #if defined(CONFIG_FPGA_XILINX) |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 305 | ret_val = xilinx_dump(desc->devdesc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 306 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 307 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 308 | #endif |
| 309 | break; |
| 310 | case fpga_altera: |
Matthias Fuchs | a440087 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 311 | #if defined(CONFIG_FPGA_ALTERA) |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 312 | ret_val = altera_dump(desc->devdesc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 313 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 314 | fpga_no_sup((char *)__func__, "Altera devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 315 | #endif |
| 316 | break; |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 317 | case fpga_lattice: |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 318 | #if defined(CONFIG_FPGA_LATTICE) |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 319 | ret_val = lattice_dump(desc->devdesc, buf, bsize); |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 320 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 321 | fpga_no_sup((char *)__func__, "Lattice devices"); |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 322 | #endif |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 323 | break; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 324 | default: |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 325 | printf("%s: Invalid or unsupported device type %d\n", |
| 326 | __func__, desc->devtype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
| 330 | return ret_val; |
| 331 | } |
| 332 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 333 | /* |
| 334 | * fpga_info |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 335 | * front end to fpga_dev_info. If devnum is invalid, report on all |
| 336 | * available devices. |
| 337 | */ |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 338 | int fpga_info(int devnum) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 339 | { |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 340 | if (devnum == FPGA_INVALID_DEVICE) { |
| 341 | if (next_desc > 0) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 342 | int dev; |
| 343 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 344 | for (dev = 0; dev < next_desc; dev++) |
| 345 | fpga_dev_info(dev); |
| 346 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 347 | return FPGA_SUCCESS; |
| 348 | } else { |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 349 | printf("%s: No FPGA devices available.\n", __func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 350 | return FPGA_FAIL; |
| 351 | } |
| 352 | } |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 353 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 354 | return fpga_dev_info(devnum); |
| 355 | } |