aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/fpga/zynq-fpga.c
diff options
context:
space:
mode:
authorMoritz Fischer <mdf@kernel.org>2017-02-27 10:19:01 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-03-17 02:10:48 -0400
commit7f33bbca14de25f24660441af5087440dd0d2fca (patch)
treef9c1759ea3a1f0644f28bcf259b9a4a7c3501339 /drivers/fpga/zynq-fpga.c
parent0f4f0c8ff1da9171bca0dc01ce5551e8b6d2f0f3 (diff)
fpga: zynq: Add support for encrypted bitstreams
Add support for encrypted bitstreams. For this to work the system must be booted in secure mode. In order for on-the-fly decryption to work, the PCAP clock rate needs to be lowered via the PCAP_RATE_EN bit. Signed-off-by: Moritz Fischer <mdf@kernel.org> Acked-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Alan Tull <atull@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/fpga/zynq-fpga.c')
-rw-r--r--drivers/fpga/zynq-fpga.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/drivers/fpga/zynq-fpga.c b/drivers/fpga/zynq-fpga.c
index 34cb98139442..70b15b303471 100644
--- a/drivers/fpga/zynq-fpga.c
+++ b/drivers/fpga/zynq-fpga.c
@@ -72,6 +72,10 @@
72#define CTRL_PCAP_PR_MASK BIT(27) 72#define CTRL_PCAP_PR_MASK BIT(27)
73/* Enable PCAP */ 73/* Enable PCAP */
74#define CTRL_PCAP_MODE_MASK BIT(26) 74#define CTRL_PCAP_MODE_MASK BIT(26)
75/* Lower rate to allow decrypt on the fly */
76#define CTRL_PCAP_RATE_EN_MASK BIT(25)
77/* System booted in secure mode */
78#define CTRL_SEC_EN_MASK BIT(7)
75 79
76/* Miscellaneous Control Register bit definitions */ 80/* Miscellaneous Control Register bit definitions */
77/* Internal PCAP loopback */ 81/* Internal PCAP loopback */
@@ -266,6 +270,17 @@ static int zynq_fpga_ops_write_init(struct fpga_manager *mgr,
266 if (err) 270 if (err)
267 return err; 271 return err;
268 272
273 /* check if bitstream is encrypted & and system's still secure */
274 if (info->flags & FPGA_MGR_ENCRYPTED_BITSTREAM) {
275 ctrl = zynq_fpga_read(priv, CTRL_OFFSET);
276 if (!(ctrl & CTRL_SEC_EN_MASK)) {
277 dev_err(&mgr->dev,
278 "System not secure, can't use crypted bitstreams\n");
279 err = -EINVAL;
280 goto out_err;
281 }
282 }
283
269 /* don't globally reset PL if we're doing partial reconfig */ 284 /* don't globally reset PL if we're doing partial reconfig */
270 if (!(info->flags & FPGA_MGR_PARTIAL_RECONFIG)) { 285 if (!(info->flags & FPGA_MGR_PARTIAL_RECONFIG)) {
271 if (!zynq_fpga_has_sync(buf, count)) { 286 if (!zynq_fpga_has_sync(buf, count)) {
@@ -337,12 +352,19 @@ static int zynq_fpga_ops_write_init(struct fpga_manager *mgr,
337 352
338 /* set configuration register with following options: 353 /* set configuration register with following options:
339 * - enable PCAP interface 354 * - enable PCAP interface
340 * - set throughput for maximum speed 355 * - set throughput for maximum speed (if bistream not crypted)
341 * - set CPU in user mode 356 * - set CPU in user mode
342 */ 357 */
343 ctrl = zynq_fpga_read(priv, CTRL_OFFSET); 358 ctrl = zynq_fpga_read(priv, CTRL_OFFSET);
344 zynq_fpga_write(priv, CTRL_OFFSET, 359 if (info->flags & FPGA_MGR_ENCRYPTED_BITSTREAM)
345 (CTRL_PCAP_PR_MASK | CTRL_PCAP_MODE_MASK | ctrl)); 360 zynq_fpga_write(priv, CTRL_OFFSET,
361 (CTRL_PCAP_PR_MASK | CTRL_PCAP_MODE_MASK
362 | CTRL_PCAP_RATE_EN_MASK | ctrl));
363 else
364 zynq_fpga_write(priv, CTRL_OFFSET,
365 (CTRL_PCAP_PR_MASK | CTRL_PCAP_MODE_MASK
366 | ctrl));
367
346 368
347 /* We expect that the command queue is empty right now. */ 369 /* We expect that the command queue is empty right now. */
348 status = zynq_fpga_read(priv, STATUS_OFFSET); 370 status = zynq_fpga_read(priv, STATUS_OFFSET);