]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/fpga.c
3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
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 */
32 #if defined(CONFIG_FPGA)
35 #define FPGA_DEBUG /* define FPGA_DEBUG to get debug messages */
38 /* Local definitions */
39 #ifndef CONFIG_MAX_FPGA_DEVICES
40 #define CONFIG_MAX_FPGA_DEVICES 5
43 /* Enable/Disable debug console messages */
45 #define PRINTF(fmt,args...) printf (fmt ,##args)
47 #define PRINTF(fmt,args...)
50 /* Local static data */
51 static ulong relocation_offset
= 0;
52 static int next_desc
= FPGA_INVALID_DEVICE
;
53 static fpga_desc desc_table
[CONFIG_MAX_FPGA_DEVICES
];
55 /* Local static functions */
56 static __attribute__((__const__
)) fpga_desc
* __attribute__((__const__
)) fpga_get_desc( int devnum
);
57 static __attribute__((__const__
)) fpga_desc
* __attribute__((__const__
)) fpga_validate( int devnum
, void *buf
,
58 size_t bsize
, char *fn
);
59 static int fpga_dev_info( int devnum
);
62 /* ------------------------------------------------------------------------- */
65 * 'no support' message function
67 static void fpga_no_sup( char *fn
, char *msg
)
70 printf( "%s: No support for %s.\n", fn
, msg
);
72 printf( "No support for %s.\n", msg
);
74 printf( "No FPGA suport!\n");
80 * map a device number to a descriptor
82 static __attribute__((__const__
)) fpga_desc
* __attribute__((__const__
)) fpga_get_desc( int devnum
)
84 fpga_desc
*desc
= (fpga_desc
* )NULL
;
86 if (( devnum
>= 0 ) && (devnum
< next_desc
)) {
87 desc
= &desc_table
[devnum
];
88 PRINTF( "%s: found fpga descriptor #%d @ 0x%p\n",
89 __FUNCTION__
, devnum
, desc
);
97 * generic parameter checking code
99 static __attribute__((__const__
)) fpga_desc
* __attribute__((__const__
)) fpga_validate( int devnum
, void *buf
,
100 size_t bsize
, char *fn
)
102 fpga_desc
* desc
= fpga_get_desc( devnum
);
105 printf( "%s: Invalid device number %d\n", fn
, devnum
);
109 printf( "%s: Null buffer.\n", fn
);
110 return (fpga_desc
* const)NULL
;
117 * generic multiplexing code
119 static int fpga_dev_info( int devnum
)
121 int ret_val
= FPGA_FAIL
; /* assume failure */
122 const fpga_desc
* const desc
= fpga_get_desc( devnum
);
125 PRINTF( "%s: Device Descriptor @ 0x%p\n",
126 __FUNCTION__
, desc
->devdesc
);
128 switch ( desc
->devtype
) {
130 #if defined(CONFIG_FPGA_XILINX)
131 printf( "Xilinx Device\nDescriptor @ 0x%p\n", desc
);
132 ret_val
= xilinx_info( desc
->devdesc
);
134 fpga_no_sup( (char *)__FUNCTION__
, "Xilinx devices" );
138 #if defined(CONFIG_FPGA_ALTERA)
139 printf( "Altera Device\nDescriptor @ 0x%p\n", desc
);
140 ret_val
= altera_info( desc
->devdesc
);
142 fpga_no_sup( (char *)__FUNCTION__
, "Altera devices" );
146 printf( "%s: Invalid or unsupported device type %d\n",
147 __FUNCTION__
, desc
->devtype
);
150 printf( "%s: Invalid device number %d\n",
151 __FUNCTION__
, devnum
);
159 * generic multiplexing code
161 int fpga_reloc( fpga_type devtype
, void *desc
, ulong reloc_off
)
163 int ret_val
= FPGA_FAIL
;
165 PRINTF( "%s: Relocating Device of type %d @ 0x%p with offset %lx\n",
166 __FUNCTION__
, devtype
, desc
, reloc_off
);
170 #if defined(CONFIG_FPGA_XILINX)
171 ret_val
= xilinx_reloc( desc
, reloc_off
);
173 fpga_no_sup( (char *)__FUNCTION__
, "Xilinx devices" );
177 #if defined(CONFIG_FPGA_ALTERA)
178 ret_val
= altera_reloc( desc
, reloc_off
);
180 fpga_no_sup( (char *)__FUNCTION__
, "Altera devices" );
184 printf( "%s: Invalid or unsupported device type %d\n",
185 __FUNCTION__
, devtype
);
191 /* ------------------------------------------------------------------------- */
192 /* fgpa_init is usually called from misc_init_r() and MUST be called
193 * before any of the other fpga functions are used.
195 void fpga_init( ulong reloc_off
)
197 relocation_offset
= reloc_off
;
199 memset( desc_table
, 0, sizeof(desc_table
));
201 PRINTF( "%s: CONFIG_FPGA = 0x%x\n", __FUNCTION__
, CONFIG_FPGA
);
205 * Basic interface function to get the current number of devices available.
207 int fpga_count( void )
213 * Attempts to relocate the device/board specific interface code
214 * to the proper RAM locations and adds the device descriptor to
217 int fpga_add( fpga_type devtype
, void *desc
)
219 int devnum
= FPGA_INVALID_DEVICE
;
221 if ( next_desc
< 0 ) {
222 printf( "%s: FPGA support not initialized!\n", __FUNCTION__
);
223 } else if (( devtype
> fpga_min_type
) && ( devtype
< fpga_undefined
)) {
225 if ( next_desc
< CONFIG_MAX_FPGA_DEVICES
) {
226 if ( fpga_reloc( devtype
, desc
, relocation_offset
)
229 desc_table
[next_desc
].devtype
= devtype
;
230 desc_table
[next_desc
++].devdesc
= desc
;
232 printf( "%s: Unable to relocate device interface table!\n",
236 printf( "%s: Exceeded Max FPGA device count\n", __FUNCTION__
);
239 printf( "%s: NULL device descriptor\n", __FUNCTION__
);
242 printf( "%s: Unsupported FPGA type %d\n", __FUNCTION__
, devtype
);
249 * Generic multiplexing code
251 int fpga_load( int devnum
, void *buf
, size_t bsize
)
253 int ret_val
= FPGA_FAIL
; /* assume failure */
254 fpga_desc
* desc
= fpga_validate( devnum
, buf
, bsize
, (char *)__FUNCTION__
);
257 switch ( desc
->devtype
) {
259 #if defined(CONFIG_FPGA_XILINX)
260 ret_val
= xilinx_load( desc
->devdesc
, buf
, bsize
);
262 fpga_no_sup( (char *)__FUNCTION__
, "Xilinx devices" );
266 #if defined(CONFIG_FPGA_ALTERA)
267 ret_val
= altera_load( desc
->devdesc
, buf
, bsize
);
269 fpga_no_sup( (char *)__FUNCTION__
, "Altera devices" );
273 printf( "%s: Invalid or unsupported device type %d\n",
274 __FUNCTION__
, desc
->devtype
);
282 * generic multiplexing code
284 int fpga_dump( int devnum
, void *buf
, size_t bsize
)
286 int ret_val
= FPGA_FAIL
; /* assume failure */
287 fpga_desc
* desc
= fpga_validate( devnum
, buf
, bsize
, (char *)__FUNCTION__
);
290 switch ( desc
->devtype
) {
292 #if defined(CONFIG_FPGA_XILINX)
293 ret_val
= xilinx_dump( desc
->devdesc
, buf
, bsize
);
295 fpga_no_sup( (char *)__FUNCTION__
, "Xilinx devices" );
299 #if defined(CONFIG_FPGA_ALTERA)
300 ret_val
= altera_dump( desc
->devdesc
, buf
, bsize
);
302 fpga_no_sup( (char *)__FUNCTION__
, "Altera devices" );
306 printf( "%s: Invalid or unsupported device type %d\n",
307 __FUNCTION__
, desc
->devtype
);
316 * front end to fpga_dev_info. If devnum is invalid, report on all
319 int fpga_info( int devnum
)
321 if ( devnum
== FPGA_INVALID_DEVICE
) {
322 if ( next_desc
> 0 ) {
325 for ( dev
= 0; dev
< next_desc
; dev
++ ) {
326 fpga_dev_info( dev
);
330 printf( "%s: No FPGA devices available.\n", __FUNCTION__
);
334 else return fpga_dev_info( devnum
);
337 /* ------------------------------------------------------------------------- */
339 #endif /* CONFIG_FPGA */