Author: dumbbell
Date: Sun Aug 25 14:27:14 2013
New Revision: 254858
URL: http://svnweb.freebsd.org/changeset/base/254858

Log:
  drm: Add missing bits to drmP.h, required by the Radeon driver
  
  Some of the FreeBSD-specific definitions are moved to drm_os_freebsd.h.
  But there's still work to do to clean it up and reduce the diff with
  Linux' drmP.h.

Added:
  head/sys/dev/drm2/drm_os_freebsd.h   (contents, props changed)
Modified:
  head/sys/dev/drm2/drmP.h

Modified: head/sys/dev/drm2/drmP.h
==============================================================================
--- head/sys/dev/drm2/drmP.h    Sun Aug 25 13:30:37 2013        (r254857)
+++ head/sys/dev/drm2/drmP.h    Sun Aug 25 14:27:14 2013        (r254858)
@@ -1,9 +1,15 @@
-/* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
- * Created: Mon Jan  4 10:05:05 1999 by fa...@precisioninsight.com
+/**
+ * \file drmP.h
+ * Private header for Direct Rendering Manager
+ *
+ * \author Rickard E. (Rik) Faith <fa...@valinux.com>
+ * \author Gareth Hughes <gar...@valinux.com>
  */
-/*-
+
+/*
  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * Copyright (c) 2009-2010, Code Aurora Forum.
  * All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -24,11 +30,6 @@
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Rickard E. (Rik) Faith <fa...@valinux.com>
- *    Gareth Hughes <gar...@valinux.com>
- *
  */
 
 #include <sys/cdefs.h>
@@ -39,9 +40,6 @@ __FBSDID("$FreeBSD$");
 
 #if defined(_KERNEL) || defined(__KERNEL__)
 
-struct drm_device;
-struct drm_file;
-
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/malloc.h>
@@ -99,12 +97,19 @@ struct drm_file;
 #include <sys/bus.h>
 
 #include <dev/drm2/drm.h>
+#include <dev/drm2/drm_sarea.h>
+
 #include <dev/drm2/drm_atomic.h>
 #include <dev/drm2/drm_internal.h>
 #include <dev/drm2/drm_linux_list.h>
 #include <dev/drm2/drm_gem_names.h>
-#include <dev/drm2/drm_mm.h>
+
+struct drm_file;
+struct drm_device;
+
+#include <dev/drm2/drm_os_freebsd.h>
 #include <dev/drm2/drm_hashtab.h>
+#include <dev/drm2/drm_mm.h>
 
 #include "opt_compat.h"
 #include "opt_drm.h"
@@ -120,6 +125,10 @@ struct drm_file;
 #undef DRM_LINUX
 #define DRM_LINUX 0
 
+/***********************************************************************/
+/** \name DRM template customization defaults */
+/*@{*/
+
 /* driver capabilities and requirements mask */
 #define DRIVER_USE_AGP     0x1
 #define DRIVER_REQUIRE_AGP 0x2
@@ -135,8 +144,8 @@ struct drm_file;
 #define DRIVER_IRQ_VBL2    0x800
 #define DRIVER_GEM         0x1000
 #define DRIVER_MODESET     0x2000
-#define DRIVER_USE_PLATFORM_DEVICE  0x4000
-#define        DRIVER_LOCKLESS_IRQ 0x8000
+#define DRIVER_PRIME       0x4000
+#define DRIVER_LOCKLESS_IRQ 0x8000
 
 
 #define DRM_HASH_SIZE        16 /* Size of key hash table                */
@@ -177,7 +186,10 @@ SYSCTL_DECL(_hw_drm);
 
 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
 
-                               /* Internal types and structures */
+/***********************************************************************/
+/** \name Internal types and structures */
+/*@{*/
+
 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
@@ -228,12 +240,6 @@ typedef void                       irqreturn_t;
 #define IRQ_HANDLED            /* nothing */
 #define IRQ_NONE               /* nothing */
 
-#define unlikely(x)            __builtin_expect(!!(x), 0)
-#define likely(x)              __builtin_expect(!!(x), 1)
-#define container_of(ptr, type, member) ({                     \
-       __typeof( ((type *)0)->member ) *__mptr = (ptr);        \
-       (type *)( (char *)__mptr - offsetof(type,member) );})
-
 enum {
        DRM_IS_NOT_AGP,
        DRM_IS_AGP,
@@ -255,16 +261,6 @@ enum {
 #define        time_after_eq(a,b)      ((long)(b) - (long)(a) <= 0)
 #define drm_msleep(x, msg)     pause((msg), ((int64_t)(x)) * hz / 1000)
 
-typedef vm_paddr_t dma_addr_t;
-typedef uint64_t u64;
-typedef uint32_t u32;
-typedef uint16_t u16;
-typedef uint8_t u8;
-typedef int64_t s64;
-typedef int32_t s32;
-typedef int16_t s16;
-typedef int8_t s8;
-
 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
  * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
  * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
@@ -312,16 +308,6 @@ typedef int8_t s8;
 #define DRM_GET_USER_UNCHECKED(val, uaddr)             \
        ((val) = fuword32(uaddr), 0)
 
-#define cpu_to_le32(x) htole32(x)
-#define le32_to_cpu(x) le32toh(x)
-
-#define DRM_HZ                 hz
-#define DRM_UDELAY(udelay)     DELAY(udelay)
-#define DRM_MDELAY(msecs)      do { int loops = (msecs);               \
-                                 while (loops--) DELAY(1000);          \
-                               } while (0)
-#define DRM_TIME_SLICE         (hz/20)  /* Time slice for GLXContexts    */
-
 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do {      \
        (_map) = (_dev)->context_sareas[_ctx];          \
 } while(0)
@@ -372,6 +358,18 @@ for ( ret = 0 ; !ret && !(condition) ; )
                        __func__ , ##__VA_ARGS__);                      \
 } while (0)
 
+#define        dev_err(dev, fmt, ...)                                          
\
+       device_printf((dev), "error: " fmt, ## __VA_ARGS__)
+#define        dev_warn(dev, fmt, ...)                                         
\
+       device_printf((dev), "warning: " fmt, ## __VA_ARGS__)
+#define        dev_info(dev, fmt, ...)                                         
\
+       device_printf((dev), "info: " fmt, ## __VA_ARGS__)
+#define        dev_dbg(dev, fmt, ...) do {                                     
\
+       if ((drm_debug_flag& DRM_DEBUGBITS_KMS) != 0) {                 \
+               device_printf((dev), "debug: " fmt, ## __VA_ARGS__);    \
+       }                                                               \
+} while (0)
+
 typedef struct drm_pci_id_list
 {
        int vendor;
@@ -387,7 +385,7 @@ struct drm_msi_blacklist_entry
 };
 
 #define DRM_AUTH       0x1
-#define DRM_MASTER     0x2
+#define        DRM_MASTER      0x2
 #define DRM_ROOT_ONLY  0x4
 #define DRM_CONTROL_ALLOW 0x8
 #define DRM_UNLOCKED   0x10
@@ -397,7 +395,9 @@ typedef struct drm_ioctl_desc {
        int (*func)(struct drm_device *dev, void *data,
                    struct drm_file *file_priv);
        int flags;
+       unsigned int cmd_drv;
 } drm_ioctl_desc_t;
+
 /**
  * Creates a driver or general drm_ioctl_desc array entry for the given
  * ioctl, for use by drm_ioctl().
@@ -405,6 +405,9 @@ typedef struct drm_ioctl_desc {
 #define DRM_IOCTL_DEF(ioctl, func, flags) \
        [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
 
+#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)                        \
+       [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, 
.flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
+
 typedef struct drm_magic_entry {
        drm_magic_t            magic;
        struct drm_file        *priv;
@@ -417,28 +420,30 @@ typedef struct drm_magic_head {
 } drm_magic_head_t;
 
 typedef struct drm_buf {
-       int               idx;         /* Index into master buflist          */
-       int               total;       /* Buffer size                        */
-       int               order;       /* log-base-2(total)                  */
-       int               used;        /* Amount of buffer in use (for DMA)  */
-       unsigned long     offset;      /* Byte offset (used internally)      */
-       void              *address;    /* Address of buffer                  */
-       unsigned long     bus_address; /* Bus address of buffer              */
-       struct drm_buf    *next;       /* Kernel-only: used for free list    */
-       __volatile__ int  pending;     /* On hardware DMA queue              */
-       struct drm_file   *file_priv;  /* Unique identifier of holding process 
*/
-       int               context;     /* Kernel queue for this buffer       */
+       int idx;                       /**< Index into master buflist */
+       int total;                     /**< Buffer size */
+       int order;                     /**< log-base-2(total) */
+       int used;                      /**< Amount of buffer in use (for DMA) */
+       unsigned long offset;          /**< Byte offset (used internally) */
+       void *address;                 /**< Address of buffer */
+       unsigned long bus_address;     /**< Bus address of buffer */
+       struct drm_buf *next;          /**< Kernel-only: used for free list */
+       __volatile__ int waiting;      /**< On kernel DMA queue */
+       __volatile__ int pending;      /**< On hardware DMA queue */
+       struct drm_file *file_priv;    /**< Private of holding file descr */
+       int context;                   /**< Kernel queue for this buffer */
+       int while_locked;              /**< Dispatch this buffer while locked */
        enum {
-               DRM_LIST_NONE    = 0,
-               DRM_LIST_FREE    = 1,
-               DRM_LIST_WAIT    = 2,
-               DRM_LIST_PEND    = 3,
-               DRM_LIST_PRIO    = 4,
+               DRM_LIST_NONE = 0,
+               DRM_LIST_FREE = 1,
+               DRM_LIST_WAIT = 2,
+               DRM_LIST_PEND = 3,
+               DRM_LIST_PRIO = 4,
                DRM_LIST_RECLAIM = 5
-       }                 list;        /* Which list we're on                */
+       } list;                        /**< Which list we're on */
 
-       int               dev_priv_size; /* Size of buffer private stoarge   */
-       void              *dev_private;  /* Per-buffer private storage       */
+       int dev_priv_size;               /**< Size of buffer private storage */
+       void *dev_private;               /**< Per-buffer private storage */
 } drm_buf_t;
 
 typedef struct drm_freelist {
@@ -478,6 +483,14 @@ struct drm_pending_event {
        void (*destroy)(struct drm_pending_event *event);
 };
 
+/* initial implementaton using a linked list - todo hashtab */
+struct drm_prime_file_private {
+       struct list_head head;
+#ifdef DUMBBELL_WIP
+       struct mutex lock;
+#endif /* DUMBBELL_WIP */
+};
+
 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
 struct drm_file {
        TAILQ_ENTRY(drm_file) link;
@@ -500,6 +513,8 @@ struct drm_file {
        struct list_head  event_list;
        int               event_space;
        struct selinfo    event_poll;
+
+       struct drm_prime_file_private prime;
 };
 
 typedef struct drm_lock_data {
@@ -518,17 +533,21 @@ typedef struct drm_lock_data {
  * concurrently accessed, so no locking is needed.
  */
 typedef struct drm_device_dma {
-       drm_buf_entry_t   bufs[DRM_MAX_ORDER+1];
-       int               buf_count;
-       drm_buf_t         **buflist;    /* Vector of pointers info bufs    */
-       int               seg_count;
-       int               page_count;
-       unsigned long     *pagelist;
-       unsigned long     byte_count;
+
+       struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];   /**< buffers, grouped 
by their size order */
+       int buf_count;                  /**< total number of buffers */
+       struct drm_buf **buflist;               /**< Vector of pointers into 
drm_device_dma::bufs */
+       int seg_count;
+       int page_count;                 /**< number of pages */
+       unsigned long *pagelist;        /**< page list */
+       unsigned long byte_count;
        enum {
                _DRM_DMA_USE_AGP = 0x01,
-               _DRM_DMA_USE_SG  = 0x02
+               _DRM_DMA_USE_SG = 0x02,
+               _DRM_DMA_USE_FB = 0x04,
+               _DRM_DMA_USE_PCI_RO = 0x08
        } flags;
+
 } drm_device_dma_t;
 
 typedef struct drm_agp_mem {
@@ -593,28 +612,13 @@ struct drm_vblank_info {
        int inmodeset;                  /* Display driver is setting mode */
 };
 
-/* Size of ringbuffer for vblank timestamps. Just double-buffer
- * in initial implementation.
- */
-#define DRM_VBLANKTIME_RBSIZE 2
-
-/* Flags and return codes for get_vblank_timestamp() driver function. */
-#define DRM_CALLED_FROM_VBLIRQ 1
-#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
-#define DRM_VBLANKTIME_INVBL             (1 << 1)
-
-/* get_scanout_position() return flags */
-#define DRM_SCANOUTPOS_VALID        (1 << 0)
-#define DRM_SCANOUTPOS_INVBL        (1 << 1)
-#define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
-
 /* location of GART table */
 #define DRM_ATI_GART_MAIN 1
 #define DRM_ATI_GART_FB   2
 
-#define DRM_ATI_GART_PCI  1
+#define DRM_ATI_GART_PCI 1
 #define DRM_ATI_GART_PCIE 2
-#define DRM_ATI_GART_IGP  3
+#define DRM_ATI_GART_IGP 3
 
 struct drm_ati_pcigart_info {
        int gart_table_location;
@@ -686,10 +690,58 @@ struct drm_gem_object {
        uint32_t pending_write_domain;
 
        void *driver_private;
+
+#ifdef DUMBBELL_WIP
+       /* dma buf exported from this GEM object */
+       struct dma_buf *export_dma_buf;
+
+       /* dma buf attachment backing this object */
+       struct dma_buf_attachment *import_attach;
+#endif /* DUMBBELL_WIP */
 };
 
 #include "drm_crtc.h"
 
+/* per-master structure */
+struct drm_master {
+
+       u_int refcount; /* refcount for this master */
+
+       struct list_head head; /**< each minor contains a list of masters */
+       struct drm_minor *minor; /**< link back to minor we are a master for */
+
+       char *unique;                   /**< Unique identifier: e.g., busid */
+       int unique_len;                 /**< Length of unique field */
+       int unique_size;                /**< amount allocated */
+
+       int blocked;                    /**< Blocked due to VC switch? */
+
+       /** \name Authentication */
+       /*@{ */
+       struct drm_open_hash magiclist;
+       struct list_head magicfree;
+       /*@} */
+
+       struct drm_lock_data lock;      /**< Information on hardware lock */
+
+       void *driver_priv; /**< Private structure for driver to use */
+};
+
+/* Size of ringbuffer for vblank timestamps. Just double-buffer
+ * in initial implementation.
+ */
+#define DRM_VBLANKTIME_RBSIZE 2
+
+/* Flags and return codes for get_vblank_timestamp() driver function. */
+#define DRM_CALLED_FROM_VBLIRQ 1
+#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
+#define DRM_VBLANKTIME_INVBL             (1 << 1)
+
+/* get_scanout_position() return flags */
+#define DRM_SCANOUTPOS_VALID        (1 << 0)
+#define DRM_SCANOUTPOS_INVBL        (1 << 1)
+#define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
+
 #ifndef DMA_BIT_MASK
 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
 #endif
@@ -761,7 +813,7 @@ struct drm_driver_info {
         *
         * \param dev  DRM device handle
         *
-        * \returns 
+        * \returns
         * One of three values is returned depending on whether or not the
         * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
         * (return of 1), or may or may not be AGP (return of 2).
@@ -816,6 +868,7 @@ struct drm_cmdline_mode {
        enum drm_connector_force force;
 };
 
+
 struct drm_pending_vblank_event {
        struct drm_pending_event base;
        int pipe;
@@ -825,8 +878,9 @@ struct drm_pending_vblank_event {
 /* Length for the array of resource pointers for drm_get_resource_*. */
 #define DRM_MAX_PCI_RESOURCE   6
 
-/** 
- * DRM device functions structure
+/**
+ * DRM device structure. This structure represent a complete card that
+ * may contain multiple heads.
  */
 struct drm_device {
        struct drm_driver_info *driver;
@@ -950,8 +1004,14 @@ struct drm_device {
        void *sysctl_private;
        char busid_str[128];
        int modesetting;
+
+       int switch_power_state;
 };
 
+#define DRM_SWITCH_POWER_ON 0
+#define DRM_SWITCH_POWER_OFF 1
+#define DRM_SWITCH_POWER_CHANGING 2
+
 static __inline__ int drm_core_check_feature(struct drm_device *dev,
                                             int feature)
 {
@@ -1031,6 +1091,41 @@ extern int               drm_open_helper(struct cdev 
                                         DRM_STRUCTPROC *p,
                                        struct drm_device *dev);
 
+#ifdef DUMBBELL_WIP
+extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
+               struct drm_file *file_priv, uint32_t handle, uint32_t flags,
+               int *prime_fd);
+extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
+               struct drm_file *file_priv, int prime_fd, uint32_t *handle);
+
+extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
+                                       struct drm_file *file_priv);
+extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
+                                       struct drm_file *file_priv);
+
+#ifdef DUMBBELL_WIP
+/*
+ * See drm_prime.c
+ *   -- dumbbell@
+ */
+extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, vm_page_t 
*pages,
+                                           dma_addr_t *addrs, int max_pages);
+#endif /* DUMBBELL_WIP */
+extern struct sg_table *drm_prime_pages_to_sg(vm_page_t *pages, int nr_pages);
+extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table 
*sg);
+
+
+void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
+void drm_prime_destroy_file_private(struct drm_prime_file_private 
*prime_fpriv);
+int drm_prime_add_imported_buf_handle(struct drm_prime_file_private 
*prime_fpriv, struct dma_buf *dma_buf, uint32_t handle);
+int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private 
*prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle);
+void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private 
*prime_fpriv, struct dma_buf *dma_buf);
+
+int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj);
+int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
+                        struct drm_gem_object **obj);
+#endif /* DUMBBELL_WIP */
+
 /* Memory management support (drm_memory.c) */
 void   drm_mem_init(void);
 void   drm_mem_uninit(void);
@@ -1319,6 +1414,8 @@ void drm_gem_pager_dtr(void *obj);
 struct ttm_bo_device;
 int ttm_bo_mmap_single(struct ttm_bo_device *bdev, vm_ooffset_t *offset,
     vm_size_t size, struct vm_object **obj_res, int nprot);
+struct ttm_buffer_object;
+void ttm_bo_release_mmap(struct ttm_buffer_object *bo);
 
 void drm_device_lock_mtx(struct drm_device *dev);
 void drm_device_unlock_mtx(struct drm_device *dev);
@@ -1407,36 +1504,13 @@ static __inline__ void drm_core_dropmap(
 {
 }
 
-#define KIB_NOTYET()                                                   \
-do {                                                                   \
-       if (drm_debug_flag && drm_notyet_flag)                          \
-               printf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \
-} while (0)
-
-#define        KTR_DRM         KTR_DEV
-#define        KTR_DRM_REG     KTR_SPARE3
-
-/* Error codes conversion from Linux to FreeBSD. */
-/* XXXKIB what is the right code for EREMOTEIO on FreeBSD? */
-#define        EREMOTEIO       ENXIO
-#define        ERESTARTSYS     ERESTART
-
-#define        PCI_VENDOR_ID_APPLE             0x106b
-#define        PCI_VENDOR_ID_ASUSTEK           0x1043
-#define        PCI_VENDOR_ID_ATI               0x1002
-#define        PCI_VENDOR_ID_DELL              0x1028
-#define        PCI_VENDOR_ID_HP                0x103c
-#define        PCI_VENDOR_ID_IBM               0x1014
-#define        PCI_VENDOR_ID_INTEL             0x8086
-#define        PCI_VENDOR_ID_SERVERWORKS       0x1166
-#define        PCI_VENDOR_ID_SONY              0x104d
-#define        PCI_VENDOR_ID_VIA               0x1106
-
 #define DRM_PCIE_SPEED_25 1
 #define DRM_PCIE_SPEED_50 2
 #define DRM_PCIE_SPEED_80 4
 
 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 
*speed_mask);
 
+#define        drm_can_sleep() (DRM_HZ & 1)
+
 #endif /* __KERNEL__ */
 #endif /* _DRM_P_H_ */

Added: head/sys/dev/drm2/drm_os_freebsd.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/drm2/drm_os_freebsd.h  Sun Aug 25 14:27:14 2013        
(r254858)
@@ -0,0 +1,144 @@
+/**
+ * \file drm_os_freebsd.h
+ * OS abstraction macros.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#if _BYTE_ORDER == _BIG_ENDIAN
+#define        __BIG_ENDIAN 4321
+#else
+#define        __LITTLE_ENDIAN 1234
+#endif
+
+#define        cpu_to_le16(x)  htole16(x)
+#define        le16_to_cpu(x)  le16toh(x)
+#define        cpu_to_le32(x)  htole32(x)
+#define        le32_to_cpu(x)  le32toh(x)
+
+#define        cpu_to_be16(x)  htobe16(x)
+#define        be16_to_cpu(x)  be16toh(x)
+#define        cpu_to_be32(x)  htobe32(x)
+#define        be32_to_cpu(x)  be32toh(x)
+#define        be32_to_cpup(x) be32toh(*x)
+
+typedef vm_paddr_t dma_addr_t;
+typedef uint64_t u64;
+typedef uint32_t u32;
+typedef uint16_t u16;
+typedef uint8_t u8;
+typedef int64_t s64;
+typedef int32_t s32;
+typedef int16_t s16;
+typedef int8_t s8;
+typedef int32_t __be32;
+
+#define        unlikely(x)            __builtin_expect(!!(x), 0)
+#define        likely(x)              __builtin_expect(!!(x), 1)
+#define        container_of(ptr, type, member) ({                      \
+       __typeof( ((type *)0)->member ) *__mptr = (ptr);        \
+       (type *)( (char *)__mptr - offsetof(type,member) );})
+
+#define DRM_HZ                 hz
+#define DRM_UDELAY(udelay)     DELAY(udelay)
+#define DRM_MDELAY(msecs)      do { int loops = (msecs);               \
+                                 while (loops--) DELAY(1000);          \
+                               } while (0)
+#define DRM_MSLEEP(msecs)      drm_msleep((msecs), "drm_msleep")
+#define DRM_TIME_SLICE         (hz/20)  /* Time slice for GLXContexts    */
+
+#define        do_div(a, b)            ((a) /= (b))
+#define        lower_32_bits(n)        ((u32)(n))
+
+#define min_t(type, x, y) ({                   \
+       type __min1 = (x);                      \
+       type __min2 = (y);                      \
+       __min1 < __min2 ? __min1 : __min2; })
+
+#define max_t(type, x, y) ({                   \
+       type __max1 = (x);                      \
+       type __max2 = (y);                      \
+       __max1 > __max2 ? __max1 : __max2; })
+
+#define        memset_io(a, b, c)      memset((a), (b), (c))
+#define        memcpy_fromio(a, b, c)  memcpy((a), (b), (c))
+#define        memcpy_toio(a, b, c)    memcpy((a), (b), (c))
+
+/* XXXKIB what is the right code for the FreeBSD ? */
+/* kib@ used ENXIO here -- dumbbell@ */
+#define        EREMOTEIO       EIO
+#define        ERESTARTSYS     ERESTART
+
+#define        KTR_DRM         KTR_DEV
+#define        KTR_DRM_REG     KTR_SPARE3
+
+#define        PCI_VENDOR_ID_APPLE             0x106b
+#define        PCI_VENDOR_ID_ASUSTEK           0x1043
+#define        PCI_VENDOR_ID_ATI               0x1002
+#define        PCI_VENDOR_ID_DELL              0x1028
+#define        PCI_VENDOR_ID_HP                0x103c
+#define        PCI_VENDOR_ID_IBM               0x1014
+#define        PCI_VENDOR_ID_INTEL             0x8086
+#define        PCI_VENDOR_ID_SERVERWORKS       0x1166
+#define        PCI_VENDOR_ID_SONY              0x104d
+#define        PCI_VENDOR_ID_VIA               0x1106
+
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#define        hweight32(i)    bitcount32(i)
+
+static inline unsigned long
+roundup_pow_of_two(unsigned long x)
+{
+       return (1UL << flsl(x - 1));
+}
+
+/**
+ * ror32 - rotate a 32-bit value right
+ * @word: value to rotate
+ * @shift: bits to roll
+ *
+ * Source: include/linux/bitops.h
+ */
+static inline uint32_t ror32(uint32_t word, unsigned int shift)
+{
+       return (word >> shift) | (word << (32 - shift));
+}
+
+#define        IS_ALIGNED(x, y)        (((x) & ((y) - 1)) == 0)
+#define        get_unaligned(ptr)                                              
\
+       ({ __typeof__(*(ptr)) __tmp;                                    \
+         memcpy(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
+
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+/* Taken from linux/include/linux/unaligned/le_struct.h. */
+struct __una_u32 { u32 x; } __packed;
+
+static inline u32 __get_unaligned_cpu32(const void *p)
+{
+       const struct __una_u32 *ptr = (const struct __una_u32 *)p;
+       return ptr->x;
+}
+
+static inline u32 get_unaligned_le32(const void *p)
+{
+       return __get_unaligned_cpu32((const u8 *)p);
+}
+#else
+/* Taken from linux/include/linux/unaligned/le_byteshift.h. */
+static inline u32 __get_unaligned_le32(const u8 *p)
+{
+       return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
+}
+
+static inline u32 get_unaligned_le32(const void *p)
+{
+       return __get_unaligned_le32((const u8 *)p);
+}
+#endif
+
+#define KIB_NOTYET()                                                   \
+do {                                                                   \
+       if (drm_debug_flag && drm_notyet_flag)                          \
+               printf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \
+} while (0)
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to