Linux Audio

Check our new training course

Loading...
v4.6
 
  1/**************************************************************************
  2 *
  3 * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
  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: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
 29 * 	    Jerome Glisse
 30 */
 31#include <linux/module.h>
 32#include <linux/device.h>
 
 33#include <linux/sched.h>
 34#include <drm/ttm/ttm_module.h>
 35#include <drm/drm_sysfs.h>
 
 36
 37static DECLARE_WAIT_QUEUE_HEAD(exit_q);
 38static atomic_t device_released;
 39
 40static struct device_type ttm_drm_class_type = {
 41	.name = "ttm",
 42	/**
 43	 * Add pm ops here.
 44	 */
 45};
 46
 47static void ttm_drm_class_device_release(struct device *dev)
 48{
 49	atomic_set(&device_released, 1);
 50	wake_up_all(&exit_q);
 51}
 52
 53static struct device ttm_drm_class_device = {
 54	.type = &ttm_drm_class_type,
 55	.release = &ttm_drm_class_device_release
 56};
 57
 58struct kobject *ttm_get_kobj(void)
 59{
 60	struct kobject *kobj = &ttm_drm_class_device.kobj;
 61	BUG_ON(kobj == NULL);
 62	return kobj;
 63}
 64
 65static int __init ttm_init(void)
 66{
 67	int ret;
 68
 69	ret = dev_set_name(&ttm_drm_class_device, "ttm");
 70	if (unlikely(ret != 0))
 71		return ret;
 72
 73	atomic_set(&device_released, 0);
 74	ret = drm_class_device_register(&ttm_drm_class_device);
 75	if (unlikely(ret != 0))
 76		goto out_no_dev_reg;
 77
 78	return 0;
 79out_no_dev_reg:
 80	atomic_set(&device_released, 1);
 81	wake_up_all(&exit_q);
 82	return ret;
 83}
 84
 85static void __exit ttm_exit(void)
 
 
 
 
 
 
 
 
 86{
 87	drm_class_device_unregister(&ttm_drm_class_device);
 88
 89	/**
 90	 * Refuse to unload until the TTM device is released.
 91	 * Not sure this is 100% needed.
 92	 */
 93
 94	wait_event(exit_q, atomic_read(&device_released) == 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 95}
 96
 97module_init(ttm_init);
 98module_exit(ttm_exit);
 99
100MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse");
101MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)");
102MODULE_LICENSE("GPL and additional rights");
v6.9.4
 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 * DOC: TTM
44 *
45 * TTM is a memory manager for accelerator devices with dedicated memory.
46 *
47 * The basic idea is that resources are grouped together in buffer objects of
48 * certain size and TTM handles lifetime, movement and CPU mappings of those
49 * objects.
50 *
51 * TODO: Add more design background and information here.
52 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
54/**
55 * ttm_prot_from_caching - Modify the page protection according to the
56 * ttm cacing mode
57 * @caching: The ttm caching mode
58 * @tmp: The original page protection
59 *
60 * Return: The modified page protection
61 */
62pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
63{
64	/* Cached mappings need no adjustment */
65	if (caching == ttm_cached)
66		return tmp;
67
68#if defined(__i386__) || defined(__x86_64__)
69	if (caching == ttm_write_combined)
70		tmp = pgprot_writecombine(tmp);
71#ifndef CONFIG_UML
72	else if (boot_cpu_data.x86 > 3)
73		tmp = pgprot_noncached(tmp);
74#endif /* CONFIG_UML */
75#endif /* __i386__ || __x86_64__ */
76#if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
77	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__)
78	if (caching == ttm_write_combined)
79		tmp = pgprot_writecombine(tmp);
80	else
81		tmp = pgprot_noncached(tmp);
82#endif
83#if defined(__sparc__)
84	tmp = pgprot_noncached(tmp);
85#endif
86	return tmp;
87}
 
 
 
88
89MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse");
90MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)");
91MODULE_LICENSE("GPL and additional rights");