Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
0002 /**************************************************************************
0003  *
0004  * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
0005  * All Rights Reserved.
0006  *
0007  * Permission is hereby granted, free of charge, to any person obtaining a
0008  * copy of this software and associated documentation files (the
0009  * "Software"), to deal in the Software without restriction, including
0010  * without limitation the rights to use, copy, modify, merge, publish,
0011  * distribute, sub license, and/or sell copies of the Software, and to
0012  * permit persons to whom the Software is furnished to do so, subject to
0013  * the following conditions:
0014  *
0015  * The above copyright notice and this permission notice (including the
0016  * next paragraph) shall be included in all copies or substantial portions
0017  * of the Software.
0018  *
0019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0020  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0021  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
0022  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
0023  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
0024  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
0025  * USE OR OTHER DEALINGS IN THE SOFTWARE.
0026  *
0027  **************************************************************************/
0028 /*
0029  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
0030  *      Jerome Glisse
0031  */
0032 #include <linux/module.h>
0033 #include <linux/device.h>
0034 #include <linux/pgtable.h>
0035 #include <linux/sched.h>
0036 #include <linux/debugfs.h>
0037 #include <drm/drm_sysfs.h>
0038 #include <drm/ttm/ttm_caching.h>
0039 
0040 #include "ttm_module.h"
0041 
0042 /**
0043  * DOC: TTM
0044  *
0045  * TTM is a memory manager for accelerator devices with dedicated memory.
0046  *
0047  * The basic idea is that resources are grouped together in buffer objects of
0048  * certain size and TTM handles lifetime, movement and CPU mappings of those
0049  * objects.
0050  *
0051  * TODO: Add more design background and information here.
0052  */
0053 
0054 /**
0055  * ttm_prot_from_caching - Modify the page protection according to the
0056  * ttm cacing mode
0057  * @caching: The ttm caching mode
0058  * @tmp: The original page protection
0059  *
0060  * Return: The modified page protection
0061  */
0062 pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
0063 {
0064     /* Cached mappings need no adjustment */
0065     if (caching == ttm_cached)
0066         return tmp;
0067 
0068 #if defined(__i386__) || defined(__x86_64__)
0069     if (caching == ttm_write_combined)
0070         tmp = pgprot_writecombine(tmp);
0071 #ifndef CONFIG_UML
0072     else if (boot_cpu_data.x86 > 3)
0073         tmp = pgprot_noncached(tmp);
0074 #endif /* CONFIG_UML */
0075 #endif /* __i386__ || __x86_64__ */
0076 #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
0077     defined(__powerpc__) || defined(__mips__) || defined(__loongarch__)
0078     if (caching == ttm_write_combined)
0079         tmp = pgprot_writecombine(tmp);
0080     else
0081         tmp = pgprot_noncached(tmp);
0082 #endif
0083 #if defined(__sparc__)
0084     tmp = pgprot_noncached(tmp);
0085 #endif
0086     return tmp;
0087 }
0088 
0089 MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse");
0090 MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)");
0091 MODULE_LICENSE("GPL and additional rights");