X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fchar%2Fdrm%2Fdrm_vm.h;h=1601447d8f94dac5eb7add0439c4c1971ddcc52d;hb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;hp=cf641664a92cebe79ae136a7f2068f3773fdd84e;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/drivers/char/drm/drm_vm.h b/drivers/char/drm/drm_vm.h index cf641664a..1601447d8 100644 --- a/drivers/char/drm/drm_vm.h +++ b/drivers/char/drm/drm_vm.h @@ -35,50 +35,21 @@ #include "drmP.h" -/** AGP virtual memory operations */ -struct vm_operations_struct DRM(vm_ops) = { - .nopage = DRM(vm_nopage), - .open = DRM(vm_open), - .close = DRM(vm_close), -}; - -/** Shared virtual memory operations */ -struct vm_operations_struct DRM(vm_shm_ops) = { - .nopage = DRM(vm_shm_nopage), - .open = DRM(vm_open), - .close = DRM(vm_shm_close), -}; - -/** DMA virtual memory operations */ -struct vm_operations_struct DRM(vm_dma_ops) = { - .nopage = DRM(vm_dma_nopage), - .open = DRM(vm_open), - .close = DRM(vm_close), -}; - -/** Scatter-gather virtual memory operations */ -struct vm_operations_struct DRM(vm_sg_ops) = { - .nopage = DRM(vm_sg_nopage), - .open = DRM(vm_open), - .close = DRM(vm_close), -}; /** * \c nopage method for AGP virtual memory. * * \param vma virtual memory area. * \param address access address. - * \param write_access sharing. * \return pointer to the page structure. * * Find the right map and if it's AGP memory find the real physical page to * map, get the page, increment the use count and return it. */ -struct page *DRM(vm_nopage)(struct vm_area_struct *vma, - unsigned long address, - int *type) +#if __OS_HAS_AGP +static __inline__ struct page *DRM(do_vm_nopage)(struct vm_area_struct *vma, + unsigned long address) { -#if __REALLY_HAVE_AGP drm_file_t *priv = vma->vm_file->private_data; drm_device_t *dev = priv->dev; drm_map_t *map = NULL; @@ -88,6 +59,8 @@ struct page *DRM(vm_nopage)(struct vm_area_struct *vma, /* * Find the right map */ + if (!drm_core_has_AGP(dev)) + goto vm_nopage_error; if(!dev->agp || !dev->agp->cant_use_aperture) goto vm_nopage_error; @@ -104,7 +77,7 @@ struct page *DRM(vm_nopage)(struct vm_area_struct *vma, struct drm_agp_mem *agpmem; struct page *page; -#if __alpha__ +#ifdef __alpha__ /* * Adjust to a bus-relative address */ @@ -131,32 +104,33 @@ struct page *DRM(vm_nopage)(struct vm_area_struct *vma, DRM_DEBUG("baddr = 0x%lx page = 0x%p, offset = 0x%lx, count=%d\n", baddr, __va(agpmem->memory->memory[offset]), offset, - atomic_read(&page->count)); + page_count(page)); - if (type) - *type = VM_FAULT_MINOR; return page; } vm_nopage_error: -#endif /* __REALLY_HAVE_AGP */ - return NOPAGE_SIGBUS; /* Disallow mremap */ } +#else /* __OS_HAS_AGP */ +static __inline__ struct page *DRM(do_vm_nopage)(struct vm_area_struct *vma, + unsigned long address) +{ + return NOPAGE_SIGBUS; +} +#endif /* __OS_HAS_AGP */ /** * \c nopage method for shared virtual memory. * * \param vma virtual memory area. * \param address access address. - * \param write_access sharing. * \return pointer to the page structure. * * Get the the mapping, find the real physical page to map, get the page, and * return it. */ -struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma, - unsigned long address, - int *type) +static __inline__ struct page *DRM(do_vm_shm_nopage)(struct vm_area_struct *vma, + unsigned long address) { drm_map_t *map = (drm_map_t *)vma->vm_private_data; unsigned long offset; @@ -172,8 +146,6 @@ struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma, if (!page) return NOPAGE_OOM; get_page(page); - if (type) - *type = VM_FAULT_MINOR; DRM_DEBUG("shm_nopage 0x%lx\n", address); return page; @@ -236,15 +208,13 @@ void DRM(vm_shm_close)(struct vm_area_struct *vma) switch (map->type) { case _DRM_REGISTERS: case _DRM_FRAME_BUFFER: -#if __REALLY_HAVE_MTRR - if (map->mtrr >= 0) { + if (drm_core_has_MTRR(dev) && map->mtrr >= 0) { int retcode; retcode = mtrr_del(map->mtrr, map->offset, map->size); DRM_DEBUG("mtrr_del = %d\n", retcode); } -#endif DRM(ioremapfree)(map->handle, map->size, dev); break; case _DRM_SHM: @@ -265,14 +235,12 @@ void DRM(vm_shm_close)(struct vm_area_struct *vma) * * \param vma virtual memory area. * \param address access address. - * \param write_access sharing. * \return pointer to the page structure. * * Determine the page number from the page offset and get it from drm_device_dma::pagelist. */ -struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma, - unsigned long address, - int *type) +static __inline__ struct page *DRM(do_vm_dma_nopage)(struct vm_area_struct *vma, + unsigned long address) { drm_file_t *priv = vma->vm_file->private_data; drm_device_t *dev = priv->dev; @@ -291,8 +259,6 @@ struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma, (offset & (~PAGE_MASK)))); get_page(page); - if (type) - *type = VM_FAULT_MINOR; DRM_DEBUG("dma_nopage 0x%lx (page %lu)\n", address, page_nr); return page; @@ -303,14 +269,12 @@ struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma, * * \param vma virtual memory area. * \param address access address. - * \param write_access sharing. * \return pointer to the page structure. * * Determine the map offset from the page offset and get it from drm_sg_mem::pagelist. */ -struct page *DRM(vm_sg_nopage)(struct vm_area_struct *vma, - unsigned long address, - int *type) +static __inline__ struct page *DRM(do_vm_sg_nopage)(struct vm_area_struct *vma, + unsigned long address) { drm_map_t *map = (drm_map_t *)vma->vm_private_data; drm_file_t *priv = vma->vm_file->private_data; @@ -331,12 +295,99 @@ struct page *DRM(vm_sg_nopage)(struct vm_area_struct *vma, page_offset = (offset >> PAGE_SHIFT) + (map_offset >> PAGE_SHIFT); page = entry->pagelist[page_offset]; get_page(page); - if (type) - *type = VM_FAULT_MINOR; return page; } + +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) + +static struct page *DRM(vm_nopage)(struct vm_area_struct *vma, + unsigned long address, + int *type) { + if (type) *type = VM_FAULT_MINOR; + return DRM(do_vm_nopage)(vma, address); +} + +static struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma, + unsigned long address, + int *type) { + if (type) *type = VM_FAULT_MINOR; + return DRM(do_vm_shm_nopage)(vma, address); +} + +static struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma, + unsigned long address, + int *type) { + if (type) *type = VM_FAULT_MINOR; + return DRM(do_vm_dma_nopage)(vma, address); +} + +static struct page *DRM(vm_sg_nopage)(struct vm_area_struct *vma, + unsigned long address, + int *type) { + if (type) *type = VM_FAULT_MINOR; + return DRM(do_vm_sg_nopage)(vma, address); +} + +#else /* LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0) */ + +static struct page *DRM(vm_nopage)(struct vm_area_struct *vma, + unsigned long address, + int unused) { + return DRM(do_vm_nopage)(vma, address); +} + +static struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma, + unsigned long address, + int unused) { + return DRM(do_vm_shm_nopage)(vma, address); +} + +static struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma, + unsigned long address, + int unused) { + return DRM(do_vm_dma_nopage)(vma, address); +} + +static struct page *DRM(vm_sg_nopage)(struct vm_area_struct *vma, + unsigned long address, + int unused) { + return DRM(do_vm_sg_nopage)(vma, address); +} + +#endif + + +/** AGP virtual memory operations */ +static struct vm_operations_struct DRM(vm_ops) = { + .nopage = DRM(vm_nopage), + .open = DRM(vm_open), + .close = DRM(vm_close), +}; + +/** Shared virtual memory operations */ +static struct vm_operations_struct DRM(vm_shm_ops) = { + .nopage = DRM(vm_shm_nopage), + .open = DRM(vm_open), + .close = DRM(vm_shm_close), +}; + +/** DMA virtual memory operations */ +static struct vm_operations_struct DRM(vm_dma_ops) = { + .nopage = DRM(vm_dma_nopage), + .open = DRM(vm_open), + .close = DRM(vm_close), +}; + +/** Scatter-gather virtual memory operations */ +static struct vm_operations_struct DRM(vm_sg_ops) = { + .nopage = DRM(vm_sg_nopage), + .open = DRM(vm_open), + .close = DRM(vm_close), +}; + + /** * \c open method for shared virtual memory. * @@ -442,18 +493,19 @@ int DRM(mmap_dma)(struct file *filp, struct vm_area_struct *vma) return 0; } -#ifndef DRIVER_GET_MAP_OFS -#define DRIVER_GET_MAP_OFS() (map->offset) -#endif +unsigned long DRM(core_get_map_ofs)(drm_map_t *map) +{ + return map->offset; +} -#ifndef DRIVER_GET_REG_OFS +unsigned long DRM(core_get_reg_ofs)(struct drm_device *dev) +{ #ifdef __alpha__ -#define DRIVER_GET_REG_OFS() (dev->hose->dense_mem_base - \ - dev->hose->mem_space->start) + return dev->hose->dense_mem_base - dev->hose->mem_space->start; #else -#define DRIVER_GET_REG_OFS() 0 -#endif + return 0; #endif +} /** * mmap DMA memory. @@ -487,7 +539,7 @@ int DRM(mmap)(struct file *filp, struct vm_area_struct *vma) * --BenH. */ if (!VM_OFFSET(vma) -#if __REALLY_HAVE_AGP +#if __OS_HAS_AGP && (!dev->agp || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE) #endif ) @@ -506,7 +558,7 @@ int DRM(mmap)(struct file *filp, struct vm_area_struct *vma) r_list = list_entry(list, drm_map_list_t, head); map = r_list->map; if (!map) continue; - off = DRIVER_GET_MAP_OFS(); + off = dev->fn_tbl.get_map_ofs(map); if (off == VM_OFFSET(vma)) break; } @@ -531,8 +583,7 @@ int DRM(mmap)(struct file *filp, struct vm_area_struct *vma) switch (map->type) { case _DRM_AGP: -#if __REALLY_HAVE_AGP - if (dev->agp->cant_use_aperture) { + if (drm_core_has_AGP(dev) && dev->agp->cant_use_aperture) { /* * On some platforms we can't talk to bus dma address from the CPU, so for * memory of type DRM_AGP, we'll deal with sorting out the real physical @@ -544,7 +595,6 @@ int DRM(mmap)(struct file *filp, struct vm_area_struct *vma) vma->vm_ops = &DRM(vm_ops); break; } -#endif /* fall through to _DRM_FRAME_BUFFER... */ case _DRM_FRAME_BUFFER: case _DRM_REGISTERS: @@ -563,7 +613,7 @@ int DRM(mmap)(struct file *filp, struct vm_area_struct *vma) if (map->type != _DRM_AGP) vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); #endif - offset = DRIVER_GET_REG_OFS(); + offset = dev->fn_tbl.get_reg_ofs(dev); #ifdef __sparc__ if (io_remap_page_range(DRM_RPR_ARG(vma) vma->vm_start, VM_OFFSET(vma) + offset,