5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 /* Generic FPGA support */
26 #include <common.h> /* core U-Boot definitions */
27 #include <xilinx.h> /* xilinx specific definitions */
28 #include <altera.h> /* altera specific definitions */
31 /* Local definitions */
32 #ifndef CONFIG_MAX_FPGA_DEVICES
33 #define CONFIG_MAX_FPGA_DEVICES 5
36 /* Local static data */
37 static int next_desc = FPGA_INVALID_DEVICE;
38 static fpga_desc desc_table[CONFIG_MAX_FPGA_DEVICES];
42 * 'no support' message function
44 static void fpga_no_sup(char *fn, char *msg)
47 printf("%s: No support for %s.\n", fn, msg);
49 printf("No support for %s.\n", msg);
51 printf("No FPGA suport!\n");
56 * map a device number to a descriptor
58 static const fpga_desc *const fpga_get_desc(int devnum)
60 fpga_desc *desc = (fpga_desc *)NULL;
62 if ((devnum >= 0) && (devnum < next_desc)) {
63 desc = &desc_table[devnum];
64 debug("%s: found fpga descriptor #%d @ 0x%p\n",
65 __func__, devnum, desc);
73 * generic parameter checking code
75 static const fpga_desc *const fpga_validate(int devnum, const void *buf,
76 size_t bsize, char *fn)
78 const fpga_desc *desc = fpga_get_desc(devnum);
81 printf("%s: Invalid device number %d\n", fn, devnum);
84 printf("%s: Null buffer.\n", fn);
85 return (fpga_desc * const)NULL;
92 * generic multiplexing code
94 static int fpga_dev_info(int devnum)
96 int ret_val = FPGA_FAIL; /* assume failure */
97 const fpga_desc * const desc = fpga_get_desc(devnum);
100 debug("%s: Device Descriptor @ 0x%p\n",
101 __func__, desc->devdesc);
103 switch (desc->devtype) {
105 #if defined(CONFIG_FPGA_XILINX)
106 printf("Xilinx Device\nDescriptor @ 0x%p\n", desc);
107 ret_val = xilinx_info(desc->devdesc);
109 fpga_no_sup((char *)__func__, "Xilinx devices");
113 #if defined(CONFIG_FPGA_ALTERA)
114 printf("Altera Device\nDescriptor @ 0x%p\n", desc);
115 ret_val = altera_info(desc->devdesc);
117 fpga_no_sup((char *)__func__, "Altera devices");
121 #if defined(CONFIG_FPGA_LATTICE)
122 printf("Lattice Device\nDescriptor @ 0x%p\n", desc);
123 ret_val = lattice_info(desc->devdesc);
125 fpga_no_sup((char *)__func__, "Lattice devices");
129 printf("%s: Invalid or unsupported device type %d\n",
130 __func__, desc->devtype);
133 printf("%s: Invalid device number %d\n", __func__, devnum);
140 * fgpa_init is usually called from misc_init_r() and MUST be called
141 * before any of the other fpga functions are used.
146 memset(desc_table, 0, sizeof(desc_table));
148 debug("%s\n", __func__);
153 * Basic interface function to get the current number of devices available.
162 * Add the device descriptor to the device table.
164 int fpga_add(fpga_type devtype, void *desc)
166 int devnum = FPGA_INVALID_DEVICE;
169 printf("%s: FPGA support not initialized!\n", __func__);
170 } else if ((devtype > fpga_min_type) && (devtype < fpga_undefined)) {
172 if (next_desc < CONFIG_MAX_FPGA_DEVICES) {
174 desc_table[next_desc].devtype = devtype;
175 desc_table[next_desc++].devdesc = desc;
177 printf("%s: Exceeded Max FPGA device count\n",
181 printf("%s: NULL device descriptor\n", __func__);
184 printf("%s: Unsupported FPGA type %d\n", __func__, devtype);
191 * Generic multiplexing code
193 int fpga_load(int devnum, const void *buf, size_t bsize)
195 int ret_val = FPGA_FAIL; /* assume failure */
196 const fpga_desc *desc = fpga_validate(devnum, buf, bsize,
200 switch (desc->devtype) {
202 #if defined(CONFIG_FPGA_XILINX)
203 ret_val = xilinx_load(desc->devdesc, buf, bsize);
205 fpga_no_sup((char *)__func__, "Xilinx devices");
209 #if defined(CONFIG_FPGA_ALTERA)
210 ret_val = altera_load(desc->devdesc, buf, bsize);
212 fpga_no_sup((char *)__func__, "Altera devices");
216 #if defined(CONFIG_FPGA_LATTICE)
217 ret_val = lattice_load(desc->devdesc, buf, bsize);
219 fpga_no_sup((char *)__func__, "Lattice devices");
223 printf("%s: Invalid or unsupported device type %d\n",
224 __func__, desc->devtype);
233 * generic multiplexing code
235 int fpga_dump(int devnum, const void *buf, size_t bsize)
237 int ret_val = FPGA_FAIL; /* assume failure */
238 const fpga_desc *desc = fpga_validate(devnum, buf, bsize,
242 switch (desc->devtype) {
244 #if defined(CONFIG_FPGA_XILINX)
245 ret_val = xilinx_dump(desc->devdesc, buf, bsize);
247 fpga_no_sup((char *)__func__, "Xilinx devices");
251 #if defined(CONFIG_FPGA_ALTERA)
252 ret_val = altera_dump(desc->devdesc, buf, bsize);
254 fpga_no_sup((char *)__func__, "Altera devices");
258 #if defined(CONFIG_FPGA_LATTICE)
259 ret_val = lattice_dump(desc->devdesc, buf, bsize);
261 fpga_no_sup((char *)__func__, "Lattice devices");
265 printf("%s: Invalid or unsupported device type %d\n",
266 __func__, desc->devtype);
275 * front end to fpga_dev_info. If devnum is invalid, report on all
278 int fpga_info(int devnum)
280 if (devnum == FPGA_INVALID_DEVICE) {
284 for (dev = 0; dev < next_desc; dev++)
289 printf("%s: No FPGA devices available.\n", __func__);
294 return fpga_dev_info(devnum);