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
7 * Portions of this software were developed by Konstantin Belousov
8 * under sponsorship from the FreeBSD Foundation.
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:
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
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.
30 * Rickard E. (Rik) Faith <faith@valinux.com>
31 * Gareth Hughes <gareth@valinux.com>
35 /** @file drm_memory.c
36 * Wrappers for kernel memory allocation routines, and MTRR management support.
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.
44 #include "drm_legacy.h"
50 # define PAGE_AGP __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
52 # define PAGE_AGP PAGE_KERNEL
56 MALLOC_DEFINE(M_DRM, "m_drm", "DRM memory allocations");
58 void drm_mem_init(void)
62 void drm_mem_uninit(void)
66 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map)
68 return pmap_mapdev_attr(map->offset, map->size, VM_MEMATTR_WRITE_COMBINING);
71 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map)
73 return pmap_mapdev(map->offset, map->size);
76 void drm_ioremapfree(drm_local_map_t *map)
78 pmap_unmapdev((vm_offset_t) map->handle, map->size);
82 drm_mtrr_add(unsigned long offset, size_t size, int flags)
85 struct mem_range_desc mrdesc;
87 mrdesc.mr_base = offset;
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);
96 drm_mtrr_del(int __unused handle, unsigned long offset, size_t size, int flags)
99 struct mem_range_desc mrdesc;
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);
110 drm_clflush_pages(vm_page_t *pages, unsigned long num_pages)
113 pmap_invalidate_cache_pages(pages, num_pages);