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 #include "drm_legacy.h" 45 46 #ifdef HAVE_PAGE_AGP 47 # include <asm/agp.h> 48 #else 49 # ifdef __powerpc__ 50 # define PAGE_AGP __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE) 51 # else 52 # define PAGE_AGP PAGE_KERNEL 53 # endif 54 #endif 55 56 MALLOC_DEFINE(M_DRM, "m_drm", "DRM memory allocations"); 57 58 void drm_mem_init(void) 59 { 60 } 61 62 void drm_mem_uninit(void) 63 { 64 } 65 66 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map) 67 { 68 return pmap_mapdev_attr(map->offset, map->size, VM_MEMATTR_WRITE_COMBINING); 69 } 70 71 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map) 72 { 73 return pmap_mapdev(map->offset, map->size); 74 } 75 76 void drm_ioremapfree(drm_local_map_t *map) 77 { 78 pmap_unmapdev((vm_offset_t) map->handle, map->size); 79 } 80 81 int 82 drm_mtrr_add(unsigned long offset, size_t size, int flags) 83 { 84 int act; 85 struct mem_range_desc mrdesc; 86 87 mrdesc.mr_base = offset; 88 mrdesc.mr_len = size; 89 mrdesc.mr_flags = flags; 90 act = MEMRANGE_SET_UPDATE; 91 strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner)); 92 return mem_range_attr_set(&mrdesc, &act); 93 } 94 95 int 96 drm_mtrr_del(int __unused handle, unsigned long offset, size_t size, int flags) 97 { 98 int act; 99 struct mem_range_desc mrdesc; 100 101 mrdesc.mr_base = offset; 102 mrdesc.mr_len = size; 103 mrdesc.mr_flags = flags; 104 act = MEMRANGE_SET_REMOVE; 105 strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner)); 106 return mem_range_attr_set(&mrdesc, &act); 107 } 108 109 void 110 drm_clflush_pages(vm_page_t *pages, unsigned long num_pages) 111 { 112 113 pmap_invalidate_cache_pages(pages, num_pages); 114 } 115