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_dma.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_dma.c -- DMA IOCTL and function support -*- linux-c -*-
    2  * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
    3  */
    4 /*-
    5  * Copyright 1999, 2000 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_dma.c 153401 2005-12-14 00:52:59Z anholt $");
   36 
   37 #include "dev/drm/drmP.h"
   38 
   39 int drm_dma_setup(drm_device_t *dev)
   40 {
   41 
   42         dev->dma = malloc(sizeof(*dev->dma), M_DRM, M_NOWAIT | M_ZERO);
   43         if (dev->dma == NULL)
   44                 return DRM_ERR(ENOMEM);
   45 
   46         DRM_SPININIT(dev->dma_lock, "drmdma");
   47 
   48         return 0;
   49 }
   50 
   51 void drm_dma_takedown(drm_device_t *dev)
   52 {
   53         drm_device_dma_t  *dma = dev->dma;
   54         int               i, j;
   55 
   56         if (dma == NULL)
   57                 return;
   58 
   59                                 /* Clear dma buffers */
   60         for (i = 0; i <= DRM_MAX_ORDER; i++) {
   61                 if (dma->bufs[i].seg_count) {
   62                         DRM_DEBUG("order %d: buf_count = %d,"
   63                                   " seg_count = %d\n",
   64                                   i,
   65                                   dma->bufs[i].buf_count,
   66                                   dma->bufs[i].seg_count);
   67                         for (j = 0; j < dma->bufs[i].seg_count; j++) {
   68                                 drm_pci_free(dev, dma->bufs[i].seglist[j]);
   69                         }
   70                         free(dma->bufs[i].seglist, M_DRM);
   71                 }
   72 
   73                 if (dma->bufs[i].buf_count) {
   74                         for (j = 0; j < dma->bufs[i].buf_count; j++) {
   75                                 free(dma->bufs[i].buflist[j].dev_private,
   76                                     M_DRM);
   77                         }
   78                         free(dma->bufs[i].buflist, M_DRM);
   79                 }
   80         }
   81 
   82         free(dma->buflist, M_DRM);
   83         free(dma->pagelist, M_DRM);
   84         free(dev->dma, M_DRM);
   85         dev->dma = NULL;
   86         DRM_SPINUNINIT(dev->dma_lock);
   87 }
   88 
   89 
   90 void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf)
   91 {
   92         if (!buf) return;
   93 
   94         buf->pending  = 0;
   95         buf->filp     = NULL;
   96         buf->used     = 0;
   97 }
   98 
   99 void drm_reclaim_buffers(drm_device_t *dev, DRMFILE filp)
  100 {
  101         drm_device_dma_t *dma = dev->dma;
  102         int              i;
  103 
  104         if (!dma) return;
  105         for (i = 0; i < dma->buf_count; i++) {
  106                 if (dma->buflist[i]->filp == filp) {
  107                         switch (dma->buflist[i]->list) {
  108                         case DRM_LIST_NONE:
  109                                 drm_free_buffer(dev, dma->buflist[i]);
  110                                 break;
  111                         case DRM_LIST_WAIT:
  112                                 dma->buflist[i]->list = DRM_LIST_RECLAIM;
  113                                 break;
  114                         default:
  115                                 /* Buffer already on hardware. */
  116                                 break;
  117                         }
  118                 }
  119         }
  120 }
  121 
  122 /* Call into the driver-specific DMA handler */
  123 int drm_dma(DRM_IOCTL_ARGS)
  124 {
  125         DRM_DEVICE;
  126 
  127         if (dev->driver.dma_ioctl) {
  128                 return dev->driver.dma_ioctl(kdev, cmd, data, flags, p, filp);
  129         } else {
  130                 DRM_DEBUG("DMA ioctl on driver with no dma handler\n");
  131                 return EINVAL;
  132         }
  133 }

Cache object: 474b09ea93a710080f5bd71b9153041e


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