ps3fb.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  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 int full_offset; /* start of fullscreen DDR fb */
  120. unsigned int fb_offset; /* start of actual DDR fb */
  121. unsigned int 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 int ps3fb_cmp_mode(const struct fb_videomode *vmode,
  237. const struct fb_var_screeninfo *var)
  238. {
  239. /* resolution + black border must match a native resolution */
  240. if (vmode->left_margin + vmode->xres + vmode->right_margin !=
  241. var->left_margin + var->xres + var->right_margin ||
  242. vmode->upper_margin + vmode->yres + vmode->lower_margin !=
  243. var->upper_margin + var->yres + var->lower_margin)
  244. return -1;
  245. /* minimum limits for margins */
  246. if (vmode->left_margin > var->left_margin ||
  247. vmode->right_margin > var->right_margin ||
  248. vmode->upper_margin > var->upper_margin ||
  249. vmode->lower_margin > var->lower_margin)
  250. return -1;
  251. /* these fields must match exactly */
  252. if (vmode->pixclock != var->pixclock ||
  253. vmode->hsync_len != var->hsync_len ||
  254. vmode->vsync_len != var->vsync_len ||
  255. vmode->sync != var->sync ||
  256. vmode->vmode != (var->vmode & FB_VMODE_MASK))
  257. return -1;
  258. return 0;
  259. }
  260. static unsigned int ps3fb_find_mode(struct fb_var_screeninfo *var,
  261. u32 *ddr_line_length, u32 *xdr_line_length)
  262. {
  263. unsigned int i, mode;
  264. for (i = PS3AV_MODE_1080P50; i < ARRAY_SIZE(ps3fb_modedb); i++)
  265. if (!ps3fb_cmp_mode(&ps3fb_modedb[i], var))
  266. goto found;
  267. pr_debug("ps3fb_find_mode: mode not found\n");
  268. return 0;
  269. found:
  270. *ddr_line_length = ps3fb_modedb[i].xres * BPP;
  271. if (!var->xres) {
  272. var->xres = 1;
  273. var->right_margin--;
  274. }
  275. if (!var->yres) {
  276. var->yres = 1;
  277. var->lower_margin--;
  278. }
  279. if (ps3_compare_firmware_version(1, 9, 0) >= 0) {
  280. *xdr_line_length = GPU_ALIGN_UP(max(var->xres,
  281. var->xres_virtual) * BPP);
  282. if (*xdr_line_length > GPU_MAX_LINE_LENGTH)
  283. *xdr_line_length = GPU_MAX_LINE_LENGTH;
  284. } else
  285. *xdr_line_length = *ddr_line_length;
  286. mode = i+1;
  287. if (mode > PS3AV_MODE_WUXGA) {
  288. mode -= PS3AV_MODE_WUXGA;
  289. /* Full broadcast modes have the full mode bit set */
  290. if (ps3fb_modedb[i].xres == var->xres &&
  291. ps3fb_modedb[i].yres == var->yres)
  292. mode |= PS3AV_MODE_FULL;
  293. }
  294. pr_debug("ps3fb_find_mode: mode %u\n", mode);
  295. return mode;
  296. }
  297. static const struct fb_videomode *ps3fb_default_mode(int id)
  298. {
  299. u32 mode = id & PS3AV_MODE_MASK;
  300. u32 flags;
  301. if (mode < PS3AV_MODE_480I || mode > PS3AV_MODE_WUXGA)
  302. return NULL;
  303. flags = id & ~PS3AV_MODE_MASK;
  304. if (mode <= PS3AV_MODE_1080P50 && flags & PS3AV_MODE_FULL) {
  305. /* Full broadcast mode */
  306. return &ps3fb_modedb[mode + PS3AV_MODE_WUXGA - 1];
  307. }
  308. return &ps3fb_modedb[mode - 1];
  309. }
  310. static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
  311. u64 dst_offset, u64 src_offset, u32 width,
  312. u32 height, u32 dst_line_length,
  313. u32 src_line_length)
  314. {
  315. int status;
  316. u64 line_length;
  317. line_length = dst_line_length;
  318. if (src_line_length != dst_line_length)
  319. line_length |= (u64)src_line_length << 32;
  320. src_offset += GPU_FB_START;
  321. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  322. L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
  323. dst_offset, GPU_IOIF + src_offset,
  324. L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
  325. (width << 16) | height,
  326. line_length);
  327. if (status)
  328. dev_err(dev,
  329. "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
  330. __func__, status);
  331. #ifdef HEAD_A
  332. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  333. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
  334. 0, frame_offset, 0, 0);
  335. if (status)
  336. dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
  337. __func__, status);
  338. #endif
  339. #ifdef HEAD_B
  340. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  341. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
  342. 1, frame_offset, 0, 0);
  343. if (status)
  344. dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
  345. __func__, status);
  346. #endif
  347. }
  348. static int ps3fb_sync(struct fb_info *info, u32 frame)
  349. {
  350. struct ps3fb_par *par = info->par;
  351. int error = 0;
  352. u64 ddr_base, xdr_base;
  353. if (frame > par->num_frames - 1) {
  354. dev_dbg(info->device, "%s: invalid frame number (%u)\n",
  355. __func__, frame);
  356. error = -EINVAL;
  357. goto out;
  358. }
  359. xdr_base = frame * par->xdr_frame_size;
  360. ddr_base = frame * par->ddr_frame_size;
  361. ps3fb_sync_image(info->device, ddr_base + par->full_offset,
  362. ddr_base + par->fb_offset, xdr_base + par->pan_offset,
  363. par->width, par->height, par->ddr_line_length,
  364. info->fix.line_length);
  365. out:
  366. return error;
  367. }
  368. static int ps3fb_open(struct fb_info *info, int user)
  369. {
  370. atomic_inc(&ps3fb.f_count);
  371. return 0;
  372. }
  373. static int ps3fb_release(struct fb_info *info, int user)
  374. {
  375. if (atomic_dec_and_test(&ps3fb.f_count)) {
  376. if (atomic_read(&ps3fb.ext_flip)) {
  377. atomic_set(&ps3fb.ext_flip, 0);
  378. if (!try_acquire_console_sem()) {
  379. ps3fb_sync(info, 0); /* single buffer */
  380. release_console_sem();
  381. }
  382. }
  383. }
  384. return 0;
  385. }
  386. /*
  387. * Setting the video mode has been split into two parts.
  388. * First part, xxxfb_check_var, must not write anything
  389. * to hardware, it should only verify and adjust var.
  390. * This means it doesn't alter par but it does use hardware
  391. * data from it to check this var.
  392. */
  393. static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  394. {
  395. u32 xdr_line_length, ddr_line_length;
  396. int mode;
  397. dev_dbg(info->device, "var->xres:%u info->var.xres:%u\n", var->xres,
  398. info->var.xres);
  399. dev_dbg(info->device, "var->yres:%u info->var.yres:%u\n", var->yres,
  400. info->var.yres);
  401. /* FIXME For now we do exact matches only */
  402. mode = ps3fb_find_mode(var, &ddr_line_length, &xdr_line_length);
  403. if (!mode)
  404. return -EINVAL;
  405. /* Virtual screen */
  406. if (var->xres_virtual < var->xres)
  407. var->xres_virtual = var->xres;
  408. if (var->yres_virtual < var->yres)
  409. var->yres_virtual = var->yres;
  410. if (var->xres_virtual > xdr_line_length / BPP) {
  411. dev_dbg(info->device,
  412. "Horizontal virtual screen size too large\n");
  413. return -EINVAL;
  414. }
  415. if (var->xoffset + var->xres > var->xres_virtual ||
  416. var->yoffset + var->yres > var->yres_virtual) {
  417. dev_dbg(info->device, "panning out-of-range\n");
  418. return -EINVAL;
  419. }
  420. /* We support ARGB8888 only */
  421. if (var->bits_per_pixel > 32 || var->grayscale ||
  422. var->red.offset > 16 || var->green.offset > 8 ||
  423. var->blue.offset > 0 || var->transp.offset > 24 ||
  424. var->red.length > 8 || var->green.length > 8 ||
  425. var->blue.length > 8 || var->transp.length > 8 ||
  426. var->red.msb_right || var->green.msb_right ||
  427. var->blue.msb_right || var->transp.msb_right || var->nonstd) {
  428. dev_dbg(info->device, "We support ARGB8888 only\n");
  429. return -EINVAL;
  430. }
  431. var->bits_per_pixel = 32;
  432. var->red.offset = 16;
  433. var->green.offset = 8;
  434. var->blue.offset = 0;
  435. var->transp.offset = 24;
  436. var->red.length = 8;
  437. var->green.length = 8;
  438. var->blue.length = 8;
  439. var->transp.length = 8;
  440. var->red.msb_right = 0;
  441. var->green.msb_right = 0;
  442. var->blue.msb_right = 0;
  443. var->transp.msb_right = 0;
  444. /* Rotation is not supported */
  445. if (var->rotate) {
  446. dev_dbg(info->device, "Rotation is not supported\n");
  447. return -EINVAL;
  448. }
  449. /* Memory limit */
  450. if (var->yres_virtual * xdr_line_length > ps3fb.xdr_size) {
  451. dev_dbg(info->device, "Not enough memory\n");
  452. return -ENOMEM;
  453. }
  454. var->height = -1;
  455. var->width = -1;
  456. return 0;
  457. }
  458. /*
  459. * This routine actually sets the video mode.
  460. */
  461. static int ps3fb_set_par(struct fb_info *info)
  462. {
  463. struct ps3fb_par *par = info->par;
  464. unsigned int mode, ddr_line_length, xdr_line_length, lines, maxlines;
  465. unsigned int ddr_xoff, ddr_yoff, offset;
  466. const struct fb_videomode *vmode;
  467. u64 dst;
  468. dev_dbg(info->device, "xres:%d xv:%d yres:%d yv:%d clock:%d\n",
  469. info->var.xres, info->var.xres_virtual,
  470. info->var.yres, info->var.yres_virtual, info->var.pixclock);
  471. mode = ps3fb_find_mode(&info->var, &ddr_line_length, &xdr_line_length);
  472. if (!mode)
  473. return -EINVAL;
  474. vmode = ps3fb_default_mode(mode | PS3AV_MODE_FULL);
  475. info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
  476. info->fix.smem_len = ps3fb.xdr_size;
  477. info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
  478. info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
  479. info->fix.line_length = xdr_line_length;
  480. info->screen_base = (char __iomem *)ps3fb.xdr_ea;
  481. par->ddr_line_length = ddr_line_length;
  482. par->ddr_frame_size = vmode->yres * ddr_line_length;
  483. par->xdr_frame_size = info->var.yres_virtual * xdr_line_length;
  484. par->num_frames = ps3fb.xdr_size /
  485. max(par->ddr_frame_size, par->xdr_frame_size);
  486. /* Keep the special bits we cannot set using fb_var_screeninfo */
  487. par->new_mode_id = (par->new_mode_id & ~PS3AV_MODE_MASK) | mode;
  488. par->width = info->var.xres;
  489. par->height = info->var.yres;
  490. /* Start of the virtual frame buffer (relative to fullscreen) */
  491. ddr_xoff = info->var.left_margin - vmode->left_margin;
  492. ddr_yoff = info->var.upper_margin - vmode->upper_margin;
  493. offset = ddr_yoff * ddr_line_length + ddr_xoff * BPP;
  494. par->fb_offset = GPU_ALIGN_UP(offset);
  495. par->full_offset = par->fb_offset - offset;
  496. par->pan_offset = info->var.yoffset * xdr_line_length +
  497. info->var.xoffset * BPP;
  498. if (par->new_mode_id != par->mode_id) {
  499. if (ps3av_set_video_mode(par->new_mode_id)) {
  500. par->new_mode_id = par->mode_id;
  501. return -EINVAL;
  502. }
  503. par->mode_id = par->new_mode_id;
  504. }
  505. /* Clear XDR frame buffer memory */
  506. memset(ps3fb.xdr_ea, 0, ps3fb.xdr_size);
  507. /* Clear DDR frame buffer memory */
  508. lines = vmode->yres * par->num_frames;
  509. if (par->full_offset)
  510. lines++;
  511. maxlines = ps3fb.xdr_size / ddr_line_length;
  512. for (dst = 0; lines; dst += maxlines * ddr_line_length) {
  513. unsigned int l = min(lines, maxlines);
  514. ps3fb_sync_image(info->device, 0, dst, 0, vmode->xres, l,
  515. ddr_line_length, ddr_line_length);
  516. lines -= l;
  517. }
  518. return 0;
  519. }
  520. /*
  521. * Set a single color register. The values supplied are already
  522. * rounded down to the hardware's capabilities (according to the
  523. * entries in the var structure). Return != 0 for invalid regno.
  524. */
  525. static int ps3fb_setcolreg(unsigned int regno, unsigned int red,
  526. unsigned int green, unsigned int blue,
  527. unsigned int transp, struct fb_info *info)
  528. {
  529. if (regno >= 16)
  530. return 1;
  531. red >>= 8;
  532. green >>= 8;
  533. blue >>= 8;
  534. transp >>= 8;
  535. ((u32 *)info->pseudo_palette)[regno] = transp << 24 | red << 16 |
  536. green << 8 | blue;
  537. return 0;
  538. }
  539. static int ps3fb_pan_display(struct fb_var_screeninfo *var,
  540. struct fb_info *info)
  541. {
  542. struct ps3fb_par *par = info->par;
  543. par->pan_offset = var->yoffset * info->fix.line_length +
  544. var->xoffset * BPP;
  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. dev_dbg(info->device, "PS3FB_IOCTL_SCREENINFO:\n");
  685. res.xres = info->fix.line_length / BPP;
  686. res.yres = info->var.yres_virtual;
  687. res.xoff = (res.xres - info->var.xres) / 2;
  688. res.yoff = (res.yres - info->var.yres) / 2;
  689. res.num_frames = par->num_frames;
  690. if (!copy_to_user(argp, &res, sizeof(res)))
  691. retval = 0;
  692. break;
  693. }
  694. case PS3FB_IOCTL_ON:
  695. dev_dbg(info->device, "PS3FB_IOCTL_ON:\n");
  696. atomic_inc(&ps3fb.ext_flip);
  697. retval = 0;
  698. break;
  699. case PS3FB_IOCTL_OFF:
  700. dev_dbg(info->device, "PS3FB_IOCTL_OFF:\n");
  701. atomic_dec_if_positive(&ps3fb.ext_flip);
  702. retval = 0;
  703. break;
  704. case PS3FB_IOCTL_FSEL:
  705. if (copy_from_user(&val, argp, sizeof(val)))
  706. break;
  707. dev_dbg(info->device, "PS3FB_IOCTL_FSEL:%d\n", val);
  708. acquire_console_sem();
  709. retval = ps3fb_sync(info, val);
  710. release_console_sem();
  711. break;
  712. default:
  713. retval = -ENOIOCTLCMD;
  714. break;
  715. }
  716. return retval;
  717. }
  718. static int ps3fbd(void *arg)
  719. {
  720. struct fb_info *info = arg;
  721. set_freezable();
  722. while (!kthread_should_stop()) {
  723. try_to_freeze();
  724. set_current_state(TASK_INTERRUPTIBLE);
  725. if (ps3fb.is_kicked) {
  726. ps3fb.is_kicked = 0;
  727. acquire_console_sem();
  728. ps3fb_sync(info, 0); /* single buffer */
  729. release_console_sem();
  730. }
  731. schedule();
  732. }
  733. return 0;
  734. }
  735. static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
  736. {
  737. struct device *dev = ptr;
  738. u64 v1;
  739. int status;
  740. struct display_head *head = &ps3fb.dinfo->display_head[1];
  741. status = lv1_gpu_context_intr(ps3fb.context_handle, &v1);
  742. if (status) {
  743. dev_err(dev, "%s: lv1_gpu_context_intr failed: %d\n", __func__,
  744. status);
  745. return IRQ_NONE;
  746. }
  747. if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) {
  748. /* VSYNC */
  749. ps3fb.vblank_count = head->vblank_count;
  750. if (ps3fb.task && !ps3fb.is_blanked &&
  751. !atomic_read(&ps3fb.ext_flip)) {
  752. ps3fb.is_kicked = 1;
  753. wake_up_process(ps3fb.task);
  754. }
  755. wake_up_interruptible(&ps3fb.wait_vsync);
  756. }
  757. return IRQ_HANDLED;
  758. }
  759. static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo,
  760. struct device *dev)
  761. {
  762. int error;
  763. dev_dbg(dev, "version_driver:%x\n", dinfo->version_driver);
  764. dev_dbg(dev, "irq outlet:%x\n", dinfo->irq.irq_outlet);
  765. dev_dbg(dev,
  766. "version_gpu: %x memory_size: %x ch: %x core_freq: %d "
  767. "mem_freq:%d\n",
  768. dinfo->version_gpu, dinfo->memory_size, dinfo->hardware_channel,
  769. dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000);
  770. if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
  771. dev_err(dev, "%s: version_driver err:%x\n", __func__,
  772. dinfo->version_driver);
  773. return -EINVAL;
  774. }
  775. error = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
  776. &ps3fb.irq_no);
  777. if (error) {
  778. dev_err(dev, "%s: ps3_alloc_irq failed %d\n", __func__, error);
  779. return error;
  780. }
  781. error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED,
  782. DEVICE_NAME, dev);
  783. if (error) {
  784. dev_err(dev, "%s: request_irq failed %d\n", __func__, error);
  785. ps3_irq_plug_destroy(ps3fb.irq_no);
  786. return error;
  787. }
  788. dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
  789. (1 << GPU_INTR_STATUS_FLIP_1);
  790. return 0;
  791. }
  792. static int ps3fb_xdr_settings(u64 xdr_lpar, struct device *dev)
  793. {
  794. int status;
  795. status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
  796. xdr_lpar, ps3fb_videomemory.size, 0);
  797. if (status) {
  798. dev_err(dev, "%s: lv1_gpu_context_iomap failed: %d\n",
  799. __func__, status);
  800. return -ENXIO;
  801. }
  802. dev_dbg(dev,
  803. "video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
  804. ps3fb_videomemory.address, ps3fb.xdr_ea, GPU_IOIF, xdr_lpar,
  805. virt_to_abs(ps3fb.xdr_ea), ps3fb_videomemory.size);
  806. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  807. L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
  808. xdr_lpar, GPU_CMD_BUF_SIZE,
  809. GPU_IOIF, 0);
  810. if (status) {
  811. dev_err(dev,
  812. "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
  813. __func__, status);
  814. return -ENXIO;
  815. }
  816. return 0;
  817. }
  818. static struct fb_ops ps3fb_ops = {
  819. .fb_open = ps3fb_open,
  820. .fb_release = ps3fb_release,
  821. .fb_read = fb_sys_read,
  822. .fb_write = fb_sys_write,
  823. .fb_check_var = ps3fb_check_var,
  824. .fb_set_par = ps3fb_set_par,
  825. .fb_setcolreg = ps3fb_setcolreg,
  826. .fb_pan_display = ps3fb_pan_display,
  827. .fb_fillrect = sys_fillrect,
  828. .fb_copyarea = sys_copyarea,
  829. .fb_imageblit = sys_imageblit,
  830. .fb_mmap = ps3fb_mmap,
  831. .fb_blank = ps3fb_blank,
  832. .fb_ioctl = ps3fb_ioctl,
  833. .fb_compat_ioctl = ps3fb_ioctl
  834. };
  835. static struct fb_fix_screeninfo ps3fb_fix __initdata = {
  836. .id = DEVICE_NAME,
  837. .type = FB_TYPE_PACKED_PIXELS,
  838. .visual = FB_VISUAL_TRUECOLOR,
  839. .accel = FB_ACCEL_NONE,
  840. };
  841. static int ps3fb_set_sync(struct device *dev)
  842. {
  843. int status;
  844. #ifdef HEAD_A
  845. status = lv1_gpu_context_attribute(0x0,
  846. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
  847. 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
  848. if (status) {
  849. dev_err(dev,
  850. "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
  851. "%d\n",
  852. __func__, status);
  853. return -1;
  854. }
  855. #endif
  856. #ifdef HEAD_B
  857. status = lv1_gpu_context_attribute(0x0,
  858. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
  859. 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
  860. if (status) {
  861. dev_err(dev,
  862. "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
  863. "%d\n",
  864. __func__, status);
  865. return -1;
  866. }
  867. #endif
  868. return 0;
  869. }
  870. static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
  871. {
  872. struct fb_info *info;
  873. struct ps3fb_par *par;
  874. int retval = -ENOMEM;
  875. u64 ddr_lpar = 0;
  876. u64 lpar_dma_control = 0;
  877. u64 lpar_driver_info = 0;
  878. u64 lpar_reports = 0;
  879. u64 lpar_reports_size = 0;
  880. u64 xdr_lpar;
  881. int status;
  882. struct task_struct *task;
  883. unsigned long max_ps3fb_size;
  884. if (ps3fb_videomemory.size < GPU_CMD_BUF_SIZE) {
  885. dev_err(&dev->core, "%s: Not enough video memory\n", __func__);
  886. return -ENOMEM;
  887. }
  888. status = ps3_open_hv_device(dev);
  889. if (status) {
  890. dev_err(&dev->core, "%s: ps3_open_hv_device failed\n",
  891. __func__);
  892. goto err;
  893. }
  894. if (!ps3fb_mode)
  895. ps3fb_mode = ps3av_get_mode();
  896. dev_dbg(&dev->core, "ps3fb_mode: %d\n", ps3fb_mode);
  897. atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
  898. atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
  899. init_waitqueue_head(&ps3fb.wait_vsync);
  900. ps3fb_set_sync(&dev->core);
  901. max_ps3fb_size = _ALIGN_UP(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
  902. if (ps3fb_videomemory.size > max_ps3fb_size) {
  903. dev_info(&dev->core, "Limiting ps3fb mem size to %lu bytes\n",
  904. max_ps3fb_size);
  905. ps3fb_videomemory.size = max_ps3fb_size;
  906. }
  907. /* get gpu context handle */
  908. status = lv1_gpu_memory_allocate(ps3fb_videomemory.size, 0, 0, 0, 0,
  909. &ps3fb.memory_handle, &ddr_lpar);
  910. if (status) {
  911. dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n",
  912. __func__, status);
  913. goto err;
  914. }
  915. dev_dbg(&dev->core, "ddr:lpar:0x%lx\n", ddr_lpar);
  916. status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0,
  917. &ps3fb.context_handle,
  918. &lpar_dma_control, &lpar_driver_info,
  919. &lpar_reports, &lpar_reports_size);
  920. if (status) {
  921. dev_err(&dev->core,
  922. "%s: lv1_gpu_context_attribute failed: %d\n", __func__,
  923. status);
  924. goto err_gpu_memory_free;
  925. }
  926. /* vsync interrupt */
  927. ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
  928. if (!ps3fb.dinfo) {
  929. dev_err(&dev->core, "%s: ioremap failed\n", __func__);
  930. goto err_gpu_context_free;
  931. }
  932. retval = ps3fb_vsync_settings(ps3fb.dinfo, &dev->core);
  933. if (retval)
  934. goto err_iounmap_dinfo;
  935. /* XDR frame buffer */
  936. ps3fb.xdr_ea = ps3fb_videomemory.address;
  937. xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb.xdr_ea));
  938. /* Clear memory to prevent kernel info leakage into userspace */
  939. memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
  940. /*
  941. * The GPU command buffer is at the start of video memory
  942. * As we don't use the full command buffer, we can put the actual
  943. * frame buffer at offset GPU_FB_START and save some precious XDR
  944. * memory
  945. */
  946. ps3fb.xdr_ea += GPU_FB_START;
  947. ps3fb.xdr_size = ps3fb_videomemory.size - GPU_FB_START;
  948. retval = ps3fb_xdr_settings(xdr_lpar, &dev->core);
  949. if (retval)
  950. goto err_free_irq;
  951. info = framebuffer_alloc(sizeof(struct ps3fb_par), &dev->core);
  952. if (!info)
  953. goto err_free_irq;
  954. par = info->par;
  955. par->mode_id = ~ps3fb_mode; /* != ps3fb_mode, to trigger change */
  956. par->new_mode_id = ps3fb_mode;
  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->core);
  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. ps3av_register_flip_ctl(NULL, NULL);
  1018. if (ps3fb.task) {
  1019. struct task_struct *task = ps3fb.task;
  1020. ps3fb.task = NULL;
  1021. kthread_stop(task);
  1022. }
  1023. if (ps3fb.irq_no) {
  1024. free_irq(ps3fb.irq_no, &dev->core);
  1025. ps3_irq_plug_destroy(ps3fb.irq_no);
  1026. }
  1027. if (info) {
  1028. unregister_framebuffer(info);
  1029. fb_dealloc_cmap(&info->cmap);
  1030. framebuffer_release(info);
  1031. info = dev->core.driver_data = NULL;
  1032. }
  1033. iounmap((u8 __iomem *)ps3fb.dinfo);
  1034. status = lv1_gpu_context_free(ps3fb.context_handle);
  1035. if (status)
  1036. dev_dbg(&dev->core, "lv1_gpu_context_free failed: %d\n",
  1037. status);
  1038. status = lv1_gpu_memory_free(ps3fb.memory_handle);
  1039. if (status)
  1040. dev_dbg(&dev->core, "lv1_gpu_memory_free failed: %d\n",
  1041. status);
  1042. ps3_close_hv_device(dev);
  1043. dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
  1044. return 0;
  1045. }
  1046. static struct ps3_system_bus_driver ps3fb_driver = {
  1047. .match_id = PS3_MATCH_ID_GRAPHICS,
  1048. .core.name = DEVICE_NAME,
  1049. .core.owner = THIS_MODULE,
  1050. .probe = ps3fb_probe,
  1051. .remove = ps3fb_shutdown,
  1052. .shutdown = ps3fb_shutdown,
  1053. };
  1054. static int __init ps3fb_setup(void)
  1055. {
  1056. char *options;
  1057. #ifdef MODULE
  1058. return 0;
  1059. #endif
  1060. if (fb_get_options(DEVICE_NAME, &options))
  1061. return -ENXIO;
  1062. if (!options || !*options)
  1063. return 0;
  1064. while (1) {
  1065. char *this_opt = strsep(&options, ",");
  1066. if (!this_opt)
  1067. break;
  1068. if (!*this_opt)
  1069. continue;
  1070. if (!strncmp(this_opt, "mode:", 5))
  1071. ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0);
  1072. else
  1073. mode_option = this_opt;
  1074. }
  1075. return 0;
  1076. }
  1077. static int __init ps3fb_init(void)
  1078. {
  1079. if (!ps3fb_videomemory.address || ps3fb_setup())
  1080. return -ENXIO;
  1081. return ps3_system_bus_driver_register(&ps3fb_driver);
  1082. }
  1083. static void __exit ps3fb_exit(void)
  1084. {
  1085. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  1086. ps3_system_bus_driver_unregister(&ps3fb_driver);
  1087. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  1088. }
  1089. module_init(ps3fb_init);
  1090. module_exit(ps3fb_exit);
  1091. MODULE_LICENSE("GPL");
  1092. MODULE_DESCRIPTION("PS3 GPU Frame Buffer Driver");
  1093. MODULE_AUTHOR("Sony Computer Entertainment Inc.");
  1094. MODULE_ALIAS(PS3_MODULE_ALIAS_GRAPHICS);