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