1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2023 Intel Corporation
6 #include <drm/drm_fb_helper.h>
8 #include "intel_display_types.h"
10 #include "intel_fbdev_fb.h"
12 #include "xe_ttm_stolen_mgr.h"
15 #include <generated/xe_wa_oob.h>
17 struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_fb_helper *helper,
18 struct drm_fb_helper_surface_size *sizes)
20 struct drm_framebuffer *fb;
21 struct drm_device *dev = helper->dev;
22 struct xe_device *xe = to_xe_device(dev);
23 struct drm_mode_fb_cmd2 mode_cmd = {};
27 /* we don't do packed 24bpp */
28 if (sizes->surface_bpp == 24)
29 sizes->surface_bpp = 32;
31 mode_cmd.width = sizes->surface_width;
32 mode_cmd.height = sizes->surface_height;
34 mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
35 DIV_ROUND_UP(sizes->surface_bpp, 8), XE_PAGE_SIZE);
36 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
37 sizes->surface_depth);
39 size = mode_cmd.pitches[0] * mode_cmd.height;
40 size = PAGE_ALIGN(size);
41 obj = ERR_PTR(-ENODEV);
43 if (!IS_DGFX(xe) && !XE_WA(xe_root_mmio_gt(xe), 22019338487_display)) {
44 obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe),
46 ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
50 drm_info(&xe->drm, "Allocated fbdev into stolen\n");
52 drm_info(&xe->drm, "Allocated fbdev into stolen failed: %li\n", PTR_ERR(obj));
56 obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe), NULL, size,
57 ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
58 XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
63 drm_err(&xe->drm, "failed to allocate framebuffer (%pe)\n", obj);
64 fb = ERR_PTR(-ENOMEM);
68 fb = intel_framebuffer_create(&obj->ttm.base, &mode_cmd);
70 xe_bo_unpin_map_no_vm(obj);
74 drm_gem_object_put(&obj->ttm.base);
76 return to_intel_framebuffer(fb);
82 int intel_fbdev_fb_fill_info(struct drm_i915_private *i915, struct fb_info *info,
83 struct drm_gem_object *_obj, struct i915_vma *vma)
85 struct xe_bo *obj = gem_to_xe_bo(_obj);
86 struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
88 if (!(obj->flags & XE_BO_FLAG_SYSTEM)) {
89 if (obj->flags & XE_BO_FLAG_STOLEN)
90 info->fix.smem_start = xe_ttm_stolen_io_offset(obj, 0);
92 info->fix.smem_start =
93 pci_resource_start(pdev, 2) +
94 xe_bo_addr(obj, 0, XE_PAGE_SIZE);
96 info->fix.smem_len = obj->ttm.base.size;
98 /* XXX: Pure fiction, as the BO may not be physically accessible.. */
99 info->fix.smem_start = 0;
100 info->fix.smem_len = obj->ttm.base.size;
102 XE_WARN_ON(iosys_map_is_null(&obj->vmap));
104 info->screen_base = obj->vmap.vaddr_iomem;
105 info->screen_size = obj->ttm.base.size;