Changeset View
Changeset View
Standalone View
Standalone View
sys/arm64/qoriq/caam/caam.c
/* | /* | ||||
* Copyright 2021 NXP | * Copyright 2021 NXP | ||||
* Copyright 2023, 2024 Alstom Group | * Copyright 2023, 2024 Alstom Group | ||||
* Copyright 2023, 2024 Sii Poland | * Copyright 2023, 2024 Sii Poland | ||||
* | * | ||||
* SPDX-License-Identifier: BSD-3-Clause | * SPDX-License-Identifier: BSD-3-Clause | ||||
* | * | ||||
* This driver is based on arm-trusted-firmware/drivers/nxp/crypto/caam code. | * This driver is based on arm-trusted-firmware/drivers/nxp/crypto/caam code. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
#include "opt_caam.h" /* For the CAAM_DEBUG option */ | #include "opt_caam.h" /* For the CAAM_DEBUG option */ | ||||
#ifdef CAAM_DEBUG | |||||
#include "caam_test.h" | |||||
#endif | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <sys/endian.h> | #include <sys/endian.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/rman.h> | #include <sys/rman.h> | ||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <dev/fdt/simplebus.h> | #include <dev/fdt/simplebus.h> | ||||
#include <dev/ofw/ofw_bus.h> | #include <dev/ofw/ofw_bus.h> | ||||
#include <dev/ofw/ofw_bus_subr.h> | #include <dev/ofw/ofw_bus_subr.h> | ||||
#include <dev/ofw/openfirm.h> | #include <dev/ofw/openfirm.h> | ||||
#include <opencrypto/cryptodev.h> | |||||
#include "cryptodev_if.h" | |||||
#include "caam.h" | #include "caam.h" | ||||
#include "caam_crypto.h" | |||||
#include "caam_debug.h" | #include "caam_debug.h" | ||||
#include "caam_internal.h" | #include "caam_internal.h" | ||||
#include "caam_test.h" | |||||
#include "caam_trng.h" | #include "caam_trng.h" | ||||
#include "jr/caam_jobdesc.h" | #include "jr/caam_jobdesc.h" | ||||
#include "jr/caam_jr.h" | #include "jr/caam_jr.h" | ||||
#include "jr/caam_jr_hw.h" | #include "jr/caam_jr_hw.h" | ||||
#include "jr/caam_jr_pool.h" | #include "jr/caam_jr_pool.h" | ||||
/*-------------------------- SFR access functions --------------------------*/ | /*-------------------------- SFR access functions --------------------------*/ | ||||
uint32_t | uint32_t | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | |||||
/* After CAAM is ready, initialize the RNG drivers */ | /* After CAAM is ready, initialize the RNG drivers */ | ||||
rv = caam_trng_attach(dev); | rv = caam_trng_attach(dev); | ||||
if (rv != 0) { | if (rv != 0) { | ||||
CAAM_LOG_ERROR("caam_trng_attach failed rv=(%d)\n", rv); | CAAM_LOG_ERROR("caam_trng_attach failed rv=(%d)\n", rv); | ||||
goto cleanup_jobrings; | goto cleanup_jobrings; | ||||
} | } | ||||
rv = caam_crypto_attach(dev); | |||||
if (rv != 0) { | |||||
CAAM_LOG_ERROR("caam_crypto_attach failed rv=(%d)\n", rv); | |||||
goto cleanup_trng; | |||||
} | |||||
#ifdef CAAM_DEBUG | #ifdef CAAM_DEBUG | ||||
/* Add the caam test device for development */ | /* Add the caam test device for development */ | ||||
rv = caam_test_attach(dev); | rv = caam_test_attach(dev); | ||||
if (rv != 0) { | if (rv != 0) { | ||||
CAAM_LOG_ERROR("caam_test_attach failed rv=(%d)\n", rv); | CAAM_LOG_ERROR("caam_test_attach failed rv=(%d)\n", rv); | ||||
goto cleanup_trng; | goto cleanup_crypto; | ||||
} | } | ||||
#endif | #endif | ||||
return (0); | return (0); | ||||
#ifdef CAAM_DEBUG | #ifdef CAAM_DEBUG | ||||
cleanup_crypto: | |||||
caam_crypto_detach(dev); | |||||
#endif | |||||
cleanup_trng: | cleanup_trng: | ||||
caam_trng_detach(dev); | caam_trng_detach(dev); | ||||
#endif | |||||
cleanup_jobrings: | cleanup_jobrings: | ||||
caam_jobrings_detach(dev); | caam_jobrings_detach(dev); | ||||
cleanup_rman: | cleanup_rman: | ||||
rman_fini(&sc->mem_rman); | rman_fini(&sc->mem_rman); | ||||
cleanup_resource: | cleanup_resource: | ||||
bus_free_resource(dev, SYS_RES_MEMORY, sc->mem_res); | bus_free_resource(dev, SYS_RES_MEMORY, sc->mem_res); | ||||
cleanup_simplebus: | cleanup_simplebus: | ||||
free(sc->sc.ranges, M_DEVBUF); | free(sc->sc.ranges, M_DEVBUF); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
free(jr_drained, M_DEVBUF); | free(jr_drained, M_DEVBUF); | ||||
} | } | ||||
static int | static int | ||||
caam_detach(device_t dev) | caam_detach(device_t dev) | ||||
{ | { | ||||
struct caam_softc *sc = device_get_softc(dev); | struct caam_softc *sc = device_get_softc(dev); | ||||
caam_crypto_detach(dev); | |||||
/* Remove TRNG drivers */ | /* Remove TRNG drivers */ | ||||
caam_trng_detach(dev); | caam_trng_detach(dev); | ||||
#ifdef CAAM_DEBUG | #ifdef CAAM_DEBUG | ||||
/* Remove the caam test device */ | /* Remove the caam test device */ | ||||
caam_test_detach(dev); | caam_test_detach(dev); | ||||
#endif | #endif | ||||
caam_jobrings_detach(dev); | caam_jobrings_detach(dev); | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | |||||
DEVMETHOD(device_probe, caam_probe), | DEVMETHOD(device_probe, caam_probe), | ||||
DEVMETHOD(device_attach, caam_attach), | DEVMETHOD(device_attach, caam_attach), | ||||
DEVMETHOD(device_detach, caam_detach), | DEVMETHOD(device_detach, caam_detach), | ||||
DEVMETHOD(bus_alloc_resource, caam_alloc_resource), | DEVMETHOD(bus_alloc_resource, caam_alloc_resource), | ||||
DEVMETHOD(bus_activate_resource, caam_activate_resource), | DEVMETHOD(bus_activate_resource, caam_activate_resource), | ||||
DEVMETHOD(bus_release_resource, caam_release_resource), | DEVMETHOD(bus_release_resource, caam_release_resource), | ||||
DEVMETHOD(cryptodev_probesession, caam_crypto_probesession), | |||||
DEVMETHOD(cryptodev_newsession, caam_crypto_newsession), | |||||
DEVMETHOD(cryptodev_freesession, caam_crypto_freesession), | |||||
DEVMETHOD(cryptodev_process, caam_crypto_process), | |||||
DEVMETHOD_END | DEVMETHOD_END | ||||
}; | }; | ||||
DEFINE_CLASS_1(caam, caam_driver, caam_methods, sizeof(struct caam_softc), | DEFINE_CLASS_1(caam, caam_driver, caam_methods, sizeof(struct caam_softc), | ||||
simplebus_driver); | simplebus_driver); | ||||
DRIVER_MODULE(caam, simplebus, caam_driver, 0, 0); | DRIVER_MODULE(caam, simplebus, caam_driver, 0, 0); | ||||
MODULE_DEPEND(caam, crypto, 1, 1, 1); | |||||
MODULE_VERSION(caam, 1); | MODULE_VERSION(caam, 1); | ||||
Context not available. |