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