[58129] | 1 | /* $Id: vbox_fb.c 102874 2024-01-15 12:08:04Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[53793] | 3 | * VirtualBox Additions Linux kernel video driver
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2013-2023 Oracle and/or its affiliates.
|
---|
[66544] | 8 | * This file is based on ast_fb.c
|
---|
[53793] | 9 | * Copyright 2012 Red Hat Inc.
|
---|
| 10 | *
|
---|
| 11 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
| 12 | * copy of this software and associated documentation files (the
|
---|
| 13 | * "Software"), to deal in the Software without restriction, including
|
---|
| 14 | * without limitation the rights to use, copy, modify, merge, publish,
|
---|
| 15 | * distribute, sub license, and/or sell copies of the Software, and to
|
---|
| 16 | * permit persons to whom the Software is furnished to do so, subject to
|
---|
| 17 | * the following conditions:
|
---|
| 18 | *
|
---|
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
---|
| 22 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
---|
| 23 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
---|
| 24 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
---|
| 25 | * USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
| 26 | *
|
---|
| 27 | * The above copyright notice and this permission notice (including the
|
---|
| 28 | * next paragraph) shall be included in all copies or substantial portions
|
---|
| 29 | * of the Software.
|
---|
| 30 | *
|
---|
| 31 | * Authors: Dave Airlie <airlied@redhat.com>
|
---|
[66544] | 32 | * Michael Thayer <michael.thayer@oracle.com,
|
---|
[53793] | 33 | */
|
---|
| 34 | #include <linux/module.h>
|
---|
| 35 | #include <linux/kernel.h>
|
---|
| 36 | #include <linux/errno.h>
|
---|
| 37 | #include <linux/string.h>
|
---|
| 38 | #include <linux/mm.h>
|
---|
| 39 | #include <linux/tty.h>
|
---|
| 40 | #include <linux/sysrq.h>
|
---|
| 41 | #include <linux/delay.h>
|
---|
| 42 | #include <linux/fb.h>
|
---|
| 43 | #include <linux/init.h>
|
---|
| 44 |
|
---|
[83109] | 45 | #include "vbox_drv.h"
|
---|
| 46 |
|
---|
[53793] | 47 | #include <drm/drm_crtc.h>
|
---|
| 48 | #include <drm/drm_fb_helper.h>
|
---|
[59526] | 49 | #include <drm/drm_crtc_helper.h>
|
---|
[74773] | 50 |
|
---|
| 51 | #include <VBoxVideo.h>
|
---|
[53793] | 52 |
|
---|
[102874] | 53 | #if RTLNX_VER_MIN(6,2,0) || RTLNX_RHEL_RANGE(8,9, 8,99) || RTLNX_RHEL_RANGE(9,3, 9,99)
|
---|
[98034] | 54 | # define VBOX_FBDEV_INFO(_helper) _helper.info
|
---|
| 55 | #else
|
---|
| 56 | # define VBOX_FBDEV_INFO(_helper) _helper.fbdev
|
---|
| 57 | #endif
|
---|
| 58 |
|
---|
[85705] | 59 | #if RTLNX_VER_MAX(4,7,0) && !RTLNX_RHEL_MAJ_PREREQ(7,4)
|
---|
[53793] | 60 | /**
|
---|
| 61 | * Tell the host about dirty rectangles to update.
|
---|
| 62 | */
|
---|
[59640] | 63 | static void vbox_dirty_update(struct vbox_fbdev *fbdev,
|
---|
[67397] | 64 | int x, int y, int width, int height)
|
---|
[53793] | 65 | {
|
---|
[67397] | 66 | struct drm_gem_object *obj;
|
---|
| 67 | struct vbox_bo *bo;
|
---|
| 68 | int ret = -EBUSY;
|
---|
| 69 | bool store_for_later = false;
|
---|
| 70 | int x2, y2;
|
---|
| 71 | unsigned long flags;
|
---|
| 72 | struct drm_clip_rect rect;
|
---|
[53793] | 73 |
|
---|
[67397] | 74 | obj = fbdev->afb.obj;
|
---|
| 75 | bo = gem_to_vbox_bo(obj);
|
---|
[53793] | 76 |
|
---|
[67397] | 77 | /*
|
---|
| 78 | * try and reserve the BO, if we fail with busy
|
---|
| 79 | * then the BO is being moved and we should
|
---|
| 80 | * store up the damage until later.
|
---|
| 81 | */
|
---|
| 82 | if (drm_can_sleep())
|
---|
| 83 | ret = vbox_bo_reserve(bo, true);
|
---|
| 84 | if (ret) {
|
---|
| 85 | if (ret != -EBUSY)
|
---|
| 86 | return;
|
---|
[53793] | 87 |
|
---|
[67397] | 88 | store_for_later = true;
|
---|
| 89 | }
|
---|
[53793] | 90 |
|
---|
[67397] | 91 | x2 = x + width - 1;
|
---|
| 92 | y2 = y + height - 1;
|
---|
| 93 | spin_lock_irqsave(&fbdev->dirty_lock, flags);
|
---|
[53793] | 94 |
|
---|
[67397] | 95 | if (fbdev->y1 < y)
|
---|
| 96 | y = fbdev->y1;
|
---|
| 97 | if (fbdev->y2 > y2)
|
---|
| 98 | y2 = fbdev->y2;
|
---|
| 99 | if (fbdev->x1 < x)
|
---|
| 100 | x = fbdev->x1;
|
---|
| 101 | if (fbdev->x2 > x2)
|
---|
| 102 | x2 = fbdev->x2;
|
---|
[53793] | 103 |
|
---|
[67397] | 104 | if (store_for_later) {
|
---|
| 105 | fbdev->x1 = x;
|
---|
| 106 | fbdev->x2 = x2;
|
---|
| 107 | fbdev->y1 = y;
|
---|
| 108 | fbdev->y2 = y2;
|
---|
| 109 | spin_unlock_irqrestore(&fbdev->dirty_lock, flags);
|
---|
| 110 | return;
|
---|
| 111 | }
|
---|
[53793] | 112 |
|
---|
[67397] | 113 | fbdev->x1 = INT_MAX;
|
---|
| 114 | fbdev->y1 = INT_MAX;
|
---|
| 115 | fbdev->x2 = 0;
|
---|
| 116 | fbdev->y2 = 0;
|
---|
[53793] | 117 |
|
---|
[67397] | 118 | spin_unlock_irqrestore(&fbdev->dirty_lock, flags);
|
---|
[53793] | 119 |
|
---|
[67397] | 120 | /*
|
---|
| 121 | * Not sure why the original code subtracted 1 here, but I will keep
|
---|
| 122 | * it that way to avoid unnecessary differences.
|
---|
| 123 | */
|
---|
| 124 | rect.x1 = x;
|
---|
| 125 | rect.x2 = x2 + 1;
|
---|
| 126 | rect.y1 = y;
|
---|
| 127 | rect.y2 = y2 + 1;
|
---|
| 128 | vbox_framebuffer_dirty_rectangles(&fbdev->afb.base, &rect, 1);
|
---|
| 129 |
|
---|
| 130 | vbox_bo_unreserve(bo);
|
---|
[53793] | 131 | }
|
---|
[85707] | 132 | #endif /* RTLNX_VER_MAX(4,7,0) && !RTLNX_RHEL_MAJ_PREREQ(7,4) */
|
---|
[53793] | 133 |
|
---|
[61602] | 134 | #ifdef CONFIG_FB_DEFERRED_IO
|
---|
[85705] | 135 | # if RTLNX_VER_MAX(4,7,0) && !RTLNX_RHEL_MAJ_PREREQ(7,4)
|
---|
[74864] | 136 | static void drm_fb_helper_deferred_io(struct fb_info *info, struct list_head *pagelist)
|
---|
[61597] | 137 | {
|
---|
[67397] | 138 | struct vbox_fbdev *fbdev = info->par;
|
---|
| 139 | unsigned long start, end, min, max;
|
---|
| 140 | struct page *page;
|
---|
| 141 | int y1, y2;
|
---|
[61597] | 142 |
|
---|
[67397] | 143 | min = ULONG_MAX;
|
---|
| 144 | max = 0;
|
---|
| 145 | list_for_each_entry(page, pagelist, lru) {
|
---|
| 146 | start = page->index << PAGE_SHIFT;
|
---|
| 147 | end = start + PAGE_SIZE - 1;
|
---|
| 148 | min = min(min, start);
|
---|
| 149 | max = max(max, end);
|
---|
| 150 | }
|
---|
[61597] | 151 |
|
---|
[67397] | 152 | if (min < max) {
|
---|
| 153 | y1 = min / info->fix.line_length;
|
---|
| 154 | y2 = (max / info->fix.line_length) + 1;
|
---|
| 155 | DRM_INFO("%s: Calling dirty update: 0, %d, %d, %d\n",
|
---|
| 156 | __func__, y1, info->var.xres, y2 - y1 - 1);
|
---|
| 157 | vbox_dirty_update(fbdev, 0, y1, info->var.xres, y2 - y1 - 1);
|
---|
| 158 | }
|
---|
[61597] | 159 | }
|
---|
[74864] | 160 | # endif
|
---|
[61597] | 161 |
|
---|
[67397] | 162 | static struct fb_deferred_io vbox_defio = {
|
---|
[74864] | 163 | .delay = HZ / 30,
|
---|
| 164 | .deferred_io = drm_fb_helper_deferred_io,
|
---|
[61597] | 165 | };
|
---|
[85707] | 166 | #endif /* CONFIG_FB_DEFERRED_IO */
|
---|
[61597] | 167 |
|
---|
[85705] | 168 | #if RTLNX_VER_MAX(4,3,0) && !RTLNX_RHEL_MAJ_PREREQ(7,3)
|
---|
[74864] | 169 | static void drm_fb_helper_sys_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
|
---|
[53793] | 170 | {
|
---|
[67397] | 171 | struct vbox_fbdev *fbdev = info->par;
|
---|
| 172 |
|
---|
| 173 | sys_fillrect(info, rect);
|
---|
| 174 | vbox_dirty_update(fbdev, rect->dx, rect->dy, rect->width, rect->height);
|
---|
[53793] | 175 | }
|
---|
| 176 |
|
---|
[74864] | 177 | static void drm_fb_helper_sys_copyarea(struct fb_info *info, const struct fb_copyarea *area)
|
---|
[53793] | 178 | {
|
---|
[67397] | 179 | struct vbox_fbdev *fbdev = info->par;
|
---|
| 180 |
|
---|
| 181 | sys_copyarea(info, area);
|
---|
| 182 | vbox_dirty_update(fbdev, area->dx, area->dy, area->width, area->height);
|
---|
[53793] | 183 | }
|
---|
| 184 |
|
---|
[74864] | 185 | static void drm_fb_helper_sys_imageblit(struct fb_info *info, const struct fb_image *image)
|
---|
[53793] | 186 | {
|
---|
[67397] | 187 | struct vbox_fbdev *fbdev = info->par;
|
---|
| 188 |
|
---|
| 189 | sys_imageblit(info, image);
|
---|
| 190 | vbox_dirty_update(fbdev, image->dx, image->dy, image->width,
|
---|
| 191 | image->height);
|
---|
[53793] | 192 | }
|
---|
[85707] | 193 | #endif /* RTLNX_VER_MAX(4,3,0) && !RTLNX_RHEL_MAJ_PREREQ(7,3) */
|
---|
[53793] | 194 |
|
---|
[59526] | 195 | static struct fb_ops vboxfb_ops = {
|
---|
[67397] | 196 | .owner = THIS_MODULE,
|
---|
| 197 | .fb_check_var = drm_fb_helper_check_var,
|
---|
| 198 | .fb_set_par = drm_fb_helper_set_par,
|
---|
[102874] | 199 | #if RTLNX_VER_MIN(6,5,0) || RTLNX_RHEL_RANGE(9,4, 9,99)
|
---|
[101079] | 200 | .fb_read = fb_sys_read,
|
---|
| 201 | .fb_write = fb_sys_write,
|
---|
| 202 | .fb_fillrect = sys_fillrect,
|
---|
| 203 | .fb_copyarea = sys_copyarea,
|
---|
| 204 | .fb_imageblit = sys_imageblit,
|
---|
| 205 | .fb_mmap = NULL,
|
---|
[100436] | 206 | #else
|
---|
[74864] | 207 | .fb_fillrect = drm_fb_helper_sys_fillrect,
|
---|
| 208 | .fb_copyarea = drm_fb_helper_sys_copyarea,
|
---|
| 209 | .fb_imageblit = drm_fb_helper_sys_imageblit,
|
---|
[100436] | 210 | #endif
|
---|
[67397] | 211 | .fb_pan_display = drm_fb_helper_pan_display,
|
---|
| 212 | .fb_blank = drm_fb_helper_blank,
|
---|
| 213 | .fb_setcmap = drm_fb_helper_setcmap,
|
---|
| 214 | .fb_debug_enter = drm_fb_helper_debug_enter,
|
---|
| 215 | .fb_debug_leave = drm_fb_helper_debug_leave,
|
---|
[53793] | 216 | };
|
---|
| 217 |
|
---|
[59640] | 218 | static int vboxfb_create_object(struct vbox_fbdev *fbdev,
|
---|
[67397] | 219 | struct DRM_MODE_FB_CMD *mode_cmd,
|
---|
| 220 | struct drm_gem_object **gobj_p)
|
---|
[53793] | 221 | {
|
---|
[67397] | 222 | struct drm_device *dev = fbdev->helper.dev;
|
---|
| 223 | u32 size;
|
---|
| 224 | struct drm_gem_object *gobj;
|
---|
[85704] | 225 | #if RTLNX_VER_MAX(3,3,0)
|
---|
[67397] | 226 | u32 pitch = mode_cmd->pitch;
|
---|
[53793] | 227 | #else
|
---|
[67397] | 228 | u32 pitch = mode_cmd->pitches[0];
|
---|
[53793] | 229 | #endif
|
---|
| 230 |
|
---|
[74773] | 231 | int ret;
|
---|
[53793] | 232 |
|
---|
[67397] | 233 | size = pitch * mode_cmd->height;
|
---|
| 234 | ret = vbox_gem_create(dev, size, true, &gobj);
|
---|
| 235 | if (ret)
|
---|
| 236 | return ret;
|
---|
[53793] | 237 |
|
---|
[67397] | 238 | *gobj_p = gobj;
|
---|
[74773] | 239 |
|
---|
| 240 | return 0;
|
---|
[53793] | 241 | }
|
---|
| 242 |
|
---|
[85705] | 243 | #if RTLNX_VER_MAX(4,3,0) && !RTLNX_RHEL_MAJ_PREREQ(7,3)
|
---|
[74864] | 244 | static struct fb_info *drm_fb_helper_alloc_fbi(struct drm_fb_helper *helper)
|
---|
| 245 | {
|
---|
| 246 | struct fb_info *info;
|
---|
| 247 | struct vbox_fbdev *fbdev =
|
---|
| 248 | container_of(helper, struct vbox_fbdev, helper);
|
---|
| 249 | struct drm_device *dev = fbdev->helper.dev;
|
---|
| 250 | struct device *device = &dev->pdev->dev;
|
---|
| 251 |
|
---|
| 252 | info = framebuffer_alloc(0, device);
|
---|
| 253 | if (!info)
|
---|
| 254 | return ERR_PTR(-ENOMEM);
|
---|
| 255 | fbdev->helper.fbdev = info;
|
---|
| 256 |
|
---|
| 257 | if (fb_alloc_cmap(&info->cmap, 256, 0))
|
---|
| 258 | return ERR_PTR(-ENOMEM);
|
---|
| 259 |
|
---|
| 260 | info->apertures = alloc_apertures(1);
|
---|
| 261 | if (!info->apertures)
|
---|
| 262 | return ERR_PTR(-ENOMEM);
|
---|
| 263 |
|
---|
| 264 | return info;
|
---|
| 265 | }
|
---|
| 266 | #endif
|
---|
| 267 |
|
---|
[59526] | 268 | static int vboxfb_create(struct drm_fb_helper *helper,
|
---|
[67397] | 269 | struct drm_fb_helper_surface_size *sizes)
|
---|
[53793] | 270 | {
|
---|
[67397] | 271 | struct vbox_fbdev *fbdev =
|
---|
| 272 | container_of(helper, struct vbox_fbdev, helper);
|
---|
| 273 | struct drm_device *dev = fbdev->helper.dev;
|
---|
| 274 | struct DRM_MODE_FB_CMD mode_cmd;
|
---|
| 275 | struct drm_framebuffer *fb;
|
---|
| 276 | struct fb_info *info;
|
---|
[74773] | 277 | struct drm_gem_object *gobj;
|
---|
| 278 | struct vbox_bo *bo;
|
---|
[67397] | 279 | int size, ret;
|
---|
| 280 | u32 pitch;
|
---|
| 281 |
|
---|
| 282 | mode_cmd.width = sizes->surface_width;
|
---|
| 283 | mode_cmd.height = sizes->surface_height;
|
---|
| 284 | pitch = mode_cmd.width * ((sizes->surface_bpp + 7) / 8);
|
---|
[85704] | 285 | #if RTLNX_VER_MAX(3,3,0)
|
---|
[67397] | 286 | mode_cmd.bpp = sizes->surface_bpp;
|
---|
| 287 | mode_cmd.depth = sizes->surface_depth;
|
---|
| 288 | mode_cmd.pitch = pitch;
|
---|
[53793] | 289 | #else
|
---|
[67397] | 290 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
|
---|
| 291 | sizes->surface_depth);
|
---|
| 292 | mode_cmd.pitches[0] = pitch;
|
---|
[53793] | 293 | #endif
|
---|
| 294 |
|
---|
[67397] | 295 | size = pitch * mode_cmd.height;
|
---|
[53793] | 296 |
|
---|
[67397] | 297 | ret = vboxfb_create_object(fbdev, &mode_cmd, &gobj);
|
---|
| 298 | if (ret) {
|
---|
| 299 | DRM_ERROR("failed to create fbcon backing object %d\n", ret);
|
---|
| 300 | return ret;
|
---|
| 301 | }
|
---|
[64830] | 302 |
|
---|
[67397] | 303 | ret = vbox_framebuffer_init(dev, &fbdev->afb, &mode_cmd, gobj);
|
---|
| 304 | if (ret)
|
---|
| 305 | return ret;
|
---|
[64830] | 306 |
|
---|
[67397] | 307 | bo = gem_to_vbox_bo(gobj);
|
---|
[53793] | 308 |
|
---|
[67397] | 309 | ret = vbox_bo_reserve(bo, false);
|
---|
| 310 | if (ret)
|
---|
| 311 | return ret;
|
---|
[53793] | 312 |
|
---|
[87092] | 313 | ret = vbox_bo_pin(bo, VBOX_MEM_TYPE_VRAM, NULL);
|
---|
[67397] | 314 | if (ret) {
|
---|
| 315 | vbox_bo_unreserve(bo);
|
---|
| 316 | return ret;
|
---|
| 317 | }
|
---|
[64830] | 318 |
|
---|
[94330] | 319 | #if RTLNX_VER_MIN(5,14,0) || RTLNX_RHEL_RANGE(8,6, 8,99)
|
---|
[98034] | 320 | ret = ttm_bo_kmap(&bo->bo, 0, VBOX_BO_RESOURCE_NUM_PAGES(bo->bo.resource), &bo->kmap);
|
---|
[90577] | 321 | #elif RTLNX_VER_MIN(5,12,0) || RTLNX_RHEL_MAJ_PREREQ(8,5)
|
---|
[88274] | 322 | ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.mem.num_pages, &bo->kmap);
|
---|
| 323 | #else
|
---|
[67397] | 324 | ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
|
---|
[88274] | 325 | #endif
|
---|
| 326 |
|
---|
[67397] | 327 | vbox_bo_unreserve(bo);
|
---|
| 328 | if (ret) {
|
---|
| 329 | DRM_ERROR("failed to kmap fbcon\n");
|
---|
| 330 | return ret;
|
---|
| 331 | }
|
---|
[64830] | 332 |
|
---|
[102874] | 333 | #if RTLNX_VER_MIN(6,2,0) || RTLNX_RHEL_RANGE(8,9, 8,99) || RTLNX_RHEL_RANGE(9,3, 9,99)
|
---|
[98034] | 334 | info = drm_fb_helper_alloc_info(helper);
|
---|
| 335 | #else
|
---|
[74864] | 336 | info = drm_fb_helper_alloc_fbi(helper);
|
---|
[98034] | 337 | #endif
|
---|
[74864] | 338 | if (IS_ERR(info))
|
---|
| 339 | return -PTR_ERR(info);
|
---|
| 340 |
|
---|
[67397] | 341 | info->par = fbdev;
|
---|
[53793] | 342 |
|
---|
[67397] | 343 | fbdev->size = size;
|
---|
[53793] | 344 |
|
---|
[67397] | 345 | fb = &fbdev->afb.base;
|
---|
| 346 | fbdev->helper.fb = fb;
|
---|
[53793] | 347 |
|
---|
[67397] | 348 | strcpy(info->fix.id, "vboxdrmfb");
|
---|
[53793] | 349 |
|
---|
[67397] | 350 | /*
|
---|
| 351 | * The last flag forces a mode set on VT switches even if the kernel
|
---|
| 352 | * does not think it is needed.
|
---|
| 353 | */
|
---|
[101079] | 354 | #if RTLNX_VER_MIN(6,6,0)
|
---|
| 355 | info->flags = FBINFO_MISC_ALWAYS_SETPAR;
|
---|
| 356 | #else
|
---|
[75664] | 357 | info->flags = FBINFO_DEFAULT | FBINFO_MISC_ALWAYS_SETPAR;
|
---|
[101079] | 358 | #endif
|
---|
[67397] | 359 | info->fbops = &vboxfb_ops;
|
---|
[53793] | 360 |
|
---|
[102874] | 361 | #if RTLNX_VER_MAX(6,3,0) && !RTLNX_RHEL_RANGE(8,9, 8,99) && !RTLNX_RHEL_RANGE(9,3, 9,99)
|
---|
[67397] | 362 | /*
|
---|
| 363 | * This seems to be done for safety checking that the framebuffer
|
---|
| 364 | * is not registered twice by different drivers.
|
---|
| 365 | */
|
---|
[90498] | 366 | info->apertures->ranges[0].base = pci_resource_start(VBOX_DRM_TO_PCI_DEV(dev), 0);
|
---|
| 367 | info->apertures->ranges[0].size = pci_resource_len(VBOX_DRM_TO_PCI_DEV(dev), 0);
|
---|
[98868] | 368 | #endif
|
---|
[53793] | 369 |
|
---|
[85705] | 370 | #if RTLNX_VER_MIN(5,2,0) || RTLNX_RHEL_MAJ_PREREQ(8,2)
|
---|
[84255] | 371 | /*
|
---|
| 372 | * The corresponding 5.2-rc1 Linux DRM kernel changes have been
|
---|
| 373 | * also backported to older RedHat based 4.18.0 Linux kernels.
|
---|
| 374 | */
|
---|
[79026] | 375 | drm_fb_helper_fill_info(info, &fbdev->helper, sizes);
|
---|
[85705] | 376 | #elif RTLNX_VER_MIN(4,11,0) || RTLNX_RHEL_MAJ_PREREQ(7, 5)
|
---|
[67397] | 377 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth);
|
---|
[65992] | 378 | #else
|
---|
[67397] | 379 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
|
---|
[65992] | 380 | #endif
|
---|
[85705] | 381 | #if RTLNX_VER_MAX(5,2,0) && !RTLNX_RHEL_MAJ_PREREQ(8,2)
|
---|
[67397] | 382 | drm_fb_helper_fill_var(info, &fbdev->helper, sizes->fb_width,
|
---|
| 383 | sizes->fb_height);
|
---|
[79026] | 384 | #endif
|
---|
[53793] | 385 |
|
---|
[100800] | 386 | #if RTLNX_VER_MIN(6,5,0)
|
---|
| 387 | info->screen_buffer = (char *)bo->kmap.virtual;
|
---|
| 388 | info->fix.smem_start = page_to_phys(vmalloc_to_page(bo->kmap.virtual));
|
---|
| 389 | #endif
|
---|
[76940] | 390 | info->screen_base = (char __iomem *)bo->kmap.virtual;
|
---|
[67397] | 391 | info->screen_size = size;
|
---|
[53793] | 392 |
|
---|
[61602] | 393 | #ifdef CONFIG_FB_DEFERRED_IO
|
---|
[102874] | 394 | # if RTLNX_VER_MIN(5,19,0) || RTLNX_RHEL_RANGE(8,8, 8,99) || RTLNX_RHEL_RANGE(9,3, 9,99) || RTLNX_SUSE_MAJ_PREREQ(15,5)
|
---|
[95212] | 395 | info->fix.smem_len = info->screen_size;
|
---|
| 396 | # endif
|
---|
[67397] | 397 | info->fbdefio = &vbox_defio;
|
---|
[100800] | 398 | # if RTLNX_VER_MIN(5,19,0)
|
---|
| 399 | ret = fb_deferred_io_init(info);
|
---|
| 400 | if (ret)
|
---|
| 401 | {
|
---|
| 402 | DRM_ERROR("failed to initialize deferred io: %d\n", ret);
|
---|
| 403 | return ret;
|
---|
| 404 | }
|
---|
| 405 | # endif
|
---|
[67397] | 406 | fb_deferred_io_init(info);
|
---|
[61602] | 407 | #endif
|
---|
[61597] | 408 |
|
---|
[67397] | 409 | info->pixmap.flags = FB_PIXMAP_SYSTEM;
|
---|
[53793] | 410 |
|
---|
[67397] | 411 | DRM_DEBUG_KMS("allocated %dx%d\n", fb->width, fb->height);
|
---|
[53793] | 412 |
|
---|
[67397] | 413 | return 0;
|
---|
[53793] | 414 | }
|
---|
| 415 |
|
---|
[59526] | 416 | static struct drm_fb_helper_funcs vbox_fb_helper_funcs = {
|
---|
[67397] | 417 | .fb_probe = vboxfb_create,
|
---|
[53793] | 418 | };
|
---|
| 419 |
|
---|
[85705] | 420 | #if RTLNX_VER_MAX(4,3,0) && !RTLNX_RHEL_MAJ_PREREQ(7,3)
|
---|
[74773] | 421 | static void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper)
|
---|
[53793] | 422 | {
|
---|
[74773] | 423 | if (fb_helper && fb_helper->fbdev)
|
---|
| 424 | unregister_framebuffer(fb_helper->fbdev);
|
---|
| 425 | }
|
---|
| 426 | #endif
|
---|
| 427 |
|
---|
| 428 | void vbox_fbdev_fini(struct drm_device *dev)
|
---|
| 429 | {
|
---|
| 430 | struct vbox_private *vbox = dev->dev_private;
|
---|
| 431 | struct vbox_fbdev *fbdev = vbox->fbdev;
|
---|
[67397] | 432 | struct vbox_framebuffer *afb = &fbdev->afb;
|
---|
[53793] | 433 |
|
---|
[76936] | 434 | #ifdef CONFIG_FB_DEFERRED_IO
|
---|
[98034] | 435 | if (VBOX_FBDEV_INFO(fbdev->helper) && VBOX_FBDEV_INFO(fbdev->helper)->fbdefio)
|
---|
| 436 | fb_deferred_io_cleanup(VBOX_FBDEV_INFO(fbdev->helper));
|
---|
[76936] | 437 | #endif
|
---|
| 438 |
|
---|
[102874] | 439 | #if RTLNX_VER_MIN(6,2,0) || RTLNX_RHEL_RANGE(8,9, 8,99) || RTLNX_RHEL_RANGE(9,3, 9,99)
|
---|
[98034] | 440 | drm_fb_helper_unregister_info(&fbdev->helper);
|
---|
| 441 | #else
|
---|
[74773] | 442 | drm_fb_helper_unregister_fbi(&fbdev->helper);
|
---|
[98034] | 443 | #endif
|
---|
[53793] | 444 |
|
---|
[67397] | 445 | if (afb->obj) {
|
---|
| 446 | struct vbox_bo *bo = gem_to_vbox_bo(afb->obj);
|
---|
| 447 |
|
---|
| 448 | if (!vbox_bo_reserve(bo, false)) {
|
---|
| 449 | if (bo->kmap.virtual)
|
---|
| 450 | ttm_bo_kunmap(&bo->kmap);
|
---|
| 451 | /*
|
---|
| 452 | * QXL does this, but is it really needed before
|
---|
| 453 | * freeing?
|
---|
| 454 | */
|
---|
| 455 | if (bo->pin_count)
|
---|
| 456 | vbox_bo_unpin(bo);
|
---|
| 457 | vbox_bo_unreserve(bo);
|
---|
| 458 | }
|
---|
[89690] | 459 | #if RTLNX_VER_MIN(5,9,0) || RTLNX_RHEL_MIN(8,4) || RTLNX_SUSE_MAJ_PREREQ(15,3)
|
---|
[86542] | 460 | drm_gem_object_put(afb->obj);
|
---|
| 461 | #else
|
---|
[74882] | 462 | drm_gem_object_put_unlocked(afb->obj);
|
---|
[86542] | 463 | #endif
|
---|
[67397] | 464 | afb->obj = NULL;
|
---|
| 465 | }
|
---|
| 466 | drm_fb_helper_fini(&fbdev->helper);
|
---|
| 467 |
|
---|
[85704] | 468 | #if RTLNX_VER_MIN(3,9,0)
|
---|
[67397] | 469 | drm_framebuffer_unregister_private(&afb->base);
|
---|
[59951] | 470 | #endif
|
---|
[67397] | 471 | drm_framebuffer_cleanup(&afb->base);
|
---|
[53793] | 472 | }
|
---|
| 473 |
|
---|
| 474 | int vbox_fbdev_init(struct drm_device *dev)
|
---|
| 475 | {
|
---|
[67397] | 476 | struct vbox_private *vbox = dev->dev_private;
|
---|
| 477 | struct vbox_fbdev *fbdev;
|
---|
[83878] | 478 | int ret = 0;
|
---|
[53793] | 479 |
|
---|
[74773] | 480 | fbdev = devm_kzalloc(dev->dev, sizeof(*fbdev), GFP_KERNEL);
|
---|
[67397] | 481 | if (!fbdev)
|
---|
| 482 | return -ENOMEM;
|
---|
[53793] | 483 |
|
---|
[67397] | 484 | vbox->fbdev = fbdev;
|
---|
| 485 | spin_lock_init(&fbdev->dirty_lock);
|
---|
[59947] | 486 |
|
---|
[102874] | 487 | #if RTLNX_VER_MIN(6,3,0) || RTLNX_RHEL_RANGE(8,9, 8,99) || RTLNX_RHEL_RANGE(9,3, 9,99)
|
---|
[98868] | 488 | drm_fb_helper_prepare(dev, &fbdev->helper, 32, &vbox_fb_helper_funcs);
|
---|
| 489 | #elif RTLNX_VER_MIN(3,17,0) || RTLNX_RHEL_MIN(7,2)
|
---|
| 490 | drm_fb_helper_prepare(dev, &fbdev->helper, &vbox_fb_helper_funcs);
|
---|
| 491 | #else
|
---|
[67397] | 492 | fbdev->helper.funcs = &vbox_fb_helper_funcs;
|
---|
[56467] | 493 | #endif
|
---|
[98868] | 494 |
|
---|
[89690] | 495 | #if RTLNX_VER_MIN(5,7,0) || RTLNX_RHEL_MIN(8,4) || RTLNX_SUSE_MAJ_PREREQ(15,3)
|
---|
[83878] | 496 | ret = drm_fb_helper_init(dev, &fbdev->helper);
|
---|
[85705] | 497 | #elif RTLNX_VER_MIN(4,11,0) || RTLNX_RHEL_MAJ_PREREQ(7,5)
|
---|
[67397] | 498 | ret = drm_fb_helper_init(dev, &fbdev->helper, vbox->num_crtcs);
|
---|
[85704] | 499 | #else /* < 4.11.0 */
|
---|
[67397] | 500 | ret =
|
---|
| 501 | drm_fb_helper_init(dev, &fbdev->helper, vbox->num_crtcs,
|
---|
| 502 | vbox->num_crtcs);
|
---|
[65992] | 503 | #endif
|
---|
[67397] | 504 | if (ret)
|
---|
[74773] | 505 | return ret;
|
---|
[53793] | 506 |
|
---|
[89690] | 507 | #if RTLNX_VER_MAX(5,7,0) && !RTLNX_RHEL_MAJ_PREREQ(8,4) && !RTLNX_SUSE_MAJ_PREREQ(15,3)
|
---|
[67397] | 508 | ret = drm_fb_helper_single_add_all_connectors(&fbdev->helper);
|
---|
| 509 | if (ret)
|
---|
[74773] | 510 | goto err_fini;
|
---|
[83878] | 511 | #endif
|
---|
[59526] | 512 |
|
---|
[67397] | 513 | /* disable all the possible outputs/crtcs before entering KMS mode */
|
---|
| 514 | drm_helper_disable_unused_functions(dev);
|
---|
[59526] | 515 |
|
---|
[102874] | 516 | #if RTLNX_VER_MIN(6,3,0) || RTLNX_RHEL_RANGE(8,9, 8,99) || RTLNX_RHEL_RANGE(9,3, 9,99)
|
---|
[98868] | 517 | ret = drm_fb_helper_initial_config(&fbdev->helper);
|
---|
| 518 | #else
|
---|
[67397] | 519 | ret = drm_fb_helper_initial_config(&fbdev->helper, 32);
|
---|
[98868] | 520 | #endif
|
---|
[67397] | 521 | if (ret)
|
---|
[74773] | 522 | goto err_fini;
|
---|
[59526] | 523 |
|
---|
[67397] | 524 | return 0;
|
---|
| 525 |
|
---|
[74773] | 526 | err_fini:
|
---|
[67397] | 527 | drm_fb_helper_fini(&fbdev->helper);
|
---|
| 528 | return ret;
|
---|
[53793] | 529 | }
|
---|
| 530 |
|
---|
[74773] | 531 | void vbox_fbdev_set_base(struct vbox_private *vbox, unsigned long gpu_addr)
|
---|
[53793] | 532 | {
|
---|
[98034] | 533 | struct fb_info *fbdev = VBOX_FBDEV_INFO(vbox->fbdev->helper);
|
---|
[53793] | 534 |
|
---|
[102874] | 535 | #if RTLNX_VER_MIN(6,3,0) || RTLNX_RHEL_RANGE(8,9, 8,99) || RTLNX_RHEL_RANGE(9,3, 9,99)
|
---|
[100800] | 536 | fbdev->fix.smem_start = pci_resource_start(VBOX_DRM_TO_PCI_DEV(vbox->fbdev->helper.dev), 0) + gpu_addr;
|
---|
[98868] | 537 | #else
|
---|
[74773] | 538 | fbdev->fix.smem_start = fbdev->apertures->ranges[0].base + gpu_addr;
|
---|
[98868] | 539 | #endif
|
---|
[74773] | 540 | fbdev->fix.smem_len = vbox->available_vram_size - gpu_addr;
|
---|
[53793] | 541 | }
|
---|