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_os_freebsd.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 /*
    2  * $FreeBSD: releng/5.0/sys/dev/drm/drm_os_freebsd.h 102775 2002-09-01 17:45:04Z anholt $
    3  */
    4 
    5 #include <sys/param.h>
    6 #include <sys/queue.h>
    7 #include <sys/lockmgr.h>
    8 #include <sys/malloc.h>
    9 #include <sys/kernel.h>
   10 #include <sys/module.h>
   11 #include <sys/systm.h>
   12 #include <sys/conf.h>
   13 #include <sys/stat.h>
   14 #include <sys/proc.h>
   15 #include <sys/lock.h>
   16 #include <sys/fcntl.h>
   17 #include <sys/uio.h>
   18 #include <sys/filio.h>
   19 #include <sys/sysctl.h>
   20 #include <vm/vm.h>
   21 #include <vm/pmap.h>
   22 #include <machine/pmap.h>
   23 #if __FreeBSD_version >= 500000
   24 #include <sys/selinfo.h>
   25 #endif
   26 #include <sys/bus.h>
   27 #if __FreeBSD_version >= 400005
   28 #include <sys/taskqueue.h>
   29 #endif
   30 #if __FreeBSD_version >= 500000
   31 #include <sys/mutex.h>
   32 #endif
   33 
   34 #if __FreeBSD_version >= 400006
   35 #define __REALLY_HAVE_AGP       __HAVE_AGP
   36 #endif
   37 
   38 #define __REALLY_HAVE_MTRR      0
   39 #define __REALLY_HAVE_SG        0
   40 
   41 #if __REALLY_HAVE_AGP
   42 #include <pci/agpvar.h>
   43 #endif
   44 
   45 /* Allow setting of debug code enabling from kernel config file */
   46 #include <opt_drm.h>
   47 #if DRM_DEBUG
   48 #undef  DRM_DEBUG_CODE
   49 #define DRM_DEBUG_CODE 2
   50 #endif
   51 #undef DRM_DEBUG
   52 
   53 #define DRM_TIME_SLICE        (hz/20)  /* Time slice for GLXContexts      */
   54 
   55 #define DRM_DEV_MODE    (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
   56 #define DRM_DEV_UID     0
   57 #define DRM_DEV_GID     0
   58 
   59 #if __FreeBSD_version >= 500000
   60 #define DRM_OS_SPINTYPE         struct mtx
   61 #define DRM_OS_SPININIT(l,name) mtx_init(&l, name, NULL, MTX_DEF)
   62 #define DRM_OS_SPINLOCK(l)      mtx_lock(l)
   63 #define DRM_OS_SPINUNLOCK(u)    mtx_unlock(u);
   64 #define DRM_OS_CURPROC          curthread
   65 #define DRM_OS_STRUCTPROC       struct thread
   66 #define DRM_OS_CURRENTPID       curthread->td_proc->p_pid
   67 #else
   68 #define DRM_OS_CURPROC          curproc
   69 #define DRM_OS_STRUCTPROC       struct proc
   70 #define DRM_OS_SPINTYPE         struct simplelock
   71 #define DRM_OS_SPININIT(l,name) simple_lock_init(&l)
   72 #define DRM_OS_SPINLOCK(l)      simple_lock(l)
   73 #define DRM_OS_SPINUNLOCK(u)    simple_unlock(u);
   74 #define DRM_OS_CURRENTPID       curproc->p_pid
   75 #endif
   76 
   77 #define DRM_OS_IOCTL            dev_t kdev, u_long cmd, caddr_t data, int flags, DRM_OS_STRUCTPROC *p
   78 #define IOCTL_ARGS_PASS         kdev, cmd, data, flags, p
   79 #define DRM_OS_LOCK             lockmgr(&dev->dev_lock, LK_EXCLUSIVE, 0, DRM_OS_CURPROC)
   80 #define DRM_OS_UNLOCK           lockmgr(&dev->dev_lock, LK_RELEASE, 0, DRM_OS_CURPROC)
   81 #define DRM_OS_CHECKSUSER       suser(p)
   82 #define DRM_OS_TASKQUEUE_ARGS   void *dev, int pending
   83 #define DRM_OS_IRQ_ARGS         void *device
   84 #define DRM_OS_DEVICE           drm_device_t    *dev    = kdev->si_drv1
   85 #define DRM_OS_MALLOC(size)     malloc( size, DRM(M_DRM), M_NOWAIT )
   86 #define DRM_OS_FREE(pt)         free( pt, DRM(M_DRM) )
   87 #define DRM_OS_VTOPHYS(addr)    vtophys(addr)
   88 
   89 #define DRM_OS_PRIV                                     \
   90         drm_file_t      *priv   = (drm_file_t *) DRM(find_file_by_proc)(dev, p); \
   91         if (!priv) {                                            \
   92                 DRM_DEBUG("can't find authenticator\n");        \
   93                 return EINVAL;                                  \
   94         }
   95 
   96 #define DRM_OS_DELAY( udelay )                                  \
   97 do {                                                            \
   98         struct timeval tv1, tv2;                                \
   99         microtime(&tv1);                                        \
  100         do {                                                    \
  101                 microtime(&tv2);                                \
  102         }                                                       \
  103         while (((tv2.tv_sec-tv1.tv_sec)*1000000 + tv2.tv_usec - tv1.tv_usec) < udelay ); \
  104 } while (0)
  105 
  106 #define DRM_OS_ERR(v)   v
  107 
  108 
  109 #define DRM_OS_KRNTOUSR( user, kern, size)      \
  110         if ( IOCPARM_LEN(cmd) != size)                  \
  111                 return EINVAL;                          \
  112         *user = kern;
  113 #define DRM_OS_KRNFROMUSR(kern, user, size) \
  114         if ( IOCPARM_LEN(cmd) != size)                  \
  115                 return EINVAL;                          \
  116         kern = *user;
  117 #define DRM_OS_COPYTOUSR(user, kern, size) \
  118         copyout(kern, user, size)
  119 #define DRM_OS_COPYFROMUSR(kern, user, size) \
  120         copyin(user, kern, size)
  121 
  122 #define DRM_OS_READMEMORYBARRIER \
  123 {                                                                                               \
  124         int xchangeDummy;                                                                       \
  125         DRM_DEBUG("%s\n", __func__);                                                    \
  126         __asm__ volatile(" push %%eax ; xchg %%eax, %0 ; pop %%eax" : : "m" (xchangeDummy));    \
  127         __asm__ volatile(" push %%eax ; push %%ebx ; push %%ecx ; push %%edx ;"                 \
  128                          " movl $0,%%eax ; cpuid ; pop %%edx ; pop %%ecx ; pop %%ebx ;"         \
  129                          " pop %%eax" : /* no outputs */ :  /* no inputs */ );                  \
  130 } while (0);
  131 
  132 #define DRM_OS_WRITEMEMORYBARRIER DRM_OS_READMEMORYBARRIER
  133 
  134 #define DRM_OS_WAKEUP(w) wakeup(w)
  135 #define DRM_OS_WAKEUP_INT(w) wakeup(w)
  136 
  137 #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
  138 
  139 #define malloctype DRM(M_DRM)
  140 /* The macros confliced in the MALLOC_DEFINE */
  141 MALLOC_DECLARE(malloctype);
  142 #undef malloctype
  143 
  144 typedef struct drm_chipinfo
  145 {
  146         int vendor;
  147         int device;
  148         int supported;
  149         char *name;
  150 } drm_chipinfo_t;
  151 
  152 typedef unsigned long atomic_t;
  153 typedef u_int32_t cycles_t;
  154 typedef u_int32_t spinlock_t;
  155 typedef u_int32_t u32;
  156 typedef u_int16_t u16;
  157 typedef u_int8_t u8;
  158 #define atomic_set(p, v)        (*(p) = (v))
  159 #define atomic_read(p)          (*(p))
  160 #define atomic_inc(p)           atomic_add_long(p, 1)
  161 #define atomic_dec(p)           atomic_subtract_long(p, 1)
  162 #define atomic_add(n, p)        atomic_add_long(p, n)
  163 #define atomic_sub(n, p)        atomic_subtract_long(p, n)
  164 
  165 /* Fake this */
  166 static __inline unsigned int
  167 test_and_set_bit(int b, volatile unsigned long *p)
  168 {
  169         int s = splhigh();
  170         unsigned int m = 1<<b;
  171         unsigned int r = *p & m;
  172         *p |= m;
  173         splx(s);
  174         return r;
  175 }
  176 
  177 static __inline void
  178 clear_bit(int b, volatile unsigned long *p)
  179 {
  180     atomic_clear_long(p + (b >> 5), 1 << (b & 0x1f));
  181 }
  182 
  183 static __inline void
  184 set_bit(int b, volatile unsigned long *p)
  185 {
  186     atomic_set_long(p + (b >> 5), 1 << (b & 0x1f));
  187 }
  188 
  189 static __inline int
  190 test_bit(int b, volatile unsigned long *p)
  191 {
  192     return p[b >> 5] & (1 << (b & 0x1f));
  193 }
  194 
  195 static __inline int
  196 find_first_zero_bit(volatile unsigned long *p, int max)
  197 {
  198     int b;
  199 
  200     for (b = 0; b < max; b += 32) {
  201         if (p[b >> 5] != ~0) {
  202             for (;;) {
  203                 if ((p[b >> 5] & (1 << (b & 0x1f))) == 0)
  204                     return b;
  205                 b++;
  206             }
  207         }
  208     }
  209     return max;
  210 }
  211 
  212 #define spldrm()                spltty()
  213 
  214 #define memset(p, v, s)         bzero(p, s)
  215 
  216 /*
  217  * Fake out the module macros for versions of FreeBSD where they don't
  218  * exist.
  219  */
  220 #if (__FreeBSD_version < 500002 && __FreeBSD_version > 500000) || __FreeBSD_version < 420000
  221 /* FIXME: again, what's the exact date? */
  222 #define MODULE_VERSION(a,b)             struct __hack
  223 #define MODULE_DEPEND(a,b,c,d,e)        struct __hack
  224 
  225 #endif
  226 
  227 #define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
  228 #define _DRM_CAS(lock,old,new,__ret)                                   \
  229         do {                                                           \
  230                 int __dummy;    /* Can't mark eax as clobbered */      \
  231                 __asm__ __volatile__(                                  \
  232                         "lock ; cmpxchg %4,%1\n\t"                     \
  233                         "setnz %0"                                     \
  234                         : "=d" (__ret),                                \
  235                           "=m" (__drm_dummy_lock(lock)),               \
  236                           "=a" (__dummy)                               \
  237                         : "2" (old),                                   \
  238                           "r" (new));                                  \
  239         } while (0)
  240 
  241 /* Redefinitions to make templating easy */
  242 #define wait_queue_head_t       long
  243 #define agp_memory              void
  244 #define jiffies                 ticks
  245 
  246                                 /* Macros to make printf easier */
  247 #define DRM_ERROR(fmt, arg...) \
  248         printf("error: [" DRM_NAME ":%s] *ERROR* " fmt , \
  249                 __func__, ##arg)
  250 #define DRM_MEM_ERROR(area, fmt, arg...) \
  251         printf("error: [" DRM_NAME ":%s:%s] *ERROR* " fmt , \
  252                __func__, DRM(mem_stats)[area].name , ##arg)
  253 #define DRM_INFO(fmt, arg...)  printf("info: " "[" DRM_NAME "] " fmt , ##arg)
  254 
  255 #if DRM_DEBUG_CODE
  256 #define DRM_DEBUG(fmt, arg...)                                          \
  257         do {                                                            \
  258                 if (DRM(flags) & DRM_FLAG_DEBUG)                        \
  259                         printf("[" DRM_NAME ":%s] " fmt ,               \
  260                                 __func__, ##arg);                       \
  261         } while (0)
  262 #else
  263 #define DRM_DEBUG(fmt, arg...)           do { } while (0)
  264 #endif
  265 
  266 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
  267 
  268 #if (__FreeBSD_version >= 500000) || ((__FreeBSD_version < 500000) && (__FreeBSD_version >= 410002))
  269 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
  270 #else
  271 #define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS
  272 #endif
  273 
  274 #define DRM_SYSCTL_PRINT(fmt, arg...)           \
  275   snprintf(buf, sizeof(buf), fmt, ##arg);       \
  276   error = SYSCTL_OUT(req, buf, strlen(buf));    \
  277   if (error) return error;
  278 
  279 #define DRM_SYSCTL_PRINT_RET(ret, fmt, arg...)  \
  280   snprintf(buf, sizeof(buf), fmt, ##arg);       \
  281   error = SYSCTL_OUT(req, buf, strlen(buf));    \
  282   if (error) { ret; return error; }
  283 
  284 
  285 #define DRM_FIND_MAP(dest, o)                                           \
  286         do {                                                            \
  287                 drm_map_list_entry_t *listentry;                        \
  288                 TAILQ_FOREACH(listentry, dev->maplist, link) {          \
  289                         if ( listentry->map->offset == o ) {            \
  290                                 dest = listentry->map;                  \
  291                                 break;                                  \
  292                         }                                               \
  293                 }                                                       \
  294         } while (0)
  295 
  296 
  297 /* Internal functions */
  298 
  299 /* drm_drv.h */
  300 extern d_open_t         DRM(open);
  301 extern d_close_t        DRM(close);
  302 extern d_read_t         DRM(read);
  303 extern d_write_t        DRM(write);
  304 extern d_poll_t         DRM(poll);
  305 extern d_mmap_t         DRM(mmap);
  306 extern int              DRM(open_helper)(dev_t kdev, int flags, int fmt, 
  307                                          DRM_OS_STRUCTPROC *p, drm_device_t *dev);
  308 extern drm_file_t       *DRM(find_file_by_proc)(drm_device_t *dev, 
  309                                          DRM_OS_STRUCTPROC *p);
  310 
  311 /* Memory management support (drm_memory.h) */
  312 extern int              DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS;
  313 
  314 /* SysCtl Support (drm_sysctl.h) */
  315 extern int              DRM(sysctl_init)(drm_device_t *dev);
  316 extern int              DRM(sysctl_cleanup)(drm_device_t *dev);

Cache object: 160ae628deb3df7096cd7a774a5f797f


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