Index: ahcisata_pci.c =================================================================== RCS file: /cvsroot/src/sys/dev/pci/ahcisata_pci.c,v retrieving revision 1.48 diff -u -p -r1.48 ahcisata_pci.c --- ahcisata_pci.c 30 Nov 2018 17:47:54 -0000 1.48 +++ ahcisata_pci.c 3 Dec 2018 19:36:50 -0000 @@ -301,11 +301,59 @@ ahci_pci_attach(device_t parent, device_ int bar = ahci_pci_abar(pa); pcireg_t memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, bar); + bus_addr_t memaddr; + +#if 1 + int error, flags; + + sc->sc_ahcit = pa->pa_memt; + error = pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, + memtype, &memaddr, &sc->sc_ahcis, &flags); + if (error) { + aprint_error_dev(self, "can't get map info\n"); + return; + } + + int msixoff; + if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_MSIX, &msixoff, + NULL)) { + pcireg_t msixtbl; + uint32_t table_offset; + int bir; + + msixtbl = pci_conf_read(pa->pa_pc, pa->pa_tag, + msixoff + PCI_MSIX_TBLOFFSET); + table_offset = msixtbl & PCI_MSIX_TBLOFFSET_MASK; + bir = msixtbl & PCI_MSIX_PBABIR_MASK; + if (bir == 0) { + sc->sc_ahcis = table_offset; + } + } + + error = bus_space_map(sc->sc_ahcit, memaddr, sc->sc_ahcis, flags, + &sc->sc_ahcih); + if (error != 0) { + aprint_error_dev(self, "can't map mem space (error=%d)\n", + error); + return; + } + + pcireg_t csr = pci_conf_read(pa->pa_pc, pa->pa_tag, + PCI_COMMAND_STATUS_REG); + csr |= (PCI_MAPREG_TYPE(memtype) == PCI_MAPREG_TYPE_IO) ? + PCI_COMMAND_IO_ENABLE : PCI_COMMAND_MEM_ENABLE; + pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, csr); +#else + if (pci_mapreg_map(pa, bar, memtype, 0, &sc->sc_ahcit, &sc->sc_ahcih, - NULL, &sc->sc_ahcis) != 0) { + &memaddr, &sc->sc_ahcis) != 0) { aprint_error_dev(self, "can't map ahci registers\n"); return; - } + } +#endif + +printf("type %d ahcis %d memaddr %lx\n", (int)memtype, (int)sc->sc_ahcis, + memaddr); psc->sc_pc = pa->pa_pc; psc->sc_pcitag = pa->pa_tag; @@ -408,7 +456,10 @@ ahci_pci_detach(device_t dv, int flags) psc->sc_pihp = NULL; } - bus_space_unmap(sc->sc_ahcit, sc->sc_ahcih, sc->sc_ahcis); + if (sc->sc_ahcis) { + bus_space_unmap(sc->sc_ahcit, sc->sc_ahcih, sc->sc_ahcis); + sc->sc_ahcis = 0; + } return 0; }