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_agpsupport.h

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_agpsupport.h -- DRM support for AGP/GART backend -*- linux-c -*-
    2  * Created: Mon Dec 13 09:56:45 1999 by faith@precisioninsight.com */
    3 /*-
    4  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
    5  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
    6  * All Rights Reserved.
    7  *
    8  * Permission is hereby granted, free of charge, to any person obtaining a
    9  * copy of this software and associated documentation files (the "Software"),
   10  * to deal in the Software without restriction, including without limitation
   11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   12  * and/or sell copies of the Software, and to permit persons to whom the
   13  * Software is furnished to do so, subject to the following conditions:
   14  *
   15  * The above copyright notice and this permission notice (including the next
   16  * paragraph) shall be included in all copies or substantial portions of the
   17  * Software.
   18  *
   19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   22  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
   23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
   24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
   25  * OTHER DEALINGS IN THE SOFTWARE.
   26  *
   27  * Author:
   28  *    Rickard E. (Rik) Faith <faith@valinux.com>
   29  *    Gareth Hughes <gareth@valinux.com>
   30  *
   31  * $FreeBSD$
   32  */
   33 
   34 #include "dev/drm/drmP.h"
   35 
   36 int DRM(agp_info)(DRM_IOCTL_ARGS)
   37 {
   38         DRM_DEVICE;
   39         struct agp_info *kern;
   40         drm_agp_info_t   info;
   41 
   42         if (!dev->agp || !dev->agp->acquired)
   43                 return EINVAL;
   44 
   45         kern                   = &dev->agp->info;
   46         agp_get_info(dev->agp->agpdev, kern);
   47         info.agp_version_major = 1;
   48         info.agp_version_minor = 0;
   49         info.mode              = kern->ai_mode;
   50         info.aperture_base     = kern->ai_aperture_base;
   51         info.aperture_size     = kern->ai_aperture_size;
   52         info.memory_allowed    = kern->ai_memory_allowed;
   53         info.memory_used       = kern->ai_memory_used;
   54         info.id_vendor         = kern->ai_devid & 0xffff;
   55         info.id_device         = kern->ai_devid >> 16;
   56 
   57         *(drm_agp_info_t *) data = info;
   58         return 0;
   59 }
   60 
   61 int DRM(agp_acquire)(DRM_IOCTL_ARGS)
   62 {
   63         DRM_DEVICE;
   64         int          retcode;
   65 
   66         if (!dev->agp || dev->agp->acquired)
   67                 return EINVAL;
   68         retcode = agp_acquire(dev->agp->agpdev);
   69         if (retcode)
   70                 return retcode;
   71         dev->agp->acquired = 1;
   72         return 0;
   73 }
   74 
   75 int DRM(agp_release)(DRM_IOCTL_ARGS)
   76 {
   77         DRM_DEVICE;
   78 
   79         if (!dev->agp || !dev->agp->acquired)
   80                 return EINVAL;
   81         agp_release(dev->agp->agpdev);
   82         dev->agp->acquired = 0;
   83         return 0;
   84         
   85 }
   86 
   87 void DRM(agp_do_release)(void)
   88 {
   89         device_t agpdev;
   90 
   91         agpdev = DRM_AGP_FIND_DEVICE();
   92         if (agpdev)
   93                 agp_release(agpdev);
   94 }
   95 
   96 int DRM(agp_enable)(DRM_IOCTL_ARGS)
   97 {
   98         DRM_DEVICE;
   99         drm_agp_mode_t mode;
  100 
  101         if (!dev->agp || !dev->agp->acquired)
  102                 return EINVAL;
  103 
  104         mode = *(drm_agp_mode_t *) data;
  105         
  106         dev->agp->mode    = mode.mode;
  107         agp_enable(dev->agp->agpdev, mode.mode);
  108         dev->agp->base    = dev->agp->info.ai_aperture_base;
  109         dev->agp->enabled = 1;
  110         return 0;
  111 }
  112 
  113 int DRM(agp_alloc)(DRM_IOCTL_ARGS)
  114 {
  115         DRM_DEVICE;
  116         drm_agp_buffer_t request;
  117         drm_agp_mem_t    *entry;
  118         void             *handle;
  119         unsigned long    pages;
  120         u_int32_t        type;
  121         struct agp_memory_info info;
  122 
  123         if (!dev->agp || !dev->agp->acquired)
  124                 return EINVAL;
  125 
  126         request = *(drm_agp_buffer_t *) data;
  127 
  128         if (!(entry = DRM(alloc)(sizeof(*entry), DRM_MEM_AGPLISTS)))
  129                 return ENOMEM;
  130    
  131         bzero(entry, sizeof(*entry));
  132 
  133         pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
  134         type = (u_int32_t) request.type;
  135 
  136         if (!(handle = DRM(alloc_agp)(pages, type))) {
  137                 DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
  138                 return ENOMEM;
  139         }
  140         
  141         entry->handle    = handle;
  142         entry->bound     = 0;
  143         entry->pages     = pages;
  144         entry->prev      = NULL;
  145         entry->next      = dev->agp->memory;
  146         if (dev->agp->memory)
  147                 dev->agp->memory->prev = entry;
  148         dev->agp->memory = entry;
  149 
  150         agp_memory_info(dev->agp->agpdev, entry->handle, &info);
  151 
  152         request.handle   = (unsigned long) entry->handle;
  153         request.physical = info.ami_physical;
  154 
  155         *(drm_agp_buffer_t *) data = request;
  156 
  157         return 0;
  158 }
  159 
  160 static drm_agp_mem_t * DRM(agp_lookup_entry)(drm_device_t *dev, void *handle)
  161 {
  162         drm_agp_mem_t *entry;
  163 
  164         for (entry = dev->agp->memory; entry; entry = entry->next) {
  165                 if (entry->handle == handle) return entry;
  166         }
  167         return NULL;
  168 }
  169 
  170 int DRM(agp_unbind)(DRM_IOCTL_ARGS)
  171 {
  172         DRM_DEVICE;
  173         drm_agp_binding_t request;
  174         drm_agp_mem_t     *entry;
  175         int retcode;
  176 
  177         if (!dev->agp || !dev->agp->acquired)
  178                 return EINVAL;
  179         request = *(drm_agp_binding_t *) data;
  180         if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
  181                 return EINVAL;
  182         if (!entry->bound) return EINVAL;
  183         retcode=DRM(unbind_agp)(entry->handle);
  184         if (!retcode)
  185         {
  186                 entry->bound=0;
  187                 return 0;
  188         }
  189         else
  190                 return retcode;
  191 }
  192 
  193 int DRM(agp_bind)(DRM_IOCTL_ARGS)
  194 {
  195         DRM_DEVICE;
  196         drm_agp_binding_t request;
  197         drm_agp_mem_t     *entry;
  198         int               retcode;
  199         int               page;
  200         
  201         DRM_DEBUG("agp_bind, page_size=%x\n", PAGE_SIZE);
  202         if (!dev->agp || !dev->agp->acquired)
  203                 return EINVAL;
  204         request = *(drm_agp_binding_t *) data;
  205         if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
  206                 return EINVAL;
  207         if (entry->bound) return EINVAL;
  208         page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE;
  209         if ((retcode = DRM(bind_agp)(entry->handle, page)))
  210                 return retcode;
  211         entry->bound = dev->agp->base + (page << PAGE_SHIFT);
  212         return 0;
  213 }
  214 
  215 int DRM(agp_free)(DRM_IOCTL_ARGS)
  216 {
  217         DRM_DEVICE;
  218         drm_agp_buffer_t request;
  219         drm_agp_mem_t    *entry;
  220         
  221         if (!dev->agp || !dev->agp->acquired)
  222                 return EINVAL;
  223         request = *(drm_agp_buffer_t *) data;
  224         if (!(entry = DRM(agp_lookup_entry)(dev, (void*) request.handle)))
  225                 return EINVAL;
  226         if (entry->bound)
  227                 DRM(unbind_agp)(entry->handle);
  228    
  229         if (entry->prev)
  230                 entry->prev->next = entry->next;
  231         else
  232                 dev->agp->memory  = entry->next;
  233         if (entry->next)
  234                 entry->next->prev = entry->prev;
  235         DRM(free_agp)(entry->handle, entry->pages);
  236         DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
  237         return 0;
  238 }
  239 
  240 drm_agp_head_t *DRM(agp_init)(void)
  241 {
  242         device_t agpdev;
  243         drm_agp_head_t *head   = NULL;
  244         int      agp_available = 1;
  245    
  246         agpdev = DRM_AGP_FIND_DEVICE();
  247         if (!agpdev)
  248                 agp_available = 0;
  249 
  250         DRM_DEBUG("agp_available = %d\n", agp_available);
  251 
  252         if (agp_available) {
  253                 if (!(head = DRM(alloc)(sizeof(*head), DRM_MEM_AGPLISTS)))
  254                         return NULL;
  255                 bzero((void *)head, sizeof(*head));
  256                 head->agpdev = agpdev;
  257                 agp_get_info(agpdev, &head->info);
  258                 head->memory = NULL;
  259                 DRM_INFO("AGP at 0x%08lx %dMB\n",
  260                          (long)head->info.ai_aperture_base,
  261                          (int)(head->info.ai_aperture_size >> 20));
  262         }
  263         return head;
  264 }
  265 
  266 void DRM(agp_uninit)(void)
  267 {
  268 /* FIXME: What goes here */
  269 }
  270 
  271 
  272 agp_memory *DRM(agp_allocate_memory)(size_t pages, u32 type)
  273 {
  274         device_t agpdev;
  275 
  276         agpdev = DRM_AGP_FIND_DEVICE();
  277         if (!agpdev)
  278                 return NULL;
  279 
  280         return agp_alloc_memory(agpdev, type, pages << AGP_PAGE_SHIFT);
  281 }
  282 
  283 int DRM(agp_free_memory)(agp_memory *handle)
  284 {
  285         device_t agpdev;
  286 
  287         agpdev = DRM_AGP_FIND_DEVICE();
  288         if (!agpdev || !handle)
  289                 return 0;
  290 
  291         agp_free_memory(agpdev, handle);
  292         return 1;
  293 }
  294 
  295 int DRM(agp_bind_memory)(agp_memory *handle, off_t start)
  296 {
  297         device_t agpdev;
  298 
  299         agpdev = DRM_AGP_FIND_DEVICE();
  300         if (!agpdev || !handle)
  301                 return EINVAL;
  302 
  303         return agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
  304 }
  305 
  306 int DRM(agp_unbind_memory)(agp_memory *handle)
  307 {
  308         device_t agpdev;
  309 
  310         agpdev = DRM_AGP_FIND_DEVICE();
  311         if (!agpdev || !handle)
  312                 return EINVAL;
  313 
  314         return agp_unbind_memory(agpdev, handle);
  315 }

Cache object: 874a2596f18acf0e70ddca07680ffcd0


[ 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.