]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/fpga/fpga.c
3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
5 * SPDX-License-Identifier: GPL-2.0+
8 /* Generic FPGA support */
9 #include <common.h> /* core U-Boot definitions */
10 #include <xilinx.h> /* xilinx specific definitions */
11 #include <altera.h> /* altera specific definitions */
14 /* Local definitions */
15 #ifndef CONFIG_MAX_FPGA_DEVICES
16 #define CONFIG_MAX_FPGA_DEVICES 5
19 /* Local static data */
20 static int next_desc
= FPGA_INVALID_DEVICE
;
21 static fpga_desc desc_table
[CONFIG_MAX_FPGA_DEVICES
];
25 * 'no support' message function
27 static void fpga_no_sup(char *fn
, char *msg
)
30 printf("%s: No support for %s.\n", fn
, msg
);
32 printf("No support for %s.\n", msg
);
34 printf("No FPGA support!\n");
39 * map a device number to a descriptor
41 const fpga_desc
*const fpga_get_desc(int devnum
)
43 fpga_desc
*desc
= (fpga_desc
*)NULL
;
45 if ((devnum
>= 0) && (devnum
< next_desc
)) {
46 desc
= &desc_table
[devnum
];
47 debug("%s: found fpga descriptor #%d @ 0x%p\n",
48 __func__
, devnum
, desc
);
56 * generic parameter checking code
58 const fpga_desc
*const fpga_validate(int devnum
, const void *buf
,
59 size_t bsize
, char *fn
)
61 const fpga_desc
*desc
= fpga_get_desc(devnum
);
64 printf("%s: Invalid device number %d\n", fn
, devnum
);
67 printf("%s: Null buffer.\n", fn
);
68 return (fpga_desc
* const)NULL
;
75 * generic multiplexing code
77 static int fpga_dev_info(int devnum
)
79 int ret_val
= FPGA_FAIL
; /* assume failure */
80 const fpga_desc
* const desc
= fpga_get_desc(devnum
);
83 debug("%s: Device Descriptor @ 0x%p\n",
84 __func__
, desc
->devdesc
);
86 switch (desc
->devtype
) {
88 #if defined(CONFIG_FPGA_XILINX)
89 printf("Xilinx Device\nDescriptor @ 0x%p\n", desc
);
90 ret_val
= xilinx_info(desc
->devdesc
);
92 fpga_no_sup((char *)__func__
, "Xilinx devices");
96 #if defined(CONFIG_FPGA_ALTERA)
97 printf("Altera Device\nDescriptor @ 0x%p\n", desc
);
98 ret_val
= altera_info(desc
->devdesc
);
100 fpga_no_sup((char *)__func__
, "Altera devices");
104 #if defined(CONFIG_FPGA_LATTICE)
105 printf("Lattice Device\nDescriptor @ 0x%p\n", desc
);
106 ret_val
= lattice_info(desc
->devdesc
);
108 fpga_no_sup((char *)__func__
, "Lattice devices");
112 printf("%s: Invalid or unsupported device type %d\n",
113 __func__
, desc
->devtype
);
116 printf("%s: Invalid device number %d\n", __func__
, devnum
);
123 * fpga_init is usually called from misc_init_r() and MUST be called
124 * before any of the other fpga functions are used.
129 memset(desc_table
, 0, sizeof(desc_table
));
131 debug("%s\n", __func__
);
136 * Basic interface function to get the current number of devices available.
145 * Add the device descriptor to the device table.
147 int fpga_add(fpga_type devtype
, void *desc
)
149 int devnum
= FPGA_INVALID_DEVICE
;
152 printf("%s: FPGA support not initialized!\n", __func__
);
153 } else if ((devtype
> fpga_min_type
) && (devtype
< fpga_undefined
)) {
155 if (next_desc
< CONFIG_MAX_FPGA_DEVICES
) {
157 desc_table
[next_desc
].devtype
= devtype
;
158 desc_table
[next_desc
++].devdesc
= desc
;
160 printf("%s: Exceeded Max FPGA device count\n",
164 printf("%s: NULL device descriptor\n", __func__
);
167 printf("%s: Unsupported FPGA type %d\n", __func__
, devtype
);
174 * Convert bitstream data and load into the fpga
176 int __weak
fpga_loadbitstream(int devnum
, char *fpgadata
, size_t size
,
177 bitstream_type bstype
)
179 printf("Bitstream support not implemented for this FPGA device\n");
183 #if defined(CONFIG_CMD_FPGA_LOADFS)
184 int fpga_fsload(int devnum
, const void *buf
, size_t size
,
185 fpga_fs_info
*fpga_fsinfo
)
187 int ret_val
= FPGA_FAIL
; /* assume failure */
188 const fpga_desc
*desc
= fpga_validate(devnum
, buf
, size
,
192 switch (desc
->devtype
) {
194 #if defined(CONFIG_FPGA_XILINX)
195 ret_val
= xilinx_loadfs(desc
->devdesc
, buf
, size
,
198 fpga_no_sup((char *)__func__
, "Xilinx devices");
202 printf("%s: Invalid or unsupported device type %d\n",
203 __func__
, desc
->devtype
);
212 * Generic multiplexing code
214 int fpga_load(int devnum
, const void *buf
, size_t bsize
, bitstream_type bstype
)
216 int ret_val
= FPGA_FAIL
; /* assume failure */
217 const fpga_desc
*desc
= fpga_validate(devnum
, buf
, bsize
,
221 switch (desc
->devtype
) {
223 #if defined(CONFIG_FPGA_XILINX)
224 ret_val
= xilinx_load(desc
->devdesc
, buf
, bsize
,
227 fpga_no_sup((char *)__func__
, "Xilinx devices");
231 #if defined(CONFIG_FPGA_ALTERA)
232 ret_val
= altera_load(desc
->devdesc
, buf
, bsize
);
234 fpga_no_sup((char *)__func__
, "Altera devices");
238 #if defined(CONFIG_FPGA_LATTICE)
239 ret_val
= lattice_load(desc
->devdesc
, buf
, bsize
);
241 fpga_no_sup((char *)__func__
, "Lattice devices");
245 printf("%s: Invalid or unsupported device type %d\n",
246 __func__
, desc
->devtype
);
255 * generic multiplexing code
257 int fpga_dump(int devnum
, const void *buf
, size_t bsize
)
259 int ret_val
= FPGA_FAIL
; /* assume failure */
260 const fpga_desc
*desc
= fpga_validate(devnum
, buf
, bsize
,
264 switch (desc
->devtype
) {
266 #if defined(CONFIG_FPGA_XILINX)
267 ret_val
= xilinx_dump(desc
->devdesc
, buf
, bsize
);
269 fpga_no_sup((char *)__func__
, "Xilinx devices");
273 #if defined(CONFIG_FPGA_ALTERA)
274 ret_val
= altera_dump(desc
->devdesc
, buf
, bsize
);
276 fpga_no_sup((char *)__func__
, "Altera devices");
280 #if defined(CONFIG_FPGA_LATTICE)
281 ret_val
= lattice_dump(desc
->devdesc
, buf
, bsize
);
283 fpga_no_sup((char *)__func__
, "Lattice devices");
287 printf("%s: Invalid or unsupported device type %d\n",
288 __func__
, desc
->devtype
);
297 * front end to fpga_dev_info. If devnum is invalid, report on all
300 int fpga_info(int devnum
)
302 if (devnum
== FPGA_INVALID_DEVICE
) {
306 for (dev
= 0; dev
< next_desc
; dev
++)
311 printf("%s: No FPGA devices available.\n", __func__
);
316 return fpga_dev_info(devnum
);