Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1438893lqp; Fri, 22 Mar 2024 15:16:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW3Yw8N/co8YLU0LFDT0OpJAKyTwd7biqgcnPGWSWNNN0PvR2agmvcAd7H/CAWTRBWWkYGQMB4TuC0XnO4u075grwiNN8ahIpuG6cliew== X-Google-Smtp-Source: AGHT+IEjrQ5lpQC2xFUOyssPyf/QZrlI8yk7Cl+0ScTtg5bZp9GtN6ksPEr2jgzFefUZ96YpYtdi X-Received: by 2002:ac2:446b:0:b0:515:8dd3:e94d with SMTP id y11-20020ac2446b000000b005158dd3e94dmr501711lfl.68.1711145777385; Fri, 22 Mar 2024 15:16:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711145777; cv=pass; d=google.com; s=arc-20160816; b=NBk5Se5Vcdlb/Zba8r6egDCQObdsZQt2gPIaYbIffd9/xRGnL/Bd+5RInC1RYoeJ38 W4Esl3dTKXYSwDsqf/HMTG+1YzUCVL4d7S5PSiWijPwazSv0EvivIZ70dIVis97sdKth q6TktfQpK1p26cWFNwHYW1gEFKph6seZC9ae0zA4umwCQabPBCKwSH8LYs8i7XM8BRsr rQ18tohyEtHw+BcJ3eRjIlOC1ET7mqrLvoB7oW4vmzDhmwrJzb2+cwa/h+pMajW6Wu6E lVGbks8sr8qomfZAeD+1Sj+tUVq9fbq77wKWu0+I9b7iKXPv3U+hjOR6wMXwzjxHrk/6 lHew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=t+o/hq/vRaAlqZorXgz61wZ5x9VfNVOFlmD2hAnuwQc=; fh=giUggxwvCEan/4rYEj4eF5WAcnS1hMPvbQxNqju48Gs=; b=wQNRJFPdvrEUMZz/FXIAPg95HNUs2LB4CIHMbrzCN312sT63W44xtbl22z3zR8V/p+ 8KdefUFD4P4EzyXGa+qz9PpCQE/4J3g0z+DOesCbWfE1q05DGhqJExFkJJ9WjdRbN6j1 f2AZE0HQYqtyIfvGow8z+GOGBgjQK9hTY8mP4qtd/NhZNiS7SozEWUG5C6crGDhkh0Sl 5UC8i+nJBCRMNiBdR3Fs6IRtaD8oyGjq2oGWZDZKmPbnocJx7IBh2u6fdOcGbCyi9Bcb QNG72NJGb+LH2aYM9ZmSa3FV1c7hsIjaCGM+QDP8UEEPtjitHlcH8Vfy04jLJu4y9BH/ I9cw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JtZkECFX; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-112065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112065-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m24-20020a170906235800b00a4500cd5a99si233918eja.573.2024.03.22.15.16.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 15:16:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JtZkECFX; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-112065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112065-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EBF641F23C82 for ; Fri, 22 Mar 2024 22:16:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0992B81750; Fri, 22 Mar 2024 22:15:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JtZkECFX" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D5E7627FC for ; Fri, 22 Mar 2024 22:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711145745; cv=none; b=ICwhhwJTa6DSZHV7G4Yp8UQAvAql4SxRxPowQXMO8RkG/Gl0n1v1/3bACMfA6mZoL9a4Vu2l55DEmw+vdEPaksY3cIGpoK4ly9Zbdnc+jYj+w/5EYxzbpPKZIk7zddlzSKPIJtGcIgLK8UVpEJWPtUasNYapjCOU3EcOmA4VIR0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711145745; c=relaxed/simple; bh=ycMrtdPn68CTRrt3aDmyI8tifKQ2EOf0nLCRHFWzr08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gag+72jv+UWfxwEYLRWsQ10UIWOM6pUf1xG4WL8GlJhbKf+DkXtCNomjJeqiQ/J9K4Nv0DurYV7WJiqF+72YjZGHBM1y7FxylDNwfpE9oFt1Ap998HLpyMeBSeJQq1CUjgkX++lBhiPKrJ9XI1tP4SVXicx/uaUcbBioii5l8Ug= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JtZkECFX; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711145742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t+o/hq/vRaAlqZorXgz61wZ5x9VfNVOFlmD2hAnuwQc=; b=JtZkECFX5OroTe2z+7T/LHbHzuguh/uULw919Wo8BycfmKV3jXP59AFMUhgkEq83R1lUj1 We9zxxFcGye0E5HsNjTkPR5WJBmGxeywNAmg5/VOruQizGsOLrJYj65E39suuk+W596Lrv BGt7VRhX9hhOxGAmW/4IourcG5G+RSI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-159-JjZz40PEMPe23vRDS-XaXg-1; Fri, 22 Mar 2024 18:15:38 -0400 X-MC-Unique: JjZz40PEMPe23vRDS-XaXg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5C3D3C02454; Fri, 22 Mar 2024 22:15:36 +0000 (UTC) Received: from emerald.redhat.com (unknown [10.22.8.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BA338173; Fri, 22 Mar 2024 22:15:36 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Asahi Lina , Martin Rodriguez Reboredo , FUJITA Tomonori , linux-kernel@vger.kernel.org (open list), rust-for-linux@vger.kernel.org (open list:RUST) Subject: [PATCH 4/4] WIP: rust/drm/kms: Add ShadowPlaneState Date: Fri, 22 Mar 2024 18:03:36 -0400 Message-ID: <20240322221305.1403600-5-lyude@redhat.com> In-Reply-To: <20240322221305.1403600-1-lyude@redhat.com> References: <20240322221305.1403600-1-lyude@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Signed-off-by: Lyude Paul --- drivers/gpu/drm/rvkms/plane.rs | 7 +++- rust/bindings/bindings_helper.h | 2 + rust/kernel/drm/kms.rs | 1 + rust/kernel/drm/kms/gem_atomic_helper.rs | 48 ++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 rust/kernel/drm/kms/gem_atomic_helper.rs diff --git a/drivers/gpu/drm/rvkms/plane.rs b/drivers/gpu/drm/rvkms/plane.rs index d98a1f7bf79e2..5fb1b63842929 100644 --- a/drivers/gpu/drm/rvkms/plane.rs +++ b/drivers/gpu/drm/rvkms/plane.rs @@ -4,7 +4,10 @@ prelude::*, drm::{ device::Device, - kms::plane::{self, DriverPlaneState}, + kms::{ + plane::{self, DriverPlaneState}, + gem_atomic_helper::ShadowPlaneState, + } }, }; @@ -15,7 +18,7 @@ pub(crate) struct DriverPlane { } pub(crate) type Plane = plane::Plane; -pub(crate) type PlaneState = plane::PlaneState; +pub(crate) type PlaneState = ShadowPlaneState; impl plane::DriverPlane for DriverPlane { type Initializer = impl PinInit; diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index 5856afbe6e8f6..73a5eb00e8625 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/rust/kernel/drm/kms.rs b/rust/kernel/drm/kms.rs index b55d14415367a..14f4c3842ada0 100644 --- a/rust/kernel/drm/kms.rs +++ b/rust/kernel/drm/kms.rs @@ -6,6 +6,7 @@ pub mod crtc; pub mod encoder; pub mod plane; +pub mod gem_atomic_helper; use crate::{ drm::{drv, device::Device}, diff --git a/rust/kernel/drm/kms/gem_atomic_helper.rs b/rust/kernel/drm/kms/gem_atomic_helper.rs new file mode 100644 index 0000000000000..85bc3df32d8b7 --- /dev/null +++ b/rust/kernel/drm/kms/gem_atomic_helper.rs @@ -0,0 +1,48 @@ +use crate::{ + prelude::*, + private::Sealed, + bindings, + init::Zeroable, +}; +use super::plane::{IntoPlaneState, DriverPlaneState}; + +unsafe impl Zeroable for bindings::drm_shadow_plane_state {} + +#[derive(Default)] +#[repr(C)] +pub struct ShadowPlaneState { + shadow_state: bindings::drm_shadow_plane_state, + inner: T, +} + +impl Sealed for ShadowPlaneState {} + +static_assert!(crate::offset_of!(bindings::drm_shadow_plane_state, base) == 0); + +// SAFETY: Our data layout starts with drm_plane_state (contained at the start of +// drm_shadow_plane_state) +unsafe impl IntoPlaneState for ShadowPlaneState { + fn __duplicate_state(&self, plane: *mut bindings::drm_plane) -> Result> { + let mut new: Box = Box::try_init(try_init!(Self { + shadow_state: bindings::drm_shadow_plane_state { ..Default::default() }, + inner: self.inner.clone() + }))?; + + // SAFETY: FFI call with no special requirements + unsafe { bindings::__drm_gem_duplicate_shadow_plane_state(plane, &mut new.shadow_state) }; + + Ok(new) + } + + fn __destroy_state(state: *mut bindings::drm_plane_state) { + // SAFETY: This would not be called without a plane state to destroy, and our data layout + // starts with `bindings::drm_plane_state` + unsafe { bindings::__drm_gem_destroy_shadow_plane_state(state.cast()) }; + } + + fn __reset_state(plane: *mut bindings::drm_plane, state: *mut bindings::drm_plane_state) { + // SAFETY: This would not be called without a plane state to reset, and our data layout + // starts with `bindings::drm_plane_state` + unsafe { bindings::__drm_gem_reset_shadow_plane(plane, state.cast()) } + } +} -- 2.43.0