Something went wrong. Try again.
(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197// SPDX-License-Identifier: MIT/* * Copyright © 2021 Intel Corporation */
#include <drm/intel/display_parent_interface.h>
#include "regs/xe_gtt_defs.h"
/* FIXME move intel_remapped_info_size() & co. */#include "intel_fb.h"
/* FIXME move intel_initial_plane_config */#include "intel_display_types.h"
#include "xe_bo.h"#include "xe_display_bo.h"#include "xe_display_vma.h"#include "xe_fb_pin.h"#include "xe_ggtt.h"#include "xe_mmio.h"#include "xe_ttm_stolen_mgr.h"#include "xe_vram_types.h"
static bool is_pte_local(u64 pte){ return pte & XE_GGTT_PTE_DM;}
static bool has_lmembar(struct xe_device *xe){ return GRAPHICS_VERx100(xe) >= 1270;}
static bool need_pte_local(struct xe_device *xe){ return IS_DGFX(xe) || has_lmembar(xe);}
static struct xe_bo *initial_plane_bo(struct xe_device *xe, struct intel_initial_plane_config *plane_config){ struct xe_tile *tile0 = xe_device_get_root_tile(xe); struct xe_bo *bo; resource_size_t phys_base; u32 base, size, flags; u64 page_size = xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K ? SZ_64K : SZ_4K;
if (plane_config->size == 0) return NULL;
flags = XE_BO_FLAG_FORCE_WC | XE_BO_FLAG_GGTT;
base = round_down(plane_config->base, page_size); size = round_up(plane_config->base + plane_config->size, page_size); size -= base;
if (IS_DGFX(xe)) { u64 pte = xe_ggtt_read_pte(tile0->mem.ggtt, base);
if (is_pte_local(pte) != need_pte_local(xe)) { drm_err(&xe->drm, "Initial plane PTE has bad local memory bit\n"); return NULL; }
phys_base = pte & ~(page_size - 1);
flags |= XE_BO_FLAG_VRAM0;
/* * We don't currently expect this to ever be placed in the * stolen portion. */ if (phys_base >= xe_vram_region_usable_size(tile0->mem.vram)) { drm_err(&xe->drm, "Initial plane programming using invalid range, phys_base=%pa\n", &phys_base); return NULL; }
drm_dbg_kms(&xe->drm, "Using phys_base=%pa, based on initial plane programming\n", &phys_base); } else { struct ttm_resource_manager *stolen; u64 pte;
stolen = ttm_manager_type(&xe->ttm, XE_PL_STOLEN); if (!stolen) { drm_dbg_kms(&xe->drm, "No stolen for initial FB\n"); return NULL; }
pte = xe_ggtt_read_pte(tile0->mem.ggtt, base);
if (is_pte_local(pte) != need_pte_local(xe)) { drm_err(&xe->drm, "Initial plane PTE has bad local memory bit\n"); return NULL; }
phys_base = base; flags |= XE_BO_FLAG_STOLEN;
if (IS_ENABLED(CONFIG_FRAMEBUFFER_CONSOLE) && IS_ENABLED(CONFIG_DRM_FBDEV_EMULATION) && !xe_display_bo_fbdev_prefer_stolen(xe, plane_config->size)) { drm_info(&xe->drm, "Initial FB size exceeds half of stolen, discarding\n"); return NULL; } }
bo = xe_bo_create_pin_map_at_novm(xe, tile0, size, phys_base, ttm_bo_type_kernel, flags, 0, false); if (IS_ERR(bo)) { drm_dbg_kms(&xe->drm, "Failed to create bo phys_base=%pa size %u with flags %x: %li\n", &phys_base, size, flags, PTR_ERR(bo)); return NULL; }
return bo;}
static struct drm_gem_object *xe_alloc_initial_plane_obj(struct drm_device *drm, struct intel_initial_plane_config *plane_config){ struct xe_device *xe = to_xe_device(drm); struct drm_mode_fb_cmd2 mode_cmd = { 0 }; struct drm_framebuffer *fb = plane_config->fb; struct xe_bo *bo;
mode_cmd.pixel_format = fb->format->format; mode_cmd.width = fb->width; mode_cmd.height = fb->height; mode_cmd.pitches[0] = fb->pitches[0]; mode_cmd.modifier[0] = fb->modifier; mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
bo = initial_plane_bo(xe, plane_config); if (!bo) return NULL;
if (intel_framebuffer_init(to_intel_framebuffer(fb), &bo->ttm.base, fb->format, &mode_cmd)) { drm_dbg_kms(&xe->drm, "intel fb init failed\n"); goto err_bo; } /* Reference handed over to fb */ xe_bo_put(bo);
return &bo->ttm.base;
err_bo: xe_bo_unpin_map_no_vm(bo); return NULL;}
static intxe_initial_plane_setup(struct drm_plane_state *_plane_state, struct intel_initial_plane_config *plane_config, struct drm_framebuffer *fb, struct i915_vma *_unused){ struct intel_plane_state *plane_state = to_intel_plane_state(_plane_state); struct i915_vma *vma; struct intel_fb_pin_params pin_params = { .view = &plane_state->view.gtt, }; u32 offset; int ret;
ret = xe_fb_pin_ggtt_pin(intel_fb_bo(fb), &pin_params, &vma, &offset, NULL); if (ret) return ret;
plane_state->ggtt_vma = vma;
plane_state->surf = offset;
plane_config->vma = vma;
return 0;}
static void xe_plane_config_fini(struct intel_initial_plane_config *plane_config){}
const struct intel_display_initial_plane_interface xe_display_initial_plane_interface = { .alloc_obj = xe_alloc_initial_plane_obj, .setup = xe_initial_plane_setup, .config_fini = xe_plane_config_fini,};