aboutsummaryrefslogtreecommitdiffstats
path: root/include/drm
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2009-12-07 22:52:41 -0500
committerDave Airlie <airlied@redhat.com>2009-12-07 22:52:41 -0500
commit1bd049fa895f9c6743f38b52ce14775f5a31ea63 (patch)
treecb9163ac1c20f7fbdbde42eaab8013d0c3734aed /include/drm
parent22763c5cf3690a681551162c15d34d935308c8d7 (diff)
parentb0a007dc27d8d3ff3db07b3ea997323d9330f770 (diff)
Merge branch 'drm-core-next' into drm-linus
Bring all core drm changes into 2.6.32 tree and resolve the conflict that occurs. Conflicts: drivers/gpu/drm/drm_fb_helper.c
Diffstat (limited to 'include/drm')
-rw-r--r--include/drm/drm.h64
-rw-r--r--include/drm/drmP.h71
-rw-r--r--include/drm/drm_crtc.h44
-rw-r--r--include/drm/drm_dp_helper.h149
-rw-r--r--include/drm/drm_edid.h8
-rw-r--r--include/drm/drm_mode.h80
-rw-r--r--include/drm/i915_drm.h4
-rw-r--r--include/drm/mga_drm.h2
-rw-r--r--include/drm/radeon_drm.h2
-rw-r--r--include/drm/ttm/ttm_bo_driver.h9
-rw-r--r--include/drm/ttm/ttm_execbuf_util.h107
-rw-r--r--include/drm/ttm/ttm_lock.h247
-rw-r--r--include/drm/ttm/ttm_memory.h1
-rw-r--r--include/drm/ttm/ttm_object.h267
-rw-r--r--include/drm/via_drm.h2
15 files changed, 1000 insertions, 57 deletions
diff --git a/include/drm/drm.h b/include/drm/drm.h
index 7cb50bdde46d..43a35b092f04 100644
--- a/include/drm/drm.h
+++ b/include/drm/drm.h
@@ -36,17 +36,27 @@
36#ifndef _DRM_H_ 36#ifndef _DRM_H_
37#define _DRM_H_ 37#define _DRM_H_
38 38
39#if defined(__linux__)
40
39#include <linux/types.h> 41#include <linux/types.h>
40#include <asm/ioctl.h> /* For _IO* macros */ 42#include <asm/ioctl.h>
41#define DRM_IOCTL_NR(n) _IOC_NR(n) 43typedef unsigned int drm_handle_t;
42#define DRM_IOC_VOID _IOC_NONE
43#define DRM_IOC_READ _IOC_READ
44#define DRM_IOC_WRITE _IOC_WRITE
45#define DRM_IOC_READWRITE _IOC_READ|_IOC_WRITE
46#define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
47 44
48#define DRM_MAJOR 226 45#else /* One of the BSDs */
49#define DRM_MAX_MINOR 15 46
47#include <sys/ioccom.h>
48#include <sys/types.h>
49typedef int8_t __s8;
50typedef uint8_t __u8;
51typedef int16_t __s16;
52typedef uint16_t __u16;
53typedef int32_t __s32;
54typedef uint32_t __u32;
55typedef int64_t __s64;
56typedef uint64_t __u64;
57typedef unsigned long drm_handle_t;
58
59#endif
50 60
51#define DRM_NAME "drm" /**< Name in kernel, /dev, and /proc */ 61#define DRM_NAME "drm" /**< Name in kernel, /dev, and /proc */
52#define DRM_MIN_ORDER 5 /**< At least 2^5 bytes = 32 bytes */ 62#define DRM_MIN_ORDER 5 /**< At least 2^5 bytes = 32 bytes */
@@ -59,7 +69,6 @@
59#define _DRM_LOCK_IS_CONT(lock) ((lock) & _DRM_LOCK_CONT) 69#define _DRM_LOCK_IS_CONT(lock) ((lock) & _DRM_LOCK_CONT)
60#define _DRM_LOCKING_CONTEXT(lock) ((lock) & ~(_DRM_LOCK_HELD|_DRM_LOCK_CONT)) 70#define _DRM_LOCKING_CONTEXT(lock) ((lock) & ~(_DRM_LOCK_HELD|_DRM_LOCK_CONT))
61 71
62typedef unsigned int drm_handle_t;
63typedef unsigned int drm_context_t; 72typedef unsigned int drm_context_t;
64typedef unsigned int drm_drawable_t; 73typedef unsigned int drm_drawable_t;
65typedef unsigned int drm_magic_t; 74typedef unsigned int drm_magic_t;
@@ -454,6 +463,7 @@ struct drm_irq_busid {
454enum drm_vblank_seq_type { 463enum drm_vblank_seq_type {
455 _DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */ 464 _DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */
456 _DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */ 465 _DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */
466 _DRM_VBLANK_EVENT = 0x4000000, /**< Send event instead of blocking */
457 _DRM_VBLANK_FLIP = 0x8000000, /**< Scheduled buffer swap should flip */ 467 _DRM_VBLANK_FLIP = 0x8000000, /**< Scheduled buffer swap should flip */
458 _DRM_VBLANK_NEXTONMISS = 0x10000000, /**< If missed, wait for next vblank */ 468 _DRM_VBLANK_NEXTONMISS = 0x10000000, /**< If missed, wait for next vblank */
459 _DRM_VBLANK_SECONDARY = 0x20000000, /**< Secondary display controller */ 469 _DRM_VBLANK_SECONDARY = 0x20000000, /**< Secondary display controller */
@@ -461,8 +471,8 @@ enum drm_vblank_seq_type {
461}; 471};
462 472
463#define _DRM_VBLANK_TYPES_MASK (_DRM_VBLANK_ABSOLUTE | _DRM_VBLANK_RELATIVE) 473#define _DRM_VBLANK_TYPES_MASK (_DRM_VBLANK_ABSOLUTE | _DRM_VBLANK_RELATIVE)
464#define _DRM_VBLANK_FLAGS_MASK (_DRM_VBLANK_SIGNAL | _DRM_VBLANK_SECONDARY | \ 474#define _DRM_VBLANK_FLAGS_MASK (_DRM_VBLANK_EVENT | _DRM_VBLANK_SIGNAL | \
465 _DRM_VBLANK_NEXTONMISS) 475 _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS)
466 476
467struct drm_wait_vblank_request { 477struct drm_wait_vblank_request {
468 enum drm_vblank_seq_type type; 478 enum drm_vblank_seq_type type;
@@ -686,6 +696,8 @@ struct drm_gem_open {
686#define DRM_IOCTL_MODE_GETFB DRM_IOWR(0xAD, struct drm_mode_fb_cmd) 696#define DRM_IOCTL_MODE_GETFB DRM_IOWR(0xAD, struct drm_mode_fb_cmd)
687#define DRM_IOCTL_MODE_ADDFB DRM_IOWR(0xAE, struct drm_mode_fb_cmd) 697#define DRM_IOCTL_MODE_ADDFB DRM_IOWR(0xAE, struct drm_mode_fb_cmd)
688#define DRM_IOCTL_MODE_RMFB DRM_IOWR(0xAF, unsigned int) 698#define DRM_IOCTL_MODE_RMFB DRM_IOWR(0xAF, unsigned int)
699#define DRM_IOCTL_MODE_PAGE_FLIP DRM_IOWR(0xB0, struct drm_mode_crtc_page_flip)
700#define DRM_IOCTL_MODE_DIRTYFB DRM_IOWR(0xB1, struct drm_mode_fb_dirty_cmd)
689 701
690/** 702/**
691 * Device specific ioctls should only be in their respective headers 703 * Device specific ioctls should only be in their respective headers
@@ -698,6 +710,34 @@ struct drm_gem_open {
698#define DRM_COMMAND_BASE 0x40 710#define DRM_COMMAND_BASE 0x40
699#define DRM_COMMAND_END 0xA0 711#define DRM_COMMAND_END 0xA0
700 712
713/**
714 * Header for events written back to userspace on the drm fd. The
715 * type defines the type of event, the length specifies the total
716 * length of the event (including the header), and user_data is
717 * typically a 64 bit value passed with the ioctl that triggered the
718 * event. A read on the drm fd will always only return complete
719 * events, that is, if for example the read buffer is 100 bytes, and
720 * there are two 64 byte events pending, only one will be returned.
721 *
722 * Event types 0 - 0x7fffffff are generic drm events, 0x80000000 and
723 * up are chipset specific.
724 */
725struct drm_event {
726 __u32 type;
727 __u32 length;
728};
729
730#define DRM_EVENT_VBLANK 0x01
731
732struct drm_event_vblank {
733 struct drm_event base;
734 __u64 user_data;
735 __u32 tv_sec;
736 __u32 tv_usec;
737 __u32 sequence;
738 __u32 reserved;
739};
740
701/* typedef area */ 741/* typedef area */
702#ifndef __KERNEL__ 742#ifndef __KERNEL__
703typedef struct drm_clip_rect drm_clip_rect_t; 743typedef struct drm_clip_rect drm_clip_rect_t;
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index c8e64bbadbcf..db56a6add5de 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -245,16 +245,6 @@ extern void drm_ut_debug_printk(unsigned int request_level,
245 245
246#endif 246#endif
247 247
248#define DRM_PROC_LIMIT (PAGE_SIZE-80)
249
250#define DRM_PROC_PRINT(fmt, arg...) \
251 len += sprintf(&buf[len], fmt , ##arg); \
252 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
253
254#define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
255 len += sprintf(&buf[len], fmt , ##arg); \
256 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
257
258/*@}*/ 248/*@}*/
259 249
260/***********************************************************************/ 250/***********************************************************************/
@@ -265,19 +255,8 @@ extern void drm_ut_debug_printk(unsigned int request_level,
265 255
266#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1)) 256#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
267#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x)) 257#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
268#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
269 258
270#define DRM_IF_VERSION(maj, min) (maj << 16 | min) 259#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
271/**
272 * Get the private SAREA mapping.
273 *
274 * \param _dev DRM device.
275 * \param _ctx context number.
276 * \param _map output mapping.
277 */
278#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
279 (_map) = (_dev)->context_sareas[_ctx]; \
280} while(0)
281 260
282/** 261/**
283 * Test that the hardware lock is held by the caller, returning otherwise. 262 * Test that the hardware lock is held by the caller, returning otherwise.
@@ -297,18 +276,6 @@ do { \
297} while (0) 276} while (0)
298 277
299/** 278/**
300 * Copy and IOCTL return string to user space
301 */
302#define DRM_COPY( name, value ) \
303 len = strlen( value ); \
304 if ( len > name##_len ) len = name##_len; \
305 name##_len = strlen( value ); \
306 if ( len && name ) { \
307 if ( copy_to_user( name, value, len ) ) \
308 return -EFAULT; \
309 }
310
311/**
312 * Ioctl function type. 279 * Ioctl function type.
313 * 280 *
314 * \param inode device inode. 281 * \param inode device inode.
@@ -322,6 +289,9 @@ typedef int drm_ioctl_t(struct drm_device *dev, void *data,
322typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd, 289typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
323 unsigned long arg); 290 unsigned long arg);
324 291
292#define DRM_IOCTL_NR(n) _IOC_NR(n)
293#define DRM_MAJOR 226
294
325#define DRM_AUTH 0x1 295#define DRM_AUTH 0x1
326#define DRM_MASTER 0x2 296#define DRM_MASTER 0x2
327#define DRM_ROOT_ONLY 0x4 297#define DRM_ROOT_ONLY 0x4
@@ -426,6 +396,14 @@ struct drm_buf_entry {
426 struct drm_freelist freelist; 396 struct drm_freelist freelist;
427}; 397};
428 398
399/* Event queued up for userspace to read */
400struct drm_pending_event {
401 struct drm_event *event;
402 struct list_head link;
403 struct drm_file *file_priv;
404 void (*destroy)(struct drm_pending_event *event);
405};
406
429/** File private data */ 407/** File private data */
430struct drm_file { 408struct drm_file {
431 int authenticated; 409 int authenticated;
@@ -449,6 +427,10 @@ struct drm_file {
449 struct drm_master *master; /* master this node is currently associated with 427 struct drm_master *master; /* master this node is currently associated with
450 N.B. not always minor->master */ 428 N.B. not always minor->master */
451 struct list_head fbs; 429 struct list_head fbs;
430
431 wait_queue_head_t event_wait;
432 struct list_head event_list;
433 int event_space;
452}; 434};
453 435
454/** Wait queue */ 436/** Wait queue */
@@ -795,6 +777,15 @@ struct drm_driver {
795 /* Master routines */ 777 /* Master routines */
796 int (*master_create)(struct drm_device *dev, struct drm_master *master); 778 int (*master_create)(struct drm_device *dev, struct drm_master *master);
797 void (*master_destroy)(struct drm_device *dev, struct drm_master *master); 779 void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
780 /**
781 * master_set is called whenever the minor master is set.
782 * master_drop is called whenever the minor master is dropped.
783 */
784
785 int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
786 bool from_open);
787 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
788 bool from_release);
798 789
799 int (*proc_init)(struct drm_minor *minor); 790 int (*proc_init)(struct drm_minor *minor);
800 void (*proc_cleanup)(struct drm_minor *minor); 791 void (*proc_cleanup)(struct drm_minor *minor);
@@ -900,6 +891,12 @@ struct drm_minor {
900 struct drm_mode_group mode_group; 891 struct drm_mode_group mode_group;
901}; 892};
902 893
894struct drm_pending_vblank_event {
895 struct drm_pending_event base;
896 int pipe;
897 struct drm_event_vblank event;
898};
899
903/** 900/**
904 * DRM device structure. This structure represent a complete card that 901 * DRM device structure. This structure represent a complete card that
905 * may contain multiple heads. 902 * may contain multiple heads.
@@ -999,6 +996,12 @@ struct drm_device {
999 996
1000 u32 max_vblank_count; /**< size of vblank counter register */ 997 u32 max_vblank_count; /**< size of vblank counter register */
1001 998
999 /**
1000 * List of events
1001 */
1002 struct list_head vblank_event_list;
1003 spinlock_t event_lock;
1004
1002 /*@} */ 1005 /*@} */
1003 cycles_t ctx_start; 1006 cycles_t ctx_start;
1004 cycles_t lck_start; 1007 cycles_t lck_start;
@@ -1135,6 +1138,8 @@ extern int drm_lastclose(struct drm_device *dev);
1135extern int drm_open(struct inode *inode, struct file *filp); 1138extern int drm_open(struct inode *inode, struct file *filp);
1136extern int drm_stub_open(struct inode *inode, struct file *filp); 1139extern int drm_stub_open(struct inode *inode, struct file *filp);
1137extern int drm_fasync(int fd, struct file *filp, int on); 1140extern int drm_fasync(int fd, struct file *filp, int on);
1141extern ssize_t drm_read(struct file *filp, char __user *buffer,
1142 size_t count, loff_t *offset);
1138extern int drm_release(struct inode *inode, struct file *filp); 1143extern int drm_release(struct inode *inode, struct file *filp);
1139 1144
1140 /* Mapping support (drm_vm.h) */ 1145 /* Mapping support (drm_vm.h) */
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index b69347b8904f..219f075d2733 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -123,7 +123,7 @@ struct drm_display_mode {
123 int type; 123 int type;
124 124
125 /* Proposed mode values */ 125 /* Proposed mode values */
126 int clock; 126 int clock; /* in kHz */
127 int hdisplay; 127 int hdisplay;
128 int hsync_start; 128 int hsync_start;
129 int hsync_end; 129 int hsync_end;
@@ -164,8 +164,8 @@ struct drm_display_mode {
164 int *private; 164 int *private;
165 int private_flags; 165 int private_flags;
166 166
167 int vrefresh; 167 int vrefresh; /* in Hz */
168 float hsync; 168 int hsync; /* in kHz */
169}; 169};
170 170
171enum drm_connector_status { 171enum drm_connector_status {
@@ -242,6 +242,21 @@ struct drm_framebuffer_funcs {
242 int (*create_handle)(struct drm_framebuffer *fb, 242 int (*create_handle)(struct drm_framebuffer *fb,
243 struct drm_file *file_priv, 243 struct drm_file *file_priv,
244 unsigned int *handle); 244 unsigned int *handle);
245 /**
246 * Optinal callback for the dirty fb ioctl.
247 *
248 * Userspace can notify the driver via this callback
249 * that a area of the framebuffer has changed and should
250 * be flushed to the display hardware.
251 *
252 * See documentation in drm_mode.h for the struct
253 * drm_mode_fb_dirty_cmd for more information as all
254 * the semantics and arguments have a one to one mapping
255 * on this function.
256 */
257 int (*dirty)(struct drm_framebuffer *framebuffer, unsigned flags,
258 unsigned color, struct drm_clip_rect *clips,
259 unsigned num_clips);
245}; 260};
246 261
247struct drm_framebuffer { 262struct drm_framebuffer {
@@ -256,7 +271,7 @@ struct drm_framebuffer {
256 unsigned int depth; 271 unsigned int depth;
257 int bits_per_pixel; 272 int bits_per_pixel;
258 int flags; 273 int flags;
259 void *fbdev; 274 struct fb_info *fbdev;
260 u32 pseudo_palette[17]; 275 u32 pseudo_palette[17];
261 struct list_head filp_head; 276 struct list_head filp_head;
262 /* if you are using the helper */ 277 /* if you are using the helper */
@@ -290,6 +305,7 @@ struct drm_property {
290struct drm_crtc; 305struct drm_crtc;
291struct drm_connector; 306struct drm_connector;
292struct drm_encoder; 307struct drm_encoder;
308struct drm_pending_vblank_event;
293 309
294/** 310/**
295 * drm_crtc_funcs - control CRTCs for a given device 311 * drm_crtc_funcs - control CRTCs for a given device
@@ -333,6 +349,19 @@ struct drm_crtc_funcs {
333 void (*destroy)(struct drm_crtc *crtc); 349 void (*destroy)(struct drm_crtc *crtc);
334 350
335 int (*set_config)(struct drm_mode_set *set); 351 int (*set_config)(struct drm_mode_set *set);
352
353 /*
354 * Flip to the given framebuffer. This implements the page
355 * flip ioctl descibed in drm_mode.h, specifically, the
356 * implementation must return immediately and block all
357 * rendering to the current fb until the flip has completed.
358 * If userspace set the event flag in the ioctl, the event
359 * argument will point to an event to send back when the flip
360 * completes, otherwise it will be NULL.
361 */
362 int (*page_flip)(struct drm_crtc *crtc,
363 struct drm_framebuffer *fb,
364 struct drm_pending_vblank_event *event);
336}; 365};
337 366
338/** 367/**
@@ -596,6 +625,7 @@ struct drm_mode_config {
596 /* Optional properties */ 625 /* Optional properties */
597 struct drm_property *scaling_mode_property; 626 struct drm_property *scaling_mode_property;
598 struct drm_property *dithering_mode_property; 627 struct drm_property *dithering_mode_property;
628 struct drm_property *dirty_info_property;
599}; 629};
600 630
601#define obj_to_crtc(x) container_of(x, struct drm_crtc, base) 631#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
@@ -667,6 +697,7 @@ extern void drm_mode_validate_size(struct drm_device *dev,
667extern void drm_mode_prune_invalid(struct drm_device *dev, 697extern void drm_mode_prune_invalid(struct drm_device *dev,
668 struct list_head *mode_list, bool verbose); 698 struct list_head *mode_list, bool verbose);
669extern void drm_mode_sort(struct list_head *mode_list); 699extern void drm_mode_sort(struct list_head *mode_list);
700extern int drm_mode_hsync(struct drm_display_mode *mode);
670extern int drm_mode_vrefresh(struct drm_display_mode *mode); 701extern int drm_mode_vrefresh(struct drm_display_mode *mode);
671extern void drm_mode_set_crtcinfo(struct drm_display_mode *p, 702extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
672 int adjust_flags); 703 int adjust_flags);
@@ -703,6 +734,7 @@ extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats
703 char *formats[]); 734 char *formats[]);
704extern int drm_mode_create_scaling_mode_property(struct drm_device *dev); 735extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
705extern int drm_mode_create_dithering_property(struct drm_device *dev); 736extern int drm_mode_create_dithering_property(struct drm_device *dev);
737extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
706extern char *drm_get_encoder_name(struct drm_encoder *encoder); 738extern char *drm_get_encoder_name(struct drm_encoder *encoder);
707 739
708extern int drm_mode_connector_attach_encoder(struct drm_connector *connector, 740extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
@@ -730,6 +762,8 @@ extern int drm_mode_rmfb(struct drm_device *dev,
730 void *data, struct drm_file *file_priv); 762 void *data, struct drm_file *file_priv);
731extern int drm_mode_getfb(struct drm_device *dev, 763extern int drm_mode_getfb(struct drm_device *dev,
732 void *data, struct drm_file *file_priv); 764 void *data, struct drm_file *file_priv);
765extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
766 void *data, struct drm_file *file_priv);
733extern int drm_mode_addmode_ioctl(struct drm_device *dev, 767extern int drm_mode_addmode_ioctl(struct drm_device *dev,
734 void *data, struct drm_file *file_priv); 768 void *data, struct drm_file *file_priv);
735extern int drm_mode_rmmode_ioctl(struct drm_device *dev, 769extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
@@ -756,6 +790,8 @@ extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
756extern int drm_mode_gamma_set_ioctl(struct drm_device *dev, 790extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
757 void *data, struct drm_file *file_priv); 791 void *data, struct drm_file *file_priv);
758extern bool drm_detect_hdmi_monitor(struct edid *edid); 792extern bool drm_detect_hdmi_monitor(struct edid *edid);
793extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
794 void *data, struct drm_file *file_priv);
759extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, 795extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
760 int hdisplay, int vdisplay, int vrefresh, 796 int hdisplay, int vdisplay, int vrefresh,
761 bool reduced, bool interlaced, bool margins); 797 bool reduced, bool interlaced, bool margins);
diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
new file mode 100644
index 000000000000..e49879ce95f9
--- /dev/null
+++ b/include/drm/drm_dp_helper.h
@@ -0,0 +1,149 @@
1/*
2 * Copyright © 2008 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#ifndef _DRM_DP_HELPER_H_
24#define _DRM_DP_HELPER_H_
25
26/* From the VESA DisplayPort spec */
27
28#define AUX_NATIVE_WRITE 0x8
29#define AUX_NATIVE_READ 0x9
30#define AUX_I2C_WRITE 0x0
31#define AUX_I2C_READ 0x1
32#define AUX_I2C_STATUS 0x2
33#define AUX_I2C_MOT 0x4
34
35#define AUX_NATIVE_REPLY_ACK (0x0 << 4)
36#define AUX_NATIVE_REPLY_NACK (0x1 << 4)
37#define AUX_NATIVE_REPLY_DEFER (0x2 << 4)
38#define AUX_NATIVE_REPLY_MASK (0x3 << 4)
39
40#define AUX_I2C_REPLY_ACK (0x0 << 6)
41#define AUX_I2C_REPLY_NACK (0x1 << 6)
42#define AUX_I2C_REPLY_DEFER (0x2 << 6)
43#define AUX_I2C_REPLY_MASK (0x3 << 6)
44
45/* AUX CH addresses */
46#define DP_LINK_BW_SET 0x100
47# define DP_LINK_BW_1_62 0x06
48# define DP_LINK_BW_2_7 0x0a
49
50#define DP_LANE_COUNT_SET 0x101
51# define DP_LANE_COUNT_MASK 0x0f
52# define DP_LANE_COUNT_ENHANCED_FRAME_EN (1 << 7)
53
54#define DP_TRAINING_PATTERN_SET 0x102
55
56# define DP_TRAINING_PATTERN_DISABLE 0
57# define DP_TRAINING_PATTERN_1 1
58# define DP_TRAINING_PATTERN_2 2
59# define DP_TRAINING_PATTERN_MASK 0x3
60
61# define DP_LINK_QUAL_PATTERN_DISABLE (0 << 2)
62# define DP_LINK_QUAL_PATTERN_D10_2 (1 << 2)
63# define DP_LINK_QUAL_PATTERN_ERROR_RATE (2 << 2)
64# define DP_LINK_QUAL_PATTERN_PRBS7 (3 << 2)
65# define DP_LINK_QUAL_PATTERN_MASK (3 << 2)
66
67# define DP_RECOVERED_CLOCK_OUT_EN (1 << 4)
68# define DP_LINK_SCRAMBLING_DISABLE (1 << 5)
69
70# define DP_SYMBOL_ERROR_COUNT_BOTH (0 << 6)
71# define DP_SYMBOL_ERROR_COUNT_DISPARITY (1 << 6)
72# define DP_SYMBOL_ERROR_COUNT_SYMBOL (2 << 6)
73# define DP_SYMBOL_ERROR_COUNT_MASK (3 << 6)
74
75#define DP_TRAINING_LANE0_SET 0x103
76#define DP_TRAINING_LANE1_SET 0x104
77#define DP_TRAINING_LANE2_SET 0x105
78#define DP_TRAINING_LANE3_SET 0x106
79
80# define DP_TRAIN_VOLTAGE_SWING_MASK 0x3
81# define DP_TRAIN_VOLTAGE_SWING_SHIFT 0
82# define DP_TRAIN_MAX_SWING_REACHED (1 << 2)
83# define DP_TRAIN_VOLTAGE_SWING_400 (0 << 0)
84# define DP_TRAIN_VOLTAGE_SWING_600 (1 << 0)
85# define DP_TRAIN_VOLTAGE_SWING_800 (2 << 0)
86# define DP_TRAIN_VOLTAGE_SWING_1200 (3 << 0)
87
88# define DP_TRAIN_PRE_EMPHASIS_MASK (3 << 3)
89# define DP_TRAIN_PRE_EMPHASIS_0 (0 << 3)
90# define DP_TRAIN_PRE_EMPHASIS_3_5 (1 << 3)
91# define DP_TRAIN_PRE_EMPHASIS_6 (2 << 3)
92# define DP_TRAIN_PRE_EMPHASIS_9_5 (3 << 3)
93
94# define DP_TRAIN_PRE_EMPHASIS_SHIFT 3
95# define DP_TRAIN_MAX_PRE_EMPHASIS_REACHED (1 << 5)
96
97#define DP_DOWNSPREAD_CTRL 0x107
98# define DP_SPREAD_AMP_0_5 (1 << 4)
99
100#define DP_MAIN_LINK_CHANNEL_CODING_SET 0x108
101# define DP_SET_ANSI_8B10B (1 << 0)
102
103#define DP_LANE0_1_STATUS 0x202
104#define DP_LANE2_3_STATUS 0x203
105
106# define DP_LANE_CR_DONE (1 << 0)
107# define DP_LANE_CHANNEL_EQ_DONE (1 << 1)
108# define DP_LANE_SYMBOL_LOCKED (1 << 2)
109
110#define DP_LANE_ALIGN_STATUS_UPDATED 0x204
111
112#define DP_INTERLANE_ALIGN_DONE (1 << 0)
113#define DP_DOWNSTREAM_PORT_STATUS_CHANGED (1 << 6)
114#define DP_LINK_STATUS_UPDATED (1 << 7)
115
116#define DP_SINK_STATUS 0x205
117
118#define DP_RECEIVE_PORT_0_STATUS (1 << 0)
119#define DP_RECEIVE_PORT_1_STATUS (1 << 1)
120
121#define DP_ADJUST_REQUEST_LANE0_1 0x206
122#define DP_ADJUST_REQUEST_LANE2_3 0x207
123
124#define DP_ADJUST_VOLTAGE_SWING_LANE0_MASK 0x03
125#define DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT 0
126#define DP_ADJUST_PRE_EMPHASIS_LANE0_MASK 0x0c
127#define DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT 2
128#define DP_ADJUST_VOLTAGE_SWING_LANE1_MASK 0x30
129#define DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT 4
130#define DP_ADJUST_PRE_EMPHASIS_LANE1_MASK 0xc0
131#define DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT 6
132
133#define MODE_I2C_START 1
134#define MODE_I2C_WRITE 2
135#define MODE_I2C_READ 4
136#define MODE_I2C_STOP 8
137
138struct i2c_algo_dp_aux_data {
139 bool running;
140 u16 address;
141 int (*aux_ch) (struct i2c_adapter *adapter,
142 int mode, uint8_t write_byte,
143 uint8_t *read_byte);
144};
145
146int
147i2c_dp_aux_add_bus(struct i2c_adapter *adapter);
148
149#endif /* _DRM_DP_HELPER_H_ */
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index 7d6c9a2dfcbb..d33c3e038606 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -106,6 +106,10 @@ struct detailed_data_color_point {
106 u8 wpindex2[3]; 106 u8 wpindex2[3];
107} __attribute__((packed)); 107} __attribute__((packed));
108 108
109struct cvt_timing {
110 u8 code[3];
111} __attribute__((packed));
112
109struct detailed_non_pixel { 113struct detailed_non_pixel {
110 u8 pad1; 114 u8 pad1;
111 u8 type; /* ff=serial, fe=string, fd=monitor range, fc=monitor name 115 u8 type; /* ff=serial, fe=string, fd=monitor range, fc=monitor name
@@ -117,9 +121,13 @@ struct detailed_non_pixel {
117 struct detailed_data_monitor_range range; 121 struct detailed_data_monitor_range range;
118 struct detailed_data_wpindex color; 122 struct detailed_data_wpindex color;
119 struct std_timing timings[5]; 123 struct std_timing timings[5];
124 struct cvt_timing cvt[4];
120 } data; 125 } data;
121} __attribute__((packed)); 126} __attribute__((packed));
122 127
128#define EDID_DETAIL_EST_TIMINGS 0xf7
129#define EDID_DETAIL_CVT_3BYTE 0xf8
130#define EDID_DETAIL_COLOR_MGMT_DATA 0xf9
123#define EDID_DETAIL_STD_MODES 0xfa 131#define EDID_DETAIL_STD_MODES 0xfa
124#define EDID_DETAIL_MONITOR_CPDATA 0xfb 132#define EDID_DETAIL_MONITOR_CPDATA 0xfb
125#define EDID_DETAIL_MONITOR_NAME 0xfc 133#define EDID_DETAIL_MONITOR_NAME 0xfc
diff --git a/include/drm/drm_mode.h b/include/drm/drm_mode.h
index 1f908416aedb..43009bc2e757 100644
--- a/include/drm/drm_mode.h
+++ b/include/drm/drm_mode.h
@@ -27,9 +27,6 @@
27#ifndef _DRM_MODE_H 27#ifndef _DRM_MODE_H
28#define _DRM_MODE_H 28#define _DRM_MODE_H
29 29
30#include <linux/kernel.h>
31#include <linux/types.h>
32
33#define DRM_DISPLAY_INFO_LEN 32 30#define DRM_DISPLAY_INFO_LEN 32
34#define DRM_CONNECTOR_NAME_LEN 32 31#define DRM_CONNECTOR_NAME_LEN 32
35#define DRM_DISPLAY_MODE_LEN 32 32#define DRM_DISPLAY_MODE_LEN 32
@@ -78,6 +75,11 @@
78#define DRM_MODE_DITHERING_OFF 0 75#define DRM_MODE_DITHERING_OFF 0
79#define DRM_MODE_DITHERING_ON 1 76#define DRM_MODE_DITHERING_ON 1
80 77
78/* Dirty info options */
79#define DRM_MODE_DIRTY_OFF 0
80#define DRM_MODE_DIRTY_ON 1
81#define DRM_MODE_DIRTY_ANNOTATE 2
82
81struct drm_mode_modeinfo { 83struct drm_mode_modeinfo {
82 __u32 clock; 84 __u32 clock;
83 __u16 hdisplay, hsync_start, hsync_end, htotal, hskew; 85 __u16 hdisplay, hsync_start, hsync_end, htotal, hskew;
@@ -225,6 +227,45 @@ struct drm_mode_fb_cmd {
225 __u32 handle; 227 __u32 handle;
226}; 228};
227 229
230#define DRM_MODE_FB_DIRTY_ANNOTATE_COPY 0x01
231#define DRM_MODE_FB_DIRTY_ANNOTATE_FILL 0x02
232#define DRM_MODE_FB_DIRTY_FLAGS 0x03
233
234/*
235 * Mark a region of a framebuffer as dirty.
236 *
237 * Some hardware does not automatically update display contents
238 * as a hardware or software draw to a framebuffer. This ioctl
239 * allows userspace to tell the kernel and the hardware what
240 * regions of the framebuffer have changed.
241 *
242 * The kernel or hardware is free to update more then just the
243 * region specified by the clip rects. The kernel or hardware
244 * may also delay and/or coalesce several calls to dirty into a
245 * single update.
246 *
247 * Userspace may annotate the updates, the annotates are a
248 * promise made by the caller that the change is either a copy
249 * of pixels or a fill of a single color in the region specified.
250 *
251 * If the DRM_MODE_FB_DIRTY_ANNOTATE_COPY flag is given then
252 * the number of updated regions are half of num_clips given,
253 * where the clip rects are paired in src and dst. The width and
254 * height of each one of the pairs must match.
255 *
256 * If the DRM_MODE_FB_DIRTY_ANNOTATE_FILL flag is given the caller
257 * promises that the region specified of the clip rects is filled
258 * completely with a single color as given in the color argument.
259 */
260
261struct drm_mode_fb_dirty_cmd {
262 __u32 fb_id;
263 __u32 flags;
264 __u32 color;
265 __u32 num_clips;
266 __u64 clips_ptr;
267};
268
228struct drm_mode_mode_cmd { 269struct drm_mode_mode_cmd {
229 __u32 connector_id; 270 __u32 connector_id;
230 struct drm_mode_modeinfo mode; 271 struct drm_mode_modeinfo mode;
@@ -268,4 +309,37 @@ struct drm_mode_crtc_lut {
268 __u64 blue; 309 __u64 blue;
269}; 310};
270 311
312#define DRM_MODE_PAGE_FLIP_EVENT 0x01
313#define DRM_MODE_PAGE_FLIP_FLAGS DRM_MODE_PAGE_FLIP_EVENT
314
315/*
316 * Request a page flip on the specified crtc.
317 *
318 * This ioctl will ask KMS to schedule a page flip for the specified
319 * crtc. Once any pending rendering targeting the specified fb (as of
320 * ioctl time) has completed, the crtc will be reprogrammed to display
321 * that fb after the next vertical refresh. The ioctl returns
322 * immediately, but subsequent rendering to the current fb will block
323 * in the execbuffer ioctl until the page flip happens. If a page
324 * flip is already pending as the ioctl is called, EBUSY will be
325 * returned.
326 *
327 * The ioctl supports one flag, DRM_MODE_PAGE_FLIP_EVENT, which will
328 * request that drm sends back a vblank event (see drm.h: struct
329 * drm_event_vblank) when the page flip is done. The user_data field
330 * passed in with this ioctl will be returned as the user_data field
331 * in the vblank event struct.
332 *
333 * The reserved field must be zero until we figure out something
334 * clever to use it for.
335 */
336
337struct drm_mode_crtc_page_flip {
338 __u32 crtc_id;
339 __u32 fb_id;
340 __u32 flags;
341 __u32 reserved;
342 __u64 user_data;
343};
344
271#endif 345#endif
diff --git a/include/drm/i915_drm.h b/include/drm/i915_drm.h
index 7e0cb1da92e6..a04c3ab1d726 100644
--- a/include/drm/i915_drm.h
+++ b/include/drm/i915_drm.h
@@ -27,11 +27,11 @@
27#ifndef _I915_DRM_H_ 27#ifndef _I915_DRM_H_
28#define _I915_DRM_H_ 28#define _I915_DRM_H_
29 29
30#include "drm.h"
31
30/* Please note that modifications to all structs defined here are 32/* Please note that modifications to all structs defined here are
31 * subject to backwards-compatibility constraints. 33 * subject to backwards-compatibility constraints.
32 */ 34 */
33#include <linux/types.h>
34#include "drm.h"
35 35
36/* Each region is a minimum of 16k, and there are at most 255 of them. 36/* Each region is a minimum of 16k, and there are at most 255 of them.
37 */ 37 */
diff --git a/include/drm/mga_drm.h b/include/drm/mga_drm.h
index 325fd6fb4a42..3ffbc4798afa 100644
--- a/include/drm/mga_drm.h
+++ b/include/drm/mga_drm.h
@@ -35,7 +35,7 @@
35#ifndef __MGA_DRM_H__ 35#ifndef __MGA_DRM_H__
36#define __MGA_DRM_H__ 36#define __MGA_DRM_H__
37 37
38#include <linux/types.h> 38#include "drm.h"
39 39
40/* WARNING: If you change any of these defines, make sure to change the 40/* WARNING: If you change any of these defines, make sure to change the
41 * defines in the Xserver file (mga_sarea.h) 41 * defines in the Xserver file (mga_sarea.h)
diff --git a/include/drm/radeon_drm.h b/include/drm/radeon_drm.h
index 3b9932ab1756..39537f3cf98a 100644
--- a/include/drm/radeon_drm.h
+++ b/include/drm/radeon_drm.h
@@ -33,7 +33,7 @@
33#ifndef __RADEON_DRM_H__ 33#ifndef __RADEON_DRM_H__
34#define __RADEON_DRM_H__ 34#define __RADEON_DRM_H__
35 35
36#include <linux/types.h> 36#include "drm.h"
37 37
38/* WARNING: If you change any of these defines, make sure to change the 38/* WARNING: If you change any of these defines, make sure to change the
39 * defines in the X server file (radeon_sarea.h) 39 * defines in the X server file (radeon_sarea.h)
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index e8cd6d20aed2..7a39ab9aa1d1 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -545,6 +545,15 @@ extern int ttm_tt_set_user(struct ttm_tt *ttm,
545extern int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem); 545extern int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem);
546 546
547/** 547/**
548 * ttm_tt_populate:
549 *
550 * @ttm: The struct ttm_tt to contain the backing pages.
551 *
552 * Add backing pages to all of @ttm
553 */
554extern int ttm_tt_populate(struct ttm_tt *ttm);
555
556/**
548 * ttm_ttm_destroy: 557 * ttm_ttm_destroy:
549 * 558 *
550 * @ttm: The struct ttm_tt. 559 * @ttm: The struct ttm_tt.
diff --git a/include/drm/ttm/ttm_execbuf_util.h b/include/drm/ttm/ttm_execbuf_util.h
new file mode 100644
index 000000000000..cd2c475da9ea
--- /dev/null
+++ b/include/drm/ttm/ttm_execbuf_util.h
@@ -0,0 +1,107 @@
1/**************************************************************************
2 *
3 * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27/*
28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29 */
30
31#ifndef _TTM_EXECBUF_UTIL_H_
32#define _TTM_EXECBUF_UTIL_H_
33
34#include "ttm/ttm_bo_api.h"
35#include <linux/list.h>
36
37/**
38 * struct ttm_validate_buffer
39 *
40 * @head: list head for thread-private list.
41 * @bo: refcounted buffer object pointer.
42 * @new_sync_obj_arg: New sync_obj_arg for @bo, to be used once
43 * adding a new sync object.
44 * @reservied: Indicates whether @bo has been reserved for validation.
45 */
46
47struct ttm_validate_buffer {
48 struct list_head head;
49 struct ttm_buffer_object *bo;
50 void *new_sync_obj_arg;
51 bool reserved;
52};
53
54/**
55 * function ttm_eu_backoff_reservation
56 *
57 * @list: thread private list of ttm_validate_buffer structs.
58 *
59 * Undoes all buffer validation reservations for bos pointed to by
60 * the list entries.
61 */
62
63extern void ttm_eu_backoff_reservation(struct list_head *list);
64
65/**
66 * function ttm_eu_reserve_buffers
67 *
68 * @list: thread private list of ttm_validate_buffer structs.
69 * @val_seq: A unique sequence number.
70 *
71 * Tries to reserve bos pointed to by the list entries for validation.
72 * If the function returns 0, all buffers are marked as "unfenced",
73 * taken off the lru lists and are not synced for write CPU usage.
74 *
75 * If the function detects a deadlock due to multiple threads trying to
76 * reserve the same buffers in reverse order, all threads except one will
77 * back off and retry. This function may sleep while waiting for
78 * CPU write reservations to be cleared, and for other threads to
79 * unreserve their buffers.
80 *
81 * This function may return -ERESTART or -EAGAIN if the calling process
82 * receives a signal while waiting. In that case, no buffers on the list
83 * will be reserved upon return.
84 *
85 * Buffers reserved by this function should be unreserved by
86 * a call to either ttm_eu_backoff_reservation() or
87 * ttm_eu_fence_buffer_objects() when command submission is complete or
88 * has failed.
89 */
90
91extern int ttm_eu_reserve_buffers(struct list_head *list, uint32_t val_seq);
92
93/**
94 * function ttm_eu_fence_buffer_objects.
95 *
96 * @list: thread private list of ttm_validate_buffer structs.
97 * @sync_obj: The new sync object for the buffers.
98 *
99 * This function should be called when command submission is complete, and
100 * it will add a new sync object to bos pointed to by entries on @list.
101 * It also unreserves all buffers, putting them on lru lists.
102 *
103 */
104
105extern void ttm_eu_fence_buffer_objects(struct list_head *list, void *sync_obj);
106
107#endif
diff --git a/include/drm/ttm/ttm_lock.h b/include/drm/ttm/ttm_lock.h
new file mode 100644
index 000000000000..81ba0b0b891a
--- /dev/null
+++ b/include/drm/ttm/ttm_lock.h
@@ -0,0 +1,247 @@
1/**************************************************************************
2 *
3 * Copyright (c) 2007-2009 VMware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27/*
28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29 */
30
31/** @file ttm_lock.h
32 * This file implements a simple replacement for the buffer manager use
33 * of the DRM heavyweight hardware lock.
34 * The lock is a read-write lock. Taking it in read mode and write mode
35 * is relatively fast, and intended for in-kernel use only.
36 *
37 * The vt mode is used only when there is a need to block all
38 * user-space processes from validating buffers.
39 * It's allowed to leave kernel space with the vt lock held.
40 * If a user-space process dies while having the vt-lock,
41 * it will be released during the file descriptor release. The vt lock
42 * excludes write lock and read lock.
43 *
44 * The suspend mode is used to lock out all TTM users when preparing for
45 * and executing suspend operations.
46 *
47 */
48
49#ifndef _TTM_LOCK_H_
50#define _TTM_LOCK_H_
51
52#include "ttm/ttm_object.h"
53#include <linux/wait.h>
54#include <asm/atomic.h>
55
56/**
57 * struct ttm_lock
58 *
59 * @base: ttm base object used solely to release the lock if the client
60 * holding the lock dies.
61 * @queue: Queue for processes waiting for lock change-of-status.
62 * @lock: Spinlock protecting some lock members.
63 * @rw: Read-write lock counter. Protected by @lock.
64 * @flags: Lock state. Protected by @lock.
65 * @kill_takers: Boolean whether to kill takers of the lock.
66 * @signal: Signal to send when kill_takers is true.
67 */
68
69struct ttm_lock {
70 struct ttm_base_object base;
71 wait_queue_head_t queue;
72 spinlock_t lock;
73 int32_t rw;
74 uint32_t flags;
75 bool kill_takers;
76 int signal;
77 struct ttm_object_file *vt_holder;
78};
79
80
81/**
82 * ttm_lock_init
83 *
84 * @lock: Pointer to a struct ttm_lock
85 * Initializes the lock.
86 */
87extern void ttm_lock_init(struct ttm_lock *lock);
88
89/**
90 * ttm_read_unlock
91 *
92 * @lock: Pointer to a struct ttm_lock
93 *
94 * Releases a read lock.
95 */
96extern void ttm_read_unlock(struct ttm_lock *lock);
97
98/**
99 * ttm_read_lock
100 *
101 * @lock: Pointer to a struct ttm_lock
102 * @interruptible: Interruptible sleeping while waiting for a lock.
103 *
104 * Takes the lock in read mode.
105 * Returns:
106 * -ERESTARTSYS If interrupted by a signal and interruptible is true.
107 */
108extern int ttm_read_lock(struct ttm_lock *lock, bool interruptible);
109
110/**
111 * ttm_read_trylock
112 *
113 * @lock: Pointer to a struct ttm_lock
114 * @interruptible: Interruptible sleeping while waiting for a lock.
115 *
116 * Tries to take the lock in read mode. If the lock is already held
117 * in write mode, the function will return -EBUSY. If the lock is held
118 * in vt or suspend mode, the function will sleep until these modes
119 * are unlocked.
120 *
121 * Returns:
122 * -EBUSY The lock was already held in write mode.
123 * -ERESTARTSYS If interrupted by a signal and interruptible is true.
124 */
125extern int ttm_read_trylock(struct ttm_lock *lock, bool interruptible);
126
127/**
128 * ttm_write_unlock
129 *
130 * @lock: Pointer to a struct ttm_lock
131 *
132 * Releases a write lock.
133 */
134extern void ttm_write_unlock(struct ttm_lock *lock);
135
136/**
137 * ttm_write_lock
138 *
139 * @lock: Pointer to a struct ttm_lock
140 * @interruptible: Interruptible sleeping while waiting for a lock.
141 *
142 * Takes the lock in write mode.
143 * Returns:
144 * -ERESTARTSYS If interrupted by a signal and interruptible is true.
145 */
146extern int ttm_write_lock(struct ttm_lock *lock, bool interruptible);
147
148/**
149 * ttm_lock_downgrade
150 *
151 * @lock: Pointer to a struct ttm_lock
152 *
153 * Downgrades a write lock to a read lock.
154 */
155extern void ttm_lock_downgrade(struct ttm_lock *lock);
156
157/**
158 * ttm_suspend_lock
159 *
160 * @lock: Pointer to a struct ttm_lock
161 *
162 * Takes the lock in suspend mode. Excludes read and write mode.
163 */
164extern void ttm_suspend_lock(struct ttm_lock *lock);
165
166/**
167 * ttm_suspend_unlock
168 *
169 * @lock: Pointer to a struct ttm_lock
170 *
171 * Releases a suspend lock
172 */
173extern void ttm_suspend_unlock(struct ttm_lock *lock);
174
175/**
176 * ttm_vt_lock
177 *
178 * @lock: Pointer to a struct ttm_lock
179 * @interruptible: Interruptible sleeping while waiting for a lock.
180 * @tfile: Pointer to a struct ttm_object_file to register the lock with.
181 *
182 * Takes the lock in vt mode.
183 * Returns:
184 * -ERESTARTSYS If interrupted by a signal and interruptible is true.
185 * -ENOMEM: Out of memory when locking.
186 */
187extern int ttm_vt_lock(struct ttm_lock *lock, bool interruptible,
188 struct ttm_object_file *tfile);
189
190/**
191 * ttm_vt_unlock
192 *
193 * @lock: Pointer to a struct ttm_lock
194 *
195 * Releases a vt lock.
196 * Returns:
197 * -EINVAL If the lock was not held.
198 */
199extern int ttm_vt_unlock(struct ttm_lock *lock);
200
201/**
202 * ttm_write_unlock
203 *
204 * @lock: Pointer to a struct ttm_lock
205 *
206 * Releases a write lock.
207 */
208extern void ttm_write_unlock(struct ttm_lock *lock);
209
210/**
211 * ttm_write_lock
212 *
213 * @lock: Pointer to a struct ttm_lock
214 * @interruptible: Interruptible sleeping while waiting for a lock.
215 *
216 * Takes the lock in write mode.
217 * Returns:
218 * -ERESTARTSYS If interrupted by a signal and interruptible is true.
219 */
220extern int ttm_write_lock(struct ttm_lock *lock, bool interruptible);
221
222/**
223 * ttm_lock_set_kill
224 *
225 * @lock: Pointer to a struct ttm_lock
226 * @val: Boolean whether to kill processes taking the lock.
227 * @signal: Signal to send to the process taking the lock.
228 *
229 * The kill-when-taking-lock functionality is used to kill processes that keep
230 * on using the TTM functionality when its resources has been taken down, for
231 * example when the X server exits. A typical sequence would look like this:
232 * - X server takes lock in write mode.
233 * - ttm_lock_set_kill() is called with @val set to true.
234 * - As part of X server exit, TTM resources are taken down.
235 * - X server releases the lock on file release.
236 * - Another dri client wants to render, takes the lock and is killed.
237 *
238 */
239static inline void ttm_lock_set_kill(struct ttm_lock *lock, bool val,
240 int signal)
241{
242 lock->kill_takers = val;
243 if (val)
244 lock->signal = signal;
245}
246
247#endif
diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
index 6983a7cf4da4..b199170b3c2c 100644
--- a/include/drm/ttm/ttm_memory.h
+++ b/include/drm/ttm/ttm_memory.h
@@ -33,6 +33,7 @@
33#include <linux/wait.h> 33#include <linux/wait.h>
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/kobject.h> 35#include <linux/kobject.h>
36#include <linux/mm.h>
36 37
37/** 38/**
38 * struct ttm_mem_shrink - callback to shrink TTM memory usage. 39 * struct ttm_mem_shrink - callback to shrink TTM memory usage.
diff --git a/include/drm/ttm/ttm_object.h b/include/drm/ttm/ttm_object.h
new file mode 100644
index 000000000000..703ca4db0a29
--- /dev/null
+++ b/include/drm/ttm/ttm_object.h
@@ -0,0 +1,267 @@
1/**************************************************************************
2 *
3 * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27/*
28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29 */
30/** @file ttm_object.h
31 *
32 * Base- and reference object implementation for the various
33 * ttm objects. Implements reference counting, minimal security checks
34 * and release on file close.
35 */
36
37#ifndef _TTM_OBJECT_H_
38#define _TTM_OBJECT_H_
39
40#include <linux/list.h>
41#include "drm_hashtab.h"
42#include <linux/kref.h>
43#include <ttm/ttm_memory.h>
44
45/**
46 * enum ttm_ref_type
47 *
48 * Describes what type of reference a ref object holds.
49 *
50 * TTM_REF_USAGE is a simple refcount on a base object.
51 *
52 * TTM_REF_SYNCCPU_READ is a SYNCCPU_READ reference on a
53 * buffer object.
54 *
55 * TTM_REF_SYNCCPU_WRITE is a SYNCCPU_WRITE reference on a
56 * buffer object.
57 *
58 */
59
60enum ttm_ref_type {
61 TTM_REF_USAGE,
62 TTM_REF_SYNCCPU_READ,
63 TTM_REF_SYNCCPU_WRITE,
64 TTM_REF_NUM
65};
66
67/**
68 * enum ttm_object_type
69 *
70 * One entry per ttm object type.
71 * Device-specific types should use the
72 * ttm_driver_typex types.
73 */
74
75enum ttm_object_type {
76 ttm_fence_type,
77 ttm_buffer_type,
78 ttm_lock_type,
79 ttm_driver_type0 = 256,
80 ttm_driver_type1
81};
82
83struct ttm_object_file;
84struct ttm_object_device;
85
86/**
87 * struct ttm_base_object
88 *
89 * @hash: hash entry for the per-device object hash.
90 * @type: derived type this object is base class for.
91 * @shareable: Other ttm_object_files can access this object.
92 *
93 * @tfile: Pointer to ttm_object_file of the creator.
94 * NULL if the object was not created by a user request.
95 * (kernel object).
96 *
97 * @refcount: Number of references to this object, not
98 * including the hash entry. A reference to a base object can
99 * only be held by a ref object.
100 *
101 * @refcount_release: A function to be called when there are
102 * no more references to this object. This function should
103 * destroy the object (or make sure destruction eventually happens),
104 * and when it is called, the object has
105 * already been taken out of the per-device hash. The parameter
106 * "base" should be set to NULL by the function.
107 *
108 * @ref_obj_release: A function to be called when a reference object
109 * with another ttm_ref_type than TTM_REF_USAGE is deleted.
110 * this function may, for example, release a lock held by a user-space
111 * process.
112 *
113 * This struct is intended to be used as a base struct for objects that
114 * are visible to user-space. It provides a global name, race-safe
115 * access and refcounting, minimal access contol and hooks for unref actions.
116 */
117
118struct ttm_base_object {
119 struct drm_hash_item hash;
120 enum ttm_object_type object_type;
121 bool shareable;
122 struct ttm_object_file *tfile;
123 struct kref refcount;
124 void (*refcount_release) (struct ttm_base_object **base);
125 void (*ref_obj_release) (struct ttm_base_object *base,
126 enum ttm_ref_type ref_type);
127};
128
129/**
130 * ttm_base_object_init
131 *
132 * @tfile: Pointer to a struct ttm_object_file.
133 * @base: The struct ttm_base_object to initialize.
134 * @shareable: This object is shareable with other applcations.
135 * (different @tfile pointers.)
136 * @type: The object type.
137 * @refcount_release: See the struct ttm_base_object description.
138 * @ref_obj_release: See the struct ttm_base_object description.
139 *
140 * Initializes a struct ttm_base_object.
141 */
142
143extern int ttm_base_object_init(struct ttm_object_file *tfile,
144 struct ttm_base_object *base,
145 bool shareable,
146 enum ttm_object_type type,
147 void (*refcount_release) (struct ttm_base_object
148 **),
149 void (*ref_obj_release) (struct ttm_base_object
150 *,
151 enum ttm_ref_type
152 ref_type));
153
154/**
155 * ttm_base_object_lookup
156 *
157 * @tfile: Pointer to a struct ttm_object_file.
158 * @key: Hash key
159 *
160 * Looks up a struct ttm_base_object with the key @key.
161 * Also verifies that the object is visible to the application, by
162 * comparing the @tfile argument and checking the object shareable flag.
163 */
164
165extern struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file
166 *tfile, uint32_t key);
167
168/**
169 * ttm_base_object_unref
170 *
171 * @p_base: Pointer to a pointer referncing a struct ttm_base_object.
172 *
173 * Decrements the base object refcount and clears the pointer pointed to by
174 * p_base.
175 */
176
177extern void ttm_base_object_unref(struct ttm_base_object **p_base);
178
179/**
180 * ttm_ref_object_add.
181 *
182 * @tfile: A struct ttm_object_file representing the application owning the
183 * ref_object.
184 * @base: The base object to reference.
185 * @ref_type: The type of reference.
186 * @existed: Upon completion, indicates that an identical reference object
187 * already existed, and the refcount was upped on that object instead.
188 *
189 * Adding a ref object to a base object is basically like referencing the
190 * base object, but a user-space application holds the reference. When the
191 * file corresponding to @tfile is closed, all its reference objects are
192 * deleted. A reference object can have different types depending on what
193 * it's intended for. It can be refcounting to prevent object destruction,
194 * When user-space takes a lock, it can add a ref object to that lock to
195 * make sure the lock is released if the application dies. A ref object
196 * will hold a single reference on a base object.
197 */
198extern int ttm_ref_object_add(struct ttm_object_file *tfile,
199 struct ttm_base_object *base,
200 enum ttm_ref_type ref_type, bool *existed);
201/**
202 * ttm_ref_object_base_unref
203 *
204 * @key: Key representing the base object.
205 * @ref_type: Ref type of the ref object to be dereferenced.
206 *
207 * Unreference a ref object with type @ref_type
208 * on the base object identified by @key. If there are no duplicate
209 * references, the ref object will be destroyed and the base object
210 * will be unreferenced.
211 */
212extern int ttm_ref_object_base_unref(struct ttm_object_file *tfile,
213 unsigned long key,
214 enum ttm_ref_type ref_type);
215
216/**
217 * ttm_object_file_init - initialize a struct ttm_object file
218 *
219 * @tdev: A struct ttm_object device this file is initialized on.
220 * @hash_order: Order of the hash table used to hold the reference objects.
221 *
222 * This is typically called by the file_ops::open function.
223 */
224
225extern struct ttm_object_file *ttm_object_file_init(struct ttm_object_device
226 *tdev,
227 unsigned int hash_order);
228
229/**
230 * ttm_object_file_release - release data held by a ttm_object_file
231 *
232 * @p_tfile: Pointer to pointer to the ttm_object_file object to release.
233 * *p_tfile will be set to NULL by this function.
234 *
235 * Releases all data associated by a ttm_object_file.
236 * Typically called from file_ops::release. The caller must
237 * ensure that there are no concurrent users of tfile.
238 */
239
240extern void ttm_object_file_release(struct ttm_object_file **p_tfile);
241
242/**
243 * ttm_object device init - initialize a struct ttm_object_device
244 *
245 * @hash_order: Order of hash table used to hash the base objects.
246 *
247 * This function is typically called on device initialization to prepare
248 * data structures needed for ttm base and ref objects.
249 */
250
251extern struct ttm_object_device *ttm_object_device_init
252 (struct ttm_mem_global *mem_glob, unsigned int hash_order);
253
254/**
255 * ttm_object_device_release - release data held by a ttm_object_device
256 *
257 * @p_tdev: Pointer to pointer to the ttm_object_device object to release.
258 * *p_tdev will be set to NULL by this function.
259 *
260 * Releases all data associated by a ttm_object_device.
261 * Typically called from driver::unload before the destruction of the
262 * device private data structure.
263 */
264
265extern void ttm_object_device_release(struct ttm_object_device **p_tdev);
266
267#endif
diff --git a/include/drm/via_drm.h b/include/drm/via_drm.h
index 170786e5c2ff..fd11a5bd892d 100644
--- a/include/drm/via_drm.h
+++ b/include/drm/via_drm.h
@@ -24,7 +24,7 @@
24#ifndef _VIA_DRM_H_ 24#ifndef _VIA_DRM_H_
25#define _VIA_DRM_H_ 25#define _VIA_DRM_H_
26 26
27#include <linux/types.h> 27#include "drm.h"
28 28
29/* WARNING: These defines must be the same as what the Xserver uses. 29/* WARNING: These defines must be the same as what the Xserver uses.
30 * if you change them, you must change the defines in the Xserver. 30 * if you change them, you must change the defines in the Xserver.