2 * (C) Copyright IBM Corporation 2007
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
25 * Ian Romanick <idr@us.ibm.com>
31 #include "xgi_cmdlist.h"
33 static void xgi_fence_poll(struct drm_device * dev, uint32_t class,
34 uint32_t waiting_types)
36 struct xgi_info * info = dev->dev_private;
37 uint32_t signaled_types = 0;
40 if ((info == NULL) || (class != 0))
43 DRM_SPINLOCK(&info->fence_lock);
46 if (waiting_types & DRM_FENCE_TYPE_EXE) {
47 const u32 begin_id = le32_to_cpu(DRM_READ32(info->mmio_map,
49 & BEGIN_BEGIN_IDENTIFICATION_MASK;
51 if (begin_id != info->complete_sequence) {
52 info->complete_sequence = begin_id;
53 signaled_types |= DRM_FENCE_TYPE_EXE;
58 drm_fence_handler(dev, 0, info->complete_sequence,
63 DRM_SPINUNLOCK(&info->fence_lock);
67 int xgi_fence_emit_sequence(struct drm_device * dev, uint32_t class,
68 uint32_t flags, uint32_t * sequence,
69 uint32_t * native_type)
71 struct xgi_info * info = dev->dev_private;
73 if ((info == NULL) || (class != 0))
77 DRM_SPINLOCK(&info->fence_lock);
78 info->next_sequence++;
79 if (info->next_sequence > BEGIN_BEGIN_IDENTIFICATION_MASK) {
80 info->next_sequence = 1;
82 DRM_SPINUNLOCK(&info->fence_lock);
87 *sequence = (uint32_t) info->next_sequence;
88 *native_type = DRM_FENCE_TYPE_EXE;
94 void xgi_fence_handler(struct drm_device * dev)
96 struct drm_fence_manager * fm = &dev->fm;
97 struct drm_fence_class_manager *fc = &fm->fence_class[0];
99 write_lock(&fm->lock);
100 xgi_fence_poll(dev, 0, fc->waiting_types);
101 write_unlock(&fm->lock);
105 int xgi_fence_has_irq(struct drm_device *dev, uint32_t class, uint32_t flags)
107 return ((class == 0) && (flags == DRM_FENCE_TYPE_EXE)) ? 1 : 0;
110 struct drm_fence_driver xgi_fence_driver = {
112 .wrap_diff = BEGIN_BEGIN_IDENTIFICATION_MASK,
113 .flush_diff = BEGIN_BEGIN_IDENTIFICATION_MASK - 1,
114 .sequence_mask = BEGIN_BEGIN_IDENTIFICATION_MASK,
115 .has_irq = xgi_fence_has_irq,
116 .emit = xgi_fence_emit_sequence,
118 .poll = xgi_fence_poll,
119 .needed_flush = NULL,