ps3fb.c 32 KB

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