ps3fb.c 33 KB

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