# Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, provided that the above
# copyright notice(s) and this permission notice appear in all copies of
# the Software and that both the above copyright notice(s) and this
# permission notice appear in supporting documentation.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 
# Except as contained in this notice, the name of a copyright holder
# shall not be used in advertising or otherwise to promote the sale, use
# or other dealings in this Software without prior written authorization
# of the copyright holder.

diff --git a/include/drm/drm.h b/include/drm/drm.h
index 8adb9d5..f9bedd0 100644
--- a/include/drm/drm.h
+++ b/include/drm/drm.h
@@ -54,10 +54,39 @@ typedef int32_t  __s32;
 typedef uint32_t __u32;
 typedef int64_t  __s64;
 typedef uint64_t __u64;
+#if defined(__SOLARIS__) || defined(__sun)
+#include <sys/types32.h>
+typedef unsigned long long drm_handle_t;
+#else
 typedef unsigned long drm_handle_t;
+#endif
 
 #endif
 
+/* Solaris-specific. */
+#if defined(__SOLARIS__) || defined(__sun)
+
+#define        _IOC_NRBITS     8
+#define        _IOC_TYPEBITS   8
+#define        _IOC_SIZEBITS   14
+#define        _IOC_DIRBITS    2
+
+#define        _IOC_NRSHIFT    0
+#define        _IOC_TYPESHIFT  (_IOC_NRSHIFT + _IOC_NRBITS)
+#define        _IOC_SIZESHIFT  (_IOC_TYPESHIFT + _IOC_TYPEBITS)
+#define        _IOC_DIRSHIFT   (_IOC_SIZESHIFT + _IOC_SIZEBITS)
+
+#define        _IOC(dir, type, nr, size) \
+       (((dir) /* already shifted */) | \
+       ((type) << _IOC_TYPESHIFT) | \
+       ((nr)   << _IOC_NRSHIFT) | \
+       ((size) << _IOC_SIZESHIFT))
+
+#endif /* __Solaris__ or __sun */
+
+
+
+
 #define DRM_NAME	"drm"	  /**< Name in kernel, /dev, and /proc */
 #define DRM_MIN_ORDER	5	  /**< At least 2^5 bytes = 32 bytes */
 #define DRM_MAX_ORDER	22	  /**< Up to 2^22 bytes = 4MB */
@@ -210,12 +239,13 @@ struct drm_ctx_priv_map {
  * \sa drmAddMap().
  */
 struct drm_map {
-	unsigned long offset;	 /**< Requested physical address (0 for SAREA)*/
+	unsigned long long offset;	 /**< Requested physical address (0 for SAREA)*/
+	unsigned long long handle;	 
+				 /**< User-space: "Handle" to pass to mmap() */
+				 /**< Kernel-space: kernel-virtual address */
 	unsigned long size;	 /**< Requested physical size (bytes) */
 	enum drm_map_type type;	 /**< Type of memory to map */
 	enum drm_map_flags flags;	 /**< Flags */
-	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
-				 /**< Kernel-space: kernel-virtual address */
 	int mtrr;		 /**< MTRR slot used */
 	/*   Private data */
 };
@@ -322,18 +352,22 @@ enum drm_dma_flags {
  *
  * \sa drmAddBufs().
  */
+
+typedef enum {
+       _DRM_PAGE_ALIGN = 0x01, /**< Align on page boundaries for DMA */
+       _DRM_AGP_BUFFER = 0x02, /**< Buffer is in AGP space */
+       _DRM_SG_BUFFER  = 0x04, /**< Scatter/gather memory buffer */
+       _DRM_FB_BUFFER  = 0x08, /**< Buffer is in frame buffer */
+       _DRM_PCI_BUFFER_RO = 0x10 /**< Map PCI DMA buffer read-only */
+} drm_buf_flag;
+
+
 struct drm_buf_desc {
 	int count;		 /**< Number of buffers of this size */
 	int size;		 /**< Size in bytes */
 	int low_mark;		 /**< Low water mark */
 	int high_mark;		 /**< High water mark */
-	enum {
-		_DRM_PAGE_ALIGN = 0x01,	/**< Align on page boundaries for DMA */
-		_DRM_AGP_BUFFER = 0x02,	/**< Buffer is in AGP space */
-		_DRM_SG_BUFFER = 0x04,	/**< Scatter/gather memory buffer */
-		_DRM_FB_BUFFER = 0x08,	/**< Buffer is in frame buffer */
-		_DRM_PCI_BUFFER_RO = 0x10 /**< Map PCI DMA buffer read-only */
-	} flags;
+	drm_buf_flag flags;
 	unsigned long agp_start; /**<
 				  * Start address of where the AGP buffers are
 				  * in the AGP aperture
@@ -379,6 +413,7 @@ struct drm_buf_map {
 	void *virtual;		/**< Mmap'd area in user-virtual */
 #endif
 	struct drm_buf_pub *list;	/**< Buffer information */
+	int fd;
 };
 
 /**
diff --git a/include/drm/i915_drm.h b/include/drm/i915_drm.h
index af3ce17..96d391d 100644
--- a/include/drm/i915_drm.h
+++ b/include/drm/i915_drm.h
@@ -75,6 +75,7 @@ typedef struct _drm_i915_sarea {
 	int pf_current_page;	/* which buffer is being displayed? */
 	int perf_boxes;		/* performance boxes to be displayed */
 	int width, height;      /* screen size in pixels */
+	int pad0;
 
 	drm_handle_t front_handle;
 	int front_offset;
@@ -114,6 +115,8 @@ typedef struct _drm_i915_sarea {
 	int pipeB_w;
 	int pipeB_h;
 
+	int pad1;
+
 	/* fill out some space for old userspace triple buffer */
 	drm_handle_t unused_handle;
 	__u32 unused1, unused2, unused3;
diff --git a/libkms/linux.c b/libkms/linux.c
index fc4f205..5d66fc7 100644
--- a/libkms/linux.c
+++ b/libkms/linux.c
@@ -39,6 +39,7 @@
 #include <unistd.h>
 
 #include <sys/stat.h>
+#include <sys/sysmacros.h>
 
 #include "internal.h"
 
diff --git a/xf86drm.c b/xf86drm.c
index 6ea068f..67e29a0 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -984,7 +984,7 @@ int drmRmMap(int fd, drm_handle_t handle)
 {
     drm_map_t map;
 
-    map.handle = (void *)(uintptr_t)handle;
+    map.handle = (drm_handle_t)(uintptr_t)handle;
 
     if(drmIoctl(fd, DRM_IOCTL_RM_MAP, &map))
 	return -errno;
diff --git a/xf86drm.h b/xf86drm.h
index 76eb94e..6a14120 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -458,6 +458,17 @@ do {	register unsigned int __old __asm("o0");		\
 #endif /* architecture */
 #endif /* __GNUC__ >= 2 */
 
+#if defined(__SUNPRO_C)
+#include <atomic.h>
+#define atomic_cmpset_int(p, c, n) ((c == atomic_cas_uint(p, c, n)) ? 1 : 0)
+#define DRM_CAS(lock,old,new,__ret)          \
+               do {                          \
+                                       unsigned int __result, __old = (old);\
+                                       __result = !atomic_cmpset_int(lock,__old,new);\
+                                       __ret = __result;          \
+                               } while(0)
+#endif
+
 #ifndef DRM_CAS
 #define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */
 #endif
diff --git a/xf86drmMode.c b/xf86drmMode.c
index c809c44..715f23a 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -737,7 +737,9 @@ int drmCheckModesettingSupported(const char *busid)
 	if (found)
 		return 0;
 #endif
-	return -ENOSYS;
+
+/* for now return 0 on solaris */
+	return 0;
 
 }
 
