From 4499ea42eae887c45403cd9ea364fccf311fee8e Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sat, 4 Sep 2004 23:21:40 +0000 Subject: [PATCH] Fixup OS_HAS_AGP/OS_HAS_MTRR along lines of patches going to kernel, as suggested by Arjan.. Signed-off-by: Dave Airlie --- linux-core/drmP.h | 32 +++++++++++------ linux-core/drm_bufs.c | 17 ++++----- linux-core/drm_drv.c | 74 +++++++++++++++++---------------------- linux-core/drm_memory.h | 31 ++++++++++++---- linux-core/drm_os_linux.h | 25 +++++++++++++ linux-core/drm_vm.c | 21 +++++------ linux/drmP.h | 32 +++++++++++------ linux/drm_bufs.h | 17 ++++----- linux/drm_drv.h | 74 +++++++++++++++++---------------------- linux/drm_memory.h | 31 ++++++++++++---- linux/drm_os_linux.h | 25 +++++++++++++ linux/drm_vm.h | 21 +++++------ 12 files changed, 238 insertions(+), 162 deletions(-) diff --git a/linux-core/drmP.h b/linux-core/drmP.h index 495277f6..1488544a 100644 --- a/linux-core/drmP.h +++ b/linux-core/drmP.h @@ -83,6 +83,9 @@ #include #include "drm.h" +#define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE))) +#define __OS_HAS_MTRR (defined(CONFIG_MTRR)) + #include "drm_os_linux.h" /* If you want the memory alloc debug functionality, change define below */ @@ -104,11 +107,8 @@ #define DRIVER_IRQ_VBL 0x200 #define DRIVER_DMA_QUEUE 0x800 -#define __OS_HAS_AGP (defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)) -#define __OS_HAS_MTRR (defined(CONFIG_MTRR)) /*@}*/ - /***********************************************************************/ /** \name Begin the DRM... */ /*@{*/ @@ -431,7 +431,6 @@ typedef struct drm_device_dma { /*@}*/ } drm_device_dma_t; -#if __OS_HAS_AGP /** * AGP memory entry. Stored as a doubly linked list. */ @@ -460,7 +459,6 @@ typedef struct drm_agp_head { int cant_use_aperture; unsigned long page_mask; } drm_agp_head_t; -#endif /** * Scatter-gather memory. @@ -654,9 +652,7 @@ typedef struct drm_device { wait_queue_head_t buf_readers; /**< Processes waiting to read */ wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */ -#if __OS_HAS_AGP drm_agp_head_t *agp; /**< AGP data */ -#endif struct pci_dev *pdev; /**< PCI device structure */ int pci_domain; /**< PCI bus domain number */ @@ -688,6 +684,24 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev, int feature return ((dev->driver_features & feature) ? 1 : 0); } +#if __OS_HAS_AGP +static inline int drm_core_has_AGP(struct drm_device *dev) +{ + return drm_core_check_feature(dev, DRIVER_USE_AGP); +} +#else +#define drm_core_has_AGP(dev) (0) +#endif + +#if __OS_HAS_MTRR +static inline int drm_core_has_MTRR(struct drm_device *dev) +{ + return drm_core_check_feature(dev, DRIVER_USE_MTRR); +} +#else +#define drm_core_has_MTRR(dev) (0) +#endif + extern void DRM(driver_register_fns)(struct drm_device *dev); /******************************************************************/ @@ -744,12 +758,10 @@ extern void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size, drm_device_t *dev); extern void DRM(ioremapfree)(void *pt, unsigned long size, drm_device_t *dev); -#if __OS_HAS_AGP extern DRM_AGP_MEM *DRM(alloc_agp)(int pages, u32 type); extern int DRM(free_agp)(DRM_AGP_MEM *handle, int pages); extern int DRM(bind_agp)(DRM_AGP_MEM *handle, unsigned int start); extern int DRM(unbind_agp)(DRM_AGP_MEM *handle); -#endif /* Misc. IOCTL support (drm_ioctl.h) */ extern int DRM(irq_by_busid)(struct inode *inode, struct file *filp, @@ -866,7 +878,6 @@ extern int DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq); extern void DRM(vbl_send_signals)( drm_device_t *dev ); -#if __OS_HAS_AGP /* AGP/GART support (drm_agpsupport.h) */ extern drm_agp_head_t *DRM(agp_init)(void); extern void DRM(agp_uninit)(void); @@ -891,7 +902,6 @@ extern DRM_AGP_MEM *DRM(agp_allocate_memory)(size_t pages, u32 type); extern int DRM(agp_free_memory)(DRM_AGP_MEM *handle); extern int DRM(agp_bind_memory)(DRM_AGP_MEM *handle, off_t start); extern int DRM(agp_unbind_memory)(DRM_AGP_MEM *handle); -#endif /* Stub support (drm_stub.h) */ int DRM(stub_register)(const char *name, diff --git a/linux-core/drm_bufs.c b/linux-core/drm_bufs.c index 9d837332..94fdaff1 100644 --- a/linux-core/drm_bufs.c +++ b/linux-core/drm_bufs.c @@ -102,15 +102,14 @@ int DRM(initmap)( drm_device_t *dev, unsigned int offset, unsigned int size, int #ifdef __alpha__ map->offset += dev->hose->mem_space->start; #endif -#if __OS_HAS_MTRR - if ( drm_core_check_feature(dev, DRIVER_USE_MTRR) ) { + if (drm_core_has_MTRR(dev)) { if ( map->type == _DRM_FRAME_BUFFER || (map->flags & _DRM_WRITE_COMBINING) ) { map->mtrr = mtrr_add( map->offset, map->size, MTRR_TYPE_WRCOMB, 1 ); } } -#endif + if (map->type == _DRM_REGISTERS) map->handle = DRM(ioremap)( map->offset, map->size, dev ); @@ -200,15 +199,13 @@ int DRM(addmap)( struct inode *inode, struct file *filp, #ifdef __alpha__ map->offset += dev->hose->mem_space->start; #endif -#if __OS_HAS_MTRR - if (drm_core_check_feature(dev, DRIVER_USE_MTRR)) { + if (drm_core_has_MTRR(dev)) { if ( map->type == _DRM_FRAME_BUFFER || (map->flags & _DRM_WRITE_COMBINING) ) { map->mtrr = mtrr_add( map->offset, map->size, MTRR_TYPE_WRCOMB, 1 ); } } -#endif if (map->type == _DRM_REGISTERS) map->handle = DRM(ioremap)( map->offset, map->size, dev ); @@ -234,9 +231,8 @@ int DRM(addmap)( struct inode *inode, struct file *filp, dev->lock.hw_lock = map->handle; /* Pointer to lock */ } break; -#if __OS_HAS_AGP case _DRM_AGP: - if (drm_core_check_feature(dev, DRIVER_USE_AGP)) { + if (drm_core_has_AGP(dev)) { #ifdef __alpha__ map->offset += dev->hose->mem_space->start; #endif @@ -244,7 +240,6 @@ int DRM(addmap)( struct inode *inode, struct file *filp, map->mtrr = dev->agp->agp_mtrr; /* for getmap */ } break; -#endif case _DRM_SCATTER_GATHER: if (!dev->sg) { DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); @@ -1264,8 +1259,8 @@ int DRM(mapbufs)( struct inode *inode, struct file *filp, return -EFAULT; if ( request.count >= dma->buf_count ) { - if (( drm_core_check_feature(dev, DRIVER_USE_AGP) && (dma->flags & _DRM_DMA_USE_AGP)) || - ( drm_core_check_feature(dev, DRIVER_SG) && (dma->flags & _DRM_DMA_USE_SG)) ) { + if ((drm_core_has_AGP(dev) && (dma->flags & _DRM_DMA_USE_AGP)) || + (drm_core_check_feature(dev, DRIVER_SG) && (dma->flags & _DRM_DMA_USE_SG))) { drm_map_t *map = dev->agp_buffer_map; if ( !map ) { diff --git a/linux-core/drm_drv.c b/linux-core/drm_drv.c index 8f42e357..2c1719da 100644 --- a/linux-core/drm_drv.c +++ b/linux-core/drm_drv.c @@ -347,9 +347,8 @@ static int DRM(takedown)( drm_device_t *dev ) dev->magiclist[i].head = dev->magiclist[i].tail = NULL; } -#if __OS_HAS_AGP /* Clear AGP information */ - if ( drm_core_check_feature(dev, DRIVER_USE_AGP) && dev->agp ) { + if ( drm_core_has_AGP(dev) && dev->agp ) { drm_agp_mem_t *entry; drm_agp_mem_t *nexte; @@ -368,7 +367,6 @@ static int DRM(takedown)( drm_device_t *dev ) dev->agp->acquired = 0; dev->agp->enabled = 0; } -#endif /* Clear vma list (only built for debugging) */ if ( dev->vmalist ) { @@ -509,8 +507,7 @@ static int drm_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if ((retcode = dev->fn_tbl.preinit(dev, ent->driver_data))) goto error_out_unreg; -#if __OS_HAS_AGP - if (drm_core_check_feature(dev, DRIVER_USE_AGP)) { + if (drm_core_has_AGP(dev)) { dev->agp = DRM(agp_init)(); if ( drm_core_check_feature(dev, DRIVER_REQUIRE_AGP) && dev->agp == NULL ) { DRM_ERROR( "Cannot initialize the agpgart module.\n" ); @@ -518,8 +515,8 @@ static int drm_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto error_out_unreg; } -#if __OS_HAS_MTRR - if (drm_core_check_feature(dev, DRIVER_USE_MTRR)) { + + if (drm_core_has_MTRR(dev)) { if (dev->agp) dev->agp->agp_mtrr = mtrr_add( dev->agp->agp_info.aper_base, dev->agp->agp_info.aper_size*1024*1024, @@ -527,8 +524,7 @@ static int drm_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 1 ); } } -#endif -#endif + retcode = DRM(ctxbitmap_init)( dev ); if( retcode ) { DRM_ERROR( "Cannot allocate memory for context bitmap.\n" ); @@ -572,7 +568,7 @@ static int drm_probe(struct pci_dev *pdev, const struct pci_device_id *ent) static void __exit drm_cleanup_pci(struct pci_dev *pdev) { drm_device_t *dev = pci_get_drvdata(pdev); - + pci_set_drvdata(pdev, NULL); drm_cleanup(dev); } @@ -680,8 +676,7 @@ static void __exit drm_cleanup( drm_device_t *dev ) break; case _DRM_FRAME_BUFFER: -#if __OS_HAS_MTRR - if ( drm_core_check_feature(dev, DRIVER_USE_MTRR)) { + if ( drm_core_has_MTRR(dev)) { if ( map->mtrr >= 0 ) { int retcode; retcode = mtrr_del( map->mtrr, @@ -690,7 +685,6 @@ static void __exit drm_cleanup( drm_device_t *dev ) DRM_DEBUG( "mtrr_del=%d\n", retcode ); } } -#endif break; case _DRM_SHM: @@ -719,22 +713,19 @@ static void __exit drm_cleanup( drm_device_t *dev ) DRM(ctxbitmap_cleanup)( dev ); -#if __OS_HAS_AGP -#if __OS_HAS_MTRR - if ( drm_core_check_feature(dev, DRIVER_USE_MTRR) && dev->agp && dev->agp->agp_mtrr >= 0 ) { + if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && dev->agp && dev->agp->agp_mtrr >= 0) { int retval; retval = mtrr_del( dev->agp->agp_mtrr, dev->agp->agp_info.aper_base, dev->agp->agp_info.aper_size*1024*1024 ); DRM_DEBUG( "mtrr_del=%d\n", retval ); } -#endif - if ( drm_core_check_feature(dev, DRIVER_USE_AGP) && dev->agp ) { + + if (drm_core_has_AGP(dev) && dev->agp ) { DRM(agp_uninit)(); DRM(free)( dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS ); dev->agp = NULL; } -#endif if (dev->fn_tbl.postcleanup) dev->fn_tbl.postcleanup(dev); } @@ -1129,29 +1120,28 @@ int DRM(lock)( struct inode *inode, struct file *filp, current->state = TASK_RUNNING; remove_wait_queue( &dev->lock.lock_queue, &entry ); - if ( !ret ) { - sigemptyset( &dev->sigmask ); - sigaddset( &dev->sigmask, SIGSTOP ); - sigaddset( &dev->sigmask, SIGTSTP ); - sigaddset( &dev->sigmask, SIGTTIN ); - sigaddset( &dev->sigmask, SIGTTOU ); - dev->sigdata.context = lock.context; - dev->sigdata.lock = dev->lock.hw_lock; - block_all_signals( DRM(notifier), - &dev->sigdata, &dev->sigmask ); - - if (dev->fn_tbl.dma_ready && (lock.flags & _DRM_LOCK_READY)) - dev->fn_tbl.dma_ready(dev); - - if ( dev->fn_tbl.dma_quiescent && (lock.flags & _DRM_LOCK_QUIESCENT )) - return dev->fn_tbl.dma_quiescent(dev); - - - if ( dev->fn_tbl.kernel_context_switch && dev->last_context != lock.context ) { - dev->fn_tbl.kernel_context_switch(dev, dev->last_context, - lock.context); - } - } + sigemptyset( &dev->sigmask ); + sigaddset( &dev->sigmask, SIGSTOP ); + sigaddset( &dev->sigmask, SIGTSTP ); + sigaddset( &dev->sigmask, SIGTTIN ); + sigaddset( &dev->sigmask, SIGTTOU ); + dev->sigdata.context = lock.context; + dev->sigdata.lock = dev->lock.hw_lock; + block_all_signals( DRM(notifier), + &dev->sigdata, &dev->sigmask ); + + if (dev->fn_tbl.dma_ready && (lock.flags & _DRM_LOCK_READY)) + dev->fn_tbl.dma_ready(dev); + + if ( dev->fn_tbl.dma_quiescent && (lock.flags & _DRM_LOCK_QUIESCENT )) + return dev->fn_tbl.dma_quiescent(dev); + + + if ( dev->fn_tbl.kernel_context_switch && dev->last_context != lock.context ) { + dev->fn_tbl.kernel_context_switch(dev, dev->last_context, + lock.context); + } + DRM_DEBUG( "%d %s\n", lock.context, ret ? "interrupted" : "has lock" ); diff --git a/linux-core/drm_memory.h b/linux-core/drm_memory.h index 38084ccc..2cdccb13 100644 --- a/linux-core/drm_memory.h +++ b/linux-core/drm_memory.h @@ -139,12 +139,29 @@ drm_follow_page (void *vaddr) return pte_pfn(*ptep) << PAGE_SHIFT; } -#endif /* __OS_HAS_AGP && defined(VMAP_4_ARGS) */ +#else /* __OS_HAS_AGP */ + +static inline drm_map_t *drm_lookup_map(unsigned long offset, unsigned long size, drm_device_t *dev) +{ + return NULL; +} + +static inline void *agp_remap(unsigned long offset, unsigned long size, drm_device_t *dev) +{ + return NULL; +} + +static inline unsigned long drm_follow_page (void *vaddr) +{ + return 0; +} + +#endif static inline void *drm_ioremap(unsigned long offset, unsigned long size, drm_device_t *dev) { -#if __OS_HAS_AGP && defined(VMAP_4_ARGS) - if ( drm_core_check_feature(dev, DRIVER_USE_AGP) && dev->agp && dev->agp->cant_use_aperture) { +#if defined(VMAP_4_ARGS) + if ( drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) { drm_map_t *map = drm_lookup_map(offset, size, dev); if (map && map->type == _DRM_AGP) @@ -158,8 +175,8 @@ static inline void *drm_ioremap(unsigned long offset, unsigned long size, drm_de static inline void *drm_ioremap_nocache(unsigned long offset, unsigned long size, drm_device_t *dev) { -#if __OS_HAS_AGP&& defined(VMAP_4_ARGS) - if ( drm_core_check_feature(dev, DRIVER_USE_AGP) && dev->agp && dev->agp->cant_use_aperture) { +#if defined(VMAP_4_ARGS) + if ( drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) { drm_map_t *map = drm_lookup_map(offset, size, dev); if (map && map->type == _DRM_AGP) @@ -172,13 +189,13 @@ static inline void *drm_ioremap_nocache(unsigned long offset, unsigned long size static inline void drm_ioremapfree(void *pt, unsigned long size, drm_device_t *dev) { -#if __OS_HAS_AGP && defined(VMAP_4_ARGS) +#if defined(VMAP_4_ARGS) /* * This is a bit ugly. It would be much cleaner if the DRM API would use separate * routines for handling mappings in the AGP space. Hopefully this can be done in * a future revision of the interface... */ - if (drm_core_check_feature(dev, DRIVER_USE_AGP) && dev->agp && dev->agp->cant_use_aperture + if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture && ((unsigned long) pt >= VMALLOC_START && (unsigned long) pt < VMALLOC_END)) { unsigned long offset; diff --git a/linux-core/drm_os_linux.h b/linux-core/drm_os_linux.h index bf58a1c2..ab16d7b3 100644 --- a/linux-core/drm_os_linux.h +++ b/linux-core/drm_os_linux.h @@ -47,6 +47,7 @@ typedef void irqreturn_t; #endif /** AGP types */ +#if __OS_HAS_AGP #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,70) #define DRM_AGP_MEM agp_memory #define DRM_AGP_KERN agp_kern_info @@ -54,6 +55,30 @@ typedef void irqreturn_t; #define DRM_AGP_MEM struct agp_memory #define DRM_AGP_KERN struct agp_kern_info #endif +#else +/* define some dummy types for non AGP supporting kernels */ +struct no_agp_kern { + unsigned long aper_base; + unsigned long aper_size; +}; +#define DRM_AGP_MEM int +#define DRM_AGP_KERN struct no_agp_kern +#endif + +#if !(__OS_HAS_MTRR) +static __inline__ int mtrr_add (unsigned long base, unsigned long size, + unsigned int type, char increment) +{ + return -ENODEV; +} + +static __inline__ int mtrr_del (int reg, unsigned long base, + unsigned long size) +{ + return -ENODEV; +} +#define MTRR_TYPE_WRCOMB 1 +#endif /** Task queue handler arguments */ #define DRM_TASKQUEUE_ARGS void *arg diff --git a/linux-core/drm_vm.c b/linux-core/drm_vm.c index 46eaf569..b5b5e2ea 100644 --- a/linux-core/drm_vm.c +++ b/linux-core/drm_vm.c @@ -46,10 +46,10 @@ * 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. */ +#if __OS_HAS_AGP static __inline__ struct page *DRM(do_vm_nopage)(struct vm_area_struct *vma, unsigned long address) { -#if __OS_HAS_AGP drm_file_t *priv = vma->vm_file->private_data; drm_device_t *dev = priv->dev; drm_map_t *map = NULL; @@ -59,7 +59,7 @@ static __inline__ struct page *DRM(do_vm_nopage)(struct vm_area_struct *vma, /* * Find the right map */ - if (!drm_core_check_feature(dev, DRIVER_USE_AGP)) + if (!drm_core_has_AGP(dev)) goto vm_nopage_error; if(!dev->agp || !dev->agp->cant_use_aperture) goto vm_nopage_error; @@ -112,10 +112,15 @@ static __inline__ struct page *DRM(do_vm_nopage)(struct vm_area_struct *vma, return page; } vm_nopage_error: -#endif /* __OS_HAS_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. @@ -206,15 +211,13 @@ void DRM(vm_shm_close)(struct vm_area_struct *vma) switch (map->type) { case _DRM_REGISTERS: case _DRM_FRAME_BUFFER: -#if __OS_HAS_MTRR - if (drm_core_check_feature(dev, DRIVER_USE_MTRR) && 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: @@ -583,8 +586,7 @@ int DRM(mmap)(struct file *filp, struct vm_area_struct *vma) switch (map->type) { case _DRM_AGP: -#if __OS_HAS_AGP - if (drm_core_check_feature(dev, DRIVER_USE_AGP) && 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 @@ -596,7 +598,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: diff --git a/linux/drmP.h b/linux/drmP.h index 495277f6..1488544a 100644 --- a/linux/drmP.h +++ b/linux/drmP.h @@ -83,6 +83,9 @@ #include #include "drm.h" +#define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE))) +#define __OS_HAS_MTRR (defined(CONFIG_MTRR)) + #include "drm_os_linux.h" /* If you want the memory alloc debug functionality, change define below */ @@ -104,11 +107,8 @@ #define DRIVER_IRQ_VBL 0x200 #define DRIVER_DMA_QUEUE 0x800 -#define __OS_HAS_AGP (defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)) -#define __OS_HAS_MTRR (defined(CONFIG_MTRR)) /*@}*/ - /***********************************************************************/ /** \name Begin the DRM... */ /*@{*/ @@ -431,7 +431,6 @@ typedef struct drm_device_dma { /*@}*/ } drm_device_dma_t; -#if __OS_HAS_AGP /** * AGP memory entry. Stored as a doubly linked list. */ @@ -460,7 +459,6 @@ typedef struct drm_agp_head { int cant_use_aperture; unsigned long page_mask; } drm_agp_head_t; -#endif /** * Scatter-gather memory. @@ -654,9 +652,7 @@ typedef struct drm_device { wait_queue_head_t buf_readers; /**< Processes waiting to read */ wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */ -#if __OS_HAS_AGP drm_agp_head_t *agp; /**< AGP data */ -#endif struct pci_dev *pdev; /**< PCI device structure */ int pci_domain; /**< PCI bus domain number */ @@ -688,6 +684,24 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev, int feature return ((dev->driver_features & feature) ? 1 : 0); } +#if __OS_HAS_AGP +static inline int drm_core_has_AGP(struct drm_device *dev) +{ + return drm_core_check_feature(dev, DRIVER_USE_AGP); +} +#else +#define drm_core_has_AGP(dev) (0) +#endif + +#if __OS_HAS_MTRR +static inline int drm_core_has_MTRR(struct drm_device *dev) +{ + return drm_core_check_feature(dev, DRIVER_USE_MTRR); +} +#else +#define drm_core_has_MTRR(dev) (0) +#endif + extern void DRM(driver_register_fns)(struct drm_device *dev); /******************************************************************/ @@ -744,12 +758,10 @@ extern void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size, drm_device_t *dev); extern void DRM(ioremapfree)(void *pt, unsigned long size, drm_device_t *dev); -#if __OS_HAS_AGP extern DRM_AGP_MEM *DRM(alloc_agp)(int pages, u32 type); extern int DRM(free_agp)(DRM_AGP_MEM *handle, int pages); extern int DRM(bind_agp)(DRM_AGP_MEM *handle, unsigned int start); extern int DRM(unbind_agp)(DRM_AGP_MEM *handle); -#endif /* Misc. IOCTL support (drm_ioctl.h) */ extern int DRM(irq_by_busid)(struct inode *inode, struct file *filp, @@ -866,7 +878,6 @@ extern int DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq); extern void DRM(vbl_send_signals)( drm_device_t *dev ); -#if __OS_HAS_AGP /* AGP/GART support (drm_agpsupport.h) */ extern drm_agp_head_t *DRM(agp_init)(void); extern void DRM(agp_uninit)(void); @@ -891,7 +902,6 @@ extern DRM_AGP_MEM *DRM(agp_allocate_memory)(size_t pages, u32 type); extern int DRM(agp_free_memory)(DRM_AGP_MEM *handle); extern int DRM(agp_bind_memory)(DRM_AGP_MEM *handle, off_t start); extern int DRM(agp_unbind_memory)(DRM_AGP_MEM *handle); -#endif /* Stub support (drm_stub.h) */ int DRM(stub_register)(const char *name, diff --git a/linux/drm_bufs.h b/linux/drm_bufs.h index 9d837332..94fdaff1 100644 --- a/linux/drm_bufs.h +++ b/linux/drm_bufs.h @@ -102,15 +102,14 @@ int DRM(initmap)( drm_device_t *dev, unsigned int offset, unsigned int size, int #ifdef __alpha__ map->offset += dev->hose->mem_space->start; #endif -#if __OS_HAS_MTRR - if ( drm_core_check_feature(dev, DRIVER_USE_MTRR) ) { + if (drm_core_has_MTRR(dev)) { if ( map->type == _DRM_FRAME_BUFFER || (map->flags & _DRM_WRITE_COMBINING) ) { map->mtrr = mtrr_add( map->offset, map->size, MTRR_TYPE_WRCOMB, 1 ); } } -#endif + if (map->type == _DRM_REGISTERS) map->handle = DRM(ioremap)( map->offset, map->size, dev ); @@ -200,15 +199,13 @@ int DRM(addmap)( struct inode *inode, struct file *filp, #ifdef __alpha__ map->offset += dev->hose->mem_space->start; #endif -#if __OS_HAS_MTRR - if (drm_core_check_feature(dev, DRIVER_USE_MTRR)) { + if (drm_core_has_MTRR(dev)) { if ( map->type == _DRM_FRAME_BUFFER || (map->flags & _DRM_WRITE_COMBINING) ) { map->mtrr = mtrr_add( map->offset, map->size, MTRR_TYPE_WRCOMB, 1 ); } } -#endif if (map->type == _DRM_REGISTERS) map->handle = DRM(ioremap)( map->offset, map->size, dev ); @@ -234,9 +231,8 @@ int DRM(addmap)( struct inode *inode, struct file *filp, dev->lock.hw_lock = map->handle; /* Pointer to lock */ } break; -#if __OS_HAS_AGP case _DRM_AGP: - if (drm_core_check_feature(dev, DRIVER_USE_AGP)) { + if (drm_core_has_AGP(dev)) { #ifdef __alpha__ map->offset += dev->hose->mem_space->start; #endif @@ -244,7 +240,6 @@ int DRM(addmap)( struct inode *inode, struct file *filp, map->mtrr = dev->agp->agp_mtrr; /* for getmap */ } break; -#endif case _DRM_SCATTER_GATHER: if (!dev->sg) { DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); @@ -1264,8 +1259,8 @@ int DRM(mapbufs)( struct inode *inode, struct file *filp, return -EFAULT; if ( request.count >= dma->buf_count ) { - if (( drm_core_check_feature(dev, DRIVER_USE_AGP) && (dma->flags & _DRM_DMA_USE_AGP)) || - ( drm_core_check_feature(dev, DRIVER_SG) && (dma->flags & _DRM_DMA_USE_SG)) ) { + if ((drm_core_has_AGP(dev) && (dma->flags & _DRM_DMA_USE_AGP)) || + (drm_core_check_feature(dev, DRIVER_SG) && (dma->flags & _DRM_DMA_USE_SG))) { drm_map_t *map = dev->agp_buffer_map; if ( !map ) { diff --git a/linux/drm_drv.h b/linux/drm_drv.h index 8f42e357..2c1719da 100644 --- a/linux/drm_drv.h +++ b/linux/drm_drv.h @@ -347,9 +347,8 @@ static int DRM(takedown)( drm_device_t *dev ) dev->magiclist[i].head = dev->magiclist[i].tail = NULL; } -#if __OS_HAS_AGP /* Clear AGP information */ - if ( drm_core_check_feature(dev, DRIVER_USE_AGP) && dev->agp ) { + if ( drm_core_has_AGP(dev) && dev->agp ) { drm_agp_mem_t *entry; drm_agp_mem_t *nexte; @@ -368,7 +367,6 @@ static int DRM(takedown)( drm_device_t *dev ) dev->agp->acquired = 0; dev->agp->enabled = 0; } -#endif /* Clear vma list (only built for debugging) */ if ( dev->vmalist ) { @@ -509,8 +507,7 @@ static int drm_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if ((retcode = dev->fn_tbl.preinit(dev, ent->driver_data))) goto error_out_unreg; -#if __OS_HAS_AGP - if (drm_core_check_feature(dev, DRIVER_USE_AGP)) { + if (drm_core_has_AGP(dev)) { dev->agp = DRM(agp_init)(); if ( drm_core_check_feature(dev, DRIVER_REQUIRE_AGP) && dev->agp == NULL ) { DRM_ERROR( "Cannot initialize the agpgart module.\n" ); @@ -518,8 +515,8 @@ static int drm_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto error_out_unreg; } -#if __OS_HAS_MTRR - if (drm_core_check_feature(dev, DRIVER_USE_MTRR)) { + + if (drm_core_has_MTRR(dev)) { if (dev->agp) dev->agp->agp_mtrr = mtrr_add( dev->agp->agp_info.aper_base, dev->agp->agp_info.aper_size*1024*1024, @@ -527,8 +524,7 @@ static int drm_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 1 ); } } -#endif -#endif + retcode = DRM(ctxbitmap_init)( dev ); if( retcode ) { DRM_ERROR( "Cannot allocate memory for context bitmap.\n" ); @@ -572,7 +568,7 @@ static int drm_probe(struct pci_dev *pdev, const struct pci_device_id *ent) static void __exit drm_cleanup_pci(struct pci_dev *pdev) { drm_device_t *dev = pci_get_drvdata(pdev); - + pci_set_drvdata(pdev, NULL); drm_cleanup(dev); } @@ -680,8 +676,7 @@ static void __exit drm_cleanup( drm_device_t *dev ) break; case _DRM_FRAME_BUFFER: -#if __OS_HAS_MTRR - if ( drm_core_check_feature(dev, DRIVER_USE_MTRR)) { + if ( drm_core_has_MTRR(dev)) { if ( map->mtrr >= 0 ) { int retcode; retcode = mtrr_del( map->mtrr, @@ -690,7 +685,6 @@ static void __exit drm_cleanup( drm_device_t *dev ) DRM_DEBUG( "mtrr_del=%d\n", retcode ); } } -#endif break; case _DRM_SHM: @@ -719,22 +713,19 @@ static void __exit drm_cleanup( drm_device_t *dev ) DRM(ctxbitmap_cleanup)( dev ); -#if __OS_HAS_AGP -#if __OS_HAS_MTRR - if ( drm_core_check_feature(dev, DRIVER_USE_MTRR) && dev->agp && dev->agp->agp_mtrr >= 0 ) { + if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && dev->agp && dev->agp->agp_mtrr >= 0) { int retval; retval = mtrr_del( dev->agp->agp_mtrr, dev->agp->agp_info.aper_base, dev->agp->agp_info.aper_size*1024*1024 ); DRM_DEBUG( "mtrr_del=%d\n", retval ); } -#endif - if ( drm_core_check_feature(dev, DRIVER_USE_AGP) && dev->agp ) { + + if (drm_core_has_AGP(dev) && dev->agp ) { DRM(agp_uninit)(); DRM(free)( dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS ); dev->agp = NULL; } -#endif if (dev->fn_tbl.postcleanup) dev->fn_tbl.postcleanup(dev); } @@ -1129,29 +1120,28 @@ int DRM(lock)( struct inode *inode, struct file *filp, current->state = TASK_RUNNING; remove_wait_queue( &dev->lock.lock_queue, &entry ); - if ( !ret ) { - sigemptyset( &dev->sigmask ); - sigaddset( &dev->sigmask, SIGSTOP ); - sigaddset( &dev->sigmask, SIGTSTP ); - sigaddset( &dev->sigmask, SIGTTIN ); - sigaddset( &dev->sigmask, SIGTTOU ); - dev->sigdata.context = lock.context; - dev->sigdata.lock = dev->lock.hw_lock; - block_all_signals( DRM(notifier), - &dev->sigdata, &dev->sigmask ); - - if (dev->fn_tbl.dma_ready && (lock.flags & _DRM_LOCK_READY)) - dev->fn_tbl.dma_ready(dev); - - if ( dev->fn_tbl.dma_quiescent && (lock.flags & _DRM_LOCK_QUIESCENT )) - return dev->fn_tbl.dma_quiescent(dev); - - - if ( dev->fn_tbl.kernel_context_switch && dev->last_context != lock.context ) { - dev->fn_tbl.kernel_context_switch(dev, dev->last_context, - lock.context); - } - } + sigemptyset( &dev->sigmask ); + sigaddset( &dev->sigmask, SIGSTOP ); + sigaddset( &dev->sigmask, SIGTSTP ); + sigaddset( &dev->sigmask, SIGTTIN ); + sigaddset( &dev->sigmask, SIGTTOU ); + dev->sigdata.context = lock.context; + dev->sigdata.lock = dev->lock.hw_lock; + block_all_signals( DRM(notifier), + &dev->sigdata, &dev->sigmask ); + + if (dev->fn_tbl.dma_ready && (lock.flags & _DRM_LOCK_READY)) + dev->fn_tbl.dma_ready(dev); + + if ( dev->fn_tbl.dma_quiescent && (lock.flags & _DRM_LOCK_QUIESCENT )) + return dev->fn_tbl.dma_quiescent(dev); + + + if ( dev->fn_tbl.kernel_context_switch && dev->last_context != lock.context ) { + dev->fn_tbl.kernel_context_switch(dev, dev->last_context, + lock.context); + } + DRM_DEBUG( "%d %s\n", lock.context, ret ? "interrupted" : "has lock" ); diff --git a/linux/drm_memory.h b/linux/drm_memory.h index 38084ccc..2cdccb13 100644 --- a/linux/drm_memory.h +++ b/linux/drm_memory.h @@ -139,12 +139,29 @@ drm_follow_page (void *vaddr) return pte_pfn(*ptep) << PAGE_SHIFT; } -#endif /* __OS_HAS_AGP && defined(VMAP_4_ARGS) */ +#else /* __OS_HAS_AGP */ + +static inline drm_map_t *drm_lookup_map(unsigned long offset, unsigned long size, drm_device_t *dev) +{ + return NULL; +} + +static inline void *agp_remap(unsigned long offset, unsigned long size, drm_device_t *dev) +{ + return NULL; +} + +static inline unsigned long drm_follow_page (void *vaddr) +{ + return 0; +} + +#endif static inline void *drm_ioremap(unsigned long offset, unsigned long size, drm_device_t *dev) { -#if __OS_HAS_AGP && defined(VMAP_4_ARGS) - if ( drm_core_check_feature(dev, DRIVER_USE_AGP) && dev->agp && dev->agp->cant_use_aperture) { +#if defined(VMAP_4_ARGS) + if ( drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) { drm_map_t *map = drm_lookup_map(offset, size, dev); if (map && map->type == _DRM_AGP) @@ -158,8 +175,8 @@ static inline void *drm_ioremap(unsigned long offset, unsigned long size, drm_de static inline void *drm_ioremap_nocache(unsigned long offset, unsigned long size, drm_device_t *dev) { -#if __OS_HAS_AGP&& defined(VMAP_4_ARGS) - if ( drm_core_check_feature(dev, DRIVER_USE_AGP) && dev->agp && dev->agp->cant_use_aperture) { +#if defined(VMAP_4_ARGS) + if ( drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) { drm_map_t *map = drm_lookup_map(offset, size, dev); if (map && map->type == _DRM_AGP) @@ -172,13 +189,13 @@ static inline void *drm_ioremap_nocache(unsigned long offset, unsigned long size static inline void drm_ioremapfree(void *pt, unsigned long size, drm_device_t *dev) { -#if __OS_HAS_AGP && defined(VMAP_4_ARGS) +#if defined(VMAP_4_ARGS) /* * This is a bit ugly. It would be much cleaner if the DRM API would use separate * routines for handling mappings in the AGP space. Hopefully this can be done in * a future revision of the interface... */ - if (drm_core_check_feature(dev, DRIVER_USE_AGP) && dev->agp && dev->agp->cant_use_aperture + if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture && ((unsigned long) pt >= VMALLOC_START && (unsigned long) pt < VMALLOC_END)) { unsigned long offset; diff --git a/linux/drm_os_linux.h b/linux/drm_os_linux.h index bf58a1c2..ab16d7b3 100644 --- a/linux/drm_os_linux.h +++ b/linux/drm_os_linux.h @@ -47,6 +47,7 @@ typedef void irqreturn_t; #endif /** AGP types */ +#if __OS_HAS_AGP #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,70) #define DRM_AGP_MEM agp_memory #define DRM_AGP_KERN agp_kern_info @@ -54,6 +55,30 @@ typedef void irqreturn_t; #define DRM_AGP_MEM struct agp_memory #define DRM_AGP_KERN struct agp_kern_info #endif +#else +/* define some dummy types for non AGP supporting kernels */ +struct no_agp_kern { + unsigned long aper_base; + unsigned long aper_size; +}; +#define DRM_AGP_MEM int +#define DRM_AGP_KERN struct no_agp_kern +#endif + +#if !(__OS_HAS_MTRR) +static __inline__ int mtrr_add (unsigned long base, unsigned long size, + unsigned int type, char increment) +{ + return -ENODEV; +} + +static __inline__ int mtrr_del (int reg, unsigned long base, + unsigned long size) +{ + return -ENODEV; +} +#define MTRR_TYPE_WRCOMB 1 +#endif /** Task queue handler arguments */ #define DRM_TASKQUEUE_ARGS void *arg diff --git a/linux/drm_vm.h b/linux/drm_vm.h index 46eaf569..b5b5e2ea 100644 --- a/linux/drm_vm.h +++ b/linux/drm_vm.h @@ -46,10 +46,10 @@ * 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. */ +#if __OS_HAS_AGP static __inline__ struct page *DRM(do_vm_nopage)(struct vm_area_struct *vma, unsigned long address) { -#if __OS_HAS_AGP drm_file_t *priv = vma->vm_file->private_data; drm_device_t *dev = priv->dev; drm_map_t *map = NULL; @@ -59,7 +59,7 @@ static __inline__ struct page *DRM(do_vm_nopage)(struct vm_area_struct *vma, /* * Find the right map */ - if (!drm_core_check_feature(dev, DRIVER_USE_AGP)) + if (!drm_core_has_AGP(dev)) goto vm_nopage_error; if(!dev->agp || !dev->agp->cant_use_aperture) goto vm_nopage_error; @@ -112,10 +112,15 @@ static __inline__ struct page *DRM(do_vm_nopage)(struct vm_area_struct *vma, return page; } vm_nopage_error: -#endif /* __OS_HAS_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. @@ -206,15 +211,13 @@ void DRM(vm_shm_close)(struct vm_area_struct *vma) switch (map->type) { case _DRM_REGISTERS: case _DRM_FRAME_BUFFER: -#if __OS_HAS_MTRR - if (drm_core_check_feature(dev, DRIVER_USE_MTRR) && 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: @@ -583,8 +586,7 @@ int DRM(mmap)(struct file *filp, struct vm_area_struct *vma) switch (map->type) { case _DRM_AGP: -#if __OS_HAS_AGP - if (drm_core_check_feature(dev, DRIVER_USE_AGP) && 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 @@ -596,7 +598,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: