1 /* $OpenBSD: ccp_pci.c,v 1.14 2024/10/24 18:52:59 bluhm Exp $ */ 2 3 /* 4 * Copyright (c) 2018 David Gwynne <dlg@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/param.h> 20 #include <sys/systm.h> 21 #include <sys/device.h> 22 #include <sys/timeout.h> 23 24 #include <machine/bus.h> 25 26 #include <dev/pci/pcidevs.h> 27 #include <dev/pci/pcivar.h> 28 29 #include <dev/ic/ccpvar.h> 30 #include <dev/ic/pspvar.h> 31 32 #include "psp.h" 33 34 #define CCP_PCI_BAR 0x18 35 36 int ccp_pci_match(struct device *, void *, void *); 37 void ccp_pci_attach(struct device *, struct device *, void *); 38 39 const struct cfattach ccp_pci_ca = { 40 sizeof(struct ccp_softc), 41 ccp_pci_match, 42 ccp_pci_attach, 43 }; 44 45 static const struct pci_matchid ccp_pci_devices[] = { 46 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_16_CCP }, 47 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_17_CCP_1 }, 48 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_17_CCP_2 }, 49 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_17_1X_CCP }, 50 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_17_3X_CCP }, 51 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_17_90_CCP }, 52 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_19_1X_PSP }, 53 }; 54 55 int 56 ccp_pci_match(struct device *parent, void *match, void *aux) 57 { 58 return (pci_matchbyid(aux, ccp_pci_devices, nitems(ccp_pci_devices))); 59 } 60 61 void 62 ccp_pci_attach(struct device *parent, struct device *self, void *aux) 63 { 64 struct ccp_softc *sc = (struct ccp_softc *)self; 65 struct pci_attach_args *pa = aux; 66 pcireg_t memtype; 67 #if NPSP > 0 68 int psp_matched; 69 #endif 70 71 memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, CCP_PCI_BAR); 72 if (PCI_MAPREG_TYPE(memtype) != PCI_MAPREG_TYPE_MEM) { 73 printf(": wrong memory type\n"); 74 return; 75 } 76 77 if (pci_mapreg_map(pa, CCP_PCI_BAR, memtype, 0, 78 &sc->sc_iot, &sc->sc_ioh, NULL, NULL, 0) != 0) { 79 printf(": cannot map registers\n"); 80 return; 81 } 82 83 #if NPSP > 0 84 psp_matched = psp_pci_match(sc, aux); 85 if (psp_matched) 86 psp_pci_intr_map(sc, pa); 87 #endif 88 89 ccp_attach(sc); 90 91 #if NPSP > 0 92 if (psp_matched) 93 psp_pci_attach(sc, pa); 94 #endif 95 } 96