1 /*- 2 *Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 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 "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: 12 * 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. 16 * 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. 24 * 25 * Authors: 26 * Rickard E. (Rik) Faith <faith@valinux.com> 27 * Gareth Hughes <gareth@valinux.com> 28 * 29 */ 30 31 /** @file drm_memory.c 32 * Wrappers for MTRR management support. 33 */ 34 35 #include <sys/types.h> 36 #include <lib/libkern/libkern.h> 37 #include <sys/memrange.h> 38 39 #if !defined(__amd64__) && !defined(__i386__) 40 #define DRM_NO_MTRR 1 41 #endif 42 43 int 44 drm_mtrr_add(unsigned long offset, size_t size, int flags) 45 { 46 #ifndef DRM_NO_MTRR 47 int act; 48 struct mem_range_desc mrdesc; 49 50 mrdesc.mr_base = offset; 51 mrdesc.mr_len = size; 52 mrdesc.mr_flags = flags; 53 act = MEMRANGE_SET_UPDATE; 54 strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner)); 55 return mem_range_attr_set(&mrdesc, &act); 56 #else 57 return 0; 58 #endif 59 } 60 61 int 62 drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags) 63 { 64 #ifndef DRM_NO_MTRR 65 int act; 66 struct mem_range_desc mrdesc; 67 68 mrdesc.mr_base = offset; 69 mrdesc.mr_len = size; 70 mrdesc.mr_flags = flags; 71 act = MEMRANGE_SET_REMOVE; 72 strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner)); 73 return mem_range_attr_set(&mrdesc, &act); 74 #else 75 return 0; 76 #endif 77 } 78