Rev 5078 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5078 | Rev 6296 | ||
---|---|---|---|
1 | /************************************************************************** |
1 | /************************************************************************** |
2 | * |
2 | * |
3 | * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA |
3 | * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA |
4 | * All Rights Reserved. |
4 | * All Rights Reserved. |
5 | * |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the |
7 | * copy of this software and associated documentation files (the |
8 | * "Software"), to deal in the Software without restriction, including |
8 | * "Software"), to deal in the Software without restriction, including |
9 | * without limitation the rights to use, copy, modify, merge, publish, |
9 | * without limitation the rights to use, copy, modify, merge, publish, |
10 | * distribute, sub license, and/or sell copies of the Software, and to |
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 |
11 | * permit persons to whom the Software is furnished to do so, subject to |
12 | * the following conditions: |
12 | * the following conditions: |
13 | * |
13 | * |
14 | * The above copyright notice and this permission notice (including the |
14 | * The above copyright notice and this permission notice (including the |
15 | * next paragraph) shall be included in all copies or substantial portions |
15 | * next paragraph) shall be included in all copies or substantial portions |
16 | * of the Software. |
16 | * of the Software. |
17 | * |
17 | * |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
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, |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
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, |
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 |
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 |
23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
25 | * |
25 | * |
26 | **************************************************************************/ |
26 | **************************************************************************/ |
27 | #define mb() asm volatile("mfence" : : : "memory") |
- | |
28 | #define rmb() asm volatile("lfence" : : : "memory") |
- | |
29 | #define wmb() asm volatile("sfence" : : : "memory") |
- | |
30 | 27 | ||
31 | #include "vmwgfx_drv.h" |
28 | #include "vmwgfx_drv.h" |
32 | #include |
29 | #include |
33 | #include |
30 | #include |
34 | 31 | ||
- | 32 | struct vmw_temp_set_context { |
|
35 | #define TASK_INTERRUPTIBLE 1 |
33 | SVGA3dCmdHeader header; |
- | 34 | SVGA3dCmdDXTempSetContext body; |
|
36 | #define TASK_UNINTERRUPTIBLE 2 |
35 | }; |
37 | 36 | ||
38 | bool vmw_fifo_have_3d(struct vmw_private *dev_priv) |
37 | bool vmw_fifo_have_3d(struct vmw_private *dev_priv) |
39 | { |
38 | { |
40 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; |
39 | u32 *fifo_mem = dev_priv->mmio_virt; |
41 | uint32_t fifo_min, hwversion; |
40 | uint32_t fifo_min, hwversion; |
42 | const struct vmw_fifo_state *fifo = &dev_priv->fifo; |
41 | const struct vmw_fifo_state *fifo = &dev_priv->fifo; |
43 | 42 | ||
44 | if (!(dev_priv->capabilities & SVGA_CAP_3D)) |
43 | if (!(dev_priv->capabilities & SVGA_CAP_3D)) |
45 | return false; |
44 | return false; |
46 | 45 | ||
47 | if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS) { |
46 | if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS) { |
48 | uint32_t result; |
47 | uint32_t result; |
49 | 48 | ||
50 | if (!dev_priv->has_mob) |
49 | if (!dev_priv->has_mob) |
51 | return false; |
50 | return false; |
52 | 51 | ||
53 | mutex_lock(&dev_priv->hw_mutex); |
52 | spin_lock(&dev_priv->cap_lock); |
54 | vmw_write(dev_priv, SVGA_REG_DEV_CAP, SVGA3D_DEVCAP_3D); |
53 | vmw_write(dev_priv, SVGA_REG_DEV_CAP, SVGA3D_DEVCAP_3D); |
55 | result = vmw_read(dev_priv, SVGA_REG_DEV_CAP); |
54 | result = vmw_read(dev_priv, SVGA_REG_DEV_CAP); |
56 | mutex_unlock(&dev_priv->hw_mutex); |
55 | spin_unlock(&dev_priv->cap_lock); |
57 | 56 | ||
58 | return (result != 0); |
57 | return (result != 0); |
59 | } |
58 | } |
60 | 59 | ||
61 | if (!(dev_priv->capabilities & SVGA_CAP_EXTENDED_FIFO)) |
60 | if (!(dev_priv->capabilities & SVGA_CAP_EXTENDED_FIFO)) |
62 | return false; |
61 | return false; |
63 | 62 | ||
64 | fifo_min = ioread32(fifo_mem + SVGA_FIFO_MIN); |
63 | fifo_min = vmw_mmio_read(fifo_mem + SVGA_FIFO_MIN); |
65 | if (fifo_min <= SVGA_FIFO_3D_HWVERSION * sizeof(unsigned int)) |
64 | if (fifo_min <= SVGA_FIFO_3D_HWVERSION * sizeof(unsigned int)) |
66 | return false; |
65 | return false; |
67 | 66 | ||
68 | hwversion = ioread32(fifo_mem + |
67 | hwversion = vmw_mmio_read(fifo_mem + |
69 | ((fifo->capabilities & |
68 | ((fifo->capabilities & |
70 | SVGA_FIFO_CAP_3D_HWVERSION_REVISED) ? |
69 | SVGA_FIFO_CAP_3D_HWVERSION_REVISED) ? |
71 | SVGA_FIFO_3D_HWVERSION_REVISED : |
70 | SVGA_FIFO_3D_HWVERSION_REVISED : |
72 | SVGA_FIFO_3D_HWVERSION)); |
71 | SVGA_FIFO_3D_HWVERSION)); |
73 | 72 | ||
74 | if (hwversion == 0) |
73 | if (hwversion == 0) |
75 | return false; |
74 | return false; |
76 | 75 | ||
77 | if (hwversion < SVGA3D_HWVERSION_WS8_B1) |
76 | if (hwversion < SVGA3D_HWVERSION_WS8_B1) |
78 | return false; |
77 | return false; |
79 | 78 | ||
80 | /* Non-Screen Object path does not support surfaces */ |
79 | /* Legacy Display Unit does not support surfaces */ |
81 | if (!dev_priv->sou_priv) |
80 | if (dev_priv->active_display_unit == vmw_du_legacy) |
82 | return false; |
81 | return false; |
83 | 82 | ||
84 | return true; |
83 | return true; |
85 | } |
84 | } |
86 | 85 | ||
87 | bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv) |
86 | bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv) |
88 | { |
87 | { |
89 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; |
88 | u32 *fifo_mem = dev_priv->mmio_virt; |
90 | uint32_t caps; |
89 | uint32_t caps; |
91 | 90 | ||
92 | if (!(dev_priv->capabilities & SVGA_CAP_EXTENDED_FIFO)) |
91 | if (!(dev_priv->capabilities & SVGA_CAP_EXTENDED_FIFO)) |
93 | return false; |
92 | return false; |
94 | 93 | ||
95 | caps = ioread32(fifo_mem + SVGA_FIFO_CAPABILITIES); |
94 | caps = vmw_mmio_read(fifo_mem + SVGA_FIFO_CAPABILITIES); |
96 | if (caps & SVGA_FIFO_CAP_PITCHLOCK) |
95 | if (caps & SVGA_FIFO_CAP_PITCHLOCK) |
97 | return true; |
96 | return true; |
98 | 97 | ||
99 | return false; |
98 | return false; |
100 | } |
99 | } |
101 | 100 | ||
102 | int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo) |
101 | int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo) |
103 | { |
102 | { |
104 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; |
103 | u32 *fifo_mem = dev_priv->mmio_virt; |
105 | uint32_t max; |
104 | uint32_t max; |
106 | uint32_t min; |
105 | uint32_t min; |
107 | uint32_t dummy; |
- | |
- | 106 | ||
108 | 107 | fifo->dx = false; |
|
109 | fifo->static_buffer_size = VMWGFX_FIFO_STATIC_SIZE; |
108 | fifo->static_buffer_size = VMWGFX_FIFO_STATIC_SIZE; |
110 | fifo->static_buffer = KernelAlloc(fifo->static_buffer_size); |
109 | fifo->static_buffer = vmalloc(fifo->static_buffer_size); |
111 | if (unlikely(fifo->static_buffer == NULL)) |
110 | if (unlikely(fifo->static_buffer == NULL)) |
112 | return -ENOMEM; |
111 | return -ENOMEM; |
113 | 112 | ||
114 | fifo->dynamic_buffer = NULL; |
113 | fifo->dynamic_buffer = NULL; |
115 | fifo->reserved_size = 0; |
114 | fifo->reserved_size = 0; |
116 | fifo->using_bounce_buffer = false; |
115 | fifo->using_bounce_buffer = false; |
117 | 116 | ||
118 | mutex_init(&fifo->fifo_mutex); |
117 | mutex_init(&fifo->fifo_mutex); |
119 | // init_rwsem(&fifo->rwsem); |
118 | init_rwsem(&fifo->rwsem); |
120 | - | ||
121 | /* |
- | |
122 | * Allow mapping the first page read-only to user-space. |
- | |
123 | */ |
- | |
124 | 119 | ||
125 | DRM_INFO("width %d\n", vmw_read(dev_priv, SVGA_REG_WIDTH)); |
120 | DRM_INFO("width %d\n", vmw_read(dev_priv, SVGA_REG_WIDTH)); |
126 | DRM_INFO("height %d\n", vmw_read(dev_priv, SVGA_REG_HEIGHT)); |
121 | DRM_INFO("height %d\n", vmw_read(dev_priv, SVGA_REG_HEIGHT)); |
127 | DRM_INFO("bpp %d\n", vmw_read(dev_priv, SVGA_REG_BITS_PER_PIXEL)); |
122 | DRM_INFO("bpp %d\n", vmw_read(dev_priv, SVGA_REG_BITS_PER_PIXEL)); |
128 | - | ||
129 | mutex_lock(&dev_priv->hw_mutex); |
123 | |
130 | dev_priv->enable_state = vmw_read(dev_priv, SVGA_REG_ENABLE); |
124 | dev_priv->enable_state = vmw_read(dev_priv, SVGA_REG_ENABLE); |
131 | dev_priv->config_done_state = vmw_read(dev_priv, SVGA_REG_CONFIG_DONE); |
125 | dev_priv->config_done_state = vmw_read(dev_priv, SVGA_REG_CONFIG_DONE); |
132 | dev_priv->traces_state = vmw_read(dev_priv, SVGA_REG_TRACES); |
126 | dev_priv->traces_state = vmw_read(dev_priv, SVGA_REG_TRACES); |
- | 127 | ||
- | 128 | vmw_write(dev_priv, SVGA_REG_ENABLE, SVGA_REG_ENABLE_ENABLE | |
|
- | 129 | SVGA_REG_ENABLE_HIDE); |
|
133 | vmw_write(dev_priv, SVGA_REG_ENABLE, 1); |
130 | vmw_write(dev_priv, SVGA_REG_TRACES, 0); |
134 | 131 | ||
135 | min = 4; |
132 | min = 4; |
136 | if (dev_priv->capabilities & SVGA_CAP_EXTENDED_FIFO) |
133 | if (dev_priv->capabilities & SVGA_CAP_EXTENDED_FIFO) |
137 | min = vmw_read(dev_priv, SVGA_REG_MEM_REGS); |
134 | min = vmw_read(dev_priv, SVGA_REG_MEM_REGS); |
138 | min <<= 2; |
135 | min <<= 2; |
139 | 136 | ||
140 | if (min < PAGE_SIZE) |
137 | if (min < PAGE_SIZE) |
141 | min = PAGE_SIZE; |
138 | min = PAGE_SIZE; |
142 | 139 | ||
143 | iowrite32(min, fifo_mem + SVGA_FIFO_MIN); |
140 | vmw_mmio_write(min, fifo_mem + SVGA_FIFO_MIN); |
144 | iowrite32(dev_priv->mmio_size, fifo_mem + SVGA_FIFO_MAX); |
141 | vmw_mmio_write(dev_priv->mmio_size, fifo_mem + SVGA_FIFO_MAX); |
145 | wmb(); |
142 | wmb(); |
146 | iowrite32(min, fifo_mem + SVGA_FIFO_NEXT_CMD); |
143 | vmw_mmio_write(min, fifo_mem + SVGA_FIFO_NEXT_CMD); |
147 | iowrite32(min, fifo_mem + SVGA_FIFO_STOP); |
144 | vmw_mmio_write(min, fifo_mem + SVGA_FIFO_STOP); |
148 | iowrite32(0, fifo_mem + SVGA_FIFO_BUSY); |
145 | vmw_mmio_write(0, fifo_mem + SVGA_FIFO_BUSY); |
149 | mb(); |
146 | mb(); |
150 | 147 | ||
151 | vmw_write(dev_priv, SVGA_REG_CONFIG_DONE, 1); |
148 | vmw_write(dev_priv, SVGA_REG_CONFIG_DONE, 1); |
152 | mutex_unlock(&dev_priv->hw_mutex); |
- | |
153 | 149 | ||
154 | max = ioread32(fifo_mem + SVGA_FIFO_MAX); |
150 | max = vmw_mmio_read(fifo_mem + SVGA_FIFO_MAX); |
155 | min = ioread32(fifo_mem + SVGA_FIFO_MIN); |
151 | min = vmw_mmio_read(fifo_mem + SVGA_FIFO_MIN); |
156 | fifo->capabilities = ioread32(fifo_mem + SVGA_FIFO_CAPABILITIES); |
152 | fifo->capabilities = vmw_mmio_read(fifo_mem + SVGA_FIFO_CAPABILITIES); |
157 | 153 | ||
158 | DRM_INFO("Fifo max 0x%08x min 0x%08x cap 0x%08x\n", |
154 | DRM_INFO("Fifo max 0x%08x min 0x%08x cap 0x%08x\n", |
159 | (unsigned int) max, |
155 | (unsigned int) max, |
160 | (unsigned int) min, |
156 | (unsigned int) min, |
161 | (unsigned int) fifo->capabilities); |
157 | (unsigned int) fifo->capabilities); |
162 | 158 | ||
163 | atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno); |
159 | atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno); |
164 | iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE); |
160 | vmw_mmio_write(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE); |
165 | vmw_marker_queue_init(&fifo->marker_queue); |
161 | vmw_marker_queue_init(&fifo->marker_queue); |
166 | - | ||
167 | int ret = 0; //vmw_fifo_send_fence(dev_priv, &dummy); |
162 | |
168 | return ret; |
163 | return 0; |
169 | } |
164 | } |
170 | 165 | ||
171 | void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason) |
166 | void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason) |
172 | { |
167 | { |
173 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; |
168 | u32 *fifo_mem = dev_priv->mmio_virt; |
174 | 169 | ||
175 | mutex_lock(&dev_priv->hw_mutex); |
- | |
176 | 170 | preempt_disable(); |
|
177 | if (unlikely(ioread32(fifo_mem + SVGA_FIFO_BUSY) == 0)) { |
- | |
178 | iowrite32(1, fifo_mem + SVGA_FIFO_BUSY); |
171 | if (cmpxchg(fifo_mem + SVGA_FIFO_BUSY, 0, 1) == 0) |
179 | vmw_write(dev_priv, SVGA_REG_SYNC, reason); |
- | |
180 | } |
- | |
181 | 172 | vmw_write(dev_priv, SVGA_REG_SYNC, reason); |
|
182 | mutex_unlock(&dev_priv->hw_mutex); |
173 | preempt_enable(); |
183 | } |
174 | } |
184 | 175 | ||
185 | void vmw_fifo_release(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo) |
176 | void vmw_fifo_release(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo) |
186 | { |
177 | { |
187 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; |
178 | u32 *fifo_mem = dev_priv->mmio_virt; |
188 | - | ||
189 | mutex_lock(&dev_priv->hw_mutex); |
- | |
190 | - | ||
191 | while (vmw_read(dev_priv, SVGA_REG_BUSY) != 0) |
179 | |
- | 180 | vmw_write(dev_priv, SVGA_REG_SYNC, SVGA_SYNC_GENERIC); |
|
- | 181 | while (vmw_read(dev_priv, SVGA_REG_BUSY) != 0) |
|
192 | vmw_write(dev_priv, SVGA_REG_SYNC, SVGA_SYNC_GENERIC); |
182 | ; |
193 | 183 | ||
194 | dev_priv->last_read_seqno = ioread32(fifo_mem + SVGA_FIFO_FENCE); |
184 | dev_priv->last_read_seqno = vmw_mmio_read(fifo_mem + SVGA_FIFO_FENCE); |
195 | 185 | ||
196 | vmw_write(dev_priv, SVGA_REG_CONFIG_DONE, |
186 | vmw_write(dev_priv, SVGA_REG_CONFIG_DONE, |
197 | dev_priv->config_done_state); |
187 | dev_priv->config_done_state); |
198 | vmw_write(dev_priv, SVGA_REG_ENABLE, |
188 | vmw_write(dev_priv, SVGA_REG_ENABLE, |
199 | dev_priv->enable_state); |
189 | dev_priv->enable_state); |
200 | vmw_write(dev_priv, SVGA_REG_TRACES, |
190 | vmw_write(dev_priv, SVGA_REG_TRACES, |
201 | dev_priv->traces_state); |
191 | dev_priv->traces_state); |
202 | - | ||
203 | mutex_unlock(&dev_priv->hw_mutex); |
192 | |
204 | vmw_marker_queue_takedown(&fifo->marker_queue); |
193 | vmw_marker_queue_takedown(&fifo->marker_queue); |
205 | 194 | ||
206 | if (likely(fifo->static_buffer != NULL)) { |
195 | if (likely(fifo->static_buffer != NULL)) { |
207 | vfree(fifo->static_buffer); |
196 | vfree(fifo->static_buffer); |
208 | fifo->static_buffer = NULL; |
197 | fifo->static_buffer = NULL; |
209 | } |
198 | } |
210 | 199 | ||
211 | if (likely(fifo->dynamic_buffer != NULL)) { |
200 | if (likely(fifo->dynamic_buffer != NULL)) { |
212 | vfree(fifo->dynamic_buffer); |
201 | vfree(fifo->dynamic_buffer); |
213 | fifo->dynamic_buffer = NULL; |
202 | fifo->dynamic_buffer = NULL; |
214 | } |
203 | } |
215 | } |
204 | } |
216 | 205 | ||
217 | static bool vmw_fifo_is_full(struct vmw_private *dev_priv, uint32_t bytes) |
206 | static bool vmw_fifo_is_full(struct vmw_private *dev_priv, uint32_t bytes) |
218 | { |
207 | { |
219 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; |
208 | u32 *fifo_mem = dev_priv->mmio_virt; |
220 | uint32_t max = ioread32(fifo_mem + SVGA_FIFO_MAX); |
209 | uint32_t max = vmw_mmio_read(fifo_mem + SVGA_FIFO_MAX); |
221 | uint32_t next_cmd = ioread32(fifo_mem + SVGA_FIFO_NEXT_CMD); |
210 | uint32_t next_cmd = vmw_mmio_read(fifo_mem + SVGA_FIFO_NEXT_CMD); |
222 | uint32_t min = ioread32(fifo_mem + SVGA_FIFO_MIN); |
211 | uint32_t min = vmw_mmio_read(fifo_mem + SVGA_FIFO_MIN); |
223 | uint32_t stop = ioread32(fifo_mem + SVGA_FIFO_STOP); |
212 | uint32_t stop = vmw_mmio_read(fifo_mem + SVGA_FIFO_STOP); |
224 | 213 | ||
225 | return ((max - next_cmd) + (stop - min) <= bytes); |
214 | return ((max - next_cmd) + (stop - min) <= bytes); |
226 | } |
215 | } |
227 | 216 | ||
228 | static int vmw_fifo_wait_noirq(struct vmw_private *dev_priv, |
217 | static int vmw_fifo_wait_noirq(struct vmw_private *dev_priv, |
229 | uint32_t bytes, bool interruptible, |
218 | uint32_t bytes, bool interruptible, |
230 | unsigned long timeout) |
219 | unsigned long timeout) |
231 | { |
220 | { |
232 | int ret = 0; |
221 | int ret = 0; |
233 | unsigned long end_jiffies = jiffies + timeout; |
222 | unsigned long end_jiffies = jiffies + timeout; |
234 | // DEFINE_WAIT(__wait); |
223 | // DEFINE_WAIT(__wait); |
235 | 224 | ||
236 | DRM_INFO("Fifo wait noirq.\n"); |
225 | DRM_INFO("Fifo wait noirq.\n"); |
237 | 226 | ||
238 | for (;;) { |
227 | for (;;) { |
239 | // prepare_to_wait(&dev_priv->fifo_queue, &__wait, |
228 | // prepare_to_wait(&dev_priv->fifo_queue, &__wait, |
240 | // (interruptible) ? |
229 | // (interruptible) ? |
241 | // TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); |
230 | // TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); |
242 | if (!vmw_fifo_is_full(dev_priv, bytes)) |
231 | if (!vmw_fifo_is_full(dev_priv, bytes)) |
243 | break; |
232 | break; |
244 | if (time_after_eq(jiffies, end_jiffies)) { |
233 | if (time_after_eq(jiffies, end_jiffies)) { |
245 | ret = -EBUSY; |
234 | ret = -EBUSY; |
246 | DRM_ERROR("SVGA device lockup.\n"); |
235 | DRM_ERROR("SVGA device lockup.\n"); |
247 | break; |
236 | break; |
248 | } |
237 | } |
249 | delay(1); |
238 | delay(1); |
250 | } |
239 | } |
251 | // finish_wait(&dev_priv->fifo_queue, &__wait); |
240 | // finish_wait(&dev_priv->fifo_queue, &__wait); |
252 | wake_up_all(&dev_priv->fifo_queue); |
241 | wake_up_all(&dev_priv->fifo_queue); |
253 | DRM_INFO("Fifo noirq exit.\n"); |
242 | DRM_INFO("Fifo noirq exit.\n"); |
254 | return ret; |
243 | return ret; |
255 | } |
244 | } |
256 | 245 | ||
257 | static int vmw_fifo_wait(struct vmw_private *dev_priv, |
246 | static int vmw_fifo_wait(struct vmw_private *dev_priv, |
258 | uint32_t bytes, bool interruptible, |
247 | uint32_t bytes, bool interruptible, |
259 | unsigned long timeout) |
248 | unsigned long timeout) |
260 | { |
249 | { |
261 | long ret = 1L; |
250 | long ret = 1L; |
262 | unsigned long irq_flags; |
- | |
263 | 251 | ||
264 | if (likely(!vmw_fifo_is_full(dev_priv, bytes))) |
252 | if (likely(!vmw_fifo_is_full(dev_priv, bytes))) |
265 | return 0; |
253 | return 0; |
266 | 254 | ||
267 | vmw_fifo_ping_host(dev_priv, SVGA_SYNC_FIFOFULL); |
255 | vmw_fifo_ping_host(dev_priv, SVGA_SYNC_FIFOFULL); |
268 | if (!(dev_priv->capabilities & SVGA_CAP_IRQMASK)) |
256 | if (!(dev_priv->capabilities & SVGA_CAP_IRQMASK)) |
269 | return vmw_fifo_wait_noirq(dev_priv, bytes, |
257 | return vmw_fifo_wait_noirq(dev_priv, bytes, |
270 | interruptible, timeout); |
258 | interruptible, timeout); |
271 | - | ||
272 | mutex_lock(&dev_priv->hw_mutex); |
- | |
273 | if (atomic_add_return(1, &dev_priv->fifo_queue_waiters) > 0) { |
- | |
274 | spin_lock_irqsave(&dev_priv->irq_lock, irq_flags); |
- | |
275 | outl(SVGA_IRQFLAG_FIFO_PROGRESS, |
- | |
276 | dev_priv->io_start + VMWGFX_IRQSTATUS_PORT); |
259 | |
277 | dev_priv->irq_mask |= SVGA_IRQFLAG_FIFO_PROGRESS; |
- | |
278 | vmw_write(dev_priv, SVGA_REG_IRQMASK, dev_priv->irq_mask); |
- | |
279 | spin_unlock_irqrestore(&dev_priv->irq_lock, irq_flags); |
- | |
280 | } |
260 | vmw_generic_waiter_add(dev_priv, SVGA_IRQFLAG_FIFO_PROGRESS, |
281 | mutex_unlock(&dev_priv->hw_mutex); |
261 | &dev_priv->fifo_queue_waiters); |
282 | 262 | ||
283 | if (interruptible) |
263 | if (interruptible) |
284 | ret = wait_event_interruptible_timeout |
264 | ret = wait_event_interruptible_timeout |
285 | (dev_priv->fifo_queue, |
265 | (dev_priv->fifo_queue, |
286 | !vmw_fifo_is_full(dev_priv, bytes), timeout); |
266 | !vmw_fifo_is_full(dev_priv, bytes), timeout); |
287 | else |
267 | else |
288 | ret = wait_event_timeout |
268 | ret = wait_event_timeout |
289 | (dev_priv->fifo_queue, |
269 | (dev_priv->fifo_queue, |
290 | !vmw_fifo_is_full(dev_priv, bytes), timeout); |
270 | !vmw_fifo_is_full(dev_priv, bytes), timeout); |
291 | 271 | ||
292 | if (unlikely(ret == 0)) |
272 | if (unlikely(ret == 0)) |
293 | ret = -EBUSY; |
273 | ret = -EBUSY; |
294 | else if (likely(ret > 0)) |
274 | else if (likely(ret > 0)) |
295 | ret = 0; |
275 | ret = 0; |
296 | - | ||
297 | mutex_lock(&dev_priv->hw_mutex); |
- | |
298 | if (atomic_dec_and_test(&dev_priv->fifo_queue_waiters)) { |
- | |
299 | spin_lock_irqsave(&dev_priv->irq_lock, irq_flags); |
276 | |
300 | dev_priv->irq_mask &= ~SVGA_IRQFLAG_FIFO_PROGRESS; |
- | |
301 | vmw_write(dev_priv, SVGA_REG_IRQMASK, dev_priv->irq_mask); |
- | |
302 | spin_unlock_irqrestore(&dev_priv->irq_lock, irq_flags); |
- | |
303 | } |
277 | vmw_generic_waiter_remove(dev_priv, SVGA_IRQFLAG_FIFO_PROGRESS, |
304 | mutex_unlock(&dev_priv->hw_mutex); |
278 | &dev_priv->fifo_queue_waiters); |
305 | 279 | ||
306 | return ret; |
280 | return ret; |
307 | } |
281 | } |
308 | 282 | ||
309 | /** |
283 | /** |
310 | * Reserve @bytes number of bytes in the fifo. |
284 | * Reserve @bytes number of bytes in the fifo. |
311 | * |
285 | * |
312 | * This function will return NULL (error) on two conditions: |
286 | * This function will return NULL (error) on two conditions: |
313 | * If it timeouts waiting for fifo space, or if @bytes is larger than the |
287 | * If it timeouts waiting for fifo space, or if @bytes is larger than the |
314 | * available fifo space. |
288 | * available fifo space. |
315 | * |
289 | * |
316 | * Returns: |
290 | * Returns: |
317 | * Pointer to the fifo, or null on error (possible hardware hang). |
291 | * Pointer to the fifo, or null on error (possible hardware hang). |
318 | */ |
292 | */ |
319 | void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes) |
293 | static void *vmw_local_fifo_reserve(struct vmw_private *dev_priv, |
- | 294 | uint32_t bytes) |
|
320 | { |
295 | { |
321 | struct vmw_fifo_state *fifo_state = &dev_priv->fifo; |
296 | struct vmw_fifo_state *fifo_state = &dev_priv->fifo; |
322 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; |
297 | u32 *fifo_mem = dev_priv->mmio_virt; |
323 | uint32_t max; |
298 | uint32_t max; |
324 | uint32_t min; |
299 | uint32_t min; |
325 | uint32_t next_cmd; |
300 | uint32_t next_cmd; |
326 | uint32_t reserveable = fifo_state->capabilities & SVGA_FIFO_CAP_RESERVE; |
301 | uint32_t reserveable = fifo_state->capabilities & SVGA_FIFO_CAP_RESERVE; |
327 | int ret; |
302 | int ret; |
328 | 303 | ||
329 | mutex_lock(&fifo_state->fifo_mutex); |
304 | mutex_lock(&fifo_state->fifo_mutex); |
330 | max = ioread32(fifo_mem + SVGA_FIFO_MAX); |
305 | max = vmw_mmio_read(fifo_mem + SVGA_FIFO_MAX); |
331 | min = ioread32(fifo_mem + SVGA_FIFO_MIN); |
306 | min = vmw_mmio_read(fifo_mem + SVGA_FIFO_MIN); |
332 | next_cmd = ioread32(fifo_mem + SVGA_FIFO_NEXT_CMD); |
307 | next_cmd = vmw_mmio_read(fifo_mem + SVGA_FIFO_NEXT_CMD); |
333 | 308 | ||
334 | if (unlikely(bytes >= (max - min))) |
309 | if (unlikely(bytes >= (max - min))) |
335 | goto out_err; |
310 | goto out_err; |
336 | 311 | ||
337 | BUG_ON(fifo_state->reserved_size != 0); |
312 | BUG_ON(fifo_state->reserved_size != 0); |
338 | BUG_ON(fifo_state->dynamic_buffer != NULL); |
313 | BUG_ON(fifo_state->dynamic_buffer != NULL); |
339 | 314 | ||
340 | fifo_state->reserved_size = bytes; |
315 | fifo_state->reserved_size = bytes; |
341 | 316 | ||
342 | while (1) { |
317 | while (1) { |
343 | uint32_t stop = ioread32(fifo_mem + SVGA_FIFO_STOP); |
318 | uint32_t stop = vmw_mmio_read(fifo_mem + SVGA_FIFO_STOP); |
344 | bool need_bounce = false; |
319 | bool need_bounce = false; |
345 | bool reserve_in_place = false; |
320 | bool reserve_in_place = false; |
346 | 321 | ||
347 | if (next_cmd >= stop) { |
322 | if (next_cmd >= stop) { |
348 | if (likely((next_cmd + bytes < max || |
323 | if (likely((next_cmd + bytes < max || |
349 | (next_cmd + bytes == max && stop > min)))) |
324 | (next_cmd + bytes == max && stop > min)))) |
350 | reserve_in_place = true; |
325 | reserve_in_place = true; |
351 | 326 | ||
352 | else if (vmw_fifo_is_full(dev_priv, bytes)) { |
327 | else if (vmw_fifo_is_full(dev_priv, bytes)) { |
353 | ret = vmw_fifo_wait(dev_priv, bytes, |
328 | ret = vmw_fifo_wait(dev_priv, bytes, |
354 | false, 3 * HZ); |
329 | false, 3 * HZ); |
355 | if (unlikely(ret != 0)) |
330 | if (unlikely(ret != 0)) |
356 | goto out_err; |
331 | goto out_err; |
357 | } else |
332 | } else |
358 | need_bounce = true; |
333 | need_bounce = true; |
359 | 334 | ||
360 | } else { |
335 | } else { |
361 | 336 | ||
362 | if (likely((next_cmd + bytes < stop))) |
337 | if (likely((next_cmd + bytes < stop))) |
363 | reserve_in_place = true; |
338 | reserve_in_place = true; |
364 | else { |
339 | else { |
365 | ret = vmw_fifo_wait(dev_priv, bytes, |
340 | ret = vmw_fifo_wait(dev_priv, bytes, |
366 | false, 3 * HZ); |
341 | false, 3 * HZ); |
367 | if (unlikely(ret != 0)) |
342 | if (unlikely(ret != 0)) |
368 | goto out_err; |
343 | goto out_err; |
369 | } |
344 | } |
370 | } |
345 | } |
371 | 346 | ||
372 | if (reserve_in_place) { |
347 | if (reserve_in_place) { |
373 | if (reserveable || bytes <= sizeof(uint32_t)) { |
348 | if (reserveable || bytes <= sizeof(uint32_t)) { |
374 | fifo_state->using_bounce_buffer = false; |
349 | fifo_state->using_bounce_buffer = false; |
375 | 350 | ||
376 | if (reserveable) |
351 | if (reserveable) |
377 | iowrite32(bytes, fifo_mem + |
352 | vmw_mmio_write(bytes, fifo_mem + |
378 | SVGA_FIFO_RESERVED); |
353 | SVGA_FIFO_RESERVED); |
- | 354 | return (void __force *) (fifo_mem + |
|
379 | return fifo_mem + (next_cmd >> 2); |
355 | (next_cmd >> 2)); |
380 | } else { |
356 | } else { |
381 | need_bounce = true; |
357 | need_bounce = true; |
382 | } |
358 | } |
383 | } |
359 | } |
384 | 360 | ||
385 | if (need_bounce) { |
361 | if (need_bounce) { |
386 | fifo_state->using_bounce_buffer = true; |
362 | fifo_state->using_bounce_buffer = true; |
387 | if (bytes < fifo_state->static_buffer_size) |
363 | if (bytes < fifo_state->static_buffer_size) |
388 | return fifo_state->static_buffer; |
364 | return fifo_state->static_buffer; |
389 | else { |
365 | else { |
390 | fifo_state->dynamic_buffer = kmalloc(bytes,0); |
366 | fifo_state->dynamic_buffer = vmalloc(bytes); |
391 | return fifo_state->dynamic_buffer; |
367 | return fifo_state->dynamic_buffer; |
392 | } |
368 | } |
393 | } |
369 | } |
394 | } |
370 | } |
395 | out_err: |
371 | out_err: |
396 | fifo_state->reserved_size = 0; |
372 | fifo_state->reserved_size = 0; |
397 | mutex_unlock(&fifo_state->fifo_mutex); |
373 | mutex_unlock(&fifo_state->fifo_mutex); |
- | 374 | ||
- | 375 | return NULL; |
|
- | 376 | } |
|
- | 377 | ||
- | 378 | void *vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, |
|
- | 379 | int ctx_id) |
|
- | 380 | { |
|
- | 381 | void *ret; |
|
- | 382 | ||
- | 383 | if (dev_priv->cman) |
|
- | 384 | ret = vmw_cmdbuf_reserve(dev_priv->cman, bytes, |
|
- | 385 | ctx_id, false, NULL); |
|
- | 386 | else if (ctx_id == SVGA3D_INVALID_ID) |
|
- | 387 | ret = vmw_local_fifo_reserve(dev_priv, bytes); |
|
- | 388 | else { |
|
- | 389 | WARN(1, "Command buffer has not been allocated.\n"); |
|
- | 390 | ret = NULL; |
|
- | 391 | } |
|
- | 392 | if (IS_ERR_OR_NULL(ret)) { |
|
- | 393 | DRM_ERROR("Fifo reserve failure of %u bytes.\n", |
|
- | 394 | (unsigned) bytes); |
|
- | 395 | // dump_stack(); |
|
398 | return NULL; |
396 | return NULL; |
399 | } |
397 | } |
- | 398 | ||
- | 399 | return ret; |
|
- | 400 | } |
|
400 | 401 | ||
401 | static void vmw_fifo_res_copy(struct vmw_fifo_state *fifo_state, |
402 | static void vmw_fifo_res_copy(struct vmw_fifo_state *fifo_state, |
402 | __le32 __iomem *fifo_mem, |
403 | u32 *fifo_mem, |
403 | uint32_t next_cmd, |
404 | uint32_t next_cmd, |
404 | uint32_t max, uint32_t min, uint32_t bytes) |
405 | uint32_t max, uint32_t min, uint32_t bytes) |
405 | { |
406 | { |
406 | uint32_t chunk_size = max - next_cmd; |
407 | uint32_t chunk_size = max - next_cmd; |
407 | uint32_t rest; |
408 | uint32_t rest; |
408 | uint32_t *buffer = (fifo_state->dynamic_buffer != NULL) ? |
409 | uint32_t *buffer = (fifo_state->dynamic_buffer != NULL) ? |
409 | fifo_state->dynamic_buffer : fifo_state->static_buffer; |
410 | fifo_state->dynamic_buffer : fifo_state->static_buffer; |
410 | 411 | ||
411 | if (bytes < chunk_size) |
412 | if (bytes < chunk_size) |
412 | chunk_size = bytes; |
413 | chunk_size = bytes; |
413 | 414 | ||
414 | iowrite32(bytes, fifo_mem + SVGA_FIFO_RESERVED); |
415 | vmw_mmio_write(bytes, fifo_mem + SVGA_FIFO_RESERVED); |
415 | mb(); |
416 | mb(); |
416 | memcpy(fifo_mem + (next_cmd >> 2), buffer, chunk_size); |
417 | memcpy(fifo_mem + (next_cmd >> 2), buffer, chunk_size); |
417 | rest = bytes - chunk_size; |
418 | rest = bytes - chunk_size; |
418 | if (rest) |
419 | if (rest) |
419 | memcpy(fifo_mem + (min >> 2), buffer + (chunk_size >> 2), |
420 | memcpy(fifo_mem + (min >> 2), buffer + (chunk_size >> 2), rest); |
420 | rest); |
- | |
421 | } |
421 | } |
422 | 422 | ||
423 | static void vmw_fifo_slow_copy(struct vmw_fifo_state *fifo_state, |
423 | static void vmw_fifo_slow_copy(struct vmw_fifo_state *fifo_state, |
424 | __le32 __iomem *fifo_mem, |
424 | u32 *fifo_mem, |
425 | uint32_t next_cmd, |
425 | uint32_t next_cmd, |
426 | uint32_t max, uint32_t min, uint32_t bytes) |
426 | uint32_t max, uint32_t min, uint32_t bytes) |
427 | { |
427 | { |
428 | uint32_t *buffer = (fifo_state->dynamic_buffer != NULL) ? |
428 | uint32_t *buffer = (fifo_state->dynamic_buffer != NULL) ? |
429 | fifo_state->dynamic_buffer : fifo_state->static_buffer; |
429 | fifo_state->dynamic_buffer : fifo_state->static_buffer; |
430 | 430 | ||
431 | while (bytes > 0) { |
431 | while (bytes > 0) { |
432 | iowrite32(*buffer++, fifo_mem + (next_cmd >> 2)); |
432 | vmw_mmio_write(*buffer++, fifo_mem + (next_cmd >> 2)); |
433 | next_cmd += sizeof(uint32_t); |
433 | next_cmd += sizeof(uint32_t); |
434 | if (unlikely(next_cmd == max)) |
434 | if (unlikely(next_cmd == max)) |
435 | next_cmd = min; |
435 | next_cmd = min; |
436 | mb(); |
436 | mb(); |
437 | iowrite32(next_cmd, fifo_mem + SVGA_FIFO_NEXT_CMD); |
437 | vmw_mmio_write(next_cmd, fifo_mem + SVGA_FIFO_NEXT_CMD); |
438 | mb(); |
438 | mb(); |
439 | bytes -= sizeof(uint32_t); |
439 | bytes -= sizeof(uint32_t); |
440 | } |
440 | } |
441 | } |
441 | } |
442 | 442 | ||
443 | void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes) |
443 | static void vmw_local_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes) |
444 | { |
444 | { |
445 | struct vmw_fifo_state *fifo_state = &dev_priv->fifo; |
445 | struct vmw_fifo_state *fifo_state = &dev_priv->fifo; |
446 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; |
446 | u32 *fifo_mem = dev_priv->mmio_virt; |
447 | uint32_t next_cmd = ioread32(fifo_mem + SVGA_FIFO_NEXT_CMD); |
447 | uint32_t next_cmd = vmw_mmio_read(fifo_mem + SVGA_FIFO_NEXT_CMD); |
448 | uint32_t max = ioread32(fifo_mem + SVGA_FIFO_MAX); |
448 | uint32_t max = vmw_mmio_read(fifo_mem + SVGA_FIFO_MAX); |
449 | uint32_t min = ioread32(fifo_mem + SVGA_FIFO_MIN); |
449 | uint32_t min = vmw_mmio_read(fifo_mem + SVGA_FIFO_MIN); |
- | 450 | bool reserveable = fifo_state->capabilities & SVGA_FIFO_CAP_RESERVE; |
|
- | 451 | ||
- | 452 | if (fifo_state->dx) |
|
- | 453 | bytes += sizeof(struct vmw_temp_set_context); |
|
450 | bool reserveable = fifo_state->capabilities & SVGA_FIFO_CAP_RESERVE; |
454 | |
451 | 455 | fifo_state->dx = false; |
|
452 | BUG_ON((bytes & 3) != 0); |
456 | BUG_ON((bytes & 3) != 0); |
453 | BUG_ON(bytes > fifo_state->reserved_size); |
457 | BUG_ON(bytes > fifo_state->reserved_size); |
454 | 458 | ||
455 | fifo_state->reserved_size = 0; |
459 | fifo_state->reserved_size = 0; |
456 | 460 | ||
457 | if (fifo_state->using_bounce_buffer) { |
461 | if (fifo_state->using_bounce_buffer) { |
458 | if (reserveable) |
462 | if (reserveable) |
459 | vmw_fifo_res_copy(fifo_state, fifo_mem, |
463 | vmw_fifo_res_copy(fifo_state, fifo_mem, |
460 | next_cmd, max, min, bytes); |
464 | next_cmd, max, min, bytes); |
461 | else |
465 | else |
462 | vmw_fifo_slow_copy(fifo_state, fifo_mem, |
466 | vmw_fifo_slow_copy(fifo_state, fifo_mem, |
463 | next_cmd, max, min, bytes); |
467 | next_cmd, max, min, bytes); |
464 | 468 | ||
465 | if (fifo_state->dynamic_buffer) { |
469 | if (fifo_state->dynamic_buffer) { |
466 | vfree(fifo_state->dynamic_buffer); |
470 | vfree(fifo_state->dynamic_buffer); |
467 | fifo_state->dynamic_buffer = NULL; |
471 | fifo_state->dynamic_buffer = NULL; |
468 | } |
472 | } |
469 | 473 | ||
470 | } |
474 | } |
471 | 475 | ||
472 | // down_write(&fifo_state->rwsem); |
476 | down_write(&fifo_state->rwsem); |
473 | if (fifo_state->using_bounce_buffer || reserveable) { |
477 | if (fifo_state->using_bounce_buffer || reserveable) { |
474 | next_cmd += bytes; |
478 | next_cmd += bytes; |
475 | if (next_cmd >= max) |
479 | if (next_cmd >= max) |
476 | next_cmd -= max - min; |
480 | next_cmd -= max - min; |
477 | mb(); |
481 | mb(); |
478 | iowrite32(next_cmd, fifo_mem + SVGA_FIFO_NEXT_CMD); |
482 | vmw_mmio_write(next_cmd, fifo_mem + SVGA_FIFO_NEXT_CMD); |
479 | } |
483 | } |
480 | 484 | ||
481 | if (reserveable) |
485 | if (reserveable) |
482 | iowrite32(0, fifo_mem + SVGA_FIFO_RESERVED); |
486 | vmw_mmio_write(0, fifo_mem + SVGA_FIFO_RESERVED); |
483 | mb(); |
487 | mb(); |
484 | // up_write(&fifo_state->rwsem); |
488 | up_write(&fifo_state->rwsem); |
485 | vmw_fifo_ping_host(dev_priv, SVGA_SYNC_GENERIC); |
489 | vmw_fifo_ping_host(dev_priv, SVGA_SYNC_GENERIC); |
486 | mutex_unlock(&fifo_state->fifo_mutex); |
490 | mutex_unlock(&fifo_state->fifo_mutex); |
487 | } |
491 | } |
- | 492 | ||
- | 493 | void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes) |
|
- | 494 | { |
|
- | 495 | if (dev_priv->cman) |
|
- | 496 | vmw_cmdbuf_commit(dev_priv->cman, bytes, NULL, false); |
|
- | 497 | else |
|
- | 498 | vmw_local_fifo_commit(dev_priv, bytes); |
|
- | 499 | } |
|
- | 500 | ||
- | 501 | ||
- | 502 | /** |
|
- | 503 | * vmw_fifo_commit_flush - Commit fifo space and flush any buffered commands. |
|
- | 504 | * |
|
- | 505 | * @dev_priv: Pointer to device private structure. |
|
- | 506 | * @bytes: Number of bytes to commit. |
|
- | 507 | */ |
|
- | 508 | void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes) |
|
- | 509 | { |
|
- | 510 | if (dev_priv->cman) |
|
- | 511 | vmw_cmdbuf_commit(dev_priv->cman, bytes, NULL, true); |
|
- | 512 | else |
|
- | 513 | vmw_local_fifo_commit(dev_priv, bytes); |
|
- | 514 | } |
|
- | 515 | ||
- | 516 | /** |
|
- | 517 | * vmw_fifo_flush - Flush any buffered commands and make sure command processing |
|
- | 518 | * starts. |
|
- | 519 | * |
|
- | 520 | * @dev_priv: Pointer to device private structure. |
|
- | 521 | * @interruptible: Whether to wait interruptible if function needs to sleep. |
|
- | 522 | */ |
|
- | 523 | int vmw_fifo_flush(struct vmw_private *dev_priv, bool interruptible) |
|
- | 524 | { |
|
- | 525 | might_sleep(); |
|
- | 526 | ||
- | 527 | if (dev_priv->cman) |
|
- | 528 | return vmw_cmdbuf_cur_flush(dev_priv->cman, interruptible); |
|
- | 529 | else |
|
- | 530 | return 0; |
|
- | 531 | } |
|
488 | 532 | ||
489 | int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno) |
533 | int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno) |
490 | { |
534 | { |
491 | struct vmw_fifo_state *fifo_state = &dev_priv->fifo; |
535 | struct vmw_fifo_state *fifo_state = &dev_priv->fifo; |
492 | struct svga_fifo_cmd_fence *cmd_fence; |
536 | struct svga_fifo_cmd_fence *cmd_fence; |
493 | void *fm; |
537 | u32 *fm; |
494 | int ret = 0; |
538 | int ret = 0; |
495 | uint32_t bytes = sizeof(__le32) + sizeof(*cmd_fence); |
539 | uint32_t bytes = sizeof(u32) + sizeof(*cmd_fence); |
496 | 540 | ||
497 | fm = vmw_fifo_reserve(dev_priv, bytes); |
541 | fm = vmw_fifo_reserve(dev_priv, bytes); |
498 | if (unlikely(fm == NULL)) { |
542 | if (unlikely(fm == NULL)) { |
499 | *seqno = atomic_read(&dev_priv->marker_seq); |
543 | *seqno = atomic_read(&dev_priv->marker_seq); |
500 | ret = -ENOMEM; |
544 | ret = -ENOMEM; |
501 | (void)vmw_fallback_wait(dev_priv, false, true, *seqno, |
545 | (void)vmw_fallback_wait(dev_priv, false, true, *seqno, |
502 | false, 3*HZ); |
546 | false, 3*HZ); |
503 | goto out_err; |
547 | goto out_err; |
504 | } |
548 | } |
505 | 549 | ||
506 | do { |
550 | do { |
507 | *seqno = atomic_add_return(1, &dev_priv->marker_seq); |
551 | *seqno = atomic_add_return(1, &dev_priv->marker_seq); |
508 | } while (*seqno == 0); |
552 | } while (*seqno == 0); |
509 | 553 | ||
510 | if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) { |
554 | if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) { |
511 | 555 | ||
512 | /* |
556 | /* |
513 | * Don't request hardware to send a fence. The |
557 | * Don't request hardware to send a fence. The |
514 | * waiting code in vmwgfx_irq.c will emulate this. |
558 | * waiting code in vmwgfx_irq.c will emulate this. |
515 | */ |
559 | */ |
516 | 560 | ||
517 | vmw_fifo_commit(dev_priv, 0); |
561 | vmw_fifo_commit(dev_priv, 0); |
518 | return 0; |
562 | return 0; |
519 | } |
563 | } |
520 | 564 | ||
521 | *(__le32 *) fm = cpu_to_le32(SVGA_CMD_FENCE); |
565 | *fm++ = SVGA_CMD_FENCE; |
522 | cmd_fence = (struct svga_fifo_cmd_fence *) |
- | |
523 | ((unsigned long)fm + sizeof(__le32)); |
- | |
524 | 566 | cmd_fence = (struct svga_fifo_cmd_fence *) fm; |
|
525 | iowrite32(*seqno, &cmd_fence->fence); |
567 | cmd_fence->fence = *seqno; |
526 | vmw_fifo_commit(dev_priv, bytes); |
568 | vmw_fifo_commit_flush(dev_priv, bytes); |
527 | (void) vmw_marker_push(&fifo_state->marker_queue, *seqno); |
569 | (void) vmw_marker_push(&fifo_state->marker_queue, *seqno); |
528 | vmw_update_seqno(dev_priv, fifo_state); |
570 | vmw_update_seqno(dev_priv, fifo_state); |
529 | 571 | ||
530 | out_err: |
572 | out_err: |
531 | return ret; |
573 | return ret; |
532 | } |
574 | } |
533 | 575 | ||
534 | /** |
576 | /** |
535 | * vmw_fifo_emit_dummy_legacy_query - emits a dummy query to the fifo using |
577 | * vmw_fifo_emit_dummy_legacy_query - emits a dummy query to the fifo using |
536 | * legacy query commands. |
578 | * legacy query commands. |
537 | * |
579 | * |
538 | * @dev_priv: The device private structure. |
580 | * @dev_priv: The device private structure. |
539 | * @cid: The hardware context id used for the query. |
581 | * @cid: The hardware context id used for the query. |
540 | * |
582 | * |
541 | * See the vmw_fifo_emit_dummy_query documentation. |
583 | * See the vmw_fifo_emit_dummy_query documentation. |
542 | */ |
584 | */ |
543 | static int vmw_fifo_emit_dummy_legacy_query(struct vmw_private *dev_priv, |
585 | static int vmw_fifo_emit_dummy_legacy_query(struct vmw_private *dev_priv, |
544 | uint32_t cid) |
586 | uint32_t cid) |
545 | { |
587 | { |
546 | /* |
588 | /* |
547 | * A query wait without a preceding query end will |
589 | * A query wait without a preceding query end will |
548 | * actually finish all queries for this cid |
590 | * actually finish all queries for this cid |
549 | * without writing to the query result structure. |
591 | * without writing to the query result structure. |
550 | */ |
592 | */ |
551 | 593 | ||
552 | struct ttm_buffer_object *bo = dev_priv->dummy_query_bo; |
594 | struct ttm_buffer_object *bo = &dev_priv->dummy_query_bo->base; |
553 | struct { |
595 | struct { |
554 | SVGA3dCmdHeader header; |
596 | SVGA3dCmdHeader header; |
555 | SVGA3dCmdWaitForQuery body; |
597 | SVGA3dCmdWaitForQuery body; |
556 | } *cmd; |
598 | } *cmd; |
557 | 599 | ||
558 | cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); |
600 | cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); |
559 | 601 | ||
560 | if (unlikely(cmd == NULL)) { |
602 | if (unlikely(cmd == NULL)) { |
561 | DRM_ERROR("Out of fifo space for dummy query.\n"); |
603 | DRM_ERROR("Out of fifo space for dummy query.\n"); |
562 | return -ENOMEM; |
604 | return -ENOMEM; |
563 | } |
605 | } |
564 | 606 | ||
565 | cmd->header.id = SVGA_3D_CMD_WAIT_FOR_QUERY; |
607 | cmd->header.id = SVGA_3D_CMD_WAIT_FOR_QUERY; |
566 | cmd->header.size = sizeof(cmd->body); |
608 | cmd->header.size = sizeof(cmd->body); |
567 | cmd->body.cid = cid; |
609 | cmd->body.cid = cid; |
568 | cmd->body.type = SVGA3D_QUERYTYPE_OCCLUSION; |
610 | cmd->body.type = SVGA3D_QUERYTYPE_OCCLUSION; |
569 | 611 | ||
570 | if (bo->mem.mem_type == TTM_PL_VRAM) { |
612 | if (bo->mem.mem_type == TTM_PL_VRAM) { |
571 | cmd->body.guestResult.gmrId = SVGA_GMR_FRAMEBUFFER; |
613 | cmd->body.guestResult.gmrId = SVGA_GMR_FRAMEBUFFER; |
572 | cmd->body.guestResult.offset = bo->offset; |
614 | cmd->body.guestResult.offset = bo->offset; |
573 | } else { |
615 | } else { |
574 | cmd->body.guestResult.gmrId = bo->mem.start; |
616 | cmd->body.guestResult.gmrId = bo->mem.start; |
575 | cmd->body.guestResult.offset = 0; |
617 | cmd->body.guestResult.offset = 0; |
576 | } |
618 | } |
577 | 619 | ||
578 | vmw_fifo_commit(dev_priv, sizeof(*cmd)); |
620 | vmw_fifo_commit(dev_priv, sizeof(*cmd)); |
579 | 621 | ||
580 | return 0; |
622 | return 0; |
581 | } |
623 | } |
582 | 624 | ||
583 | /** |
625 | /** |
584 | * vmw_fifo_emit_dummy_gb_query - emits a dummy query to the fifo using |
626 | * vmw_fifo_emit_dummy_gb_query - emits a dummy query to the fifo using |
585 | * guest-backed resource query commands. |
627 | * guest-backed resource query commands. |
586 | * |
628 | * |
587 | * @dev_priv: The device private structure. |
629 | * @dev_priv: The device private structure. |
588 | * @cid: The hardware context id used for the query. |
630 | * @cid: The hardware context id used for the query. |
589 | * |
631 | * |
590 | * See the vmw_fifo_emit_dummy_query documentation. |
632 | * See the vmw_fifo_emit_dummy_query documentation. |
591 | */ |
633 | */ |
592 | static int vmw_fifo_emit_dummy_gb_query(struct vmw_private *dev_priv, |
634 | static int vmw_fifo_emit_dummy_gb_query(struct vmw_private *dev_priv, |
593 | uint32_t cid) |
635 | uint32_t cid) |
594 | { |
636 | { |
595 | /* |
637 | /* |
596 | * A query wait without a preceding query end will |
638 | * A query wait without a preceding query end will |
597 | * actually finish all queries for this cid |
639 | * actually finish all queries for this cid |
598 | * without writing to the query result structure. |
640 | * without writing to the query result structure. |
599 | */ |
641 | */ |
600 | 642 | ||
601 | struct ttm_buffer_object *bo = dev_priv->dummy_query_bo; |
643 | struct ttm_buffer_object *bo = &dev_priv->dummy_query_bo->base; |
602 | struct { |
644 | struct { |
603 | SVGA3dCmdHeader header; |
645 | SVGA3dCmdHeader header; |
604 | SVGA3dCmdWaitForGBQuery body; |
646 | SVGA3dCmdWaitForGBQuery body; |
605 | } *cmd; |
647 | } *cmd; |
606 | 648 | ||
607 | cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); |
649 | cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); |
608 | 650 | ||
609 | if (unlikely(cmd == NULL)) { |
651 | if (unlikely(cmd == NULL)) { |
610 | DRM_ERROR("Out of fifo space for dummy query.\n"); |
652 | DRM_ERROR("Out of fifo space for dummy query.\n"); |
611 | return -ENOMEM; |
653 | return -ENOMEM; |
612 | } |
654 | } |
613 | 655 | ||
614 | cmd->header.id = SVGA_3D_CMD_WAIT_FOR_GB_QUERY; |
656 | cmd->header.id = SVGA_3D_CMD_WAIT_FOR_GB_QUERY; |
615 | cmd->header.size = sizeof(cmd->body); |
657 | cmd->header.size = sizeof(cmd->body); |
616 | cmd->body.cid = cid; |
658 | cmd->body.cid = cid; |
617 | cmd->body.type = SVGA3D_QUERYTYPE_OCCLUSION; |
659 | cmd->body.type = SVGA3D_QUERYTYPE_OCCLUSION; |
618 | BUG_ON(bo->mem.mem_type != VMW_PL_MOB); |
660 | BUG_ON(bo->mem.mem_type != VMW_PL_MOB); |
619 | cmd->body.mobid = bo->mem.start; |
661 | cmd->body.mobid = bo->mem.start; |
620 | cmd->body.offset = 0; |
662 | cmd->body.offset = 0; |
621 | 663 | ||
622 | vmw_fifo_commit(dev_priv, sizeof(*cmd)); |
664 | vmw_fifo_commit(dev_priv, sizeof(*cmd)); |
623 | 665 | ||
624 | return 0; |
666 | return 0; |
625 | } |
667 | } |
626 | 668 | ||
627 | 669 | ||
628 | /** |
670 | /** |
629 | * vmw_fifo_emit_dummy_gb_query - emits a dummy query to the fifo using |
671 | * vmw_fifo_emit_dummy_gb_query - emits a dummy query to the fifo using |
630 | * appropriate resource query commands. |
672 | * appropriate resource query commands. |
631 | * |
673 | * |
632 | * @dev_priv: The device private structure. |
674 | * @dev_priv: The device private structure. |
633 | * @cid: The hardware context id used for the query. |
675 | * @cid: The hardware context id used for the query. |
634 | * |
676 | * |
635 | * This function is used to emit a dummy occlusion query with |
677 | * This function is used to emit a dummy occlusion query with |
636 | * no primitives rendered between query begin and query end. |
678 | * no primitives rendered between query begin and query end. |
637 | * It's used to provide a query barrier, in order to know that when |
679 | * It's used to provide a query barrier, in order to know that when |
638 | * this query is finished, all preceding queries are also finished. |
680 | * this query is finished, all preceding queries are also finished. |
639 | * |
681 | * |
640 | * A Query results structure should have been initialized at the start |
682 | * A Query results structure should have been initialized at the start |
641 | * of the dev_priv->dummy_query_bo buffer object. And that buffer object |
683 | * of the dev_priv->dummy_query_bo buffer object. And that buffer object |
642 | * must also be either reserved or pinned when this function is called. |
684 | * must also be either reserved or pinned when this function is called. |
643 | * |
685 | * |
644 | * Returns -ENOMEM on failure to reserve fifo space. |
686 | * Returns -ENOMEM on failure to reserve fifo space. |
645 | */ |
687 | */ |
646 | int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv, |
688 | int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv, |
647 | uint32_t cid) |
689 | uint32_t cid) |
648 | { |
690 | { |
649 | if (dev_priv->has_mob) |
691 | if (dev_priv->has_mob) |
650 | return vmw_fifo_emit_dummy_gb_query(dev_priv, cid); |
692 | return vmw_fifo_emit_dummy_gb_query(dev_priv, cid); |
651 | 693 | ||
652 | return vmw_fifo_emit_dummy_legacy_query(dev_priv, cid); |
694 | return vmw_fifo_emit_dummy_legacy_query(dev_priv, cid); |
653 | }>>=>>>=>>=><=>>=> |
695 | } |
- | 696 | ||
- | 697 | void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes) |
|
- | 698 | { |
|
- | 699 | return vmw_fifo_reserve_dx(dev_priv, bytes, SVGA3D_INVALID_ID); |
|
- | 700 | }>>=>>>=>>=><=>>=> |