diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2015-04-08 02:28:14 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2015-04-08 02:28:14 +0000 |
commit | 348d40200984234819c240eea6304f306a678871 (patch) | |
tree | 4ef96961eaebc7de663f5ebe12f9b1e33d44a6df | |
parent | 47aaddf4650438695425219483a930b11b02a03e (diff) |
ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.
Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.
looks good kettenis@
-rw-r--r-- | sys/dev/pci/drm/drm_linux.c | 64 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_linux.h | 11 | ||||
-rw-r--r-- | sys/dev/pci/drm/i915/i915_gem.c | 31 | ||||
-rw-r--r-- | sys/dev/pci/drm/i915/i915_gem_tiling.c | 22 | ||||
-rw-r--r-- | sys/dev/pci/drm/ttm/ttm_bo_driver.h | 6 | ||||
-rw-r--r-- | sys/dev/pci/drm/ttm/ttm_bo_util.c | 70 |
6 files changed, 80 insertions, 124 deletions
diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c index 8810360c58c..7939c70570a 100644 --- a/sys/dev/pci/drm/drm_linux.c +++ b/sys/dev/pci/drm/drm_linux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.c,v 1.2 2015/04/06 12:25:10 jsg Exp $ */ +/* $OpenBSD: drm_linux.c,v 1.3 2015/04/08 02:28:13 jsg Exp $ */ /* * Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org> * @@ -117,3 +117,65 @@ dmi_check_system(const struct dmi_system_id *sysid) } return (num); } + +void * +kmap(struct vm_page *pg) +{ + vaddr_t va; + +#if defined (__HAVE_PMAP_DIRECT) + va = pmap_map_direct(pg); +#else + va = uvm_km_valloc_wait(phys_map, PAGE_SIZE); + pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg), PROT_READ | PROT_WRITE); + pmap_update(pmap_kernel()); +#endif + return (void *)va; +} + +void +kunmap(void *addr) +{ + vaddr_t va = (vaddr_t)addr; + +#if defined (__HAVE_PMAP_DIRECT) + pmap_unmap_direct(va); +#else + pmap_kremove(va, PAGE_SIZE); + pmap_update(pmap_kernel()); + uvm_km_free_wakeup(phys_map, va, PAGE_SIZE); +#endif +} + +void * +vmap(struct vm_page **pages, unsigned int npages, unsigned long flags, + pgprot_t prot) +{ + vaddr_t va; + paddr_t pa; + int i; + + va = uvm_km_valloc_wait(phys_map, PAGE_SIZE * npages); + if (va == 0) + return NULL; + for (i = 0; i < npages; i++) { + pa = VM_PAGE_TO_PHYS(pages[i]) | prot; + pmap_enter(pmap_kernel(), va + (i * PAGE_SIZE), pa, + PROT_READ | PROT_WRITE, + PROT_READ | PROT_WRITE | PMAP_WIRED); + pmap_update(pmap_kernel()); + } + + return (void *)va; +} + +void +vunmap(void *addr, size_t size) +{ + vaddr_t va = (vaddr_t)addr; + + pmap_remove(pmap_kernel(), va, va + size); + pmap_update(pmap_kernel()); + uvm_km_free(phys_map, va, size); +} + diff --git a/sys/dev/pci/drm/drm_linux.h b/sys/dev/pci/drm/drm_linux.h index ee74927d6bc..3b4c3e00e92 100644 --- a/sys/dev/pci/drm/drm_linux.h +++ b/sys/dev/pci/drm/drm_linux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.h,v 1.13 2015/04/06 15:43:15 jsg Exp $ */ +/* $OpenBSD: drm_linux.h,v 1.14 2015/04/08 02:28:13 jsg Exp $ */ /* * Copyright (c) 2013, 2014 Mark Kettenis * @@ -462,6 +462,15 @@ struct pci_dev { #define page_to_pfn(pp) (VM_PAGE_TO_PHYS(pp) / PAGE_SIZE) #define offset_in_page(off) ((off) & PAGE_MASK) +typedef int pgprot_t; +#define pgprot_val(v) (v) +#define PAGE_KERNEL 0 + +void *kmap(struct vm_page *); +void kunmap(void *addr); +void *vmap(struct vm_page **, unsigned int, unsigned long, pgprot_t); +void vunmap(void *, size_t); + #define round_up(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) #define round_down(x, y) (((x) / (y)) * (y)) #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ diff --git a/sys/dev/pci/drm/i915/i915_gem.c b/sys/dev/pci/drm/i915/i915_gem.c index 2aa75694069..0dc5341ee7c 100644 --- a/sys/dev/pci/drm/i915/i915_gem.c +++ b/sys/dev/pci/drm/i915/i915_gem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i915_gem.c,v 1.88 2015/04/06 12:25:10 jsg Exp $ */ +/* $OpenBSD: i915_gem.c,v 1.89 2015/04/08 02:28:13 jsg Exp $ */ /* * Copyright (c) 2008-2009 Owain G. Ainsworth <oga@openbsd.org> * @@ -290,35 +290,6 @@ static int i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj) obj->tiling_mode != I915_TILING_NONE; } -static void * -kmap(struct vm_page *pg) -{ - vaddr_t va; - -#if defined (__HAVE_PMAP_DIRECT) - va = pmap_map_direct(pg); -#else - va = uvm_km_valloc_wait(phys_map, PAGE_SIZE); - pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg), PROT_READ | PROT_WRITE); - pmap_update(pmap_kernel()); -#endif - return (void *)va; -} - -static void -kunmap(void *addr) -{ - vaddr_t va = (vaddr_t)addr; - -#if defined (__HAVE_PMAP_DIRECT) - pmap_unmap_direct(va); -#else - pmap_kremove(va, PAGE_SIZE); - pmap_update(pmap_kernel()); - uvm_km_free_wakeup(phys_map, va, PAGE_SIZE); -#endif -} - static inline void drm_clflush_virt_range(void *addr, size_t len) { diff --git a/sys/dev/pci/drm/i915/i915_gem_tiling.c b/sys/dev/pci/drm/i915/i915_gem_tiling.c index fb72cd32f84..e579cd326df 100644 --- a/sys/dev/pci/drm/i915/i915_gem_tiling.c +++ b/sys/dev/pci/drm/i915/i915_gem_tiling.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i915_gem_tiling.c,v 1.16 2015/02/10 01:39:32 jsg Exp $ */ +/* $OpenBSD: i915_gem_tiling.c,v 1.17 2015/04/08 02:28:13 jsg Exp $ */ /* * Copyright (c) 2008-2009 Owain G. Ainsworth <oga@openbsd.org> * @@ -472,21 +472,13 @@ i915_gem_get_tiling(struct drm_device *dev, void *data, * by the GPU. */ static void -i915_gem_swizzle_page(struct vm_page *pg) +i915_gem_swizzle_page(struct vm_page *page) { char temp[64]; char *vaddr; int i; - vaddr_t va; -#if defined (__HAVE_PMAP_DIRECT) - va = pmap_map_direct(pg); -#else - va = uvm_km_valloc_wait(phys_map, PAGE_SIZE); - pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg), PROT_READ | PROT_WRITE); - pmap_update(pmap_kernel()); -#endif - vaddr = (char *)va; + vaddr = kmap(page); for (i = 0; i < PAGE_SIZE; i += 128) { memcpy(temp, &vaddr[i], 64); @@ -494,13 +486,7 @@ i915_gem_swizzle_page(struct vm_page *pg) memcpy(&vaddr[i + 64], temp, 64); } -#if defined (__HAVE_PMAP_DIRECT) - pmap_unmap_direct(va); -#else - pmap_kremove(va, PAGE_SIZE); - pmap_update(pmap_kernel()); - uvm_km_free_wakeup(phys_map, va, PAGE_SIZE); -#endif + kunmap(vaddr); } void diff --git a/sys/dev/pci/drm/ttm/ttm_bo_driver.h b/sys/dev/pci/drm/ttm/ttm_bo_driver.h index e418d49a4f4..0b7b3aa31c9 100644 --- a/sys/dev/pci/drm/ttm/ttm_bo_driver.h +++ b/sys/dev/pci/drm/ttm/ttm_bo_driver.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ttm_bo_driver.h,v 1.3 2015/02/10 06:19:36 jsg Exp $ */ +/* $OpenBSD: ttm_bo_driver.h,v 1.4 2015/04/08 02:28:13 jsg Exp $ */ /************************************************************************** * * Copyright (c) 2006-2009 Vmware, Inc., Palo Alto, CA., USA @@ -38,10 +38,6 @@ #include <dev/pci/drm/drm_mm.h> #include <dev/pci/drm/drm_global.h> -typedef int pgprot_t; -#define pgprot_val(v) (v) -#define PAGE_KERNEL 0 - struct ttm_backend_func { /** * struct ttm_backend_func member bind diff --git a/sys/dev/pci/drm/ttm/ttm_bo_util.c b/sys/dev/pci/drm/ttm/ttm_bo_util.c index c8cba1187c7..21e8c50b55e 100644 --- a/sys/dev/pci/drm/ttm/ttm_bo_util.c +++ b/sys/dev/pci/drm/ttm/ttm_bo_util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ttm_bo_util.c,v 1.10 2015/04/06 12:25:10 jsg Exp $ */ +/* $OpenBSD: ttm_bo_util.c,v 1.11 2015/04/08 02:28:13 jsg Exp $ */ /************************************************************************** * * Copyright (c) 2007-2009 VMware, Inc., Palo Alto, CA., USA @@ -38,11 +38,6 @@ int ttm_mem_reg_ioremap(struct ttm_bo_device *, struct ttm_mem_reg *, void ttm_mem_reg_iounmap(struct ttm_bo_device *, struct ttm_mem_reg *, void *); -void *kmap(struct vm_page *); -void kunmap(void *addr); -void *vmap(struct vm_page **, unsigned int, unsigned long, pgprot_t); -void vunmap(void *, size_t); - void ttm_bo_free_old_node(struct ttm_buffer_object *bo) { ttm_bo_mem_put(bo, &bo->mem); @@ -519,69 +514,6 @@ static int ttm_bo_ioremap(struct ttm_buffer_object *bo, return (!map->virtual) ? -ENOMEM : 0; } -void * -kmap(struct vm_page *pg) -{ - vaddr_t va; - -#if defined (__HAVE_PMAP_DIRECT) - va = pmap_map_direct(pg); -#else - va = uvm_km_valloc(kernel_map, PAGE_SIZE); - if (va == 0) - return (NULL); - pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg), PROT_READ | PROT_WRITE); - pmap_update(pmap_kernel()); -#endif - return (void *)va; -} - -void -kunmap(void *addr) -{ - vaddr_t va = (vaddr_t)addr; - -#if defined (__HAVE_PMAP_DIRECT) - pmap_unmap_direct(va); -#else - pmap_kremove(va, PAGE_SIZE); - pmap_update(pmap_kernel()); - uvm_km_free(kernel_map, va, PAGE_SIZE); -#endif -} - -void * -vmap(struct vm_page **pages, unsigned int npages, unsigned long flags, - pgprot_t prot) -{ - vaddr_t va; - paddr_t pa; - int i; - - va = uvm_km_valloc(kernel_map, PAGE_SIZE * npages); - if (va == 0) - return NULL; - for (i = 0; i < npages; i++) { - pa = VM_PAGE_TO_PHYS(pages[i]) | prot; - pmap_enter(pmap_kernel(), va + (i * PAGE_SIZE), pa, - PROT_READ | PROT_WRITE, - PROT_READ | PROT_WRITE | PMAP_WIRED); - pmap_update(pmap_kernel()); - } - - return (void *)va; -} - -void -vunmap(void *addr, size_t size) -{ - vaddr_t va = (vaddr_t)addr; - - pmap_remove(pmap_kernel(), va, va + size); - pmap_update(pmap_kernel()); - uvm_km_free(kernel_map, va, size); -} - static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo, unsigned long start_page, unsigned long num_pages, |