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,
26 * Generic FPGA support
28 #include <common.h> /* core U-Boot definitions */
29 #include <xilinx.h> /* xilinx specific definitions */
30 #include <altera.h> /* altera specific definitions */
33 #define FPGA_DEBUG /* define FPGA_DEBUG to get debug messages */
36 /* Local definitions */
37 #ifndef CONFIG_MAX_FPGA_DEVICES
38 #define CONFIG_MAX_FPGA_DEVICES 5
41 /* Enable/Disable debug console messages */
43 #define PRINTF(fmt,args...) printf (fmt ,##args)
45 #define PRINTF(fmt,args...)
48 /* Local static data */
49 static int next_desc = FPGA_INVALID_DEVICE;
50 static fpga_desc desc_table[CONFIG_MAX_FPGA_DEVICES];
52 /* Local static functions */
53 static __attribute__((__const__)) fpga_desc * __attribute__((__const__)) fpga_get_desc( int devnum );
54 static __attribute__((__const__)) fpga_desc * __attribute__((__const__)) fpga_validate( int devnum, void *buf,
55 size_t bsize, char *fn );
56 static int fpga_dev_info( int devnum );
59 /* ------------------------------------------------------------------------- */
62 * 'no support' message function
64 static void fpga_no_sup( char *fn, char *msg )
67 printf( "%s: No support for %s.\n", fn, msg);
69 printf( "No support for %s.\n", msg);
71 printf( "No FPGA suport!\n");
77 * map a device number to a descriptor
79 static __attribute__((__const__)) fpga_desc * __attribute__((__const__)) fpga_get_desc( int devnum )
81 fpga_desc *desc = (fpga_desc * )NULL;
83 if (( devnum >= 0 ) && (devnum < next_desc )) {
84 desc = &desc_table[devnum];
85 PRINTF( "%s: found fpga descriptor #%d @ 0x%p\n",
86 __FUNCTION__, devnum, desc );
94 * generic parameter checking code
96 static __attribute__((__const__)) fpga_desc * __attribute__((__const__)) fpga_validate( int devnum, void *buf,
97 size_t bsize, char *fn )
99 fpga_desc * desc = fpga_get_desc( devnum );
102 printf( "%s: Invalid device number %d\n", fn, devnum );
106 printf( "%s: Null buffer.\n", fn );
107 return (fpga_desc * const)NULL;
114 * generic multiplexing code
116 static int fpga_dev_info( int devnum )
118 int ret_val = FPGA_FAIL; /* assume failure */
119 const fpga_desc * const desc = fpga_get_desc( devnum );
122 PRINTF( "%s: Device Descriptor @ 0x%p\n",
123 __FUNCTION__, desc->devdesc );
125 switch ( desc->devtype ) {
127 #if defined(CONFIG_FPGA_XILINX)
128 printf( "Xilinx Device\nDescriptor @ 0x%p\n", desc );
129 ret_val = xilinx_info( desc->devdesc );
131 fpga_no_sup( (char *)__FUNCTION__, "Xilinx devices" );
135 #if defined(CONFIG_FPGA_ALTERA)
136 printf( "Altera Device\nDescriptor @ 0x%p\n", desc );
137 ret_val = altera_info( desc->devdesc );
139 fpga_no_sup( (char *)__FUNCTION__, "Altera devices" );
143 printf( "%s: Invalid or unsupported device type %d\n",
144 __FUNCTION__, desc->devtype );
147 printf( "%s: Invalid device number %d\n",
148 __FUNCTION__, devnum );
155 /* ------------------------------------------------------------------------- */
156 /* fgpa_init is usually called from misc_init_r() and MUST be called
157 * before any of the other fpga functions are used.
162 memset( desc_table, 0, sizeof(desc_table));
164 PRINTF( "%s: CONFIG_FPGA = 0x%x\n", __FUNCTION__, CONFIG_FPGA );
168 * Basic interface function to get the current number of devices available.
170 int fpga_count( void )
176 * Add the device descriptor to the device table.
178 int fpga_add( fpga_type devtype, void *desc )
180 int devnum = FPGA_INVALID_DEVICE;
182 if ( next_desc < 0 ) {
183 printf( "%s: FPGA support not initialized!\n", __FUNCTION__ );
184 } else if (( devtype > fpga_min_type ) && ( devtype < fpga_undefined )) {
186 if ( next_desc < CONFIG_MAX_FPGA_DEVICES ) {
188 desc_table[next_desc].devtype = devtype;
189 desc_table[next_desc++].devdesc = desc;
191 printf( "%s: Exceeded Max FPGA device count\n", __FUNCTION__ );
194 printf( "%s: NULL device descriptor\n", __FUNCTION__ );
197 printf( "%s: Unsupported FPGA type %d\n", __FUNCTION__, devtype );
204 * Generic multiplexing code
206 int fpga_load( int devnum, void *buf, size_t bsize )
208 int ret_val = FPGA_FAIL; /* assume failure */
209 fpga_desc * desc = fpga_validate( devnum, buf, bsize, (char *)__FUNCTION__ );
212 switch ( desc->devtype ) {
214 #if defined(CONFIG_FPGA_XILINX)
215 ret_val = xilinx_load( desc->devdesc, buf, bsize );
217 fpga_no_sup( (char *)__FUNCTION__, "Xilinx devices" );
221 #if defined(CONFIG_FPGA_ALTERA)
222 ret_val = altera_load( desc->devdesc, buf, bsize );
224 fpga_no_sup( (char *)__FUNCTION__, "Altera devices" );
228 printf( "%s: Invalid or unsupported device type %d\n",
229 __FUNCTION__, desc->devtype );
237 * generic multiplexing code
239 int fpga_dump( int devnum, void *buf, size_t bsize )
241 int ret_val = FPGA_FAIL; /* assume failure */
242 fpga_desc * desc = fpga_validate( devnum, buf, bsize, (char *)__FUNCTION__ );
245 switch ( desc->devtype ) {
247 #if defined(CONFIG_FPGA_XILINX)
248 ret_val = xilinx_dump( desc->devdesc, buf, bsize );
250 fpga_no_sup( (char *)__FUNCTION__, "Xilinx devices" );
254 #if defined(CONFIG_FPGA_ALTERA)
255 ret_val = altera_dump( desc->devdesc, buf, bsize );
257 fpga_no_sup( (char *)__FUNCTION__, "Altera devices" );
261 printf( "%s: Invalid or unsupported device type %d\n",
262 __FUNCTION__, desc->devtype );
271 * front end to fpga_dev_info. If devnum is invalid, report on all
274 int fpga_info( int devnum )
276 if ( devnum == FPGA_INVALID_DEVICE ) {
277 if ( next_desc > 0 ) {
280 for ( dev = 0; dev < next_desc; dev++ ) {
281 fpga_dev_info( dev );
285 printf( "%s: No FPGA devices available.\n", __FUNCTION__ );
289 else return fpga_dev_info( devnum );
292 /* ------------------------------------------------------------------------- */