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_ioctl.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_ioctl.h -- IOCTL processing for DRM -*- linux-c -*-
    2  * Created: Fri Jan  8 09:01:26 1999 by faith@valinux.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  * Authors:
   28  *    Rickard E. (Rik) Faith <faith@valinux.com>
   29  *    Gareth Hughes <gareth@valinux.com>
   30  *
   31  * $FreeBSD: releng/5.0/sys/dev/drm/drm_ioctl.h 95693 2002-04-29 00:25:10Z anholt $
   32  */
   33 
   34 #define __NO_VERSION__
   35 #include "dev/drm/drmP.h"
   36 #ifdef __FreeBSD__
   37 #include <sys/bus.h>
   38 #include <pci/pcivar.h>
   39 #endif /* __FreeBSD__ */
   40 
   41 int DRM(irq_busid)( DRM_OS_IOCTL )
   42 {
   43         drm_irq_busid_t id;
   44 #ifdef __linux__
   45         struct pci_dev  *dev;
   46 #endif /* __linux__ */
   47 #ifdef __FreeBSD__
   48         devclass_t pci;
   49         device_t bus, dev;
   50         device_t *kids;
   51         int error, i, num_kids;
   52 #endif /* __FreeBSD__ */
   53 
   54         DRM_OS_KRNFROMUSR( id, (drm_irq_busid_t *)data, sizeof(id) );
   55 
   56 #ifdef __linux__
   57         dev = pci_find_slot(id.busnum, PCI_DEVFN(id.devnum, id.funcnum));
   58         if (dev) id.irq = dev->irq;
   59         else     id.irq = 0;
   60 #endif /* __linux__ */
   61 #ifdef __FreeBSD__
   62         pci = devclass_find("pci");
   63         if (!pci)
   64                 return ENOENT;
   65         bus = devclass_get_device(pci, id.busnum);
   66         if (!bus)
   67                 return ENOENT;
   68         error = device_get_children(bus, &kids, &num_kids);
   69         if (error)
   70                 return error;
   71 
   72         dev = 0;
   73         for (i = 0; i < num_kids; i++) {
   74                 dev = kids[i];
   75                 if (pci_get_slot(dev) == id.devnum
   76                     && pci_get_function(dev) == id.funcnum)
   77                         break;
   78         }
   79 
   80         free(kids, M_TEMP);
   81 
   82         if (i != num_kids)
   83                 id.irq = pci_get_irq(dev);
   84         else
   85                 id.irq = 0;
   86 #endif /* __FreeBSD__ */
   87         DRM_DEBUG("%d:%d:%d => IRQ %d\n",
   88                   id.busnum, id.devnum, id.funcnum, id.irq);
   89         
   90         DRM_OS_KRNTOUSR( (drm_irq_busid_t *)data, id, sizeof(id) );
   91 
   92         return 0;
   93 }
   94 
   95 int DRM(getunique)( DRM_OS_IOCTL )
   96 {
   97         DRM_OS_DEVICE;
   98         drm_unique_t     u;
   99 
  100         DRM_OS_KRNFROMUSR( u, (drm_unique_t *)data, sizeof(u) );
  101 
  102         if (u.unique_len >= dev->unique_len) {
  103                 if (DRM_OS_COPYTOUSR(u.unique, dev->unique, dev->unique_len))
  104                         return DRM_OS_ERR(EFAULT);
  105         }
  106         u.unique_len = dev->unique_len;
  107 
  108         DRM_OS_KRNTOUSR( (drm_unique_t *)data, u, sizeof(u) );
  109 
  110         return 0;
  111 }
  112 
  113 int DRM(setunique)( DRM_OS_IOCTL )
  114 {
  115         DRM_OS_DEVICE;
  116         drm_unique_t     u;
  117 
  118         if (dev->unique_len || dev->unique)
  119                 return DRM_OS_ERR(EBUSY);
  120 
  121         DRM_OS_KRNFROMUSR( u, (drm_unique_t *)data, sizeof(u) );
  122 
  123         if (!u.unique_len || u.unique_len > 1024)
  124                 return DRM_OS_ERR(EINVAL);
  125 
  126         dev->unique_len = u.unique_len;
  127         dev->unique     = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
  128 
  129         if(!dev->unique) return DRM_OS_ERR(ENOMEM);
  130 
  131         if (DRM_OS_COPYFROMUSR(dev->unique, u.unique, dev->unique_len))
  132                 return DRM_OS_ERR(EFAULT);
  133 
  134         dev->unique[dev->unique_len] = '\0';
  135 
  136         dev->devname = DRM(alloc)(strlen(dev->name) + strlen(dev->unique) + 2,
  137                                   DRM_MEM_DRIVER);
  138         if(!dev->devname) {
  139                 DRM(free)(dev->devname, sizeof(*dev->devname), DRM_MEM_DRIVER);
  140                 return DRM_OS_ERR(ENOMEM);
  141         }
  142         sprintf(dev->devname, "%s@%s", dev->name, dev->unique);
  143 
  144 #ifdef __linux__
  145         do {
  146                 struct pci_dev *pci_dev;
  147                 int b, d, f;
  148                 char *p;
  149  
  150                 for(p = dev->unique; p && *p && *p != ':'; p++);
  151                 if (!p || !*p) break;
  152                 b = (int)simple_strtoul(p+1, &p, 10);
  153                 if (*p != ':') break;
  154                 d = (int)simple_strtoul(p+1, &p, 10);
  155                 if (*p != ':') break;
  156                 f = (int)simple_strtoul(p+1, &p, 10);
  157                 if (*p) break;
  158  
  159                 pci_dev = pci_find_slot(b, PCI_DEVFN(d,f));
  160                 if (pci_dev) {
  161                         dev->pdev = pci_dev;
  162 #ifdef __alpha__
  163                         dev->hose = pci_dev->sysdata;
  164 #endif
  165                 }
  166         } while(0);
  167 #endif /* __linux__ */
  168 
  169         return 0;
  170 }
  171 
  172 
  173 int DRM(getmap)( DRM_OS_IOCTL )
  174 {
  175         DRM_OS_DEVICE;
  176         drm_map_t    map;
  177 #ifdef __linux__
  178         drm_map_list_t *r_list = NULL;
  179         struct list_head *list;
  180 #endif /* __linux__ */
  181 #ifdef __FreeBSD__
  182         drm_map_t    *mapinlist;
  183         drm_map_list_entry_t *list;
  184 #endif /* __FreeBSD__ */
  185         int          idx;
  186         int          i = 0;
  187 
  188         DRM_OS_KRNFROMUSR( map, (drm_map_t *)data, sizeof(map) );
  189 
  190         idx = map.offset;
  191 
  192         DRM_OS_LOCK;
  193         if (idx < 0 || idx >= dev->map_count) {
  194                 DRM_OS_UNLOCK;
  195                 return DRM_OS_ERR(EINVAL);
  196         }
  197 
  198 #ifdef __linux__
  199         list_for_each(list, &dev->maplist->head) {
  200                 if(i == idx) {
  201                         r_list = (drm_map_list_t *)list;
  202                         break;
  203                 }
  204                 i++;
  205         }
  206         if(!r_list || !r_list->map) {
  207                 DRM_OS_UNLOCK;
  208                 return DRM_OS_ERR(EINVAL);
  209         }
  210 
  211         map.offset = r_list->map->offset;
  212         map.size   = r_list->map->size;
  213         map.type   = r_list->map->type;
  214         map.flags  = r_list->map->flags;
  215         map.handle = r_list->map->handle;
  216         map.mtrr   = r_list->map->mtrr;
  217 #endif /* __linux__ */
  218 #ifdef __FreeBSD__
  219         TAILQ_FOREACH(list, dev->maplist, link) {
  220                 mapinlist = list->map;
  221                 if (i==idx) {
  222                         map.offset = mapinlist->offset;
  223                         map.size   = mapinlist->size;
  224                         map.type   = mapinlist->type;
  225                         map.flags  = mapinlist->flags;
  226                         map.handle = mapinlist->handle;
  227                         map.mtrr   = mapinlist->mtrr;
  228                         break;
  229                 }
  230                 i++;
  231         }
  232 #endif /* __FreeBSD__ */
  233 
  234         DRM_OS_UNLOCK;
  235 
  236 #ifdef __FreeBSD__
  237         if (!list)
  238                 return EINVAL;
  239 #endif /* __FreeBSD__ */
  240 
  241         DRM_OS_KRNTOUSR( (drm_map_t *)data, map, sizeof(map) );
  242 
  243         return 0;
  244 }
  245 
  246 int DRM(getclient)( DRM_OS_IOCTL )
  247 {
  248         DRM_OS_DEVICE;
  249         drm_client_t client;
  250         drm_file_t   *pt;
  251         int          idx;
  252         int          i = 0;
  253 
  254         DRM_OS_KRNFROMUSR( client, (drm_client_t *)data, sizeof(client) );
  255 
  256         idx = client.idx;
  257         DRM_OS_LOCK;
  258 #ifdef __linux__
  259         for (i = 0, pt = dev->file_first; i < idx && pt; i++, pt = pt->next)
  260                 ;
  261 
  262         if (!pt) {
  263                 DRM_OS_UNLOCK;
  264                 return DRM_OS_ERR(EINVAL);
  265         }
  266         client.auth  = pt->authenticated;
  267         client.pid   = pt->pid;
  268         client.uid   = pt->uid;
  269         client.magic = pt->magic;
  270         client.iocs  = pt->ioctl_count;
  271 #endif /* __linux__ */
  272 #ifdef __FreeBSD__
  273         TAILQ_FOREACH(pt, &dev->files, link) {
  274                 if (i==idx)
  275                 {
  276                         client.auth  = pt->authenticated;
  277                         client.pid   = pt->pid;
  278                         client.uid   = pt->uid;
  279                         client.magic = pt->magic;
  280                         client.iocs  = pt->ioctl_count;
  281                         DRM_OS_UNLOCK;
  282 
  283                         *(drm_client_t *)data = client;
  284                         return 0;
  285                 }
  286                 i++;
  287         }
  288 #endif /* __FreeBSD__ */
  289         DRM_OS_UNLOCK;
  290 
  291         DRM_OS_KRNTOUSR( (drm_client_t *)data, client, sizeof(client) );
  292 
  293         return 0;
  294 }
  295 
  296 int DRM(getstats)( DRM_OS_IOCTL )
  297 {
  298         DRM_OS_DEVICE;
  299         drm_stats_t  stats;
  300         int          i;
  301 
  302         memset(&stats, 0, sizeof(stats));
  303         
  304         DRM_OS_LOCK;
  305 
  306         for (i = 0; i < dev->counters; i++) {
  307                 if (dev->types[i] == _DRM_STAT_LOCK)
  308                         stats.data[i].value
  309                                 = (dev->lock.hw_lock
  310                                    ? dev->lock.hw_lock->lock : 0);
  311                 else 
  312                         stats.data[i].value = atomic_read(&dev->counts[i]);
  313                 stats.data[i].type  = dev->types[i];
  314         }
  315         
  316         stats.count = dev->counters;
  317 
  318         DRM_OS_UNLOCK;
  319 
  320         DRM_OS_KRNTOUSR( (drm_stats_t *)data, stats, sizeof(stats) );
  321 
  322         return 0;
  323 }

Cache object: c068db42d5322849abae59ce8f4b5b46


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