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_types.h"
9#include "intel_fbdev_fb.h"
10#include "xe_bo.h"
11#include "xe_gt.h"
12#include "xe_ttm_stolen_mgr.h"
13
14struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_fb_helper *helper,
15 struct drm_fb_helper_surface_size *sizes)
16{
17 struct drm_framebuffer *fb;
18 struct drm_device *dev = helper->dev;
19 struct xe_device *xe = to_xe_device(dev);
20 struct drm_mode_fb_cmd2 mode_cmd = {};
21 struct drm_i915_gem_object *obj;
22 int size;
23
24 /* we don't do packed 24bpp */
25 if (sizes->surface_bpp == 24)
26 sizes->surface_bpp = 32;
27
28 mode_cmd.width = sizes->surface_width;
29 mode_cmd.height = sizes->surface_height;
30
31 mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
32 DIV_ROUND_UP(sizes->surface_bpp, 8), XE_PAGE_SIZE);
33 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
34 sizes->surface_depth);
35
36 size = mode_cmd.pitches[0] * mode_cmd.height;
37 size = PAGE_ALIGN(size);
38 obj = ERR_PTR(-ENODEV);
39
40 if (!IS_DGFX(xe)) {
41 obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe),
42 NULL, size,
43 ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
44 XE_BO_FLAG_STOLEN |
45 XE_BO_FLAG_PINNED);
46 if (!IS_ERR(obj))
47 drm_info(&xe->drm, "Allocated fbdev into stolen\n");
48 else
49 drm_info(&xe->drm, "Allocated fbdev into stolen failed: %li\n", PTR_ERR(obj));
50 }
51 if (IS_ERR(obj)) {
52 obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe), NULL, size,
53 ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
54 XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
55 XE_BO_FLAG_PINNED);
56 }
57
58 if (IS_ERR(obj)) {
59 drm_err(&xe->drm, "failed to allocate framebuffer (%pe)\n", obj);
60 fb = ERR_PTR(-ENOMEM);
61 goto err;
62 }
63
64 fb = intel_framebuffer_create(obj, &mode_cmd);
65 if (IS_ERR(fb)) {
66 xe_bo_unpin_map_no_vm(obj);
67 goto err;
68 }
69
70 drm_gem_object_put(intel_bo_to_drm_bo(obj));
71
72 return to_intel_framebuffer(fb);
73
74err:
75 return ERR_CAST(fb);
76}
77
78int intel_fbdev_fb_fill_info(struct drm_i915_private *i915, struct fb_info *info,
79 struct drm_i915_gem_object *obj, struct i915_vma *vma)
80{
81 struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
82
83 if (!(obj->flags & XE_BO_FLAG_SYSTEM)) {
84 if (obj->flags & XE_BO_FLAG_STOLEN)
85 info->fix.smem_start = xe_ttm_stolen_io_offset(obj, 0);
86 else
87 info->fix.smem_start =
88 pci_resource_start(pdev, 2) +
89 xe_bo_addr(obj, 0, XE_PAGE_SIZE);
90
91 info->fix.smem_len = obj->ttm.base.size;
92 } else {
93 /* XXX: Pure fiction, as the BO may not be physically accessible.. */
94 info->fix.smem_start = 0;
95 info->fix.smem_len = obj->ttm.base.size;
96 }
97 XE_WARN_ON(iosys_map_is_null(&obj->vmap));
98
99 info->screen_base = obj->vmap.vaddr_iomem;
100 info->screen_size = intel_bo_to_drm_bo(obj)->size;
101
102 return 0;
103}