ps3fb.c 32 KB

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