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