2003-03-04 23:04:50 -07:00
|
|
|
/*
|
2003-03-11 13:51:28 -07:00
|
|
|
* $FreeBSD: src/sys/dev/drm/drm_vm.h,v 1.4 2003/03/09 02:08:28 anholt Exp $
|
2003-03-04 23:04:50 -07:00
|
|
|
*/
|
2002-01-27 11:23:04 -07:00
|
|
|
|
2003-03-04 23:04:50 -07:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
|
|
|
|
static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, vm_offset_t *paddr,
|
|
|
|
int prot)
|
|
|
|
#elif defined(__FreeBSD__)
|
2002-01-27 11:23:04 -07:00
|
|
|
static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot)
|
2002-07-05 02:31:11 -06:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
static paddr_t DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot)
|
|
|
|
#endif
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
2002-07-05 02:31:11 -06:00
|
|
|
DRM_DEVICE;
|
2002-01-27 11:23:04 -07:00
|
|
|
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];
|
|
|
|
|
2002-07-05 02:31:11 -06:00
|
|
|
DRM_DEBUG("0x%08lx (page %lu) => 0x%08lx\n", (long)offset, page, physical);
|
2003-03-04 23:04:50 -07:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
|
|
|
|
*paddr = physical;
|
|
|
|
return 0;
|
|
|
|
#else
|
2002-01-27 11:23:04 -07:00
|
|
|
return atop(physical);
|
2003-03-04 23:04:50 -07:00
|
|
|
#endif
|
2002-01-27 11:23:04 -07:00
|
|
|
}
|
|
|
|
|
2003-03-04 23:04:50 -07:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
|
|
|
|
int DRM(mmap)(dev_t kdev, vm_offset_t offset, vm_offset_t *paddr,
|
|
|
|
int prot)
|
|
|
|
#elif defined(__FreeBSD__)
|
2002-01-27 11:23:04 -07:00
|
|
|
int DRM(mmap)(dev_t kdev, vm_offset_t offset, int prot)
|
2002-07-05 02:31:11 -06:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
paddr_t DRM(mmap)(dev_t kdev, off_t offset, int prot)
|
|
|
|
#endif
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
2002-07-05 02:31:11 -06:00
|
|
|
DRM_DEVICE;
|
2003-02-21 16:23:09 -07:00
|
|
|
drm_local_map_t *map = NULL;
|
2002-01-27 11:23:04 -07:00
|
|
|
drm_map_list_entry_t *listentry=NULL;
|
2002-07-05 02:31:11 -06:00
|
|
|
drm_file_t *priv;
|
2002-01-27 11:23:04 -07:00
|
|
|
|
2002-07-05 02:31:11 -06:00
|
|
|
priv = DRM(find_file_by_proc)(dev, DRM_CURPROC);
|
2002-01-27 11:23:04 -07:00
|
|
|
if (!priv) {
|
|
|
|
DRM_DEBUG("can't find authenticator\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2003-04-01 11:53:24 -07:00
|
|
|
if (!priv->authenticated)
|
|
|
|
return DRM_ERR(EACCES);
|
2002-01-27 11:23:04 -07:00
|
|
|
|
|
|
|
if (dev->dma
|
|
|
|
&& offset >= 0
|
|
|
|
&& offset < ptoa(dev->dma->page_count))
|
2003-03-04 23:04:50 -07:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
|
|
|
|
return DRM(dma_mmap)(kdev, offset, paddr, prot);
|
|
|
|
#else
|
2002-01-27 11:23:04 -07:00
|
|
|
return DRM(dma_mmap)(kdev, offset, prot);
|
2003-03-04 23:04:50 -07:00
|
|
|
#endif
|
2002-01-27 11:23:04 -07:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
2002-07-05 02:31:11 -06:00
|
|
|
if (((map->flags&_DRM_RESTRICTED) && DRM_SUSER(DRM_CURPROC))) {
|
2002-01-27 11:23:04 -07:00
|
|
|
DRM_DEBUG("restricted map\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (map->type) {
|
|
|
|
case _DRM_FRAME_BUFFER:
|
|
|
|
case _DRM_REGISTERS:
|
|
|
|
case _DRM_AGP:
|
2003-03-04 23:04:50 -07:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
|
|
|
|
*paddr = offset;
|
|
|
|
return 0;
|
|
|
|
#else
|
2002-01-27 11:23:04 -07:00
|
|
|
return atop(offset);
|
2003-03-04 23:04:50 -07:00
|
|
|
#endif
|
2002-07-05 02:31:11 -06:00
|
|
|
case _DRM_SCATTER_GATHER:
|
2002-01-27 11:23:04 -07:00
|
|
|
case _DRM_SHM:
|
2003-03-04 23:04:50 -07:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
|
|
|
|
*paddr = vtophys(offset);
|
|
|
|
return 0;
|
|
|
|
#else
|
2002-01-27 11:23:04 -07:00
|
|
|
return atop(vtophys(offset));
|
2003-03-04 23:04:50 -07:00
|
|
|
#endif
|
2002-01-27 11:23:04 -07:00
|
|
|
default:
|
|
|
|
return -1; /* This should never happen. */
|
|
|
|
}
|
|
|
|
DRM_DEBUG("bailing out\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|