ps3fb.c 33 KB

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