Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp173966lqc; Thu, 7 Mar 2024 13:52:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXuIZpeJpYIapp3pWROFsZplnDhYSfIZn3Wtyr6zhiv8MgdoaYwFHcVpys3sil0ksa6h/YuzEgF70wEjvvgCr+ehRbpBUON6UIw3ni1Hw== X-Google-Smtp-Source: AGHT+IEoaryoZG+QaWQr1dc+AV+DJMdTStJJm6TKRrWl58DhC/AwxnYakPWwGi+wqBu2V7l+hiFy X-Received: by 2002:a17:902:f64c:b0:1dd:52d9:f154 with SMTP id m12-20020a170902f64c00b001dd52d9f154mr3456154plg.20.1709848355835; Thu, 07 Mar 2024 13:52:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709848355; cv=pass; d=google.com; s=arc-20160816; b=YLkVhgWE0PynJL60XvNV5VMnt1YA0RWezZvcbj9uhkuGnVJMxuyP/VTdQpswvyp7A6 i9vfdwfE8kp6lJ9KG+ms/nhWvu1TcebnPJxNgEKLUYivq8EFG5NHHUO+0+Rrh/8ld7UZ 7r1B//QMt3lVeCTb3TU3nrCae6gYs0+jf9VI04pjiOyCGWnvDnqIdU5rt0atDlr0NFlE cWmTAPO6XDuGWW4wlTit9o2UsonfKO6JuZs9WMtFNcBjA8L3Xtv+HNEp+/DpKw1PRcFg P46AS0T7fN9F2RKBvdznP+vk/O/p8pXOQ87Gy5SJYFWVWR18i75nbAz/z04ScwjWMdyD ZTxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:user-agent:subject:message-id :mime-version:list-unsubscribe:list-subscribe:list-id:precedence:to :cc:date:references:in-reply-to:from; bh=/BnhwLX3YCXgpJPOjFVmzjuieRhTLJ3wb2Nr+Ze6lRY=; fh=305g3WxktWn/mYlDIEuLU1KUA92l5KPANCOws5el8j0=; b=B/2vXChMBgGCWOTEazIbpX809Ukb93cJwzyoLArsUZoVEFFcKwqj/PlqTEbgAe7ya2 +ftWfjfBqGv/cypAAPj+jM3G+H2kOhpMK4XJzga9ZWf3qvKpwlWrcx4+SNchxXwvEp95 D0PmB1QZmMNhwiRWe6EeuBHRYCWAGmNcTyxXi1T1/tYs3x6UxRFg9/DtqSHZj3YmErxF HsQDyhGrbtN82SzYyAN2V+E7m9QU2Ae/YoXhzYZaruXX0n+5rl5ZMkBtAYVeNSh2Xqia yyEGKuFxtb002TBlkLBhzg6SjXO9DJKBXwyQEwFPi2iwUNA+Se2JZtMT6Zg51T8hJSAp cVQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-96285-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96285-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=collabora.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id v7-20020a1709029a0700b001dcc84cec4esi14281251plp.577.2024.03.07.13.52.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 13:52:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96285-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-96285-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96285-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=collabora.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B256A288AB4 for ; Thu, 7 Mar 2024 21:46:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DAAF13E7F1; Thu, 7 Mar 2024 21:45:38 +0000 (UTC) Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (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 5A81864A9F; Thu, 7 Mar 2024 21:45:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709847937; cv=none; b=iRpgt6TlM06wGB4M9dFksydBIyOgeYwQg2uCIOHKYpiMbjNtYmXnimso+ShRJUos+47u6RFA4ZtjvHUm+19hRh+reourGK0nsj1RNB7cuizEiB09hCbmLKmyzVzIwo6OqqydgMk1NXwve/aDNCFEfUpxKnMBZ9bcd5kdeGgsdIs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709847937; c=relaxed/simple; bh=XyrV3yZlEAF1mxbGdo1czbAm9N+9F+OQ3GDp0j0njqM=; h=From:In-Reply-To:Content-Type:References:Date:Cc:To:MIME-Version: Message-ID:Subject; b=oBOrwQy1ywVVlvj6Hqu2CYWRNvcG2FDhO8zu/k8CH+wfyP1Jl+U6lRdYxOXqevj9QhV/jQ1NBx93IleqIXKbwjv9iqxDn4TI8DonbAPIzjTrL7mGn0rf+OpeUATDK3nubsRHQwuFYnlq5I6RKPkmXXoxxXkX8letoQknERmpUIY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Received: from harlem.collaboradmins.com (harlem.collaboradmins.com [IPv6:2a01:4f8:1c0c:5936::1]) by madrid.collaboradmins.com (Postfix) with ESMTP id 86CEE37804B2; Thu, 7 Mar 2024 21:45:33 +0000 (UTC) From: "Daniel Almeida" In-Reply-To: Content-Type: text/plain; charset="utf-8" X-Forward: 127.0.0.1 References: <20240227215146.46487-1-daniel.almeida@collabora.com> <20240307190841.10260-1-daniel.almeida@collabora.com> <20240307190841.10260-3-daniel.almeida@collabora.com> Date: Thu, 07 Mar 2024 21:45:33 +0000 Cc: wedsonaf@gmail.com, ojeda@kernel.org, mchehab@kernel.org, hverkuil@xs4all.nl, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, kernel@collabora.com To: "Nicolas Dufresne" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <144b27-65ea3580-f-61876d80@130641868> Subject: =?utf-8?q?Re=3A?= [RFC PATCH v2 2/2] =?utf-8?q?media=3A?= =?utf-8?q?_rkvdec=3A?= rewrite parts of the driver in Rust User-Agent: SOGoMail 5.10.0 Content-Transfer-Encoding: quoted-printable Hi Nicolas, > struct reg123 { > val1 :3 // bit 31-29 > val2 :20 // bit 28-9 > val3 :9 // bit 8-0 > }; What you're describing can be modeled as Ranges in Rust: ``` use core::ops::Range; struct Foo { reg1: Range, reg2: Range, reg3: Range } const FOO=5FREGMAP: Foo =3D Foo { reg1: 0..3, reg2: 3..24, reg3: 24..32 }; ``` It becomes more useful when you pair that with a bit writer. For an exa= mple of previous art, see Faith's work: [0] This has asserts in the right places so that you do not shoot yourself = in the foot. IMHO, such a data structure can be shared with the whole R= ust code in the kernel. You can then describe your writes using the ranges, e.g.: [1]=20 But as we've established, instead of writing the ranges down directly, = you can simply refer to them as FOO=5FREGMAP.reg1, FOO=5FREGMAP.reg2 an= d so on. I believe this is both more readable and safer. [0]: https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/nouveau/c= ompiler/bitview/lib.rs?ref=5Ftype=3Dheads [1]: https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/nouveau/c= ompiler/nak/encode=5Fsm70.rs?ref=5Ftype=3Dheads#L228