diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2018-04-20 04:37:22 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2018-04-20 04:37:22 +0000 |
commit | a81444beb21996e9e2da43fea54dc17a974a1b8d (patch) | |
tree | bbd634b9c7003096e1eed18789c9550f6e08a55a /sys/dev | |
parent | 4981398be1f052f9004563077f088dce600f9b50 (diff) |
add a small driver for AMDs cryptographic co processor.
the hardware provides crypto offload, zlib offload, and an rng.
this code only supports the rng at the moment.
this device is present on their amd seatlle platforms, and very
present on their epyc stuff.
ok kettenis@ jmatthew@
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/fdt/ccp_fdt.c | 70 | ||||
-rw-r--r-- | sys/dev/fdt/files.fdt | 5 | ||||
-rw-r--r-- | sys/dev/ic/ccp.c | 63 | ||||
-rw-r--r-- | sys/dev/ic/ccpvar.h | 29 | ||||
-rw-r--r-- | sys/dev/pci/ccp_pci.c | 77 | ||||
-rw-r--r-- | sys/dev/pci/files.pci | 6 |
6 files changed, 248 insertions, 2 deletions
diff --git a/sys/dev/fdt/ccp_fdt.c b/sys/dev/fdt/ccp_fdt.c new file mode 100644 index 00000000000..3174b5252e3 --- /dev/null +++ b/sys/dev/fdt/ccp_fdt.c @@ -0,0 +1,70 @@ +/* $OpenBSD: ccp_fdt.c,v 1.1 2018/04/20 04:37:21 dlg Exp $ */ +/* + * Copyright (c) 2018 David Gwynne <dlg@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <sys/systm.h> +#include <sys/device.h> +#include <sys/malloc.h> + +#include <machine/bus.h> +#include <machine/fdt.h> + +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_misc.h> +#include <dev/ofw/ofw_regulator.h> +#include <dev/ofw/fdt.h> + +#include <dev/ic/ccpvar.h> + +static int ccp_fdt_match(struct device *, void *, void *); +static void ccp_fdt_attach(struct device *, struct device *, void *); + +struct cfattach ccp_fdt_ca = { + sizeof(struct ccp_softc), + ccp_fdt_match, + ccp_fdt_attach +}; + +static int +ccp_fdt_match(struct device *parent, void *match, void *aux) +{ + struct fdt_attach_args *faa = aux; + + return OF_is_compatible(faa->fa_node, "amd,ccp-seattle-v1a"); +} + +static void +ccp_fdt_attach(struct device *parent, struct device *self, void *aux) +{ + struct ccp_softc *sc = (struct ccp_softc *)self; + struct fdt_attach_args *faa = aux; + + if (faa->fa_nreg < 1) { + printf(": no registers\n"); + return; + } + + sc->sc_iot = faa->fa_iot; + + if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, + faa->fa_reg[0].size, 0, &sc->sc_ioh)) { + printf(": cannot map registers\n"); + return; + } + + ccp_attach(sc); +} diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt index 6b20ad09289..4c58981bb48 100644 --- a/sys/dev/fdt/files.fdt +++ b/sys/dev/fdt/files.fdt @@ -1,4 +1,4 @@ -# $OpenBSD: files.fdt,v 1.57 2018/04/02 21:40:59 kettenis Exp $ +# $OpenBSD: files.fdt,v 1.58 2018/04/20 04:37:21 dlg Exp $ # # Config file and device description for machine-independent FDT code. # Included by ports that need it. @@ -229,3 +229,6 @@ file dev/fdt/imxuart.c imxuart device fec: ether, ifnet, mii, ifmedia attach fec at fdt file dev/fdt/if_fec.c fec + +attach ccp at fdt with ccp_fdt +file dev/fdt/ccp_fdt.c ccp_fdt diff --git a/sys/dev/ic/ccp.c b/sys/dev/ic/ccp.c new file mode 100644 index 00000000000..76bce67d254 --- /dev/null +++ b/sys/dev/ic/ccp.c @@ -0,0 +1,63 @@ +/* $OpenBSD: ccp.c,v 1.1 2018/04/20 04:37:21 dlg Exp $ */ + +/* + * Copyright (c) 2018 David Gwynne <dlg@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/buf.h> +#include <sys/device.h> +#include <sys/malloc.h> +#include <sys/kernel.h> +#include <sys/timeout.h> + +#include <machine/bus.h> + +#include <dev/rndvar.h> + +#include <dev/ic/ccpvar.h> + +#define CCP_REG_TRNG 0xc + +static void ccp_rng(void *); + +struct cfdriver ccp_cd = { + NULL, + "ccp", + DV_DULL +}; + +void +ccp_attach(struct ccp_softc *sc) +{ + timeout_set(&sc->sc_tick, ccp_rng, sc); + ccp_rng(sc); + + printf("\n"); +} + +static void +ccp_rng(void *arg) +{ + struct ccp_softc *sc = arg; + uint32_t trng; + + trng = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CCP_REG_TRNG); + if (trng != 0) + add_true_randomness(trng); + + timeout_add_msec(&sc->sc_tick, 100); +} diff --git a/sys/dev/ic/ccpvar.h b/sys/dev/ic/ccpvar.h new file mode 100644 index 00000000000..237a5d45f5e --- /dev/null +++ b/sys/dev/ic/ccpvar.h @@ -0,0 +1,29 @@ +/* $OpenBSD: ccpvar.h,v 1.1 2018/04/20 04:37:21 dlg Exp $ */ + +/* + * Copyright (c) 2018 David Gwynne <dlg@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/timeout.h> + +struct ccp_softc { + struct device sc_dev; + bus_space_tag_t sc_iot; + bus_space_handle_t sc_ioh; + + struct timeout sc_tick; +}; + +void ccp_attach(struct ccp_softc *); diff --git a/sys/dev/pci/ccp_pci.c b/sys/dev/pci/ccp_pci.c new file mode 100644 index 00000000000..422f8044599 --- /dev/null +++ b/sys/dev/pci/ccp_pci.c @@ -0,0 +1,77 @@ +/* $OpenBSD: ccp_pci.c,v 1.1 2018/04/20 04:37:21 dlg Exp $ */ + +/* + * Copyright (c) 2018 David Gwynne <dlg@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/rwlock.h> +#include <sys/device.h> +#include <sys/timeout.h> +#include <sys/queue.h> + +#include <machine/bus.h> + +#include <dev/pci/pcidevs.h> +#include <dev/pci/pcivar.h> + +#include <dev/ic/ccpvar.h> + +#define CCP_PCI_BAR 0x18 + +int ccp_pci_match(struct device *, void *, void *); +void ccp_pci_attach(struct device *, struct device *, void *); + +struct cfattach ccp_pci_ca = { + sizeof(struct ccp_softc), + ccp_pci_match, + ccp_pci_attach, +}; + +static const struct pci_matchid ccp_pci_devices[] = { + { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_CCPV3 }, + { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_CCPV5A }, + { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_CCPV5B }, +}; + +int +ccp_pci_match(struct device *parent, void *match, void *aux) +{ + return (pci_matchbyid(aux, ccp_pci_devices, nitems(ccp_pci_devices))); +} + +void +ccp_pci_attach(struct device *parent, struct device *self, void *aux) +{ + struct ccp_softc *sc = (struct ccp_softc *)self; + struct pci_attach_args *pa = aux; + pcireg_t memtype; + + memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, CCP_PCI_BAR); + if (PCI_MAPREG_TYPE(memtype) != PCI_MAPREG_TYPE_MEM) { + printf(": wrong memory type\n"); + return; + } + + if (pci_mapreg_map(pa, CCP_PCI_BAR, memtype, 0, + &sc->sc_iot, &sc->sc_ioh, NULL, NULL, 0) != 0) { + printf(": cannot map registers\n"); + return; + } + + ccp_attach(sc); +} diff --git a/sys/dev/pci/files.pci b/sys/dev/pci/files.pci index 9d0c00a728a..cbec1fcd7a3 100644 --- a/sys/dev/pci/files.pci +++ b/sys/dev/pci/files.pci @@ -1,4 +1,4 @@ -# $OpenBSD: files.pci,v 1.333 2017/12/24 19:50:56 patrick Exp $ +# $OpenBSD: files.pci,v 1.334 2018/04/20 04:37:21 dlg Exp $ # $NetBSD: files.pci,v 1.20 1996/09/24 17:47:15 christos Exp $ # # Config file and device description for machine-independent PCI code. @@ -819,5 +819,9 @@ file dev/pci/dwiic_pci.c dwiic_pci attach bwfm at pci with bwfm_pci: firmload file dev/pci/if_bwfm_pci.c bwfm_pci +# AMD Cryptographic Co-processor +attach ccp at pci with ccp_pci +file dev/pci/ccp_pci.c ccp_pci + include "dev/pci/files.agp" include "dev/pci/drm/files.drm" |