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.
| 1/** 2 * \file drm_memory.c 3 * Memory management wrappers for DRM
|
6 *
| 4 *
|
7 * Portions of this software were developed by Konstantin Belousov 8 * under sponsorship from the FreeBSD Foundation.
| 5 * \author Rickard E. (Rik) Faith <faith@valinux.com> 6 * \author Gareth Hughes <gareth@valinux.com> 7 */ 8 9/* 10 * Created: Thu Feb 4 14:00:34 1999 by faith@valinux.com
|
9 *
| 11 *
|
| 12 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 14 * All Rights Reserved. 15 *
|
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.
| 16 * Permission is hereby granted, free of charge, to any person obtaining a 17 * copy of this software and associated documentation files (the "Software"), 18 * to deal in the Software without restriction, including without limitation 19 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 20 * and/or sell copies of the Software, and to permit persons to whom the 21 * Software is furnished to do so, subject to the following conditions: 22 * 23 * The above copyright notice and this permission notice (including the next 24 * paragraph) shall be included in all copies or substantial portions of the 25 * Software. 26 * 27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 31 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 32 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 33 * 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#include <sys/cdefs.h>
| 34 */ 35 36#include <sys/cdefs.h>
|
36__FBSDID("$FreeBSD: head/sys/dev/drm2/drm_memory.c 277487 2015-01-21 16:10:37Z kib $");
| 37__FBSDID("$FreeBSD: head/sys/dev/drm2/drm_memory.c 280183 2015-03-17 18:50:33Z dumbbell $");
|
37
| 38
|
38/** @file drm_memory.c 39 * Wrappers for kernel memory allocation routines, and MTRR management support. 40 * 41 * This file previously implemented a memory consumption tracking system using 42 * the "area" argument for various different types of allocations, but that 43 * has been stripped out for now. 44 */ 45
| |
46#include <dev/drm2/drmP.h> 47
| 39#include <dev/drm2/drmP.h> 40
|
48MALLOC_DEFINE(DRM_MEM_DMA, "drm_dma", "DRM DMA Data Structures"); 49MALLOC_DEFINE(DRM_MEM_SAREA, "drm_sarea", "DRM SAREA Data Structures"); 50MALLOC_DEFINE(DRM_MEM_DRIVER, "drm_driver", "DRM DRIVER Data Structures"); 51MALLOC_DEFINE(DRM_MEM_MAGIC, "drm_magic", "DRM MAGIC Data Structures"); 52MALLOC_DEFINE(DRM_MEM_IOCTLS, "drm_ioctls", "DRM IOCTL Data Structures"); 53MALLOC_DEFINE(DRM_MEM_MAPS, "drm_maps", "DRM MAP Data Structures"); 54MALLOC_DEFINE(DRM_MEM_BUFS, "drm_bufs", "DRM BUFFER Data Structures"); 55MALLOC_DEFINE(DRM_MEM_SEGS, "drm_segs", "DRM SEGMENTS Data Structures"); 56MALLOC_DEFINE(DRM_MEM_PAGES, "drm_pages", "DRM PAGES Data Structures"); 57MALLOC_DEFINE(DRM_MEM_FILES, "drm_files", "DRM FILE Data Structures"); 58MALLOC_DEFINE(DRM_MEM_QUEUES, "drm_queues", "DRM QUEUE Data Structures"); 59MALLOC_DEFINE(DRM_MEM_CMDS, "drm_cmds", "DRM COMMAND Data Structures"); 60MALLOC_DEFINE(DRM_MEM_MAPPINGS, "drm_mapping", "DRM MAPPING Data Structures"); 61MALLOC_DEFINE(DRM_MEM_BUFLISTS, "drm_buflists", "DRM BUFLISTS Data Structures"); 62MALLOC_DEFINE(DRM_MEM_AGPLISTS, "drm_agplists", "DRM AGPLISTS Data Structures"); 63MALLOC_DEFINE(DRM_MEM_CTXBITMAP, "drm_ctxbitmap", 64 "DRM CTXBITMAP Data Structures"); 65MALLOC_DEFINE(DRM_MEM_SGLISTS, "drm_sglists", "DRM SGLISTS Data Structures"); 66MALLOC_DEFINE(DRM_MEM_DRAWABLE, "drm_drawable", "DRM DRAWABLE Data Structures"); 67MALLOC_DEFINE(DRM_MEM_MM, "drm_sman", "DRM MEMORY MANAGER Data Structures"); 68MALLOC_DEFINE(DRM_MEM_HASHTAB, "drm_hashtab", "DRM HASHTABLE Data Structures"); 69MALLOC_DEFINE(DRM_MEM_KMS, "drm_kms", "DRM KMS Data Structures"); 70 71void drm_mem_init(void)
| 41#if __OS_HAS_AGP 42static void *agp_remap(unsigned long offset, unsigned long size, 43 struct drm_device * dev)
|
72{
| 44{
|
| 45 /* 46 * FIXME Linux<->FreeBSD: Not implemented. This is never called 47 * on FreeBSD anyway, because drm_agp_mem->cant_use_aperture is 48 * set to 0. 49 */ 50 return NULL;
|
73} 74
| 51} 52
|
75void drm_mem_uninit(void) 76{ 77}
| 53#define vunmap(handle)
|
78
| 54
|
79void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map)
| 55/** Wrapper around agp_free_memory() */ 56void drm_free_agp(DRM_AGP_MEM * handle, int pages)
|
80{
| 57{
|
81 return pmap_mapdev_attr(map->offset, map->size, VM_MEMATTR_WRITE_COMBINING); 82}
| 58 device_t agpdev;
|
83
| 59
|
84void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map) 85{ 86 return pmap_mapdev(map->offset, map->size);
| 60 agpdev = agp_find_device(); 61 if (!agpdev || !handle) 62 return; 63 64 agp_free_memory(agpdev, handle);
|
87}
| 65}
|
| 66EXPORT_SYMBOL(drm_free_agp);
|
88
| 67
|
89void drm_ioremapfree(drm_local_map_t *map)
| 68/** Wrapper around agp_bind_memory() */ 69int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
|
90{
| 70{
|
91 pmap_unmapdev((vm_offset_t) map->virtual, map->size);
| 71 device_t agpdev; 72 73 agpdev = agp_find_device(); 74 if (!agpdev || !handle) 75 return -EINVAL; 76 77 return -agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
|
92} 93
| 78} 79
|
94int 95drm_mtrr_add(unsigned long offset, size_t size, int flags)
| 80/** Wrapper around agp_unbind_memory() */ 81int drm_unbind_agp(DRM_AGP_MEM * handle)
|
96{
| 82{
|
97 int act; 98 struct mem_range_desc mrdesc;
| 83 device_t agpdev;
|
99
| 84
|
100 mrdesc.mr_base = offset; 101 mrdesc.mr_len = size; 102 mrdesc.mr_flags = flags; 103 act = MEMRANGE_SET_UPDATE; 104 strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner)); 105 return mem_range_attr_set(&mrdesc, &act);
| 85 agpdev = agp_find_device(); 86 if (!agpdev || !handle) 87 return -EINVAL; 88 89 return -agp_unbind_memory(agpdev, handle);
|
106}
| 90}
|
| 91EXPORT_SYMBOL(drm_unbind_agp);
|
107
| 92
|
108int 109drm_mtrr_del(int __unused handle, unsigned long offset, size_t size, int flags)
| 93#else /* __OS_HAS_AGP */ 94static inline void *agp_remap(unsigned long offset, unsigned long size, 95 struct drm_device * dev)
|
110{
| 96{
|
111 int act; 112 struct mem_range_desc mrdesc; 113 114 mrdesc.mr_base = offset; 115 mrdesc.mr_len = size; 116 mrdesc.mr_flags = flags; 117 act = MEMRANGE_SET_REMOVE; 118 strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner)); 119 return mem_range_attr_set(&mrdesc, &act);
| 97 return NULL;
|
120} 121
| 98} 99
|
122void 123drm_clflush_pages(vm_page_t *pages, unsigned long num_pages)
| 100#endif /* agp */ 101 102void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
|
124{
| 103{
|
| 104 if (drm_core_has_AGP(dev) && 105 dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP) 106 map->handle = agp_remap(map->offset, map->size, dev); 107 else 108 map->handle = pmap_mapdev(map->offset, map->size); 109} 110EXPORT_SYMBOL(drm_core_ioremap);
|
125
| 111
|
126 pmap_invalidate_cache_pages(pages, num_pages);
| 112void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev) 113{ 114 if (drm_core_has_AGP(dev) && 115 dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP) 116 map->handle = agp_remap(map->offset, map->size, dev); 117 else 118 map->handle = pmap_mapdev_attr(map->offset, map->size, 119 VM_MEMATTR_WRITE_COMBINING);
|
127}
| 120}
|
| 121EXPORT_SYMBOL(drm_core_ioremap_wc);
|
128
| 122
|
129void 130drm_clflush_virt_range(char *addr, unsigned long length)
| 123void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
|
131{
| 124{
|
| 125 if (!map->handle || !map->size) 126 return;
|
132
| 127
|
133 pmap_invalidate_cache_range((vm_offset_t)addr, 134 (vm_offset_t)addr + length, TRUE);
| 128 if (drm_core_has_AGP(dev) && 129 dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP) 130 vunmap(map->handle); 131 else 132 pmap_unmapdev((vm_offset_t)map->handle, map->size);
|
135}
| 133}
|
| 134EXPORT_SYMBOL(drm_core_ioremapfree);
|
| |