Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/ps3fb.c -- PS3 GPU frame buffer device |
| 3 | * |
| 4 | * Copyright (C) 2006 Sony Computer Entertainment Inc. |
| 5 | * Copyright 2006, 2007 Sony Corporation |
| 6 | * |
| 7 | * This file is based on : |
| 8 | * |
| 9 | * linux/drivers/video/vfb.c -- Virtual frame buffer device |
| 10 | * |
| 11 | * Copyright (C) 2002 James Simmons |
| 12 | * |
| 13 | * Copyright (C) 1997 Geert Uytterhoeven |
| 14 | * |
| 15 | * This file is subject to the terms and conditions of the GNU General Public |
| 16 | * License. See the file COPYING in the main directory of this archive for |
| 17 | * more details. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/string.h> |
| 24 | #include <linux/mm.h> |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 26 | #include <linux/console.h> |
| 27 | #include <linux/ioctl.h> |
Geert Uytterhoeven | 1c0c846 | 2007-05-02 14:48:31 +0200 | [diff] [blame] | 28 | #include <linux/kthread.h> |
| 29 | #include <linux/freezer.h> |
Krzysztof Helt | 84902b7 | 2007-10-16 01:29:04 -0700 | [diff] [blame] | 30 | #include <linux/uaccess.h> |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 31 | #include <linux/fb.h> |
| 32 | #include <linux/init.h> |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 33 | |
| 34 | #include <asm/abs_addr.h> |
Geert Uytterhoeven | e78d0c5 | 2009-06-10 04:38:46 +0000 | [diff] [blame^] | 35 | #include <asm/iommu.h> |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 36 | #include <asm/lv1call.h> |
| 37 | #include <asm/ps3av.h> |
| 38 | #include <asm/ps3fb.h> |
| 39 | #include <asm/ps3.h> |
| 40 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 41 | |
| 42 | #define DEVICE_NAME "ps3fb" |
| 43 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 44 | #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC 0x101 |
| 45 | #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP 0x102 |
| 46 | #define L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP 0x600 |
| 47 | #define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT 0x601 |
| 48 | #define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT_SYNC 0x602 |
| 49 | |
| 50 | #define L1GPU_FB_BLIT_WAIT_FOR_COMPLETION (1ULL << 32) |
| 51 | |
| 52 | #define L1GPU_DISPLAY_SYNC_HSYNC 1 |
| 53 | #define L1GPU_DISPLAY_SYNC_VSYNC 2 |
| 54 | |
Geert Uytterhoeven | 9ac67a3 | 2007-12-19 11:16:41 +0100 | [diff] [blame] | 55 | #define GPU_CMD_BUF_SIZE (2 * 1024 * 1024) |
| 56 | #define GPU_FB_START (64 * 1024) |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 57 | #define GPU_IOIF (0x0d000000UL) |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 58 | #define GPU_ALIGN_UP(x) _ALIGN_UP((x), 64) |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 59 | #define GPU_MAX_LINE_LENGTH (65536 - 64) |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 60 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 61 | #define GPU_INTR_STATUS_VSYNC_0 0 /* vsync on head A */ |
| 62 | #define GPU_INTR_STATUS_VSYNC_1 1 /* vsync on head B */ |
| 63 | #define GPU_INTR_STATUS_FLIP_0 3 /* flip head A */ |
| 64 | #define GPU_INTR_STATUS_FLIP_1 4 /* flip head B */ |
| 65 | #define GPU_INTR_STATUS_QUEUE_0 5 /* queue head A */ |
| 66 | #define GPU_INTR_STATUS_QUEUE_1 6 /* queue head B */ |
| 67 | |
| 68 | #define GPU_DRIVER_INFO_VERSION 0x211 |
| 69 | |
| 70 | /* gpu internals */ |
| 71 | struct display_head { |
| 72 | u64 be_time_stamp; |
| 73 | u32 status; |
| 74 | u32 offset; |
| 75 | u32 res1; |
| 76 | u32 res2; |
| 77 | u32 field; |
| 78 | u32 reserved1; |
| 79 | |
| 80 | u64 res3; |
| 81 | u32 raster; |
| 82 | |
| 83 | u64 vblank_count; |
| 84 | u32 field_vsync; |
| 85 | u32 reserved2; |
| 86 | }; |
| 87 | |
| 88 | struct gpu_irq { |
| 89 | u32 irq_outlet; |
| 90 | u32 status; |
| 91 | u32 mask; |
| 92 | u32 video_cause; |
| 93 | u32 graph_cause; |
| 94 | u32 user_cause; |
| 95 | |
| 96 | u32 res1; |
| 97 | u64 res2; |
| 98 | |
| 99 | u32 reserved[4]; |
| 100 | }; |
| 101 | |
| 102 | struct gpu_driver_info { |
| 103 | u32 version_driver; |
| 104 | u32 version_gpu; |
| 105 | u32 memory_size; |
| 106 | u32 hardware_channel; |
| 107 | |
| 108 | u32 nvcore_frequency; |
| 109 | u32 memory_frequency; |
| 110 | |
| 111 | u32 reserved[1063]; |
| 112 | struct display_head display_head[8]; |
| 113 | struct gpu_irq irq; |
| 114 | }; |
| 115 | |
| 116 | struct ps3fb_priv { |
| 117 | unsigned int irq_no; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 118 | |
| 119 | u64 context_handle, memory_handle; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 120 | struct gpu_driver_info *dinfo; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 121 | |
| 122 | u64 vblank_count; /* frame count */ |
| 123 | wait_queue_head_t wait_vsync; |
| 124 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 125 | atomic_t ext_flip; /* on/off flip with vsync */ |
| 126 | atomic_t f_count; /* fb_open count */ |
| 127 | int is_blanked; |
Geert Uytterhoeven | 1c0c846 | 2007-05-02 14:48:31 +0200 | [diff] [blame] | 128 | int is_kicked; |
| 129 | struct task_struct *task; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 130 | }; |
| 131 | static struct ps3fb_priv ps3fb; |
| 132 | |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 133 | struct ps3fb_par { |
| 134 | u32 pseudo_palette[16]; |
| 135 | int mode_id, new_mode_id; |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 136 | unsigned int num_frames; /* num of frame buffers */ |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 137 | unsigned int width; |
| 138 | unsigned int height; |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 139 | unsigned int ddr_line_length; |
| 140 | unsigned int ddr_frame_size; |
| 141 | unsigned int xdr_frame_size; |
Geert Uytterhoeven | 7974f72 | 2008-02-06 01:39:32 -0800 | [diff] [blame] | 142 | unsigned int full_offset; /* start of fullscreen DDR fb */ |
| 143 | unsigned int fb_offset; /* start of actual DDR fb */ |
| 144 | unsigned int pan_offset; |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 147 | |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 148 | #define FIRST_NATIVE_MODE_INDEX 10 |
| 149 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 150 | static const struct fb_videomode ps3fb_modedb[] = { |
| 151 | /* 60 Hz broadcast modes (modes "1" to "5") */ |
| 152 | { |
| 153 | /* 480i */ |
| 154 | "480i", 60, 576, 384, 74074, 130, 89, 78, 57, 63, 6, |
| 155 | FB_SYNC_BROADCAST, FB_VMODE_INTERLACED |
| 156 | }, { |
| 157 | /* 480p */ |
| 158 | "480p", 60, 576, 384, 37037, 130, 89, 78, 57, 63, 6, |
| 159 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 160 | }, { |
| 161 | /* 720p */ |
| 162 | "720p", 60, 1124, 644, 13481, 298, 148, 57, 44, 80, 5, |
| 163 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 164 | }, { |
| 165 | /* 1080i */ |
| 166 | "1080i", 60, 1688, 964, 13481, 264, 160, 94, 62, 88, 5, |
| 167 | FB_SYNC_BROADCAST, FB_VMODE_INTERLACED |
| 168 | }, { |
| 169 | /* 1080p */ |
| 170 | "1080p", 60, 1688, 964, 6741, 264, 160, 94, 62, 88, 5, |
| 171 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 172 | }, |
| 173 | |
| 174 | /* 50 Hz broadcast modes (modes "6" to "10") */ |
| 175 | { |
| 176 | /* 576i */ |
| 177 | "576i", 50, 576, 460, 74074, 142, 83, 97, 63, 63, 5, |
| 178 | FB_SYNC_BROADCAST, FB_VMODE_INTERLACED |
| 179 | }, { |
| 180 | /* 576p */ |
| 181 | "576p", 50, 576, 460, 37037, 142, 83, 97, 63, 63, 5, |
| 182 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 183 | }, { |
| 184 | /* 720p */ |
| 185 | "720p", 50, 1124, 644, 13468, 298, 478, 57, 44, 80, 5, |
| 186 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 187 | }, { |
Geoff Levand | a782eed | 2008-02-06 01:39:36 -0800 | [diff] [blame] | 188 | /* 1080i */ |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 189 | "1080i", 50, 1688, 964, 13468, 264, 600, 94, 62, 88, 5, |
| 190 | FB_SYNC_BROADCAST, FB_VMODE_INTERLACED |
| 191 | }, { |
| 192 | /* 1080p */ |
| 193 | "1080p", 50, 1688, 964, 6734, 264, 600, 94, 62, 88, 5, |
| 194 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 195 | }, |
| 196 | |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 197 | [FIRST_NATIVE_MODE_INDEX] = |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 198 | /* 60 Hz broadcast modes (full resolution versions of modes "1" to "5") */ |
| 199 | { |
| 200 | /* 480if */ |
| 201 | "480if", 60, 720, 480, 74074, 58, 17, 30, 9, 63, 6, |
| 202 | FB_SYNC_BROADCAST, FB_VMODE_INTERLACED |
| 203 | }, { |
| 204 | /* 480pf */ |
| 205 | "480pf", 60, 720, 480, 37037, 58, 17, 30, 9, 63, 6, |
| 206 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 207 | }, { |
| 208 | /* 720pf */ |
| 209 | "720pf", 60, 1280, 720, 13481, 220, 70, 19, 6, 80, 5, |
| 210 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 211 | }, { |
| 212 | /* 1080if */ |
| 213 | "1080if", 60, 1920, 1080, 13481, 148, 44, 36, 4, 88, 5, |
| 214 | FB_SYNC_BROADCAST, FB_VMODE_INTERLACED |
| 215 | }, { |
| 216 | /* 1080pf */ |
| 217 | "1080pf", 60, 1920, 1080, 6741, 148, 44, 36, 4, 88, 5, |
| 218 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 219 | }, |
| 220 | |
| 221 | /* 50 Hz broadcast modes (full resolution versions of modes "6" to "10") */ |
| 222 | { |
| 223 | /* 576if */ |
| 224 | "576if", 50, 720, 576, 74074, 70, 11, 39, 5, 63, 5, |
| 225 | FB_SYNC_BROADCAST, FB_VMODE_INTERLACED |
| 226 | }, { |
| 227 | /* 576pf */ |
| 228 | "576pf", 50, 720, 576, 37037, 70, 11, 39, 5, 63, 5, |
| 229 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 230 | }, { |
| 231 | /* 720pf */ |
| 232 | "720pf", 50, 1280, 720, 13468, 220, 400, 19, 6, 80, 5, |
| 233 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
| 234 | }, { |
| 235 | /* 1080if */ |
Geoff Levand | a782eed | 2008-02-06 01:39:36 -0800 | [diff] [blame] | 236 | "1080if", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5, |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 237 | FB_SYNC_BROADCAST, FB_VMODE_INTERLACED |
| 238 | }, { |
| 239 | /* 1080pf */ |
| 240 | "1080pf", 50, 1920, 1080, 6734, 148, 484, 36, 4, 88, 5, |
| 241 | FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 242 | }, |
| 243 | |
| 244 | /* VESA modes (modes "11" to "13") */ |
| 245 | { |
| 246 | /* WXGA */ |
| 247 | "wxga", 60, 1280, 768, 12924, 160, 24, 29, 3, 136, 6, |
| 248 | 0, FB_VMODE_NONINTERLACED, |
| 249 | FB_MODE_IS_VESA |
| 250 | }, { |
| 251 | /* SXGA */ |
| 252 | "sxga", 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3, |
| 253 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, |
| 254 | FB_MODE_IS_VESA |
| 255 | }, { |
| 256 | /* WUXGA */ |
| 257 | "wuxga", 60, 1920, 1200, 6494, 80, 48, 26, 3, 32, 6, |
| 258 | FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED, |
| 259 | FB_MODE_IS_VESA |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 260 | } |
| 261 | }; |
| 262 | |
| 263 | |
| 264 | #define HEAD_A |
| 265 | #define HEAD_B |
| 266 | |
Geert Uytterhoeven | 2ce32e1 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 267 | #define BPP 4 /* number of bytes per pixel */ |
| 268 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 269 | |
Geert Uytterhoeven | bd685ac | 2007-05-02 14:48:34 +0200 | [diff] [blame] | 270 | static int ps3fb_mode; |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 271 | module_param(ps3fb_mode, int, 0); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 272 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 273 | static char *mode_option __devinitdata; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 274 | |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 275 | static int ps3fb_cmp_mode(const struct fb_videomode *vmode, |
| 276 | const struct fb_var_screeninfo *var) |
| 277 | { |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 278 | long xres, yres, left_margin, right_margin, upper_margin, lower_margin; |
| 279 | long dx, dy; |
| 280 | |
| 281 | /* maximum values */ |
| 282 | if (var->xres > vmode->xres || var->yres > vmode->yres || |
| 283 | var->pixclock > vmode->pixclock || |
| 284 | var->hsync_len > vmode->hsync_len || |
| 285 | var->vsync_len > vmode->vsync_len) |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 286 | return -1; |
| 287 | |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 288 | /* progressive/interlaced must match */ |
| 289 | if ((var->vmode & FB_VMODE_MASK) != vmode->vmode) |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 290 | return -1; |
| 291 | |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 292 | /* minimum resolution */ |
| 293 | xres = max(var->xres, 1U); |
| 294 | yres = max(var->yres, 1U); |
| 295 | |
| 296 | /* minimum margins */ |
| 297 | left_margin = max(var->left_margin, vmode->left_margin); |
| 298 | right_margin = max(var->right_margin, vmode->right_margin); |
| 299 | upper_margin = max(var->upper_margin, vmode->upper_margin); |
| 300 | lower_margin = max(var->lower_margin, vmode->lower_margin); |
| 301 | |
| 302 | /* resolution + margins may not exceed native parameters */ |
| 303 | dx = ((long)vmode->left_margin + (long)vmode->xres + |
| 304 | (long)vmode->right_margin) - |
| 305 | (left_margin + xres + right_margin); |
| 306 | if (dx < 0) |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 307 | return -1; |
| 308 | |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 309 | dy = ((long)vmode->upper_margin + (long)vmode->yres + |
| 310 | (long)vmode->lower_margin) - |
| 311 | (upper_margin + yres + lower_margin); |
| 312 | if (dy < 0) |
| 313 | return -1; |
| 314 | |
| 315 | /* exact match */ |
| 316 | if (!dx && !dy) |
| 317 | return 0; |
| 318 | |
| 319 | /* resolution difference */ |
| 320 | return (vmode->xres - xres) * (vmode->yres - yres); |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 323 | static const struct fb_videomode *ps3fb_native_vmode(enum ps3av_mode_num id) |
| 324 | { |
| 325 | return &ps3fb_modedb[FIRST_NATIVE_MODE_INDEX + id - 1]; |
| 326 | } |
| 327 | |
| 328 | static const struct fb_videomode *ps3fb_vmode(int id) |
| 329 | { |
| 330 | u32 mode = id & PS3AV_MODE_MASK; |
| 331 | |
| 332 | if (mode < PS3AV_MODE_480I || mode > PS3AV_MODE_WUXGA) |
| 333 | return NULL; |
| 334 | |
| 335 | if (mode <= PS3AV_MODE_1080P50 && !(id & PS3AV_MODE_FULL)) { |
| 336 | /* Non-fullscreen broadcast mode */ |
| 337 | return &ps3fb_modedb[mode - 1]; |
| 338 | } |
| 339 | |
| 340 | return ps3fb_native_vmode(mode); |
| 341 | } |
| 342 | |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 343 | static unsigned int ps3fb_find_mode(struct fb_var_screeninfo *var, |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 344 | u32 *ddr_line_length, u32 *xdr_line_length) |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 345 | { |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 346 | unsigned int id, best_id; |
| 347 | int diff, best_diff; |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 348 | const struct fb_videomode *vmode; |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 349 | long gap; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 350 | |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 351 | best_id = 0; |
| 352 | best_diff = INT_MAX; |
| 353 | pr_debug("%s: wanted %u [%u] %u x %u [%u] %u\n", __func__, |
| 354 | var->left_margin, var->xres, var->right_margin, |
| 355 | var->upper_margin, var->yres, var->lower_margin); |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 356 | for (id = PS3AV_MODE_480I; id <= PS3AV_MODE_WUXGA; id++) { |
| 357 | vmode = ps3fb_native_vmode(id); |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 358 | diff = ps3fb_cmp_mode(vmode, var); |
| 359 | pr_debug("%s: mode %u: %u [%u] %u x %u [%u] %u: diff = %d\n", |
| 360 | __func__, id, vmode->left_margin, vmode->xres, |
| 361 | vmode->right_margin, vmode->upper_margin, |
| 362 | vmode->yres, vmode->lower_margin, diff); |
| 363 | if (diff < 0) |
| 364 | continue; |
| 365 | if (diff < best_diff) { |
| 366 | best_id = id; |
| 367 | if (!diff) |
| 368 | break; |
| 369 | best_diff = diff; |
| 370 | } |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 371 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 372 | |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 373 | if (!best_id) { |
| 374 | pr_debug("%s: no suitable mode found\n", __func__); |
| 375 | return 0; |
| 376 | } |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 377 | |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 378 | id = best_id; |
| 379 | vmode = ps3fb_native_vmode(id); |
| 380 | |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 381 | *ddr_line_length = vmode->xres * BPP; |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 382 | |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 383 | /* minimum resolution */ |
| 384 | if (!var->xres) |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 385 | var->xres = 1; |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 386 | if (!var->yres) |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 387 | var->yres = 1; |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 388 | |
| 389 | /* minimum virtual resolution */ |
| 390 | if (var->xres_virtual < var->xres) |
| 391 | var->xres_virtual = var->xres; |
| 392 | if (var->yres_virtual < var->yres) |
| 393 | var->yres_virtual = var->yres; |
| 394 | |
| 395 | /* minimum margins */ |
| 396 | if (var->left_margin < vmode->left_margin) |
| 397 | var->left_margin = vmode->left_margin; |
| 398 | if (var->right_margin < vmode->right_margin) |
| 399 | var->right_margin = vmode->right_margin; |
| 400 | if (var->upper_margin < vmode->upper_margin) |
| 401 | var->upper_margin = vmode->upper_margin; |
| 402 | if (var->lower_margin < vmode->lower_margin) |
| 403 | var->lower_margin = vmode->lower_margin; |
| 404 | |
| 405 | /* extra margins */ |
| 406 | gap = ((long)vmode->left_margin + (long)vmode->xres + |
| 407 | (long)vmode->right_margin) - |
| 408 | ((long)var->left_margin + (long)var->xres + |
| 409 | (long)var->right_margin); |
| 410 | if (gap > 0) { |
| 411 | var->left_margin += gap/2; |
| 412 | var->right_margin += (gap+1)/2; |
| 413 | pr_debug("%s: rounded up H to %u [%u] %u\n", __func__, |
| 414 | var->left_margin, var->xres, var->right_margin); |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 415 | } |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 416 | |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 417 | gap = ((long)vmode->upper_margin + (long)vmode->yres + |
| 418 | (long)vmode->lower_margin) - |
| 419 | ((long)var->upper_margin + (long)var->yres + |
| 420 | (long)var->lower_margin); |
| 421 | if (gap > 0) { |
| 422 | var->upper_margin += gap/2; |
| 423 | var->lower_margin += (gap+1)/2; |
| 424 | pr_debug("%s: rounded up V to %u [%u] %u\n", __func__, |
| 425 | var->upper_margin, var->yres, var->lower_margin); |
| 426 | } |
| 427 | |
| 428 | /* fixed fields */ |
| 429 | var->pixclock = vmode->pixclock; |
| 430 | var->hsync_len = vmode->hsync_len; |
| 431 | var->vsync_len = vmode->vsync_len; |
| 432 | var->sync = vmode->sync; |
| 433 | |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 434 | if (ps3_compare_firmware_version(1, 9, 0) >= 0) { |
Geert Uytterhoeven | a366536 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 435 | *xdr_line_length = GPU_ALIGN_UP(var->xres_virtual * BPP); |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 436 | if (*xdr_line_length > GPU_MAX_LINE_LENGTH) |
| 437 | *xdr_line_length = GPU_MAX_LINE_LENGTH; |
| 438 | } else |
| 439 | *xdr_line_length = *ddr_line_length; |
| 440 | |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 441 | if (vmode->sync & FB_SYNC_BROADCAST) { |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 442 | /* Full broadcast modes have the full mode bit set */ |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 443 | if (vmode->xres == var->xres && vmode->yres == var->yres) |
| 444 | id |= PS3AV_MODE_FULL; |
Geert Uytterhoeven | 633bd11 | 2008-02-06 01:39:33 -0800 | [diff] [blame] | 445 | } |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 446 | |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 447 | pr_debug("%s: mode %u\n", __func__, id); |
| 448 | return id; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 449 | } |
| 450 | |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 451 | static void ps3fb_sync_image(struct device *dev, u64 frame_offset, |
| 452 | u64 dst_offset, u64 src_offset, u32 width, |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 453 | u32 height, u32 dst_line_length, |
| 454 | u32 src_line_length) |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 455 | { |
| 456 | int status; |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 457 | u64 line_length; |
| 458 | |
| 459 | line_length = dst_line_length; |
| 460 | if (src_line_length != dst_line_length) |
| 461 | line_length |= (u64)src_line_length << 32; |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 462 | |
Geert Uytterhoeven | 9ac67a3 | 2007-12-19 11:16:41 +0100 | [diff] [blame] | 463 | src_offset += GPU_FB_START; |
Geert Uytterhoeven | 9b82f3e | 2008-10-30 08:12:58 +0000 | [diff] [blame] | 464 | |
| 465 | mutex_lock(&ps3_gpu_mutex); |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 466 | status = lv1_gpu_context_attribute(ps3fb.context_handle, |
| 467 | L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT, |
| 468 | dst_offset, GPU_IOIF + src_offset, |
| 469 | L1GPU_FB_BLIT_WAIT_FOR_COMPLETION | |
| 470 | (width << 16) | height, |
| 471 | line_length); |
Geert Uytterhoeven | 9b82f3e | 2008-10-30 08:12:58 +0000 | [diff] [blame] | 472 | mutex_unlock(&ps3_gpu_mutex); |
| 473 | |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 474 | if (status) |
| 475 | dev_err(dev, |
| 476 | "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n", |
| 477 | __func__, status); |
| 478 | #ifdef HEAD_A |
| 479 | status = lv1_gpu_context_attribute(ps3fb.context_handle, |
| 480 | L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, |
| 481 | 0, frame_offset, 0, 0); |
| 482 | if (status) |
| 483 | dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n", |
| 484 | __func__, status); |
| 485 | #endif |
| 486 | #ifdef HEAD_B |
| 487 | status = lv1_gpu_context_attribute(ps3fb.context_handle, |
| 488 | L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, |
| 489 | 1, frame_offset, 0, 0); |
| 490 | if (status) |
| 491 | dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n", |
| 492 | __func__, status); |
| 493 | #endif |
| 494 | } |
| 495 | |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 496 | static int ps3fb_sync(struct fb_info *info, u32 frame) |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 497 | { |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 498 | struct ps3fb_par *par = info->par; |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 499 | int error = 0; |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 500 | u64 ddr_base, xdr_base; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 501 | |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 502 | if (frame > par->num_frames - 1) { |
Geert Uytterhoeven | 0138bd8 | 2007-10-16 01:29:46 -0700 | [diff] [blame] | 503 | dev_dbg(info->device, "%s: invalid frame number (%u)\n", |
| 504 | __func__, frame); |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 505 | error = -EINVAL; |
| 506 | goto out; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 507 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 508 | |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 509 | xdr_base = frame * par->xdr_frame_size; |
| 510 | ddr_base = frame * par->ddr_frame_size; |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 511 | |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 512 | ps3fb_sync_image(info->device, ddr_base + par->full_offset, |
| 513 | ddr_base + par->fb_offset, xdr_base + par->pan_offset, |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 514 | par->width, par->height, par->ddr_line_length, |
| 515 | info->fix.line_length); |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 516 | |
| 517 | out: |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 518 | return error; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 521 | static int ps3fb_open(struct fb_info *info, int user) |
| 522 | { |
| 523 | atomic_inc(&ps3fb.f_count); |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | static int ps3fb_release(struct fb_info *info, int user) |
| 528 | { |
| 529 | if (atomic_dec_and_test(&ps3fb.f_count)) { |
| 530 | if (atomic_read(&ps3fb.ext_flip)) { |
| 531 | atomic_set(&ps3fb.ext_flip, 0); |
Jeremy Kerr | 8dab637 | 2008-01-11 14:28:04 +0100 | [diff] [blame] | 532 | if (!try_acquire_console_sem()) { |
| 533 | ps3fb_sync(info, 0); /* single buffer */ |
| 534 | release_console_sem(); |
| 535 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | /* |
| 542 | * Setting the video mode has been split into two parts. |
| 543 | * First part, xxxfb_check_var, must not write anything |
| 544 | * to hardware, it should only verify and adjust var. |
| 545 | * This means it doesn't alter par but it does use hardware |
| 546 | * data from it to check this var. |
| 547 | */ |
| 548 | |
| 549 | static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
| 550 | { |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 551 | u32 xdr_line_length, ddr_line_length; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 552 | int mode; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 553 | |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 554 | mode = ps3fb_find_mode(var, &ddr_line_length, &xdr_line_length); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 555 | if (!mode) |
| 556 | return -EINVAL; |
| 557 | |
Geert Uytterhoeven | fc7028b7 | 2007-10-16 01:29:50 -0700 | [diff] [blame] | 558 | /* Virtual screen */ |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 559 | if (var->xres_virtual > xdr_line_length / BPP) { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 560 | dev_dbg(info->device, |
Geert Uytterhoeven | fc7028b7 | 2007-10-16 01:29:50 -0700 | [diff] [blame] | 561 | "Horizontal virtual screen size too large\n"); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 562 | return -EINVAL; |
| 563 | } |
| 564 | |
Geert Uytterhoeven | fc7028b7 | 2007-10-16 01:29:50 -0700 | [diff] [blame] | 565 | if (var->xoffset + var->xres > var->xres_virtual || |
| 566 | var->yoffset + var->yres > var->yres_virtual) { |
| 567 | dev_dbg(info->device, "panning out-of-range\n"); |
| 568 | return -EINVAL; |
| 569 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 570 | |
| 571 | /* We support ARGB8888 only */ |
| 572 | if (var->bits_per_pixel > 32 || var->grayscale || |
| 573 | var->red.offset > 16 || var->green.offset > 8 || |
| 574 | var->blue.offset > 0 || var->transp.offset > 24 || |
| 575 | var->red.length > 8 || var->green.length > 8 || |
| 576 | var->blue.length > 8 || var->transp.length > 8 || |
| 577 | var->red.msb_right || var->green.msb_right || |
| 578 | var->blue.msb_right || var->transp.msb_right || var->nonstd) { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 579 | dev_dbg(info->device, "We support ARGB8888 only\n"); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 580 | return -EINVAL; |
| 581 | } |
| 582 | |
| 583 | var->bits_per_pixel = 32; |
| 584 | var->red.offset = 16; |
| 585 | var->green.offset = 8; |
| 586 | var->blue.offset = 0; |
| 587 | var->transp.offset = 24; |
| 588 | var->red.length = 8; |
| 589 | var->green.length = 8; |
| 590 | var->blue.length = 8; |
| 591 | var->transp.length = 8; |
| 592 | var->red.msb_right = 0; |
| 593 | var->green.msb_right = 0; |
| 594 | var->blue.msb_right = 0; |
| 595 | var->transp.msb_right = 0; |
| 596 | |
| 597 | /* Rotation is not supported */ |
| 598 | if (var->rotate) { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 599 | dev_dbg(info->device, "Rotation is not supported\n"); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 600 | return -EINVAL; |
| 601 | } |
| 602 | |
| 603 | /* Memory limit */ |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 604 | if (var->yres_virtual * xdr_line_length > info->fix.smem_len) { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 605 | dev_dbg(info->device, "Not enough memory\n"); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 606 | return -ENOMEM; |
| 607 | } |
| 608 | |
| 609 | var->height = -1; |
| 610 | var->width = -1; |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | /* |
| 616 | * This routine actually sets the video mode. |
| 617 | */ |
| 618 | |
| 619 | static int ps3fb_set_par(struct fb_info *info) |
| 620 | { |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 621 | struct ps3fb_par *par = info->par; |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 622 | unsigned int mode, ddr_line_length, xdr_line_length, lines, maxlines; |
Geert Uytterhoeven | 7974f72 | 2008-02-06 01:39:32 -0800 | [diff] [blame] | 623 | unsigned int ddr_xoff, ddr_yoff, offset; |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 624 | const struct fb_videomode *vmode; |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 625 | u64 dst; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 626 | |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 627 | mode = ps3fb_find_mode(&info->var, &ddr_line_length, &xdr_line_length); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 628 | if (!mode) |
| 629 | return -EINVAL; |
| 630 | |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 631 | vmode = ps3fb_native_vmode(mode & PS3AV_MODE_MASK); |
Geert Uytterhoeven | c95344a | 2007-10-16 01:29:25 -0700 | [diff] [blame] | 632 | |
Geert Uytterhoeven | fc7028b7 | 2007-10-16 01:29:50 -0700 | [diff] [blame] | 633 | info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0; |
| 634 | info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0; |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 635 | info->fix.line_length = xdr_line_length; |
Geert Uytterhoeven | fc7028b7 | 2007-10-16 01:29:50 -0700 | [diff] [blame] | 636 | |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 637 | par->ddr_line_length = ddr_line_length; |
| 638 | par->ddr_frame_size = vmode->yres * ddr_line_length; |
| 639 | par->xdr_frame_size = info->var.yres_virtual * xdr_line_length; |
| 640 | |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 641 | par->num_frames = info->fix.smem_len / |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 642 | max(par->ddr_frame_size, par->xdr_frame_size); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 643 | |
| 644 | /* Keep the special bits we cannot set using fb_var_screeninfo */ |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 645 | par->new_mode_id = (par->new_mode_id & ~PS3AV_MODE_MASK) | mode; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 646 | |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 647 | par->width = info->var.xres; |
| 648 | par->height = info->var.yres; |
Geert Uytterhoeven | d9a4ba6 | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 649 | |
| 650 | /* Start of the virtual frame buffer (relative to fullscreen) */ |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 651 | ddr_xoff = info->var.left_margin - vmode->left_margin; |
| 652 | ddr_yoff = info->var.upper_margin - vmode->upper_margin; |
| 653 | offset = ddr_yoff * ddr_line_length + ddr_xoff * BPP; |
Geert Uytterhoeven | d9a4ba6 | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 654 | |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 655 | par->fb_offset = GPU_ALIGN_UP(offset); |
| 656 | par->full_offset = par->fb_offset - offset; |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 657 | par->pan_offset = info->var.yoffset * xdr_line_length + |
Geert Uytterhoeven | fc7028b7 | 2007-10-16 01:29:50 -0700 | [diff] [blame] | 658 | info->var.xoffset * BPP; |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 659 | |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 660 | if (par->new_mode_id != par->mode_id) { |
| 661 | if (ps3av_set_video_mode(par->new_mode_id)) { |
| 662 | par->new_mode_id = par->mode_id; |
| 663 | return -EINVAL; |
| 664 | } |
| 665 | par->mode_id = par->new_mode_id; |
| 666 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 667 | |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 668 | /* Clear XDR frame buffer memory */ |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 669 | memset((void __force *)info->screen_base, 0, info->fix.smem_len); |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 670 | |
| 671 | /* Clear DDR frame buffer memory */ |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 672 | lines = vmode->yres * par->num_frames; |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 673 | if (par->full_offset) |
| 674 | lines++; |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 675 | maxlines = info->fix.smem_len / ddr_line_length; |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 676 | for (dst = 0; lines; dst += maxlines * ddr_line_length) { |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 677 | unsigned int l = min(lines, maxlines); |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 678 | ps3fb_sync_image(info->device, 0, dst, 0, vmode->xres, l, |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 679 | ddr_line_length, ddr_line_length); |
Geert Uytterhoeven | f1664ed | 2007-10-16 01:29:49 -0700 | [diff] [blame] | 680 | lines -= l; |
| 681 | } |
| 682 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | /* |
| 687 | * Set a single color register. The values supplied are already |
| 688 | * rounded down to the hardware's capabilities (according to the |
| 689 | * entries in the var structure). Return != 0 for invalid regno. |
| 690 | */ |
| 691 | |
| 692 | static int ps3fb_setcolreg(unsigned int regno, unsigned int red, |
| 693 | unsigned int green, unsigned int blue, |
| 694 | unsigned int transp, struct fb_info *info) |
| 695 | { |
| 696 | if (regno >= 16) |
| 697 | return 1; |
| 698 | |
| 699 | red >>= 8; |
| 700 | green >>= 8; |
| 701 | blue >>= 8; |
| 702 | transp >>= 8; |
| 703 | |
| 704 | ((u32 *)info->pseudo_palette)[regno] = transp << 24 | red << 16 | |
| 705 | green << 8 | blue; |
| 706 | return 0; |
| 707 | } |
| 708 | |
Geert Uytterhoeven | fc7028b7 | 2007-10-16 01:29:50 -0700 | [diff] [blame] | 709 | static int ps3fb_pan_display(struct fb_var_screeninfo *var, |
| 710 | struct fb_info *info) |
| 711 | { |
| 712 | struct ps3fb_par *par = info->par; |
| 713 | |
| 714 | par->pan_offset = var->yoffset * info->fix.line_length + |
| 715 | var->xoffset * BPP; |
| 716 | return 0; |
| 717 | } |
| 718 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 719 | /* |
| 720 | * As we have a virtual frame buffer, we need our own mmap function |
| 721 | */ |
| 722 | |
| 723 | static int ps3fb_mmap(struct fb_info *info, struct vm_area_struct *vma) |
| 724 | { |
| 725 | unsigned long size, offset; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 726 | |
| 727 | size = vma->vm_end - vma->vm_start; |
| 728 | offset = vma->vm_pgoff << PAGE_SHIFT; |
| 729 | if (offset + size > info->fix.smem_len) |
| 730 | return -EINVAL; |
| 731 | |
Geert Uytterhoeven | 2ce32e1 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 732 | offset += info->fix.smem_start; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 733 | if (remap_pfn_range(vma, vma->vm_start, offset >> PAGE_SHIFT, |
| 734 | size, vma->vm_page_prot)) |
| 735 | return -EAGAIN; |
| 736 | |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 737 | dev_dbg(info->device, "ps3fb: mmap framebuffer P(%lx)->V(%lx)\n", |
| 738 | offset, vma->vm_start); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | /* |
| 743 | * Blank the display |
| 744 | */ |
| 745 | |
| 746 | static int ps3fb_blank(int blank, struct fb_info *info) |
| 747 | { |
| 748 | int retval; |
| 749 | |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 750 | dev_dbg(info->device, "%s: blank:%d\n", __func__, blank); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 751 | switch (blank) { |
| 752 | case FB_BLANK_POWERDOWN: |
| 753 | case FB_BLANK_HSYNC_SUSPEND: |
| 754 | case FB_BLANK_VSYNC_SUSPEND: |
| 755 | case FB_BLANK_NORMAL: |
| 756 | retval = ps3av_video_mute(1); /* mute on */ |
| 757 | if (!retval) |
| 758 | ps3fb.is_blanked = 1; |
| 759 | break; |
| 760 | |
| 761 | default: /* unblank */ |
| 762 | retval = ps3av_video_mute(0); /* mute off */ |
| 763 | if (!retval) |
| 764 | ps3fb.is_blanked = 0; |
| 765 | break; |
| 766 | } |
| 767 | return retval; |
| 768 | } |
| 769 | |
| 770 | static int ps3fb_get_vblank(struct fb_vblank *vblank) |
| 771 | { |
Li Zefan | 3cc2c17 | 2007-11-14 16:58:33 -0800 | [diff] [blame] | 772 | memset(vblank, 0, sizeof(*vblank)); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 773 | vblank->flags = FB_VBLANK_HAVE_VSYNC; |
| 774 | return 0; |
| 775 | } |
| 776 | |
Geert Uytterhoeven | 15e4d00 | 2007-10-16 01:29:47 -0700 | [diff] [blame] | 777 | static int ps3fb_wait_for_vsync(u32 crtc) |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 778 | { |
| 779 | int ret; |
| 780 | u64 count; |
| 781 | |
| 782 | count = ps3fb.vblank_count; |
| 783 | ret = wait_event_interruptible_timeout(ps3fb.wait_vsync, |
| 784 | count != ps3fb.vblank_count, |
| 785 | HZ / 10); |
| 786 | if (!ret) |
| 787 | return -ETIMEDOUT; |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 792 | |
| 793 | /* |
| 794 | * ioctl |
| 795 | */ |
| 796 | |
| 797 | static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd, |
| 798 | unsigned long arg) |
| 799 | { |
| 800 | void __user *argp = (void __user *)arg; |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 801 | u32 val; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 802 | int retval = -EFAULT; |
| 803 | |
| 804 | switch (cmd) { |
| 805 | case FBIOGET_VBLANK: |
| 806 | { |
| 807 | struct fb_vblank vblank; |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 808 | dev_dbg(info->device, "FBIOGET_VBLANK:\n"); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 809 | retval = ps3fb_get_vblank(&vblank); |
| 810 | if (retval) |
| 811 | break; |
| 812 | |
| 813 | if (copy_to_user(argp, &vblank, sizeof(vblank))) |
| 814 | retval = -EFAULT; |
| 815 | break; |
| 816 | } |
| 817 | |
| 818 | case FBIO_WAITFORVSYNC: |
| 819 | { |
| 820 | u32 crt; |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 821 | dev_dbg(info->device, "FBIO_WAITFORVSYNC:\n"); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 822 | if (get_user(crt, (u32 __user *) arg)) |
| 823 | break; |
| 824 | |
| 825 | retval = ps3fb_wait_for_vsync(crt); |
| 826 | break; |
| 827 | } |
| 828 | |
| 829 | case PS3FB_IOCTL_SETMODE: |
| 830 | { |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 831 | struct ps3fb_par *par = info->par; |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 832 | const struct fb_videomode *vmode; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 833 | struct fb_var_screeninfo var; |
| 834 | |
| 835 | if (copy_from_user(&val, argp, sizeof(val))) |
| 836 | break; |
| 837 | |
Masashi Kimoto | 6407290 | 2007-05-02 14:48:36 +0200 | [diff] [blame] | 838 | if (!(val & PS3AV_MODE_MASK)) { |
Geert Uytterhoeven | ce4c371 | 2007-10-16 01:29:44 -0700 | [diff] [blame] | 839 | u32 id = ps3av_get_auto_mode(); |
Masashi Kimoto | 6407290 | 2007-05-02 14:48:36 +0200 | [diff] [blame] | 840 | if (id > 0) |
| 841 | val = (val & ~PS3AV_MODE_MASK) | id; |
| 842 | } |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 843 | dev_dbg(info->device, "PS3FB_IOCTL_SETMODE:%x\n", val); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 844 | retval = -EINVAL; |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 845 | vmode = ps3fb_vmode(val); |
| 846 | if (vmode) { |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 847 | var = info->var; |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 848 | fb_videomode_to_var(&var, vmode); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 849 | acquire_console_sem(); |
| 850 | info->flags |= FBINFO_MISC_USEREVENT; |
| 851 | /* Force, in case only special bits changed */ |
| 852 | var.activate |= FB_ACTIVATE_FORCE; |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 853 | par->new_mode_id = val; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 854 | retval = fb_set_var(info, &var); |
| 855 | info->flags &= ~FBINFO_MISC_USEREVENT; |
| 856 | release_console_sem(); |
| 857 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 858 | break; |
| 859 | } |
| 860 | |
| 861 | case PS3FB_IOCTL_GETMODE: |
| 862 | val = ps3av_get_mode(); |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 863 | dev_dbg(info->device, "PS3FB_IOCTL_GETMODE:%x\n", val); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 864 | if (!copy_to_user(argp, &val, sizeof(val))) |
| 865 | retval = 0; |
| 866 | break; |
| 867 | |
| 868 | case PS3FB_IOCTL_SCREENINFO: |
| 869 | { |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 870 | struct ps3fb_par *par = info->par; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 871 | struct ps3fb_ioctl_res res; |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 872 | dev_dbg(info->device, "PS3FB_IOCTL_SCREENINFO:\n"); |
Geert Uytterhoeven | 61e0b28 | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 873 | res.xres = info->fix.line_length / BPP; |
| 874 | res.yres = info->var.yres_virtual; |
| 875 | res.xoff = (res.xres - info->var.xres) / 2; |
| 876 | res.yoff = (res.yres - info->var.yres) / 2; |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 877 | res.num_frames = par->num_frames; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 878 | if (!copy_to_user(argp, &res, sizeof(res))) |
| 879 | retval = 0; |
| 880 | break; |
| 881 | } |
| 882 | |
| 883 | case PS3FB_IOCTL_ON: |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 884 | dev_dbg(info->device, "PS3FB_IOCTL_ON:\n"); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 885 | atomic_inc(&ps3fb.ext_flip); |
| 886 | retval = 0; |
| 887 | break; |
| 888 | |
| 889 | case PS3FB_IOCTL_OFF: |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 890 | dev_dbg(info->device, "PS3FB_IOCTL_OFF:\n"); |
Geert Uytterhoeven | eca2874 | 2007-05-02 14:48:32 +0200 | [diff] [blame] | 891 | atomic_dec_if_positive(&ps3fb.ext_flip); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 892 | retval = 0; |
| 893 | break; |
| 894 | |
| 895 | case PS3FB_IOCTL_FSEL: |
| 896 | if (copy_from_user(&val, argp, sizeof(val))) |
| 897 | break; |
| 898 | |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 899 | dev_dbg(info->device, "PS3FB_IOCTL_FSEL:%d\n", val); |
Jeremy Kerr | 8dab637 | 2008-01-11 14:28:04 +0100 | [diff] [blame] | 900 | acquire_console_sem(); |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 901 | retval = ps3fb_sync(info, val); |
Jeremy Kerr | 8dab637 | 2008-01-11 14:28:04 +0100 | [diff] [blame] | 902 | release_console_sem(); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | default: |
| 906 | retval = -ENOIOCTLCMD; |
| 907 | break; |
| 908 | } |
| 909 | return retval; |
| 910 | } |
| 911 | |
| 912 | static int ps3fbd(void *arg) |
| 913 | { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 914 | struct fb_info *info = arg; |
| 915 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 916 | set_freezable(); |
Geert Uytterhoeven | 1c0c846 | 2007-05-02 14:48:31 +0200 | [diff] [blame] | 917 | while (!kthread_should_stop()) { |
| 918 | try_to_freeze(); |
| 919 | set_current_state(TASK_INTERRUPTIBLE); |
| 920 | if (ps3fb.is_kicked) { |
| 921 | ps3fb.is_kicked = 0; |
Jeremy Kerr | 8dab637 | 2008-01-11 14:28:04 +0100 | [diff] [blame] | 922 | acquire_console_sem(); |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 923 | ps3fb_sync(info, 0); /* single buffer */ |
Jeremy Kerr | 8dab637 | 2008-01-11 14:28:04 +0100 | [diff] [blame] | 924 | release_console_sem(); |
Geert Uytterhoeven | 1c0c846 | 2007-05-02 14:48:31 +0200 | [diff] [blame] | 925 | } |
| 926 | schedule(); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 927 | } |
| 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr) |
| 932 | { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 933 | struct device *dev = ptr; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 934 | u64 v1; |
| 935 | int status; |
| 936 | struct display_head *head = &ps3fb.dinfo->display_head[1]; |
| 937 | |
| 938 | status = lv1_gpu_context_intr(ps3fb.context_handle, &v1); |
| 939 | if (status) { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 940 | dev_err(dev, "%s: lv1_gpu_context_intr failed: %d\n", __func__, |
| 941 | status); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 942 | return IRQ_NONE; |
| 943 | } |
| 944 | |
| 945 | if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) { |
| 946 | /* VSYNC */ |
| 947 | ps3fb.vblank_count = head->vblank_count; |
Geert Uytterhoeven | 1c0c846 | 2007-05-02 14:48:31 +0200 | [diff] [blame] | 948 | if (ps3fb.task && !ps3fb.is_blanked && |
| 949 | !atomic_read(&ps3fb.ext_flip)) { |
| 950 | ps3fb.is_kicked = 1; |
| 951 | wake_up_process(ps3fb.task); |
| 952 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 953 | wake_up_interruptible(&ps3fb.wait_vsync); |
| 954 | } |
| 955 | |
| 956 | return IRQ_HANDLED; |
| 957 | } |
| 958 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 959 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 960 | static struct fb_ops ps3fb_ops = { |
| 961 | .fb_open = ps3fb_open, |
| 962 | .fb_release = ps3fb_release, |
Geert Uytterhoeven | 92c4579 | 2007-05-23 13:57:50 -0700 | [diff] [blame] | 963 | .fb_read = fb_sys_read, |
| 964 | .fb_write = fb_sys_write, |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 965 | .fb_check_var = ps3fb_check_var, |
| 966 | .fb_set_par = ps3fb_set_par, |
| 967 | .fb_setcolreg = ps3fb_setcolreg, |
Geert Uytterhoeven | fc7028b7 | 2007-10-16 01:29:50 -0700 | [diff] [blame] | 968 | .fb_pan_display = ps3fb_pan_display, |
Geert Uytterhoeven | 92c4579 | 2007-05-23 13:57:50 -0700 | [diff] [blame] | 969 | .fb_fillrect = sys_fillrect, |
| 970 | .fb_copyarea = sys_copyarea, |
| 971 | .fb_imageblit = sys_imageblit, |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 972 | .fb_mmap = ps3fb_mmap, |
| 973 | .fb_blank = ps3fb_blank, |
| 974 | .fb_ioctl = ps3fb_ioctl, |
| 975 | .fb_compat_ioctl = ps3fb_ioctl |
| 976 | }; |
| 977 | |
| 978 | static struct fb_fix_screeninfo ps3fb_fix __initdata = { |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 979 | .id = DEVICE_NAME, |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 980 | .type = FB_TYPE_PACKED_PIXELS, |
| 981 | .visual = FB_VISUAL_TRUECOLOR, |
| 982 | .accel = FB_ACCEL_NONE, |
| 983 | }; |
| 984 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 985 | static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev) |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 986 | { |
| 987 | struct fb_info *info; |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 988 | struct ps3fb_par *par; |
Geert Uytterhoeven | ca971ea | 2009-06-10 04:38:44 +0000 | [diff] [blame] | 989 | int retval; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 990 | u64 ddr_lpar = 0; |
| 991 | u64 lpar_dma_control = 0; |
| 992 | u64 lpar_driver_info = 0; |
| 993 | u64 lpar_reports = 0; |
| 994 | u64 lpar_reports_size = 0; |
| 995 | u64 xdr_lpar; |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 996 | struct gpu_driver_info *dinfo; |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 997 | void *fb_start; |
Geert Uytterhoeven | 9f4f21b | 2008-02-06 01:39:31 -0800 | [diff] [blame] | 998 | int status; |
Geert Uytterhoeven | 1c0c846 | 2007-05-02 14:48:31 +0200 | [diff] [blame] | 999 | struct task_struct *task; |
Geert Uytterhoeven | ee592a5 | 2007-11-28 16:21:11 -0800 | [diff] [blame] | 1000 | unsigned long max_ps3fb_size; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1001 | |
Geert Uytterhoeven | 9ac67a3 | 2007-12-19 11:16:41 +0100 | [diff] [blame] | 1002 | if (ps3fb_videomemory.size < GPU_CMD_BUF_SIZE) { |
| 1003 | dev_err(&dev->core, "%s: Not enough video memory\n", __func__); |
| 1004 | return -ENOMEM; |
| 1005 | } |
| 1006 | |
Geert Uytterhoeven | ca971ea | 2009-06-10 04:38:44 +0000 | [diff] [blame] | 1007 | retval = ps3_open_hv_device(dev); |
| 1008 | if (retval) { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 1009 | dev_err(&dev->core, "%s: ps3_open_hv_device failed\n", |
| 1010 | __func__); |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1011 | goto err; |
| 1012 | } |
| 1013 | |
| 1014 | if (!ps3fb_mode) |
| 1015 | ps3fb_mode = ps3av_get_mode(); |
Geert Uytterhoeven | 084ffff | 2008-02-06 01:39:29 -0800 | [diff] [blame] | 1016 | dev_dbg(&dev->core, "ps3fb_mode: %d\n", ps3fb_mode); |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1017 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1018 | atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */ |
| 1019 | atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */ |
| 1020 | init_waitqueue_head(&ps3fb.wait_vsync); |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1021 | |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1022 | #ifdef HEAD_A |
| 1023 | status = lv1_gpu_context_attribute(0x0, |
| 1024 | L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC, |
| 1025 | 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0); |
| 1026 | if (status) { |
| 1027 | dev_err(&dev->core, |
| 1028 | "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: " |
| 1029 | "%d\n", |
| 1030 | __func__, status); |
Geert Uytterhoeven | ca971ea | 2009-06-10 04:38:44 +0000 | [diff] [blame] | 1031 | retval = -ENODEV; |
| 1032 | goto err_close_device; |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1033 | } |
| 1034 | #endif |
| 1035 | #ifdef HEAD_B |
| 1036 | status = lv1_gpu_context_attribute(0x0, |
| 1037 | L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC, |
| 1038 | 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0); |
| 1039 | |
| 1040 | if (status) { |
| 1041 | dev_err(&dev->core, |
| 1042 | "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: " |
| 1043 | "%d\n", |
| 1044 | __func__, status); |
Geert Uytterhoeven | ca971ea | 2009-06-10 04:38:44 +0000 | [diff] [blame] | 1045 | retval = -ENODEV; |
| 1046 | goto err_close_device; |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1047 | } |
| 1048 | #endif |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1049 | |
Geert Uytterhoeven | ee592a5 | 2007-11-28 16:21:11 -0800 | [diff] [blame] | 1050 | max_ps3fb_size = _ALIGN_UP(GPU_IOIF, 256*1024*1024) - GPU_IOIF; |
| 1051 | if (ps3fb_videomemory.size > max_ps3fb_size) { |
| 1052 | dev_info(&dev->core, "Limiting ps3fb mem size to %lu bytes\n", |
| 1053 | max_ps3fb_size); |
| 1054 | ps3fb_videomemory.size = max_ps3fb_size; |
| 1055 | } |
| 1056 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1057 | /* get gpu context handle */ |
Geert Uytterhoeven | ee592a5 | 2007-11-28 16:21:11 -0800 | [diff] [blame] | 1058 | status = lv1_gpu_memory_allocate(ps3fb_videomemory.size, 0, 0, 0, 0, |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1059 | &ps3fb.memory_handle, &ddr_lpar); |
| 1060 | if (status) { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 1061 | dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n", |
| 1062 | __func__, status); |
Geert Uytterhoeven | ca971ea | 2009-06-10 04:38:44 +0000 | [diff] [blame] | 1063 | goto err_close_device; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1064 | } |
Stephen Rothwell | 5d9ee3f | 2009-01-13 20:13:39 +0000 | [diff] [blame] | 1065 | dev_dbg(&dev->core, "ddr:lpar:0x%llx\n", ddr_lpar); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1066 | |
| 1067 | status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0, |
| 1068 | &ps3fb.context_handle, |
| 1069 | &lpar_dma_control, &lpar_driver_info, |
| 1070 | &lpar_reports, &lpar_reports_size); |
| 1071 | if (status) { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 1072 | dev_err(&dev->core, |
| 1073 | "%s: lv1_gpu_context_attribute failed: %d\n", __func__, |
| 1074 | status); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1075 | goto err_gpu_memory_free; |
| 1076 | } |
| 1077 | |
| 1078 | /* vsync interrupt */ |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1079 | dinfo = (void __force *)ioremap(lpar_driver_info, 128 * 1024); |
| 1080 | if (!dinfo) { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 1081 | dev_err(&dev->core, "%s: ioremap failed\n", __func__); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1082 | goto err_gpu_context_free; |
| 1083 | } |
| 1084 | |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1085 | ps3fb.dinfo = dinfo; |
| 1086 | dev_dbg(&dev->core, "version_driver:%x\n", dinfo->version_driver); |
| 1087 | dev_dbg(&dev->core, "irq outlet:%x\n", dinfo->irq.irq_outlet); |
| 1088 | dev_dbg(&dev->core, "version_gpu: %x memory_size: %x ch: %x " |
| 1089 | "core_freq: %d mem_freq:%d\n", dinfo->version_gpu, |
| 1090 | dinfo->memory_size, dinfo->hardware_channel, |
| 1091 | dinfo->nvcore_frequency/1000000, |
| 1092 | dinfo->memory_frequency/1000000); |
| 1093 | |
| 1094 | if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) { |
| 1095 | dev_err(&dev->core, "%s: version_driver err:%x\n", __func__, |
| 1096 | dinfo->version_driver); |
| 1097 | retval = -EINVAL; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1098 | goto err_iounmap_dinfo; |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | retval = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet, |
| 1102 | &ps3fb.irq_no); |
| 1103 | if (retval) { |
| 1104 | dev_err(&dev->core, "%s: ps3_alloc_irq failed %d\n", __func__, |
| 1105 | retval); |
| 1106 | goto err_iounmap_dinfo; |
| 1107 | } |
| 1108 | |
| 1109 | retval = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, |
| 1110 | IRQF_DISABLED, DEVICE_NAME, &dev->core); |
| 1111 | if (retval) { |
| 1112 | dev_err(&dev->core, "%s: request_irq failed %d\n", __func__, |
| 1113 | retval); |
| 1114 | goto err_destroy_plug; |
| 1115 | } |
| 1116 | |
| 1117 | dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) | |
| 1118 | (1 << GPU_INTR_STATUS_FLIP_1); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1119 | |
Geert Uytterhoeven | 2ce32e1 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 1120 | /* Clear memory to prevent kernel info leakage into userspace */ |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 1121 | memset(ps3fb_videomemory.address, 0, ps3fb_videomemory.size); |
Geert Uytterhoeven | 2ce32e1 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 1122 | |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 1123 | xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb_videomemory.address)); |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1124 | |
| 1125 | status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF, |
Geert Uytterhoeven | e78d0c5 | 2009-06-10 04:38:46 +0000 | [diff] [blame^] | 1126 | xdr_lpar, ps3fb_videomemory.size, |
| 1127 | CBE_IOPTE_PP_W | CBE_IOPTE_PP_R | |
| 1128 | CBE_IOPTE_M); |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1129 | if (status) { |
| 1130 | dev_err(&dev->core, "%s: lv1_gpu_context_iomap failed: %d\n", |
| 1131 | __func__, status); |
| 1132 | retval = -ENXIO; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1133 | goto err_free_irq; |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | dev_dbg(&dev->core, "video:%p ioif:%lx lpar:%llx size:%lx\n", |
| 1137 | ps3fb_videomemory.address, GPU_IOIF, xdr_lpar, |
| 1138 | ps3fb_videomemory.size); |
| 1139 | |
| 1140 | status = lv1_gpu_context_attribute(ps3fb.context_handle, |
| 1141 | L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP, |
| 1142 | xdr_lpar, GPU_CMD_BUF_SIZE, |
| 1143 | GPU_IOIF, 0); |
| 1144 | if (status) { |
| 1145 | dev_err(&dev->core, |
| 1146 | "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n", |
| 1147 | __func__, status); |
| 1148 | retval = -ENXIO; |
Geert Uytterhoeven | e78d0c5 | 2009-06-10 04:38:46 +0000 | [diff] [blame^] | 1149 | goto err_context_unmap; |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1150 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1151 | |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 1152 | info = framebuffer_alloc(sizeof(struct ps3fb_par), &dev->core); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1153 | if (!info) |
Geert Uytterhoeven | e78d0c5 | 2009-06-10 04:38:46 +0000 | [diff] [blame^] | 1154 | goto err_context_unmap; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1155 | |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 1156 | par = info->par; |
| 1157 | par->mode_id = ~ps3fb_mode; /* != ps3fb_mode, to trigger change */ |
| 1158 | par->new_mode_id = ps3fb_mode; |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 1159 | par->num_frames = 1; |
| 1160 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1161 | info->fbops = &ps3fb_ops; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1162 | info->fix = ps3fb_fix; |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 1163 | |
| 1164 | /* |
| 1165 | * The GPU command buffer is at the start of video memory |
| 1166 | * As we don't use the full command buffer, we can put the actual |
| 1167 | * frame buffer at offset GPU_FB_START and save some precious XDR |
| 1168 | * memory |
| 1169 | */ |
| 1170 | fb_start = ps3fb_videomemory.address + GPU_FB_START; |
| 1171 | info->screen_base = (char __force __iomem *)fb_start; |
| 1172 | info->fix.smem_start = virt_to_abs(fb_start); |
| 1173 | info->fix.smem_len = ps3fb_videomemory.size - GPU_FB_START; |
| 1174 | |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 1175 | info->pseudo_palette = par->pseudo_palette; |
Geert Uytterhoeven | fc7028b7 | 2007-10-16 01:29:50 -0700 | [diff] [blame] | 1176 | info->flags = FBINFO_DEFAULT | FBINFO_READS_FAST | |
| 1177 | FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1178 | |
| 1179 | retval = fb_alloc_cmap(&info->cmap, 256, 0); |
| 1180 | if (retval < 0) |
| 1181 | goto err_framebuffer_release; |
| 1182 | |
| 1183 | if (!fb_find_mode(&info->var, info, mode_option, ps3fb_modedb, |
Geert Uytterhoeven | 0333d835 | 2007-10-16 01:29:48 -0700 | [diff] [blame] | 1184 | ARRAY_SIZE(ps3fb_modedb), |
Geert Uytterhoeven | 34c422f | 2008-02-06 01:39:34 -0800 | [diff] [blame] | 1185 | ps3fb_vmode(par->new_mode_id), 32)) { |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1186 | retval = -EINVAL; |
| 1187 | goto err_fb_dealloc; |
| 1188 | } |
| 1189 | |
| 1190 | fb_videomode_to_modelist(ps3fb_modedb, ARRAY_SIZE(ps3fb_modedb), |
| 1191 | &info->modelist); |
| 1192 | |
| 1193 | retval = register_framebuffer(info); |
| 1194 | if (retval < 0) |
| 1195 | goto err_fb_dealloc; |
| 1196 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1197 | dev->core.driver_data = info; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1198 | |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 1199 | dev_info(info->device, "%s %s, using %u KiB of video memory\n", |
Kay Sievers | 7ad33e7 | 2009-03-24 16:38:21 -0700 | [diff] [blame] | 1200 | dev_driver_string(info->dev), dev_name(info->dev), |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 1201 | info->fix.smem_len >> 10); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1202 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1203 | task = kthread_run(ps3fbd, info, DEVICE_NAME); |
Geert Uytterhoeven | 1c0c846 | 2007-05-02 14:48:31 +0200 | [diff] [blame] | 1204 | if (IS_ERR(task)) { |
| 1205 | retval = PTR_ERR(task); |
| 1206 | goto err_unregister_framebuffer; |
| 1207 | } |
| 1208 | |
| 1209 | ps3fb.task = task; |
| 1210 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1211 | return 0; |
| 1212 | |
Geert Uytterhoeven | 1c0c846 | 2007-05-02 14:48:31 +0200 | [diff] [blame] | 1213 | err_unregister_framebuffer: |
| 1214 | unregister_framebuffer(info); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1215 | err_fb_dealloc: |
| 1216 | fb_dealloc_cmap(&info->cmap); |
| 1217 | err_framebuffer_release: |
| 1218 | framebuffer_release(info); |
Geert Uytterhoeven | e78d0c5 | 2009-06-10 04:38:46 +0000 | [diff] [blame^] | 1219 | err_context_unmap: |
| 1220 | lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF, xdr_lpar, |
| 1221 | ps3fb_videomemory.size, CBE_IOPTE_M); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1222 | err_free_irq: |
Geoff Levand | fcbe6e9 | 2007-12-19 11:17:31 +0100 | [diff] [blame] | 1223 | free_irq(ps3fb.irq_no, &dev->core); |
Geert Uytterhoeven | bb94f07 | 2009-06-10 04:38:43 +0000 | [diff] [blame] | 1224 | err_destroy_plug: |
Geoff Levand | dc4f60c | 2007-05-01 07:01:01 +1000 | [diff] [blame] | 1225 | ps3_irq_plug_destroy(ps3fb.irq_no); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1226 | err_iounmap_dinfo: |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 1227 | iounmap((u8 __force __iomem *)ps3fb.dinfo); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1228 | err_gpu_context_free: |
| 1229 | lv1_gpu_context_free(ps3fb.context_handle); |
| 1230 | err_gpu_memory_free: |
| 1231 | lv1_gpu_memory_free(ps3fb.memory_handle); |
Geert Uytterhoeven | ca971ea | 2009-06-10 04:38:44 +0000 | [diff] [blame] | 1232 | err_close_device: |
| 1233 | ps3_close_hv_device(dev); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1234 | err: |
| 1235 | return retval; |
| 1236 | } |
| 1237 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1238 | static int ps3fb_shutdown(struct ps3_system_bus_device *dev) |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1239 | { |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1240 | struct fb_info *info = dev->core.driver_data; |
Geert Uytterhoeven | e78d0c5 | 2009-06-10 04:38:46 +0000 | [diff] [blame^] | 1241 | u64 xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb_videomemory.address)); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1242 | |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 1243 | dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__); |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1244 | |
Geert Uytterhoeven | 9b82f3e | 2008-10-30 08:12:58 +0000 | [diff] [blame] | 1245 | atomic_inc(&ps3fb.ext_flip); /* flip off */ |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1246 | ps3fb.dinfo->irq.mask = 0; |
| 1247 | |
Geert Uytterhoeven | 1c0c846 | 2007-05-02 14:48:31 +0200 | [diff] [blame] | 1248 | if (ps3fb.task) { |
| 1249 | struct task_struct *task = ps3fb.task; |
| 1250 | ps3fb.task = NULL; |
| 1251 | kthread_stop(task); |
| 1252 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1253 | if (ps3fb.irq_no) { |
Geoff Levand | fcbe6e9 | 2007-12-19 11:17:31 +0100 | [diff] [blame] | 1254 | free_irq(ps3fb.irq_no, &dev->core); |
Geoff Levand | dc4f60c | 2007-05-01 07:01:01 +1000 | [diff] [blame] | 1255 | ps3_irq_plug_destroy(ps3fb.irq_no); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1256 | } |
Jeremy Kerr | ba21611 | 2008-01-11 14:27:10 +0100 | [diff] [blame] | 1257 | if (info) { |
| 1258 | unregister_framebuffer(info); |
| 1259 | fb_dealloc_cmap(&info->cmap); |
| 1260 | framebuffer_release(info); |
| 1261 | info = dev->core.driver_data = NULL; |
| 1262 | } |
Geert Uytterhoeven | a286408 | 2008-02-06 01:39:35 -0800 | [diff] [blame] | 1263 | iounmap((u8 __force __iomem *)ps3fb.dinfo); |
Geert Uytterhoeven | e78d0c5 | 2009-06-10 04:38:46 +0000 | [diff] [blame^] | 1264 | lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF, xdr_lpar, |
| 1265 | ps3fb_videomemory.size, CBE_IOPTE_M); |
Geert Uytterhoeven | 02aad32 | 2009-06-10 04:38:42 +0000 | [diff] [blame] | 1266 | lv1_gpu_context_free(ps3fb.context_handle); |
| 1267 | lv1_gpu_memory_free(ps3fb.memory_handle); |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1268 | ps3_close_hv_device(dev); |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 1269 | dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1270 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1271 | return 0; |
| 1272 | } |
| 1273 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1274 | static struct ps3_system_bus_driver ps3fb_driver = { |
Geert Uytterhoeven | 46d0149 | 2008-12-03 13:52:21 +0000 | [diff] [blame] | 1275 | .match_id = PS3_MATCH_ID_GPU, |
| 1276 | .match_sub_id = PS3_MATCH_SUB_ID_GPU_FB, |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1277 | .core.name = DEVICE_NAME, |
| 1278 | .core.owner = THIS_MODULE, |
| 1279 | .probe = ps3fb_probe, |
| 1280 | .remove = ps3fb_shutdown, |
| 1281 | .shutdown = ps3fb_shutdown, |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1282 | }; |
| 1283 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1284 | static int __init ps3fb_setup(void) |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1285 | { |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1286 | char *options; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1287 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1288 | #ifdef MODULE |
| 1289 | return 0; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1290 | #endif |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1291 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1292 | if (fb_get_options(DEVICE_NAME, &options)) |
| 1293 | return -ENXIO; |
| 1294 | |
| 1295 | if (!options || !*options) |
| 1296 | return 0; |
| 1297 | |
| 1298 | while (1) { |
| 1299 | char *this_opt = strsep(&options, ","); |
| 1300 | |
| 1301 | if (!this_opt) |
| 1302 | break; |
| 1303 | if (!*this_opt) |
| 1304 | continue; |
| 1305 | if (!strncmp(this_opt, "mode:", 5)) |
| 1306 | ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0); |
| 1307 | else |
| 1308 | mode_option = this_opt; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1309 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1310 | return 0; |
| 1311 | } |
| 1312 | |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1313 | static int __init ps3fb_init(void) |
| 1314 | { |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1315 | if (!ps3fb_videomemory.address || ps3fb_setup()) |
| 1316 | return -ENXIO; |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1317 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1318 | return ps3_system_bus_driver_register(&ps3fb_driver); |
| 1319 | } |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1320 | |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1321 | static void __exit ps3fb_exit(void) |
| 1322 | { |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 1323 | pr_debug(" -> %s:%d\n", __func__, __LINE__); |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1324 | ps3_system_bus_driver_unregister(&ps3fb_driver); |
Geert Uytterhoeven | 535da7f | 2007-10-16 01:29:45 -0700 | [diff] [blame] | 1325 | pr_debug(" <- %s:%d\n", __func__, __LINE__); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | module_init(ps3fb_init); |
Geert Uytterhoeven | 310d8c1 | 2007-02-12 00:55:23 -0800 | [diff] [blame] | 1329 | module_exit(ps3fb_exit); |
| 1330 | |
| 1331 | MODULE_LICENSE("GPL"); |
Geert Uytterhoeven | 9e6b99b | 2007-06-16 08:05:38 +1000 | [diff] [blame] | 1332 | MODULE_DESCRIPTION("PS3 GPU Frame Buffer Driver"); |
| 1333 | MODULE_AUTHOR("Sony Computer Entertainment Inc."); |
Geert Uytterhoeven | 46d0149 | 2008-12-03 13:52:21 +0000 | [diff] [blame] | 1334 | MODULE_ALIAS(PS3_MODULE_ALIAS_GPU_FB); |