1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright © 2023 Intel Corporation 4 */ 5 6 #include "intel_fbdev_fb.h" 7 8 #include <drm/drm_fb_helper.h> 9 10 #include "xe_gt.h" 11 #include "xe_ttm_stolen_mgr.h" 12 13 #include "i915_drv.h" 14 #include "intel_display_types.h" 15 16 struct drm_framebuffer *intel_fbdev_fb_alloc(struct drm_fb_helper *helper, 17 struct drm_fb_helper_surface_size *sizes) 18 { 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; 24 int size; 25 26 /* we don't do packed 24bpp */ 27 if (sizes->surface_bpp == 24) 28 sizes->surface_bpp = 32; 29 30 mode_cmd.width = sizes->surface_width; 31 mode_cmd.height = sizes->surface_height; 32 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); 37 38 size = mode_cmd.pitches[0] * mode_cmd.height; 39 size = PAGE_ALIGN(size); 40 obj = ERR_PTR(-ENODEV); 41 42 if (!IS_DGFX(dev_priv)) { 43 obj = xe_bo_create_pin_map(dev_priv, xe_device_get_root_tile(dev_priv), 44 NULL, size, 45 ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT | 46 XE_BO_FLAG_STOLEN | 47 XE_BO_FLAG_PINNED); 48 if (!IS_ERR(obj)) 49 drm_info(&dev_priv->drm, "Allocated fbdev into stolen\n"); 50 else 51 drm_info(&dev_priv->drm, "Allocated fbdev into stolen failed: %li\n", PTR_ERR(obj)); 52 } 53 if (IS_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)) | 57 XE_BO_FLAG_PINNED); 58 } 59 60 if (IS_ERR(obj)) { 61 drm_err(&dev_priv->drm, "failed to allocate framebuffer (%pe)\n", obj); 62 fb = ERR_PTR(-ENOMEM); 63 goto err; 64 } 65 66 fb = intel_framebuffer_create(obj, &mode_cmd); 67 if (IS_ERR(fb)) { 68 xe_bo_unpin_map_no_vm(obj); 69 goto err; 70 } 71 72 drm_gem_object_put(intel_bo_to_drm_bo(obj)); 73 return fb; 74 75 err: 76 return fb; 77 } 78 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) 81 { 82 struct pci_dev *pdev = to_pci_dev(i915->drm.dev); 83 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); 87 else 88 info->fix.smem_start = 89 pci_resource_start(pdev, 2) + 90 xe_bo_addr(obj, 0, XE_PAGE_SIZE); 91 92 info->fix.smem_len = obj->ttm.base.size; 93 } else { 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; 97 } 98 XE_WARN_ON(iosys_map_is_null(&obj->vmap)); 99 100 info->screen_base = obj->vmap.vaddr_iomem; 101 info->screen_size = intel_bo_to_drm_bo(obj)->size; 102 103 return 0; 104 } 105