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