From 07159f9c56de91cb7d7bd6b6a795eebfee78133e Mon Sep 17 00:00:00 2001 From: Maxime Henrion Date: Tue, 25 Feb 2003 03:21:22 +0000 Subject: Cleanup of the d_mmap_t interface. - Get rid of the useless atop() / pmap_phys_address() detour. The device mmap handlers must now give back the physical address without atop()'ing it. - Don't borrow the physical address of the mapping in the returned int. Now we properly pass a vm_offset_t * and expect it to be filled by the mmap handler when the mapping was successful. The mmap handler must now return 0 when successful, any other value is considered as an error. Previously, returning -1 was the only way to fail. This change thus accidentally fixes some devices which were bogusly returning errno constants which would have been considered as addresses by the device pager. - Garbage collect the poorly named pmap_phys_address() now that it's no longer used. - Convert all the d_mmap_t consumers to the new API. I'm still not sure wheter we need a __FreeBSD_version bump for this, since and we didn't guarantee API/ABI stability until 5.1-RELEASE. Discussed with: alc, phk, jake Reviewed by: peter Compile-tested on: LINT (i386), GENERIC (alpha and sparc64) Runtime-tested on: i386 --- sys/dev/agp/agp.c | 5 +++-- sys/dev/bktr/bktr_os.c | 5 +++-- sys/dev/drm/drm_vm.h | 16 ++++++++++------ sys/dev/fb/fb.c | 8 ++++---- sys/dev/fb/fbreg.h | 5 +++-- sys/dev/fb/gfb.c | 16 +++++----------- sys/dev/fb/s3_pci.c | 5 +++-- sys/dev/fb/vga.c | 19 +++++++------------ sys/dev/fb/vgareg.h | 2 +- sys/dev/firewire/fwdev.c | 4 ++-- sys/dev/firewire/fwmem.c | 2 +- sys/dev/gfb/gfb_pci.c | 4 ++-- sys/dev/sound/pcm/dsp.c | 7 +++---- sys/dev/syscons/syscons.c | 4 ++-- sys/dev/tdfx/tdfx_pci.c | 9 ++++++--- 15 files changed, 55 insertions(+), 56 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/agp/agp.c b/sys/dev/agp/agp.c index f8210267ccba5..be2f7f88a3563 100644 --- a/sys/dev/agp/agp.c +++ b/sys/dev/agp/agp.c @@ -722,14 +722,15 @@ agp_ioctl(dev_t kdev, u_long cmd, caddr_t data, int fflag, struct thread *td) } static int -agp_mmap(dev_t kdev, vm_offset_t offset, int prot) +agp_mmap(dev_t kdev, vm_offset_t offset, vm_offset_t *paddr, int prot) { device_t dev = KDEV2DEV(kdev); struct agp_softc *sc = device_get_softc(dev); if (offset > AGP_GET_APERTURE(dev)) return -1; - return atop(rman_get_start(sc->as_aperture) + offset); + *paddr = rman_get_start(sc->as_aperture) + offset; + return 0; } /* Implementation of the kernel api */ diff --git a/sys/dev/bktr/bktr_os.c b/sys/dev/bktr/bktr_os.c index 4aae13cdf35ff..7c7f9a12f6858 100644 --- a/sys/dev/bktr/bktr_os.c +++ b/sys/dev/bktr/bktr_os.c @@ -753,7 +753,7 @@ bktr_ioctl( dev_t dev, ioctl_cmd_t cmd, caddr_t arg, int flag, struct thread *td * */ static int -bktr_mmap( dev_t dev, vm_offset_t offset, int nprot ) +bktr_mmap( dev_t dev, vm_offset_t offset, vm_offset_t *paddr, int nprot ) { int unit; bktr_ptr_t bktr; @@ -779,7 +779,8 @@ bktr_mmap( dev_t dev, vm_offset_t offset, int nprot ) if (offset >= bktr->alloc_pages * PAGE_SIZE) return( -1 ); - return( atop(vtophys(bktr->bigbuf) + offset) ); + *paddr = vtophys(bktr->bigbuf) + offset; + return( 0 ); } static int diff --git a/sys/dev/drm/drm_vm.h b/sys/dev/drm/drm_vm.h index 5fd9a398b5e11..705ca480d89da 100644 --- a/sys/dev/drm/drm_vm.h +++ b/sys/dev/drm/drm_vm.h @@ -5,7 +5,8 @@ #include #include -static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot) +static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, vm_offset_t *paddr, + int prot) { drm_device_t *dev = kdev->si_drv1; drm_device_dma_t *dma = dev->dma; @@ -19,10 +20,11 @@ static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot) physical = dma->pagelist[page]; DRM_DEBUG("0x%08x (page %lu) => 0x%08lx\n", offset, page, physical); - return atop(physical); + *paddr = physical; + return 0; } -int DRM(mmap)(dev_t kdev, vm_offset_t offset, int prot) +int DRM(mmap)(dev_t kdev, vm_offset_t offset, vm_offset_t *paddr, int prot) { drm_device_t *dev = kdev->si_drv1; drm_map_t *map = NULL; @@ -43,7 +45,7 @@ int DRM(mmap)(dev_t kdev, vm_offset_t offset, int prot) if (dev->dma && offset >= 0 && offset < ptoa(dev->dma->page_count)) - return DRM(dma_mmap)(kdev, offset, prot); + return DRM(dma_mmap)(kdev, offset, paddr, prot); /* A sequential search of a linked list is fine here because: 1) there will only be @@ -72,9 +74,11 @@ int DRM(mmap)(dev_t kdev, vm_offset_t offset, int prot) case _DRM_FRAME_BUFFER: case _DRM_REGISTERS: case _DRM_AGP: - return atop(offset); + *paddr = offset; + return 0; case _DRM_SHM: - return atop(vtophys(offset)); + *paddr = vtophys(offset); + return 0; default: return -1; /* This should never happen. */ } diff --git a/sys/dev/fb/fb.c b/sys/dev/fb/fb.c index 0dbb73bac8301..6f8bab775f0a0 100644 --- a/sys/dev/fb/fb.c +++ b/sys/dev/fb/fb.c @@ -501,7 +501,7 @@ fbioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td) } static int -fbmmap(dev_t dev, vm_offset_t offset, int nprot) +fbmmap(dev_t dev, vm_offset_t offset, vm_offset_t *paddr, int nprot) { int unit; @@ -509,7 +509,7 @@ fbmmap(dev_t dev, vm_offset_t offset, int nprot) if (vidcdevsw[unit] == NULL) return ENXIO; return (*vidcdevsw[unit]->d_mmap)(makedev(0, adapter[unit]->va_minor), - offset, nprot); + offset, paddr, nprot); } #if experimental @@ -591,9 +591,9 @@ int genfbioctl(genfb_softc_t *sc, video_adapter_t *adp, u_long cmd, } int genfbmmap(genfb_softc_t *sc, video_adapter_t *adp, vm_offset_t offset, - int prot) + vm_offset_t *paddr, int prot) { - return (*vidsw[adp->va_index]->mmap)(adp, offset, prot); + return (*vidsw[adp->va_index]->mmap)(adp, offset, paddr, prot); } #endif /* FB_INSTALL_CDEV */ diff --git a/sys/dev/fb/fbreg.h b/sys/dev/fb/fbreg.h index d55679134e68b..ce9869ec639a0 100644 --- a/sys/dev/fb/fbreg.h +++ b/sys/dev/fb/fbreg.h @@ -81,7 +81,8 @@ typedef int vi_blank_display_t(video_adapter_t *adp, int mode); #define V_DISPLAY_STAND_BY 2 #define V_DISPLAY_SUSPEND 3 */ -typedef int vi_mmap_t(video_adapter_t *adp, vm_offset_t offset, int prot); +typedef int vi_mmap_t(video_adapter_t *adp, vm_offset_t offset, + vm_offset_t *paddr, int prot); typedef int vi_ioctl_t(video_adapter_t *adp, u_long cmd, caddr_t data); typedef int vi_clear_t(video_adapter_t *adp); typedef int vi_fill_rect_t(video_adapter_t *adp, int val, int x, int y, @@ -212,7 +213,7 @@ int genfbwrite(genfb_softc_t *sc, video_adapter_t *adp, int genfbioctl(genfb_softc_t *sc, video_adapter_t *adp, u_long cmd, caddr_t arg, int flag, struct thread *td); int genfbmmap(genfb_softc_t *sc, video_adapter_t *adp, - vm_offset_t offset, int prot); + vm_offset_t offset, vm_offset_t *paddr, int prot); #endif /* FB_INSTALL_CDEV */ diff --git a/sys/dev/fb/gfb.c b/sys/dev/fb/gfb.c index fcb8aedb04c95..4e031692ee291 100644 --- a/sys/dev/fb/gfb.c +++ b/sys/dev/fb/gfb.c @@ -451,20 +451,14 @@ gfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, } int -gfb_mmap(video_adapter_t *adp, vm_offset_t offset, int prot) +gfb_mmap(video_adapter_t *adp, vm_offset_t offset, vm_offset_t *paddr, int prot) { - int error; + /* XXX */ if(offset > adp->va_window_size - PAGE_SIZE) - error = ENXIO; -#ifdef __i386__ - error = i386_btop(adp->va_info.vi_window + offset); -#elsif defined(__alpha__) - error = alpha_btop(adp->va_info.vi_window + offset); -#else - error = ENXIO; -#endif - return(error); + return(ENXIO); + *paddr = adp->va_info.vi_window + offset; + return(0); } int diff --git a/sys/dev/fb/s3_pci.c b/sys/dev/fb/s3_pci.c index c7a1be8506af6..69549db99adf7 100644 --- a/sys/dev/fb/s3_pci.c +++ b/sys/dev/fb/s3_pci.c @@ -389,9 +389,10 @@ s3lfb_blank_display(video_adapter_t *adp, int mode) } static int -s3lfb_mmap(video_adapter_t *adp, vm_offset_t offset, int prot) +s3lfb_mmap(video_adapter_t *adp, vm_offset_t offset, vm_offset_t *paddr, + int prot) { - return (*prevvidsw->mmap)(adp, offset, prot); + return (*prevvidsw->mmap)(adp, offset, paddr, prot); } static int diff --git a/sys/dev/fb/vga.c b/sys/dev/fb/vga.c index 56e015ba1399e..562f71611e477 100644 --- a/sys/dev/fb/vga.c +++ b/sys/dev/fb/vga.c @@ -133,9 +133,10 @@ vga_ioctl(dev_t dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag, } int -vga_mmap(dev_t dev, vga_softc_t *sc, vm_offset_t offset, int prot) +vga_mmap(dev_t dev, vga_softc_t *sc, vm_offset_t offset, vm_offset_t *paddr, + int prot) { - return genfbmmap(&sc->gensc, sc->adp, offset, prot); + return genfbmmap(&sc->gensc, sc->adp, offset, paddr, prot); } #endif /* FB_INSTALL_CDEV */ @@ -2449,7 +2450,8 @@ vga_blank_display(video_adapter_t *adp, int mode) * all adapters */ static int -vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, int prot) +vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, vm_offset_t *paddr, + int prot) { if (adp->va_info.vi_flags & V_INFO_LINEAR) return -1; @@ -2463,15 +2465,8 @@ vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, int prot) if (offset > adp->va_window_size - PAGE_SIZE) return -1; -#ifdef __i386__ - return i386_btop(adp->va_info.vi_window + offset); -#endif -#ifdef __alpha__ - return alpha_btop(adp->va_info.vi_window + offset); -#endif -#ifdef __ia64__ - return ia64_btop(adp->va_info.vi_window + offset); -#endif + *paddr = adp->va_info.vi_window + offset; + return 0; } #ifndef VGA_NO_MODE_CHANGE diff --git a/sys/dev/fb/vgareg.h b/sys/dev/fb/vgareg.h index f59c7ee751a4c..f3903182a59fa 100644 --- a/sys/dev/fb/vgareg.h +++ b/sys/dev/fb/vgareg.h @@ -87,7 +87,7 @@ int vga_write(dev_t dev, vga_softc_t *sc, struct uio *uio, int flag); int vga_ioctl(dev_t dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag, struct thread *td); int vga_mmap(dev_t dev, vga_softc_t *sc, vm_offset_t offset, - int prot); + vm_offset_t *paddr, int prot); #endif extern int (*vga_sub_configure)(int flags); diff --git a/sys/dev/firewire/fwdev.c b/sys/dev/firewire/fwdev.c index 31b3a2c2f18b3..a85db14ab8d4c 100644 --- a/sys/dev/firewire/fwdev.c +++ b/sys/dev/firewire/fwdev.c @@ -921,13 +921,13 @@ fw_poll(dev_t dev, int events, fw_proc *td) } static int -fw_mmap (dev_t dev, vm_offset_t offset, int nproto) +fw_mmap (dev_t dev, vm_offset_t offset, vm_offset_t *paddr, int nproto) { struct firewire_softc *fc; int unit = DEV2UNIT(dev); if (DEV_FWMEM(dev)) - return fwmem_mmap(dev, offset, nproto); + return fwmem_mmap(dev, offset, paddr, nproto); fc = devclass_get_softc(firewire_devclass, unit); diff --git a/sys/dev/firewire/fwmem.c b/sys/dev/firewire/fwmem.c index dd3a27a82a867..9c64fdc3f8353 100644 --- a/sys/dev/firewire/fwmem.c +++ b/sys/dev/firewire/fwmem.c @@ -419,7 +419,7 @@ fwmem_poll (dev_t dev, int events, fw_proc *td) return EINVAL; } int -fwmem_mmap (dev_t dev, vm_offset_t offset, int nproto) +fwmem_mmap (dev_t dev, vm_offset_t offset, vm_offset_t *paddr, int nproto) { return EINVAL; } diff --git a/sys/dev/gfb/gfb_pci.c b/sys/dev/gfb/gfb_pci.c index 3b38781462453..904f536a7cc0d 100644 --- a/sys/dev/gfb/gfb_pci.c +++ b/sys/dev/gfb/gfb_pci.c @@ -313,12 +313,12 @@ pcigfb_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td) } int -pcigfb_mmap(dev_t dev, vm_offset_t offset, int prot) +pcigfb_mmap(dev_t dev, vm_offset_t offset, vm_offset_t *paddr, int prot) { struct gfb_softc *sc; sc = (struct gfb_softc *)devclass_get_softc(gfb_devclass, minor(dev)); - return genfbmmap(&sc->gensc, sc->adp, offset, prot); + return genfbmmap(&sc->gensc, sc->adp, offset, paddr, prot); } #endif /*FB_INSTALL_CDEV*/ diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c index f2d463c53e2f4..cc3c8405cce4e 100644 --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -990,11 +990,10 @@ dsp_poll(dev_t i_dev, int events, struct thread *td) } static int -dsp_mmap(dev_t i_dev, vm_offset_t offset, int nprot) +dsp_mmap(dev_t i_dev, vm_offset_t offset, vm_offset_t *paddr, int nprot) { struct pcm_channel *wrch = NULL, *rdch = NULL, *c; intrmask_t s; - int ret; if (nprot & PROT_EXEC) return -1; @@ -1034,11 +1033,11 @@ dsp_mmap(dev_t i_dev, vm_offset_t offset, int nprot) if (!(c->flags & CHN_F_MAPPED)) c->flags |= CHN_F_MAPPED; - ret = atop(vtophys(sndbuf_getbufofs(c->bufsoft, offset))); + *paddr = vtophys(sndbuf_getbufofs(c->bufsoft, offset)); relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR); splx(s); - return ret; + return 0; } int diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c index aeb80fa8c793e..987e57ec682e3 100644 --- a/sys/dev/syscons/syscons.c +++ b/sys/dev/syscons/syscons.c @@ -3364,14 +3364,14 @@ next_code: } static int -scmmap(dev_t dev, vm_offset_t offset, int nprot) +scmmap(dev_t dev, vm_offset_t offset, vm_offset_t *paddr, int nprot) { scr_stat *scp; scp = SC_STAT(dev); if (scp != scp->sc->cur_scp) return -1; - return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot); + return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, paddr, nprot); } static int diff --git a/sys/dev/tdfx/tdfx_pci.c b/sys/dev/tdfx/tdfx_pci.c index 40fcfadd4dca9..33e0896f724f3 100644 --- a/sys/dev/tdfx/tdfx_pci.c +++ b/sys/dev/tdfx/tdfx_pci.c @@ -441,7 +441,7 @@ tdfx_close(dev_t dev, int fflag, int devtype, struct thread *td) } static int -tdfx_mmap(dev_t dev, vm_offset_t offset, int nprot) +tdfx_mmap(dev_t dev, vm_offset_t offset, vm_offset_t *paddr, int nprot) { /* * mmap(2) is called by a user process to request that an area of memory @@ -472,14 +472,17 @@ tdfx_mmap(dev_t dev, vm_offset_t offset, int nprot) /* We must stay within the bound of our address space */ if((offset & 0xff000000) == tdfx_info[0]->addr0) { offset &= 0xffffff; - return atop(rman_get_start(tdfx_info[0]->memrange) + offset); + *paddr = rman_get_start(tdfx_info[0]->memrange) + offset; + return 0; } if(tdfx_count > 1) { tdfx_info[1] = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, 1); if((offset & 0xff000000) == tdfx_info[1]->addr0) { offset &= 0xffffff; - return atop(rman_get_start(tdfx_info[1]->memrange) + offset); + *paddr = rman_get_start(tdfx_info[1]->memrange) + + offset; + return 0; } } -- cgit v1.3