]> err.no Git - linux-2.6/blobdiff - drivers/video/ps3fb.c
Merge branch 'orion' into devel
[linux-2.6] / drivers / video / ps3fb.c
index 64af173d18f91437e5e958b219de667c7a1dea6b..044a423a72cbe406e0a5811796b246cb788f1ec3 100644 (file)
 #define L1GPU_DISPLAY_SYNC_HSYNC               1
 #define L1GPU_DISPLAY_SYNC_VSYNC               2
 
-#define DDR_SIZE                               (0)     /* used no ddr */
-#define GPU_CMD_BUF_SIZE                       (64 * 1024)
+#define GPU_CMD_BUF_SIZE                       (2 * 1024 * 1024)
+#define GPU_FB_START                           (64 * 1024)
 #define GPU_IOIF                               (0x0d000000UL)
 #define GPU_ALIGN_UP(x)                                _ALIGN_UP((x), 64)
+#define GPU_MAX_LINE_LENGTH                    (65536 - 64)
 
 #define PS3FB_FULL_MODE_BIT                    0x80
 
@@ -335,7 +336,7 @@ static int ps3fb_get_res_table(u32 xres, u32 yres, int mode)
 }
 
 static unsigned int ps3fb_find_mode(const struct fb_var_screeninfo *var,
-                                   u32 *line_length)
+                                   u32 *ddr_line_length, u32 *xdr_line_length)
 {
        unsigned int i, mode;
 
@@ -350,19 +351,30 @@ static unsigned int ps3fb_find_mode(const struct fb_var_screeninfo *var,
                    var->upper_margin == ps3fb_modedb[i].upper_margin &&
                    var->lower_margin == ps3fb_modedb[i].lower_margin &&
                    var->sync == ps3fb_modedb[i].sync &&
-                   (var->vmode & FB_VMODE_MASK) == ps3fb_modedb[i].vmode) {
-                       /* Cropped broadcast modes use the full line_length */
-                       *line_length =
-                           ps3fb_modedb[i < 10 ? i + 13 : i].xres * 4;
-                       /* Full broadcast modes have the full mode bit set */
-                       mode = i > 12 ? (i - 12) | PS3FB_FULL_MODE_BIT : i + 1;
-
-                       pr_debug("ps3fb_find_mode: mode %u\n", mode);
-                       return mode;
-               }
+                   (var->vmode & FB_VMODE_MASK) == ps3fb_modedb[i].vmode)
+                       goto found;
 
        pr_debug("ps3fb_find_mode: mode not found\n");
        return 0;
+
+found:
+       /* Cropped broadcast modes use the full line length */
+       *ddr_line_length = ps3fb_modedb[i < 10 ? i + 13 : i].xres * BPP;
+
+       if (ps3_compare_firmware_version(1, 9, 0) >= 0) {
+               *xdr_line_length = GPU_ALIGN_UP(max(var->xres,
+                                                   var->xres_virtual) * BPP);
+               if (*xdr_line_length > GPU_MAX_LINE_LENGTH)
+                       *xdr_line_length = GPU_MAX_LINE_LENGTH;
+       } else
+               *xdr_line_length = *ddr_line_length;
+
+       /* Full broadcast modes have the full mode bit set */
+       mode = i > 12 ? (i - 12) | PS3FB_FULL_MODE_BIT : i + 1;
+
+       pr_debug("ps3fb_find_mode: mode %u\n", mode);
+
+       return mode;
 }
 
 static const struct fb_videomode *ps3fb_default_mode(int id)
@@ -385,10 +397,17 @@ static const struct fb_videomode *ps3fb_default_mode(int id)
 
 static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
                             u64 dst_offset, u64 src_offset, u32 width,
-                            u32 height, u64 line_length)
+                            u32 height, u32 dst_line_length,
+                            u32 src_line_length)
 {
        int status;
+       u64 line_length;
+
+       line_length = dst_line_length;
+       if (src_line_length != dst_line_length)
+               line_length |= (u64)src_line_length << 32;
 
+       src_offset += GPU_FB_START;
        status = lv1_gpu_context_attribute(ps3fb.context_handle,
                                           L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
                                           dst_offset, GPU_IOIF + src_offset,
@@ -421,10 +440,8 @@ static int ps3fb_sync(struct fb_info *info, u32 frame)
 {
        struct ps3fb_par *par = info->par;
        int i, error = 0;
-       u32 xres, yres;
-       u64 line_length, base;
-
-       acquire_console_sem();
+       u32 ddr_line_length, xdr_line_length;
+       u64 ddr_base, xdr_base;
 
        if (frame > par->num_frames - 1) {
                dev_dbg(info->device, "%s: invalid frame number (%u)\n",
@@ -434,18 +451,17 @@ static int ps3fb_sync(struct fb_info *info, u32 frame)
        }
 
        i = par->res_index;
-       xres = ps3fb_res[i].xres;
-       yres = ps3fb_res[i].yres;
+       xdr_line_length = info->fix.line_length;
+       ddr_line_length = ps3fb_res[i].xres * BPP;
+       xdr_base = frame * info->var.yres_virtual * xdr_line_length;
+       ddr_base = frame * ps3fb_res[i].yres * ddr_line_length;
 
-       line_length = xres * BPP;
-       base = frame * yres * line_length;
-
-       ps3fb_sync_image(info->device, base + par->full_offset,
-                        base + par->fb_offset, base + par->pan_offset,
-                        par->width, par->height, line_length);
+       ps3fb_sync_image(info->device, ddr_base + par->full_offset,
+                        ddr_base + par->fb_offset, xdr_base + par->pan_offset,
+                        par->width, par->height, ddr_line_length,
+                        xdr_line_length);
 
 out:
-       release_console_sem();
        return error;
 }
 
@@ -460,7 +476,10 @@ static int ps3fb_release(struct fb_info *info, int user)
        if (atomic_dec_and_test(&ps3fb.f_count)) {
                if (atomic_read(&ps3fb.ext_flip)) {
                        atomic_set(&ps3fb.ext_flip, 0);
-                       ps3fb_sync(info, 0);    /* single buffer */
+                       if (!try_acquire_console_sem()) {
+                               ps3fb_sync(info, 0);    /* single buffer */
+                               release_console_sem();
+                       }
                }
        }
        return 0;
@@ -476,7 +495,7 @@ static int ps3fb_release(struct fb_info *info, int user)
 
 static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 {
-       u32 line_length;
+       u32 xdr_line_length, ddr_line_length;
        int mode;
 
        dev_dbg(info->device, "var->xres:%u info->var.xres:%u\n", var->xres,
@@ -485,7 +504,7 @@ static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
                info->var.yres);
 
        /* FIXME For now we do exact matches only */
-       mode = ps3fb_find_mode(var, &line_length);
+       mode = ps3fb_find_mode(var, &ddr_line_length, &xdr_line_length);
        if (!mode)
                return -EINVAL;
 
@@ -495,7 +514,7 @@ static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
        if (var->yres_virtual < var->yres)
                var->yres_virtual = var->yres;
 
-       if (var->xres_virtual > line_length / BPP) {
+       if (var->xres_virtual > xdr_line_length / BPP) {
                dev_dbg(info->device,
                        "Horizontal virtual screen size too large\n");
                return -EINVAL;
@@ -540,7 +559,7 @@ static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
        }
 
        /* Memory limit */
-       if (var->yres_virtual * line_length > ps3fb.xdr_size) {
+       if (var->yres_virtual * xdr_line_length > ps3fb.xdr_size) {
                dev_dbg(info->device, "Not enough memory\n");
                return -ENOMEM;
        }
@@ -558,15 +577,16 @@ static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 static int ps3fb_set_par(struct fb_info *info)
 {
        struct ps3fb_par *par = info->par;
-       unsigned int mode, line_length, lines, maxlines;
+       unsigned int mode, ddr_line_length, xdr_line_length, lines, maxlines;
        int i;
-       unsigned long offset, dst;
+       unsigned long offset;
+       u64 dst;
 
        dev_dbg(info->device, "xres:%d xv:%d yres:%d yv:%d clock:%d\n",
                info->var.xres, info->var.xres_virtual,
                info->var.yres, info->var.yres_virtual, info->var.pixclock);
 
-       mode = ps3fb_find_mode(&info->var, &line_length);
+       mode = ps3fb_find_mode(&info->var, &ddr_line_length, &xdr_line_length);
        if (!mode)
                return -EINVAL;
 
@@ -577,12 +597,13 @@ static int ps3fb_set_par(struct fb_info *info)
        info->fix.smem_len = ps3fb.xdr_size;
        info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
        info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
-       info->fix.line_length = line_length;
+       info->fix.line_length = xdr_line_length;
 
        info->screen_base = (char __iomem *)ps3fb.xdr_ea;
 
-       par->num_frames = info->fix.smem_len/
-                         (ps3fb_res[i].xres*ps3fb_res[i].yres*BPP);
+       par->num_frames = ps3fb.xdr_size /
+                         max(ps3fb_res[i].yres * ddr_line_length,
+                             info->var.yres_virtual * xdr_line_length);
 
        /* Keep the special bits we cannot set using fb_var_screeninfo */
        par->new_mode_id = (par->new_mode_id & ~PS3AV_MODE_MASK) | mode;
@@ -592,7 +613,7 @@ static int ps3fb_set_par(struct fb_info *info)
        offset = VP_OFF(i);
        par->fb_offset = GPU_ALIGN_UP(offset);
        par->full_offset = par->fb_offset - offset;
-       par->pan_offset = info->var.yoffset * line_length +
+       par->pan_offset = info->var.yoffset * xdr_line_length +
                          info->var.xoffset * BPP;
 
        if (par->new_mode_id != par->mode_id) {
@@ -610,11 +631,11 @@ static int ps3fb_set_par(struct fb_info *info)
        lines = ps3fb_res[i].yres * par->num_frames;
        if (par->full_offset)
                lines++;
-       maxlines = ps3fb.xdr_size / line_length;
-       for (dst = 0; lines; dst += maxlines * line_length) {
+       maxlines = ps3fb.xdr_size / ddr_line_length;
+       for (dst = 0; lines; dst += maxlines * ddr_line_length) {
                unsigned int l = min(lines, maxlines);
                ps3fb_sync_image(info->device, 0, dst, 0, ps3fb_res[i].xres, l,
-                                line_length);
+                                ddr_line_length, ddr_line_length);
                lines -= l;
        }
 
@@ -707,7 +728,7 @@ static int ps3fb_blank(int blank, struct fb_info *info)
 
 static int ps3fb_get_vblank(struct fb_vblank *vblank)
 {
-       memset(vblank, 0, sizeof(&vblank));
+       memset(vblank, 0, sizeof(*vblank));
        vblank->flags = FB_VBLANK_HAVE_VSYNC;
        return 0;
 }
@@ -816,12 +837,11 @@ static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
                {
                        struct ps3fb_par *par = info->par;
                        struct ps3fb_ioctl_res res;
-                       int i = par->res_index;
                        dev_dbg(info->device, "PS3FB_IOCTL_SCREENINFO:\n");
-                       res.xres = ps3fb_res[i].xres;
-                       res.yres = ps3fb_res[i].yres;
-                       res.xoff = ps3fb_res[i].xoff;
-                       res.yoff = ps3fb_res[i].yoff;
+                       res.xres = info->fix.line_length / BPP;
+                       res.yres = info->var.yres_virtual;
+                       res.xoff = (res.xres - info->var.xres) / 2;
+                       res.yoff = (res.yres - info->var.yres) / 2;
                        res.num_frames = par->num_frames;
                        if (!copy_to_user(argp, &res, sizeof(res)))
                                retval = 0;
@@ -845,7 +865,9 @@ static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
                        break;
 
                dev_dbg(info->device, "PS3FB_IOCTL_FSEL:%d\n", val);
+               acquire_console_sem();
                retval = ps3fb_sync(info, val);
+               release_console_sem();
                break;
 
        default:
@@ -865,7 +887,9 @@ static int ps3fbd(void *arg)
                set_current_state(TASK_INTERRUPTIBLE);
                if (ps3fb.is_kicked) {
                        ps3fb.is_kicked = 0;
+                       acquire_console_sem();
                        ps3fb_sync(info, 0);    /* single buffer */
+                       release_console_sem();
                }
                schedule();
        }
@@ -958,9 +982,8 @@ static int ps3fb_xdr_settings(u64 xdr_lpar, struct device *dev)
 
        status = lv1_gpu_context_attribute(ps3fb.context_handle,
                                           L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
-                                          xdr_lpar + ps3fb.xdr_size,
-                                          GPU_CMD_BUF_SIZE,
-                                          GPU_IOIF + ps3fb.xdr_size, 0);
+                                          xdr_lpar, GPU_CMD_BUF_SIZE,
+                                          GPU_IOIF, 0);
        if (status) {
                dev_err(dev,
                        "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
@@ -1041,6 +1064,12 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        u64 xdr_lpar;
        int status, res_index;
        struct task_struct *task;
+       unsigned long max_ps3fb_size;
+
+       if (ps3fb_videomemory.size < GPU_CMD_BUF_SIZE) {
+               dev_err(&dev->core, "%s: Not enough video memory\n", __func__);
+               return -ENOMEM;
+       }
 
        status = ps3_open_hv_device(dev);
        if (status) {
@@ -1066,8 +1095,15 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
 
        ps3fb_set_sync(&dev->core);
 
+       max_ps3fb_size = _ALIGN_UP(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
+       if (ps3fb_videomemory.size > max_ps3fb_size) {
+               dev_info(&dev->core, "Limiting ps3fb mem size to %lu bytes\n",
+                        max_ps3fb_size);
+               ps3fb_videomemory.size = max_ps3fb_size;
+       }
+
        /* get gpu context handle */
-       status = lv1_gpu_memory_allocate(DDR_SIZE, 0, 0, 0, 0,
+       status = lv1_gpu_memory_allocate(ps3fb_videomemory.size, 0, 0, 0, 0,
                                         &ps3fb.memory_handle, &ddr_lpar);
        if (status) {
                dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n",
@@ -1105,8 +1141,14 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        /* Clear memory to prevent kernel info leakage into userspace */
        memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
 
-       /* The GPU command buffer is at the end of video memory */
-       ps3fb.xdr_size = ps3fb_videomemory.size - GPU_CMD_BUF_SIZE;
+       /*
+        * The GPU command buffer is at the start of video memory
+        * As we don't use the full command buffer, we can put the actual
+        * frame buffer at offset GPU_FB_START and save some precious XDR
+        * memory
+        */
+       ps3fb.xdr_ea += GPU_FB_START;
+       ps3fb.xdr_size = ps3fb_videomemory.size - GPU_FB_START;
 
        retval = ps3fb_xdr_settings(xdr_lpar, &dev->core);
        if (retval)
@@ -1174,7 +1216,7 @@ err_fb_dealloc:
 err_framebuffer_release:
        framebuffer_release(info);
 err_free_irq:
-       free_irq(ps3fb.irq_no, dev);
+       free_irq(ps3fb.irq_no, &dev->core);
        ps3_irq_plug_destroy(ps3fb.irq_no);
 err_iounmap_dinfo:
        iounmap((u8 __iomem *)ps3fb.dinfo);
@@ -1196,12 +1238,6 @@ static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
        ps3fb_flip_ctl(0, &ps3fb);      /* flip off */
        ps3fb.dinfo->irq.mask = 0;
 
-       if (info) {
-               unregister_framebuffer(info);
-               fb_dealloc_cmap(&info->cmap);
-               framebuffer_release(info);
-       }
-
        ps3av_register_flip_ctl(NULL, NULL);
        if (ps3fb.task) {
                struct task_struct *task = ps3fb.task;
@@ -1209,9 +1245,15 @@ static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
                kthread_stop(task);
        }
        if (ps3fb.irq_no) {
-               free_irq(ps3fb.irq_no, dev);
+               free_irq(ps3fb.irq_no, &dev->core);
                ps3_irq_plug_destroy(ps3fb.irq_no);
        }
+       if (info) {
+               unregister_framebuffer(info);
+               fb_dealloc_cmap(&info->cmap);
+               framebuffer_release(info);
+               info = dev->core.driver_data = NULL;
+       }
        iounmap((u8 __iomem *)ps3fb.dinfo);
 
        status = lv1_gpu_context_free(ps3fb.context_handle);