diff options
Diffstat (limited to 'drivers/gpu/nvgpu')
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/mm_gk20a.c | 60 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/mm_gk20a.h | 10 |
2 files changed, 49 insertions, 21 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c index 1d32a41f..6de7425b 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c | |||
@@ -395,6 +395,8 @@ static int __must_check gk20a_init_hwpm(struct mm_gk20a *mm); | |||
395 | static int __must_check gk20a_init_cde_vm(struct mm_gk20a *mm); | 395 | static int __must_check gk20a_init_cde_vm(struct mm_gk20a *mm); |
396 | static int __must_check gk20a_init_ce_vm(struct mm_gk20a *mm); | 396 | static int __must_check gk20a_init_ce_vm(struct mm_gk20a *mm); |
397 | 397 | ||
398 | static struct gk20a *gk20a_vidmem_buf_owner(struct dma_buf *dmabuf); | ||
399 | |||
398 | struct gk20a_dmabuf_priv { | 400 | struct gk20a_dmabuf_priv { |
399 | struct mutex lock; | 401 | struct mutex lock; |
400 | 402 | ||
@@ -1677,7 +1679,7 @@ u64 gk20a_locked_gmmu_map(struct vm_gk20a *vm, | |||
1677 | gk20a_dbg(gpu_dbg_map, | 1679 | gk20a_dbg(gpu_dbg_map, |
1678 | "as=%d pgsz=%d " | 1680 | "as=%d pgsz=%d " |
1679 | "kind=0x%x flags=0x%x " | 1681 | "kind=0x%x flags=0x%x " |
1680 | "ctags=%d start=%d gv=0x%x,%08x -> 0x%x,%08x -> 0x%x,%08x + %llx", | 1682 | "ctags=%d start=%d gv=0x%x,%08x -> 0x%x,%08x -> 0x%x,%08x + %llx size=%lld aperture=%s", |
1681 | vm_aspace_id(vm), pgsz_idx, | 1683 | vm_aspace_id(vm), pgsz_idx, |
1682 | kind_v, flags, | 1684 | kind_v, flags, |
1683 | ctag_lines, ctag_offset, | 1685 | ctag_lines, ctag_offset, |
@@ -1686,7 +1688,9 @@ u64 gk20a_locked_gmmu_map(struct vm_gk20a *vm, | |||
1686 | lo32((u64)sg_dma_address(sgt->sgl)), | 1688 | lo32((u64)sg_dma_address(sgt->sgl)), |
1687 | hi32((u64)sg_phys(sgt->sgl)), | 1689 | hi32((u64)sg_phys(sgt->sgl)), |
1688 | lo32((u64)sg_phys(sgt->sgl)), | 1690 | lo32((u64)sg_phys(sgt->sgl)), |
1689 | buffer_offset); | 1691 | buffer_offset, |
1692 | size, | ||
1693 | gk20a_aperture_str(aperture)); | ||
1690 | 1694 | ||
1691 | err = update_gmmu_ptes_locked(vm, pgsz_idx, | 1695 | err = update_gmmu_ptes_locked(vm, pgsz_idx, |
1692 | sgt, | 1696 | sgt, |
@@ -1777,6 +1781,28 @@ void gk20a_locked_gmmu_unmap(struct vm_gk20a *vm, | |||
1777 | } | 1781 | } |
1778 | } | 1782 | } |
1779 | 1783 | ||
1784 | static enum gk20a_aperture gk20a_dmabuf_aperture(struct gk20a *g, | ||
1785 | struct dma_buf *dmabuf) | ||
1786 | { | ||
1787 | struct gk20a *buf_owner = gk20a_vidmem_buf_owner(dmabuf); | ||
1788 | if (buf_owner == NULL) { | ||
1789 | /* Not nvgpu-allocated, assume system memory */ | ||
1790 | return APERTURE_SYSMEM; | ||
1791 | } else if (WARN_ON(buf_owner == g && !g->mm.vidmem_is_vidmem)) { | ||
1792 | /* Looks like our video memory, but this gpu doesn't support | ||
1793 | * it. Warn about a bug and bail out */ | ||
1794 | gk20a_warn(dev_from_gk20a(g), | ||
1795 | "dmabuf is our vidmem but we don't have local vidmem"); | ||
1796 | return APERTURE_INVALID; | ||
1797 | } else if (buf_owner != g) { | ||
1798 | /* Someone else's vidmem */ | ||
1799 | return APERTURE_INVALID; | ||
1800 | } else { | ||
1801 | /* Yay, buf_owner == g */ | ||
1802 | return APERTURE_VIDMEM; | ||
1803 | } | ||
1804 | } | ||
1805 | |||
1780 | static u64 gk20a_vm_map_duplicate_locked(struct vm_gk20a *vm, | 1806 | static u64 gk20a_vm_map_duplicate_locked(struct vm_gk20a *vm, |
1781 | struct dma_buf *dmabuf, | 1807 | struct dma_buf *dmabuf, |
1782 | u64 offset_align, | 1808 | u64 offset_align, |
@@ -1786,6 +1812,7 @@ static u64 gk20a_vm_map_duplicate_locked(struct vm_gk20a *vm, | |||
1786 | bool user_mapped, | 1812 | bool user_mapped, |
1787 | int rw_flag) | 1813 | int rw_flag) |
1788 | { | 1814 | { |
1815 | struct gk20a *g = gk20a_from_vm(vm); | ||
1789 | struct mapped_buffer_node *mapped_buffer = NULL; | 1816 | struct mapped_buffer_node *mapped_buffer = NULL; |
1790 | 1817 | ||
1791 | mapped_buffer = | 1818 | mapped_buffer = |
@@ -1824,7 +1851,7 @@ static u64 gk20a_vm_map_duplicate_locked(struct vm_gk20a *vm, | |||
1824 | gk20a_dbg(gpu_dbg_map, | 1851 | gk20a_dbg(gpu_dbg_map, |
1825 | "reusing as=%d pgsz=%d flags=0x%x ctags=%d " | 1852 | "reusing as=%d pgsz=%d flags=0x%x ctags=%d " |
1826 | "start=%d gv=0x%x,%08x -> 0x%x,%08x -> 0x%x,%08x " | 1853 | "start=%d gv=0x%x,%08x -> 0x%x,%08x -> 0x%x,%08x " |
1827 | "own_mem_ref=%d user_mapped=%d", | 1854 | "own_mem_ref=%d user_mapped=%d size=%zu aperture=%s", |
1828 | vm_aspace_id(vm), mapped_buffer->pgsz_idx, | 1855 | vm_aspace_id(vm), mapped_buffer->pgsz_idx, |
1829 | mapped_buffer->flags, | 1856 | mapped_buffer->flags, |
1830 | mapped_buffer->ctag_lines, | 1857 | mapped_buffer->ctag_lines, |
@@ -1834,7 +1861,9 @@ static u64 gk20a_vm_map_duplicate_locked(struct vm_gk20a *vm, | |||
1834 | lo32((u64)sg_dma_address(mapped_buffer->sgt->sgl)), | 1861 | lo32((u64)sg_dma_address(mapped_buffer->sgt->sgl)), |
1835 | hi32((u64)sg_phys(mapped_buffer->sgt->sgl)), | 1862 | hi32((u64)sg_phys(mapped_buffer->sgt->sgl)), |
1836 | lo32((u64)sg_phys(mapped_buffer->sgt->sgl)), | 1863 | lo32((u64)sg_phys(mapped_buffer->sgt->sgl)), |
1837 | mapped_buffer->own_mem_ref, user_mapped); | 1864 | mapped_buffer->own_mem_ref, user_mapped, |
1865 | dmabuf->size, | ||
1866 | gk20a_aperture_str(gk20a_dmabuf_aperture(g, dmabuf))); | ||
1838 | 1867 | ||
1839 | if (sgt) | 1868 | if (sgt) |
1840 | *sgt = mapped_buffer->sgt; | 1869 | *sgt = mapped_buffer->sgt; |
@@ -2024,7 +2053,6 @@ u64 gk20a_vm_map(struct vm_gk20a *vm, | |||
2024 | u32 ctag_map_win_ctagline = 0; | 2053 | u32 ctag_map_win_ctagline = 0; |
2025 | struct vm_reserved_va_node *va_node = NULL; | 2054 | struct vm_reserved_va_node *va_node = NULL; |
2026 | u32 ctag_offset; | 2055 | u32 ctag_offset; |
2027 | struct gk20a *buf_owner; | ||
2028 | enum gk20a_aperture aperture; | 2056 | enum gk20a_aperture aperture; |
2029 | 2057 | ||
2030 | if (user_mapped && vm->userspace_managed && | 2058 | if (user_mapped && vm->userspace_managed && |
@@ -2201,22 +2229,10 @@ u64 gk20a_vm_map(struct vm_gk20a *vm, | |||
2201 | ctag_offset += buffer_offset >> | 2229 | ctag_offset += buffer_offset >> |
2202 | ilog2(g->ops.fb.compression_page_size(g)); | 2230 | ilog2(g->ops.fb.compression_page_size(g)); |
2203 | 2231 | ||
2204 | buf_owner = gk20a_vidmem_buf_owner(dmabuf); | 2232 | aperture = gk20a_dmabuf_aperture(g, dmabuf); |
2205 | if (buf_owner == NULL) { | 2233 | if (aperture == APERTURE_INVALID) { |
2206 | /* Not nvgpu-allocated, assume system memory */ | ||
2207 | aperture = APERTURE_SYSMEM; | ||
2208 | } else if (WARN_ON(buf_owner == g && !g->mm.vidmem_is_vidmem)) { | ||
2209 | /* Looks like our video memory, but this gpu doesn't support | ||
2210 | * it. Warn about a bug and bail out */ | ||
2211 | err = -EINVAL; | 2234 | err = -EINVAL; |
2212 | goto clean_up; | 2235 | goto clean_up; |
2213 | } else if (buf_owner != g) { | ||
2214 | /* Someone else's vidmem */ | ||
2215 | err = -EINVAL; | ||
2216 | goto clean_up; | ||
2217 | } else { | ||
2218 | /* Yay, buf_owner == g */ | ||
2219 | aperture = APERTURE_VIDMEM; | ||
2220 | } | 2236 | } |
2221 | 2237 | ||
2222 | /* update gmmu ptes */ | 2238 | /* update gmmu ptes */ |
@@ -2239,7 +2255,7 @@ u64 gk20a_vm_map(struct vm_gk20a *vm, | |||
2239 | gk20a_dbg(gpu_dbg_map, | 2255 | gk20a_dbg(gpu_dbg_map, |
2240 | "as=%d pgsz=%d " | 2256 | "as=%d pgsz=%d " |
2241 | "kind=0x%x kind_uc=0x%x flags=0x%x " | 2257 | "kind=0x%x kind_uc=0x%x flags=0x%x " |
2242 | "ctags=%d start=%d ctags_allocated=%d ctags_mappable=%d gv=0x%x,%08x -> 0x%x,%08x -> 0x%x,%08x", | 2258 | "ctags=%d start=%d ctags_allocated=%d ctags_mappable=%d gv=0x%x,%08x -> 0x%x,%08x -> 0x%x,%08x size=%lld/%lld aperture=%s", |
2243 | vm_aspace_id(vm), gmmu_page_size, | 2259 | vm_aspace_id(vm), gmmu_page_size, |
2244 | bfr.kind_v, bfr.uc_kind_v, flags, | 2260 | bfr.kind_v, bfr.uc_kind_v, flags, |
2245 | bfr.ctag_lines, bfr.ctag_offset, | 2261 | bfr.ctag_lines, bfr.ctag_offset, |
@@ -2248,7 +2264,9 @@ u64 gk20a_vm_map(struct vm_gk20a *vm, | |||
2248 | hi32((u64)sg_dma_address(bfr.sgt->sgl)), | 2264 | hi32((u64)sg_dma_address(bfr.sgt->sgl)), |
2249 | lo32((u64)sg_dma_address(bfr.sgt->sgl)), | 2265 | lo32((u64)sg_dma_address(bfr.sgt->sgl)), |
2250 | hi32((u64)sg_phys(bfr.sgt->sgl)), | 2266 | hi32((u64)sg_phys(bfr.sgt->sgl)), |
2251 | lo32((u64)sg_phys(bfr.sgt->sgl))); | 2267 | lo32((u64)sg_phys(bfr.sgt->sgl)), |
2268 | bfr.size, mapping_size, | ||
2269 | gk20a_aperture_str(aperture)); | ||
2252 | 2270 | ||
2253 | #if defined(NVHOST_DEBUG) | 2271 | #if defined(NVHOST_DEBUG) |
2254 | { | 2272 | { |
diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h index 5f0ce657..60f653e0 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h | |||
@@ -51,6 +51,16 @@ enum gk20a_aperture { | |||
51 | APERTURE_VIDMEM | 51 | APERTURE_VIDMEM |
52 | }; | 52 | }; |
53 | 53 | ||
54 | static inline const char *gk20a_aperture_str(enum gk20a_aperture aperture) | ||
55 | { | ||
56 | switch (aperture) { | ||
57 | case APERTURE_INVALID: return "invalid"; | ||
58 | case APERTURE_SYSMEM: return "sysmem"; | ||
59 | case APERTURE_VIDMEM: return "vidmem"; | ||
60 | }; | ||
61 | return "UNKNOWN"; | ||
62 | } | ||
63 | |||
54 | struct mem_desc { | 64 | struct mem_desc { |
55 | void *cpu_va; /* sysmem only */ | 65 | void *cpu_va; /* sysmem only */ |
56 | struct page **pages; /* sysmem only */ | 66 | struct page **pages; /* sysmem only */ |