1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2023 Intel Corporation
6 #include "intel_fbdev_fb.h"
8 #include <drm/drm_fb_helper.h>
11 #include "xe_ttm_stolen_mgr.h"
14 #include "intel_display_types.h"
16 struct drm_framebuffer *intel_fbdev_fb_alloc(struct drm_fb_helper *helper,
17 struct drm_fb_helper_surface_size *sizes)
19 struct drm_framebuffer *fb;
20 struct drm_device *dev = helper->dev;
21 struct drm_i915_private *dev_priv = to_i915(dev);
22 struct drm_mode_fb_cmd2 mode_cmd = {};
23 struct drm_i915_gem_object *obj;
26 /* we don't do packed 24bpp */
27 if (sizes->surface_bpp == 24)
28 sizes->surface_bpp = 32;
30 mode_cmd.width = sizes->surface_width;
31 mode_cmd.height = sizes->surface_height;
33 mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
34 DIV_ROUND_UP(sizes->surface_bpp, 8), XE_PAGE_SIZE);
35 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
36 sizes->surface_depth);
38 size = mode_cmd.pitches[0] * mode_cmd.height;
39 size = PAGE_ALIGN(size);
40 obj = ERR_PTR(-ENODEV);
42 if (!IS_DGFX(dev_priv)) {
43 obj = xe_bo_create_pin_map(dev_priv, xe_device_get_root_tile(dev_priv),
45 ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
49 drm_info(&dev_priv->drm, "Allocated fbdev into stolen\n");
51 drm_info(&dev_priv->drm, "Allocated fbdev into stolen failed: %li\n", PTR_ERR(obj));
54 obj = xe_bo_create_pin_map(dev_priv, xe_device_get_root_tile(dev_priv), NULL, size,
55 ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
56 XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(dev_priv)) |
61 drm_err(&dev_priv->drm, "failed to allocate framebuffer (%pe)\n", obj);
62 fb = ERR_PTR(-ENOMEM);
66 fb = intel_framebuffer_create(obj, &mode_cmd);
68 xe_bo_unpin_map_no_vm(obj);
72 drm_gem_object_put(intel_bo_to_drm_bo(obj));
79 int intel_fbdev_fb_fill_info(struct drm_i915_private *i915, struct fb_info *info,
80 struct drm_i915_gem_object *obj, struct i915_vma *vma)
82 struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
84 if (!(obj->flags & XE_BO_FLAG_SYSTEM)) {
85 if (obj->flags & XE_BO_FLAG_STOLEN)
86 info->fix.smem_start = xe_ttm_stolen_io_offset(obj, 0);
88 info->fix.smem_start =
89 pci_resource_start(pdev, 2) +
90 xe_bo_addr(obj, 0, XE_PAGE_SIZE);
92 info->fix.smem_len = obj->ttm.base.size;
94 /* XXX: Pure fiction, as the BO may not be physically accessible.. */
95 info->fix.smem_start = 0;
96 info->fix.smem_len = obj->ttm.base.size;
98 XE_WARN_ON(iosys_map_is_null(&obj->vmap));
100 info->screen_base = obj->vmap.vaddr_iomem;
101 info->screen_size = intel_bo_to_drm_bo(obj)->size;