Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  linux/drivers/video/ps3fb.c -- PS3 GPU frame buffer device
0003  *
0004  *  Copyright (C) 2006 Sony Computer Entertainment Inc.
0005  *  Copyright 2006, 2007 Sony Corporation
0006  *
0007  *  This file is based on :
0008  *
0009  *  linux/drivers/video/vfb.c -- Virtual frame buffer device
0010  *
0011  *  Copyright (C) 2002 James Simmons
0012  *
0013  *  Copyright (C) 1997 Geert Uytterhoeven
0014  *
0015  *  This file is subject to the terms and conditions of the GNU General Public
0016  *  License. See the file COPYING in the main directory of this archive for
0017  *  more details.
0018  */
0019 
0020 #include <linux/module.h>
0021 #include <linux/kernel.h>
0022 #include <linux/errno.h>
0023 #include <linux/string.h>
0024 #include <linux/mm.h>
0025 #include <linux/interrupt.h>
0026 #include <linux/console.h>
0027 #include <linux/ioctl.h>
0028 #include <linux/kthread.h>
0029 #include <linux/freezer.h>
0030 #include <linux/uaccess.h>
0031 #include <linux/fb.h>
0032 #include <linux/fbcon.h>
0033 #include <linux/init.h>
0034 
0035 #include <asm/cell-regs.h>
0036 #include <asm/lv1call.h>
0037 #include <asm/ps3av.h>
0038 #include <asm/ps3fb.h>
0039 #include <asm/ps3.h>
0040 #include <asm/ps3gpu.h>
0041 
0042 
0043 #define DEVICE_NAME     "ps3fb"
0044 
0045 #define GPU_CMD_BUF_SIZE            (2 * 1024 * 1024)
0046 #define GPU_FB_START                (64 * 1024)
0047 #define GPU_IOIF                (0x0d000000UL)
0048 #define GPU_ALIGN_UP(x)             ALIGN((x), 64)
0049 #define GPU_MAX_LINE_LENGTH         (65536 - 64)
0050 
0051 #define GPU_INTR_STATUS_VSYNC_0         0   /* vsync on head A */
0052 #define GPU_INTR_STATUS_VSYNC_1         1   /* vsync on head B */
0053 #define GPU_INTR_STATUS_FLIP_0          3   /* flip head A */
0054 #define GPU_INTR_STATUS_FLIP_1          4   /* flip head B */
0055 #define GPU_INTR_STATUS_QUEUE_0         5   /* queue head A */
0056 #define GPU_INTR_STATUS_QUEUE_1         6   /* queue head B */
0057 
0058 #define GPU_DRIVER_INFO_VERSION         0x211
0059 
0060 /* gpu internals */
0061 struct display_head {
0062     u64 be_time_stamp;
0063     u32 status;
0064     u32 offset;
0065     u32 res1;
0066     u32 res2;
0067     u32 field;
0068     u32 reserved1;
0069 
0070     u64 res3;
0071     u32 raster;
0072 
0073     u64 vblank_count;
0074     u32 field_vsync;
0075     u32 reserved2;
0076 };
0077 
0078 struct gpu_irq {
0079     u32 irq_outlet;
0080     u32 status;
0081     u32 mask;
0082     u32 video_cause;
0083     u32 graph_cause;
0084     u32 user_cause;
0085 
0086     u32 res1;
0087     u64 res2;
0088 
0089     u32 reserved[4];
0090 };
0091 
0092 struct gpu_driver_info {
0093     u32 version_driver;
0094     u32 version_gpu;
0095     u32 memory_size;
0096     u32 hardware_channel;
0097 
0098     u32 nvcore_frequency;
0099     u32 memory_frequency;
0100 
0101     u32 reserved[1063];
0102     struct display_head display_head[8];
0103     struct gpu_irq irq;
0104 };
0105 
0106 struct ps3fb_priv {
0107     unsigned int irq_no;
0108 
0109     u64 context_handle, memory_handle;
0110     struct gpu_driver_info *dinfo;
0111 
0112     u64 vblank_count;   /* frame count */
0113     wait_queue_head_t wait_vsync;
0114 
0115     atomic_t ext_flip;  /* on/off flip with vsync */
0116     atomic_t f_count;   /* fb_open count */
0117     int is_blanked;
0118     int is_kicked;
0119     struct task_struct *task;
0120 };
0121 static struct ps3fb_priv ps3fb;
0122 
0123 struct ps3fb_par {
0124     u32 pseudo_palette[16];
0125     int mode_id, new_mode_id;
0126     unsigned int num_frames;    /* num of frame buffers */
0127     unsigned int width;
0128     unsigned int height;
0129     unsigned int ddr_line_length;
0130     unsigned int ddr_frame_size;
0131     unsigned int xdr_frame_size;
0132     unsigned int full_offset;   /* start of fullscreen DDR fb */
0133     unsigned int fb_offset;     /* start of actual DDR fb */
0134     unsigned int pan_offset;
0135 };
0136 
0137 
0138 #define FIRST_NATIVE_MODE_INDEX 10
0139 
0140 static const struct fb_videomode ps3fb_modedb[] = {
0141     /* 60 Hz broadcast modes (modes "1" to "5") */
0142     {
0143         /* 480i */
0144         "480i", 60, 576, 384, 74074, 130, 89, 78, 57, 63, 6,
0145         FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
0146     },    {
0147         /* 480p */
0148         "480p", 60, 576, 384, 37037, 130, 89, 78, 57, 63, 6,
0149         FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0150     },    {
0151         /* 720p */
0152         "720p", 60, 1124, 644, 13481, 298, 148, 57, 44, 80, 5,
0153         FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0154     },    {
0155         /* 1080i */
0156         "1080i", 60, 1688, 964, 13481, 264, 160, 94, 62, 88, 5,
0157         FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
0158     },    {
0159         /* 1080p */
0160         "1080p", 60, 1688, 964, 6741, 264, 160, 94, 62, 88, 5,
0161         FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0162     },
0163 
0164     /* 50 Hz broadcast modes (modes "6" to "10") */
0165     {
0166         /* 576i */
0167         "576i", 50, 576, 460, 74074, 142, 83, 97, 63, 63, 5,
0168         FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
0169     },    {
0170         /* 576p */
0171         "576p", 50, 576, 460, 37037, 142, 83, 97, 63, 63, 5,
0172         FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0173     },    {
0174         /* 720p */
0175         "720p", 50, 1124, 644, 13468, 298, 478, 57, 44, 80, 5,
0176         FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0177     },    {
0178         /* 1080i */
0179         "1080i", 50, 1688, 964, 13468, 264, 600, 94, 62, 88, 5,
0180         FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
0181     },    {
0182         /* 1080p */
0183         "1080p", 50, 1688, 964, 6734, 264, 600, 94, 62, 88, 5,
0184         FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0185     },
0186 
0187     [FIRST_NATIVE_MODE_INDEX] =
0188     /* 60 Hz broadcast modes (full resolution versions of modes "1" to "5") */
0189     {
0190     /* 480if */
0191     "480if", 60, 720, 480, 74074, 58, 17, 30, 9, 63, 6,
0192     FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
0193     }, {
0194     /* 480pf */
0195     "480pf", 60, 720, 480, 37037, 58, 17, 30, 9, 63, 6,
0196     FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0197     }, {
0198     /* 720pf */
0199     "720pf", 60, 1280, 720, 13481, 220, 70, 19, 6, 80, 5,
0200     FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0201     }, {
0202     /* 1080if */
0203     "1080if", 60, 1920, 1080, 13481, 148, 44, 36, 4, 88, 5,
0204     FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
0205     }, {
0206     /* 1080pf */
0207     "1080pf", 60, 1920, 1080, 6741, 148, 44, 36, 4, 88, 5,
0208     FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0209     },
0210 
0211     /* 50 Hz broadcast modes (full resolution versions of modes "6" to "10") */
0212     {
0213     /* 576if */
0214     "576if", 50, 720, 576, 74074, 70, 11, 39, 5, 63, 5,
0215     FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
0216     }, {
0217     /* 576pf */
0218     "576pf", 50, 720, 576, 37037, 70, 11, 39, 5, 63, 5,
0219     FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0220     }, {
0221     /* 720pf */
0222     "720pf", 50, 1280, 720, 13468, 220, 400, 19, 6, 80, 5,
0223     FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0224     }, {
0225     /* 1080if */
0226     "1080if", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
0227     FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
0228     }, {
0229     /* 1080pf */
0230     "1080pf", 50, 1920, 1080, 6734, 148, 484, 36, 4, 88, 5,
0231     FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
0232     },
0233 
0234     /* VESA modes (modes "11" to "13") */
0235     {
0236     /* WXGA */
0237     "wxga", 60, 1280, 768, 12924, 160, 24, 29, 3, 136, 6,
0238     0, FB_VMODE_NONINTERLACED,
0239     FB_MODE_IS_VESA
0240     }, {
0241     /* SXGA */
0242     "sxga", 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
0243     FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED,
0244     FB_MODE_IS_VESA
0245     }, {
0246     /* WUXGA */
0247     "wuxga", 60, 1920, 1200, 6494, 80, 48, 26, 3, 32, 6,
0248     FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED,
0249     FB_MODE_IS_VESA
0250     }
0251 };
0252 
0253 
0254 #define HEAD_A
0255 #define HEAD_B
0256 
0257 #define BPP     4           /* number of bytes per pixel */
0258 
0259 
0260 static int ps3fb_mode;
0261 module_param(ps3fb_mode, int, 0);
0262 
0263 static char *mode_option;
0264 
0265 static int ps3fb_cmp_mode(const struct fb_videomode *vmode,
0266               const struct fb_var_screeninfo *var)
0267 {
0268     long xres, yres, left_margin, right_margin, upper_margin, lower_margin;
0269     long dx, dy;
0270 
0271     /* maximum values */
0272     if (var->xres > vmode->xres || var->yres > vmode->yres ||
0273         var->pixclock > vmode->pixclock ||
0274         var->hsync_len > vmode->hsync_len ||
0275         var->vsync_len > vmode->vsync_len)
0276         return -1;
0277 
0278     /* progressive/interlaced must match */
0279     if ((var->vmode & FB_VMODE_MASK) != vmode->vmode)
0280         return -1;
0281 
0282     /* minimum resolution */
0283     xres = max(var->xres, 1U);
0284     yres = max(var->yres, 1U);
0285 
0286     /* minimum margins */
0287     left_margin = max(var->left_margin, vmode->left_margin);
0288     right_margin = max(var->right_margin, vmode->right_margin);
0289     upper_margin = max(var->upper_margin, vmode->upper_margin);
0290     lower_margin = max(var->lower_margin, vmode->lower_margin);
0291 
0292     /* resolution + margins may not exceed native parameters */
0293     dx = ((long)vmode->left_margin + (long)vmode->xres +
0294           (long)vmode->right_margin) -
0295          (left_margin + xres + right_margin);
0296     if (dx < 0)
0297         return -1;
0298 
0299     dy = ((long)vmode->upper_margin + (long)vmode->yres +
0300           (long)vmode->lower_margin) -
0301          (upper_margin + yres + lower_margin);
0302     if (dy < 0)
0303         return -1;
0304 
0305     /* exact match */
0306     if (!dx && !dy)
0307         return 0;
0308 
0309     /* resolution difference */
0310     return (vmode->xres - xres) * (vmode->yres - yres);
0311 }
0312 
0313 static const struct fb_videomode *ps3fb_native_vmode(enum ps3av_mode_num id)
0314 {
0315     return &ps3fb_modedb[FIRST_NATIVE_MODE_INDEX + id - 1];
0316 }
0317 
0318 static const struct fb_videomode *ps3fb_vmode(int id)
0319 {
0320     u32 mode = id & PS3AV_MODE_MASK;
0321 
0322     if (mode < PS3AV_MODE_480I || mode > PS3AV_MODE_WUXGA)
0323         return NULL;
0324 
0325     if (mode <= PS3AV_MODE_1080P50 && !(id & PS3AV_MODE_FULL)) {
0326         /* Non-fullscreen broadcast mode */
0327         return &ps3fb_modedb[mode - 1];
0328     }
0329 
0330     return ps3fb_native_vmode(mode);
0331 }
0332 
0333 static unsigned int ps3fb_find_mode(struct fb_var_screeninfo *var,
0334                     u32 *ddr_line_length, u32 *xdr_line_length)
0335 {
0336     unsigned int id, best_id;
0337     int diff, best_diff;
0338     const struct fb_videomode *vmode;
0339     long gap;
0340 
0341     best_id = 0;
0342     best_diff = INT_MAX;
0343     pr_debug("%s: wanted %u [%u] %u x %u [%u] %u\n", __func__,
0344          var->left_margin, var->xres, var->right_margin,
0345          var->upper_margin, var->yres, var->lower_margin);
0346     for (id = PS3AV_MODE_480I; id <= PS3AV_MODE_WUXGA; id++) {
0347         vmode = ps3fb_native_vmode(id);
0348         diff = ps3fb_cmp_mode(vmode, var);
0349         pr_debug("%s: mode %u: %u [%u] %u x %u [%u] %u: diff = %d\n",
0350              __func__, id, vmode->left_margin, vmode->xres,
0351              vmode->right_margin, vmode->upper_margin,
0352              vmode->yres, vmode->lower_margin, diff);
0353         if (diff < 0)
0354             continue;
0355         if (diff < best_diff) {
0356             best_id = id;
0357             if (!diff)
0358                 break;
0359             best_diff = diff;
0360         }
0361     }
0362 
0363     if (!best_id) {
0364         pr_debug("%s: no suitable mode found\n", __func__);
0365         return 0;
0366     }
0367 
0368     id = best_id;
0369     vmode = ps3fb_native_vmode(id);
0370 
0371     *ddr_line_length = vmode->xres * BPP;
0372 
0373     /* minimum resolution */
0374     if (!var->xres)
0375         var->xres = 1;
0376     if (!var->yres)
0377         var->yres = 1;
0378 
0379     /* minimum virtual resolution */
0380     if (var->xres_virtual < var->xres)
0381         var->xres_virtual = var->xres;
0382     if (var->yres_virtual < var->yres)
0383         var->yres_virtual = var->yres;
0384 
0385     /* minimum margins */
0386     if (var->left_margin < vmode->left_margin)
0387         var->left_margin = vmode->left_margin;
0388     if (var->right_margin < vmode->right_margin)
0389         var->right_margin = vmode->right_margin;
0390     if (var->upper_margin < vmode->upper_margin)
0391         var->upper_margin = vmode->upper_margin;
0392     if (var->lower_margin < vmode->lower_margin)
0393         var->lower_margin = vmode->lower_margin;
0394 
0395     /* extra margins */
0396     gap = ((long)vmode->left_margin + (long)vmode->xres +
0397            (long)vmode->right_margin) -
0398           ((long)var->left_margin + (long)var->xres +
0399            (long)var->right_margin);
0400     if (gap > 0) {
0401         var->left_margin += gap/2;
0402         var->right_margin += (gap+1)/2;
0403         pr_debug("%s: rounded up H to %u [%u] %u\n", __func__,
0404              var->left_margin, var->xres, var->right_margin);
0405     }
0406 
0407     gap = ((long)vmode->upper_margin + (long)vmode->yres +
0408            (long)vmode->lower_margin) -
0409           ((long)var->upper_margin + (long)var->yres +
0410            (long)var->lower_margin);
0411     if (gap > 0) {
0412         var->upper_margin += gap/2;
0413         var->lower_margin += (gap+1)/2;
0414         pr_debug("%s: rounded up V to %u [%u] %u\n", __func__,
0415              var->upper_margin, var->yres, var->lower_margin);
0416     }
0417 
0418     /* fixed fields */
0419     var->pixclock = vmode->pixclock;
0420     var->hsync_len = vmode->hsync_len;
0421     var->vsync_len = vmode->vsync_len;
0422     var->sync = vmode->sync;
0423 
0424     if (ps3_compare_firmware_version(1, 9, 0) >= 0) {
0425         *xdr_line_length = GPU_ALIGN_UP(var->xres_virtual * BPP);
0426         if (*xdr_line_length > GPU_MAX_LINE_LENGTH)
0427             *xdr_line_length = GPU_MAX_LINE_LENGTH;
0428     } else
0429         *xdr_line_length = *ddr_line_length;
0430 
0431     if (vmode->sync & FB_SYNC_BROADCAST) {
0432         /* Full broadcast modes have the full mode bit set */
0433         if (vmode->xres == var->xres && vmode->yres == var->yres)
0434             id |= PS3AV_MODE_FULL;
0435     }
0436 
0437     pr_debug("%s: mode %u\n", __func__, id);
0438     return id;
0439 }
0440 
0441 static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
0442                  u64 dst_offset, u64 src_offset, u32 width,
0443                  u32 height, u32 dst_line_length,
0444                  u32 src_line_length)
0445 {
0446     int status;
0447     u64 line_length;
0448 
0449     line_length = dst_line_length;
0450     if (src_line_length != dst_line_length)
0451         line_length |= (u64)src_line_length << 32;
0452 
0453     src_offset += GPU_FB_START;
0454 
0455     mutex_lock(&ps3_gpu_mutex);
0456     status = lv1_gpu_fb_blit(ps3fb.context_handle, dst_offset,
0457                  GPU_IOIF + src_offset,
0458                  L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
0459                  (width << 16) | height,
0460                  line_length);
0461     mutex_unlock(&ps3_gpu_mutex);
0462 
0463     if (status)
0464         dev_err(dev, "%s: lv1_gpu_fb_blit failed: %d\n", __func__,
0465             status);
0466 #ifdef HEAD_A
0467     status = lv1_gpu_display_flip(ps3fb.context_handle, 0, frame_offset);
0468     if (status)
0469         dev_err(dev, "%s: lv1_gpu_display_flip failed: %d\n", __func__,
0470             status);
0471 #endif
0472 #ifdef HEAD_B
0473     status = lv1_gpu_display_flip(ps3fb.context_handle, 1, frame_offset);
0474     if (status)
0475         dev_err(dev, "%s: lv1_gpu_display_flip failed: %d\n", __func__,
0476             status);
0477 #endif
0478 }
0479 
0480 static int ps3fb_sync(struct fb_info *info, u32 frame)
0481 {
0482     struct ps3fb_par *par = info->par;
0483     int error = 0;
0484     u64 ddr_base, xdr_base;
0485 
0486     if (frame > par->num_frames - 1) {
0487         dev_dbg(info->device, "%s: invalid frame number (%u)\n",
0488             __func__, frame);
0489         error = -EINVAL;
0490         goto out;
0491     }
0492 
0493     xdr_base = frame * par->xdr_frame_size;
0494     ddr_base = frame * par->ddr_frame_size;
0495 
0496     ps3fb_sync_image(info->device, ddr_base + par->full_offset,
0497              ddr_base + par->fb_offset, xdr_base + par->pan_offset,
0498              par->width, par->height, par->ddr_line_length,
0499              info->fix.line_length);
0500 
0501 out:
0502     return error;
0503 }
0504 
0505 static int ps3fb_open(struct fb_info *info, int user)
0506 {
0507     atomic_inc(&ps3fb.f_count);
0508     return 0;
0509 }
0510 
0511 static int ps3fb_release(struct fb_info *info, int user)
0512 {
0513     if (atomic_dec_and_test(&ps3fb.f_count)) {
0514         if (atomic_read(&ps3fb.ext_flip)) {
0515             atomic_set(&ps3fb.ext_flip, 0);
0516             if (console_trylock()) {
0517                 ps3fb_sync(info, 0);    /* single buffer */
0518                 console_unlock();
0519             }
0520         }
0521     }
0522     return 0;
0523 }
0524 
0525     /*
0526      *  Setting the video mode has been split into two parts.
0527      *  First part, xxxfb_check_var, must not write anything
0528      *  to hardware, it should only verify and adjust var.
0529      *  This means it doesn't alter par but it does use hardware
0530      *  data from it to check this var.
0531      */
0532 
0533 static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
0534 {
0535     u32 xdr_line_length, ddr_line_length;
0536     int mode;
0537 
0538     mode = ps3fb_find_mode(var, &ddr_line_length, &xdr_line_length);
0539     if (!mode)
0540         return -EINVAL;
0541 
0542     /* Virtual screen */
0543     if (var->xres_virtual > xdr_line_length / BPP) {
0544         dev_dbg(info->device,
0545             "Horizontal virtual screen size too large\n");
0546         return -EINVAL;
0547     }
0548 
0549     if (var->xoffset + var->xres > var->xres_virtual ||
0550         var->yoffset + var->yres > var->yres_virtual) {
0551         dev_dbg(info->device, "panning out-of-range\n");
0552         return -EINVAL;
0553     }
0554 
0555     /* We support ARGB8888 only */
0556     if (var->bits_per_pixel > 32 || var->grayscale ||
0557         var->red.offset > 16 || var->green.offset > 8 ||
0558         var->blue.offset > 0 || var->transp.offset > 24 ||
0559         var->red.length > 8 || var->green.length > 8 ||
0560         var->blue.length > 8 || var->transp.length > 8 ||
0561         var->red.msb_right || var->green.msb_right ||
0562         var->blue.msb_right || var->transp.msb_right || var->nonstd) {
0563         dev_dbg(info->device, "We support ARGB8888 only\n");
0564         return -EINVAL;
0565     }
0566 
0567     var->bits_per_pixel = 32;
0568     var->red.offset = 16;
0569     var->green.offset = 8;
0570     var->blue.offset = 0;
0571     var->transp.offset = 24;
0572     var->red.length = 8;
0573     var->green.length = 8;
0574     var->blue.length = 8;
0575     var->transp.length = 8;
0576     var->red.msb_right = 0;
0577     var->green.msb_right = 0;
0578     var->blue.msb_right = 0;
0579     var->transp.msb_right = 0;
0580 
0581     /* Rotation is not supported */
0582     if (var->rotate) {
0583         dev_dbg(info->device, "Rotation is not supported\n");
0584         return -EINVAL;
0585     }
0586 
0587     /* Memory limit */
0588     if (var->yres_virtual * xdr_line_length > info->fix.smem_len) {
0589         dev_dbg(info->device, "Not enough memory\n");
0590         return -ENOMEM;
0591     }
0592 
0593     var->height = -1;
0594     var->width = -1;
0595 
0596     return 0;
0597 }
0598 
0599     /*
0600      * This routine actually sets the video mode.
0601      */
0602 
0603 static int ps3fb_set_par(struct fb_info *info)
0604 {
0605     struct ps3fb_par *par = info->par;
0606     unsigned int mode, ddr_line_length, xdr_line_length, lines, maxlines;
0607     unsigned int ddr_xoff, ddr_yoff, offset;
0608     const struct fb_videomode *vmode;
0609     u64 dst;
0610 
0611     mode = ps3fb_find_mode(&info->var, &ddr_line_length, &xdr_line_length);
0612     if (!mode)
0613         return -EINVAL;
0614 
0615     vmode = ps3fb_native_vmode(mode & PS3AV_MODE_MASK);
0616 
0617     info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
0618     info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
0619     info->fix.line_length = xdr_line_length;
0620 
0621     par->ddr_line_length = ddr_line_length;
0622     par->ddr_frame_size = vmode->yres * ddr_line_length;
0623     par->xdr_frame_size = info->var.yres_virtual * xdr_line_length;
0624 
0625     par->num_frames = info->fix.smem_len /
0626               max(par->ddr_frame_size, par->xdr_frame_size);
0627 
0628     /* Keep the special bits we cannot set using fb_var_screeninfo */
0629     par->new_mode_id = (par->new_mode_id & ~PS3AV_MODE_MASK) | mode;
0630 
0631     par->width = info->var.xres;
0632     par->height = info->var.yres;
0633 
0634     /* Start of the virtual frame buffer (relative to fullscreen) */
0635     ddr_xoff = info->var.left_margin - vmode->left_margin;
0636     ddr_yoff = info->var.upper_margin - vmode->upper_margin;
0637     offset = ddr_yoff * ddr_line_length + ddr_xoff * BPP;
0638 
0639     par->fb_offset = GPU_ALIGN_UP(offset);
0640     par->full_offset = par->fb_offset - offset;
0641     par->pan_offset = info->var.yoffset * xdr_line_length +
0642               info->var.xoffset * BPP;
0643 
0644     if (par->new_mode_id != par->mode_id) {
0645         if (ps3av_set_video_mode(par->new_mode_id)) {
0646             par->new_mode_id = par->mode_id;
0647             return -EINVAL;
0648         }
0649         par->mode_id = par->new_mode_id;
0650     }
0651 
0652     /* Clear XDR frame buffer memory */
0653     memset((void __force *)info->screen_base, 0, info->fix.smem_len);
0654 
0655     /* Clear DDR frame buffer memory */
0656     lines = vmode->yres * par->num_frames;
0657     if (par->full_offset)
0658         lines++;
0659     maxlines = info->fix.smem_len / ddr_line_length;
0660     for (dst = 0; lines; dst += maxlines * ddr_line_length) {
0661         unsigned int l = min(lines, maxlines);
0662         ps3fb_sync_image(info->device, 0, dst, 0, vmode->xres, l,
0663                  ddr_line_length, ddr_line_length);
0664         lines -= l;
0665     }
0666 
0667     return 0;
0668 }
0669 
0670     /*
0671      *  Set a single color register. The values supplied are already
0672      *  rounded down to the hardware's capabilities (according to the
0673      *  entries in the var structure). Return != 0 for invalid regno.
0674      */
0675 
0676 static int ps3fb_setcolreg(unsigned int regno, unsigned int red,
0677                unsigned int green, unsigned int blue,
0678                unsigned int transp, struct fb_info *info)
0679 {
0680     if (regno >= 16)
0681         return 1;
0682 
0683     red >>= 8;
0684     green >>= 8;
0685     blue >>= 8;
0686     transp >>= 8;
0687 
0688     ((u32 *)info->pseudo_palette)[regno] = transp << 24 | red << 16 |
0689                            green << 8 | blue;
0690     return 0;
0691 }
0692 
0693 static int ps3fb_pan_display(struct fb_var_screeninfo *var,
0694                  struct fb_info *info)
0695 {
0696     struct ps3fb_par *par = info->par;
0697 
0698     par->pan_offset = var->yoffset * info->fix.line_length +
0699               var->xoffset * BPP;
0700     return 0;
0701 }
0702 
0703     /*
0704      *  As we have a virtual frame buffer, we need our own mmap function
0705      */
0706 
0707 static int ps3fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
0708 {
0709     int r;
0710 
0711     r = vm_iomap_memory(vma, info->fix.smem_start, info->fix.smem_len);
0712 
0713     dev_dbg(info->device, "ps3fb: mmap framebuffer P(%lx)->V(%lx)\n",
0714         info->fix.smem_start + (vma->vm_pgoff << PAGE_SHIFT),
0715         vma->vm_start);
0716 
0717     return r;
0718 }
0719 
0720     /*
0721      * Blank the display
0722      */
0723 
0724 static int ps3fb_blank(int blank, struct fb_info *info)
0725 {
0726     int retval;
0727 
0728     dev_dbg(info->device, "%s: blank:%d\n", __func__, blank);
0729     switch (blank) {
0730     case FB_BLANK_POWERDOWN:
0731     case FB_BLANK_HSYNC_SUSPEND:
0732     case FB_BLANK_VSYNC_SUSPEND:
0733     case FB_BLANK_NORMAL:
0734         retval = ps3av_video_mute(1);   /* mute on */
0735         if (!retval)
0736             ps3fb.is_blanked = 1;
0737         break;
0738 
0739     default:        /* unblank */
0740         retval = ps3av_video_mute(0);   /* mute off */
0741         if (!retval)
0742             ps3fb.is_blanked = 0;
0743         break;
0744     }
0745     return retval;
0746 }
0747 
0748 static int ps3fb_get_vblank(struct fb_vblank *vblank)
0749 {
0750     memset(vblank, 0, sizeof(*vblank));
0751     vblank->flags = FB_VBLANK_HAVE_VSYNC;
0752     return 0;
0753 }
0754 
0755 static int ps3fb_wait_for_vsync(u32 crtc)
0756 {
0757     int ret;
0758     u64 count;
0759 
0760     count = ps3fb.vblank_count;
0761     ret = wait_event_interruptible_timeout(ps3fb.wait_vsync,
0762                            count != ps3fb.vblank_count,
0763                            HZ / 10);
0764     if (!ret)
0765         return -ETIMEDOUT;
0766 
0767     return 0;
0768 }
0769 
0770 
0771     /*
0772      * ioctl
0773      */
0774 
0775 static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
0776                unsigned long arg)
0777 {
0778     void __user *argp = (void __user *)arg;
0779     u32 val;
0780     int retval = -EFAULT;
0781 
0782     switch (cmd) {
0783     case FBIOGET_VBLANK:
0784         {
0785             struct fb_vblank vblank;
0786             dev_dbg(info->device, "FBIOGET_VBLANK:\n");
0787             retval = ps3fb_get_vblank(&vblank);
0788             if (retval)
0789                 break;
0790 
0791             if (copy_to_user(argp, &vblank, sizeof(vblank)))
0792                 retval = -EFAULT;
0793             break;
0794         }
0795 
0796     case FBIO_WAITFORVSYNC:
0797         {
0798             u32 crt;
0799             dev_dbg(info->device, "FBIO_WAITFORVSYNC:\n");
0800             if (get_user(crt, (u32 __user *) arg))
0801                 break;
0802 
0803             retval = ps3fb_wait_for_vsync(crt);
0804             break;
0805         }
0806 
0807     case PS3FB_IOCTL_SETMODE:
0808         {
0809             struct ps3fb_par *par = info->par;
0810             const struct fb_videomode *vmode;
0811             struct fb_var_screeninfo var;
0812 
0813             if (copy_from_user(&val, argp, sizeof(val)))
0814                 break;
0815 
0816             if (!(val & PS3AV_MODE_MASK)) {
0817                 u32 id = ps3av_get_auto_mode();
0818                 if (id > 0)
0819                     val = (val & ~PS3AV_MODE_MASK) | id;
0820             }
0821             dev_dbg(info->device, "PS3FB_IOCTL_SETMODE:%x\n", val);
0822             retval = -EINVAL;
0823             vmode = ps3fb_vmode(val);
0824             if (vmode) {
0825                 var = info->var;
0826                 fb_videomode_to_var(&var, vmode);
0827                 console_lock();
0828                 /* Force, in case only special bits changed */
0829                 var.activate |= FB_ACTIVATE_FORCE;
0830                 par->new_mode_id = val;
0831                 retval = fb_set_var(info, &var);
0832                 if (!retval)
0833                     fbcon_update_vcs(info, var.activate & FB_ACTIVATE_ALL);
0834                 console_unlock();
0835             }
0836             break;
0837         }
0838 
0839     case PS3FB_IOCTL_GETMODE:
0840         val = ps3av_get_mode();
0841         dev_dbg(info->device, "PS3FB_IOCTL_GETMODE:%x\n", val);
0842         if (!copy_to_user(argp, &val, sizeof(val)))
0843             retval = 0;
0844         break;
0845 
0846     case PS3FB_IOCTL_SCREENINFO:
0847         {
0848             struct ps3fb_par *par = info->par;
0849             struct ps3fb_ioctl_res res;
0850             dev_dbg(info->device, "PS3FB_IOCTL_SCREENINFO:\n");
0851             res.xres = info->fix.line_length / BPP;
0852             res.yres = info->var.yres_virtual;
0853             res.xoff = (res.xres - info->var.xres) / 2;
0854             res.yoff = (res.yres - info->var.yres) / 2;
0855             res.num_frames = par->num_frames;
0856             if (!copy_to_user(argp, &res, sizeof(res)))
0857                 retval = 0;
0858             break;
0859         }
0860 
0861     case PS3FB_IOCTL_ON:
0862         dev_dbg(info->device, "PS3FB_IOCTL_ON:\n");
0863         atomic_inc(&ps3fb.ext_flip);
0864         retval = 0;
0865         break;
0866 
0867     case PS3FB_IOCTL_OFF:
0868         dev_dbg(info->device, "PS3FB_IOCTL_OFF:\n");
0869         atomic_dec_if_positive(&ps3fb.ext_flip);
0870         retval = 0;
0871         break;
0872 
0873     case PS3FB_IOCTL_FSEL:
0874         if (copy_from_user(&val, argp, sizeof(val)))
0875             break;
0876 
0877         dev_dbg(info->device, "PS3FB_IOCTL_FSEL:%d\n", val);
0878         console_lock();
0879         retval = ps3fb_sync(info, val);
0880         console_unlock();
0881         break;
0882 
0883     default:
0884         retval = -ENOIOCTLCMD;
0885         break;
0886     }
0887     return retval;
0888 }
0889 
0890 static int ps3fbd(void *arg)
0891 {
0892     struct fb_info *info = arg;
0893 
0894     set_freezable();
0895     while (!kthread_should_stop()) {
0896         try_to_freeze();
0897         set_current_state(TASK_INTERRUPTIBLE);
0898         if (ps3fb.is_kicked) {
0899             ps3fb.is_kicked = 0;
0900             console_lock();
0901             ps3fb_sync(info, 0);    /* single buffer */
0902             console_unlock();
0903         }
0904         schedule();
0905     }
0906     return 0;
0907 }
0908 
0909 static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
0910 {
0911     struct device *dev = ptr;
0912     u64 v1;
0913     int status;
0914     struct display_head *head = &ps3fb.dinfo->display_head[1];
0915 
0916     status = lv1_gpu_context_intr(ps3fb.context_handle, &v1);
0917     if (status) {
0918         dev_err(dev, "%s: lv1_gpu_context_intr failed: %d\n", __func__,
0919             status);
0920         return IRQ_NONE;
0921     }
0922 
0923     if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) {
0924         /* VSYNC */
0925         ps3fb.vblank_count = head->vblank_count;
0926         if (ps3fb.task && !ps3fb.is_blanked &&
0927             !atomic_read(&ps3fb.ext_flip)) {
0928             ps3fb.is_kicked = 1;
0929             wake_up_process(ps3fb.task);
0930         }
0931         wake_up_interruptible(&ps3fb.wait_vsync);
0932     }
0933 
0934     return IRQ_HANDLED;
0935 }
0936 
0937 
0938 static const struct fb_ops ps3fb_ops = {
0939     .fb_open    = ps3fb_open,
0940     .fb_release = ps3fb_release,
0941     .fb_read        = fb_sys_read,
0942     .fb_write       = fb_sys_write,
0943     .fb_check_var   = ps3fb_check_var,
0944     .fb_set_par = ps3fb_set_par,
0945     .fb_setcolreg   = ps3fb_setcolreg,
0946     .fb_pan_display = ps3fb_pan_display,
0947     .fb_fillrect    = sys_fillrect,
0948     .fb_copyarea    = sys_copyarea,
0949     .fb_imageblit   = sys_imageblit,
0950     .fb_mmap    = ps3fb_mmap,
0951     .fb_blank   = ps3fb_blank,
0952     .fb_ioctl   = ps3fb_ioctl,
0953     .fb_compat_ioctl = ps3fb_ioctl
0954 };
0955 
0956 static const struct fb_fix_screeninfo ps3fb_fix = {
0957     .id =       DEVICE_NAME,
0958     .type =     FB_TYPE_PACKED_PIXELS,
0959     .visual =   FB_VISUAL_TRUECOLOR,
0960     .accel =    FB_ACCEL_NONE,
0961 };
0962 
0963 static int ps3fb_probe(struct ps3_system_bus_device *dev)
0964 {
0965     struct fb_info *info;
0966     struct ps3fb_par *par;
0967     int retval;
0968     u64 ddr_lpar = 0;
0969     u64 lpar_dma_control = 0;
0970     u64 lpar_driver_info = 0;
0971     u64 lpar_reports = 0;
0972     u64 lpar_reports_size = 0;
0973     u64 xdr_lpar;
0974     struct gpu_driver_info *dinfo;
0975     void *fb_start;
0976     int status;
0977     struct task_struct *task;
0978     unsigned long max_ps3fb_size;
0979 
0980     if (ps3fb_videomemory.size < GPU_CMD_BUF_SIZE) {
0981         dev_err(&dev->core, "%s: Not enough video memory\n", __func__);
0982         return -ENOMEM;
0983     }
0984 
0985     retval = ps3_open_hv_device(dev);
0986     if (retval) {
0987         dev_err(&dev->core, "%s: ps3_open_hv_device failed\n",
0988             __func__);
0989         goto err;
0990     }
0991 
0992     if (!ps3fb_mode)
0993         ps3fb_mode = ps3av_get_mode();
0994     dev_dbg(&dev->core, "ps3fb_mode: %d\n", ps3fb_mode);
0995 
0996     atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
0997     atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
0998     init_waitqueue_head(&ps3fb.wait_vsync);
0999 
1000 #ifdef HEAD_A
1001     status = lv1_gpu_display_sync(0x0, 0, L1GPU_DISPLAY_SYNC_VSYNC);
1002     if (status) {
1003         dev_err(&dev->core, "%s: lv1_gpu_display_sync failed: %d\n",
1004             __func__, status);
1005         retval = -ENODEV;
1006         goto err_close_device;
1007     }
1008 #endif
1009 #ifdef HEAD_B
1010     status = lv1_gpu_display_sync(0x0, 1, L1GPU_DISPLAY_SYNC_VSYNC);
1011     if (status) {
1012         dev_err(&dev->core, "%s: lv1_gpu_display_sync failed: %d\n",
1013             __func__, status);
1014         retval = -ENODEV;
1015         goto err_close_device;
1016     }
1017 #endif
1018 
1019     max_ps3fb_size = ALIGN(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
1020     if (ps3fb_videomemory.size > max_ps3fb_size) {
1021         dev_info(&dev->core, "Limiting ps3fb mem size to %lu bytes\n",
1022              max_ps3fb_size);
1023         ps3fb_videomemory.size = max_ps3fb_size;
1024     }
1025 
1026     /* get gpu context handle */
1027     status = lv1_gpu_memory_allocate(ps3fb_videomemory.size, 0, 0, 0, 0,
1028                      &ps3fb.memory_handle, &ddr_lpar);
1029     if (status) {
1030         dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n",
1031             __func__, status);
1032         retval = -ENOMEM;
1033         goto err_close_device;
1034     }
1035     dev_dbg(&dev->core, "ddr:lpar:0x%llx\n", ddr_lpar);
1036 
1037     status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0,
1038                       &ps3fb.context_handle,
1039                       &lpar_dma_control, &lpar_driver_info,
1040                       &lpar_reports, &lpar_reports_size);
1041     if (status) {
1042         dev_err(&dev->core,
1043             "%s: lv1_gpu_context_allocate failed: %d\n", __func__,
1044             status);
1045         retval = -ENOMEM;
1046         goto err_gpu_memory_free;
1047     }
1048 
1049     /* vsync interrupt */
1050     dinfo = (void __force *)ioremap(lpar_driver_info, 128 * 1024);
1051     if (!dinfo) {
1052         dev_err(&dev->core, "%s: ioremap failed\n", __func__);
1053         retval = -ENOMEM;
1054         goto err_gpu_context_free;
1055     }
1056 
1057     ps3fb.dinfo = dinfo;
1058     dev_dbg(&dev->core, "version_driver:%x\n", dinfo->version_driver);
1059     dev_dbg(&dev->core, "irq outlet:%x\n", dinfo->irq.irq_outlet);
1060     dev_dbg(&dev->core, "version_gpu: %x memory_size: %x ch: %x "
1061         "core_freq: %d mem_freq:%d\n", dinfo->version_gpu,
1062         dinfo->memory_size, dinfo->hardware_channel,
1063         dinfo->nvcore_frequency/1000000,
1064         dinfo->memory_frequency/1000000);
1065 
1066     if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
1067         dev_err(&dev->core, "%s: version_driver err:%x\n", __func__,
1068             dinfo->version_driver);
1069         retval = -EINVAL;
1070         goto err_iounmap_dinfo;
1071     }
1072 
1073     retval = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
1074                     &ps3fb.irq_no);
1075     if (retval) {
1076         dev_err(&dev->core, "%s: ps3_alloc_irq failed %d\n", __func__,
1077             retval);
1078         goto err_iounmap_dinfo;
1079     }
1080 
1081     retval = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt,
1082                  0, DEVICE_NAME, &dev->core);
1083     if (retval) {
1084         dev_err(&dev->core, "%s: request_irq failed %d\n", __func__,
1085             retval);
1086         goto err_destroy_plug;
1087     }
1088 
1089     dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
1090               (1 << GPU_INTR_STATUS_FLIP_1);
1091 
1092     /* Clear memory to prevent kernel info leakage into userspace */
1093     memset(ps3fb_videomemory.address, 0, ps3fb_videomemory.size);
1094 
1095     xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb_videomemory.address));
1096 
1097     status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
1098                        xdr_lpar, ps3fb_videomemory.size,
1099                        CBE_IOPTE_PP_W | CBE_IOPTE_PP_R |
1100                        CBE_IOPTE_M);
1101     if (status) {
1102         dev_err(&dev->core, "%s: lv1_gpu_context_iomap failed: %d\n",
1103             __func__, status);
1104         retval =  -ENXIO;
1105         goto err_free_irq;
1106     }
1107 
1108     dev_dbg(&dev->core, "video:%p ioif:%lx lpar:%llx size:%lx\n",
1109         ps3fb_videomemory.address, GPU_IOIF, xdr_lpar,
1110         ps3fb_videomemory.size);
1111 
1112     status = lv1_gpu_fb_setup(ps3fb.context_handle, xdr_lpar,
1113                   GPU_CMD_BUF_SIZE, GPU_IOIF);
1114     if (status) {
1115         dev_err(&dev->core, "%s: lv1_gpu_fb_setup failed: %d\n",
1116             __func__, status);
1117         retval = -ENXIO;
1118         goto err_context_unmap;
1119     }
1120 
1121     info = framebuffer_alloc(sizeof(struct ps3fb_par), &dev->core);
1122     if (!info) {
1123         retval = -ENOMEM;
1124         goto err_context_fb_close;
1125     }
1126 
1127     par = info->par;
1128     par->mode_id = ~ps3fb_mode; /* != ps3fb_mode, to trigger change */
1129     par->new_mode_id = ps3fb_mode;
1130     par->num_frames = 1;
1131 
1132     info->fbops = &ps3fb_ops;
1133     info->fix = ps3fb_fix;
1134 
1135     /*
1136      * The GPU command buffer is at the start of video memory
1137      * As we don't use the full command buffer, we can put the actual
1138      * frame buffer at offset GPU_FB_START and save some precious XDR
1139      * memory
1140      */
1141     fb_start = ps3fb_videomemory.address + GPU_FB_START;
1142     info->screen_base = (char __force __iomem *)fb_start;
1143     info->fix.smem_start = __pa(fb_start);
1144     info->fix.smem_len = ps3fb_videomemory.size - GPU_FB_START;
1145 
1146     info->pseudo_palette = par->pseudo_palette;
1147     info->flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
1148               FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
1149 
1150     retval = fb_alloc_cmap(&info->cmap, 256, 0);
1151     if (retval < 0)
1152         goto err_framebuffer_release;
1153 
1154     if (!fb_find_mode(&info->var, info, mode_option, ps3fb_modedb,
1155               ARRAY_SIZE(ps3fb_modedb),
1156               ps3fb_vmode(par->new_mode_id), 32)) {
1157         retval = -EINVAL;
1158         goto err_fb_dealloc;
1159     }
1160 
1161     fb_videomode_to_modelist(ps3fb_modedb, ARRAY_SIZE(ps3fb_modedb),
1162                  &info->modelist);
1163 
1164     retval = register_framebuffer(info);
1165     if (retval < 0)
1166         goto err_fb_dealloc;
1167 
1168     ps3_system_bus_set_drvdata(dev, info);
1169 
1170     dev_info(info->device, "%s %s, using %u KiB of video memory\n",
1171          dev_driver_string(info->dev), dev_name(info->dev),
1172          info->fix.smem_len >> 10);
1173 
1174     task = kthread_run(ps3fbd, info, DEVICE_NAME);
1175     if (IS_ERR(task)) {
1176         retval = PTR_ERR(task);
1177         goto err_unregister_framebuffer;
1178     }
1179 
1180     ps3fb.task = task;
1181 
1182     return 0;
1183 
1184 err_unregister_framebuffer:
1185     unregister_framebuffer(info);
1186 err_fb_dealloc:
1187     fb_dealloc_cmap(&info->cmap);
1188 err_framebuffer_release:
1189     framebuffer_release(info);
1190 err_context_fb_close:
1191     lv1_gpu_fb_close(ps3fb.context_handle);
1192 err_context_unmap:
1193     lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF, xdr_lpar,
1194                   ps3fb_videomemory.size, CBE_IOPTE_M);
1195 err_free_irq:
1196     free_irq(ps3fb.irq_no, &dev->core);
1197 err_destroy_plug:
1198     ps3_irq_plug_destroy(ps3fb.irq_no);
1199 err_iounmap_dinfo:
1200     iounmap((u8 __force __iomem *)ps3fb.dinfo);
1201 err_gpu_context_free:
1202     lv1_gpu_context_free(ps3fb.context_handle);
1203 err_gpu_memory_free:
1204     lv1_gpu_memory_free(ps3fb.memory_handle);
1205 err_close_device:
1206     ps3_close_hv_device(dev);
1207 err:
1208     return retval;
1209 }
1210 
1211 static void ps3fb_shutdown(struct ps3_system_bus_device *dev)
1212 {
1213     struct fb_info *info = ps3_system_bus_get_drvdata(dev);
1214     u64 xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb_videomemory.address));
1215 
1216     dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__);
1217 
1218     atomic_inc(&ps3fb.ext_flip);    /* flip off */
1219     ps3fb.dinfo->irq.mask = 0;
1220 
1221     if (ps3fb.task) {
1222         struct task_struct *task = ps3fb.task;
1223         ps3fb.task = NULL;
1224         kthread_stop(task);
1225     }
1226     if (ps3fb.irq_no) {
1227         free_irq(ps3fb.irq_no, &dev->core);
1228         ps3_irq_plug_destroy(ps3fb.irq_no);
1229     }
1230     if (info) {
1231         unregister_framebuffer(info);
1232         fb_dealloc_cmap(&info->cmap);
1233         framebuffer_release(info);
1234         ps3_system_bus_set_drvdata(dev, NULL);
1235     }
1236     iounmap((u8 __force __iomem *)ps3fb.dinfo);
1237     lv1_gpu_fb_close(ps3fb.context_handle);
1238     lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF, xdr_lpar,
1239                   ps3fb_videomemory.size, CBE_IOPTE_M);
1240     lv1_gpu_context_free(ps3fb.context_handle);
1241     lv1_gpu_memory_free(ps3fb.memory_handle);
1242     ps3_close_hv_device(dev);
1243     dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
1244 }
1245 
1246 static struct ps3_system_bus_driver ps3fb_driver = {
1247     .match_id   = PS3_MATCH_ID_GPU,
1248     .match_sub_id   = PS3_MATCH_SUB_ID_GPU_FB,
1249     .core.name  = DEVICE_NAME,
1250     .core.owner = THIS_MODULE,
1251     .probe      = ps3fb_probe,
1252     .remove     = ps3fb_shutdown,
1253     .shutdown   = ps3fb_shutdown,
1254 };
1255 
1256 static int __init ps3fb_setup(void)
1257 {
1258     char *options;
1259 
1260 #ifdef MODULE
1261     return 0;
1262 #endif
1263 
1264     if (fb_get_options(DEVICE_NAME, &options))
1265         return -ENXIO;
1266 
1267     if (!options || !*options)
1268         return 0;
1269 
1270     while (1) {
1271         char *this_opt = strsep(&options, ",");
1272 
1273         if (!this_opt)
1274             break;
1275         if (!*this_opt)
1276             continue;
1277         if (!strncmp(this_opt, "mode:", 5))
1278             ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0);
1279         else
1280             mode_option = this_opt;
1281     }
1282     return 0;
1283 }
1284 
1285 static int __init ps3fb_init(void)
1286 {
1287     if (!ps3fb_videomemory.address ||  ps3fb_setup())
1288         return -ENXIO;
1289 
1290     return ps3_system_bus_driver_register(&ps3fb_driver);
1291 }
1292 
1293 static void __exit ps3fb_exit(void)
1294 {
1295     pr_debug(" -> %s:%d\n", __func__, __LINE__);
1296     ps3_system_bus_driver_unregister(&ps3fb_driver);
1297     pr_debug(" <- %s:%d\n", __func__, __LINE__);
1298 }
1299 
1300 module_init(ps3fb_init);
1301 module_exit(ps3fb_exit);
1302 
1303 MODULE_LICENSE("GPL");
1304 MODULE_DESCRIPTION("PS3 GPU Frame Buffer Driver");
1305 MODULE_AUTHOR("Sony Computer Entertainment Inc.");
1306 MODULE_ALIAS(PS3_MODULE_ALIAS_GPU_FB);