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