Line data Source code
1 : /* $OpenBSD: ccp_pci.c,v 1.1 2018/04/20 04:37:21 dlg 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_CCPV3 },
47 : { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_CCPV5A },
48 : { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_CCPV5B },
49 : };
50 :
51 : int
52 0 : ccp_pci_match(struct device *parent, void *match, void *aux)
53 : {
54 0 : return (pci_matchbyid(aux, ccp_pci_devices, nitems(ccp_pci_devices)));
55 : }
56 :
57 : void
58 0 : ccp_pci_attach(struct device *parent, struct device *self, void *aux)
59 : {
60 0 : struct ccp_softc *sc = (struct ccp_softc *)self;
61 0 : struct pci_attach_args *pa = aux;
62 : pcireg_t memtype;
63 :
64 0 : memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, CCP_PCI_BAR);
65 0 : if (PCI_MAPREG_TYPE(memtype) != PCI_MAPREG_TYPE_MEM) {
66 0 : printf(": wrong memory type\n");
67 0 : return;
68 : }
69 :
70 0 : if (pci_mapreg_map(pa, CCP_PCI_BAR, memtype, 0,
71 0 : &sc->sc_iot, &sc->sc_ioh, NULL, NULL, 0) != 0) {
72 0 : printf(": cannot map registers\n");
73 0 : return;
74 : }
75 :
76 0 : ccp_attach(sc);
77 0 : }
|