| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sun8i_crypto.c,v 1.30 2022/03/19 11:37:05 riastradh Exp $ */ | | 1 | /* $NetBSD: sun8i_crypto.c,v 1.31 2022/05/15 16:58:28 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Taylor R. Campbell. | | 8 | * by Taylor R. Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -33,27 +33,27 @@ | | | @@ -33,27 +33,27 @@ |
33 | * sun8i_crypto -- Allwinner Crypto Engine driver | | 33 | * sun8i_crypto -- Allwinner Crypto Engine driver |
34 | * | | 34 | * |
35 | * The Crypto Engine is documented in Sec. 3.15 of the Allwinner A64 | | 35 | * The Crypto Engine is documented in Sec. 3.15 of the Allwinner A64 |
36 | * User Manual v1.1, on pp. 230--241. We only use it for the TRNG at | | 36 | * User Manual v1.1, on pp. 230--241. We only use it for the TRNG at |
37 | * the moment, but in principle it could be wired up with opencrypto(9) | | 37 | * the moment, but in principle it could be wired up with opencrypto(9) |
38 | * to compute AES, DES, 3DES, MD5, SHA-1, SHA-224, SHA-256, HMAC-SHA1, | | 38 | * to compute AES, DES, 3DES, MD5, SHA-1, SHA-224, SHA-256, HMAC-SHA1, |
39 | * HMAC-HA256, RSA, and an undocumented PRNG. It also seems to support | | 39 | * HMAC-HA256, RSA, and an undocumented PRNG. It also seems to support |
40 | * AES keys in SRAM (for some kind of HDMI HDCP stuff?). | | 40 | * AES keys in SRAM (for some kind of HDMI HDCP stuff?). |
41 | * | | 41 | * |
42 | * https://linux-sunxi.org/images/b/b4/Allwinner_A64_User_Manual_V1.1.pdf | | 42 | * https://linux-sunxi.org/images/b/b4/Allwinner_A64_User_Manual_V1.1.pdf |
43 | */ | | 43 | */ |
44 | | | 44 | |
45 | #include <sys/cdefs.h> | | 45 | #include <sys/cdefs.h> |
46 | __KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.30 2022/03/19 11:37:05 riastradh Exp $"); | | 46 | __KERNEL_RCSID(1, "$NetBSD: sun8i_crypto.c,v 1.31 2022/05/15 16:58:28 riastradh Exp $"); |
47 | | | 47 | |
48 | #include <sys/types.h> | | 48 | #include <sys/types.h> |
49 | #include <sys/param.h> | | 49 | #include <sys/param.h> |
50 | #include <sys/atomic.h> | | 50 | #include <sys/atomic.h> |
51 | #include <sys/bus.h> | | 51 | #include <sys/bus.h> |
52 | #include <sys/callout.h> | | 52 | #include <sys/callout.h> |
53 | #include <sys/conf.h> | | 53 | #include <sys/conf.h> |
54 | #include <sys/cprng.h> | | 54 | #include <sys/cprng.h> |
55 | #include <sys/device.h> | | 55 | #include <sys/device.h> |
56 | #include <sys/kernel.h> | | 56 | #include <sys/kernel.h> |
57 | #include <sys/kmem.h> | | 57 | #include <sys/kmem.h> |
58 | #include <sys/mbuf.h> | | 58 | #include <sys/mbuf.h> |
59 | #include <sys/mutex.h> | | 59 | #include <sys/mutex.h> |
| @@ -484,27 +484,27 @@ sun8i_crypto_attach(device_t parent, dev | | | @@ -484,27 +484,27 @@ sun8i_crypto_attach(device_t parent, dev |
484 | * Set up the RNG. This will try to synchronously draw the | | 484 | * Set up the RNG. This will try to synchronously draw the |
485 | * first sample by polling, so do this before we establish | | 485 | * first sample by polling, so do this before we establish |
486 | * the interrupt handler. | | 486 | * the interrupt handler. |
487 | */ | | 487 | */ |
488 | sun8i_crypto_rng_attach(sc); | | 488 | sun8i_crypto_rng_attach(sc); |
489 | | | 489 | |
490 | /* | | 490 | /* |
491 | * Self-test has passed and first RNG draw has finished. Use | | 491 | * Self-test has passed and first RNG draw has finished. Use |
492 | * interrupts, not polling, for all subsequent tasks. Set this | | 492 | * interrupts, not polling, for all subsequent tasks. Set this |
493 | * atomically in case the interrupt handler has fired -- can't | | 493 | * atomically in case the interrupt handler has fired -- can't |
494 | * be from us because we've kept ICR set to 0 to mask all | | 494 | * be from us because we've kept ICR set to 0 to mask all |
495 | * interrupts, but in case the interrupt vector is shared. | | 495 | * interrupts, but in case the interrupt vector is shared. |
496 | */ | | 496 | */ |
497 | atomic_store_relaxed(&sc->sc_polling, true); | | 497 | atomic_store_relaxed(&sc->sc_polling, false); |
498 | | | 498 | |
499 | /* Attach the sysctl. */ | | 499 | /* Attach the sysctl. */ |
500 | sun8i_crypto_sysctl_attach(sc); | | 500 | sun8i_crypto_sysctl_attach(sc); |
501 | | | 501 | |
502 | /* Register opencrypto handlers. */ | | 502 | /* Register opencrypto handlers. */ |
503 | sun8i_crypto_register(sc); | | 503 | sun8i_crypto_register(sc); |
504 | } | | 504 | } |
505 | | | 505 | |
506 | static int | | 506 | static int |
507 | sun8i_crypto_task_ctor(void *cookie, void *vtask, int pflags) | | 507 | sun8i_crypto_task_ctor(void *cookie, void *vtask, int pflags) |
508 | { | | 508 | { |
509 | struct sun8i_crypto_softc *sc = cookie; | | 509 | struct sun8i_crypto_softc *sc = cookie; |
510 | struct sun8i_crypto_task *task = vtask; | | 510 | struct sun8i_crypto_task *task = vtask; |