1 /* $OpenBSD: ccp_pci.c,v 1.2 2019/05/02 09:52:36 kettenis 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 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_CCPV5C }, 50 }; 51 52 int 53 ccp_pci_match(struct device *parent, void *match, void *aux) 54 { 55 return (pci_matchbyid(aux, ccp_pci_devices, nitems(ccp_pci_devices))); 56 } 57 58 void 59 ccp_pci_attach(struct device *parent, struct device *self, void *aux) 60 { 61 struct ccp_softc *sc = (struct ccp_softc *)self; 62 struct pci_attach_args *pa = aux; 63 pcireg_t memtype; 64 65 memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, CCP_PCI_BAR); 66 if (PCI_MAPREG_TYPE(memtype) != PCI_MAPREG_TYPE_MEM) { 67 printf(": wrong memory type\n"); 68 return; 69 } 70 71 if (pci_mapreg_map(pa, CCP_PCI_BAR, memtype, 0, 72 &sc->sc_iot, &sc->sc_ioh, NULL, NULL, 0) != 0) { 73 printf(": cannot map registers\n"); 74 return; 75 } 76 77 ccp_attach(sc); 78 } 79