2 * Copyright (c) 2007, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 * Authors: Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
26 static void psb_fence_poll(struct ttm_fence_device
*fdev
,
27 uint32_t fence_class
, uint32_t waiting_types
)
29 struct drm_psb_private
*dev_priv
=
30 container_of(fdev
, struct drm_psb_private
, fdev
);
33 if (unlikely(!dev_priv
))
36 if (waiting_types
== 0)
39 /* DRM_ERROR("Polling fence sequence, got 0x%08x\n", sequence); */
40 ttm_fence_handler(fdev
, fence_class
, 0 /* Sequence */,
41 _PSB_FENCE_TYPE_EXE
, 0);
44 void psb_fence_error(struct drm_device
*dev
,
46 uint32_t sequence
, uint32_t type
, int error
)
48 struct drm_psb_private
*dev_priv
= psb_priv(dev
);
49 struct ttm_fence_device
*fdev
= &dev_priv
->fdev
;
50 unsigned long irq_flags
;
51 struct ttm_fence_class_manager
*fc
=
52 &fdev
->fence_class
[fence_class
];
54 BUG_ON(fence_class
>= PSB_NUM_ENGINES
);
55 write_lock_irqsave(&fc
->lock
, irq_flags
);
56 ttm_fence_handler(fdev
, fence_class
, sequence
, type
, error
);
57 write_unlock_irqrestore(&fc
->lock
, irq_flags
);
60 int psb_fence_emit_sequence(struct ttm_fence_device
*fdev
,
62 uint32_t flags
, uint32_t *sequence
,
63 unsigned long *timeout_jiffies
)
65 struct drm_psb_private
*dev_priv
=
66 container_of(fdev
, struct drm_psb_private
, fdev
);
71 if (fence_class
>= PSB_NUM_ENGINES
)
74 DRM_ERROR("Unexpected fence class\n");
78 static void psb_fence_lockup(struct ttm_fence_object
*fence
,
81 DRM_ERROR("Unsupported fence class\n");
84 void psb_fence_handler(struct drm_device
*dev
, uint32_t fence_class
)
86 struct drm_psb_private
*dev_priv
= psb_priv(dev
);
87 struct ttm_fence_device
*fdev
= &dev_priv
->fdev
;
88 struct ttm_fence_class_manager
*fc
=
89 &fdev
->fence_class
[fence_class
];
90 unsigned long irq_flags
;
92 write_lock_irqsave(&fc
->lock
, irq_flags
);
93 psb_fence_poll(fdev
, fence_class
, fc
->waiting_types
);
94 write_unlock_irqrestore(&fc
->lock
, irq_flags
);
98 static struct ttm_fence_driver psb_ttm_fence_driver
= {
100 .emit
= psb_fence_emit_sequence
,
102 .poll
= psb_fence_poll
,
103 .needed_flush
= NULL
,
106 .lockup
= psb_fence_lockup
,
109 int psb_ttm_fence_device_init(struct ttm_fence_device
*fdev
)
111 struct drm_psb_private
*dev_priv
=
112 container_of(fdev
, struct drm_psb_private
, fdev
);
113 struct ttm_fence_class_init fci
= {.wrap_diff
= (1 << 30),
114 .flush_diff
= (1 << 29),
115 .sequence_mask
= 0xFFFFFFFF
118 return ttm_fence_device_init(PSB_NUM_ENGINES
,
119 dev_priv
->mem_global_ref
.object
,
121 &psb_ttm_fence_driver
);