ps3fb.c 33 KB

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