From 72983ff30183745cd96760aa07b857c44daebde7 Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Wed, 27 Feb 2008 19:46:28 +0100 Subject: [PATCH 01/11] Don't wait for buffer idle before applying relocations. --- shared-core/i915_dma.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/shared-core/i915_dma.c b/shared-core/i915_dma.c index b916441d..2d26fcc1 100644 --- a/shared-core/i915_dma.c +++ b/shared-core/i915_dma.c @@ -860,6 +860,15 @@ int i915_apply_reloc(struct drm_file *file_priv, int num_buffers, drm_bo_kunmap(&relocatee->kmap); relocatee->data_page = NULL; relocatee->offset = new_cmd_offset; + + /* + * Note on buffer idle: + * Since we're applying relocations, this part of the + * buffer is obviously not used by the GPU and we don't + * need to wait for buffer idle. This is an important + * consideration for user-space buffer pools. + */ + ret = drm_bo_kmap(relocatee->buf, new_cmd_offset >> PAGE_SHIFT, 1, &relocatee->kmap); if (ret) { @@ -1003,10 +1012,6 @@ static int i915_exec_reloc(struct drm_file *file_priv, drm_handle_t buf_handle, } mutex_lock (&relocatee.buf->mutex); - ret = drm_bo_wait (relocatee.buf, 0, 0, FALSE); - if (ret) - goto out_err1; - while (reloc_user_ptr) { ret = i915_process_relocs(file_priv, buf_handle, &reloc_user_ptr, &relocatee, buffers, buf_count); if (ret) { From fd595fa4dc6f788a8a1e1b56178e15f411706cb9 Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Wed, 27 Feb 2008 21:44:40 +0100 Subject: [PATCH 02/11] Reinstate buffer idle before applying relocations. --- shared-core/i915_dma.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shared-core/i915_dma.c b/shared-core/i915_dma.c index 2d26fcc1..f9e02c77 100644 --- a/shared-core/i915_dma.c +++ b/shared-core/i915_dma.c @@ -805,6 +805,7 @@ struct i915_relocatee_info { unsigned page_offset; struct drm_bo_kmap_obj kmap; int is_iomem; + int idle; }; struct drm_i915_validate_buffer { @@ -860,14 +861,13 @@ int i915_apply_reloc(struct drm_file *file_priv, int num_buffers, drm_bo_kunmap(&relocatee->kmap); relocatee->data_page = NULL; relocatee->offset = new_cmd_offset; - - /* - * Note on buffer idle: - * Since we're applying relocations, this part of the - * buffer is obviously not used by the GPU and we don't - * need to wait for buffer idle. This is an important - * consideration for user-space buffer pools. - */ + + if (unlikely(!relocatee->idle)) { + ret = drm_bo_wait(relocatee->buf, 0, 0, 0); + if (ret) + return ret; + relocatee->idle = 1; + } ret = drm_bo_kmap(relocatee->buf, new_cmd_offset >> PAGE_SHIFT, 1, &relocatee->kmap); From 8ef838e5ff7b3c005d7fbc725e17bcccd0e1e1eb Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Thu, 28 Feb 2008 13:47:15 +0100 Subject: [PATCH 03/11] Add a compat kmap_atomic_prot_pfn to do quick kernel map / unmaps of PCI- or high memory. This is substantially more efficient than drm_bo_kmap, since the mapping only lives on a single processor. Unmapping is done use kunmap_atomic(). Flushes only a single tlb() entry. Add a support utility int drm_bo_pfn_prot() that returns the pfn and desired page protection for a given bo offset. This is all intended for relocations in bound TTMS or vram. Mapping-accessing-unmapping must be atomic, either using preempt_xx() macros or a spinlock. --- linux-core/drm_bo_move.c | 33 +++++++++++++++++++++++++++++++++ linux-core/drm_compat.c | 32 ++++++++++++++++++++++++++++++++ linux-core/drm_compat.h | 5 +++++ linux-core/drm_objects.h | 4 ++++ 4 files changed, 74 insertions(+) diff --git a/linux-core/drm_bo_move.c b/linux-core/drm_bo_move.c index b06a09f0..30e0f43f 100644 --- a/linux-core/drm_bo_move.c +++ b/linux-core/drm_bo_move.c @@ -595,3 +595,36 @@ void drm_bo_kunmap(struct drm_bo_kmap_obj *map) map->page = NULL; } EXPORT_SYMBOL(drm_bo_kunmap); + +int drm_bo_pfn_prot(struct drm_buffer_object *bo, + unsigned long dst_offset, + unsigned long *pfn, + pgprot_t *prot) +{ + struct drm_bo_mem_reg *mem = &bo->mem; + struct drm_device *dev = bo->dev; + unsigned long bus_offset; + unsigned long bus_size; + unsigned long bus_base; + struct drm_mem_type_manager *man = &dev->bm.man[mem->mem_type]; + int ret; + + ret = drm_bo_pci_offset(dev, mem, &bus_base, &bus_offset, + &bus_size); + if (ret) + return -EINVAL; + + if (bus_size != 0) + *pfn = (bus_base + bus_offset + dst_offset) >> PAGE_SHIFT; + else if (!bo->ttm) + return -EINVAL; + else + *pfn = page_to_pfn(drm_ttm_get_page(bo->ttm, dst_offset >> PAGE_SHIFT)); + + *prot = (mem->flags & DRM_BO_FLAG_CACHED) ? + PAGE_KERNEL : drm_kernel_io_prot(man->drm_bus_maptype); + + return 0; +} +EXPORT_SYMBOL(drm_bo_pfn_prot); + diff --git a/linux-core/drm_compat.c b/linux-core/drm_compat.c index a745a7d9..32e43a0a 100644 --- a/linux-core/drm_compat.c +++ b/linux-core/drm_compat.c @@ -729,3 +729,35 @@ void *idr_replace(struct idr *idp, void *ptr, int id) } EXPORT_SYMBOL(idr_replace); #endif + +#if defined(CONFIG_X86) + +#define drm_kmap_get_fixmap_pte(vaddr) \ + pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), vaddr), (vaddr)), (vaddr)) + +void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, + pgprot_t protection) +{ + enum fixed_addresses idx; + unsigned long vaddr; + static pte_t *km_pte; + static int initialized = 0; + + if (unlikely(!initialized)) { + km_pte = drm_kmap_get_fixmap_pte(__fix_to_virt(FIX_KMAP_BEGIN)); + initialized = 1; + } + + pagefault_disable(); + idx = type + KM_TYPE_NR*smp_processor_id(); + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); + set_pte(km_pte-idx, pfn_pte(pfn, protection)); + + return (void*) vaddr; +} + +EXPORT_SYMBOL(kmap_atomic_prot_pfn); + +#endif + + diff --git a/linux-core/drm_compat.h b/linux-core/drm_compat.h index f8933e0c..39027cf4 100644 --- a/linux-core/drm_compat.h +++ b/linux-core/drm_compat.h @@ -328,4 +328,9 @@ void *idr_replace(struct idr *idp, void *ptr, int id); typedef _Bool bool; #endif +#if defined(CONFIG_X86) +#define DRM_KMAP_ATOMIC_PROT_PFN +extern void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, + pgprot_t protection); +#endif #endif diff --git a/linux-core/drm_objects.h b/linux-core/drm_objects.h index e43e8dfd..8055afe1 100644 --- a/linux-core/drm_objects.h +++ b/linux-core/drm_objects.h @@ -738,6 +738,10 @@ static inline void *drm_bmo_virtual(struct drm_bo_kmap_obj *map, int *is_iomem) extern void drm_bo_kunmap(struct drm_bo_kmap_obj *map); extern int drm_bo_kmap(struct drm_buffer_object *bo, unsigned long start_page, unsigned long num_pages, struct drm_bo_kmap_obj *map); +extern int drm_bo_pfn_prot(struct drm_buffer_object *bo, + unsigned long dst_offset, + unsigned long *pfn, + pgprot_t *prot); /* From cdbd616ea5f0ee491ff82cac74b918a14b039917 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 29 Feb 2008 10:16:24 +1000 Subject: [PATCH 04/11] agp: export the correct symbol --- linux-core/drm_agpsupport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-core/drm_agpsupport.c b/linux-core/drm_agpsupport.c index 02187017..f58d5516 100644 --- a/linux-core/drm_agpsupport.c +++ b/linux-core/drm_agpsupport.c @@ -666,7 +666,7 @@ void drm_agp_chipset_flush(struct drm_device *dev) { agp_flush_chipset(dev->agp->bridge); } -EXPORT_SYMBOL(drm_agp_flush_chipset); +EXPORT_SYMBOL(drm_agp_chipset_flush); #endif #endif /* __OS_HAS_AGP */ From 1d068973d5f5e6d8d14b4c0c6e28588107aafc6f Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Fri, 29 Feb 2008 13:31:14 +0100 Subject: [PATCH 05/11] Fix compilation breakage on x86-64. --- linux-core/drm_compat.c | 3 +-- linux-core/drm_compat.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/linux-core/drm_compat.c b/linux-core/drm_compat.c index 32e43a0a..eb6c5d81 100644 --- a/linux-core/drm_compat.c +++ b/linux-core/drm_compat.c @@ -730,8 +730,7 @@ void *idr_replace(struct idr *idp, void *ptr, int id) EXPORT_SYMBOL(idr_replace); #endif -#if defined(CONFIG_X86) - +#if defined(DRM_KMAP_ATOMIC_PROT_PFN) #define drm_kmap_get_fixmap_pte(vaddr) \ pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), vaddr), (vaddr)), (vaddr)) diff --git a/linux-core/drm_compat.h b/linux-core/drm_compat.h index 39027cf4..08892e6b 100644 --- a/linux-core/drm_compat.h +++ b/linux-core/drm_compat.h @@ -328,7 +328,7 @@ void *idr_replace(struct idr *idp, void *ptr, int id); typedef _Bool bool; #endif -#if defined(CONFIG_X86) +#if (defined(CONFIG_X86) && defined(CONFIG_X86_32)) #define DRM_KMAP_ATOMIC_PROT_PFN extern void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t protection); From 09999c90ab1bf3f7d8b277895c962c8a7b3afc18 Mon Sep 17 00:00:00 2001 From: Patrice Mandin Date: Fri, 29 Feb 2008 21:57:40 +0100 Subject: [PATCH 06/11] FIX_KMAP_BEGIN requires CONFIG_HIMEM (see include/asm-i386.h/fixmap.h) --- linux-core/drm_compat.c | 2 +- linux-core/drm_compat.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linux-core/drm_compat.c b/linux-core/drm_compat.c index eb6c5d81..d4044cbd 100644 --- a/linux-core/drm_compat.c +++ b/linux-core/drm_compat.c @@ -730,7 +730,7 @@ void *idr_replace(struct idr *idp, void *ptr, int id) EXPORT_SYMBOL(idr_replace); #endif -#if defined(DRM_KMAP_ATOMIC_PROT_PFN) +#if defined(DRM_KMAP_ATOMIC_PROT_PFN) && defined(CONFIG_HIMEM) #define drm_kmap_get_fixmap_pte(vaddr) \ pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), vaddr), (vaddr)), (vaddr)) diff --git a/linux-core/drm_compat.h b/linux-core/drm_compat.h index 08892e6b..136a7296 100644 --- a/linux-core/drm_compat.h +++ b/linux-core/drm_compat.h @@ -328,7 +328,7 @@ void *idr_replace(struct idr *idp, void *ptr, int id); typedef _Bool bool; #endif -#if (defined(CONFIG_X86) && defined(CONFIG_X86_32)) +#if (defined(CONFIG_X86) && defined(CONFIG_X86_32) && defined(CONFIG_HIMEM)) #define DRM_KMAP_ATOMIC_PROT_PFN extern void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t protection); From 63fd6f284ddd1096d34b39941683ae244c1e01fc Mon Sep 17 00:00:00 2001 From: Zou Nan hai Date: Mon, 3 Mar 2008 14:49:49 +0800 Subject: [PATCH 07/11] [i915] 2D driver may reset Frame count value, this may lead driver to leap it's vblank count a huge value. This will stall some applications that switch video mode if vblank_mode is set to a non zero value in drirc. --- shared-core/i915_irq.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/shared-core/i915_irq.c b/shared-core/i915_irq.c index fd08b6e8..126f0379 100644 --- a/shared-core/i915_irq.c +++ b/shared-core/i915_irq.c @@ -406,6 +406,13 @@ u32 i915_get_vblank_counter(struct drm_device *dev, int plane) if (i915_in_vblank(dev, pipe)) count++; #endif + /* count may be reset by other driver(e.g. 2D driver), + we have no way to know if it is wrapped or resetted + when count is zero. do a rough guess. + */ + if (count == 0 && dev->last_vblank[pipe] < dev->max_vblank_count/2) + dev->last_vblank[pipe] = 0; + return count; } From eedf3fa2f08eb774a36109c2fbda7207bf83fbe9 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 4 Mar 2008 12:16:51 -0800 Subject: [PATCH 08/11] Don't shortcut the info syscall for drmBOBusy on nonshareable objects. This broke the results when you're trying to check if a buffer you dispatched some time ago is done being rendered from. --- libdrm/xf86drm.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index e3550de7..fb8f1c66 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2799,23 +2799,18 @@ int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint) } return 0; } - + int drmBOBusy(int fd, drmBO *buf, int *busy) { - if (!(buf->flags & DRM_BO_FLAG_SHAREABLE) && - !(buf->replyFlags & DRM_BO_REP_BUSY)) { - *busy = 0; - return 0; - } - else { - int ret = drmBOInfo(fd, buf); - if (ret) - return ret; - *busy = (buf->replyFlags & DRM_BO_REP_BUSY); - return 0; - } + int ret = drmBOInfo(fd, buf); + + if (ret) + return ret; + + *busy = (buf->replyFlags & DRM_BO_REP_BUSY); + return 0; } - + int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize, unsigned memType) { From d41846adb72ba89c94ea1164e366032b1d36bd55 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 4 Mar 2008 13:35:23 -0800 Subject: [PATCH 09/11] Clarify through the names what drm_ttm_alloc_pages() and friend actually did. These are all about the page directory (pointers to pages) rather than the actual pages backing the allocation. --- linux-core/drm_objects.h | 2 +- linux-core/drm_ttm.c | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/linux-core/drm_objects.h b/linux-core/drm_objects.h index 8055afe1..69a5c27f 100644 --- a/linux-core/drm_objects.h +++ b/linux-core/drm_objects.h @@ -384,7 +384,7 @@ extern int drm_ttm_destroy(struct drm_ttm *ttm); * The array of page pointers was allocated with vmalloc * instead of drm_calloc. */ -#define DRM_TTM_PAGE_VMALLOC (1 << 4) +#define DRM_TTM_PAGEDIR_VMALLOC (1 << 4) /* * This ttm is mapped from user space */ diff --git a/linux-core/drm_ttm.c b/linux-core/drm_ttm.c index a9d87338..cc80b132 100644 --- a/linux-core/drm_ttm.c +++ b/linux-core/drm_ttm.c @@ -42,11 +42,12 @@ void drm_ttm_cache_flush(void) } EXPORT_SYMBOL(drm_ttm_cache_flush); -/* - * Use kmalloc if possible. Otherwise fall back to vmalloc. +/** + * Allocates storage for pointers to the pages that back the ttm. + * + * Uses kmalloc if possible. Otherwise falls back to vmalloc. */ - -static void drm_ttm_alloc_pages(struct drm_ttm *ttm) +static void drm_ttm_alloc_page_directory(struct drm_ttm *ttm) { unsigned long size = ttm->num_pages * sizeof(*ttm->pages); ttm->pages = NULL; @@ -60,19 +61,19 @@ static void drm_ttm_alloc_pages(struct drm_ttm *ttm) if (!ttm->pages) { ttm->pages = vmalloc_user(size); if (ttm->pages) - ttm->page_flags |= DRM_TTM_PAGE_VMALLOC; + ttm->page_flags |= DRM_TTM_PAGEDIR_VMALLOC; } if (!ttm->pages) drm_free_memctl(size); } -static void drm_ttm_free_pages(struct drm_ttm *ttm) +static void drm_ttm_free_page_directory(struct drm_ttm *ttm) { unsigned long size = ttm->num_pages * sizeof(*ttm->pages); - if (ttm->page_flags & DRM_TTM_PAGE_VMALLOC) { + if (ttm->page_flags & DRM_TTM_PAGEDIR_VMALLOC) { vfree(ttm->pages); - ttm->page_flags &= ~DRM_TTM_PAGE_VMALLOC; + ttm->page_flags &= ~DRM_TTM_PAGEDIR_VMALLOC; } else { drm_free(ttm->pages, size, DRM_MEM_TTM); } @@ -215,7 +216,7 @@ int drm_ttm_destroy(struct drm_ttm *ttm) else drm_ttm_free_alloced_pages(ttm); - drm_ttm_free_pages(ttm); + drm_ttm_free_page_directory(ttm); } drm_ctl_free(ttm, sizeof(*ttm), DRM_MEM_TTM); @@ -349,7 +350,7 @@ struct drm_ttm *drm_ttm_create(struct drm_device *dev, unsigned long size, * Account also for AGP module memory usage. */ - drm_ttm_alloc_pages(ttm); + drm_ttm_alloc_page_directory(ttm); if (!ttm->pages) { drm_ttm_destroy(ttm); DRM_ERROR("Failed allocating page table\n"); From 3332a0add63162222bd9c829117cd7e30d981aa7 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 30 Jan 2008 19:02:56 -0800 Subject: [PATCH 10/11] Remove unused DRM_FENCE_FLAG_WAIT_IGNORE_SIGNALS. --- shared-core/drm.h | 1 - 1 file changed, 1 deletion(-) diff --git a/shared-core/drm.h b/shared-core/drm.h index 6c134566..213d3c7a 100644 --- a/shared-core/drm.h +++ b/shared-core/drm.h @@ -646,7 +646,6 @@ struct drm_set_version { #define DRM_FENCE_FLAG_EMIT 0x00000001 #define DRM_FENCE_FLAG_SHAREABLE 0x00000002 #define DRM_FENCE_FLAG_WAIT_LAZY 0x00000004 -#define DRM_FENCE_FLAG_WAIT_IGNORE_SIGNALS 0x00000008 #define DRM_FENCE_FLAG_NO_USER 0x00000010 /* Reserved for driver use */ From a6a2f2c8c491617de702dc7d62bb55cbada4d42b Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 4 Mar 2008 13:45:41 -0800 Subject: [PATCH 11/11] Clarify when WAIT_LAZY is relevant to users. --- shared-core/drm.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/shared-core/drm.h b/shared-core/drm.h index 213d3c7a..663696c1 100644 --- a/shared-core/drm.h +++ b/shared-core/drm.h @@ -645,6 +645,13 @@ struct drm_set_version { #define DRM_FENCE_FLAG_EMIT 0x00000001 #define DRM_FENCE_FLAG_SHAREABLE 0x00000002 +/** + * On hardware with no interrupt events for operation completion, + * indicates that the kernel should sleep while waiting for any blocking + * operation to complete rather than spinning. + * + * Has no effect otherwise. + */ #define DRM_FENCE_FLAG_WAIT_LAZY 0x00000004 #define DRM_FENCE_FLAG_NO_USER 0x00000010 @@ -794,13 +801,12 @@ struct drm_fence_arg { * with it as a result of this operation */ #define DRM_BO_HINT_DONT_FENCE 0x00000004 -/* - * Sleep while waiting for the operation to complete. - * Without this flag, the kernel will, instead, spin - * until this operation has completed. I'm not sure - * why you would ever want this, so please always - * provide DRM_BO_HINT_WAIT_LAZY to any operation - * which may block +/** + * On hardware with no interrupt events for operation completion, + * indicates that the kernel should sleep while waiting for any blocking + * operation to complete rather than spinning. + * + * Has no effect otherwise. */ #define DRM_BO_HINT_WAIT_LAZY 0x00000008 /*