ps3fb.c 33 KB

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