Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: MIT */
2/*
3 * Copyright © 2023 Intel Corporation
4 */
5
6#include <drm/drm_fb_helper.h>
7
8#include "intel_display_core.h"
9#include "intel_display_types.h"
10#include "intel_fb.h"
11#include "intel_fbdev_fb.h"
12#include "xe_bo.h"
13#include "xe_ttm_stolen_mgr.h"
14#include "xe_wa.h"
15
16#include <generated/xe_wa_oob.h>
17
18struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_fb_helper *helper,
19 struct drm_fb_helper_surface_size *sizes)
20{
21 struct drm_framebuffer *fb;
22 struct drm_device *dev = helper->dev;
23 struct xe_device *xe = to_xe_device(dev);
24 struct drm_mode_fb_cmd2 mode_cmd = {};
25 struct xe_bo *obj;
26 int size;
27
28 /* we don't do packed 24bpp */
29 if (sizes->surface_bpp == 24)
30 sizes->surface_bpp = 32;
31
32 mode_cmd.width = sizes->surface_width;
33 mode_cmd.height = sizes->surface_height;
34
35 mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
36 DIV_ROUND_UP(sizes->surface_bpp, 8), XE_PAGE_SIZE);
37 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
38 sizes->surface_depth);
39
40 size = mode_cmd.pitches[0] * mode_cmd.height;
41 size = PAGE_ALIGN(size);
42 obj = ERR_PTR(-ENODEV);
43
44 if (!IS_DGFX(xe) && !XE_GT_WA(xe_root_mmio_gt(xe), 22019338487_display)) {
45 obj = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe),
46 size,
47 ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
48 XE_BO_FLAG_STOLEN |
49 XE_BO_FLAG_GGTT, false);
50 if (!IS_ERR(obj))
51 drm_info(&xe->drm, "Allocated fbdev into stolen\n");
52 else
53 drm_info(&xe->drm, "Allocated fbdev into stolen failed: %li\n", PTR_ERR(obj));
54 }
55
56 if (IS_ERR(obj)) {
57 obj = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe), size,
58 ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
59 XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
60 XE_BO_FLAG_GGTT, false);
61 }
62
63 if (IS_ERR(obj)) {
64 drm_err(&xe->drm, "failed to allocate framebuffer (%pe)\n", obj);
65 fb = ERR_PTR(-ENOMEM);
66 goto err;
67 }
68
69 fb = intel_framebuffer_create(&obj->ttm.base,
70 drm_get_format_info(dev,
71 mode_cmd.pixel_format,
72 mode_cmd.modifier[0]),
73 &mode_cmd);
74 if (IS_ERR(fb)) {
75 xe_bo_unpin_map_no_vm(obj);
76 goto err;
77 }
78
79 drm_gem_object_put(&obj->ttm.base);
80
81 return to_intel_framebuffer(fb);
82
83err:
84 return ERR_CAST(fb);
85}
86
87int intel_fbdev_fb_fill_info(struct intel_display *display, struct fb_info *info,
88 struct drm_gem_object *_obj, struct i915_vma *vma)
89{
90 struct xe_bo *obj = gem_to_xe_bo(_obj);
91 struct pci_dev *pdev = to_pci_dev(display->drm->dev);
92
93 if (!(obj->flags & XE_BO_FLAG_SYSTEM)) {
94 if (obj->flags & XE_BO_FLAG_STOLEN)
95 info->fix.smem_start = xe_ttm_stolen_io_offset(obj, 0);
96 else
97 info->fix.smem_start =
98 pci_resource_start(pdev, 2) +
99 xe_bo_addr(obj, 0, XE_PAGE_SIZE);
100
101 info->fix.smem_len = obj->ttm.base.size;
102 } else {
103 /* XXX: Pure fiction, as the BO may not be physically accessible.. */
104 info->fix.smem_start = 0;
105 info->fix.smem_len = obj->ttm.base.size;
106 }
107 XE_WARN_ON(iosys_map_is_null(&obj->vmap));
108
109 info->screen_base = obj->vmap.vaddr_iomem;
110 info->screen_size = obj->ttm.base.size;
111
112 return 0;
113}