Annotation of sys/dev/pci/sli_pci.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: sli_pci.c,v 1.4 2007/05/19 04:10:20 dlg Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 2007 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/malloc.h>
! 23: #include <sys/device.h>
! 24:
! 25: #include <machine/bus.h>
! 26:
! 27: #include <dev/pci/pcireg.h>
! 28: #include <dev/pci/pcivar.h>
! 29: #include <dev/pci/pcidevs.h>
! 30:
! 31: #include <scsi/scsi_all.h>
! 32: #include <scsi/scsiconf.h>
! 33:
! 34: #include <dev/ic/slireg.h>
! 35: #include <dev/ic/slivar.h>
! 36:
! 37: int sli_pci_match(struct device *, void *, void *);
! 38: void sli_pci_attach(struct device *, struct device *, void *);
! 39: int sli_pci_detach(struct device *, int);
! 40:
! 41: struct sli_pci_softc {
! 42: struct sli_softc psc_sli;
! 43:
! 44: pci_chipset_tag_t psc_pc;
! 45: pcitag_t psc_tag;
! 46:
! 47: void *psc_ih;
! 48: };
! 49:
! 50: struct cfattach sli_pci_ca = {
! 51: sizeof(struct sli_pci_softc),
! 52: sli_pci_match,
! 53: sli_pci_attach,
! 54: sli_pci_detach
! 55: };
! 56:
! 57: static const struct pci_matchid sli_pci_devices[] = {
! 58: { PCI_VENDOR_EMULEX, PCI_PRODUCT_EMULEX_LP8000 }
! 59: };
! 60:
! 61: int
! 62: sli_pci_match(struct device *parent, void *match, void *aux)
! 63: {
! 64: return (pci_matchbyid((struct pci_attach_args *)aux, sli_pci_devices,
! 65: sizeof(sli_pci_devices) / sizeof(sli_pci_devices[0])));
! 66: }
! 67:
! 68: void
! 69: sli_pci_attach(struct device *parent, struct device *self, void *aux)
! 70: {
! 71: struct sli_pci_softc *psc = (struct sli_pci_softc *)self;
! 72: struct sli_softc *sc = &psc->psc_sli;
! 73: struct pci_attach_args *pa = aux;
! 74: pcireg_t memtype;
! 75: pci_intr_handle_t ih;
! 76:
! 77: psc->psc_pc = pa->pa_pc;
! 78: psc->psc_tag = pa->pa_tag;
! 79: psc->psc_ih = NULL;
! 80: sc->sc_dmat = pa->pa_dmat;
! 81: sc->sc_ios_slim = 0;
! 82: sc->sc_ios_reg = 0;
! 83:
! 84: memtype = pci_mapreg_type(psc->psc_pc, psc->psc_tag,
! 85: SLI_PCI_BAR_SLIM);
! 86: if (pci_mapreg_map(pa, SLI_PCI_BAR_SLIM, memtype, 0,
! 87: &sc->sc_iot_slim, &sc->sc_ioh_slim, NULL,
! 88: &sc->sc_ios_slim, 0) != 0) {
! 89: printf(": unable to map SLIM bar\n");
! 90: return;
! 91: }
! 92:
! 93: memtype = pci_mapreg_type(psc->psc_pc, psc->psc_tag,
! 94: SLI_PCI_BAR_REGISTER);
! 95: if (pci_mapreg_map(pa, SLI_PCI_BAR_REGISTER, memtype, 0,
! 96: &sc->sc_iot_reg, &sc->sc_ioh_reg, NULL,
! 97: &sc->sc_ios_reg, 0) != 0) {
! 98: printf(": unable to map REGISTER bar\n");
! 99: goto unmap_slim;
! 100: }
! 101:
! 102: if (pci_intr_map(pa, &ih)) {
! 103: printf(": unable to map interrupt\n");
! 104: goto unmap_reg;
! 105: }
! 106: printf(": %s", pci_intr_string(psc->psc_pc, ih));
! 107:
! 108: if (sli_attach(sc) != 0) {
! 109: /* error already printed by sli_attach() */
! 110: goto unmap_reg;
! 111: }
! 112:
! 113: psc->psc_ih = pci_intr_establish(psc->psc_pc, ih, IPL_BIO,
! 114: sli_intr, sc, DEVNAME(sc));
! 115: if (psc->psc_ih == NULL) {
! 116: printf("%s: unable to establish interrupt\n");
! 117: goto detach;
! 118: }
! 119:
! 120: return;
! 121:
! 122: detach:
! 123: sli_detach(sc, DETACH_FORCE|DETACH_QUIET);
! 124: unmap_reg:
! 125: bus_space_unmap(sc->sc_iot_reg, sc->sc_ioh_reg, sc->sc_ios_reg);
! 126: sc->sc_ios_reg = 0;
! 127: unmap_slim:
! 128: bus_space_unmap(sc->sc_iot_slim, sc->sc_ioh_slim, sc->sc_ios_slim);
! 129: sc->sc_ios_slim = 0;
! 130: }
! 131:
! 132: int
! 133: sli_pci_detach(struct device *self, int flags)
! 134: {
! 135: struct sli_pci_softc *psc = (struct sli_pci_softc *)self;
! 136: struct sli_softc *sc = &psc->psc_sli;
! 137: int rv;
! 138:
! 139: rv = sli_detach(sc, flags);
! 140: if (rv != 0)
! 141: return (rv);
! 142:
! 143: return (0);
! 144: }
CVSweb