xref: /openbsd-src/sys/dev/pci/ccp_pci.c (revision 46035553bfdd96e63c94e32da0210227ec2e3cf1)
1 /*	$OpenBSD: ccp_pci.c,v 1.5 2020/01/04 01:34:24 jsg 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/kernel.h>
22 #include <sys/rwlock.h>
23 #include <sys/device.h>
24 #include <sys/timeout.h>
25 #include <sys/queue.h>
26 
27 #include <machine/bus.h>
28 
29 #include <dev/pci/pcidevs.h>
30 #include <dev/pci/pcivar.h>
31 
32 #include <dev/ic/ccpvar.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 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 };
52 
53 int
54 ccp_pci_match(struct device *parent, void *match, void *aux)
55 {
56 	return (pci_matchbyid(aux, ccp_pci_devices, nitems(ccp_pci_devices)));
57 }
58 
59 void
60 ccp_pci_attach(struct device *parent, struct device *self, void *aux)
61 {
62 	struct ccp_softc *sc = (struct ccp_softc *)self;
63 	struct pci_attach_args *pa = aux;
64 	pcireg_t memtype;
65 
66 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, CCP_PCI_BAR);
67 	if (PCI_MAPREG_TYPE(memtype) != PCI_MAPREG_TYPE_MEM) {
68 		printf(": wrong memory type\n");
69 		return;
70 	}
71 
72 	if (pci_mapreg_map(pa, CCP_PCI_BAR, memtype, 0,
73 	    &sc->sc_iot, &sc->sc_ioh, NULL, NULL, 0) != 0) {
74 		printf(": cannot map registers\n");
75 		return;
76 	}
77 
78 	ccp_attach(sc);
79 }
80