ps3fb.c 32 KB

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