xref: /openbsd-src/sys/dev/pci/ccp_pci.c (revision 38923a1915850ed4b92810be9822ffb79ad5d579)
1*38923a19Sbluhm /*	$OpenBSD: ccp_pci.c,v 1.14 2024/10/24 18:52:59 bluhm Exp $ */
25f5e4d1bSdlg 
35f5e4d1bSdlg /*
45f5e4d1bSdlg  * Copyright (c) 2018 David Gwynne <dlg@openbsd.org>
55f5e4d1bSdlg  *
65f5e4d1bSdlg  * Permission to use, copy, modify, and distribute this software for any
75f5e4d1bSdlg  * purpose with or without fee is hereby granted, provided that the above
85f5e4d1bSdlg  * copyright notice and this permission notice appear in all copies.
95f5e4d1bSdlg  *
105f5e4d1bSdlg  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
115f5e4d1bSdlg  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
125f5e4d1bSdlg  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
135f5e4d1bSdlg  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
145f5e4d1bSdlg  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
155f5e4d1bSdlg  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
165f5e4d1bSdlg  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
175f5e4d1bSdlg  */
185f5e4d1bSdlg 
195f5e4d1bSdlg #include <sys/param.h>
205f5e4d1bSdlg #include <sys/systm.h>
215f5e4d1bSdlg #include <sys/device.h>
225f5e4d1bSdlg #include <sys/timeout.h>
235f5e4d1bSdlg 
245f5e4d1bSdlg #include <machine/bus.h>
255f5e4d1bSdlg 
265f5e4d1bSdlg #include <dev/pci/pcidevs.h>
275f5e4d1bSdlg #include <dev/pci/pcivar.h>
285f5e4d1bSdlg 
295f5e4d1bSdlg #include <dev/ic/ccpvar.h>
300b9f4c66Sjsg #include <dev/ic/pspvar.h>
315f5e4d1bSdlg 
328eadc5ecSjsg #include "psp.h"
338eadc5ecSjsg 
345f5e4d1bSdlg #define CCP_PCI_BAR	0x18
355f5e4d1bSdlg 
365f5e4d1bSdlg int	ccp_pci_match(struct device *, void *, void *);
375f5e4d1bSdlg void	ccp_pci_attach(struct device *, struct device *, void *);
385f5e4d1bSdlg 
398d2c75e4Smpi const struct cfattach ccp_pci_ca = {
405f5e4d1bSdlg 	sizeof(struct ccp_softc),
415f5e4d1bSdlg 	ccp_pci_match,
425f5e4d1bSdlg 	ccp_pci_attach,
435f5e4d1bSdlg };
445f5e4d1bSdlg 
455f5e4d1bSdlg static const struct pci_matchid ccp_pci_devices[] = {
463ddeb659Sjsg 	{ PCI_VENDOR_AMD,	PCI_PRODUCT_AMD_16_CCP },
473ddeb659Sjsg 	{ PCI_VENDOR_AMD,	PCI_PRODUCT_AMD_17_CCP_1 },
483ddeb659Sjsg 	{ PCI_VENDOR_AMD,	PCI_PRODUCT_AMD_17_CCP_2 },
493ddeb659Sjsg 	{ PCI_VENDOR_AMD,	PCI_PRODUCT_AMD_17_1X_CCP },
503ddeb659Sjsg 	{ PCI_VENDOR_AMD,	PCI_PRODUCT_AMD_17_3X_CCP },
5187c6952eSjsg 	{ PCI_VENDOR_AMD,	PCI_PRODUCT_AMD_17_90_CCP },
521267c24dSjmatthew 	{ PCI_VENDOR_AMD,	PCI_PRODUCT_AMD_19_1X_PSP },
535f5e4d1bSdlg };
545f5e4d1bSdlg 
555f5e4d1bSdlg int
565f5e4d1bSdlg ccp_pci_match(struct device *parent, void *match, void *aux)
575f5e4d1bSdlg {
585f5e4d1bSdlg 	return (pci_matchbyid(aux, ccp_pci_devices, nitems(ccp_pci_devices)));
595f5e4d1bSdlg }
605f5e4d1bSdlg 
615f5e4d1bSdlg void
625f5e4d1bSdlg ccp_pci_attach(struct device *parent, struct device *self, void *aux)
635f5e4d1bSdlg {
645f5e4d1bSdlg 	struct ccp_softc *sc = (struct ccp_softc *)self;
655f5e4d1bSdlg 	struct pci_attach_args *pa = aux;
665f5e4d1bSdlg 	pcireg_t memtype;
67*38923a19Sbluhm #if NPSP > 0
68*38923a19Sbluhm 	int psp_matched;
69*38923a19Sbluhm #endif
705f5e4d1bSdlg 
715f5e4d1bSdlg 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, CCP_PCI_BAR);
725f5e4d1bSdlg 	if (PCI_MAPREG_TYPE(memtype) != PCI_MAPREG_TYPE_MEM) {
735f5e4d1bSdlg 		printf(": wrong memory type\n");
745f5e4d1bSdlg 		return;
755f5e4d1bSdlg 	}
765f5e4d1bSdlg 
775f5e4d1bSdlg 	if (pci_mapreg_map(pa, CCP_PCI_BAR, memtype, 0,
78820d5ee4Sbluhm 	    &sc->sc_iot, &sc->sc_ioh, NULL, NULL, 0) != 0) {
795f5e4d1bSdlg 		printf(": cannot map registers\n");
805f5e4d1bSdlg 		return;
815f5e4d1bSdlg 	}
825f5e4d1bSdlg 
83*38923a19Sbluhm #if NPSP > 0
84*38923a19Sbluhm 	psp_matched = psp_pci_match(sc, aux);
85*38923a19Sbluhm 	if (psp_matched)
86*38923a19Sbluhm 		psp_pci_intr_map(sc, pa);
87*38923a19Sbluhm #endif
888cb10e2eSbluhm 
895f5e4d1bSdlg 	ccp_attach(sc);
908eadc5ecSjsg 
918eadc5ecSjsg #if NPSP > 0
92*38923a19Sbluhm 	if (psp_matched)
93*38923a19Sbluhm 		psp_pci_attach(sc, pa);
948eadc5ecSjsg #endif
958cb10e2eSbluhm }
96