ps3fb.c 31 KB

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