The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/drm/drm_memory.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* drm_memory.h -- Memory management wrappers for DRM -*- linux-c -*-
    2  * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
    3  */
    4 /*-
    5  *Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
    6  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
    7  * All Rights Reserved.
    8  *
    9  * Permission is hereby granted, free of charge, to any person obtaining a
   10  * copy of this software and associated documentation files (the "Software"),
   11  * to deal in the Software without restriction, including without limitation
   12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   13  * and/or sell copies of the Software, and to permit persons to whom the
   14  * Software is furnished to do so, subject to the following conditions:
   15  *
   16  * The above copyright notice and this permission notice (including the next
   17  * paragraph) shall be included in all copies or substantial portions of the
   18  * Software.
   19  *
   20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   23  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
   24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
   25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
   26  * OTHER DEALINGS IN THE SOFTWARE.
   27  *
   28  * Authors:
   29  *    Rickard E. (Rik) Faith <faith@valinux.com>
   30  *    Gareth Hughes <gareth@valinux.com>
   31  *
   32  */
   33 
   34 #include <sys/cdefs.h>
   35 __FBSDID("$FreeBSD: releng/6.4/sys/dev/drm/drm_memory.c 153401 2005-12-14 00:52:59Z anholt $");
   36 
   37 #include "dev/drm/drmP.h"
   38 
   39 MALLOC_DEFINE(M_DRM, "drm", "DRM Data Structures");
   40 
   41 void drm_mem_init(void)
   42 {
   43 #if defined(__NetBSD__) || defined(__OpenBSD__)
   44         malloc_type_attach(M_DRM);
   45 #endif
   46 }
   47 
   48 void drm_mem_uninit(void)
   49 {
   50 }
   51 
   52 void *drm_alloc(size_t size, int area)
   53 {
   54         return malloc(size, M_DRM, M_NOWAIT);
   55 }
   56 
   57 void *drm_calloc(size_t nmemb, size_t size, int area)
   58 {
   59         return malloc(size * nmemb, M_DRM, M_NOWAIT | M_ZERO);
   60 }
   61 
   62 void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
   63 {
   64         void *pt;
   65 
   66         pt = malloc(size, M_DRM, M_NOWAIT);
   67         if (pt == NULL)
   68                 return NULL;
   69         if (oldpt && oldsize) {
   70                 memcpy(pt, oldpt, oldsize);
   71                 free(oldpt, M_DRM);
   72         }
   73         return pt;
   74 }
   75 
   76 void drm_free(void *pt, size_t size, int area)
   77 {
   78         free(pt, M_DRM);
   79 }
   80 
   81 void *drm_ioremap(drm_device_t *dev, drm_local_map_t *map)
   82 {
   83 #ifdef __FreeBSD__
   84         return pmap_mapdev(map->offset, map->size);
   85 #elif defined(__NetBSD__) || defined(__OpenBSD__)
   86         map->bst = dev->pa.pa_memt;
   87         if (bus_space_map(map->bst, map->offset, map->size, 
   88             BUS_SPACE_MAP_LINEAR, &map->bsh))
   89                 return NULL;
   90         return bus_space_vaddr(map->bst, map->bsh);
   91 #endif
   92 }
   93 
   94 void drm_ioremapfree(drm_local_map_t *map)
   95 {
   96 #ifdef __FreeBSD__
   97         pmap_unmapdev((vm_offset_t) map->handle, map->size);
   98 #elif defined(__NetBSD__) || defined(__OpenBSD__)
   99         bus_space_unmap(map->bst, map->bsh, map->size);
  100 #endif
  101 }
  102 
  103 #ifdef __FreeBSD__
  104 int
  105 drm_mtrr_add(unsigned long offset, size_t size, int flags)
  106 {
  107         int act;
  108         struct mem_range_desc mrdesc;
  109 
  110         mrdesc.mr_base = offset;
  111         mrdesc.mr_len = size;
  112         mrdesc.mr_flags = flags;
  113         act = MEMRANGE_SET_UPDATE;
  114         strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
  115         return mem_range_attr_set(&mrdesc, &act);
  116 }
  117 
  118 int
  119 drm_mtrr_del(int __unused handle, unsigned long offset, size_t size, int flags)
  120 {
  121         int act;
  122         struct mem_range_desc mrdesc;
  123 
  124         mrdesc.mr_base = offset;
  125         mrdesc.mr_len = size;
  126         mrdesc.mr_flags = flags;
  127         act = MEMRANGE_SET_REMOVE;
  128         strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
  129         return mem_range_attr_set(&mrdesc, &act);
  130 }
  131 #elif defined(__NetBSD__) || defined(__OpenBSD__)
  132 int
  133 drm_mtrr_add(unsigned long offset, size_t size, int flags)
  134 {
  135         struct mtrr mtrrmap;
  136         int one = 1;
  137 
  138         mtrrmap.base = offset;
  139         mtrrmap.len = size;
  140         mtrrmap.type = flags;
  141         mtrrmap.flags = MTRR_VALID;
  142         return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
  143 }
  144 
  145 int
  146 drm_mtrr_del(unsigned long offset, size_t size, int flags)
  147 {
  148         struct mtrr mtrrmap;
  149         int one = 1;
  150 
  151         mtrrmap.base = offset;
  152         mtrrmap.len = size;
  153         mtrrmap.type = flags;
  154         mtrrmap.flags = 0;
  155         return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
  156 }
  157 #endif

Cache object: 10d1d624d4c979f7dce22e752443ae9b


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.