1 /**************************************************************************
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.
18 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
19 * develop this driver.
21 **************************************************************************/
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/errno.h>
26 #include <linux/string.h>
28 #include <linux/tty.h>
29 #include <linux/slab.h>
30 #include <linux/delay.h>
32 #include <linux/init.h>
33 #include <linux/console.h>
37 #include <drm/drm_crtc.h>
45 void psb_spank(struct drm_psb_private *dev_priv)
47 PSB_WSGX32(_PSB_CS_RESET_BIF_RESET | _PSB_CS_RESET_DPM_RESET |
48 _PSB_CS_RESET_TA_RESET | _PSB_CS_RESET_USE_RESET |
49 _PSB_CS_RESET_ISP_RESET | _PSB_CS_RESET_TSP_RESET |
50 _PSB_CS_RESET_TWOD_RESET, PSB_CR_SOFT_RESET);
51 (void) PSB_RSGX32(PSB_CR_SOFT_RESET);
55 PSB_WSGX32(0, PSB_CR_SOFT_RESET);
57 PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_CB_CTRL_CLEAR_FAULT,
60 (void) PSB_RSGX32(PSB_CR_BIF_CTRL);
63 PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) & ~_PSB_CB_CTRL_CLEAR_FAULT,
65 (void) PSB_RSGX32(PSB_CR_BIF_CTRL);
66 PSB_WSGX32(dev_priv->pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE);
69 static int psb_2d_wait_available(struct drm_psb_private *dev_priv,
72 uint32_t avail = PSB_RSGX32(PSB_CR_2D_SOCIF);
73 unsigned long t = jiffies + HZ;
76 avail = PSB_RSGX32(PSB_CR_2D_SOCIF);
77 if (time_after(jiffies, t)) {
85 /* FIXME: Remember if we expose the 2D engine to the DRM we need to serialize
86 it with console use */
88 static int psbfb_2d_submit(struct drm_psb_private *dev_priv, uint32_t *cmdbuf,
96 submit_size = (size < 0x60) ? size : 0x60;
98 ret = psb_2d_wait_available(dev_priv, submit_size);
103 for (i = 0; i < submit_size; i += 4) {
104 PSB_WSGX32(*cmdbuf++, PSB_SGX_2D_SLAVE_PORT + i);
106 (void)PSB_RSGX32(PSB_SGX_2D_SLAVE_PORT + i - 4);
111 static int psb_accel_2d_fillrect(struct drm_psb_private *dev_priv,
112 uint32_t dst_offset, uint32_t dst_stride,
113 uint32_t dst_format, uint16_t dst_x,
114 uint16_t dst_y, uint16_t size_x,
115 uint16_t size_y, uint32_t fill)
122 *buf++ = PSB_2D_FENCE_BH;
125 PSB_2D_DST_SURF_BH | dst_format | (dst_stride <<
126 PSB_2D_DST_STRIDE_SHIFT);
132 PSB_2D_COPYORDER_TL2BR |
133 PSB_2D_DSTCK_DISABLE |
134 PSB_2D_SRCCK_DISABLE | PSB_2D_USE_FILL | PSB_2D_ROP3_PATCOPY;
136 *buf++ = fill << PSB_2D_FILLCOLOUR_SHIFT;
138 (dst_x << PSB_2D_DST_XSTART_SHIFT) | (dst_y <<
139 PSB_2D_DST_YSTART_SHIFT);
141 (size_x << PSB_2D_DST_XSIZE_SHIFT) | (size_y <<
142 PSB_2D_DST_YSIZE_SHIFT);
143 *buf++ = PSB_2D_FLUSH_BH;
145 return psbfb_2d_submit(dev_priv, buffer, buf - buffer);
148 static void psbfb_fillrect_accel(struct fb_info *info,
149 const struct fb_fillrect *r)
151 struct psb_fbdev *fbdev = info->par;
152 struct psb_framebuffer *psbfb = fbdev->pfb;
153 struct drm_device *dev = psbfb->base.dev;
154 struct drm_framebuffer *fb = fbdev->psb_fb_helper.fb;
155 struct drm_psb_private *dev_priv = dev->dev_private;
164 offset = psbfb->offset;
169 format = PSB_2D_DST_332RGB;
172 format = PSB_2D_DST_555RGB;
175 format = PSB_2D_DST_565RGB;
179 /* this is wrong but since we don't do blending its okay */
180 format = PSB_2D_DST_8888ARGB;
183 /* software fallback */
184 cfb_fillrect(info, r);
188 psb_accel_2d_fillrect(dev_priv,
189 offset, stride, format,
190 r->dx, r->dy, r->width, r->height, r->color);
193 void psbfb_fillrect(struct fb_info *info,
194 const struct fb_fillrect *rect)
196 if (unlikely(info->state != FBINFO_STATE_RUNNING))
199 if (1 || (info->flags & FBINFO_HWACCEL_DISABLED))
200 return cfb_fillrect(info, rect);
202 /*psb_check_power_state(dev, PSB_DEVICE_SGX); */
203 psbfb_fillrect_accel(info, rect);
204 /* Drop power again here on MRST FIXMEAC */
207 static u32 psb_accel_2d_copy_direction(int xdir, int ydir)
210 return (ydir < 0) ? PSB_2D_COPYORDER_BR2TL :
211 PSB_2D_COPYORDER_TR2BL;
213 return (ydir < 0) ? PSB_2D_COPYORDER_BL2TR :
214 PSB_2D_COPYORDER_TL2BR;
218 * @src_offset in bytes
219 * @src_stride in bytes
220 * @src_format psb 2D format defines
221 * @dst_offset in bytes
222 * @dst_stride in bytes
223 * @dst_format psb 2D format defines
224 * @src_x offset in pixels
225 * @src_y offset in pixels
226 * @dst_x offset in pixels
227 * @dst_y offset in pixels
228 * @size_x of the copied area
229 * @size_y of the copied area
231 static int psb_accel_2d_copy(struct drm_psb_private *dev_priv,
232 uint32_t src_offset, uint32_t src_stride,
233 uint32_t src_format, uint32_t dst_offset,
234 uint32_t dst_stride, uint32_t dst_format,
235 uint16_t src_x, uint16_t src_y,
236 uint16_t dst_x, uint16_t dst_y,
237 uint16_t size_x, uint16_t size_y)
247 psb_accel_2d_copy_direction(src_x - dst_x, src_y - dst_y);
249 if (direction == PSB_2D_COPYORDER_BR2TL ||
250 direction == PSB_2D_COPYORDER_TR2BL) {
254 if (direction == PSB_2D_COPYORDER_BR2TL ||
255 direction == PSB_2D_COPYORDER_BL2TR) {
263 PSB_2D_DSTCK_DISABLE |
264 PSB_2D_SRCCK_DISABLE |
265 PSB_2D_USE_PAT | PSB_2D_ROP3_SRCCOPY | direction;
267 *buf++ = PSB_2D_FENCE_BH;
269 PSB_2D_DST_SURF_BH | dst_format | (dst_stride <<
270 PSB_2D_DST_STRIDE_SHIFT);
273 PSB_2D_SRC_SURF_BH | src_format | (src_stride <<
274 PSB_2D_SRC_STRIDE_SHIFT);
277 PSB_2D_SRC_OFF_BH | (src_x << PSB_2D_SRCOFF_XSTART_SHIFT) |
278 (src_y << PSB_2D_SRCOFF_YSTART_SHIFT);
281 (dst_x << PSB_2D_DST_XSTART_SHIFT) | (dst_y <<
282 PSB_2D_DST_YSTART_SHIFT);
284 (size_x << PSB_2D_DST_XSIZE_SHIFT) | (size_y <<
285 PSB_2D_DST_YSIZE_SHIFT);
286 *buf++ = PSB_2D_FLUSH_BH;
288 return psbfb_2d_submit(dev_priv, buffer, buf - buffer);
291 static void psbfb_copyarea_accel(struct fb_info *info,
292 const struct fb_copyarea *a)
294 struct psb_fbdev *fbdev = info->par;
295 struct psb_framebuffer *psbfb = fbdev->pfb;
296 struct drm_device *dev = psbfb->base.dev;
297 struct drm_framebuffer *fb = fbdev->psb_fb_helper.fb;
298 struct drm_psb_private *dev_priv = dev->dev_private;
307 offset = psbfb->offset;
312 src_format = PSB_2D_SRC_332RGB;
313 dst_format = PSB_2D_DST_332RGB;
316 src_format = PSB_2D_SRC_555RGB;
317 dst_format = PSB_2D_DST_555RGB;
320 src_format = PSB_2D_SRC_565RGB;
321 dst_format = PSB_2D_DST_565RGB;
325 /* this is wrong but since we don't do blending its okay */
326 src_format = PSB_2D_SRC_8888ARGB;
327 dst_format = PSB_2D_DST_8888ARGB;
330 /* software fallback */
331 cfb_copyarea(info, a);
335 psb_accel_2d_copy(dev_priv,
336 offset, stride, src_format,
337 offset, stride, dst_format,
338 a->sx, a->sy, a->dx, a->dy, a->width, a->height);
341 void psbfb_copyarea(struct fb_info *info,
342 const struct fb_copyarea *region)
344 if (unlikely(info->state != FBINFO_STATE_RUNNING))
347 if (1 || (info->flags & FBINFO_HWACCEL_DISABLED))
348 return cfb_copyarea(info, region);
350 /* psb_check_power_state(dev, PSB_DEVICE_SGX); */
351 psbfb_copyarea_accel(info, region);
352 /* Need to power back off here for MRST FIXMEAC */
355 void psbfb_imageblit(struct fb_info *info, const struct fb_image *image)
358 cfb_imageblit(info, image);
361 int psbfb_sync(struct fb_info *info)
363 struct psb_fbdev *fbdev = info->par;
364 struct psb_framebuffer *psbfb = fbdev->pfb;
365 struct drm_device *dev = psbfb->base.dev;
366 struct drm_psb_private *dev_priv = dev->dev_private;
367 unsigned long _end = jiffies + DRM_HZ;
371 /* Just a way to quickly test if cmd issue explodes */
375 psbfb_2d_submit(dev_priv, test, 1);
378 * First idle the 2D engine.
381 if ((PSB_RSGX32(PSB_CR_2D_SOCIF) == _PSB_C2_SOCIF_EMPTY) &&
382 ((PSB_RSGX32(PSB_CR_2D_BLIT_STATUS) & _PSB_C2B_STATUS_BUSY) == 0))
386 busy = (PSB_RSGX32(PSB_CR_2D_SOCIF) != _PSB_C2_SOCIF_EMPTY);
388 } while (busy && !time_after_eq(jiffies, _end));
391 busy = (PSB_RSGX32(PSB_CR_2D_SOCIF) != _PSB_C2_SOCIF_EMPTY);
396 busy = ((PSB_RSGX32(PSB_CR_2D_BLIT_STATUS) &
397 _PSB_C2B_STATUS_BUSY) != 0);
399 } while (busy && !time_after_eq(jiffies, _end));
401 busy = ((PSB_RSGX32(PSB_CR_2D_BLIT_STATUS) &
402 _PSB_C2B_STATUS_BUSY) != 0);
405 return (busy) ? -EBUSY : 0;
409 info->fix.accel = FB_ACCEL_I830;
410 info->flags = FBINFO_DEFAULT;