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: releng/5.0/sys/dev/drm/drm_agpsupport.h 95584 2002-04-27 20:47:57Z anholt $
   32  */
   33 
   34 #include "dev/drm/drmP.h"
   35 
   36 #ifdef __FreeBSD__
   37 #include <vm/vm.h>
   38 #include <vm/pmap.h>
   39 #if __REALLY_HAVE_AGP
   40 #include <sys/agpio.h>
   41 #endif
   42 #endif
   43 
   44 int DRM(agp_info)(DRM_OS_IOCTL)
   45 {
   46         drm_device_t    *dev    = kdev->si_drv1;
   47         struct agp_info *kern;
   48         drm_agp_info_t   info;
   49 
   50         if (!dev->agp || !dev->agp->acquired) return EINVAL;
   51 
   52         kern                   = &dev->agp->info;
   53         agp_get_info(dev->agp->agpdev, kern);
   54         info.agp_version_major = 1;
   55         info.agp_version_minor = 0;
   56         info.mode              = kern->ai_mode;
   57         info.aperture_base     = kern->ai_aperture_base;
   58         info.aperture_size     = kern->ai_aperture_size;
   59         info.memory_allowed    = kern->ai_memory_allowed;
   60         info.memory_used       = kern->ai_memory_used;
   61         info.id_vendor         = kern->ai_devid & 0xffff;
   62         info.id_device         = kern->ai_devid >> 16;
   63 
   64         *(drm_agp_info_t *) data = info;
   65         return 0;
   66 }
   67 
   68 int DRM(agp_acquire)(DRM_OS_IOCTL)
   69 {
   70         drm_device_t *dev = kdev->si_drv1;
   71         int          retcode;
   72 
   73         if (!dev->agp || dev->agp->acquired) return EINVAL;
   74         retcode = agp_acquire(dev->agp->agpdev);
   75         if (retcode) return retcode;
   76         dev->agp->acquired = 1;
   77         return 0;
   78 }
   79 
   80 int DRM(agp_release)(DRM_OS_IOCTL)
   81 {
   82         drm_device_t *dev = kdev->si_drv1;
   83 
   84         if (!dev->agp || !dev->agp->acquired)
   85                 return EINVAL;
   86         agp_release(dev->agp->agpdev);
   87         dev->agp->acquired = 0;
   88         return 0;
   89         
   90 }
   91 
   92 void DRM(agp_do_release)(void)
   93 {
   94         device_t agpdev;
   95 
   96         agpdev = agp_find_device();
   97         if (agpdev)
   98                 agp_release(agpdev);
   99 }
  100 
  101 int DRM(agp_enable)(DRM_OS_IOCTL)
  102 {
  103         drm_device_t   *dev = kdev->si_drv1;
  104         drm_agp_mode_t mode;
  105 
  106         if (!dev->agp || !dev->agp->acquired) return EINVAL;
  107 
  108         mode = *(drm_agp_mode_t *) data;
  109         
  110         dev->agp->mode    = mode.mode;
  111         agp_enable(dev->agp->agpdev, mode.mode);
  112         dev->agp->base    = dev->agp->info.ai_aperture_base;
  113         dev->agp->enabled = 1;
  114         return 0;
  115 }
  116 
  117 int DRM(agp_alloc)(DRM_OS_IOCTL)
  118 {
  119         drm_device_t     *dev = kdev->si_drv1;
  120         drm_agp_buffer_t request;
  121         drm_agp_mem_t    *entry;
  122         void             *handle;
  123         unsigned long    pages;
  124         u_int32_t        type;
  125         struct agp_memory_info info;
  126 
  127         if (!dev->agp || !dev->agp->acquired) return EINVAL;
  128 
  129         request = *(drm_agp_buffer_t *) data;
  130 
  131         if (!(entry = DRM(alloc)(sizeof(*entry), DRM_MEM_AGPLISTS)))
  132                 return ENOMEM;
  133    
  134         bzero(entry, sizeof(*entry));
  135 
  136         pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
  137         type = (u_int32_t) request.type;
  138 
  139         if (!(handle = DRM(alloc_agp)(pages, type))) {
  140                 DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
  141                 return ENOMEM;
  142         }
  143         
  144         entry->handle    = handle;
  145         entry->bound     = 0;
  146         entry->pages     = pages;
  147         entry->prev      = NULL;
  148         entry->next      = dev->agp->memory;
  149         if (dev->agp->memory) dev->agp->memory->prev = entry;
  150         dev->agp->memory = entry;
  151 
  152         agp_memory_info(dev->agp->agpdev, entry->handle, &info);
  153 
  154         request.handle   = (unsigned long) entry->handle;
  155         request.physical = info.ami_physical;
  156 
  157         *(drm_agp_buffer_t *) data = request;
  158 
  159         return 0;
  160 }
  161 
  162 static drm_agp_mem_t * DRM(agp_lookup_entry)(drm_device_t *dev, void *handle)
  163 {
  164         drm_agp_mem_t *entry;
  165 
  166         for (entry = dev->agp->memory; entry; entry = entry->next) {
  167                 if (entry->handle == handle) return entry;
  168         }
  169         return NULL;
  170 }
  171 
  172 int DRM(agp_unbind)(DRM_OS_IOCTL)
  173 {
  174         drm_device_t      *dev = kdev->si_drv1;
  175         drm_agp_binding_t request;
  176         drm_agp_mem_t     *entry;
  177         int retcode;
  178 
  179         if (!dev->agp || !dev->agp->acquired) return EINVAL;
  180         request = *(drm_agp_binding_t *) data;
  181         if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
  182                 return EINVAL;
  183         if (!entry->bound) return EINVAL;
  184         retcode=DRM(unbind_agp)(entry->handle);
  185         if (!retcode)
  186         {
  187                 entry->bound=0;
  188                 return 0;
  189         }
  190         else
  191                 return retcode;
  192 }
  193 
  194 int DRM(agp_bind)(DRM_OS_IOCTL)
  195 {
  196         drm_device_t      *dev = kdev->si_drv1;
  197         drm_agp_binding_t request;
  198         drm_agp_mem_t     *entry;
  199         int               retcode;
  200         int               page;
  201         
  202         DRM_DEBUG("agp_bind, page_size=%x\n", PAGE_SIZE);
  203         if (!dev->agp || !dev->agp->acquired)
  204                 return EINVAL;
  205         request = *(drm_agp_binding_t *) data;
  206         if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
  207                 return EINVAL;
  208         if (entry->bound) return EINVAL;
  209         page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE;
  210         if ((retcode = DRM(bind_agp)(entry->handle, page)))
  211                 return retcode;
  212         entry->bound = dev->agp->base + (page << PAGE_SHIFT);
  213         return 0;
  214 }
  215 
  216 int DRM(agp_free)(DRM_OS_IOCTL)
  217 {
  218         drm_device_t     *dev = kdev->si_drv1;
  219         drm_agp_buffer_t request;
  220         drm_agp_mem_t    *entry;
  221         
  222         if (!dev->agp || !dev->agp->acquired) 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) DRM(unbind_agp)(entry->handle);
  227    
  228         if (entry->prev) entry->prev->next = entry->next;
  229         else             dev->agp->memory  = entry->next;
  230         if (entry->next) entry->next->prev = entry->prev;
  231         DRM(free_agp)(entry->handle, entry->pages);
  232         DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
  233         return 0;
  234 }
  235 
  236 drm_agp_head_t *DRM(agp_init)(void)
  237 {
  238         device_t agpdev;
  239         drm_agp_head_t *head   = NULL;
  240         int      agp_available = 1;
  241    
  242         agpdev = agp_find_device();
  243         if (!agpdev)
  244                 agp_available = 0;
  245 
  246         DRM_DEBUG("agp_available = %d\n", agp_available);
  247 
  248         if (agp_available) {
  249                 if (!(head = DRM(alloc)(sizeof(*head), DRM_MEM_AGPLISTS)))
  250                         return NULL;
  251                 bzero((void *)head, sizeof(*head));
  252                 head->agpdev = agpdev;
  253                 agp_get_info(agpdev, &head->info);
  254                 head->memory = NULL;
  255 #if 0                           /* bogus */
  256                 switch (head->agp_info.chipset) {
  257                 case INTEL_GENERIC:  head->chipset = "Intel";          break;
  258                 case INTEL_LX:       head->chipset = "Intel 440LX";    break;
  259                 case INTEL_BX:       head->chipset = "Intel 440BX";    break;
  260                 case INTEL_GX:       head->chipset = "Intel 440GX";    break;
  261                 case INTEL_I810:     head->chipset = "Intel i810";     break;
  262                 case VIA_GENERIC:    head->chipset = "VIA";            break;
  263                 case VIA_VP3:        head->chipset = "VIA VP3";        break;
  264                 case VIA_MVP3:       head->chipset = "VIA MVP3";       break;
  265                 case VIA_APOLLO_PRO: head->chipset = "VIA Apollo Pro"; break;
  266                 case SIS_GENERIC:    head->chipset = "SiS";            break;
  267                 case AMD_GENERIC:    head->chipset = "AMD";            break;
  268                 case AMD_IRONGATE:   head->chipset = "AMD Irongate";   break;
  269                 case ALI_GENERIC:    head->chipset = "ALi";            break;
  270                 case ALI_M1541:      head->chipset = "ALi M1541";      break;
  271                 default:
  272                 }
  273 #endif
  274                 DRM_INFO("AGP at 0x%08x %dMB\n",
  275                          head->info.ai_aperture_base,
  276                          head->info.ai_aperture_size >> 20);
  277         }
  278         return head;
  279 }
  280 
  281 void DRM(agp_uninit)(void)
  282 {
  283 /* FIXME: What goes here */
  284 }
  285 
  286 
  287 agp_memory *DRM(agp_allocate_memory)(size_t pages, u32 type)
  288 {
  289         device_t agpdev;
  290 
  291         agpdev = agp_find_device();
  292         if (!agpdev)
  293                 return NULL;
  294 
  295         return agp_alloc_memory(agpdev, type, pages << AGP_PAGE_SHIFT);
  296 }
  297 
  298 int DRM(agp_free_memory)(agp_memory *handle)
  299 {
  300         device_t agpdev;
  301 
  302         agpdev = agp_find_device();
  303         if (!agpdev || !handle)
  304                 return 0;
  305 
  306         agp_free_memory(agpdev, handle);
  307         return 1;
  308 }
  309 
  310 int DRM(agp_bind_memory)(agp_memory *handle, off_t start)
  311 {
  312         device_t agpdev;
  313 
  314         agpdev = agp_find_device();
  315         if (!agpdev || !handle)
  316                 return EINVAL;
  317 
  318         return agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
  319 }
  320 
  321 int DRM(agp_unbind_memory)(agp_memory *handle)
  322 {
  323         device_t agpdev;
  324 
  325         agpdev = agp_find_device();
  326         if (!agpdev || !handle)
  327                 return EINVAL;
  328 
  329         return agp_unbind_memory(agpdev, handle);
  330 }

Cache object: 45e54ac70f6bd3ff8c22a5f84b92efd6


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