11297bf2eSDirk Hohndel /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 2ba4e7d97SThomas Hellstrom /************************************************************************** 3ba4e7d97SThomas Hellstrom * 4ba4e7d97SThomas Hellstrom * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA 5ba4e7d97SThomas Hellstrom * All Rights Reserved. 6ba4e7d97SThomas Hellstrom * 7ba4e7d97SThomas Hellstrom * Permission is hereby granted, free of charge, to any person obtaining a 8ba4e7d97SThomas Hellstrom * copy of this software and associated documentation files (the 9ba4e7d97SThomas Hellstrom * "Software"), to deal in the Software without restriction, including 10ba4e7d97SThomas Hellstrom * without limitation the rights to use, copy, modify, merge, publish, 11ba4e7d97SThomas Hellstrom * distribute, sub license, and/or sell copies of the Software, and to 12ba4e7d97SThomas Hellstrom * permit persons to whom the Software is furnished to do so, subject to 13ba4e7d97SThomas Hellstrom * the following conditions: 14ba4e7d97SThomas Hellstrom * 15ba4e7d97SThomas Hellstrom * The above copyright notice and this permission notice (including the 16ba4e7d97SThomas Hellstrom * next paragraph) shall be included in all copies or substantial portions 17ba4e7d97SThomas Hellstrom * of the Software. 18ba4e7d97SThomas Hellstrom * 19ba4e7d97SThomas Hellstrom * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20ba4e7d97SThomas Hellstrom * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21ba4e7d97SThomas Hellstrom * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 22ba4e7d97SThomas Hellstrom * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 23ba4e7d97SThomas Hellstrom * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 24ba4e7d97SThomas Hellstrom * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 25ba4e7d97SThomas Hellstrom * USE OR OTHER DEALINGS IN THE SOFTWARE. 26ba4e7d97SThomas Hellstrom * 27ba4e7d97SThomas Hellstrom **************************************************************************/ 28ba4e7d97SThomas Hellstrom /* 29ba4e7d97SThomas Hellstrom * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 30ba4e7d97SThomas Hellstrom * Jerome Glisse 31ba4e7d97SThomas Hellstrom */ 32ba4e7d97SThomas Hellstrom #include <linux/module.h> 33e9840be8SThomas Hellstrom #include <linux/device.h> 34*3bf3710eSThomas Hellström #include <linux/pgtable.h> 35e9840be8SThomas Hellstrom #include <linux/sched.h> 363763d635SChristian König #include <linux/debugfs.h> 37760285e7SDavid Howells #include <drm/drm_sysfs.h> 38*3bf3710eSThomas Hellström #include <drm/ttm/ttm_caching.h> 39e9840be8SThomas Hellstrom 405cf82904SChristian König #include "ttm_module.h" 415cf82904SChristian König 42*3bf3710eSThomas Hellström /** 43*3bf3710eSThomas Hellström * ttm_prot_from_caching - Modify the page protection according to the 44*3bf3710eSThomas Hellström * ttm cacing mode 45*3bf3710eSThomas Hellström * @caching: The ttm caching mode 46*3bf3710eSThomas Hellström * @tmp: The original page protection 47*3bf3710eSThomas Hellström * 48*3bf3710eSThomas Hellström * Return: The modified page protection 49*3bf3710eSThomas Hellström */ 50*3bf3710eSThomas Hellström pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp) 51*3bf3710eSThomas Hellström { 52*3bf3710eSThomas Hellström /* Cached mappings need no adjustment */ 53*3bf3710eSThomas Hellström if (caching == ttm_cached) 54*3bf3710eSThomas Hellström return tmp; 55*3bf3710eSThomas Hellström 56*3bf3710eSThomas Hellström #if defined(__i386__) || defined(__x86_64__) 57*3bf3710eSThomas Hellström if (caching == ttm_write_combined) 58*3bf3710eSThomas Hellström tmp = pgprot_writecombine(tmp); 59*3bf3710eSThomas Hellström else if (boot_cpu_data.x86 > 3) 60*3bf3710eSThomas Hellström tmp = pgprot_noncached(tmp); 61*3bf3710eSThomas Hellström #endif 62*3bf3710eSThomas Hellström #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \ 63*3bf3710eSThomas Hellström defined(__powerpc__) || defined(__mips__) 64*3bf3710eSThomas Hellström if (caching == ttm_write_combined) 65*3bf3710eSThomas Hellström tmp = pgprot_writecombine(tmp); 66*3bf3710eSThomas Hellström else 67*3bf3710eSThomas Hellström tmp = pgprot_noncached(tmp); 68*3bf3710eSThomas Hellström #endif 69*3bf3710eSThomas Hellström #if defined(__sparc__) 70*3bf3710eSThomas Hellström tmp = pgprot_noncached(tmp); 71*3bf3710eSThomas Hellström #endif 72*3bf3710eSThomas Hellström return tmp; 73*3bf3710eSThomas Hellström } 74*3bf3710eSThomas Hellström 753763d635SChristian König struct dentry *ttm_debugfs_root; 76e9840be8SThomas Hellstrom 77ba4e7d97SThomas Hellstrom static int __init ttm_init(void) 78ba4e7d97SThomas Hellstrom { 793763d635SChristian König ttm_debugfs_root = debugfs_create_dir("ttm", NULL); 80ba4e7d97SThomas Hellstrom return 0; 81ba4e7d97SThomas Hellstrom } 82ba4e7d97SThomas Hellstrom 83ba4e7d97SThomas Hellstrom static void __exit ttm_exit(void) 84ba4e7d97SThomas Hellstrom { 853763d635SChristian König debugfs_remove(ttm_debugfs_root); 86ba4e7d97SThomas Hellstrom } 87ba4e7d97SThomas Hellstrom 88ba4e7d97SThomas Hellstrom module_init(ttm_init); 89ba4e7d97SThomas Hellstrom module_exit(ttm_exit); 90ba4e7d97SThomas Hellstrom 91ba4e7d97SThomas Hellstrom MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse"); 92ba4e7d97SThomas Hellstrom MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)"); 93ba4e7d97SThomas Hellstrom MODULE_LICENSE("GPL and additional rights"); 94