ps3fb.c 33 KB

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