freebsd-dev/sys/dev/drm/drm_vm.h
Maxime Henrion 07159f9c56 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
2003-02-25 03:21:22 +00:00

90 lines
2.1 KiB
C

/*
* $FreeBSD$
*/
#include <vm/vm.h>
#include <vm/pmap.h>
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;
unsigned long physical;
unsigned long page;
if (!dma) return -1; /* Error */
if (!dma->pagelist) return -1; /* Nothing allocated */
page = offset >> PAGE_SHIFT;
physical = dma->pagelist[page];
DRM_DEBUG("0x%08x (page %lu) => 0x%08lx\n", offset, page, physical);
*paddr = physical;
return 0;
}
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;
drm_map_list_entry_t *listentry=NULL;
/*drm_file_t *priv;*/
/* DRM_DEBUG("offset = 0x%x\n", offset);*/
/*XXX Fixme */
/*priv = DRM(find_file_by_proc)(dev, p);
if (!priv) {
DRM_DEBUG("can't find authenticator\n");
return EINVAL;
}
if (!priv->authenticated) return DRM_OS_ERR(EACCES);*/
if (dev->dma
&& offset >= 0
&& offset < ptoa(dev->dma->page_count))
return DRM(dma_mmap)(kdev, offset, paddr, prot);
/* A sequential search of a linked list is
fine here because: 1) there will only be
about 5-10 entries in the list and, 2) a
DRI client only has to do this mapping
once, so it doesn't have to be optimized
for performance, even if the list was a
bit longer. */
TAILQ_FOREACH(listentry, dev->maplist, link) {
map = listentry->map;
/* DRM_DEBUG("considering 0x%x..0x%x\n", map->offset, map->offset + map->size - 1);*/
if (offset >= map->offset
&& offset < map->offset + map->size) break;
}
if (!listentry) {
DRM_DEBUG("can't find map\n");
return -1;
}
if (((map->flags&_DRM_RESTRICTED) && suser(DRM_OS_CURPROC))) {
DRM_DEBUG("restricted map\n");
return -1;
}
switch (map->type) {
case _DRM_FRAME_BUFFER:
case _DRM_REGISTERS:
case _DRM_AGP:
*paddr = offset;
return 0;
case _DRM_SHM:
*paddr = vtophys(offset);
return 0;
default:
return -1; /* This should never happen. */
}
DRM_DEBUG("bailing out\n");
return -1;
}