8e452934e92005109726a6d1e3cba29b9311e569
[dragonfly.git] / sys / dev / drm / drm_memory.c
1 /*-
2  *Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4  * Copyright (c) 2011 The FreeBSD Foundation
5  * All rights reserved.
6  *
7  * Portions of this software were developed by Konstantin Belousov
8  * under sponsorship from the FreeBSD Foundation.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice (including the next
18  * paragraph) shall be included in all copies or substantial portions of the
19  * Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  *
29  * Authors:
30  *    Rickard E. (Rik) Faith <faith@valinux.com>
31  *    Gareth Hughes <gareth@valinux.com>
32  *
33  */
34
35 /** @file drm_memory.c
36  * Wrappers for kernel memory allocation routines, and MTRR management support.
37  *
38  * This file previously implemented a memory consumption tracking system using
39  * the "area" argument for various different types of allocations, but that
40  * has been stripped out for now.
41  */
42
43 #include <drm/drmP.h>
44
45 MALLOC_DEFINE(M_DRM, "m_drm", "DRM memory allocations");
46
47 void drm_mem_init(void)
48 {
49 }
50
51 void drm_mem_uninit(void)
52 {
53 }
54
55 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map)
56 {
57         return pmap_mapdev_attr(map->offset, map->size, VM_MEMATTR_WRITE_COMBINING);
58 }
59
60 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map)
61 {
62         return pmap_mapdev(map->offset, map->size);
63 }
64
65 void drm_ioremapfree(drm_local_map_t *map)
66 {
67         pmap_unmapdev((vm_offset_t) map->handle, map->size);
68 }
69
70 int
71 drm_mtrr_add(unsigned long offset, size_t size, int flags)
72 {
73         int act;
74         struct mem_range_desc mrdesc;
75
76         mrdesc.mr_base = offset;
77         mrdesc.mr_len = size;
78         mrdesc.mr_flags = flags;
79         act = MEMRANGE_SET_UPDATE;
80         strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
81         return mem_range_attr_set(&mrdesc, &act);
82 }
83
84 int
85 drm_mtrr_del(int __unused handle, unsigned long offset, size_t size, int flags)
86 {
87         int act;
88         struct mem_range_desc mrdesc;
89
90         mrdesc.mr_base = offset;
91         mrdesc.mr_len = size;
92         mrdesc.mr_flags = flags;
93         act = MEMRANGE_SET_REMOVE;
94         strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
95         return mem_range_attr_set(&mrdesc, &act);
96 }
97
98 void
99 drm_clflush_pages(vm_page_t *pages, unsigned long num_pages)
100 {
101
102         pmap_invalidate_cache_pages(pages, num_pages);
103 }