Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v4.17 314 lines 7.4 kB view raw
1/* 2 * Copyright 2010 Matt Turner. 3 * Copyright 2012 Red Hat 4 * 5 * This file is subject to the terms and conditions of the GNU General 6 * Public License version 2. See the file COPYING in the main 7 * directory of this archive for more details. 8 * 9 * Authors: Matthew Garrett 10 * Matt Turner 11 * Dave Airlie 12 */ 13#include <linux/module.h> 14#include <drm/drmP.h> 15#include <drm/drm_fb_helper.h> 16#include <drm/drm_crtc_helper.h> 17 18#include "mgag200_drv.h" 19 20static void mga_dirty_update(struct mga_fbdev *mfbdev, 21 int x, int y, int width, int height) 22{ 23 int i; 24 struct drm_gem_object *obj; 25 struct mgag200_bo *bo; 26 int src_offset, dst_offset; 27 int bpp = mfbdev->mfb.base.format->cpp[0]; 28 int ret = -EBUSY; 29 bool unmap = false; 30 bool store_for_later = false; 31 int x2, y2; 32 unsigned long flags; 33 34 obj = mfbdev->mfb.obj; 35 bo = gem_to_mga_bo(obj); 36 37 /* 38 * try and reserve the BO, if we fail with busy 39 * then the BO is being moved and we should 40 * store up the damage until later. 41 */ 42 if (drm_can_sleep()) 43 ret = mgag200_bo_reserve(bo, true); 44 if (ret) { 45 if (ret != -EBUSY) 46 return; 47 48 store_for_later = true; 49 } 50 51 x2 = x + width - 1; 52 y2 = y + height - 1; 53 spin_lock_irqsave(&mfbdev->dirty_lock, flags); 54 55 if (mfbdev->y1 < y) 56 y = mfbdev->y1; 57 if (mfbdev->y2 > y2) 58 y2 = mfbdev->y2; 59 if (mfbdev->x1 < x) 60 x = mfbdev->x1; 61 if (mfbdev->x2 > x2) 62 x2 = mfbdev->x2; 63 64 if (store_for_later) { 65 mfbdev->x1 = x; 66 mfbdev->x2 = x2; 67 mfbdev->y1 = y; 68 mfbdev->y2 = y2; 69 spin_unlock_irqrestore(&mfbdev->dirty_lock, flags); 70 return; 71 } 72 73 mfbdev->x1 = mfbdev->y1 = INT_MAX; 74 mfbdev->x2 = mfbdev->y2 = 0; 75 spin_unlock_irqrestore(&mfbdev->dirty_lock, flags); 76 77 if (!bo->kmap.virtual) { 78 ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap); 79 if (ret) { 80 DRM_ERROR("failed to kmap fb updates\n"); 81 mgag200_bo_unreserve(bo); 82 return; 83 } 84 unmap = true; 85 } 86 for (i = y; i <= y2; i++) { 87 /* assume equal stride for now */ 88 src_offset = dst_offset = i * mfbdev->mfb.base.pitches[0] + (x * bpp); 89 memcpy_toio(bo->kmap.virtual + src_offset, mfbdev->sysram + src_offset, (x2 - x + 1) * bpp); 90 91 } 92 if (unmap) 93 ttm_bo_kunmap(&bo->kmap); 94 95 mgag200_bo_unreserve(bo); 96} 97 98static void mga_fillrect(struct fb_info *info, 99 const struct fb_fillrect *rect) 100{ 101 struct mga_fbdev *mfbdev = info->par; 102 drm_fb_helper_sys_fillrect(info, rect); 103 mga_dirty_update(mfbdev, rect->dx, rect->dy, rect->width, 104 rect->height); 105} 106 107static void mga_copyarea(struct fb_info *info, 108 const struct fb_copyarea *area) 109{ 110 struct mga_fbdev *mfbdev = info->par; 111 drm_fb_helper_sys_copyarea(info, area); 112 mga_dirty_update(mfbdev, area->dx, area->dy, area->width, 113 area->height); 114} 115 116static void mga_imageblit(struct fb_info *info, 117 const struct fb_image *image) 118{ 119 struct mga_fbdev *mfbdev = info->par; 120 drm_fb_helper_sys_imageblit(info, image); 121 mga_dirty_update(mfbdev, image->dx, image->dy, image->width, 122 image->height); 123} 124 125 126static struct fb_ops mgag200fb_ops = { 127 .owner = THIS_MODULE, 128 .fb_check_var = drm_fb_helper_check_var, 129 .fb_set_par = drm_fb_helper_set_par, 130 .fb_fillrect = mga_fillrect, 131 .fb_copyarea = mga_copyarea, 132 .fb_imageblit = mga_imageblit, 133 .fb_pan_display = drm_fb_helper_pan_display, 134 .fb_blank = drm_fb_helper_blank, 135 .fb_setcmap = drm_fb_helper_setcmap, 136}; 137 138static int mgag200fb_create_object(struct mga_fbdev *afbdev, 139 const struct drm_mode_fb_cmd2 *mode_cmd, 140 struct drm_gem_object **gobj_p) 141{ 142 struct drm_device *dev = afbdev->helper.dev; 143 u32 size; 144 struct drm_gem_object *gobj; 145 int ret = 0; 146 147 size = mode_cmd->pitches[0] * mode_cmd->height; 148 ret = mgag200_gem_create(dev, size, true, &gobj); 149 if (ret) 150 return ret; 151 152 *gobj_p = gobj; 153 return ret; 154} 155 156static int mgag200fb_create(struct drm_fb_helper *helper, 157 struct drm_fb_helper_surface_size *sizes) 158{ 159 struct mga_fbdev *mfbdev = 160 container_of(helper, struct mga_fbdev, helper); 161 struct drm_device *dev = mfbdev->helper.dev; 162 struct drm_mode_fb_cmd2 mode_cmd; 163 struct mga_device *mdev = dev->dev_private; 164 struct fb_info *info; 165 struct drm_framebuffer *fb; 166 struct drm_gem_object *gobj = NULL; 167 int ret; 168 void *sysram; 169 int size; 170 171 mode_cmd.width = sizes->surface_width; 172 mode_cmd.height = sizes->surface_height; 173 mode_cmd.pitches[0] = mode_cmd.width * ((sizes->surface_bpp + 7) / 8); 174 175 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, 176 sizes->surface_depth); 177 size = mode_cmd.pitches[0] * mode_cmd.height; 178 179 ret = mgag200fb_create_object(mfbdev, &mode_cmd, &gobj); 180 if (ret) { 181 DRM_ERROR("failed to create fbcon backing object %d\n", ret); 182 return ret; 183 } 184 185 sysram = vmalloc(size); 186 if (!sysram) { 187 ret = -ENOMEM; 188 goto err_sysram; 189 } 190 191 info = drm_fb_helper_alloc_fbi(helper); 192 if (IS_ERR(info)) { 193 ret = PTR_ERR(info); 194 goto err_alloc_fbi; 195 } 196 197 info->par = mfbdev; 198 199 ret = mgag200_framebuffer_init(dev, &mfbdev->mfb, &mode_cmd, gobj); 200 if (ret) 201 goto err_alloc_fbi; 202 203 mfbdev->sysram = sysram; 204 mfbdev->size = size; 205 206 fb = &mfbdev->mfb.base; 207 208 /* setup helper */ 209 mfbdev->helper.fb = fb; 210 211 strcpy(info->fix.id, "mgadrmfb"); 212 213 info->fbops = &mgag200fb_ops; 214 215 /* setup aperture base/size for vesafb takeover */ 216 info->apertures->ranges[0].base = mdev->dev->mode_config.fb_base; 217 info->apertures->ranges[0].size = mdev->mc.vram_size; 218 219 drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth); 220 drm_fb_helper_fill_var(info, &mfbdev->helper, sizes->fb_width, 221 sizes->fb_height); 222 223 info->screen_base = sysram; 224 info->screen_size = size; 225 info->pixmap.flags = FB_PIXMAP_SYSTEM; 226 227 DRM_DEBUG_KMS("allocated %dx%d\n", 228 fb->width, fb->height); 229 230 return 0; 231 232err_alloc_fbi: 233 vfree(sysram); 234err_sysram: 235 drm_gem_object_put_unlocked(gobj); 236 237 return ret; 238} 239 240static int mga_fbdev_destroy(struct drm_device *dev, 241 struct mga_fbdev *mfbdev) 242{ 243 struct mga_framebuffer *mfb = &mfbdev->mfb; 244 245 drm_fb_helper_unregister_fbi(&mfbdev->helper); 246 247 if (mfb->obj) { 248 drm_gem_object_put_unlocked(mfb->obj); 249 mfb->obj = NULL; 250 } 251 drm_fb_helper_fini(&mfbdev->helper); 252 vfree(mfbdev->sysram); 253 drm_framebuffer_unregister_private(&mfb->base); 254 drm_framebuffer_cleanup(&mfb->base); 255 256 return 0; 257} 258 259static const struct drm_fb_helper_funcs mga_fb_helper_funcs = { 260 .fb_probe = mgag200fb_create, 261}; 262 263int mgag200_fbdev_init(struct mga_device *mdev) 264{ 265 struct mga_fbdev *mfbdev; 266 int ret; 267 int bpp_sel = 32; 268 269 /* prefer 16bpp on low end gpus with limited VRAM */ 270 if (IS_G200_SE(mdev) && mdev->mc.vram_size < (2048*1024)) 271 bpp_sel = 16; 272 273 mfbdev = devm_kzalloc(mdev->dev->dev, sizeof(struct mga_fbdev), GFP_KERNEL); 274 if (!mfbdev) 275 return -ENOMEM; 276 277 mdev->mfbdev = mfbdev; 278 spin_lock_init(&mfbdev->dirty_lock); 279 280 drm_fb_helper_prepare(mdev->dev, &mfbdev->helper, &mga_fb_helper_funcs); 281 282 ret = drm_fb_helper_init(mdev->dev, &mfbdev->helper, 283 MGAG200FB_CONN_LIMIT); 284 if (ret) 285 goto err_fb_helper; 286 287 ret = drm_fb_helper_single_add_all_connectors(&mfbdev->helper); 288 if (ret) 289 goto err_fb_setup; 290 291 /* disable all the possible outputs/crtcs before entering KMS mode */ 292 drm_helper_disable_unused_functions(mdev->dev); 293 294 ret = drm_fb_helper_initial_config(&mfbdev->helper, bpp_sel); 295 if (ret) 296 goto err_fb_setup; 297 298 return 0; 299 300err_fb_setup: 301 drm_fb_helper_fini(&mfbdev->helper); 302err_fb_helper: 303 mdev->mfbdev = NULL; 304 305 return ret; 306} 307 308void mgag200_fbdev_fini(struct mga_device *mdev) 309{ 310 if (!mdev->mfbdev) 311 return; 312 313 mga_fbdev_destroy(mdev->dev, mdev->mfbdev); 314}