LUT updates
[platform/upstream/libdrm.git] / linux-core / radeon_fence.c
1 /**************************************************************************
2  * 
3  * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
19  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
20  * USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  * 
26  * 
27  **************************************************************************/
28 /*
29  * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
30  */
31
32 #include "drmP.h"
33 #include "drm.h"
34 #include "radeon_drm.h"
35 #include "radeon_drv.h"
36
37 int radeon_fence_emit_sequence(struct drm_device *dev, uint32_t class,
38                                uint32_t flags, uint32_t *sequence,
39                                uint32_t *native_type)
40 {
41         struct drm_radeon_private *dev_priv = (struct drm_radeon_private *) dev->dev_private;
42         RING_LOCALS;
43
44         if (!dev_priv)
45                 return -EINVAL;
46
47         radeon_emit_irq(dev);
48         *sequence = (uint32_t) dev_priv->counter;
49         *native_type = DRM_FENCE_TYPE_EXE;
50
51         return 0;
52 }
53
54 static void radeon_fence_poll(struct drm_device *dev, uint32_t fence_class,
55                               uint32_t waiting_types)
56 {
57         struct drm_radeon_private *dev_priv = (struct drm_radeon_private *) dev->dev_private;
58         uint32_t sequence;
59         if (waiting_types & DRM_FENCE_TYPE_EXE) {
60
61                 sequence = READ_BREADCRUMB(dev_priv);
62
63                 drm_fence_handler(dev, 0, sequence,
64                                   DRM_FENCE_TYPE_EXE, 0);
65         }
66 }
67
68 void radeon_fence_handler(struct drm_device * dev)
69 {
70         struct drm_fence_manager *fm = &dev->fm;
71         struct drm_fence_class_manager *fc = &fm->fence_class[0];
72
73         write_lock(&fm->lock);
74         radeon_fence_poll(dev, 0, fc->waiting_types);
75         write_unlock(&fm->lock);
76 }
77
78 int radeon_fence_has_irq(struct drm_device *dev, uint32_t class, uint32_t flags)
79 {
80         /*
81          * We have an irq that tells us when we have a new breadcrumb.
82          */
83         return 1;
84 }
85
86
87 struct drm_fence_driver radeon_fence_driver = {
88         .num_classes = 1,
89         .wrap_diff = (1U << (BREADCRUMB_BITS -1)),
90         .flush_diff = (1U << (BREADCRUMB_BITS - 2)),
91         .sequence_mask = BREADCRUMB_MASK,
92         .emit = radeon_fence_emit_sequence,
93         .has_irq = radeon_fence_has_irq,
94         .poll = radeon_fence_poll,
95 };
96