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