[intel] Quirk away MSI support on 945G/GM.
[platform/upstream/libdrm.git] / linux-core / xgi_fence.c
1 /*
2  * (C) Copyright IBM Corporation 2007
3  * All Rights Reserved.
4  *
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:
11  *
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
14  * Software.
15  *
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.
23  *
24  * Authors:
25  *    Ian Romanick <idr@us.ibm.com>
26  */
27
28 #include "xgi_drv.h"
29 #include "xgi_regs.h"
30 #include "xgi_misc.h"
31 #include "xgi_cmdlist.h"
32
33 static void xgi_fence_poll(struct drm_device * dev, uint32_t class, 
34                            uint32_t waiting_types)
35 {
36         struct xgi_info * info = dev->dev_private;
37         uint32_t signaled_types = 0;
38
39
40         if ((info == NULL) || (class != 0))
41                 return;
42
43         DRM_SPINLOCK(&info->fence_lock);
44
45         if (waiting_types) {
46                 if (waiting_types & DRM_FENCE_TYPE_EXE) {
47                         const u32 begin_id = le32_to_cpu(DRM_READ32(info->mmio_map,
48                                                         0x2820))
49                                 & BEGIN_BEGIN_IDENTIFICATION_MASK;
50
51                         if (begin_id != info->complete_sequence) {
52                                 info->complete_sequence = begin_id;
53                                 signaled_types |= DRM_FENCE_TYPE_EXE;
54                         }
55                 }
56
57                 if (signaled_types) {
58                         drm_fence_handler(dev, 0, info->complete_sequence,
59                                           signaled_types, 0);
60                 }
61         }
62
63         DRM_SPINUNLOCK(&info->fence_lock);
64 }
65
66
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)
70 {
71         struct xgi_info * info = dev->dev_private;
72
73         if ((info == NULL) || (class != 0))
74                 return -EINVAL;
75
76
77         DRM_SPINLOCK(&info->fence_lock);
78         info->next_sequence++;
79         if (info->next_sequence > BEGIN_BEGIN_IDENTIFICATION_MASK) {
80                 info->next_sequence = 1;
81         }
82         DRM_SPINUNLOCK(&info->fence_lock);
83
84
85         xgi_emit_irq(info);
86
87         *sequence = (uint32_t) info->next_sequence;
88         *native_type = DRM_FENCE_TYPE_EXE;
89
90         return 0;
91 }
92
93
94 void xgi_fence_handler(struct drm_device * dev)
95 {
96         struct drm_fence_manager * fm = &dev->fm;
97         struct drm_fence_class_manager *fc = &fm->fence_class[0];
98
99         write_lock(&fm->lock);
100         xgi_fence_poll(dev, 0, fc->waiting_types);
101         write_unlock(&fm->lock);
102 }
103
104
105 int xgi_fence_has_irq(struct drm_device *dev, uint32_t class, uint32_t flags)
106 {
107         return ((class == 0) && (flags == DRM_FENCE_TYPE_EXE)) ? 1 : 0;
108 }
109
110 struct drm_fence_driver xgi_fence_driver = {
111         .num_classes = 1,
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,
117         .flush = NULL,
118         .poll = xgi_fence_poll,
119         .needed_flush = NULL,
120         .wait = NULL
121 };
122