ps3fb.c 32 KB

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