diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-09-01 19:12:12 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-09-01 19:12:12 +0000 |
commit | e7a1521471d33885c0f5b86f603a840d1c127726 (patch) | |
tree | e4f71a49725fc963e90531f8f515c8a457efc250 /sys | |
parent | b344bc340d5801e48286239a15399bdab458a27a (diff) |
Implement address translation for bus_space_mmap(9).
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/powerpc64/dev/phb.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/sys/arch/powerpc64/dev/phb.c b/sys/arch/powerpc64/dev/phb.c index bedd1880ba2..b0e286cce4c 100644 --- a/sys/arch/powerpc64/dev/phb.c +++ b/sys/arch/powerpc64/dev/phb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: phb.c,v 1.14 2020/09/01 19:09:47 kettenis Exp $ */ +/* $OpenBSD: phb.c,v 1.15 2020/09/01 19:12:11 kettenis Exp $ */ /* * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org> * @@ -101,6 +101,7 @@ int phb_bs_iomap(bus_space_tag_t, bus_addr_t, bus_size_t, int, bus_space_handle_t *); int phb_bs_memmap(bus_space_tag_t, bus_addr_t, bus_size_t, int, bus_space_handle_t *); +paddr_t phb_bs_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); int phb_dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t, struct proc *, int, paddr_t *, int *, int); int phb_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, @@ -329,6 +330,7 @@ phb_attach(struct device *parent, struct device *self, void *aux) memcpy(&sc->sc_bus_memt, sc->sc_iot, sizeof(sc->sc_bus_memt)); sc->sc_bus_memt.bus_private = sc; sc->sc_bus_memt._space_map = phb_bs_memmap; + sc->sc_bus_memt._space_mmap = phb_bs_mmap; sc->sc_bus_memt._space_read_2 = little_space_read_2; sc->sc_bus_memt._space_read_4 = little_space_read_4; sc->sc_bus_memt._space_read_8 = little_space_read_8; @@ -632,6 +634,28 @@ phb_bs_memmap(bus_space_tag_t t, bus_addr_t addr, bus_size_t size, return ENXIO; } +paddr_t +phb_bs_mmap(bus_space_tag_t t, bus_addr_t addr, off_t off, + int prot, int flags) +{ + struct phb_softc *sc = t->bus_private; + int i; + + for (i = 0; i < sc->sc_nranges; i++) { + uint64_t pci_start = sc->sc_ranges[i].pci_base; + uint64_t pci_end = pci_start + sc->sc_ranges[i].size; + uint64_t phys_start = sc->sc_ranges[i].phys_base; + + if ((sc->sc_ranges[i].flags & 0x02000000) == 0x02000000 && + addr >= pci_start && addr + PAGE_SIZE <= pci_end) { + return bus_space_mmap(sc->sc_iot, + addr - pci_start + phys_start, off, prot, flags); + } + } + + return -1; +} + int phb_dmamap_load_buffer(bus_dma_tag_t t, bus_dmamap_t map, void *buf, bus_size_t buflen, struct proc *p, int flags, paddr_t *lastaddrp, |