jsg points out i simultaneously sent too much, and not enough of the diff. On Fri, Apr 20, 2018 at 01:09:18PM +1000, David Gwynne wrote: > a bunch of amd things, eg, their a1100 arm chip and epycs, include > a chip that you can offload a bunch of cryptos and zlib, and which > also provide an rng. this is a quick driver that adds support for > reading the rng periodically. another way of looking at it is a > very long winded way of reducing the number of unknown devices on > the new epyc box we just got. > > it looks like this on an overdrive 1000: > > dlg@o1000 ~$ dmesg | grep ccp > ccp0 at simplebus0 > > and this on an r6415: > > dlg@r6415 ~$ dmesg | grep ccp > ccp0 at pci1 dev 0 function 2 "AMD Cryptographic Co-processor v5a" rev 0x00 > ccp1 at pci2 dev 0 function 1 "AMD Cryptographic Co-processor v5b" rev 0x00 > ccp2 at pci4 dev 0 function 2 "AMD Cryptographic Co-processor v5a" rev 0x00 > ccp3 at pci5 dev 0 function 1 "AMD Cryptographic Co-processor v5b" rev 0x00 > ccp4 at pci11 dev 0 function 2 "AMD Cryptographic Co-processor v5a" rev 0x00 > ccp5 at pci12 dev 0 function 1 "AMD Cryptographic Co-processor v5b" rev 0x00 > ccp6 at pci15 dev 0 function 2 "AMD Cryptographic Co-processor v5a" rev 0x00 > ccp7 at pci16 dev 0 function 1 "AMD Cryptographic Co-processor v5b" rev 0x00 > > ok?
? share/man/man4/ccp.4 Index: share/man/man4/Makefile =================================================================== RCS file: /cvs/src/share/man/man4/Makefile,v retrieving revision 1.678 diff -u -p -r1.678 Makefile --- share/man/man4/Makefile 7 Apr 2018 18:30:53 -0000 1.678 +++ share/man/man4/Makefile 20 Apr 2018 03:16:41 -0000 @@ -17,7 +17,7 @@ MAN= aac.4 ac97.4 acphy.4 acrtc.4 \ bce.4 bcmaux.4 bcmdog.4 bcmrng.4 bcmtemp.4 berkwdt.4 bge.4 \ bgw.4 bio.4 bktr.4 bmtphy.4 bnx.4 \ boca.4 bpf.4 brgphy.4 bridge.4 brswphy.4 bwfm.4 bwi.4 bytgpio.4 \ - cac.4 cas.4 cardbus.4 carp.4 cd.4 cdce.4 cfxga.4 \ + cac.4 cas.4 cardbus.4 carp.4 ccp.4 cd.4 cdce.4 cfxga.4 \ ch.4 chvgpio.4 ciphy.4 ciss.4 clcs.4 clct.4 cmpci.4 \ com.4 cue.4 cy.4 cz.4 \ dc.4 dcphy.4 ddb.4 de.4 diskmap.4 divert.4 dpt.4 drm.4 dwctwo.4 \ Index: sys/dev/fdt/ccp_fdt.c =================================================================== RCS file: sys/dev/fdt/ccp_fdt.c diff -N sys/dev/fdt/ccp_fdt.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sys/dev/fdt/ccp_fdt.c 20 Apr 2018 03:16:41 -0000 @@ -0,0 +1,70 @@ +/* $OpenBSD: xhci_fdt.c,v 1.8 2018/04/09 20:39:03 kettenis Exp $ */ +/* + * Copyright (c) 2018 David Gwynne <d...@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); +} Index: sys/dev/fdt/files.fdt =================================================================== RCS file: /cvs/src/sys/dev/fdt/files.fdt,v retrieving revision 1.57 diff -u -p -r1.57 files.fdt --- sys/dev/fdt/files.fdt 2 Apr 2018 21:40:59 -0000 1.57 +++ sys/dev/fdt/files.fdt 20 Apr 2018 03:16:41 -0000 @@ -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 Index: sys/dev/ic/ccp.c =================================================================== RCS file: sys/dev/ic/ccp.c diff -N sys/dev/ic/ccp.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sys/dev/ic/ccp.c 20 Apr 2018 03:16:41 -0000 @@ -0,0 +1,63 @@ +/* $OpenBSD$ */ + +/* + * Copyright (c) 2018 David Gwynne <d...@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); +} Index: sys/dev/ic/ccpvar.h =================================================================== RCS file: sys/dev/ic/ccpvar.h diff -N sys/dev/ic/ccpvar.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sys/dev/ic/ccpvar.h 20 Apr 2018 03:16:41 -0000 @@ -0,0 +1,29 @@ +/* $OpenBSD$ */ + +/* + * Copyright (c) 2018 David Gwynne <d...@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 *); Index: sys/dev/pci/ccp_pci.c =================================================================== RCS file: sys/dev/pci/ccp_pci.c diff -N sys/dev/pci/ccp_pci.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sys/dev/pci/ccp_pci.c 20 Apr 2018 03:16:41 -0000 @@ -0,0 +1,77 @@ +/* $OpenBSD$ */ + +/* + * Copyright (c) 2018 David Gwynne <d...@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); +} Index: sys/dev/pci/files.pci =================================================================== RCS file: /cvs/src/sys/dev/pci/files.pci,v retrieving revision 1.333 diff -u -p -r1.333 files.pci --- sys/dev/pci/files.pci 24 Dec 2017 19:50:56 -0000 1.333 +++ sys/dev/pci/files.pci 20 Apr 2018 03:16:41 -0000 @@ -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" Index: sys/dev/pci/pcidevs =================================================================== RCS file: /cvs/src/sys/dev/pci/pcidevs,v retrieving revision 1.1843 diff -u -p -r1.1843 pcidevs --- sys/dev/pci/pcidevs 14 Apr 2018 20:27:17 -0000 1.1843 +++ sys/dev/pci/pcidevs 20 Apr 2018 03:16:41 -0000 @@ -719,6 +719,8 @@ product AMD AMD64_15_1x_PCIE_6 0x1417 AM product AMD AMD64_15_1x_PCIE_7 0x1418 AMD64 15/1xh PCIE product AMD AMD64_15_1x_IOMMU 0x1419 AMD64 15/1xh IOMMU product AMD AMD64_16_PCIE 0x1439 AMD64 16h PCIE +product AMD CCPV5A 0x1456 Cryptographic Co-processor v5a +product AMD CCPV5B 0x1468 Cryptographic Co-processor v5b product AMD AMD64_14_HB 0x1510 AMD64 14h Host product AMD AMD64_14_PCIE_1 0x1512 AMD64 14h PCIE product AMD AMD64_14_PCIE_2 0x1513 AMD64 14h PCIE @@ -731,7 +733,7 @@ product AMD AMD64_16_DRAM 0x1532 AMD64 1 product AMD AMD64_16_MISC 0x1533 AMD64 16h Misc Cfg product AMD AMD64_16_CPU_PM 0x1534 AMD64 16h CPU Power product AMD AMD64_16_HB 0x1536 AMD64 16h Host -product AMD CCP 0x1537 CCP +product AMD CCPV3 0x1537 Cryptographic Co-processor v3 product AMD AMD64_16_3X_RC 0x1566 AMD64 16h Root Complex product AMD AMD64_16_3X_HB 0x156b AMD64 16h Host product AMD AMD64_15_6X_LINK 0x1570 AMD64 15h Link Cfg Index: sys/dev/pci/pcidevs.h =================================================================== RCS file: /cvs/src/sys/dev/pci/pcidevs.h,v retrieving revision 1.1836 diff -u -p -r1.1836 pcidevs.h --- sys/dev/pci/pcidevs.h 14 Apr 2018 20:27:38 -0000 1.1836 +++ sys/dev/pci/pcidevs.h 20 Apr 2018 03:16:41 -0000 @@ -724,6 +724,8 @@ #define PCI_PRODUCT_AMD_AMD64_15_1x_PCIE_7 0x1418 /* AMD64 15/1xh PCIE */ #define PCI_PRODUCT_AMD_AMD64_15_1x_IOMMU 0x1419 /* AMD64 15/1xh IOMMU */ #define PCI_PRODUCT_AMD_AMD64_16_PCIE 0x1439 /* AMD64 16h PCIE */ +#define PCI_PRODUCT_AMD_CCPV5A 0x1456 /* Cryptographic Co-processor v5a */ +#define PCI_PRODUCT_AMD_CCPV5B 0x1468 /* Cryptographic Co-processor v5b */ #define PCI_PRODUCT_AMD_AMD64_14_HB 0x1510 /* AMD64 14h Host */ #define PCI_PRODUCT_AMD_AMD64_14_PCIE_1 0x1512 /* AMD64 14h PCIE */ #define PCI_PRODUCT_AMD_AMD64_14_PCIE_2 0x1513 /* AMD64 14h PCIE */ @@ -736,7 +738,7 @@ #define PCI_PRODUCT_AMD_AMD64_16_MISC 0x1533 /* AMD64 16h Misc Cfg */ #define PCI_PRODUCT_AMD_AMD64_16_CPU_PM 0x1534 /* AMD64 16h CPU Power */ #define PCI_PRODUCT_AMD_AMD64_16_HB 0x1536 /* AMD64 16h Host */ -#define PCI_PRODUCT_AMD_CCP 0x1537 /* CCP */ +#define PCI_PRODUCT_AMD_CCPV3 0x1537 /* Cryptographic Co-processor v3 */ #define PCI_PRODUCT_AMD_AMD64_16_3X_RC 0x1566 /* AMD64 16h Root Complex */ #define PCI_PRODUCT_AMD_AMD64_16_3X_HB 0x156b /* AMD64 16h Host */ #define PCI_PRODUCT_AMD_AMD64_15_6X_LINK 0x1570 /* AMD64 15h Link Cfg */ Index: sys/dev/pci/pcidevs_data.h =================================================================== RCS file: /cvs/src/sys/dev/pci/pcidevs_data.h,v retrieving revision 1.1831 diff -u -p -r1.1831 pcidevs_data.h --- sys/dev/pci/pcidevs_data.h 14 Apr 2018 20:27:38 -0000 1.1831 +++ sys/dev/pci/pcidevs_data.h 20 Apr 2018 03:16:41 -0000 @@ -1232,6 +1232,14 @@ static const struct pci_known_product pc "AMD64 16h PCIE", }, { + PCI_VENDOR_AMD, PCI_PRODUCT_AMD_CCPV5A, + "Cryptographic Co-processor v5a", + }, + { + PCI_VENDOR_AMD, PCI_PRODUCT_AMD_CCPV5B, + "Cryptographic Co-processor v5b", + }, + { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_AMD64_14_HB, "AMD64 14h Host", }, @@ -1280,8 +1288,8 @@ static const struct pci_known_product pc "AMD64 16h Host", }, { - PCI_VENDOR_AMD, PCI_PRODUCT_AMD_CCP, - "CCP", + PCI_VENDOR_AMD, PCI_PRODUCT_AMD_CCPV3, + "Cryptographic Co-processor v3", }, { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_AMD64_16_3X_RC, Index: sys/conf/files =================================================================== RCS file: /cvs/src/sys/conf/files,v retrieving revision 1.660 diff -u -p -r1.660 files --- sys/conf/files 14 Feb 2018 23:51:49 -0000 1.660 +++ sys/conf/files 20 Apr 2018 03:16:41 -0000 @@ -464,6 +464,10 @@ file dev/usb/ehci.c ehci needs-flag device xhci: usbus file dev/usb/xhci.c xhci needs-flag +# AMD Cryptographic Co-processor +device ccp +file dev/ic/ccp.c ccp + # SDHC SD/MMC controller device sdhc: sdmmcbus file dev/sdmmc/sdhc.c sdhc Index: sys/arch/amd64/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v retrieving revision 1.452 diff -u -p -r1.452 GENERIC --- sys/arch/amd64/conf/GENERIC 27 Mar 2018 21:11:16 -0000 1.452 +++ sys/arch/amd64/conf/GENERIC 20 Apr 2018 03:16:42 -0000 @@ -98,6 +98,7 @@ kate* at pci? # AMD K8 temperature sen km* at pci? # AMD K10 temperature sensor amas* at pci? disable # AMD memory configuration pchtemp* at pci? # Intel C610 termperature sensor +ccp* at pci? # AMD Cryptographic Co-processor # National Semiconductor LM7[89] and compatible hardware monitors lm0 at isa? port 0x290 Index: sys/arch/arm64/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/arm64/conf/GENERIC,v retrieving revision 1.66 diff -u -p -r1.66 GENERIC --- sys/arch/arm64/conf/GENERIC 7 Apr 2018 18:31:22 -0000 1.66 +++ sys/arch/arm64/conf/GENERIC 20 Apr 2018 03:16:42 -0000 @@ -60,6 +60,7 @@ pci* at pciecam? sdhc* at fdt? sdmmc* at sdhc? xhci* at fdt? +ccp* at fdt? # AMD Cryptographic Co-processor # NS16550 compatible serial ports com* at fdt?