DRM from FreeBSD current, tested for r600
[dragonfly.git] / sys / dev / drm / drm_memory.c
blob41a641c7d990e5e38cdd2820a478a4e1be966fb9
1 /*-
2 *Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4 * All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
25 * Authors:
26 * Rickard E. (Rik) Faith <faith@valinux.com>
27 * Gareth Hughes <gareth@valinux.com>
31 /** @file drm_memory.c
32 * Wrappers for kernel memory allocation routines, and MTRR management support.
34 * This file previously implemented a memory consumption tracking system using
35 * the "area" argument for various different types of allocations, but that
36 * has been stripped out for now.
39 #include "dev/drm/drmP.h"
41 MALLOC_DEFINE(DRM_MEM_DMA, "drm_dma", "DRM DMA Data Structures");
42 MALLOC_DEFINE(DRM_MEM_SAREA, "drm_sarea", "DRM SAREA Data Structures");
43 MALLOC_DEFINE(DRM_MEM_DRIVER, "drm_driver", "DRM DRIVER Data Structures");
44 MALLOC_DEFINE(DRM_MEM_MAGIC, "drm_magic", "DRM MAGIC Data Structures");
45 MALLOC_DEFINE(DRM_MEM_IOCTLS, "drm_ioctls", "DRM IOCTL Data Structures");
46 MALLOC_DEFINE(DRM_MEM_MAPS, "drm_maps", "DRM MAP Data Structures");
47 MALLOC_DEFINE(DRM_MEM_BUFS, "drm_bufs", "DRM BUFFER Data Structures");
48 MALLOC_DEFINE(DRM_MEM_SEGS, "drm_segs", "DRM SEGMENTS Data Structures");
49 MALLOC_DEFINE(DRM_MEM_PAGES, "drm_pages", "DRM PAGES Data Structures");
50 MALLOC_DEFINE(DRM_MEM_FILES, "drm_files", "DRM FILE Data Structures");
51 MALLOC_DEFINE(DRM_MEM_QUEUES, "drm_queues", "DRM QUEUE Data Structures");
52 MALLOC_DEFINE(DRM_MEM_CMDS, "drm_cmds", "DRM COMMAND Data Structures");
53 MALLOC_DEFINE(DRM_MEM_MAPPINGS, "drm_mapping", "DRM MAPPING Data Structures");
54 MALLOC_DEFINE(DRM_MEM_BUFLISTS, "drm_buflists", "DRM BUFLISTS Data Structures");
55 MALLOC_DEFINE(DRM_MEM_AGPLISTS, "drm_agplists", "DRM AGPLISTS Data Structures");
56 MALLOC_DEFINE(DRM_MEM_CTXBITMAP, "drm_ctxbitmap",
57 "DRM CTXBITMAP Data Structures");
58 MALLOC_DEFINE(DRM_MEM_SGLISTS, "drm_sglists", "DRM SGLISTS Data Structures");
59 MALLOC_DEFINE(DRM_MEM_DRAWABLE, "drm_drawable", "DRM DRAWABLE Data Structures");
60 MALLOC_DEFINE(DRM_MEM_MM, "drm_sman", "DRM MEMORY MANAGER Data Structures");
61 MALLOC_DEFINE(DRM_MEM_HASHTAB, "drm_hashtab", "DRM HASHTABLE Data Structures");
63 void drm_mem_init(void)
67 void drm_mem_uninit(void)
71 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map)
73 #if 0 /* XXX */
74 return pmap_mapdev_attr(map->offset, map->size, PAT_WRITE_COMBINING);
75 #endif
76 return pmap_mapdev(map->offset, map->size);
79 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map)
81 return pmap_mapdev(map->offset, map->size);
84 void drm_ioremapfree(drm_local_map_t *map)
86 pmap_unmapdev((vm_offset_t) map->handle, map->size);
89 int
90 drm_mtrr_add(unsigned long offset, size_t size, int flags)
92 int act;
93 struct mem_range_desc mrdesc;
95 mrdesc.mr_base = offset;
96 mrdesc.mr_len = size;
97 mrdesc.mr_flags = flags;
98 act = MEMRANGE_SET_UPDATE;
99 strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
100 return mem_range_attr_set(&mrdesc, &act);
104 drm_mtrr_del(int __unused handle, unsigned long offset, size_t size, int flags)
106 int act;
107 struct mem_range_desc mrdesc;
109 mrdesc.mr_base = offset;
110 mrdesc.mr_len = size;
111 mrdesc.mr_flags = flags;
112 act = MEMRANGE_SET_REMOVE;
113 strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
114 return mem_range_attr_set(&mrdesc, &act);