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

drm/vram: Move VRAM memory manager to GEM VRAM implementation

The separation between GEM VRAM objects and the memory manager is
artificial, as they are only used with each other. Copying both
implementations into the same file is a first step to simplifying
the code.

This patch only moves code without functional changes.

v3:
* update to use dev->vma_offset_manager
v2:
* update for debugfs support
* typos in commit message

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190911110910.30698-2-tzimmermann@suse.de

+435 -455
-12
Documentation/gpu/drm-mm.rst
··· 400 400 .. kernel-doc:: drivers/gpu/drm/drm_gem_vram_helper.c 401 401 :export: 402 402 403 - VRAM MM Helper Functions Reference 404 - ---------------------------------- 405 - 406 - .. kernel-doc:: drivers/gpu/drm/drm_vram_mm_helper.c 407 - :doc: overview 408 - 409 - .. kernel-doc:: include/drm/drm_vram_mm_helper.h 410 - :internal: 411 - 412 - .. kernel-doc:: drivers/gpu/drm/drm_vram_mm_helper.c 413 - :export: 414 - 415 403 GEM TTM Helper Functions Reference 416 404 ----------------------------------- 417 405
+1 -2
drivers/gpu/drm/Makefile
··· 33 33 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o 34 34 35 35 drm_vram_helper-y := drm_gem_vram_helper.o \ 36 - drm_vram_helper_common.o \ 37 - drm_vram_mm_helper.o 36 + drm_vram_helper_common.o 38 37 obj-$(CONFIG_DRM_VRAM_HELPER) += drm_vram_helper.o 39 38 40 39 drm_ttm_helper-y := drm_gem_ttm_helper.o
-1
drivers/gpu/drm/ast/ast_drv.c
··· 35 35 #include <drm/drm_gem_vram_helper.h> 36 36 #include <drm/drm_pci.h> 37 37 #include <drm/drm_probe_helper.h> 38 - #include <drm/drm_vram_mm_helper.h> 39 38 40 39 #include "ast_drv.h" 41 40
-1
drivers/gpu/drm/ast/ast_main.c
··· 33 33 #include <drm/drm_gem.h> 34 34 #include <drm/drm_gem_framebuffer_helper.h> 35 35 #include <drm/drm_gem_vram_helper.h> 36 - #include <drm/drm_vram_mm_helper.h> 37 36 38 37 #include "ast_drv.h" 39 38
-1
drivers/gpu/drm/ast/ast_ttm.c
··· 30 30 31 31 #include <drm/drm_print.h> 32 32 #include <drm/drm_gem_vram_helper.h> 33 - #include <drm/drm_vram_mm_helper.h> 34 33 35 34 #include "ast_drv.h" 36 35
-1
drivers/gpu/drm/bochs/bochs.h
··· 10 10 #include <drm/drm_gem.h> 11 11 #include <drm/drm_gem_vram_helper.h> 12 12 #include <drm/drm_simple_kms_helper.h> 13 - #include <drm/drm_vram_mm_helper.h> 14 13 15 14 /* ---------------------------------------------------------------------- */ 16 15
+348 -1
drivers/gpu/drm/drm_gem_vram_helper.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 2 3 + #include <drm/drm_debugfs.h> 4 + #include <drm/drm_device.h> 5 + #include <drm/drm_file.h> 3 6 #include <drm/drm_gem_ttm_helper.h> 4 7 #include <drm/drm_gem_vram_helper.h> 5 - #include <drm/drm_device.h> 6 8 #include <drm/drm_mode.h> 7 9 #include <drm/drm_prime.h> 8 10 #include <drm/drm_vram_mm_helper.h> ··· 17 15 * 18 16 * This library provides a GEM buffer object that is backed by video RAM 19 17 * (VRAM). It can be used for framebuffer devices with dedicated memory. 18 + * 19 + * The data structure &struct drm_vram_mm and its helpers implement a memory 20 + * manager for simple framebuffer devices with dedicated video memory. Buffer 21 + * objects are either placed in video RAM or evicted to system memory. The rsp. 22 + * buffer object is provided by &struct drm_gem_vram_object. 20 23 */ 21 24 22 25 /* ··· 743 736 .vunmap = drm_gem_vram_object_vunmap, 744 737 .print_info = drm_gem_ttm_print_info, 745 738 }; 739 + 740 + /* 741 + * VRAM memory manager 742 + */ 743 + 744 + /* 745 + * TTM TT 746 + */ 747 + 748 + static void backend_func_destroy(struct ttm_tt *tt) 749 + { 750 + ttm_tt_fini(tt); 751 + kfree(tt); 752 + } 753 + 754 + static struct ttm_backend_func backend_func = { 755 + .destroy = backend_func_destroy 756 + }; 757 + 758 + /* 759 + * TTM BO device 760 + */ 761 + 762 + static struct ttm_tt *bo_driver_ttm_tt_create(struct ttm_buffer_object *bo, 763 + uint32_t page_flags) 764 + { 765 + struct ttm_tt *tt; 766 + int ret; 767 + 768 + tt = kzalloc(sizeof(*tt), GFP_KERNEL); 769 + if (!tt) 770 + return NULL; 771 + 772 + tt->func = &backend_func; 773 + 774 + ret = ttm_tt_init(tt, bo, page_flags); 775 + if (ret < 0) 776 + goto err_ttm_tt_init; 777 + 778 + return tt; 779 + 780 + err_ttm_tt_init: 781 + kfree(tt); 782 + return NULL; 783 + } 784 + 785 + static int bo_driver_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, 786 + struct ttm_mem_type_manager *man) 787 + { 788 + switch (type) { 789 + case TTM_PL_SYSTEM: 790 + man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; 791 + man->available_caching = TTM_PL_MASK_CACHING; 792 + man->default_caching = TTM_PL_FLAG_CACHED; 793 + break; 794 + case TTM_PL_VRAM: 795 + man->func = &ttm_bo_manager_func; 796 + man->flags = TTM_MEMTYPE_FLAG_FIXED | 797 + TTM_MEMTYPE_FLAG_MAPPABLE; 798 + man->available_caching = TTM_PL_FLAG_UNCACHED | 799 + TTM_PL_FLAG_WC; 800 + man->default_caching = TTM_PL_FLAG_WC; 801 + break; 802 + default: 803 + return -EINVAL; 804 + } 805 + return 0; 806 + } 807 + 808 + static void bo_driver_evict_flags(struct ttm_buffer_object *bo, 809 + struct ttm_placement *placement) 810 + { 811 + struct drm_vram_mm *vmm = drm_vram_mm_of_bdev(bo->bdev); 812 + 813 + if (vmm->funcs && vmm->funcs->evict_flags) 814 + vmm->funcs->evict_flags(bo, placement); 815 + } 816 + 817 + static int bo_driver_verify_access(struct ttm_buffer_object *bo, 818 + struct file *filp) 819 + { 820 + struct drm_vram_mm *vmm = drm_vram_mm_of_bdev(bo->bdev); 821 + 822 + if (!vmm->funcs || !vmm->funcs->verify_access) 823 + return 0; 824 + return vmm->funcs->verify_access(bo, filp); 825 + } 826 + 827 + static void bo_driver_move_notify(struct ttm_buffer_object *bo, 828 + bool evict, 829 + struct ttm_mem_reg *new_mem) 830 + { 831 + struct drm_vram_mm *vmm = drm_vram_mm_of_bdev(bo->bdev); 832 + 833 + if (!vmm->funcs || !vmm->funcs->move_notify) 834 + return; 835 + vmm->funcs->move_notify(bo, evict, new_mem); 836 + } 837 + 838 + static int bo_driver_io_mem_reserve(struct ttm_bo_device *bdev, 839 + struct ttm_mem_reg *mem) 840 + { 841 + struct ttm_mem_type_manager *man = bdev->man + mem->mem_type; 842 + struct drm_vram_mm *vmm = drm_vram_mm_of_bdev(bdev); 843 + 844 + if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE)) 845 + return -EINVAL; 846 + 847 + mem->bus.addr = NULL; 848 + mem->bus.size = mem->num_pages << PAGE_SHIFT; 849 + 850 + switch (mem->mem_type) { 851 + case TTM_PL_SYSTEM: /* nothing to do */ 852 + mem->bus.offset = 0; 853 + mem->bus.base = 0; 854 + mem->bus.is_iomem = false; 855 + break; 856 + case TTM_PL_VRAM: 857 + mem->bus.offset = mem->start << PAGE_SHIFT; 858 + mem->bus.base = vmm->vram_base; 859 + mem->bus.is_iomem = true; 860 + break; 861 + default: 862 + return -EINVAL; 863 + } 864 + 865 + return 0; 866 + } 867 + 868 + static void bo_driver_io_mem_free(struct ttm_bo_device *bdev, 869 + struct ttm_mem_reg *mem) 870 + { } 871 + 872 + static struct ttm_bo_driver bo_driver = { 873 + .ttm_tt_create = bo_driver_ttm_tt_create, 874 + .ttm_tt_populate = ttm_pool_populate, 875 + .ttm_tt_unpopulate = ttm_pool_unpopulate, 876 + .init_mem_type = bo_driver_init_mem_type, 877 + .eviction_valuable = ttm_bo_eviction_valuable, 878 + .evict_flags = bo_driver_evict_flags, 879 + .verify_access = bo_driver_verify_access, 880 + .move_notify = bo_driver_move_notify, 881 + .io_mem_reserve = bo_driver_io_mem_reserve, 882 + .io_mem_free = bo_driver_io_mem_free, 883 + }; 884 + 885 + /* 886 + * struct drm_vram_mm 887 + */ 888 + 889 + #if defined(CONFIG_DEBUG_FS) 890 + static int drm_vram_mm_debugfs(struct seq_file *m, void *data) 891 + { 892 + struct drm_info_node *node = (struct drm_info_node *) m->private; 893 + struct drm_vram_mm *vmm = node->minor->dev->vram_mm; 894 + struct drm_mm *mm = vmm->bdev.man[TTM_PL_VRAM].priv; 895 + struct ttm_bo_global *glob = vmm->bdev.glob; 896 + struct drm_printer p = drm_seq_file_printer(m); 897 + 898 + spin_lock(&glob->lru_lock); 899 + drm_mm_print(mm, &p); 900 + spin_unlock(&glob->lru_lock); 901 + return 0; 902 + } 903 + 904 + static const struct drm_info_list drm_vram_mm_debugfs_list[] = { 905 + { "vram-mm", drm_vram_mm_debugfs, 0, NULL }, 906 + }; 907 + #endif 908 + 909 + /** 910 + * drm_vram_mm_debugfs_init() - Register VRAM MM debugfs file. 911 + * 912 + * @minor: drm minor device. 913 + * 914 + * Returns: 915 + * 0 on success, or 916 + * a negative error code otherwise. 917 + */ 918 + int drm_vram_mm_debugfs_init(struct drm_minor *minor) 919 + { 920 + int ret = 0; 921 + 922 + #if defined(CONFIG_DEBUG_FS) 923 + ret = drm_debugfs_create_files(drm_vram_mm_debugfs_list, 924 + ARRAY_SIZE(drm_vram_mm_debugfs_list), 925 + minor->debugfs_root, minor); 926 + #endif 927 + return ret; 928 + } 929 + EXPORT_SYMBOL(drm_vram_mm_debugfs_init); 930 + 931 + /** 932 + * drm_vram_mm_init() - Initialize an instance of VRAM MM. 933 + * @vmm: the VRAM MM instance to initialize 934 + * @dev: the DRM device 935 + * @vram_base: the base address of the video memory 936 + * @vram_size: the size of the video memory in bytes 937 + * @funcs: callback functions for buffer objects 938 + * 939 + * Returns: 940 + * 0 on success, or 941 + * a negative error code otherwise. 942 + */ 943 + int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev, 944 + uint64_t vram_base, size_t vram_size, 945 + const struct drm_vram_mm_funcs *funcs) 946 + { 947 + int ret; 948 + 949 + vmm->vram_base = vram_base; 950 + vmm->vram_size = vram_size; 951 + vmm->funcs = funcs; 952 + 953 + ret = ttm_bo_device_init(&vmm->bdev, &bo_driver, 954 + dev->anon_inode->i_mapping, 955 + dev->vma_offset_manager, 956 + true); 957 + if (ret) 958 + return ret; 959 + 960 + ret = ttm_bo_init_mm(&vmm->bdev, TTM_PL_VRAM, vram_size >> PAGE_SHIFT); 961 + if (ret) 962 + return ret; 963 + 964 + return 0; 965 + } 966 + EXPORT_SYMBOL(drm_vram_mm_init); 967 + 968 + /** 969 + * drm_vram_mm_cleanup() - Cleans up an initialized instance of VRAM MM. 970 + * @vmm: the VRAM MM instance to clean up 971 + */ 972 + void drm_vram_mm_cleanup(struct drm_vram_mm *vmm) 973 + { 974 + ttm_bo_device_release(&vmm->bdev); 975 + } 976 + EXPORT_SYMBOL(drm_vram_mm_cleanup); 977 + 978 + /** 979 + * drm_vram_mm_mmap() - Helper for implementing &struct file_operations.mmap() 980 + * @filp: the mapping's file structure 981 + * @vma: the mapping's memory area 982 + * @vmm: the VRAM MM instance 983 + * 984 + * Returns: 985 + * 0 on success, or 986 + * a negative error code otherwise. 987 + */ 988 + int drm_vram_mm_mmap(struct file *filp, struct vm_area_struct *vma, 989 + struct drm_vram_mm *vmm) 990 + { 991 + return ttm_bo_mmap(filp, vma, &vmm->bdev); 992 + } 993 + EXPORT_SYMBOL(drm_vram_mm_mmap); 994 + 995 + /* 996 + * Helpers for integration with struct drm_device 997 + */ 998 + 999 + /** 1000 + * drm_vram_helper_alloc_mm - Allocates a device's instance of \ 1001 + &struct drm_vram_mm 1002 + * @dev: the DRM device 1003 + * @vram_base: the base address of the video memory 1004 + * @vram_size: the size of the video memory in bytes 1005 + * @funcs: callback functions for buffer objects 1006 + * 1007 + * Returns: 1008 + * The new instance of &struct drm_vram_mm on success, or 1009 + * an ERR_PTR()-encoded errno code otherwise. 1010 + */ 1011 + struct drm_vram_mm *drm_vram_helper_alloc_mm( 1012 + struct drm_device *dev, uint64_t vram_base, size_t vram_size, 1013 + const struct drm_vram_mm_funcs *funcs) 1014 + { 1015 + int ret; 1016 + 1017 + if (WARN_ON(dev->vram_mm)) 1018 + return dev->vram_mm; 1019 + 1020 + dev->vram_mm = kzalloc(sizeof(*dev->vram_mm), GFP_KERNEL); 1021 + if (!dev->vram_mm) 1022 + return ERR_PTR(-ENOMEM); 1023 + 1024 + ret = drm_vram_mm_init(dev->vram_mm, dev, vram_base, vram_size, funcs); 1025 + if (ret) 1026 + goto err_kfree; 1027 + 1028 + return dev->vram_mm; 1029 + 1030 + err_kfree: 1031 + kfree(dev->vram_mm); 1032 + dev->vram_mm = NULL; 1033 + return ERR_PTR(ret); 1034 + } 1035 + EXPORT_SYMBOL(drm_vram_helper_alloc_mm); 1036 + 1037 + /** 1038 + * drm_vram_helper_release_mm - Releases a device's instance of \ 1039 + &struct drm_vram_mm 1040 + * @dev: the DRM device 1041 + */ 1042 + void drm_vram_helper_release_mm(struct drm_device *dev) 1043 + { 1044 + if (!dev->vram_mm) 1045 + return; 1046 + 1047 + drm_vram_mm_cleanup(dev->vram_mm); 1048 + kfree(dev->vram_mm); 1049 + dev->vram_mm = NULL; 1050 + } 1051 + EXPORT_SYMBOL(drm_vram_helper_release_mm); 1052 + 1053 + /* 1054 + * Helpers for &struct file_operations 1055 + */ 1056 + 1057 + /** 1058 + * drm_vram_mm_file_operations_mmap() - \ 1059 + Implements &struct file_operations.mmap() 1060 + * @filp: the mapping's file structure 1061 + * @vma: the mapping's memory area 1062 + * 1063 + * Returns: 1064 + * 0 on success, or 1065 + * a negative error code otherwise. 1066 + */ 1067 + int drm_vram_mm_file_operations_mmap( 1068 + struct file *filp, struct vm_area_struct *vma) 1069 + { 1070 + struct drm_file *file_priv = filp->private_data; 1071 + struct drm_device *dev = file_priv->minor->dev; 1072 + 1073 + if (WARN_ONCE(!dev->vram_mm, "VRAM MM not initialized")) 1074 + return -EINVAL; 1075 + 1076 + return drm_vram_mm_mmap(filp, vma, dev->vram_mm); 1077 + } 1078 + EXPORT_SYMBOL(drm_vram_mm_file_operations_mmap);
-354
drivers/gpu/drm/drm_vram_mm_helper.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - 3 - #include <drm/drm_debugfs.h> 4 - #include <drm/drm_device.h> 5 - #include <drm/drm_file.h> 6 - #include <drm/drm_gem_ttm_helper.h> 7 - #include <drm/drm_vram_mm_helper.h> 8 - 9 - #include <drm/ttm/ttm_page_alloc.h> 10 - 11 - /** 12 - * DOC: overview 13 - * 14 - * The data structure &struct drm_vram_mm and its helpers implement a memory 15 - * manager for simple framebuffer devices with dedicated video memory. Buffer 16 - * objects are either placed in video RAM or evicted to system memory. These 17 - * helper functions work well with &struct drm_gem_vram_object. 18 - */ 19 - 20 - /* 21 - * TTM TT 22 - */ 23 - 24 - static void backend_func_destroy(struct ttm_tt *tt) 25 - { 26 - ttm_tt_fini(tt); 27 - kfree(tt); 28 - } 29 - 30 - static struct ttm_backend_func backend_func = { 31 - .destroy = backend_func_destroy 32 - }; 33 - 34 - /* 35 - * TTM BO device 36 - */ 37 - 38 - static struct ttm_tt *bo_driver_ttm_tt_create(struct ttm_buffer_object *bo, 39 - uint32_t page_flags) 40 - { 41 - struct ttm_tt *tt; 42 - int ret; 43 - 44 - tt = kzalloc(sizeof(*tt), GFP_KERNEL); 45 - if (!tt) 46 - return NULL; 47 - 48 - tt->func = &backend_func; 49 - 50 - ret = ttm_tt_init(tt, bo, page_flags); 51 - if (ret < 0) 52 - goto err_ttm_tt_init; 53 - 54 - return tt; 55 - 56 - err_ttm_tt_init: 57 - kfree(tt); 58 - return NULL; 59 - } 60 - 61 - static int bo_driver_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, 62 - struct ttm_mem_type_manager *man) 63 - { 64 - switch (type) { 65 - case TTM_PL_SYSTEM: 66 - man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; 67 - man->available_caching = TTM_PL_MASK_CACHING; 68 - man->default_caching = TTM_PL_FLAG_CACHED; 69 - break; 70 - case TTM_PL_VRAM: 71 - man->func = &ttm_bo_manager_func; 72 - man->flags = TTM_MEMTYPE_FLAG_FIXED | 73 - TTM_MEMTYPE_FLAG_MAPPABLE; 74 - man->available_caching = TTM_PL_FLAG_UNCACHED | 75 - TTM_PL_FLAG_WC; 76 - man->default_caching = TTM_PL_FLAG_WC; 77 - break; 78 - default: 79 - return -EINVAL; 80 - } 81 - return 0; 82 - } 83 - 84 - static void bo_driver_evict_flags(struct ttm_buffer_object *bo, 85 - struct ttm_placement *placement) 86 - { 87 - struct drm_vram_mm *vmm = drm_vram_mm_of_bdev(bo->bdev); 88 - 89 - if (vmm->funcs && vmm->funcs->evict_flags) 90 - vmm->funcs->evict_flags(bo, placement); 91 - } 92 - 93 - static int bo_driver_verify_access(struct ttm_buffer_object *bo, 94 - struct file *filp) 95 - { 96 - struct drm_vram_mm *vmm = drm_vram_mm_of_bdev(bo->bdev); 97 - 98 - if (!vmm->funcs || !vmm->funcs->verify_access) 99 - return 0; 100 - return vmm->funcs->verify_access(bo, filp); 101 - } 102 - 103 - static void bo_driver_move_notify(struct ttm_buffer_object *bo, 104 - bool evict, 105 - struct ttm_mem_reg *new_mem) 106 - { 107 - struct drm_vram_mm *vmm = drm_vram_mm_of_bdev(bo->bdev); 108 - 109 - if (!vmm->funcs || !vmm->funcs->move_notify) 110 - return; 111 - vmm->funcs->move_notify(bo, evict, new_mem); 112 - } 113 - 114 - static int bo_driver_io_mem_reserve(struct ttm_bo_device *bdev, 115 - struct ttm_mem_reg *mem) 116 - { 117 - struct ttm_mem_type_manager *man = bdev->man + mem->mem_type; 118 - struct drm_vram_mm *vmm = drm_vram_mm_of_bdev(bdev); 119 - 120 - if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE)) 121 - return -EINVAL; 122 - 123 - mem->bus.addr = NULL; 124 - mem->bus.size = mem->num_pages << PAGE_SHIFT; 125 - 126 - switch (mem->mem_type) { 127 - case TTM_PL_SYSTEM: /* nothing to do */ 128 - mem->bus.offset = 0; 129 - mem->bus.base = 0; 130 - mem->bus.is_iomem = false; 131 - break; 132 - case TTM_PL_VRAM: 133 - mem->bus.offset = mem->start << PAGE_SHIFT; 134 - mem->bus.base = vmm->vram_base; 135 - mem->bus.is_iomem = true; 136 - break; 137 - default: 138 - return -EINVAL; 139 - } 140 - 141 - return 0; 142 - } 143 - 144 - static void bo_driver_io_mem_free(struct ttm_bo_device *bdev, 145 - struct ttm_mem_reg *mem) 146 - { } 147 - 148 - static struct ttm_bo_driver bo_driver = { 149 - .ttm_tt_create = bo_driver_ttm_tt_create, 150 - .ttm_tt_populate = ttm_pool_populate, 151 - .ttm_tt_unpopulate = ttm_pool_unpopulate, 152 - .init_mem_type = bo_driver_init_mem_type, 153 - .eviction_valuable = ttm_bo_eviction_valuable, 154 - .evict_flags = bo_driver_evict_flags, 155 - .verify_access = bo_driver_verify_access, 156 - .move_notify = bo_driver_move_notify, 157 - .io_mem_reserve = bo_driver_io_mem_reserve, 158 - .io_mem_free = bo_driver_io_mem_free, 159 - }; 160 - 161 - /* 162 - * struct drm_vram_mm 163 - */ 164 - 165 - #if defined(CONFIG_DEBUG_FS) 166 - static int drm_vram_mm_debugfs(struct seq_file *m, void *data) 167 - { 168 - struct drm_info_node *node = (struct drm_info_node *) m->private; 169 - struct drm_vram_mm *vmm = node->minor->dev->vram_mm; 170 - struct drm_mm *mm = vmm->bdev.man[TTM_PL_VRAM].priv; 171 - struct ttm_bo_global *glob = vmm->bdev.glob; 172 - struct drm_printer p = drm_seq_file_printer(m); 173 - 174 - spin_lock(&glob->lru_lock); 175 - drm_mm_print(mm, &p); 176 - spin_unlock(&glob->lru_lock); 177 - return 0; 178 - } 179 - 180 - static const struct drm_info_list drm_vram_mm_debugfs_list[] = { 181 - { "vram-mm", drm_vram_mm_debugfs, 0, NULL }, 182 - }; 183 - #endif 184 - 185 - /** 186 - * drm_vram_mm_debugfs_init() - Register VRAM MM debugfs file. 187 - * 188 - * @minor: drm minor device. 189 - * 190 - * Returns: 191 - * 0 on success, or 192 - * a negative error code otherwise. 193 - */ 194 - int drm_vram_mm_debugfs_init(struct drm_minor *minor) 195 - { 196 - int ret = 0; 197 - 198 - #if defined(CONFIG_DEBUG_FS) 199 - ret = drm_debugfs_create_files(drm_vram_mm_debugfs_list, 200 - ARRAY_SIZE(drm_vram_mm_debugfs_list), 201 - minor->debugfs_root, minor); 202 - #endif 203 - return ret; 204 - } 205 - EXPORT_SYMBOL(drm_vram_mm_debugfs_init); 206 - 207 - /** 208 - * drm_vram_mm_init() - Initialize an instance of VRAM MM. 209 - * @vmm: the VRAM MM instance to initialize 210 - * @dev: the DRM device 211 - * @vram_base: the base address of the video memory 212 - * @vram_size: the size of the video memory in bytes 213 - * @funcs: callback functions for buffer objects 214 - * 215 - * Returns: 216 - * 0 on success, or 217 - * a negative error code otherwise. 218 - */ 219 - int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev, 220 - uint64_t vram_base, size_t vram_size, 221 - const struct drm_vram_mm_funcs *funcs) 222 - { 223 - int ret; 224 - 225 - vmm->vram_base = vram_base; 226 - vmm->vram_size = vram_size; 227 - vmm->funcs = funcs; 228 - 229 - ret = ttm_bo_device_init(&vmm->bdev, &bo_driver, 230 - dev->anon_inode->i_mapping, 231 - dev->vma_offset_manager, 232 - true); 233 - if (ret) 234 - return ret; 235 - 236 - ret = ttm_bo_init_mm(&vmm->bdev, TTM_PL_VRAM, vram_size >> PAGE_SHIFT); 237 - if (ret) 238 - return ret; 239 - 240 - return 0; 241 - } 242 - EXPORT_SYMBOL(drm_vram_mm_init); 243 - 244 - /** 245 - * drm_vram_mm_cleanup() - Cleans up an initialized instance of VRAM MM. 246 - * @vmm: the VRAM MM instance to clean up 247 - */ 248 - void drm_vram_mm_cleanup(struct drm_vram_mm *vmm) 249 - { 250 - ttm_bo_device_release(&vmm->bdev); 251 - } 252 - EXPORT_SYMBOL(drm_vram_mm_cleanup); 253 - 254 - /** 255 - * drm_vram_mm_mmap() - Helper for implementing &struct file_operations.mmap() 256 - * @filp: the mapping's file structure 257 - * @vma: the mapping's memory area 258 - * @vmm: the VRAM MM instance 259 - * 260 - * Returns: 261 - * 0 on success, or 262 - * a negative error code otherwise. 263 - */ 264 - int drm_vram_mm_mmap(struct file *filp, struct vm_area_struct *vma, 265 - struct drm_vram_mm *vmm) 266 - { 267 - return ttm_bo_mmap(filp, vma, &vmm->bdev); 268 - } 269 - EXPORT_SYMBOL(drm_vram_mm_mmap); 270 - 271 - /* 272 - * Helpers for integration with struct drm_device 273 - */ 274 - 275 - /** 276 - * drm_vram_helper_alloc_mm - Allocates a device's instance of \ 277 - &struct drm_vram_mm 278 - * @dev: the DRM device 279 - * @vram_base: the base address of the video memory 280 - * @vram_size: the size of the video memory in bytes 281 - * @funcs: callback functions for buffer objects 282 - * 283 - * Returns: 284 - * The new instance of &struct drm_vram_mm on success, or 285 - * an ERR_PTR()-encoded errno code otherwise. 286 - */ 287 - struct drm_vram_mm *drm_vram_helper_alloc_mm( 288 - struct drm_device *dev, uint64_t vram_base, size_t vram_size, 289 - const struct drm_vram_mm_funcs *funcs) 290 - { 291 - int ret; 292 - 293 - if (WARN_ON(dev->vram_mm)) 294 - return dev->vram_mm; 295 - 296 - dev->vram_mm = kzalloc(sizeof(*dev->vram_mm), GFP_KERNEL); 297 - if (!dev->vram_mm) 298 - return ERR_PTR(-ENOMEM); 299 - 300 - ret = drm_vram_mm_init(dev->vram_mm, dev, vram_base, vram_size, funcs); 301 - if (ret) 302 - goto err_kfree; 303 - 304 - return dev->vram_mm; 305 - 306 - err_kfree: 307 - kfree(dev->vram_mm); 308 - dev->vram_mm = NULL; 309 - return ERR_PTR(ret); 310 - } 311 - EXPORT_SYMBOL(drm_vram_helper_alloc_mm); 312 - 313 - /** 314 - * drm_vram_helper_release_mm - Releases a device's instance of \ 315 - &struct drm_vram_mm 316 - * @dev: the DRM device 317 - */ 318 - void drm_vram_helper_release_mm(struct drm_device *dev) 319 - { 320 - if (!dev->vram_mm) 321 - return; 322 - 323 - drm_vram_mm_cleanup(dev->vram_mm); 324 - kfree(dev->vram_mm); 325 - dev->vram_mm = NULL; 326 - } 327 - EXPORT_SYMBOL(drm_vram_helper_release_mm); 328 - 329 - /* 330 - * Helpers for &struct file_operations 331 - */ 332 - 333 - /** 334 - * drm_vram_mm_file_operations_mmap() - \ 335 - Implements &struct file_operations.mmap() 336 - * @filp: the mapping's file structure 337 - * @vma: the mapping's memory area 338 - * 339 - * Returns: 340 - * 0 on success, or 341 - * a negative error code otherwise. 342 - */ 343 - int drm_vram_mm_file_operations_mmap( 344 - struct file *filp, struct vm_area_struct *vma) 345 - { 346 - struct drm_file *file_priv = filp->private_data; 347 - struct drm_device *dev = file_priv->minor->dev; 348 - 349 - if (WARN_ONCE(!dev->vram_mm, "VRAM MM not initialized")) 350 - return -EINVAL; 351 - 352 - return drm_vram_mm_mmap(filp, vma, dev->vram_mm); 353 - } 354 - EXPORT_SYMBOL(drm_vram_mm_file_operations_mmap);
-1
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
··· 22 22 #include <drm/drm_print.h> 23 23 #include <drm/drm_probe_helper.h> 24 24 #include <drm/drm_vblank.h> 25 - #include <drm/drm_vram_mm_helper.h> 26 25 27 26 #include "hibmc_drm_drv.h" 28 27 #include "hibmc_drm_regs.h"
-1
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
··· 17 17 #include <drm/drm_gem.h> 18 18 #include <drm/drm_gem_vram_helper.h> 19 19 #include <drm/drm_print.h> 20 - #include <drm/drm_vram_mm_helper.h> 21 20 22 21 #include "hibmc_drm_drv.h" 23 22
-1
drivers/gpu/drm/mgag200/mgag200_drv.h
··· 19 19 #include <drm/drm_fb_helper.h> 20 20 #include <drm/drm_gem.h> 21 21 #include <drm/drm_gem_vram_helper.h> 22 - #include <drm/drm_vram_mm_helper.h> 23 22 24 23 #include "mgag200_reg.h" 25 24
-2
drivers/gpu/drm/vboxvideo/vbox_drv.h
··· 20 20 #include <drm/drm_gem.h> 21 21 #include <drm/drm_gem_vram_helper.h> 22 22 23 - #include <drm/drm_vram_mm_helper.h> 24 - 25 23 #include "vboxvideo_guest.h" 26 24 #include "vboxvideo_vbe.h" 27 25 #include "hgsmi_ch_setup.h"
+86
include/drm/drm_gem_vram_helper.h
··· 3 3 #ifndef DRM_GEM_VRAM_HELPER_H 4 4 #define DRM_GEM_VRAM_HELPER_H 5 5 6 + #include <drm/drm_file.h> 6 7 #include <drm/drm_gem.h> 8 + #include <drm/drm_ioctl.h> 7 9 #include <drm/ttm/ttm_bo_api.h> 10 + #include <drm/ttm/ttm_bo_driver.h> 8 11 #include <drm/ttm/ttm_placement.h> 12 + 9 13 #include <linux/kernel.h> /* for container_of() */ 10 14 11 15 struct drm_mode_create_dumb; ··· 148 144 .dumb_create = drm_gem_vram_driver_dumb_create, \ 149 145 .dumb_map_offset = drm_gem_vram_driver_dumb_mmap_offset, \ 150 146 .gem_prime_mmap = drm_gem_prime_mmap 147 + 148 + /* 149 + * VRAM memory manager 150 + */ 151 + 152 + /** 153 + * struct drm_vram_mm - An instance of VRAM MM 154 + * @vram_base: Base address of the managed video memory 155 + * @vram_size: Size of the managed video memory in bytes 156 + * @bdev: The TTM BO device. 157 + * @funcs: TTM BO functions 158 + * 159 + * The fields &struct drm_vram_mm.vram_base and 160 + * &struct drm_vram_mm.vrm_size are managed by VRAM MM, but are 161 + * available for public read access. Use the field 162 + * &struct drm_vram_mm.bdev to access the TTM BO device. 163 + */ 164 + struct drm_vram_mm { 165 + uint64_t vram_base; 166 + size_t vram_size; 167 + 168 + struct ttm_bo_device bdev; 169 + 170 + const struct drm_vram_mm_funcs *funcs; 171 + }; 172 + 173 + /** 174 + * drm_vram_mm_of_bdev() - \ 175 + Returns the container of type &struct ttm_bo_device for field bdev. 176 + * @bdev: the TTM BO device 177 + * 178 + * Returns: 179 + * The containing instance of &struct drm_vram_mm 180 + */ 181 + static inline struct drm_vram_mm *drm_vram_mm_of_bdev( 182 + struct ttm_bo_device *bdev) 183 + { 184 + return container_of(bdev, struct drm_vram_mm, bdev); 185 + } 186 + 187 + int drm_vram_mm_debugfs_init(struct drm_minor *minor); 188 + int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev, 189 + uint64_t vram_base, size_t vram_size, 190 + const struct drm_vram_mm_funcs *funcs); 191 + void drm_vram_mm_cleanup(struct drm_vram_mm *vmm); 192 + 193 + int drm_vram_mm_mmap(struct file *filp, struct vm_area_struct *vma, 194 + struct drm_vram_mm *vmm); 195 + 196 + /* 197 + * Helpers for integration with struct drm_device 198 + */ 199 + 200 + struct drm_vram_mm *drm_vram_helper_alloc_mm( 201 + struct drm_device *dev, uint64_t vram_base, size_t vram_size, 202 + const struct drm_vram_mm_funcs *funcs); 203 + void drm_vram_helper_release_mm(struct drm_device *dev); 204 + 205 + /* 206 + * Helpers for &struct file_operations 207 + */ 208 + 209 + int drm_vram_mm_file_operations_mmap( 210 + struct file *filp, struct vm_area_struct *vma); 211 + 212 + /** 213 + * define DRM_VRAM_MM_FILE_OPERATIONS - default callback functions for \ 214 + &struct file_operations 215 + * 216 + * Drivers that use VRAM MM can use this macro to initialize 217 + * &struct file_operations with default functions. 218 + */ 219 + #define DRM_VRAM_MM_FILE_OPERATIONS \ 220 + .llseek = no_llseek, \ 221 + .read = drm_read, \ 222 + .poll = drm_poll, \ 223 + .unlocked_ioctl = drm_ioctl, \ 224 + .compat_ioctl = drm_compat_ioctl, \ 225 + .mmap = drm_vram_mm_file_operations_mmap, \ 226 + .open = drm_open, \ 227 + .release = drm_release \ 228 + 151 229 152 230 #endif
-77
include/drm/drm_vram_mm_helper.h
··· 29 29 struct ttm_mem_reg *new_mem); 30 30 }; 31 31 32 - /** 33 - * struct drm_vram_mm - An instance of VRAM MM 34 - * @vram_base: Base address of the managed video memory 35 - * @vram_size: Size of the managed video memory in bytes 36 - * @bdev: The TTM BO device. 37 - * @funcs: TTM BO functions 38 - * 39 - * The fields &struct drm_vram_mm.vram_base and 40 - * &struct drm_vram_mm.vrm_size are managed by VRAM MM, but are 41 - * available for public read access. Use the field 42 - * &struct drm_vram_mm.bdev to access the TTM BO device. 43 - */ 44 - struct drm_vram_mm { 45 - uint64_t vram_base; 46 - size_t vram_size; 47 - 48 - struct ttm_bo_device bdev; 49 - 50 - const struct drm_vram_mm_funcs *funcs; 51 - }; 52 - 53 - /** 54 - * drm_vram_mm_of_bdev() - \ 55 - Returns the container of type &struct ttm_bo_device for field bdev. 56 - * @bdev: the TTM BO device 57 - * 58 - * Returns: 59 - * The containing instance of &struct drm_vram_mm 60 - */ 61 - static inline struct drm_vram_mm *drm_vram_mm_of_bdev( 62 - struct ttm_bo_device *bdev) 63 - { 64 - return container_of(bdev, struct drm_vram_mm, bdev); 65 - } 66 - 67 - int drm_vram_mm_debugfs_init(struct drm_minor *minor); 68 - int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev, 69 - uint64_t vram_base, size_t vram_size, 70 - const struct drm_vram_mm_funcs *funcs); 71 - void drm_vram_mm_cleanup(struct drm_vram_mm *vmm); 72 - 73 - int drm_vram_mm_mmap(struct file *filp, struct vm_area_struct *vma, 74 - struct drm_vram_mm *vmm); 75 - 76 - /* 77 - * Helpers for integration with struct drm_device 78 - */ 79 - 80 - struct drm_vram_mm *drm_vram_helper_alloc_mm( 81 - struct drm_device *dev, uint64_t vram_base, size_t vram_size, 82 - const struct drm_vram_mm_funcs *funcs); 83 - void drm_vram_helper_release_mm(struct drm_device *dev); 84 - 85 - /* 86 - * Helpers for &struct file_operations 87 - */ 88 - 89 - int drm_vram_mm_file_operations_mmap( 90 - struct file *filp, struct vm_area_struct *vma); 91 - 92 - /** 93 - * define DRM_VRAM_MM_FILE_OPERATIONS - default callback functions for \ 94 - &struct file_operations 95 - * 96 - * Drivers that use VRAM MM can use this macro to initialize 97 - * &struct file_operations with default functions. 98 - */ 99 - #define DRM_VRAM_MM_FILE_OPERATIONS \ 100 - .llseek = no_llseek, \ 101 - .read = drm_read, \ 102 - .poll = drm_poll, \ 103 - .unlocked_ioctl = drm_ioctl, \ 104 - .compat_ioctl = drm_compat_ioctl, \ 105 - .mmap = drm_vram_mm_file_operations_mmap, \ 106 - .open = drm_open, \ 107 - .release = drm_release \ 108 - 109 32 #endif