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 | |
Christian Taedcke | df36981 | 2023-07-20 09:27:24 +0200 | [diff] [blame] | 247 | static int fpga_load_event_notify(const void *buf, size_t bsize, int result) |
| 248 | { |
| 249 | if (CONFIG_IS_ENABLED(EVENT)) { |
| 250 | struct event_fpga_load load = { |
| 251 | .buf = buf, |
| 252 | .bsize = bsize, |
| 253 | .result = result |
| 254 | }; |
| 255 | |
| 256 | return event_notify(EVT_FPGA_LOAD, &load, sizeof(load)); |
| 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
Michal Simek | cd5a1cf | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 262 | /* |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 263 | * Generic multiplexing code |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 264 | */ |
Oleksandr Suvorov | 4ff163d | 2022-07-22 17:16:07 +0300 | [diff] [blame] | 265 | int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype, |
| 266 | int flags) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 267 | { |
| 268 | int ret_val = FPGA_FAIL; /* assume failure */ |
Christian Taedcke | df36981 | 2023-07-20 09:27:24 +0200 | [diff] [blame] | 269 | int ret_notify; |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 270 | const fpga_desc *desc = fpga_validate(devnum, buf, bsize, |
| 271 | (char *)__func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 272 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 273 | if (desc) { |
| 274 | switch (desc->devtype) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 275 | case fpga_xilinx: |
Matthias Fuchs | a440087 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 276 | #if defined(CONFIG_FPGA_XILINX) |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 277 | ret_val = xilinx_load(desc->devdesc, buf, bsize, |
Oleksandr Suvorov | 4ff163d | 2022-07-22 17:16:07 +0300 | [diff] [blame] | 278 | bstype, flags); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 279 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 280 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 281 | #endif |
| 282 | break; |
| 283 | case fpga_altera: |
Matthias Fuchs | a440087 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 284 | #if defined(CONFIG_FPGA_ALTERA) |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 285 | ret_val = altera_load(desc->devdesc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 286 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 287 | fpga_no_sup((char *)__func__, "Altera devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 288 | #endif |
| 289 | break; |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 290 | case fpga_lattice: |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 291 | #if defined(CONFIG_FPGA_LATTICE) |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 292 | ret_val = lattice_load(desc->devdesc, buf, bsize); |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 293 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 294 | fpga_no_sup((char *)__func__, "Lattice devices"); |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 295 | #endif |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 296 | break; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 297 | default: |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 298 | printf("%s: Invalid or unsupported device type %d\n", |
| 299 | __func__, desc->devtype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Christian Taedcke | df36981 | 2023-07-20 09:27:24 +0200 | [diff] [blame] | 303 | ret_notify = fpga_load_event_notify(buf, bsize, ret_val); |
| 304 | if (ret_notify) |
| 305 | return ret_notify; |
| 306 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 307 | return ret_val; |
| 308 | } |
| 309 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 310 | /* |
| 311 | * fpga_dump |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 312 | * generic multiplexing code |
| 313 | */ |
Wolfgang Denk | 74f9b38 | 2011-07-30 13:33:49 +0000 | [diff] [blame] | 314 | int fpga_dump(int devnum, const void *buf, size_t bsize) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 315 | { |
| 316 | int ret_val = FPGA_FAIL; /* assume failure */ |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 317 | const fpga_desc *desc = fpga_validate(devnum, buf, bsize, |
| 318 | (char *)__func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 319 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 320 | if (desc) { |
| 321 | switch (desc->devtype) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 322 | case fpga_xilinx: |
Matthias Fuchs | a440087 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 323 | #if defined(CONFIG_FPGA_XILINX) |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 324 | ret_val = xilinx_dump(desc->devdesc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 325 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 326 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 327 | #endif |
| 328 | break; |
| 329 | case fpga_altera: |
Matthias Fuchs | a440087 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 330 | #if defined(CONFIG_FPGA_ALTERA) |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 331 | ret_val = altera_dump(desc->devdesc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 332 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 333 | fpga_no_sup((char *)__func__, "Altera devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 334 | #endif |
| 335 | break; |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 336 | case fpga_lattice: |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 337 | #if defined(CONFIG_FPGA_LATTICE) |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 338 | ret_val = lattice_dump(desc->devdesc, buf, bsize); |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 339 | #else |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 340 | fpga_no_sup((char *)__func__, "Lattice devices"); |
Wolfgang Denk | ace143a | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 341 | #endif |
Stefano Babic | ec65c59 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 342 | break; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 343 | default: |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 344 | printf("%s: Invalid or unsupported device type %d\n", |
| 345 | __func__, desc->devtype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | return ret_val; |
| 350 | } |
| 351 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 352 | /* |
| 353 | * fpga_info |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 354 | * front end to fpga_dev_info. If devnum is invalid, report on all |
| 355 | * available devices. |
| 356 | */ |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 357 | int fpga_info(int devnum) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 358 | { |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 359 | if (devnum == FPGA_INVALID_DEVICE) { |
| 360 | if (next_desc > 0) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 361 | int dev; |
| 362 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 363 | for (dev = 0; dev < next_desc; dev++) |
| 364 | fpga_dev_info(dev); |
| 365 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 366 | return FPGA_SUCCESS; |
| 367 | } else { |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 368 | printf("%s: No FPGA devices available.\n", __func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 369 | return FPGA_FAIL; |
| 370 | } |
| 371 | } |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 372 | |
Michal Simek | 5125ba1 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 373 | return fpga_dev_info(devnum); |
| 374 | } |
Oleksandr Suvorov | a4d9593 | 2022-07-22 17:16:08 +0300 | [diff] [blame] | 375 | |
| 376 | #if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE) |
| 377 | int fpga_compatible2flag(int devnum, const char *compatible) |
| 378 | { |
| 379 | const fpga_desc * const desc = fpga_get_desc(devnum); |
| 380 | |
| 381 | if (!desc) |
| 382 | return 0; |
| 383 | |
| 384 | switch (desc->devtype) { |
| 385 | #if defined(CONFIG_FPGA_XILINX) |
| 386 | case fpga_xilinx: |
| 387 | { |
| 388 | xilinx_desc *xdesc = (xilinx_desc *)desc->devdesc; |
| 389 | |
| 390 | if (xdesc->operations && xdesc->operations->str2flag) |
| 391 | return xdesc->operations->str2flag(xdesc, compatible); |
| 392 | } |
| 393 | #endif |
| 394 | default: |
| 395 | break; |
| 396 | } |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | #endif |