LCOV - code coverage report
Current view: top level - dev/pci/drm - drm_linux.h (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 672 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 160 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: drm_linux.h,v 1.91 2018/08/20 19:33:31 kettenis Exp $ */
       2             : /*
       3             :  * Copyright (c) 2013, 2014, 2015 Mark Kettenis
       4             :  * Copyright (c) 2017 Martin Pieuchot
       5             :  *
       6             :  * Permission to use, copy, modify, and distribute this software for any
       7             :  * purpose with or without fee is hereby granted, provided that the above
       8             :  * copyright notice and this permission notice appear in all copies.
       9             :  *
      10             :  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      11             :  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
      12             :  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
      13             :  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
      14             :  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
      15             :  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
      16             :  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
      17             :  */
      18             : 
      19             : #ifndef _DRM_LINUX_H_
      20             : #define _DRM_LINUX_H_
      21             : 
      22             : #include <sys/param.h>
      23             : #include <sys/atomic.h>
      24             : #include <sys/errno.h>
      25             : #include <sys/fcntl.h>
      26             : #include <sys/kernel.h>
      27             : #include <sys/signalvar.h>
      28             : #include <sys/stdint.h>
      29             : #include <sys/systm.h>
      30             : #include <sys/task.h>
      31             : #include <sys/time.h>
      32             : #include <sys/timeout.h>
      33             : #include <sys/tree.h>
      34             : 
      35             : #include <uvm/uvm_extern.h>
      36             : 
      37             : #include <ddb/db_var.h>
      38             : 
      39             : #include <dev/i2c/i2cvar.h>
      40             : #include <dev/pci/pcireg.h>
      41             : #include <dev/pci/pcivar.h>
      42             : 
      43             : #include <dev/pci/drm/linux_types.h>
      44             : #include <dev/pci/drm/drm_linux_atomic.h>
      45             : #include <dev/pci/drm/drm_linux_list.h>
      46             : 
      47             : /* The Linux code doesn't meet our usual standards! */
      48             : #ifdef __clang__
      49             : #pragma clang diagnostic ignored "-Wenum-conversion"
      50             : #pragma clang diagnostic ignored "-Winitializer-overrides"
      51             : #pragma clang diagnostic ignored "-Wtautological-compare"
      52             : #pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
      53             : #pragma clang diagnostic ignored "-Wunused-const-variable"
      54             : #else
      55             : #pragma GCC diagnostic ignored "-Wformat-zero-length"
      56             : #endif
      57             : 
      58             : #define STUB() do { printf("%s: stub\n", __func__); } while(0)
      59             : 
      60             : typedef int irqreturn_t;
      61             : enum irqreturn {
      62             :         IRQ_NONE = 0,
      63             :         IRQ_HANDLED = 1
      64             : };
      65             : 
      66             : typedef int8_t   s8;
      67             : typedef uint8_t  u8;
      68             : typedef int16_t  s16;
      69             : typedef uint16_t u16;
      70             : typedef int32_t  s32;
      71             : typedef uint32_t u32;
      72             : typedef int64_t  s64;
      73             : typedef uint64_t u64;
      74             : 
      75             : #define U64_C(x) UINT64_C(x)
      76             : #define U64_MAX UINT64_MAX
      77             : 
      78             : typedef uint16_t __le16;
      79             : typedef uint16_t __be16;
      80             : typedef uint32_t __le32;
      81             : typedef uint32_t __be32;
      82             : 
      83             : typedef bus_addr_t dma_addr_t;
      84             : typedef bus_addr_t phys_addr_t;
      85             : 
      86             : typedef bus_addr_t resource_size_t;
      87             : 
      88             : typedef off_t loff_t;
      89             : 
      90             : #define __force
      91             : #define __always_unused __unused
      92             : #define __read_mostly
      93             : #define __iomem
      94             : #define __must_check
      95             : #define __init
      96             : #define __exit
      97             : 
      98             : #ifndef __user
      99             : #define __user
     100             : #endif
     101             : 
     102             : #define __printf(x, y)
     103             : 
     104             : #define barrier()               __asm __volatile("" : : : "memory");
     105             : 
     106             : #define uninitialized_var(x) x
     107             : 
     108             : #if BYTE_ORDER == BIG_ENDIAN
     109             : #define __BIG_ENDIAN
     110             : #else
     111             : #define __LITTLE_ENDIAN
     112             : #endif
     113             : 
     114             : #define le16_to_cpu(x) letoh16(x)
     115             : #define le32_to_cpu(x) letoh32(x)
     116             : #define be16_to_cpu(x) betoh16(x)
     117             : #define be32_to_cpu(x) betoh32(x)
     118             : #define le16_to_cpup(x) lemtoh16(x)
     119             : #define le32_to_cpup(x) lemtoh32(x)
     120             : #define be16_to_cpup(x) bemtoh16(x)
     121             : #define be32_to_cpup(x) bemtoh32(x)
     122             : #define get_unaligned_le32(x)   lemtoh32(x)
     123             : #define cpu_to_le16(x) htole16(x)
     124             : #define cpu_to_le32(x) htole32(x)
     125             : #define cpu_to_be16(x) htobe16(x)
     126             : #define cpu_to_be32(x) htobe32(x)
     127             : 
     128             : static inline uint8_t
     129           0 : hweight8(uint32_t x)
     130             : {
     131           0 :         x = (x & 0x55) + ((x & 0xaa) >> 1);
     132           0 :         x = (x & 0x33) + ((x & 0xcc) >> 2);
     133           0 :         x = (x + (x >> 4)) & 0x0f;
     134           0 :         return (x);
     135             : }
     136             : 
     137             : static inline uint16_t
     138           0 : hweight16(uint32_t x)
     139             : {
     140           0 :         x = (x & 0x5555) + ((x & 0xaaaa) >> 1);
     141           0 :         x = (x & 0x3333) + ((x & 0xcccc) >> 2);
     142           0 :         x = (x + (x >> 4)) & 0x0f0f;
     143           0 :         x = (x + (x >> 8)) & 0x00ff;
     144           0 :         return (x);
     145             : }
     146             : 
     147             : static inline uint32_t
     148           0 : hweight32(uint32_t x)
     149             : {
     150           0 :         x = (x & 0x55555555) + ((x & 0xaaaaaaaa) >> 1);
     151           0 :         x = (x & 0x33333333) + ((x & 0xcccccccc) >> 2);
     152           0 :         x = (x + (x >> 4)) & 0x0f0f0f0f;
     153           0 :         x = (x + (x >> 8));
     154           0 :         x = (x + (x >> 16)) & 0x000000ff;
     155           0 :         return x;
     156             : }
     157             : 
     158             : static inline uint32_t
     159           0 : hweight64(uint64_t x)
     160             : {
     161           0 :         x = (x & 0x5555555555555555ULL) + ((x & 0xaaaaaaaaaaaaaaaaULL) >> 1);
     162           0 :         x = (x & 0x3333333333333333ULL) + ((x & 0xccccccccccccccccULL) >> 2);
     163           0 :         x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
     164           0 :         x = (x + (x >> 8));
     165           0 :         x = (x + (x >> 16));
     166           0 :         x = (x + (x >> 32)) & 0x000000ff;
     167           0 :         return x;
     168             : }
     169             : 
     170             : #define lower_32_bits(n)        ((u32)(n))
     171             : #define upper_32_bits(_val)     ((u32)(((_val) >> 16) >> 16))
     172             : #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) -1)
     173             : #define BIT(x)                  (1UL << x)
     174             : #define BITS_TO_LONGS(x)        howmany((x), 8 * sizeof(long))
     175             : 
     176             : #define DECLARE_BITMAP(x, y)    unsigned long x[BITS_TO_LONGS(y)];
     177             : #define bitmap_empty(p, n)      (find_first_bit(p, n) == n)
     178             : #define GENMASK(h, l)           ((~0U >> (32 - h -1)) & (~0U << l))
     179             : 
     180             : static inline void
     181           0 : bitmap_set(void *p, int b, u_int n)
     182             : {
     183           0 :         u_int end = b + n;
     184             : 
     185           0 :         for (; b < end; b++)
     186           0 :                 __set_bit(b, p);
     187           0 : }
     188             : 
     189             : static inline void
     190           0 : bitmap_zero(void *p, u_int n)
     191             : {
     192           0 :         u_int *ptr = p;
     193             :         u_int b;
     194             : 
     195           0 :         for (b = 0; b < n; b += 32)
     196           0 :                 ptr[b >> 5] = 0;
     197           0 : }
     198             : 
     199             : static inline void
     200           0 : bitmap_or(void *d, void *s1, void *s2, u_int n)
     201             : {
     202           0 :         u_int *dst = d;
     203           0 :         u_int *src1 = s1;
     204           0 :         u_int *src2 = s2;
     205             :         u_int b;
     206             : 
     207           0 :         for (b = 0; b < n; b += 32)
     208           0 :                 dst[b >> 5] = src1[b >> 5] | src2[b >> 5];
     209           0 : }
     210             : 
     211             : static inline int
     212           0 : bitmap_weight(void *p, u_int n)
     213             : {
     214           0 :         u_int *ptr = p;
     215             :         u_int b;
     216             :         int sum = 0;
     217             : 
     218           0 :         for (b = 0; b < n; b += 32)
     219           0 :                 sum += hweight32(ptr[b >> 5]);
     220           0 :         return sum;
     221             : }
     222             : 
     223             : #define DECLARE_HASHTABLE(name, bits) struct hlist_head name[1 << (bits)]
     224             : 
     225             : static inline void
     226           0 : __hash_init(struct hlist_head *table, u_int size)
     227             : {
     228             :         u_int i;
     229             : 
     230           0 :         for (i = 0; i < size; i++)
     231           0 :                 INIT_HLIST_HEAD(&table[i]);
     232           0 : }
     233             : 
     234             : static inline bool
     235           0 : __hash_empty(struct hlist_head *table, u_int size)
     236             : {
     237             :         u_int i;
     238             : 
     239           0 :         for (i = 0; i < size; i++) {
     240           0 :                 if (!hlist_empty(&table[i]))
     241           0 :                         return false;
     242             :         }
     243             : 
     244           0 :         return true;
     245           0 : }
     246             : 
     247             : #define __hash(table, key)      &table[key % (nitems(table) - 1)]
     248             : 
     249             : #define hash_init(table)        __hash_init(table, nitems(table))
     250             : #define hash_add(table, node, key) \
     251             :         hlist_add_head(node, __hash(table, key))
     252             : #define hash_del(node)          hlist_del_init(node)
     253             : #define hash_empty(table)       __hash_empty(table, nitems(table))
     254             : #define hash_for_each_possible(table, obj, member, key) \
     255             :         hlist_for_each_entry(obj, __hash(table, key), member)
     256             : #define hash_for_each_safe(table, i, tmp, obj, member)  \
     257             :         for (i = 0; i < nitems(table); i++)          \
     258             :                hlist_for_each_entry_safe(obj, tmp, &table[i], member)
     259             : 
     260             : #define ACCESS_ONCE(x)          (x)
     261             : 
     262             : #define EXPORT_SYMBOL(x)
     263             : 
     264             : #define IS_ENABLED(x) x - 0
     265             : 
     266             : #define IS_BUILTIN(x) 1
     267             : 
     268             : struct device_node;
     269             : 
     270             : struct device_driver {
     271             :         struct device *dev;
     272             : };
     273             : 
     274             : #define dev_get_drvdata(x)      NULL
     275             : #define dev_set_drvdata(x, y)
     276             : #define dev_name(dev)           ""
     277             : 
     278             : #define devm_kzalloc(x, y, z)   kzalloc(y, z)
     279             : 
     280             : struct module;
     281             : 
     282             : #define MODULE_AUTHOR(x)
     283             : #define MODULE_DESCRIPTION(x)
     284             : #define MODULE_LICENSE(x)
     285             : #define MODULE_FIRMWARE(x)
     286             : #define MODULE_DEVICE_TABLE(x, y)
     287             : #define MODULE_PARM_DESC(parm, desc)
     288             : #define module_param_named(name, value, type, perm)
     289             : #define module_param_named_unsafe(name, value, type, perm)
     290             : #define module_param_unsafe(name, type, perm)
     291             : #define module_init(x)
     292             : #define module_exit(x)
     293             : 
     294             : #define THIS_MODULE     NULL
     295             : 
     296             : #define ARRAY_SIZE nitems
     297             : 
     298             : #define ERESTARTSYS     EINTR
     299             : #define ETIME           ETIMEDOUT
     300             : #define EREMOTEIO       EIO
     301             : #define ENOTSUPP        ENOTSUP
     302             : #define ENODATA         ENOTSUP
     303             : #define ECHRNG          EINVAL
     304             : 
     305             : #define KERN_INFO       ""
     306             : #define KERN_WARNING    ""
     307             : #define KERN_NOTICE     ""
     308             : #define KERN_DEBUG      ""
     309             : #define KERN_CRIT       ""
     310             : #define KERN_ERR        ""
     311             : 
     312             : #define KBUILD_MODNAME "drm"
     313             : 
     314             : #define UTS_RELEASE     ""
     315             : 
     316             : #define TASK_COMM_LEN   (MAXCOMLEN + 1)
     317             : 
     318             : #ifndef pr_fmt
     319             : #define pr_fmt(fmt) fmt
     320             : #endif
     321             : 
     322             : #define printk_once(fmt, arg...) ({             \
     323             :         static int __warned;                    \
     324             :         if (!__warned) {                        \
     325             :                 printf(fmt, ## arg);            \
     326             :                 __warned = 1;                   \
     327             :         }                                       \
     328             : })
     329             : 
     330             : #define printk(fmt, arg...)     printf(fmt, ## arg)
     331             : #define pr_warn(fmt, arg...)    printf(pr_fmt(fmt), ## arg)
     332             : #define pr_warn_once(fmt, arg...)       printk_once(pr_fmt(fmt), ## arg)
     333             : #define pr_notice(fmt, arg...)  printf(pr_fmt(fmt), ## arg)
     334             : #define pr_crit(fmt, arg...)    printf(pr_fmt(fmt), ## arg)
     335             : #define pr_err(fmt, arg...)     printf(pr_fmt(fmt), ## arg)
     336             : 
     337             : #ifdef DRMDEBUG
     338             : #define pr_info(fmt, arg...)    printf(pr_fmt(fmt), ## arg)
     339             : #define pr_info_once(fmt, arg...)       printk_once(pr_fmt(fmt), ## arg)
     340             : #define pr_debug(fmt, arg...)   printf(pr_fmt(fmt), ## arg)
     341             : #else
     342             : #define pr_info(fmt, arg...)    do { } while(0)
     343             : #define pr_info_once(fmt, arg...)       do { } while(0)
     344             : #define pr_debug(fmt, arg...)   do { } while(0)
     345             : #endif
     346             : 
     347             : #define dev_warn(dev, fmt, arg...)                              \
     348             :         printf("drm:pid%d:%s *WARNING* " fmt, curproc->p_p->ps_pid,     \
     349             :             __func__ , ## arg)
     350             : #define dev_notice(dev, fmt, arg...)                            \
     351             :         printf("drm:pid%d:%s *NOTICE* " fmt, curproc->p_p->ps_pid,      \
     352             :             __func__ , ## arg)
     353             : #define dev_crit(dev, fmt, arg...)                              \
     354             :         printf("drm:pid%d:%s *ERROR* " fmt, curproc->p_p->ps_pid,       \
     355             :             __func__ , ## arg)
     356             : #define dev_err(dev, fmt, arg...)                               \
     357             :         printf("drm:pid%d:%s *ERROR* " fmt, curproc->p_p->ps_pid,       \
     358             :             __func__ , ## arg)
     359             : 
     360             : #ifdef DRMDEBUG
     361             : #define dev_info(dev, fmt, arg...)                              \
     362             :         printf("drm: " fmt, ## arg)
     363             : #define dev_debug(dev, fmt, arg...)                             \
     364             :         printf("drm:pid%d:%s *DEBUG* " fmt, curproc->p_p->ps_pid,       \
     365             :             __func__ , ## arg)
     366             : #else
     367             : #define dev_info(dev, fmt, arg...)                              \
     368             :             do { } while(0)
     369             : #define dev_debug(dev, fmt, arg...)                             \
     370             :             do { } while(0)
     371             : #endif
     372             : 
     373             : enum {
     374             :         DUMP_PREFIX_NONE,
     375             :         DUMP_PREFIX_ADDRESS,
     376             :         DUMP_PREFIX_OFFSET
     377             : };
     378             : 
     379             : void print_hex_dump(const char *, const char *, int, int, int,
     380             :          const void *, size_t, bool);
     381             : 
     382             : #define scnprintf(str, size, fmt, arg...) snprintf(str, size, fmt, ## arg)
     383             : 
     384             : #define unlikely(x)     __builtin_expect(!!(x), 0)
     385             : #define likely(x)       __builtin_expect(!!(x), 1)
     386             : 
     387             : #define BUG()                                                           \
     388             : do {                                                                    \
     389             :         panic("BUG at %s:%d", __FILE__, __LINE__);                    \
     390             : } while (0)
     391             : 
     392             : #ifndef DIAGNOSTIC
     393             : #define BUG_ON(x)       ((void)(x))
     394             : #else
     395             : #define BUG_ON(x)       KASSERT(!(x))
     396             : #endif
     397             : 
     398             : #define BUILD_BUG()
     399             : #define BUILD_BUG_ON(x) CTASSERT(!(x))
     400             : #define BUILD_BUG_ON_NOT_POWER_OF_2(x)
     401             : #define BUILD_BUG_ON_MSG(x, y)
     402             : 
     403             : #define WARN(condition, fmt...) ({                                      \
     404             :         int __ret = !!(condition);                                      \
     405             :         if (__ret)                                                      \
     406             :                 printf(fmt);                                            \
     407             :         unlikely(__ret);                                                \
     408             : })
     409             : 
     410             : #define WARN_ONCE(condition, fmt...) ({                                 \
     411             :         static int __warned;                                            \
     412             :         int __ret = !!(condition);                                      \
     413             :         if (__ret && !__warned) {                                       \
     414             :                 printf(fmt);                                            \
     415             :                 __warned = 1;                                           \
     416             :         }                                                               \
     417             :         unlikely(__ret);                                                \
     418             : })
     419             : 
     420             : #define _WARN_STR(x) #x
     421             : 
     422             : #define WARN_ON(condition) ({                                           \
     423             :         int __ret = !!(condition);                                      \
     424             :         if (__ret)                                                      \
     425             :                 printf("WARNING %s failed at %s:%d\n",                        \
     426             :                     _WARN_STR(condition), __FILE__, __LINE__);          \
     427             :         unlikely(__ret);                                                \
     428             : })
     429             : 
     430             : #define WARN_ON_ONCE(condition) ({                                      \
     431             :         static int __warned;                                            \
     432             :         int __ret = !!(condition);                                      \
     433             :         if (__ret && !__warned) {                                       \
     434             :                 printf("WARNING %s failed at %s:%d\n",                        \
     435             :                     _WARN_STR(condition), __FILE__, __LINE__);          \
     436             :                 __warned = 1;                                           \
     437             :         }                                                               \
     438             :         unlikely(__ret);                                                \
     439             : })
     440             : 
     441             : #define TP_PROTO(x...) x
     442             : 
     443             : #define DEFINE_EVENT(template, name, proto, args) \
     444             : static inline void trace_##name(proto) {}
     445             : 
     446             : #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
     447             : static inline void trace_##name(proto) {}
     448             : 
     449             : #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
     450             : static inline void trace_##name(proto) {}
     451             : 
     452             : #define TRACE_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
     453             : static inline void trace_##name(proto) {}
     454             : 
     455             : #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
     456             : static inline void trace_##name(proto) {}
     457             : 
     458             : #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-ELAST)
     459             : 
     460             : static inline void *
     461           0 : ERR_PTR(long error)
     462             : {
     463           0 :         return (void *) error;
     464             : }
     465             : 
     466             : static inline long
     467           0 : PTR_ERR(const void *ptr)
     468             : {
     469           0 :         return (long) ptr;
     470             : }
     471             : 
     472             : static inline long
     473           0 : IS_ERR(const void *ptr)
     474             : {
     475           0 :         return IS_ERR_VALUE((unsigned long)ptr);
     476             : }
     477             : 
     478             : static inline long
     479           0 : IS_ERR_OR_NULL(const void *ptr)
     480             : {
     481           0 :         return !ptr || IS_ERR_VALUE((unsigned long)ptr);
     482             : }
     483             : 
     484             : static inline void *
     485           0 : ERR_CAST(const void *ptr)
     486             : {
     487           0 :         return (void *)ptr;
     488             : }
     489             : 
     490             : static inline int
     491           0 : PTR_ERR_OR_ZERO(const void *ptr)
     492             : {
     493           0 :         return IS_ERR(ptr)? PTR_ERR(ptr) : 0;
     494             : }
     495             : 
     496             : #define swap(a, b) \
     497             :         do { __typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
     498             : 
     499             : #define container_of(ptr, type, member) ({                      \
     500             :         const __typeof( ((type *)0)->member ) *__mptr = (ptr);        \
     501             :         (type *)( (char *)__mptr - offsetof(type,member) );})
     502             : 
     503             : #ifndef __DECONST
     504             : #define __DECONST(type, var)    ((type)(__uintptr_t)(const void *)(var))
     505             : #endif
     506             : 
     507             : typedef struct rwlock rwlock_t;
     508             : typedef struct mutex spinlock_t;
     509             : #define DEFINE_SPINLOCK(x)      struct mutex x
     510             : #define DEFINE_MUTEX(x)         struct rwlock x
     511             : 
     512             : static inline void
     513           0 : _spin_lock_irqsave(struct mutex *mtxp, __unused unsigned long flags
     514             :     LOCK_FL_VARS)
     515             : {
     516           0 :         _mtx_enter(mtxp LOCK_FL_ARGS);
     517           0 : }
     518             : static inline void
     519           0 : _spin_unlock_irqrestore(struct mutex *mtxp, __unused unsigned long flags
     520             :     LOCK_FL_VARS)
     521             : {
     522           0 :         _mtx_leave(mtxp LOCK_FL_ARGS);
     523           0 : }
     524             : #define spin_lock_irqsave(m, fl)        \
     525             :         _spin_lock_irqsave(m, fl LOCK_FILE_LINE)
     526             : #define spin_unlock_irqrestore(m, fl)   \
     527             :         _spin_unlock_irqrestore(m, fl LOCK_FILE_LINE)
     528             : 
     529             : 
     530             : #define spin_lock(mtxp)                 mtx_enter(mtxp)
     531             : #define spin_unlock(mtxp)               mtx_leave(mtxp)
     532             : #define spin_lock_irq(mtxp)             mtx_enter(mtxp)
     533             : #define spin_unlock_irq(mtxp)           mtx_leave(mtxp)
     534             : #define assert_spin_locked(mtxp)        MUTEX_ASSERT_LOCKED(mtxp)
     535             : #define mutex_lock_interruptible(rwl)   -rw_enter(rwl, RW_WRITE | RW_INTR)
     536             : #define mutex_lock(rwl)                 rw_enter_write(rwl)
     537             : #define mutex_lock_nest_lock(rwl, sub)  rw_enter_write(rwl)
     538             : #define mutex_trylock(rwl)              (rw_enter(rwl, RW_WRITE | RW_NOSLEEP) == 0)
     539             : #define mutex_unlock(rwl)               rw_exit_write(rwl)
     540             : #define mutex_is_locked(rwl)            (rw_status(rwl) == RW_WRITE)
     541             : #define mutex_destroy(rwl)
     542             : #define down_read(rwl)                  rw_enter_read(rwl)
     543             : #define down_read_trylock(rwl)          (rw_enter(rwl, RW_READ | RW_NOSLEEP) == 0)
     544             : #define up_read(rwl)                    rw_exit_read(rwl)
     545             : #define down_write(rwl)                 rw_enter_write(rwl)
     546             : #define up_write(rwl)                   rw_exit_write(rwl)
     547             : #define read_lock(rwl)                  rw_enter_read(rwl)
     548             : #define read_unlock(rwl)                rw_exit_read(rwl)
     549             : #define write_lock(rwl)                 rw_enter_write(rwl)
     550             : #define write_unlock(rwl)               rw_exit_write(rwl)
     551             : 
     552             : #define might_lock(lock)
     553             : #define lockdep_assert_held(lock)       do { (void)(lock); } while(0)
     554             : 
     555             : #define IRQF_SHARED     0
     556             : 
     557             : #define local_irq_save(x)               (x) = splhigh()
     558             : #define local_irq_restore(x)            splx((x))
     559             : 
     560             : #define request_irq(irq, hdlr, flags, name, dev)        (0)
     561             : #define free_irq(irq, dev)
     562             : #define synchronize_irq(x)
     563             : 
     564             : typedef struct wait_queue wait_queue_t;
     565             : struct wait_queue {
     566             :         unsigned int flags;
     567             :         void *private;
     568             :         int (*func)(wait_queue_t *, unsigned, int, void *);
     569             : };
     570             : 
     571             : extern struct mutex sch_mtx;
     572             : extern void *sch_ident;
     573             : extern int sch_priority;
     574             : 
     575             : struct wait_queue_head {
     576             :         struct mutex lock;
     577             :         unsigned int count;
     578             :         struct wait_queue *_wq;
     579             : };
     580             : typedef struct wait_queue_head wait_queue_head_t;
     581             : 
     582             : #define MAX_SCHEDULE_TIMEOUT (INT32_MAX)
     583             : 
     584             : static inline void
     585           0 : init_waitqueue_head(wait_queue_head_t *wq)
     586             : {
     587           0 :         mtx_init(&wq->lock, IPL_TTY);
     588           0 :         wq->count = 0;
     589           0 :         wq->_wq = NULL;
     590           0 : }
     591             : 
     592             : static inline void
     593           0 : __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
     594             : {
     595           0 :         head->_wq = new;
     596           0 : }
     597             : 
     598             : static inline void
     599           0 : __remove_wait_queue(wait_queue_head_t *head, wait_queue_t *old)
     600             : {
     601           0 :         head->_wq = NULL;
     602           0 : }
     603             : 
     604             : #define __wait_event_intr_timeout(wq, condition, timo, prio)            \
     605             : ({                                                                      \
     606             :         long ret = timo;                                                \
     607             :         do {                                                            \
     608             :                 int deadline, __error;                                  \
     609             :                                                                         \
     610             :                 KASSERT(!cold);                                         \
     611             :                                                                         \
     612             :                 mtx_enter(&sch_mtx);                                        \
     613             :                 atomic_inc_int(&(wq).count);                                \
     614             :                 deadline = ticks + ret;                                 \
     615             :                 __error = msleep(&wq, &sch_mtx, prio, "drmweti", ret);        \
     616             :                 ret = deadline - ticks;                                 \
     617             :                 atomic_dec_int(&(wq).count);                                \
     618             :                 if (__error == ERESTART || __error == EINTR) {          \
     619             :                         ret = -ERESTARTSYS;                             \
     620             :                         mtx_leave(&sch_mtx);                                \
     621             :                         break;                                          \
     622             :                 }                                                       \
     623             :                 if (timo && (ret <= 0 || __error == EWOULDBLOCK)) {  \
     624             :                         mtx_leave(&sch_mtx);                                \
     625             :                         ret = ((condition)) ? 1 : 0;                    \
     626             :                         break;                                          \
     627             :                 }                                                       \
     628             :                 mtx_leave(&sch_mtx);                                        \
     629             :         } while (ret > 0 && !(condition));                           \
     630             :         ret;                                                            \
     631             : })
     632             : 
     633             : /*
     634             :  * Sleep until `condition' gets true.
     635             :  */
     636             : #define wait_event(wq, condition)               \
     637             : do {                                            \
     638             :         if (!(condition))                       \
     639             :                 __wait_event_intr_timeout(wq, condition, 0, 0); \
     640             : } while (0)
     641             : 
     642             : #define wait_event_interruptible_locked(wq, condition)          \
     643             : ({                                              \
     644             :         int __ret = 0;                          \
     645             :         if (!(condition))                       \
     646             :                 __ret = __wait_event_intr_timeout(wq, condition, 0, PCATCH); \
     647             :         __ret;                                  \
     648             : })
     649             : 
     650             : /*
     651             :  * Sleep until `condition' gets true or `timo' expires.
     652             :  *
     653             :  * Returns 0 if `condition' is still false when `timo' expires or
     654             :  * the remaining (>=1) ticks otherwise.
     655             :  */
     656             : #define wait_event_timeout(wq, condition, timo) \
     657             : ({                                              \
     658             :         long __ret = timo;                      \
     659             :         if (!(condition))                       \
     660             :                 __ret = __wait_event_intr_timeout(wq, condition, timo, 0); \
     661             :         __ret;                                  \
     662             : })
     663             : 
     664             : /*
     665             :  * Sleep until `condition' gets true, `timo' expires or the process
     666             :  * receives a signal.
     667             :  *
     668             :  * Returns -ERESTARTSYS if interrupted by a signal.
     669             :  * Returns 0 if `condition' is still false when `timo' expires or
     670             :  * the remaining (>=1) ticks otherwise.
     671             :  */
     672             : #define wait_event_interruptible_timeout(wq, condition, timo) \
     673             : ({                                              \
     674             :         long __ret = timo;                      \
     675             :         if (!(condition))                       \
     676             :                 __ret = __wait_event_intr_timeout(wq, condition, timo, PCATCH);\
     677             :         __ret;                                  \
     678             : })
     679             : 
     680             : static inline void
     681           0 : _wake_up(wait_queue_head_t *wq LOCK_FL_VARS)
     682             : {
     683           0 :         _mtx_enter(&wq->lock LOCK_FL_ARGS);
     684           0 :         if (wq->_wq != NULL && wq->_wq->func != NULL)
     685           0 :                 wq->_wq->func(wq->_wq, 0, wq->_wq->flags, NULL);
     686             :         else {
     687           0 :                 mtx_enter(&sch_mtx);
     688           0 :                 wakeup(wq);
     689           0 :                 mtx_leave(&sch_mtx);
     690             :         }
     691           0 :         _mtx_leave(&wq->lock LOCK_FL_ARGS);
     692           0 : }
     693             : 
     694             : #define wake_up_process(task)                   \
     695             : do {                                            \
     696             :         mtx_enter(&sch_mtx);                        \
     697             :         wakeup(task);                           \
     698             :         mtx_leave(&sch_mtx);                        \
     699             : } while (0)
     700             : 
     701             : #define wake_up(wq)                     _wake_up(wq LOCK_FILE_LINE)
     702             : #define wake_up_all(wq)                 _wake_up(wq LOCK_FILE_LINE)
     703             : 
     704             : static inline void
     705           0 : wake_up_all_locked(wait_queue_head_t *wq)
     706             : {
     707           0 :         if (wq->_wq != NULL && wq->_wq->func != NULL)
     708           0 :                 wq->_wq->func(wq->_wq, 0, wq->_wq->flags, NULL);
     709             :         else {
     710           0 :                 mtx_enter(&sch_mtx);
     711           0 :                 wakeup(wq);
     712           0 :                 mtx_leave(&sch_mtx);
     713             :         }
     714           0 : }
     715             : 
     716             : #define wake_up_interruptible(wq)       _wake_up(wq LOCK_FILE_LINE)
     717             : #define waitqueue_active(wq)            ((wq)->count > 0)
     718             : 
     719             : struct completion {
     720             :         u_int done;
     721             :         wait_queue_head_t wait;
     722             : };
     723             : 
     724             : #define INIT_COMPLETION(x) ((x).done = 0)
     725             : 
     726             : static inline void
     727             : init_completion(struct completion *x)
     728             : {
     729             :         x->done = 0;
     730             :         mtx_init(&x->wait.lock, IPL_NONE);
     731             : }
     732             : 
     733             : static inline u_long
     734             : _wait_for_completion_interruptible_timeout(struct completion *x, u_long timo
     735             :     LOCK_FL_VARS)
     736             : {
     737             :         int ret;
     738             : 
     739             :         _mtx_enter(&x->wait.lock LOCK_FL_ARGS);
     740             :         while (x->done == 0) {
     741             :                 ret = msleep(x, &x->wait.lock, PCATCH, "wfcit", timo);
     742             :                 if (ret) {
     743             :                         _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
     744             :                         return (ret == EWOULDBLOCK) ? 0 : -ret;
     745             :                 }
     746             :         }
     747             : 
     748             :         return 1;
     749             : }
     750             : #define wait_for_completion_interruptible_timeout(x, timo)      \
     751             :         _wait_for_completion_interruptible_timeout(x, timo LOCK_FILE_LINE)
     752             : 
     753             : static inline void
     754             : _complete_all(struct completion *x LOCK_FL_VARS)
     755             : {
     756             :         _mtx_enter(&x->wait.lock LOCK_FL_ARGS);
     757             :         x->done = 1;
     758             :         _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
     759             :         wakeup(x);
     760             : }
     761             : #define complete_all(x) _complete_all(x LOCK_FILE_LINE)
     762             : 
     763             : struct workqueue_struct;
     764             : 
     765             : #define system_wq (struct workqueue_struct *)systq
     766             : #define system_long_wq (struct workqueue_struct *)systq
     767             : 
     768             : static inline struct workqueue_struct *
     769           0 : alloc_ordered_workqueue(const char *name, int flags)
     770             : {
     771           0 :         struct taskq *tq = taskq_create(name, 1, IPL_TTY, 0);
     772           0 :         return (struct workqueue_struct *)tq;
     773             : }
     774             : 
     775             : static inline struct workqueue_struct *
     776           0 : create_singlethread_workqueue(const char *name)
     777             : {
     778           0 :         struct taskq *tq = taskq_create(name, 1, IPL_TTY, 0);
     779           0 :         return (struct workqueue_struct *)tq;
     780             : }
     781             : 
     782             : static inline void
     783           0 : destroy_workqueue(struct workqueue_struct *wq)
     784             : {
     785           0 :         taskq_destroy((struct taskq *)wq);
     786           0 : }
     787             : 
     788             : struct work_struct {
     789             :         struct task task;
     790             :         struct taskq *tq;
     791             : };
     792             : 
     793             : typedef void (*work_func_t)(struct work_struct *);
     794             : 
     795             : static inline void
     796           0 : INIT_WORK(struct work_struct *work, work_func_t func)
     797             : {
     798           0 :         work->tq = systq;
     799           0 :         task_set(&work->task, (void (*)(void *))func, work);
     800           0 : }
     801             : 
     802             : #define INIT_WORK_ONSTACK(x, y) INIT_WORK((x), (y))
     803             : 
     804             : static inline bool
     805           0 : queue_work(struct workqueue_struct *wq, struct work_struct *work)
     806             : {
     807           0 :         work->tq = (struct taskq *)wq;
     808           0 :         return task_add(work->tq, &work->task);
     809             : }
     810             : 
     811             : static inline void
     812           0 : cancel_work_sync(struct work_struct *work)
     813             : {
     814           0 :         task_del(work->tq, &work->task);
     815           0 : }
     816             : 
     817             : struct delayed_work {
     818             :         struct work_struct work;
     819             :         struct timeout to;
     820             :         struct taskq *tq;
     821             : };
     822             : 
     823             : #define system_power_efficient_wq ((struct workqueue_struct *)systq)
     824             : 
     825             : static inline struct delayed_work *
     826           0 : to_delayed_work(struct work_struct *work)
     827             : {
     828           0 :         return container_of(work, struct delayed_work, work);
     829             : }
     830             : 
     831             : static void
     832           0 : __delayed_work_tick(void *arg)
     833             : {
     834           0 :         struct delayed_work *dwork = arg;
     835             : 
     836           0 :         task_add(dwork->tq, &dwork->work.task);
     837           0 : }
     838             : 
     839             : static inline void
     840           0 : INIT_DELAYED_WORK(struct delayed_work *dwork, work_func_t func)
     841             : {
     842           0 :         INIT_WORK(&dwork->work, func);
     843           0 :         timeout_set(&dwork->to, __delayed_work_tick, &dwork->work);
     844           0 : }
     845             : 
     846             : static inline bool
     847           0 : schedule_work(struct work_struct *work)
     848             : {
     849           0 :         return task_add(work->tq, &work->task);
     850             : }
     851             : 
     852             : static inline bool
     853           0 : schedule_delayed_work(struct delayed_work *dwork, int jiffies)
     854             : {
     855           0 :         dwork->tq = systq;
     856           0 :         return timeout_add(&dwork->to, jiffies);
     857             : }
     858             : 
     859             : static inline bool
     860           0 : queue_delayed_work(struct workqueue_struct *wq,
     861             :     struct delayed_work *dwork, int jiffies)
     862             : {
     863           0 :         dwork->tq = (struct taskq *)wq;
     864           0 :         return timeout_add(&dwork->to, jiffies);
     865             : }
     866             : 
     867             : static inline bool
     868           0 : mod_delayed_work(struct workqueue_struct *wq,
     869             :     struct delayed_work *dwork, int jiffies)
     870             : {
     871           0 :         dwork->tq = (struct taskq *)wq;
     872           0 :         return (timeout_add(&dwork->to, jiffies) == 0);
     873             : }
     874             : 
     875             : static inline bool
     876           0 : cancel_delayed_work(struct delayed_work *dwork)
     877             : {
     878           0 :         if (timeout_del(&dwork->to))
     879           0 :                 return true;
     880           0 :         return task_del(dwork->tq, &dwork->work.task);
     881           0 : }
     882             : 
     883             : static inline bool
     884           0 : cancel_delayed_work_sync(struct delayed_work *dwork)
     885             : {
     886           0 :         if (timeout_del(&dwork->to))
     887           0 :                 return true;
     888           0 :         return task_del(dwork->tq, &dwork->work.task);
     889           0 : }
     890             : 
     891             : void flush_workqueue(struct workqueue_struct *);
     892             : void flush_work(struct work_struct *);
     893             : void flush_delayed_work(struct delayed_work *);
     894             : #define flush_scheduled_work()  flush_workqueue(system_wq)
     895             : 
     896             : #define destroy_work_on_stack(x)
     897             : 
     898             : typedef void *async_cookie_t;
     899             : #define async_schedule(func, data)      (func)((data), NULL)
     900             : 
     901             : #define local_irq_disable()     intr_disable()
     902             : #define local_irq_enable()      intr_enable()
     903             : 
     904             : #define setup_timer(x, y, z)    timeout_set((x), (void (*)(void *))(y), (void *)(z))
     905             : #define mod_timer(x, y)         timeout_add((x), (y - jiffies))
     906             : #define mod_timer_pinned(x, y)  timeout_add((x), (y - jiffies))
     907             : #define del_timer_sync(x)       timeout_del((x))
     908             : #define timer_pending(x)        timeout_pending((x))
     909             : 
     910             : #define cond_resched()          sched_pause(yield)
     911             : #define drm_need_resched() \
     912             :     (curcpu()->ci_schedstate.spc_schedflags & SPCF_SHOULDYIELD)
     913             : 
     914             : #define TASK_UNINTERRUPTIBLE    0
     915             : #define TASK_INTERRUPTIBLE      PCATCH
     916             : #define TASK_RUNNING            -1
     917             : 
     918             : #define signal_pending_state(x, y) CURSIG(curproc)
     919             : #define signal_pending(y) CURSIG(curproc)
     920             : 
     921             : #define NSEC_PER_USEC   1000L
     922             : #define NSEC_PER_MSEC   1000000L
     923             : #define NSEC_PER_SEC    1000000000L
     924             : #define KHZ2PICOS(a)    (1000000000UL/(a))
     925             : 
     926             : extern struct timespec ns_to_timespec(const int64_t);
     927             : extern int64_t timeval_to_ns(const struct timeval *);
     928             : extern int64_t timeval_to_us(const struct timeval *);
     929             : extern struct timeval ns_to_timeval(const int64_t);
     930             : 
     931             : static inline struct timespec
     932             : timespec_sub(struct timespec t1, struct timespec t2)
     933             : {
     934             :         struct timespec diff;
     935             : 
     936             :         timespecsub(&t1, &t2, &diff);
     937             :         return diff;
     938             : }
     939             : 
     940             : #define time_in_range(x, min, max) ((x) >= (min) && (x) <= (max))
     941             : 
     942             : extern volatile unsigned long jiffies;
     943             : #define jiffies_64 jiffies /* XXX */
     944             : #undef HZ
     945             : #define HZ      hz
     946             : 
     947             : #define MAX_JIFFY_OFFSET        ((INT_MAX >> 1) - 1)
     948             : 
     949             : static inline unsigned long
     950             : round_jiffies_up(unsigned long j)
     951             : {
     952             :         return roundup(j, hz);
     953             : }
     954             : 
     955             : static inline unsigned long
     956           0 : round_jiffies_up_relative(unsigned long j)
     957             : {
     958           0 :         return roundup(j, hz);
     959             : }
     960             : 
     961             : #define jiffies_to_msecs(x)     (((uint64_t)(x)) * 1000 / hz)
     962             : #define jiffies_to_usecs(x)     (((uint64_t)(x)) * 1000000 / hz)
     963             : #define msecs_to_jiffies(x)     (((uint64_t)(x)) * hz / 1000)
     964             : #define nsecs_to_jiffies64(x)   (((uint64_t)(x)) * hz / 1000000000)
     965             : #define get_jiffies_64()        jiffies
     966             : #define time_after(a,b)         ((long)(b) - (long)(a) < 0)
     967             : #define time_after_eq(a,b)      ((long)(b) - (long)(a) <= 0)
     968             : #define get_seconds()           time_second
     969             : #define getrawmonotonic(x)      nanouptime(x)
     970             : 
     971             : static inline void
     972             : set_normalized_timespec(struct timespec *ts, time_t sec, int64_t nsec)
     973             : {
     974             :         while (nsec > NSEC_PER_SEC) {
     975             :                 nsec -= NSEC_PER_SEC;
     976             :                 sec++;
     977             :         }
     978             : 
     979             :         ts->tv_sec = sec;
     980             :         ts->tv_nsec = nsec;
     981             : }
     982             : 
     983             : static inline int64_t
     984             : timespec_to_ns(const struct timespec *ts)
     985             : {
     986             :         return ((ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec);
     987             : }
     988             : 
     989             : static inline unsigned long
     990             : timespec_to_jiffies(const struct timespec *ts)
     991             : {
     992             :         long long to_ticks;
     993             : 
     994             :         to_ticks = (long long)hz * ts->tv_sec + ts->tv_nsec / (tick * 1000);
     995             :         if (to_ticks > INT_MAX)
     996             :                 to_ticks = INT_MAX;
     997             : 
     998             :         return ((int)to_ticks);
     999             : }
    1000             : 
    1001             : static inline int
    1002             : timespec_valid(const struct timespec *ts)
    1003             : {
    1004             :         if (ts->tv_sec < 0 || ts->tv_sec > 100000000 ||
    1005             :             ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000)
    1006             :                 return (0);
    1007             :         return (1);
    1008             : }
    1009             : 
    1010             : typedef struct timeval ktime_t;
    1011             : 
    1012             : static inline struct timeval
    1013           0 : ktime_get(void)
    1014             : {
    1015           0 :         struct timeval tv;
    1016             :         
    1017           0 :         getmicrouptime(&tv);
    1018           0 :         return tv;
    1019           0 : }
    1020             : 
    1021             : static inline struct timeval
    1022             : ktime_get_monotonic_offset(void)
    1023             : {
    1024             :         struct timeval tv = {0, 0};
    1025             :         return tv;
    1026             : }
    1027             : 
    1028             : static inline int64_t
    1029           0 : ktime_to_us(struct timeval tv)
    1030             : {
    1031           0 :         return timeval_to_us(&tv);
    1032             : }
    1033             : 
    1034             : static inline int64_t
    1035           0 : ktime_to_ns(struct timeval tv)
    1036             : {
    1037           0 :         return timeval_to_ns(&tv);
    1038             : }
    1039             : 
    1040             : static inline int64_t
    1041           0 : ktime_get_raw_ns(void)
    1042             : {
    1043           0 :         return ktime_to_ns(ktime_get());
    1044             : }
    1045             : 
    1046             : #define ktime_to_timeval(tv) (tv)
    1047             : 
    1048             : static inline struct timeval
    1049           0 : ktime_sub(struct timeval a, struct timeval b)
    1050             : {
    1051             :         struct timeval res;
    1052           0 :         timersub(&a, &b, &res);
    1053             :         return res;
    1054           0 : }
    1055             : 
    1056             : static inline struct timeval
    1057           0 : ktime_add_ns(struct timeval tv, int64_t ns)
    1058             : {
    1059           0 :         return ns_to_timeval(timeval_to_ns(&tv) + ns);
    1060             : }
    1061             : 
    1062             : static inline struct timeval
    1063           0 : ktime_sub_ns(struct timeval tv, int64_t ns)
    1064             : {
    1065           0 :         return ns_to_timeval(timeval_to_ns(&tv) - ns);
    1066             : }
    1067             : 
    1068             : static inline int64_t
    1069           0 : ktime_us_delta(struct timeval a, struct timeval b)
    1070             : {
    1071           0 :         return ktime_to_us(ktime_sub(a, b));
    1072             : }
    1073             : 
    1074             : #define ktime_mono_to_real(x) (x)
    1075             : #define ktime_get_real() ktime_get()
    1076             : 
    1077             : #define do_gettimeofday(tv) getmicrouptime(tv)
    1078             : 
    1079             : #define GFP_ATOMIC      M_NOWAIT
    1080             : #define GFP_NOWAIT      M_NOWAIT
    1081             : #define GFP_KERNEL      (M_WAITOK | M_CANFAIL)
    1082             : #define GFP_USER        (M_WAITOK | M_CANFAIL)
    1083             : #define GFP_TEMPORARY   (M_WAITOK | M_CANFAIL)
    1084             : #define GFP_HIGHUSER    0
    1085             : #define GFP_DMA32       0
    1086             : #define __GFP_NOWARN    0
    1087             : #define __GFP_NORETRY   0
    1088             : #define __GFP_ZERO      M_ZERO
    1089             : 
    1090             : static inline void *
    1091           0 : kmalloc(size_t size, int flags)
    1092             : {
    1093           0 :         return malloc(size, M_DRM, flags);
    1094             : }
    1095             : 
    1096             : static inline void *
    1097           0 : kmalloc_array(size_t n, size_t size, int flags)
    1098             : {
    1099           0 :         if (n == 0 || SIZE_MAX / n < size)
    1100           0 :                 return NULL;
    1101           0 :         return malloc(n * size, M_DRM, flags);
    1102           0 : }
    1103             : 
    1104             : static inline void *
    1105           0 : kcalloc(size_t n, size_t size, int flags)
    1106             : {
    1107           0 :         if (n == 0 || SIZE_MAX / n < size)
    1108           0 :                 return NULL;
    1109           0 :         return malloc(n * size, M_DRM, flags | M_ZERO);
    1110           0 : }
    1111             : 
    1112             : static inline void *
    1113           0 : kzalloc(size_t size, int flags)
    1114             : {
    1115           0 :         return malloc(size, M_DRM, flags | M_ZERO);
    1116             : }
    1117             : 
    1118             : static inline void
    1119           0 : kfree(const void *objp)
    1120             : {
    1121           0 :         free((void *)objp, M_DRM, 0);
    1122           0 : }
    1123             : 
    1124             : static inline void *
    1125           0 : kmemdup(const void *src, size_t len, int flags)
    1126             : {
    1127           0 :         void *p = malloc(len, M_DRM, flags);
    1128           0 :         if (p)
    1129           0 :                 memcpy(p, src, len);
    1130           0 :         return (p);
    1131             : }
    1132             : 
    1133             : static inline char *
    1134           0 : kasprintf(int flags, const char *fmt, ...)
    1135             : {
    1136             :         char *buf;
    1137             :         size_t len;
    1138           0 :         va_list ap;
    1139             : 
    1140           0 :         va_start(ap, fmt);
    1141           0 :         len = vsnprintf(NULL, 0, fmt, ap);
    1142           0 :         va_end(ap);
    1143             : 
    1144           0 :         buf = kmalloc(len, flags);
    1145           0 :         if (buf) {
    1146           0 :                 va_start(ap, fmt);
    1147           0 :                 vsnprintf(buf, len, fmt, ap);
    1148           0 :                 va_end(ap);
    1149           0 :         }
    1150             : 
    1151           0 :         return buf;
    1152           0 : }
    1153             : 
    1154             : static inline void *
    1155           0 : vmalloc(unsigned long size)
    1156             : {
    1157           0 :         return malloc(size, M_DRM, M_WAITOK | M_CANFAIL);
    1158             : }
    1159             : 
    1160             : static inline void *
    1161           0 : vzalloc(unsigned long size)
    1162             : {
    1163           0 :         return malloc(size, M_DRM, M_WAITOK | M_CANFAIL | M_ZERO);
    1164             : }
    1165             : 
    1166             : static inline void
    1167           0 : vfree(void *objp)
    1168             : {
    1169           0 :         free(objp, M_DRM, 0);
    1170           0 : }
    1171             : 
    1172             : struct kref {
    1173             :         uint32_t refcount;
    1174             : };
    1175             : 
    1176             : static inline void
    1177           0 : kref_init(struct kref *ref)
    1178             : {
    1179           0 :         ref->refcount = 1;
    1180           0 : }
    1181             : 
    1182             : static inline void
    1183           0 : kref_get(struct kref *ref)
    1184             : {
    1185           0 :         atomic_inc_int(&ref->refcount);
    1186           0 : }
    1187             : 
    1188             : static inline int
    1189           0 : kref_get_unless_zero(struct kref *ref)
    1190             : {
    1191           0 :         if (ref->refcount != 0) {
    1192           0 :                 atomic_inc_int(&ref->refcount);
    1193           0 :                 return (1);
    1194             :         } else {
    1195           0 :                 return (0);
    1196             :         }
    1197           0 : }
    1198             : 
    1199             : static inline void
    1200           0 : kref_put(struct kref *ref, void (*release)(struct kref *ref))
    1201             : {
    1202           0 :         if (atomic_dec_int_nv(&ref->refcount) == 0)
    1203           0 :                 release(ref);
    1204           0 : }
    1205             : 
    1206             : static inline void
    1207           0 : kref_sub(struct kref *ref, unsigned int v, void (*release)(struct kref *ref))
    1208             : {
    1209           0 :         if (atomic_sub_int_nv(&ref->refcount, v) == 0)
    1210           0 :                 release(ref);
    1211           0 : }
    1212             : 
    1213             : static inline int
    1214           0 : kref_put_mutex(struct kref *kref, void (*release)(struct kref *kref),
    1215             :     struct rwlock *lock)
    1216             : {
    1217           0 :         if (!atomic_add_unless(&kref->refcount, -1, 1)) {
    1218           0 :                 rw_enter_write(lock);
    1219           0 :                 if (likely(atomic_dec_and_test(&kref->refcount))) {
    1220           0 :                         release(kref);
    1221           0 :                         return 1;
    1222             :                 }
    1223           0 :                 rw_exit_write(lock);
    1224           0 :                 return 0;
    1225             :         }
    1226             : 
    1227           0 :         return 0;
    1228           0 : }
    1229             : 
    1230             : struct kobject {
    1231             :         struct kref kref;
    1232             :         struct kobj_type *type;
    1233             : };
    1234             : 
    1235             : struct kobj_type {
    1236             :         void (*release)(struct kobject *);
    1237             : };
    1238             : 
    1239             : static inline void
    1240           0 : kobject_init(struct kobject *obj, struct kobj_type *type)
    1241             : {
    1242           0 :         kref_init(&obj->kref);
    1243           0 :         obj->type = type;
    1244           0 : }
    1245             : 
    1246             : static inline int
    1247           0 : kobject_init_and_add(struct kobject *obj, struct kobj_type *type,
    1248             :     struct kobject *parent, const char *fmt, ...)
    1249             : {
    1250           0 :         kobject_init(obj, type);
    1251           0 :         return (0);
    1252             : }
    1253             : 
    1254             : static inline struct kobject *
    1255             : kobject_get(struct kobject *obj)
    1256             : {
    1257             :         if (obj != NULL)
    1258             :                 kref_get(&obj->kref);
    1259             :         return (obj);
    1260             : }
    1261             : 
    1262             : static inline void
    1263           0 : kobject_release(struct kref *ref)
    1264             : {
    1265           0 :         struct kobject *obj = container_of(ref, struct kobject, kref);
    1266           0 :         if (obj->type && obj->type->release)
    1267           0 :                 obj->type->release(obj);
    1268           0 : }
    1269             : 
    1270             : static inline void
    1271           0 : kobject_put(struct kobject *obj)
    1272             : {
    1273           0 :         if (obj != NULL)
    1274           0 :                 kref_put(&obj->kref, kobject_release);
    1275           0 : }
    1276             : 
    1277             : static inline void
    1278           0 : kobject_del(struct kobject *obj)
    1279             : {
    1280           0 : }
    1281             : 
    1282             : #define DEFINE_WAIT(wait)               wait_queue_head_t *wait = NULL
    1283             : 
    1284             : static inline void
    1285           0 : prepare_to_wait(wait_queue_head_t *wq, wait_queue_head_t **wait, int state)
    1286             : {
    1287           0 :         if (*wait == NULL) {
    1288           0 :                 mtx_enter(&sch_mtx);
    1289           0 :                 *wait = wq;
    1290           0 :         }
    1291           0 :         MUTEX_ASSERT_LOCKED(&sch_mtx);
    1292           0 :         sch_ident = wq;
    1293           0 :         sch_priority = state;
    1294           0 : }
    1295             : 
    1296             : static inline void
    1297           0 : finish_wait(wait_queue_head_t *wq, wait_queue_head_t **wait)
    1298             : {
    1299           0 :         if (*wait) {
    1300           0 :                 MUTEX_ASSERT_LOCKED(&sch_mtx);
    1301           0 :                 sch_ident = NULL;
    1302           0 :                 mtx_leave(&sch_mtx);
    1303           0 :         }
    1304           0 : }
    1305             : 
    1306             : static inline void
    1307           0 : set_current_state(int state)
    1308             : {
    1309           0 :         if (sch_ident != curproc)
    1310           0 :                 mtx_enter(&sch_mtx);
    1311           0 :         MUTEX_ASSERT_LOCKED(&sch_mtx);
    1312           0 :         sch_ident = curproc;
    1313           0 :         sch_priority = state;
    1314           0 : }
    1315             : 
    1316             : static inline void
    1317           0 : __set_current_state(int state)
    1318             : {
    1319           0 :         KASSERT(state == TASK_RUNNING);
    1320           0 :         if (sch_ident == curproc) {
    1321           0 :                 MUTEX_ASSERT_LOCKED(&sch_mtx);
    1322           0 :                 sch_ident = NULL;
    1323           0 :                 mtx_leave(&sch_mtx);
    1324           0 :         }
    1325           0 : }
    1326             : 
    1327             : static inline long
    1328           0 : schedule_timeout(long timeout)
    1329             : {
    1330             :         int err;
    1331             :         long deadline;
    1332             : 
    1333           0 :         if (cold) {
    1334           0 :                 delay((timeout * 1000000) / hz);
    1335           0 :                 return 0;
    1336             :         }
    1337             : 
    1338           0 :         if (timeout == MAX_SCHEDULE_TIMEOUT) {
    1339           0 :                 err = msleep(sch_ident, &sch_mtx, sch_priority, "schto", 0);
    1340           0 :                 sch_ident = curproc;
    1341           0 :                 return timeout;
    1342             :         }
    1343             : 
    1344           0 :         deadline = ticks + timeout;
    1345           0 :         err = msleep(sch_ident, &sch_mtx, sch_priority, "schto", timeout);
    1346           0 :         timeout = deadline - ticks;
    1347           0 :         if (timeout < 0)
    1348             :                 timeout = 0;
    1349           0 :         sch_ident = curproc;
    1350           0 :         return timeout;
    1351           0 : }
    1352             : 
    1353             : struct seq_file;
    1354             : 
    1355             : static inline void
    1356           0 : seq_printf(struct seq_file *m, const char *fmt, ...) {};
    1357             : 
    1358             : #define preempt_enable()
    1359             : #define preempt_disable()
    1360             : 
    1361             : #define FENCE_TRACE(fence, fmt, args...) do {} while(0)
    1362             : 
    1363             : struct fence {
    1364             :         struct kref refcount;
    1365             :         const struct fence_ops *ops;
    1366             :         unsigned long flags;
    1367             :         unsigned int context;
    1368             :         unsigned int seqno;
    1369             :         struct mutex *lock;
    1370             :         struct list_head cb_list;
    1371             : };
    1372             : 
    1373             : enum fence_flag_bits {
    1374             :         FENCE_FLAG_SIGNALED_BIT,
    1375             :         FENCE_FLAG_ENABLE_SIGNAL_BIT,
    1376             :         FENCE_FLAG_USER_BITS,
    1377             : };
    1378             : 
    1379             : struct fence_ops {
    1380             :         const char * (*get_driver_name)(struct fence *);
    1381             :         const char * (*get_timeline_name)(struct fence *);
    1382             :         bool (*enable_signaling)(struct fence *);
    1383             :         bool (*signaled)(struct fence *);
    1384             :         long (*wait)(struct fence *, bool, long);
    1385             :         void (*release)(struct fence *);
    1386             : };
    1387             : 
    1388             : struct fence_cb;
    1389             : typedef void (*fence_func_t)(struct fence *fence, struct fence_cb *cb);
    1390             : 
    1391             : struct fence_cb {
    1392             :         struct list_head node;
    1393             :         fence_func_t func;
    1394             : };
    1395             : 
    1396             : unsigned int fence_context_alloc(unsigned int);
    1397             : 
    1398             : static inline struct fence *
    1399           0 : fence_get(struct fence *fence)
    1400             : {
    1401           0 :         if (fence)
    1402           0 :                 kref_get(&fence->refcount);
    1403           0 :         return fence;
    1404             : }
    1405             : 
    1406             : static inline struct fence *
    1407           0 : fence_get_rcu(struct fence *fence)
    1408             : {
    1409           0 :         if (fence)
    1410           0 :                 kref_get(&fence->refcount);
    1411           0 :         return fence;
    1412             : }
    1413             : 
    1414             : static inline void
    1415           0 : fence_release(struct kref *ref)
    1416             : {
    1417           0 :         struct fence *fence = container_of(ref, struct fence, refcount);
    1418           0 :         if (fence->ops && fence->ops->release)
    1419           0 :                 fence->ops->release(fence);
    1420             :         else
    1421           0 :                 free(fence, M_DRM, 0);
    1422           0 : }
    1423             : 
    1424             : static inline void
    1425           0 : fence_put(struct fence *fence)
    1426             : {
    1427           0 :         if (fence)
    1428           0 :                 kref_put(&fence->refcount, fence_release);
    1429           0 : }
    1430             : 
    1431             : static inline int
    1432           0 : fence_signal(struct fence *fence)
    1433             : {
    1434           0 :         if (fence == NULL)
    1435           0 :                 return -EINVAL;
    1436             : 
    1437           0 :         if (test_and_set_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags))
    1438           0 :                 return -EINVAL;
    1439             : 
    1440           0 :         if (test_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) {
    1441             :                 struct fence_cb *cur, *tmp;
    1442             : 
    1443           0 :                 mtx_enter(fence->lock);
    1444           0 :                 list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
    1445           0 :                         list_del_init(&cur->node);
    1446           0 :                         cur->func(fence, cur);
    1447             :                 }
    1448           0 :                 mtx_leave(fence->lock);
    1449           0 :         }
    1450             : 
    1451           0 :         return 0;
    1452           0 : }
    1453             : 
    1454             : static inline int
    1455           0 : fence_signal_locked(struct fence *fence)
    1456             : {
    1457             :         struct fence_cb *cur, *tmp;
    1458             : 
    1459           0 :         if (fence == NULL)
    1460           0 :                 return -EINVAL;
    1461             : 
    1462           0 :         if (test_and_set_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags))
    1463           0 :                 return -EINVAL;
    1464             : 
    1465           0 :         list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
    1466           0 :                 list_del_init(&cur->node);
    1467           0 :                 cur->func(fence, cur);
    1468             :         }
    1469             : 
    1470           0 :         return 0;
    1471           0 : }
    1472             : 
    1473             : static inline bool
    1474           0 : fence_is_signaled(struct fence *fence)
    1475             : {
    1476           0 :         if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags))
    1477           0 :                 return true;
    1478             : 
    1479           0 :         if (fence->ops->signaled && fence->ops->signaled(fence)) {
    1480           0 :                 fence_signal(fence);
    1481           0 :                 return true;
    1482             :         }
    1483             : 
    1484           0 :         return false;
    1485           0 : }
    1486             : 
    1487             : static inline long
    1488           0 : fence_wait_timeout(struct fence *fence, bool intr, signed long timeout)
    1489             : {
    1490           0 :         if (timeout < 0)
    1491           0 :                 return -EINVAL;
    1492             : 
    1493           0 :         if (timeout == 0)
    1494           0 :                 return fence_is_signaled(fence);
    1495             : 
    1496           0 :         return fence->ops->wait(fence, intr, timeout);
    1497           0 : }
    1498             : 
    1499             : static inline long
    1500           0 : fence_wait(struct fence *fence, bool intr)
    1501             : {
    1502           0 :         return fence_wait_timeout(fence, intr, MAX_SCHEDULE_TIMEOUT);
    1503             : }
    1504             : 
    1505             : static inline void
    1506           0 : fence_enable_sw_signaling(struct fence *fence)
    1507             : {
    1508           0 :         if (!test_and_set_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags) &&
    1509           0 :             !test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
    1510           0 :                 mtx_enter(fence->lock);
    1511           0 :                 if (!fence->ops->enable_signaling(fence))
    1512           0 :                         fence_signal_locked(fence);
    1513           0 :                 mtx_leave(fence->lock);
    1514           0 :         }
    1515           0 : }
    1516             : 
    1517             : static inline void
    1518           0 : fence_init(struct fence *fence, const struct fence_ops *ops,
    1519             :     struct mutex *lock, unsigned context, unsigned seqno)
    1520             : {
    1521           0 :         fence->ops = ops;
    1522           0 :         fence->lock = lock;
    1523           0 :         fence->context = context;
    1524           0 :         fence->seqno = seqno;
    1525           0 :         fence->flags = 0;
    1526           0 :         kref_init(&fence->refcount);
    1527           0 :         INIT_LIST_HEAD(&fence->cb_list);
    1528           0 : }
    1529             : 
    1530             : static inline int
    1531           0 : fence_add_callback(struct fence *fence, struct fence_cb *cb,
    1532             :     fence_func_t func)
    1533             : {
    1534             :         int ret = 0;
    1535             :         bool was_set;
    1536             : 
    1537           0 :         if (WARN_ON(!fence || !func))
    1538           0 :                 return -EINVAL;
    1539             : 
    1540           0 :         if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
    1541           0 :                 INIT_LIST_HEAD(&cb->node);
    1542           0 :                 return -ENOENT;
    1543             :         }
    1544             : 
    1545           0 :         mtx_enter(fence->lock);
    1546             : 
    1547           0 :         was_set = test_and_set_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags);
    1548             : 
    1549           0 :         if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags))
    1550           0 :                 ret = -ENOENT;
    1551           0 :         else if (!was_set) {
    1552           0 :                 if (!fence->ops->enable_signaling(fence)) {
    1553           0 :                         fence_signal_locked(fence);
    1554             :                         ret = -ENOENT;
    1555           0 :                 }
    1556             :         }
    1557             : 
    1558           0 :         if (!ret) {
    1559           0 :                 cb->func = func;
    1560           0 :                 list_add_tail(&cb->node, &fence->cb_list);
    1561           0 :         } else
    1562           0 :                 INIT_LIST_HEAD(&cb->node);
    1563           0 :         mtx_leave(fence->lock);
    1564             : 
    1565           0 :         return ret;
    1566           0 : }
    1567             : 
    1568             : static inline bool
    1569           0 : fence_remove_callback(struct fence *fence, struct fence_cb *cb)
    1570             : {
    1571             :         bool ret;
    1572             : 
    1573           0 :         mtx_enter(fence->lock);
    1574             : 
    1575           0 :         ret = !list_empty(&cb->node);
    1576           0 :         if (ret)
    1577           0 :                 list_del_init(&cb->node);
    1578             : 
    1579           0 :         mtx_leave(fence->lock);
    1580             : 
    1581           0 :         return ret;
    1582             : }
    1583             : 
    1584             : struct idr_entry {
    1585             :         SPLAY_ENTRY(idr_entry) entry;
    1586             :         int id;
    1587             :         void *ptr;
    1588             : };
    1589             : 
    1590             : struct idr {
    1591             :         SPLAY_HEAD(idr_tree, idr_entry) tree;
    1592             : };
    1593             : 
    1594             : void idr_init(struct idr *);
    1595             : void idr_preload(unsigned int);
    1596             : int idr_alloc(struct idr *, void *, int, int, unsigned int);
    1597             : #define idr_preload_end()
    1598             : void *idr_find(struct idr *, int);
    1599             : void *idr_replace(struct idr *, void *ptr, int);
    1600             : void idr_remove(struct idr *, int);
    1601             : void idr_destroy(struct idr *);
    1602             : int idr_for_each(struct idr *, int (*)(int, void *, void *), void *);
    1603             : void *idr_get_next(struct idr *, int *);
    1604             : 
    1605             : #define idr_for_each_entry(idp, entry, id) \
    1606             :         for (id = 0; ((entry) = idr_get_next(idp, &(id))) != NULL; id++)
    1607             : 
    1608             : 
    1609             : struct ida {
    1610             :         int counter;
    1611             : };
    1612             : 
    1613             : void ida_init(struct ida *);
    1614             : void ida_destroy(struct ida *);
    1615             : int ida_simple_get(struct ida *, unsigned int, unsigned nt, int);
    1616             : void ida_remove(struct ida *, int);
    1617             : 
    1618             : struct notifier_block {
    1619             :         void *notifier_call;
    1620             : };
    1621             : 
    1622             : #define register_reboot_notifier(x)
    1623             : #define unregister_reboot_notifier(x)
    1624             : 
    1625             : #define SYS_RESTART 0
    1626             : 
    1627             : #define min_t(t, a, b) ({ \
    1628             :         t __min_a = (a); \
    1629             :         t __min_b = (b); \
    1630             :         __min_a < __min_b ? __min_a : __min_b; })
    1631             : 
    1632             : #define max_t(t, a, b) ({ \
    1633             :         t __max_a = (a); \
    1634             :         t __max_b = (b); \
    1635             :         __max_a > __max_b ? __max_a : __max_b; })
    1636             : 
    1637             : #define clamp_t(t, x, a, b) min_t(t, max_t(t, x, a), b)
    1638             : #define clamp(x, a, b) clamp_t(__typeof(x), x, a, b)
    1639             : 
    1640             : #define min3(x, y, z) MIN(x, MIN(y, z))
    1641             : 
    1642             : #define do_div(n, base) ({                              \
    1643             :         uint32_t __base = (base);                       \
    1644             :         uint32_t __rem = ((uint64_t)(n)) % __base;      \
    1645             :         (n) = ((uint64_t)(n)) / __base;                 \
    1646             :         __rem;                                          \
    1647             : })
    1648             : 
    1649             : static inline uint64_t
    1650           0 : div_u64(uint64_t x, uint32_t y)
    1651             : {
    1652           0 :         return (x / y);
    1653             : }
    1654             : 
    1655             : static inline int64_t
    1656           0 : div_s64(int64_t x, int64_t y)
    1657             : {
    1658           0 :         return (x / y);
    1659             : }
    1660             : 
    1661             : static inline uint64_t
    1662           0 : div64_u64(uint64_t x, uint64_t y)
    1663             : {
    1664           0 :         return (x / y);
    1665             : }
    1666             : 
    1667             : static inline uint64_t
    1668           0 : div64_u64_rem(uint64_t x, uint64_t y, uint64_t *rem)
    1669             : {
    1670           0 :         *rem = x % y;
    1671           0 :         return (x / y);
    1672             : }
    1673             : 
    1674             : static inline int64_t
    1675           0 : div64_s64(int64_t x, int64_t y)
    1676             : {
    1677           0 :         return (x / y);
    1678             : }
    1679             : 
    1680             : #define mult_frac(x, n, d) (((x) * (n)) / (d))
    1681             : #define order_base_2(x) drm_order(x)
    1682             : 
    1683             : static inline int64_t
    1684             : abs64(int64_t x)
    1685             : {
    1686             :         return (x < 0 ? -x : x);
    1687             : }
    1688             : 
    1689             : static inline unsigned long
    1690           0 : __copy_to_user(void *to, const void *from, unsigned len)
    1691             : {
    1692           0 :         if (copyout(from, to, len))
    1693           0 :                 return len;
    1694           0 :         return 0;
    1695           0 : }
    1696             : 
    1697             : static inline unsigned long
    1698           0 : copy_to_user(void *to, const void *from, unsigned len)
    1699             : {
    1700           0 :         return __copy_to_user(to, from, len);
    1701             : }
    1702             : 
    1703             : static inline unsigned long
    1704           0 : __copy_from_user(void *to, const void *from, unsigned len)
    1705             : {
    1706           0 :         if (copyin(from, to, len))
    1707           0 :                 return len;
    1708           0 :         return 0;
    1709           0 : }
    1710             : 
    1711             : static inline unsigned long
    1712           0 : copy_from_user(void *to, const void *from, unsigned len)
    1713             : {
    1714           0 :         return __copy_from_user(to, from, len);
    1715             : }
    1716             : 
    1717             : #define get_user(x, ptr)        -copyin(ptr, &(x), sizeof(x))
    1718             : #define put_user(x, ptr)        -copyout(&(x), ptr, sizeof(x))
    1719             : 
    1720             : #define console_lock()
    1721             : #define console_trylock()       1
    1722             : #define console_unlock()
    1723             : 
    1724             : #ifndef PCI_MEM_START
    1725             : #define PCI_MEM_START   0
    1726             : #endif
    1727             : 
    1728             : #ifndef PCI_MEM_END
    1729             : #define PCI_MEM_END     0xffffffff
    1730             : #endif
    1731             : 
    1732             : enum dmi_field {
    1733             :         DMI_NONE,
    1734             :         DMI_BIOS_VENDOR,
    1735             :         DMI_BIOS_VERSION,
    1736             :         DMI_BIOS_DATE,
    1737             :         DMI_SYS_VENDOR,
    1738             :         DMI_PRODUCT_NAME,
    1739             :         DMI_PRODUCT_VERSION,
    1740             :         DMI_PRODUCT_SERIAL,
    1741             :         DMI_PRODUCT_UUID,
    1742             :         DMI_BOARD_VENDOR,
    1743             :         DMI_BOARD_NAME,
    1744             :         DMI_BOARD_VERSION,
    1745             :         DMI_BOARD_SERIAL,
    1746             :         DMI_BOARD_ASSET_TAG,
    1747             :         DMI_CHASSIS_VENDOR,
    1748             :         DMI_CHASSIS_TYPE,
    1749             :         DMI_CHASSIS_VERSION,
    1750             :         DMI_CHASSIS_SERIAL,
    1751             :         DMI_CHASSIS_ASSET_TAG,
    1752             :         DMI_STRING_MAX,
    1753             : };
    1754             : 
    1755             : struct dmi_strmatch {
    1756             :         unsigned char slot;
    1757             :         char substr[79];
    1758             : };
    1759             : 
    1760             : struct dmi_system_id {
    1761             :         int (*callback)(const struct dmi_system_id *);
    1762             :         const char *ident;
    1763             :         struct dmi_strmatch matches[4];
    1764             : };
    1765             : #define DMI_MATCH(a, b) {(a), (b)}
    1766             : #define DMI_EXACT_MATCH(a, b) {(a), (b)}
    1767             : int dmi_check_system(const struct dmi_system_id *);
    1768             : bool dmi_match(int, const char *);
    1769             : 
    1770             : struct resource {
    1771             :         u_long  start;
    1772             : };
    1773             : 
    1774             : struct pci_bus {
    1775             :         pci_chipset_tag_t pc;
    1776             :         unsigned char   number;
    1777             :         pcitag_t        *bridgetag;
    1778             : };
    1779             : 
    1780             : struct pci_dev {
    1781             :         struct pci_bus  _bus;
    1782             :         struct pci_bus  *bus;
    1783             : 
    1784             :         unsigned int    devfn;
    1785             :         uint16_t        vendor;
    1786             :         uint16_t        device;
    1787             :         uint16_t        subsystem_vendor;
    1788             :         uint16_t        subsystem_device;
    1789             :         uint8_t         revision;
    1790             : 
    1791             :         pci_chipset_tag_t pc;
    1792             :         pcitag_t        tag;
    1793             :         struct pci_softc *pci;
    1794             : 
    1795             :         int             irq;
    1796             :         int             msi_enabled;
    1797             : };
    1798             : #define PCI_ANY_ID (uint16_t) (~0U)
    1799             : 
    1800             : #define PCI_VENDOR_ID_APPLE     PCI_VENDOR_APPLE
    1801             : #define PCI_VENDOR_ID_ASUSTEK   PCI_VENDOR_ASUSTEK
    1802             : #define PCI_VENDOR_ID_ATI       PCI_VENDOR_ATI
    1803             : #define PCI_VENDOR_ID_DELL      PCI_VENDOR_DELL
    1804             : #define PCI_VENDOR_ID_HP        PCI_VENDOR_HP
    1805             : #define PCI_VENDOR_ID_IBM       PCI_VENDOR_IBM
    1806             : #define PCI_VENDOR_ID_INTEL     PCI_VENDOR_INTEL
    1807             : #define PCI_VENDOR_ID_SONY      PCI_VENDOR_SONY
    1808             : #define PCI_VENDOR_ID_VIA       PCI_VENDOR_VIATECH
    1809             : 
    1810             : #define PCI_DEVICE_ID_ATI_RADEON_QY     PCI_PRODUCT_ATI_RADEON_QY
    1811             : 
    1812             : #define PCI_DEVFN(slot, func)   ((slot) << 3 | (func))
    1813             : #define PCI_SLOT(devfn)         ((devfn) >> 3)
    1814             : #define PCI_FUNC(devfn)         ((devfn) & 0x7)
    1815             : 
    1816             : #define pci_dev_put(x)
    1817             : 
    1818             : #define PCI_EXP_DEVSTA          0x0a
    1819             : #define PCI_EXP_DEVSTA_TRPND    0x0020
    1820             : #define PCI_EXP_LNKCAP          0x0c
    1821             : #define PCI_EXP_LNKCAP_CLKPM    0x00040000
    1822             : #define PCI_EXP_LNKCTL          0x10
    1823             : #define PCI_EXP_LNKCTL_HAWD     0x0200
    1824             : #define PCI_EXP_LNKCTL2         0x30
    1825             : 
    1826             : static inline int
    1827           0 : pci_read_config_dword(struct pci_dev *pdev, int reg, u32 *val)
    1828             : {
    1829           0 :         *val = pci_conf_read(pdev->pc, pdev->tag, reg);
    1830           0 :         return 0;
    1831             : } 
    1832             : 
    1833             : static inline int
    1834           0 : pci_read_config_word(struct pci_dev *pdev, int reg, u16 *val)
    1835             : {
    1836             :         uint32_t v;
    1837             : 
    1838           0 :         v = pci_conf_read(pdev->pc, pdev->tag, (reg & ~0x2));
    1839           0 :         *val = (v >> ((reg & 0x2) * 8));
    1840           0 :         return 0;
    1841             : } 
    1842             : 
    1843             : static inline int
    1844           0 : pci_read_config_byte(struct pci_dev *pdev, int reg, u8 *val)
    1845             : {
    1846             :         uint32_t v;
    1847             : 
    1848           0 :         v = pci_conf_read(pdev->pc, pdev->tag, (reg & ~0x3));
    1849           0 :         *val = (v >> ((reg & 0x3) * 8));
    1850           0 :         return 0;
    1851             : } 
    1852             : 
    1853             : static inline int
    1854           0 : pci_write_config_dword(struct pci_dev *pdev, int reg, u32 val)
    1855             : {
    1856           0 :         pci_conf_write(pdev->pc, pdev->tag, reg, val);
    1857           0 :         return 0;
    1858             : } 
    1859             : 
    1860             : static inline int
    1861           0 : pci_write_config_word(struct pci_dev *pdev, int reg, u16 val)
    1862             : {
    1863             :         uint32_t v;
    1864             : 
    1865           0 :         v = pci_conf_read(pdev->pc, pdev->tag, (reg & ~0x2));
    1866           0 :         v &= ~(0xffff << ((reg & 0x2) * 8));
    1867           0 :         v |= (val << ((reg & 0x2) * 8));
    1868           0 :         pci_conf_write(pdev->pc, pdev->tag, (reg & ~0x2), v);
    1869           0 :         return 0;
    1870             : } 
    1871             : 
    1872             : static inline int
    1873           0 : pci_write_config_byte(struct pci_dev *pdev, int reg, u8 val)
    1874             : {
    1875             :         uint32_t v;
    1876             : 
    1877           0 :         v = pci_conf_read(pdev->pc, pdev->tag, (reg & ~0x3));
    1878           0 :         v &= ~(0xff << ((reg & 0x3) * 8));
    1879           0 :         v |= (val << ((reg & 0x3) * 8));
    1880           0 :         pci_conf_write(pdev->pc, pdev->tag, (reg & ~0x3), v);
    1881           0 :         return 0;
    1882             : }
    1883             : 
    1884             : static inline int
    1885           0 : pci_bus_read_config_word(struct pci_bus *bus, unsigned int devfn,
    1886             :     int reg, u16 *val)
    1887             : {
    1888           0 :         pcitag_t tag = pci_make_tag(bus->pc, bus->number,
    1889           0 :             PCI_SLOT(devfn), PCI_FUNC(devfn));
    1890             :         uint32_t v;
    1891             : 
    1892           0 :         v = pci_conf_read(bus->pc, tag, (reg & ~0x2));
    1893           0 :         *val = (v >> ((reg & 0x2) * 8));
    1894           0 :         return 0;
    1895             : }
    1896             : 
    1897             : static inline int
    1898           0 : pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn,
    1899             :     int reg, u8 *val)
    1900             : {
    1901           0 :         pcitag_t tag = pci_make_tag(bus->pc, bus->number,
    1902           0 :             PCI_SLOT(devfn), PCI_FUNC(devfn));
    1903             :         uint32_t v;
    1904             : 
    1905           0 :         v = pci_conf_read(bus->pc, tag, (reg & ~0x3));
    1906           0 :         *val = (v >> ((reg & 0x3) * 8));
    1907           0 :         return 0;
    1908             : }
    1909             : 
    1910             : static inline int
    1911           0 : pci_pcie_cap(struct pci_dev *pdev)
    1912             : {
    1913           0 :         int pos;
    1914           0 :         if (!pci_get_capability(pdev->pc, pdev->tag, PCI_CAP_PCIEXPRESS,
    1915             :             &pos, NULL))
    1916           0 :                 return -EINVAL;
    1917           0 :         return pos;
    1918           0 : }
    1919             : 
    1920             : static inline bool
    1921           0 : pci_is_root_bus(struct pci_bus *pbus)
    1922             : {
    1923           0 :         return (pbus->bridgetag == NULL);
    1924             : }
    1925             : 
    1926             : static inline int
    1927           0 : pcie_capability_read_dword(struct pci_dev *pdev, int off, u32 *val)
    1928             : {
    1929           0 :         int pos;
    1930           0 :         if (!pci_get_capability(pdev->pc, pdev->tag, PCI_CAP_PCIEXPRESS,
    1931             :             &pos, NULL)) {
    1932           0 :                 *val = 0;
    1933           0 :                 return -EINVAL;
    1934             :         }
    1935           0 :         *val = pci_conf_read(pdev->pc, pdev->tag, pos + off);
    1936           0 :         return 0;
    1937           0 : }
    1938             : 
    1939             : #define pci_set_master(x)
    1940             : #define pci_clear_master(x)
    1941             : 
    1942             : #define pci_save_state(x)
    1943             : #define pci_restore_state(x)
    1944             : 
    1945             : #define pci_enable_msi(x)
    1946             : #define pci_disable_msi(x)
    1947             : 
    1948             : typedef enum {
    1949             :         PCI_D0,
    1950             :         PCI_D1,
    1951             :         PCI_D2,
    1952             :         PCI_D3hot,
    1953             :         PCI_D3cold
    1954             : } pci_power_t;
    1955             : 
    1956             : #define pci_save_state(x)
    1957             : #define pci_enable_device(x)    0
    1958             : #define pci_disable_device(x)
    1959             : #define pci_set_power_state(d, s)
    1960             : 
    1961             : static inline int
    1962           0 : vga_client_register(struct pci_dev *a, void *b, void *c, void *d)
    1963             : {
    1964           0 :         return -ENODEV;
    1965             : }
    1966             : 
    1967             : #if defined(__amd64__) || defined(__i386__)
    1968             : 
    1969             : #define AGP_USER_MEMORY                 0
    1970             : #define AGP_USER_CACHED_MEMORY          BUS_DMA_COHERENT
    1971             : 
    1972             : #define PCI_DMA_BIDIRECTIONAL   0
    1973             : 
    1974             : static inline dma_addr_t
    1975             : pci_map_page(struct pci_dev *pdev, struct vm_page *page, unsigned long offset, size_t size, int direction)
    1976             : {
    1977             :         return VM_PAGE_TO_PHYS(page);
    1978             : }
    1979             : 
    1980             : static inline void
    1981             : pci_unmap_page(struct pci_dev *pdev, dma_addr_t dma_address, size_t size, int direction)
    1982             : {
    1983             : }
    1984             : 
    1985             : static inline int
    1986             : pci_dma_mapping_error(struct pci_dev *pdev, dma_addr_t dma_addr)
    1987             : {
    1988             :         return 0;
    1989             : }
    1990             : 
    1991             : #define dma_set_coherent_mask(x, y)
    1992             : 
    1993             : #define VGA_RSRC_LEGACY_IO      0x01
    1994             : 
    1995             : void vga_get_uninterruptible(struct pci_dev *, int);
    1996             : void vga_put(struct pci_dev *, int);
    1997             : 
    1998             : #endif
    1999             : 
    2000             : #define vga_switcheroo_register_client(a, b, c) 0
    2001             : #define vga_switcheroo_unregister_client(a)
    2002             : #define vga_switcheroo_process_delayed_switch()
    2003             : #define vga_switcheroo_fini_domain_pm_ops(x)
    2004             : 
    2005             : struct i2c_algorithm;
    2006             : 
    2007             : #define I2C_FUNC_I2C                    0
    2008             : #define I2C_FUNC_SMBUS_EMUL             0
    2009             : #define I2C_FUNC_SMBUS_READ_BLOCK_DATA  0
    2010             : #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL  0
    2011             : #define I2C_FUNC_10BIT_ADDR             0
    2012             : 
    2013             : struct i2c_adapter {
    2014             :         struct i2c_controller ic;
    2015             : 
    2016             :         char name[48];
    2017             :         const struct i2c_algorithm *algo;
    2018             :         void *algo_data;
    2019             :         int retries;
    2020             : 
    2021             :         void *data;
    2022             : };
    2023             : 
    2024             : #define I2C_NAME_SIZE   20
    2025             : 
    2026             : struct i2c_msg {
    2027             :         uint16_t addr;
    2028             :         uint16_t flags;
    2029             :         uint16_t len;
    2030             :         uint8_t *buf;
    2031             : };
    2032             : 
    2033             : #define I2C_M_RD        0x0001
    2034             : #define I2C_M_NOSTART   0x0002
    2035             : 
    2036             : struct i2c_algorithm {
    2037             :         int (*master_xfer)(struct i2c_adapter *, struct i2c_msg *, int);
    2038             :         u32 (*functionality)(struct i2c_adapter *);
    2039             : };
    2040             : 
    2041             : extern struct i2c_algorithm i2c_bit_algo;
    2042             : 
    2043             : struct i2c_algo_bit_data {
    2044             :         struct i2c_controller ic;
    2045             : };
    2046             : 
    2047             : int i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int);
    2048             : #define i2c_add_adapter(x) 0
    2049             : #define i2c_del_adapter(x)
    2050             : 
    2051             : static inline void *
    2052           0 : i2c_get_adapdata(struct i2c_adapter *adap)
    2053             : {
    2054           0 :         return adap->data;
    2055             : }
    2056             : 
    2057             : static inline void
    2058           0 : i2c_set_adapdata(struct i2c_adapter *adap, void *data)
    2059             : {
    2060           0 :         adap->data = data;
    2061           0 : }
    2062             : 
    2063             : int i2c_bit_add_bus(struct i2c_adapter *);
    2064             : 
    2065             : #define memcpy_toio(d, s, n)    memcpy(d, s, n)
    2066             : #define memcpy_fromio(d, s, n)  memcpy(d, s, n)
    2067             : #define memset_io(d, b, n)      memset(d, b, n)
    2068             : 
    2069             : static inline u32
    2070           0 : ioread32(const volatile void __iomem *addr)
    2071             : {
    2072           0 :         return (*(volatile uint32_t *)addr);
    2073             : }
    2074             : 
    2075             : static inline u64
    2076           0 : ioread64(const volatile void __iomem *addr)
    2077             : {
    2078           0 :         return (*(volatile uint64_t *)addr);
    2079             : }
    2080             : 
    2081             : static inline void
    2082           0 : iowrite32(u32 val, volatile void __iomem *addr)
    2083             : {
    2084           0 :         *(volatile uint32_t *)addr = val;
    2085           0 : }
    2086             : 
    2087             : static inline void
    2088           0 : iowrite64(u64 val, volatile void __iomem *addr)
    2089             : {
    2090           0 :         *(volatile uint64_t *)addr = val;
    2091           0 : }
    2092             : 
    2093             : #define readl(p) ioread32(p)
    2094             : #define writel(v, p) iowrite32(v, p)
    2095             : #define readq(p) ioread64(p)
    2096             : #define writeq(v, p) iowrite64(v, p)
    2097             : 
    2098             : #define page_to_phys(page)      (VM_PAGE_TO_PHYS(page))
    2099             : #define page_to_pfn(pp)         (VM_PAGE_TO_PHYS(pp) / PAGE_SIZE)
    2100             : #define offset_in_page(off)     ((off) & PAGE_MASK)
    2101             : #define set_page_dirty(page)    atomic_clearbits_int(&page->pg_flags, PG_CLEAN)
    2102             : 
    2103             : #define VERIFY_READ     0x1
    2104             : #define VERIFY_WRITE    0x2
    2105             : static inline int
    2106           0 : access_ok(int type, const void *addr, unsigned long size)
    2107             : {
    2108           0 :         return true;
    2109             : }
    2110             : 
    2111             : #define CAP_SYS_ADMIN   0x1
    2112             : static inline int
    2113           0 : capable(int cap)
    2114             : {
    2115           0 :         KASSERT(cap == CAP_SYS_ADMIN);
    2116           0 :         return suser(curproc);
    2117             : }
    2118             : 
    2119             : typedef int pgprot_t;
    2120             : #define pgprot_val(v)   (v)
    2121             : #define PAGE_KERNEL     0
    2122             : 
    2123             : static inline pgprot_t
    2124           0 : pgprot_writecombine(pgprot_t prot)
    2125             : {
    2126             : #ifdef PMAP_WC
    2127           0 :         return prot | PMAP_WC;
    2128             : #else
    2129             :         return prot | PMAP_NOCACHE;
    2130             : #endif
    2131             : }
    2132             : 
    2133             : static inline pgprot_t
    2134           0 : pgprot_noncached(pgprot_t prot)
    2135             : {
    2136             : #ifdef PMAP_DEVICE
    2137             :         return prot | PMAP_DEVICE;
    2138             : #else
    2139           0 :         return prot | PMAP_NOCACHE;
    2140             : #endif
    2141             : }
    2142             : 
    2143             : void    *kmap(struct vm_page *);
    2144             : void     kunmap(void *addr);
    2145             : void    *vmap(struct vm_page **, unsigned int, unsigned long, pgprot_t);
    2146             : void     vunmap(void *, size_t);
    2147             : 
    2148             : #define round_up(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
    2149             : #define round_down(x, y) (((x) / (y)) * (y))
    2150             : #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
    2151             : #define DIV_ROUND_UP(x, y)      (((x) + ((y) - 1)) / (y))
    2152             : #define DIV_ROUND_UP_ULL(x, y)  DIV_ROUND_UP(x, y)
    2153             : #define DIV_ROUND_CLOSEST(x, y) (((x) + ((y) / 2)) / (y))
    2154             : #define DIV_ROUND_CLOSEST_ULL(x, y)     DIV_ROUND_CLOSEST(x, y)
    2155             : 
    2156             : /*
    2157             :  * Compute the greatest common divisor of a and b.
    2158             :  * from libc getopt_long.c
    2159             :  */
    2160             : static inline unsigned long
    2161           0 : gcd(unsigned long a, unsigned long b)
    2162             : {
    2163             :         unsigned long c;
    2164             : 
    2165           0 :         c = a % b;
    2166           0 :         while (c != 0) {
    2167             :                 a = b;
    2168             :                 b = c;
    2169           0 :                 c = a % b;
    2170             :         }
    2171             : 
    2172           0 :         return (b);
    2173             : }
    2174             : 
    2175             : 
    2176             : static inline unsigned long
    2177           0 : roundup_pow_of_two(unsigned long x)
    2178             : {
    2179           0 :         return (1UL << flsl(x - 1));
    2180             : }
    2181             : 
    2182             : #define is_power_of_2(x)        (x != 0 && (((x) - 1) & (x)) == 0)
    2183             : 
    2184             : #define PAGE_ALIGN(addr)        (((addr) + PAGE_MASK) & ~PAGE_MASK)
    2185             : #define IS_ALIGNED(x, y)        (((x) & ((y) - 1)) == 0)
    2186             : 
    2187             : static __inline void
    2188           0 : udelay(unsigned long usecs)
    2189             : {
    2190           0 :         DELAY(usecs);
    2191           0 : }
    2192             : 
    2193             : static __inline void
    2194           0 : ndelay(unsigned long nsecs)
    2195             : {
    2196           0 :         DELAY(max(nsecs / 1000, 1));
    2197           0 : }
    2198             : 
    2199             : static __inline void
    2200           0 : usleep_range(unsigned long min, unsigned long max)
    2201             : {
    2202           0 :         DELAY(min);
    2203           0 : }
    2204             : 
    2205             : static __inline void
    2206           0 : mdelay(unsigned long msecs)
    2207             : {
    2208           0 :         int loops = msecs;
    2209           0 :         while (loops--)
    2210           0 :                 DELAY(1000);
    2211           0 : }
    2212             : 
    2213             : static __inline void
    2214           0 : cpu_relax(void)
    2215             : {
    2216           0 :         CPU_BUSY_CYCLE();
    2217           0 :         if (cold) {
    2218           0 :                 delay(tick);
    2219           0 :                 jiffies++;
    2220           0 :         }
    2221           0 : }
    2222             : 
    2223             : #define cpu_relax_lowlatency() CPU_BUSY_CYCLE()
    2224             : #define cpu_has_pat     1
    2225             : #define cpu_has_clflush 1
    2226             : 
    2227             : struct lock_class_key {
    2228             : };
    2229             : 
    2230             : typedef struct {
    2231             :         unsigned int sequence;
    2232             : } seqcount_t;
    2233             : 
    2234             : static inline void
    2235           0 : __seqcount_init(seqcount_t *s, const char *name,
    2236             :     struct lock_class_key *key)
    2237             : {
    2238           0 :         s->sequence = 0;
    2239           0 : }
    2240             : 
    2241             : static inline unsigned int
    2242           0 : read_seqcount_begin(const seqcount_t *s)
    2243             : {
    2244             :         unsigned int r;
    2245           0 :         for (;;) {
    2246           0 :                 r = s->sequence;
    2247           0 :                 if ((r & 1) == 0)
    2248             :                         break;
    2249           0 :                 cpu_relax();
    2250             :         }
    2251           0 :         membar_consumer();
    2252           0 :         return r;
    2253             : }
    2254             : 
    2255             : static inline int
    2256           0 : read_seqcount_retry(const seqcount_t *s, unsigned start)
    2257             : {
    2258           0 :         membar_consumer();
    2259           0 :         return (s->sequence != start);
    2260             : }
    2261             : 
    2262             : static inline void
    2263           0 : write_seqcount_begin(seqcount_t *s)
    2264             : {
    2265           0 :         s->sequence++;
    2266           0 :         membar_producer();
    2267           0 : }
    2268             : 
    2269             : static inline void
    2270           0 : write_seqcount_end(seqcount_t *s)
    2271             : {
    2272           0 :         membar_producer();
    2273           0 :         s->sequence++;
    2274           0 : }
    2275             : 
    2276             : static inline uint32_t ror32(uint32_t word, unsigned int shift)
    2277             : {
    2278             :         return (word >> shift) | (word << (32 - shift));
    2279             : }
    2280             : 
    2281             : static inline int
    2282           0 : irqs_disabled(void)
    2283             : {
    2284           0 :         return (cold);
    2285             : }
    2286             : 
    2287             : static inline int
    2288           0 : in_dbg_master(void)
    2289             : {
    2290             : #ifdef DDB
    2291           0 :         return (db_is_active);
    2292             : #endif
    2293             :         return (0);
    2294             : }
    2295             : 
    2296             : #define oops_in_progress in_dbg_master()
    2297             : 
    2298             : static inline int
    2299           0 : power_supply_is_system_supplied(void)
    2300             : {
    2301             :         /* XXX return 0 if on battery */
    2302           0 :         return (1);
    2303             : }
    2304             : 
    2305             : #define pm_qos_update_request(x, y)
    2306             : #define pm_qos_remove_request(x)
    2307             : #define pm_runtime_mark_last_busy(x)
    2308             : #define pm_runtime_use_autosuspend(x)
    2309             : #define pm_runtime_put_autosuspend(x)
    2310             : #define pm_runtime_set_autosuspend_delay(x, y)
    2311             : #define pm_runtime_set_active(x)
    2312             : #define pm_runtime_allow(x)
    2313             : 
    2314             : static inline int
    2315           0 : pm_runtime_get_sync(struct device *dev)
    2316             : {
    2317           0 :         return 0;
    2318             : }
    2319             : 
    2320             : #define _U      0x01
    2321             : #define _L      0x02
    2322             : #define _N      0x04
    2323             : #define _S      0x08
    2324             : #define _P      0x10
    2325             : #define _C      0x20
    2326             : #define _X      0x40
    2327             : #define _B      0x80
    2328             : 
    2329             : static inline int
    2330           0 : isascii(int c)
    2331             : {
    2332           0 :         return ((unsigned int)c <= 0177);
    2333             : }
    2334             : 
    2335             : static inline int
    2336           0 : isprint(int c)
    2337             : {
    2338           0 :         if (c == -1)
    2339           0 :                 return (0);
    2340           0 :         if ((unsigned char)c >= 040 && (unsigned char)c <= 0176)
    2341           0 :                 return (1);
    2342           0 :         return (0);
    2343           0 : }
    2344             : 
    2345             : #ifdef __macppc__
    2346             : static __inline int
    2347             : of_machine_is_compatible(const char *model)
    2348             : {
    2349             :         extern char *hw_prod;
    2350             :         return (strcmp(model, hw_prod) == 0);
    2351             : }
    2352             : #endif
    2353             : 
    2354             : typedef unsigned int gfp_t;
    2355             : 
    2356             : struct vm_page *alloc_pages(unsigned int, unsigned int);
    2357             : void    __free_pages(struct vm_page *, unsigned int);
    2358             : 
    2359             : static inline struct vm_page *
    2360           0 : alloc_page(unsigned int gfp_mask)
    2361             : {
    2362           0 :         return alloc_pages(gfp_mask, 0);
    2363             : }
    2364             : 
    2365             : static inline void
    2366           0 : __free_page(struct vm_page *page)
    2367             : {
    2368           0 :         return __free_pages(page, 0);
    2369             : }
    2370             : 
    2371             : static inline unsigned int
    2372             : get_order(size_t size)
    2373             : {
    2374             :         return flsl((size - 1) >> PAGE_SHIFT);
    2375             : }
    2376             : 
    2377             : #define ilog2(x) ((sizeof(x) <= 4) ? (fls(x) - 1) : (flsl(x) - 1))
    2378             : 
    2379             : #if defined(__i386__) || defined(__amd64__)
    2380             : 
    2381             : #define _PAGE_PRESENT   PG_V
    2382             : #define _PAGE_RW        PG_RW
    2383             : #define _PAGE_PAT       PG_PAT
    2384             : #define _PAGE_PWT       PG_WT
    2385             : #define _PAGE_PCD       PG_N
    2386             : 
    2387             : static inline void
    2388           0 : pagefault_disable(void)
    2389             : {
    2390           0 :         KASSERT(curcpu()->ci_inatomic == 0);
    2391           0 :         curcpu()->ci_inatomic = 1;
    2392           0 : }
    2393             : 
    2394             : static inline void
    2395           0 : pagefault_enable(void)
    2396             : {
    2397           0 :         KASSERT(curcpu()->ci_inatomic == 1);
    2398           0 :         curcpu()->ci_inatomic = 0;
    2399           0 : }
    2400             : 
    2401             : static inline int
    2402           0 : pagefault_disabled(void)
    2403             : {
    2404           0 :         return curcpu()->ci_inatomic;
    2405             : }
    2406             : 
    2407             : static inline void *
    2408           0 : kmap_atomic(struct vm_page *pg)
    2409             : {
    2410             :         vaddr_t va;
    2411             : 
    2412             : #if defined (__HAVE_PMAP_DIRECT)
    2413           0 :         va = pmap_map_direct(pg);
    2414             : #else
    2415             :         extern vaddr_t pmap_tmpmap_pa(paddr_t);
    2416             :         va = pmap_tmpmap_pa(VM_PAGE_TO_PHYS(pg));
    2417             : #endif
    2418           0 :         return (void *)va;
    2419             : }
    2420             : 
    2421             : static inline void
    2422           0 : kunmap_atomic(void *addr)
    2423             : {
    2424             : #if defined (__HAVE_PMAP_DIRECT)
    2425           0 :         pmap_unmap_direct((vaddr_t)addr);
    2426             : #else
    2427             :         extern void pmap_tmpunmap_pa(void);
    2428             :         pmap_tmpunmap_pa();
    2429             : #endif
    2430           0 : }
    2431             : 
    2432             : static inline unsigned long
    2433           0 : __copy_to_user_inatomic(void *to, const void *from, unsigned len)
    2434             : {
    2435           0 :         struct cpu_info *ci = curcpu();
    2436           0 :         int inatomic = ci->ci_inatomic;
    2437             :         int error;
    2438             : 
    2439           0 :         ci->ci_inatomic = 1;
    2440           0 :         error = copyout(from, to, len);
    2441           0 :         ci->ci_inatomic = inatomic;
    2442             : 
    2443           0 :         return (error ? len : 0);
    2444             : }
    2445             : 
    2446             : static inline unsigned long
    2447           0 : __copy_from_user_inatomic(void *to, const void *from, unsigned len)
    2448             : {
    2449           0 :         struct cpu_info *ci = curcpu();
    2450           0 :         int inatomic = ci->ci_inatomic;
    2451             :         int error;
    2452             : 
    2453           0 :         ci->ci_inatomic = 1;
    2454           0 :         error = copyin(from, to, len);
    2455           0 :         ci->ci_inatomic = inatomic;
    2456             : 
    2457           0 :         return (error ? len : 0);
    2458             : }
    2459             : 
    2460             : static inline unsigned long
    2461           0 : __copy_from_user_inatomic_nocache(void *to, const void *from, unsigned len)
    2462             : {
    2463           0 :         return __copy_from_user_inatomic(to, from, len);
    2464             : }
    2465             : 
    2466             : #endif
    2467             : 
    2468             : struct fb_var_screeninfo {
    2469             :         int pixclock;
    2470             : };
    2471             : 
    2472             : struct fb_info {
    2473             :         struct fb_var_screeninfo var;
    2474             :         void *par;
    2475             : };
    2476             : 
    2477             : #define FB_BLANK_UNBLANK        0
    2478             : #define FB_BLANK_NORMAL         1
    2479             : #define FB_BLANK_HSYNC_SUSPEND  2
    2480             : #define FB_BLANK_VSYNC_SUSPEND  3
    2481             : #define FB_BLANK_POWERDOWN      4
    2482             : 
    2483             : #define FBINFO_STATE_RUNNING    0
    2484             : #define FBINFO_STATE_SUSPENDED  1
    2485             : 
    2486             : #define framebuffer_alloc(flags, device) \
    2487             :         kzalloc(sizeof(struct fb_info), GFP_KERNEL)
    2488             : 
    2489             : struct address_space;
    2490             : #define unmap_mapping_range(mapping, holebegin, holeend, even_cows)
    2491             : 
    2492             : /*
    2493             :  * ACPI types and interfaces.
    2494             :  */
    2495             : 
    2496             : typedef size_t acpi_size;
    2497             : typedef int acpi_status;
    2498             : 
    2499             : struct acpi_table_header;
    2500             : 
    2501             : #define ACPI_SUCCESS(x) ((x) == 0)
    2502             : 
    2503             : #define AE_NOT_FOUND    0x0005
    2504             : 
    2505             : acpi_status acpi_get_table_with_size(const char *, int, struct acpi_table_header **, acpi_size *);
    2506             : 
    2507             : #define acpi_video_register()
    2508             : #define acpi_video_unregister()
    2509             : 
    2510             : struct backlight_device;
    2511             : 
    2512             : struct backlight_properties {
    2513             :         int type;
    2514             :         int max_brightness;
    2515             :         int brightness;
    2516             :         int power;
    2517             : };
    2518             : 
    2519             : struct backlight_ops {
    2520             :         int (*update_status)(struct backlight_device *);
    2521             :         int (*get_brightness)(struct backlight_device *);
    2522             : };
    2523             : 
    2524             : struct backlight_device {
    2525             :         const struct backlight_ops *ops;
    2526             :         struct backlight_properties props;
    2527             :         struct task task;
    2528             :         void *data;
    2529             : };
    2530             : 
    2531             : #define bl_get_data(bd) (bd)->data
    2532             : 
    2533             : #define BACKLIGHT_RAW           0
    2534             : #define BACKLIGHT_FIRMWARE      1
    2535             : 
    2536             : struct backlight_device *backlight_device_register(const char *, void *,
    2537             :      void *, const struct backlight_ops *, struct backlight_properties *);
    2538             : void backlight_device_unregister(struct backlight_device *);
    2539             : 
    2540             : static inline void
    2541           0 : backlight_update_status(struct backlight_device *bd)
    2542             : {
    2543           0 :         bd->ops->update_status(bd);
    2544           0 : }
    2545             : 
    2546             : void backlight_schedule_update_status(struct backlight_device *);
    2547             : 
    2548             : #define MIPI_DSI_V_SYNC_START                   0x01
    2549             : #define MIPI_DSI_V_SYNC_END                     0x11
    2550             : #define MIPI_DSI_H_SYNC_START                   0x21
    2551             : #define MIPI_DSI_H_SYNC_END                     0x31
    2552             : #define MIPI_DSI_COLOR_MODE_OFF                 0x02
    2553             : #define MIPI_DSI_COLOR_MODE_ON                  0x12
    2554             : #define MIPI_DSI_SHUTDOWN_PERIPHERAL            0x22
    2555             : #define MIPI_DSI_TURN_ON_PERIPHERAL             0x32
    2556             : #define MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM    0x03
    2557             : #define MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM    0x13
    2558             : #define MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM    0x23
    2559             : #define MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM   0x04
    2560             : #define MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM   0x14
    2561             : #define MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM   0x24
    2562             : #define MIPI_DSI_DCS_SHORT_WRITE                0x05
    2563             : #define MIPI_DSI_DCS_SHORT_WRITE_PARAM          0x15
    2564             : #define MIPI_DSI_DCS_READ                       0x06
    2565             : #define MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE 0x37
    2566             : #define MIPI_DSI_END_OF_TRANSMISSION            0x08
    2567             : #define MIPI_DSI_NULL_PACKET                    0x09
    2568             : #define MIPI_DSI_BLANKING_PACKET                0x19
    2569             : #define MIPI_DSI_GENERIC_LONG_WRITE             0x29
    2570             : #define MIPI_DSI_DCS_LONG_WRITE                 0x39
    2571             : #define MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20    0x0c
    2572             : #define MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24    0x1c
    2573             : #define MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16    0x2c
    2574             : #define MIPI_DSI_PACKED_PIXEL_STREAM_30         0x0d
    2575             : #define MIPI_DSI_PACKED_PIXEL_STREAM_36         0x1d
    2576             : #define MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12    0x3d
    2577             : #define MIPI_DSI_PACKED_PIXEL_STREAM_16         0x0e
    2578             : #define MIPI_DSI_PACKED_PIXEL_STREAM_18         0x1e
    2579             : #define MIPI_DSI_PIXEL_STREAM_3BYTE_18          0x2e
    2580             : #define MIPI_DSI_PACKED_PIXEL_STREAM_24         0x3e
    2581             : 
    2582             : #define MIPI_DCS_NOP                            0x00
    2583             : #define MIPI_DCS_SOFT_RESET                     0x01
    2584             : #define MIPI_DCS_GET_POWER_MODE                 0x0a
    2585             : #define MIPI_DCS_GET_PIXEL_FORMAT               0x0c
    2586             : #define MIPI_DCS_ENTER_SLEEP_MODE               0x10
    2587             : #define MIPI_DCS_EXIT_SLEEP_MODE                0x11
    2588             : #define MIPI_DCS_SET_DISPLAY_OFF                0x28
    2589             : #define MIPI_DCS_SET_DISPLAY_ON                 0x29
    2590             : #define MIPI_DCS_SET_COLUMN_ADDRESS             0x2a
    2591             : #define MIPI_DCS_SET_PAGE_ADDRESS               0x2b
    2592             : #define MIPI_DCS_SET_TEAR_OFF                   0x34
    2593             : #define MIPI_DCS_SET_TEAR_ON                    0x35
    2594             : #define MIPI_DCS_SET_PIXEL_FORMAT               0x3a
    2595             : 
    2596             : struct pwm_device;
    2597             : 
    2598             : static inline struct pwm_device *
    2599           0 : pwm_get(struct device *dev, const char *consumer)
    2600             : {
    2601           0 :         return ERR_PTR(-ENODEV);
    2602             : }
    2603             : 
    2604             : static inline void
    2605           0 : pwm_put(struct pwm_device *pwm)
    2606             : {
    2607           0 : }
    2608             : 
    2609             : static inline unsigned int
    2610           0 : pwm_get_duty_cycle(const struct pwm_device *pwm)
    2611             : {
    2612           0 :         return 0;
    2613             : }
    2614             : 
    2615             : static inline int
    2616           0 : pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
    2617             : {
    2618           0 :         return -EINVAL;
    2619             : }
    2620             : 
    2621             : static inline int
    2622           0 : pwm_enable(struct pwm_device *pwm)
    2623             : {
    2624           0 :         return -EINVAL;
    2625             : }
    2626             : 
    2627             : static inline void
    2628           0 : pwm_disable(struct pwm_device *pwm)
    2629             : {
    2630           0 : }
    2631             : 
    2632             : struct scatterlist {
    2633             :         dma_addr_t dma_address;
    2634             :         unsigned int offset;
    2635             :         unsigned int length;
    2636             : };
    2637             : 
    2638             : struct sg_table {
    2639             :         struct scatterlist *sgl;
    2640             :         unsigned int nents;
    2641             :         unsigned int orig_nents;
    2642             : };
    2643             : 
    2644             : struct sg_page_iter {
    2645             :         struct scatterlist *sg;
    2646             :         unsigned int sg_pgoffset;
    2647             :         unsigned int __nents;
    2648             : };
    2649             : 
    2650             : int sg_alloc_table(struct sg_table *, unsigned int, gfp_t);
    2651             : void sg_free_table(struct sg_table *);
    2652             : 
    2653             : #define sg_mark_end(x)
    2654             : 
    2655             : static __inline void
    2656           0 : __sg_page_iter_start(struct sg_page_iter *iter, struct scatterlist *sgl,
    2657             :     unsigned int nents, unsigned long pgoffset)
    2658             : {
    2659           0 :         iter->sg = sgl;
    2660           0 :         iter->sg_pgoffset = pgoffset - 1;
    2661           0 :         iter->__nents = nents;
    2662           0 : }
    2663             : 
    2664             : static inline bool
    2665           0 : __sg_page_iter_next(struct sg_page_iter *iter)
    2666             : {
    2667           0 :         iter->sg_pgoffset++;
    2668           0 :         while (iter->__nents > 0 && 
    2669           0 :             iter->sg_pgoffset >= (iter->sg->length / PAGE_SIZE)) {
    2670           0 :                 iter->sg_pgoffset -= (iter->sg->length / PAGE_SIZE);
    2671           0 :                 iter->sg++;
    2672           0 :                 iter->__nents--;
    2673             :         }
    2674             : 
    2675           0 :         return (iter->__nents > 0);
    2676             : }
    2677             : 
    2678             : static inline paddr_t
    2679           0 : sg_page_iter_dma_address(struct sg_page_iter *iter)
    2680             : {
    2681           0 :         return iter->sg->dma_address + (iter->sg_pgoffset << PAGE_SHIFT);
    2682             : }
    2683             : 
    2684             : static inline struct vm_page *
    2685           0 : sg_page_iter_page(struct sg_page_iter *iter)
    2686             : {
    2687           0 :         return PHYS_TO_VM_PAGE(sg_page_iter_dma_address(iter));
    2688             : }
    2689             : 
    2690             : static inline struct vm_page *
    2691           0 : sg_page(struct scatterlist *sgl)
    2692             : {
    2693           0 :         return PHYS_TO_VM_PAGE(sgl->dma_address);
    2694             : }
    2695             : 
    2696             : #define sg_dma_address(sg)      ((sg)->dma_address)
    2697             : #define sg_dma_len(sg)          ((sg)->length)
    2698             : 
    2699             : #define for_each_sg_page(sgl, iter, nents, pgoffset) \
    2700             :   __sg_page_iter_start((iter), (sgl), (nents), (pgoffset)); \
    2701             :   while (__sg_page_iter_next(iter))
    2702             : 
    2703             : size_t sg_copy_from_buffer(struct scatterlist *, unsigned int,
    2704             :     const void *, size_t);
    2705             : 
    2706             : struct firmware {
    2707             :         size_t size;
    2708             :         const u8 *data;
    2709             : };
    2710             : 
    2711             : static inline int
    2712           0 : request_firmware(const struct firmware **fw, const char *name,
    2713             :     struct device *device)
    2714             : {
    2715             :         int r;
    2716           0 :         struct firmware *f = malloc(sizeof(struct firmware), M_DRM,
    2717             :             M_WAITOK | M_ZERO);
    2718           0 :         *fw = f;
    2719           0 :         r = loadfirmware(name, __DECONST(u_char **, &f->data), &f->size);
    2720           0 :         if (r != 0)
    2721           0 :                 return -r;
    2722             :         else
    2723           0 :                 return 0;
    2724           0 : }
    2725             : 
    2726             : #define request_firmware_nowait(a, b, c, d, e, f, g) -EINVAL
    2727             : 
    2728             : static inline void
    2729           0 : release_firmware(const struct firmware *fw)
    2730             : {
    2731           0 :         if (fw)
    2732           0 :                 free(__DECONST(u_char *, fw->data), M_DEVBUF, fw->size);
    2733           0 :         free(__DECONST(struct firmware *, fw), M_DRM, sizeof(*fw));
    2734           0 : }
    2735             : 
    2736             : void *memchr_inv(const void *, int, size_t);
    2737             : 
    2738             : struct dma_buf_ops;
    2739             : 
    2740             : struct dma_buf {
    2741             :         const struct dma_buf_ops *ops;
    2742             :         void *priv;
    2743             :         size_t size;
    2744             :         struct file *file;
    2745             : };
    2746             : 
    2747             : struct dma_buf_attachment;
    2748             : 
    2749             : void    get_dma_buf(struct dma_buf *);
    2750             : struct dma_buf *dma_buf_get(int);
    2751             : void    dma_buf_put(struct dma_buf *);
    2752             : int     dma_buf_fd(struct dma_buf *, int);
    2753             : 
    2754             : struct dma_buf_ops {
    2755             :         void (*release)(struct dma_buf *);
    2756             : };
    2757             : 
    2758             : struct dma_buf_export_info {
    2759             :         const struct dma_buf_ops *ops;
    2760             :         size_t size;
    2761             :         int flags;
    2762             :         void *priv;
    2763             : };
    2764             : 
    2765             : #define DEFINE_DMA_BUF_EXPORT_INFO(x)  struct dma_buf_export_info x 
    2766             : 
    2767             : struct dma_buf *dma_buf_export(const struct dma_buf_export_info *);
    2768             : 
    2769             : #define dma_buf_attach(x, y) NULL
    2770             : #define dma_buf_detach(x, y) panic("dma_buf_detach")
    2771             : 
    2772             : #endif

Generated by: LCOV version 1.13