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 18 struct 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_WA(xe_root_mmio_gt(xe), 22019338487_display)) { 45 obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe), 46 NULL, size, 47 ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT | 48 XE_BO_FLAG_STOLEN | 49 XE_BO_FLAG_GGTT); 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(xe, xe_device_get_root_tile(xe), NULL, 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); 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, &mode_cmd); 70 if (IS_ERR(fb)) { 71 xe_bo_unpin_map_no_vm(obj); 72 goto err; 73 } 74 75 drm_gem_object_put(&obj->ttm.base); 76 77 return to_intel_framebuffer(fb); 78 79 err: 80 return ERR_CAST(fb); 81 } 82 83 int intel_fbdev_fb_fill_info(struct intel_display *display, struct fb_info *info, 84 struct drm_gem_object *_obj, struct i915_vma *vma) 85 { 86 struct xe_bo *obj = gem_to_xe_bo(_obj); 87 struct pci_dev *pdev = to_pci_dev(display->drm->dev); 88 89 if (!(obj->flags & XE_BO_FLAG_SYSTEM)) { 90 if (obj->flags & XE_BO_FLAG_STOLEN) 91 info->fix.smem_start = xe_ttm_stolen_io_offset(obj, 0); 92 else 93 info->fix.smem_start = 94 pci_resource_start(pdev, 2) + 95 xe_bo_addr(obj, 0, XE_PAGE_SIZE); 96 97 info->fix.smem_len = obj->ttm.base.size; 98 } else { 99 /* XXX: Pure fiction, as the BO may not be physically accessible.. */ 100 info->fix.smem_start = 0; 101 info->fix.smem_len = obj->ttm.base.size; 102 } 103 XE_WARN_ON(iosys_map_is_null(&obj->vmap)); 104 105 info->screen_base = obj->vmap.vaddr_iomem; 106 info->screen_size = obj->ttm.base.size; 107 108 return 0; 109 } 110