Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/ttm: Add DMA map/unmap tracepoint (v3)

Also exports two functions that vendor drivers can call
to trace DMA mappings. This is meant to help translate
IOMMU mappings of bus addresses back to physical pages.

Used by the umr amdgpu debugger for instance.

Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

(v2): Use dev_name() to get PCI path instead.
(v3): Use correct types for dma/phys addresses

authored by

Tom St Denis and committed by
Alex Deucher
a92e1450 727030b0

+239 -1
+2 -1
drivers/gpu/drm/ttm/Makefile
··· 1 1 # 2 2 # Makefile for the drm device driver. This driver provides support for the 3 3 4 + ccflags-y := -I$(src)/. 4 5 ttm-y := ttm_memory.o ttm_tt.o ttm_bo.o \ 5 6 ttm_bo_util.o ttm_bo_vm.o ttm_module.o \ 6 7 ttm_object.o ttm_lock.o ttm_execbuf_util.o ttm_page_alloc.o \ 7 - ttm_bo_manager.o ttm_page_alloc_dma.o 8 + ttm_bo_manager.o ttm_page_alloc_dma.o ttm_debug.o ttm_tracepoints.o 8 9 ttm-$(CONFIG_AGP) += ttm_agp_backend.o 9 10 10 11 obj-$(CONFIG_DRM_TTM) += ttm.o
+74
drivers/gpu/drm/ttm/ttm_debug.c
··· 1 + /************************************************************************** 2 + * 3 + * Copyright (c) 2017 Advanced Micro Devices, Inc. 4 + * All Rights Reserved. 5 + * 6 + * Permission is hereby granted, free of charge, to any person obtaining a 7 + * copy of this software and associated documentation files (the 8 + * "Software"), to deal in the Software without restriction, including 9 + * without limitation the rights to use, copy, modify, merge, publish, 10 + * distribute, sub license, and/or sell copies of the Software, and to 11 + * permit persons to whom the Software is furnished to do so, subject to 12 + * the following conditions: 13 + * 14 + * The above copyright notice and this permission notice (including the 15 + * next paragraph) shall be included in all copies or substantial portions 16 + * of the Software. 17 + * 18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21 + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 22 + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24 + * USE OR OTHER DEALINGS IN THE SOFTWARE. 25 + * 26 + **************************************************************************/ 27 + /* 28 + * Authors: Tom St Denis <tom.stdenis@amd.com> 29 + */ 30 + #include <linux/sched.h> 31 + #include <linux/highmem.h> 32 + #include <linux/pagemap.h> 33 + #include <linux/shmem_fs.h> 34 + #include <linux/file.h> 35 + #include <linux/swap.h> 36 + #include <linux/slab.h> 37 + #include <linux/export.h> 38 + #include <drm/drm_cache.h> 39 + #include <drm/ttm/ttm_module.h> 40 + #include <drm/ttm/ttm_bo_driver.h> 41 + #include <drm/ttm/ttm_placement.h> 42 + #include <drm/ttm/ttm_page_alloc.h> 43 + #include "ttm_trace.h" 44 + 45 + void ttm_trace_dma_map(struct device *dev, struct ttm_dma_tt *tt) 46 + { 47 + unsigned i; 48 + 49 + if (unlikely(trace_ttm_dma_map_enabled())) { 50 + for (i = 0; i < tt->ttm.num_pages; i++) { 51 + trace_ttm_dma_map( 52 + dev, 53 + tt->ttm.pages[i], 54 + tt->dma_address[i]); 55 + } 56 + } 57 + } 58 + EXPORT_SYMBOL(ttm_trace_dma_map); 59 + 60 + void ttm_trace_dma_unmap(struct device *dev, struct ttm_dma_tt *tt) 61 + { 62 + unsigned i; 63 + 64 + if (unlikely(trace_ttm_dma_unmap_enabled())) { 65 + for (i = 0; i < tt->ttm.num_pages; i++) { 66 + trace_ttm_dma_unmap( 67 + dev, 68 + tt->ttm.pages[i], 69 + tt->dma_address[i]); 70 + } 71 + } 72 + } 73 + EXPORT_SYMBOL(ttm_trace_dma_unmap); 74 +
+87
drivers/gpu/drm/ttm/ttm_trace.h
··· 1 + /************************************************************************** 2 + * 3 + * Copyright (c) 2017 Advanced Micro Devices, Inc. 4 + * All Rights Reserved. 5 + * 6 + * Permission is hereby granted, free of charge, to any person obtaining a 7 + * copy of this software and associated documentation files (the 8 + * "Software"), to deal in the Software without restriction, including 9 + * without limitation the rights to use, copy, modify, merge, publish, 10 + * distribute, sub license, and/or sell copies of the Software, and to 11 + * permit persons to whom the Software is furnished to do so, subject to 12 + * the following conditions: 13 + * 14 + * The above copyright notice and this permission notice (including the 15 + * next paragraph) shall be included in all copies or substantial portions 16 + * of the Software. 17 + * 18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21 + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 22 + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24 + * USE OR OTHER DEALINGS IN THE SOFTWARE. 25 + * 26 + **************************************************************************/ 27 + /* 28 + * Authors: Tom St Denis <tom.stdenis@amd.com> 29 + */ 30 + #if !defined(_TTM_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) 31 + #define _TTM_TRACE_H_ 32 + 33 + #include <linux/stringify.h> 34 + #include <linux/types.h> 35 + #include <linux/tracepoint.h> 36 + 37 + #include <drm/drmP.h> 38 + 39 + #undef TRACE_SYSTEM 40 + #define TRACE_SYSTEM ttm 41 + #define TRACE_INCLUDE_FILE ttm_trace 42 + 43 + TRACE_EVENT(ttm_dma_map, 44 + TP_PROTO(struct device *dev, struct page *page, dma_addr_t dma_address), 45 + TP_ARGS(dev, page, dma_address), 46 + TP_STRUCT__entry( 47 + __string(device, dev_name(dev)) 48 + __field(dma_addr_t, dma) 49 + __field(phys_addr_t, phys) 50 + ), 51 + TP_fast_assign( 52 + __assign_str(device, dev_name(dev)); 53 + __entry->dma = dma_address; 54 + __entry->phys = page_to_phys(page); 55 + ), 56 + TP_printk("%s: %pad => %pa", 57 + __get_str(device), 58 + &__entry->dma, 59 + &__entry->phys) 60 + ); 61 + 62 + TRACE_EVENT(ttm_dma_unmap, 63 + TP_PROTO(struct device *dev, struct page *page, dma_addr_t dma_address), 64 + TP_ARGS(dev, page, dma_address), 65 + TP_STRUCT__entry( 66 + __string(device, dev_name(dev)) 67 + __field(dma_addr_t, dma) 68 + __field(phys_addr_t, phys) 69 + ), 70 + TP_fast_assign( 71 + __assign_str(device, dev_name(dev)); 72 + __entry->dma = dma_address; 73 + __entry->phys = page_to_phys(page); 74 + ), 75 + TP_printk("%s: %pad => %pa", 76 + __get_str(device), 77 + &__entry->dma, 78 + &__entry->phys) 79 + ); 80 + 81 + #endif 82 + 83 + /* This part must be outside protection */ 84 + #undef TRACE_INCLUDE_PATH 85 + #define TRACE_INCLUDE_PATH . 86 + #include <trace/define_trace.h> 87 +
+45
drivers/gpu/drm/ttm/ttm_tracepoints.c
··· 1 + /************************************************************************** 2 + * 3 + * Copyright (c) 2017 Advanced Micro Devices, Inc. 4 + * All Rights Reserved. 5 + * 6 + * Permission is hereby granted, free of charge, to any person obtaining a 7 + * copy of this software and associated documentation files (the 8 + * "Software"), to deal in the Software without restriction, including 9 + * without limitation the rights to use, copy, modify, merge, publish, 10 + * distribute, sub license, and/or sell copies of the Software, and to 11 + * permit persons to whom the Software is furnished to do so, subject to 12 + * the following conditions: 13 + * 14 + * The above copyright notice and this permission notice (including the 15 + * next paragraph) shall be included in all copies or substantial portions 16 + * of the Software. 17 + * 18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21 + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 22 + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24 + * USE OR OTHER DEALINGS IN THE SOFTWARE. 25 + * 26 + **************************************************************************/ 27 + /* 28 + * Authors: Tom St Denis <tom.stdenis@amd.com> 29 + */ 30 + #include <linux/sched.h> 31 + #include <linux/highmem.h> 32 + #include <linux/pagemap.h> 33 + #include <linux/shmem_fs.h> 34 + #include <linux/file.h> 35 + #include <linux/swap.h> 36 + #include <linux/slab.h> 37 + #include <linux/export.h> 38 + #include <drm/drm_cache.h> 39 + #include <drm/ttm/ttm_module.h> 40 + #include <drm/ttm/ttm_bo_driver.h> 41 + #include <drm/ttm/ttm_placement.h> 42 + #include <drm/ttm/ttm_page_alloc.h> 43 + 44 + #define CREATE_TRACE_POINTS 45 + #include "ttm_trace.h"
+31
include/drm/ttm/ttm_debug.h
··· 1 + /************************************************************************** 2 + * 3 + * Copyright (c) 2017 Advanced Micro Devices, Inc. 4 + * All Rights Reserved. 5 + * 6 + * Permission is hereby granted, free of charge, to any person obtaining a 7 + * copy of this software and associated documentation files (the 8 + * "Software"), to deal in the Software without restriction, including 9 + * without limitation the rights to use, copy, modify, merge, publish, 10 + * distribute, sub license, and/or sell copies of the Software, and to 11 + * permit persons to whom the Software is furnished to do so, subject to 12 + * the following conditions: 13 + * 14 + * The above copyright notice and this permission notice (including the 15 + * next paragraph) shall be included in all copies or substantial portions 16 + * of the Software. 17 + * 18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21 + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 22 + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24 + * USE OR OTHER DEALINGS IN THE SOFTWARE. 25 + * 26 + **************************************************************************/ 27 + /* 28 + * Authors: Tom St Denis <tom.stdenis@amd.com> 29 + */ 30 + extern void ttm_trace_dma_map(struct device *dev, struct ttm_dma_tt *tt); 31 + extern void ttm_trace_dma_unmap(struct device *dev, struct ttm_dma_tt *tt);