From patchwork Mon Dec 9 15:59:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 13899991 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 977DB136358; Mon, 9 Dec 2024 15:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759981; cv=none; b=gtcOghAEnAt7vTd9PXMrvkpZFz3bVYBXkCQW2ZfOOvQs5MsBpZeAeDmRvsDddcsywTAgmQOUcneeRvLf+4e7tCpwvHEj91j7z3cHpAcqy96LBLQEfR7iD1kOVzUIbrTm4QEebk4u0aNLTf0NKCUgrOheboNo5d0n618MtDNgff8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759981; c=relaxed/simple; bh=xQCMhd6sNmqzoVJsu+DPTvtqg8ej/py6WlhJVntLvWM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DjCbaxDXCvCJHWv7iO58VtRdXUBoNWtlC55gZEBoZZJHttPPZXWq6Sn4/GtzUDtTumcI3okarnC9CtH5WwJ74t9CmAX7Y1e3AzDbbp/XBPDdyL+VjovKHhd0S/PWVQYNKDc0aREC1VE5keVN8kN7bQfOcXssWKTu5jvJSk0F1z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=MUr01IBH; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="MUr01IBH" Received: by mail.gandi.net (Postfix) with ESMTPSA id 866F720002; Mon, 9 Dec 2024 15:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733759977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=633wi9jbGbmh5aHGKOl+TzK8t9Yq9KUEmvEFtmIsafs=; b=MUr01IBHsv8gjJuGOuFTUSwYBjE0+sIKC6cmCq29uAbAk1m+uBGGUtOgoWFz2GBPhvXWyN SZJIW+dAJAXUR0gA01hsOU75SwKP3q2kYNposElmgs73H8LpYdM9BkA6gMVt+tZm/bauXj PBTbtWxYJuK/7Ucwvbah/B9rQB55Cs1AFgqOpV8G/Tiw9961Nrn0xMjKzRRJjX3nEU5ifA RkHjyHrQTjpTjuuUs9/+zNqTvz9gdOHCNdDoHVuxvR9VuoToTWd5FYKPTVkEUtT+Ipymsc mYpANezYbI19JI9/wQao4/dYtC+D4sZWIkguOAiONddy/mjt4hiaCCL7higtFg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 09 Dec 2024 16:59:35 +0100 Subject: [PATCH v2 1/6] dt-bindings: nvmem: rmem: Add mobileye,eyeq5-bootloader-config Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-rmem-v2-1-cbc0e8c08a21@bootlin.com> References: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> In-Reply-To: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Saenz Julienne , Thomas Bogendoerfer Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Vladimir Kondratiev , =?utf-8?q?Gr=C3=A9?= =?utf-8?q?gory_Clement?= , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com On Mobileye EyeQ5, the bootloader will put MAC addresses into memory. Declare that as reserved memory to be used by the kernel, exposing nvmem cells. That region has a 12-byte header and a 4-byte trailing CRC. Acked-by: Rob Herring (Arm) Signed-off-by: Théo Lebrun --- Documentation/devicetree/bindings/nvmem/rmem.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/nvmem/rmem.yaml b/Documentation/devicetree/bindings/nvmem/rmem.yaml index 1ec0d09bcafa857c05ae722834c9e13bf63ee851..85f9f5de3906d2f1afce74ce001cf5db06e50806 100644 --- a/Documentation/devicetree/bindings/nvmem/rmem.yaml +++ b/Documentation/devicetree/bindings/nvmem/rmem.yaml @@ -16,6 +16,7 @@ properties: compatible: items: - enum: + - mobileye,eyeq5-bootloader-config - raspberrypi,bootloader-config - raspberrypi,bootloader-public-key - const: nvmem-rmem From patchwork Mon Dec 9 15:59:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 13899992 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 6D019136E21; Mon, 9 Dec 2024 15:59:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759982; cv=none; b=GViaW+WF05C0uWyChx1PEfdi1iQAI+kuw3yCCAV/Oy7yFwOknK2Z55KcU+hUQQNuzahaJxsHd2I01g69I1SqX3QMJtj84QdrH8Z85VOxrMUnGqVnFjwB3PDOwCg4Q1QkHXKWfa6K5iT9feQ0MVJwuXVwdHpiVZTIz3ndlcjpwXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759982; c=relaxed/simple; bh=BCAbN9+hhUpSq62Zs2Q0dGIwhF6v/NoYlHMxxEJlrjQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CKYvqSwpFbhE4+7htKQPe0XVFRqOoDVtESwD/1qb2MR/PuiZreBXf9GCCLpwu4ewGEsiHeNgOD1H7iSHZnJ/OrAfnCn4sr1u0JC+j3tpY7wm0pVVdB/DmtKsFjsWwVfpY2axIF/d8zXamVq084jCEQKQkEp8KXra5YYizoTp/LQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=FBvl4Bwt; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="FBvl4Bwt" Received: by mail.gandi.net (Postfix) with ESMTPSA id 462AD20005; Mon, 9 Dec 2024 15:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733759977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QIIUswryJGOD7vz1EWBwFcVso7Qevi29wufjM5nkywY=; b=FBvl4BwtugjRw+Q/BBxmabHVufGyAHjmtF1fxbluOqiTlA9XKO9xthyAYOmOQMiiKoJWP5 X9iCndNzARnj4Ng55oGHYJ1ImZAPM8UDUpY3lGRzxTy3i8L8mro+v59tEPsRhOOl2ePVDe pQGfYukhT5HMdye8ryV8TrdSiiSKeMjFRvIvf2yekrghNiKamSJYd9vERE1eXxi9utwWK1 H1O4bWXrK6LG+IJaaNQK+4uZgFYfVe5+dOMdyHIHFLYNpZSDjidEWAeKPiWxiCRxE8uZA7 /dcEamxNXa2Man5fTyrXX6aGT5djI8goFVN/i7+P/d4qnAiJAg5urcZABecxew== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 09 Dec 2024 16:59:36 +0100 Subject: [PATCH v2 2/6] nvmem: specify ->reg_read/reg_write() expected return values Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-rmem-v2-2-cbc0e8c08a21@bootlin.com> References: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> In-Reply-To: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Saenz Julienne , Thomas Bogendoerfer Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Vladimir Kondratiev , =?utf-8?q?Gr=C3=A9?= =?utf-8?q?gory_Clement?= , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com Both ->reg_read() and ->reg_write() return values are not easy to deduce. Explicit that they should return zero on success (and negative values otherwise). Such callbacks, in some alternative world, could return the number of bytes in the success case. That would be translated to errors in the nvmem core because of checks like: ret = nvmem->reg_write(nvmem->priv, offset, val, bytes); if (ret) { // error case } This mistake is not just theoretical, see commit 28b008751aa2 ("nvmem: rmem: Fix return value of rmem_read()"). Signed-off-by: Théo Lebrun --- include/linux/nvmem-provider.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 3ebeaa0ded00c8d12230e5be7eed045a89a82669..515676ebe59875fa0ab8a4e772542bdc90ead8e3 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -92,8 +92,8 @@ struct nvmem_cell_info { * @read_only: Device is read-only. * @root_only: Device is accessibly to root only. * @of_node: If given, this will be used instead of the parent's of_node. - * @reg_read: Callback to read data. - * @reg_write: Callback to write data. + * @reg_read: Callback to read data; return zero if successful. + * @reg_write: Callback to write data; return zero if successful. * @size: Device size. * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride. From patchwork Mon Dec 9 15:59:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 13899993 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 AAAAF136671; Mon, 9 Dec 2024 15:59:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759982; cv=none; b=RUrfC4w4zOhvsQ4DgTdmeBbs40ymZKpMUbxQ2Dw3zayOH31khCe/JCTXFbJ8eANQlBYfG/L729AuKAr3RL9ZcA0IAhb5UMBNx97EAMAjFPzvAoo7IoeqKgb3Aj9RYNK3LLOHWZ4SPfRmTxzLOgdnumgnCG7MYpVMWNnR65VieUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759982; c=relaxed/simple; bh=/Wb5mnMykMP2xH0s1vcKryQucphSiN86XrEBmBaWTAw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m0iSc0mxfUwkRVyQsssYR0TRfI9qDaFPxqPUxylJR6/H3OhQcuoxyItpobueHWzYAN/EeIGgppEVIuLNSOJP7dK+ZnQumpoRqDcWFoighDJdYIPtTYxzOkmDKXQFvSKpFgovgnNhXNigGOw4+N5HrHTskZnELuTF9SVWn/8f1Kc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=nlfb/+Uu; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="nlfb/+Uu" Received: by mail.gandi.net (Postfix) with ESMTPSA id E668320004; Mon, 9 Dec 2024 15:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733759978; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2t34cnBs5FIaeftw7DyeBVQ1s8Ww5ZRuvy9kmRpnaCI=; b=nlfb/+Uuu16k1TzU2Rq8J1zJkT82CiKICUZyW9Mr8IWwM8HMZV0hXZ9jgN5romH6Chv/tu HCZepT5M8deXvtje1niDVuB7u8VA95aXf6q/Mi6EfuXv+7DgOcf0XiLsw728MeY8HySzAh mQLKkOz8gvFDweDJnU2oLSqF4qORfGll2x2lV0KtY8fDMLlNC/JVTKnNqnK26+HeW8LDww PSYMA1LMqdbr+3srBsArzk7Eool79wEx2Z+RrRfCrRnCqPteVyD/rnZc5BgT3mkX5+LtYM +oV8gSgeHQxQ7hpykM8/v2Kqappi26K4tpxyjeA6XhlZa5/vfn87cwLVFF1r7A== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 09 Dec 2024 16:59:37 +0100 Subject: [PATCH v2 3/6] nvmem: rmem: make ->reg_read() straight forward code Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-rmem-v2-3-cbc0e8c08a21@bootlin.com> References: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> In-Reply-To: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Saenz Julienne , Thomas Bogendoerfer Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Vladimir Kondratiev , =?utf-8?q?Gr=C3=A9?= =?utf-8?q?gory_Clement?= , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com memory_read_from_buffer() is a weird choice; it: - is made for iteration with ppos a pointer. - does futile error checking in our case. - does NOT ensure we read exactly N bytes. Replace it by: 1. A check that (offset + bytes) lands inside the region and, 2. a plain memcpy(). Signed-off-by: Théo Lebrun --- drivers/nvmem/rmem.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/nvmem/rmem.c b/drivers/nvmem/rmem.c index 7f907c5a445e7865c8626e00362df0040fe52241..0dc5c8237c7538efe4597c182d7bdb709b945851 100644 --- a/drivers/nvmem/rmem.c +++ b/drivers/nvmem/rmem.c @@ -21,10 +21,10 @@ static int rmem_read(void *context, unsigned int offset, void *val, size_t bytes) { struct rmem *priv = context; - size_t available = priv->mem->size; - loff_t off = offset; void *addr; - int count; + + if ((phys_addr_t)offset + bytes > priv->mem->size) + return -EIO; /* * Only map the reserved memory at this point to avoid potential rogue @@ -36,20 +36,17 @@ static int rmem_read(void *context, unsigned int offset, * An alternative would be setting the memory as RO, set_memory_ro(), * but as of Dec 2020 this isn't possible on arm64. */ - addr = memremap(priv->mem->base, available, MEMREMAP_WB); + addr = memremap(priv->mem->base, priv->mem->size, MEMREMAP_WB); if (!addr) { dev_err(priv->dev, "Failed to remap memory region\n"); return -ENOMEM; } - count = memory_read_from_buffer(val, bytes, &off, addr, available); + memcpy(val, addr + offset, bytes); memunmap(addr); - if (count < 0) - return count; - - return count == bytes ? 0 : -EIO; + return 0; } static int rmem_probe(struct platform_device *pdev) From patchwork Mon Dec 9 15:59:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 13899994 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 AAB0013775E; Mon, 9 Dec 2024 15:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759982; cv=none; b=qI0jO3RJZwVE0lrTeZZibJDNHpoXjUiv8iawUoLAyhH+DxCB2d6lry5svPHGe+tXLeEt3ZjcKPdXbSPe2y0DH5QB4A9Dc/oG6SOgc5yEG9b1sw4DRSC+y8gFtj0g1MFo6Cvt1gEVUIxt5MIvvDvgD6Y4fb20c+VrwAZL0Bju4Xk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759982; c=relaxed/simple; bh=MdWR4geCX0sDA47jJ/SqTV1HnlhBmPs5PiPUOZHai9E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RXBlfIkq8K8xTjnRoqgCECZtr/GOp+HRxzKO7Lfnq0wwg3vEZ0Ji9dgui7r4lVX0nPN9vZr+GvB3rc47Rof31TGPxdUsgxIq74bW/Leb/meKEjvGf/ndX6TPVjV1x6cc2SLPc/rZ9R+XDib4D2V6myzwPCBAd3D/4pKFWEzMfx0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=CzeaPsD1; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="CzeaPsD1" Received: by mail.gandi.net (Postfix) with ESMTPSA id 9597B20007; Mon, 9 Dec 2024 15:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733759979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0N40lnlE7TZQY7BMgIIS/Ptfi/+E+ziL+VaV/uRj/us=; b=CzeaPsD1d7DoArU5lhHLk6VONkZDgZetW6gGMTyZKw4DX6IO+AYRbeovm323S3e9/LuVsB ewQRLcWrdLfeoxDNRVJrOi3QU9Ou7RgcgB0Spf7N5KINSbW2+Ta/FP1U0ipgbhAIPUeANy j12Xq3NJJCx+IkLpRbL4xNFF7J02QfCi9WX1ojDO64AqMtBy29S9SBp7QIxfnSEhrFxYUm 24NFqx0ocAPLk+skVnMa9c/danXz6TGIniVyewus2GG3zOkJ/+OJZPrzPJRMgp7fd6oL50 r5ea5C2Ss41V8kBMqEB56KqT0bWF5awqG10F7+Wg0IoS3vFSZHMYbtcFWzpTrw== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 09 Dec 2024 16:59:38 +0100 Subject: [PATCH v2 4/6] nvmem: rmem: remove unused struct rmem::size field Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-rmem-v2-4-cbc0e8c08a21@bootlin.com> References: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> In-Reply-To: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Saenz Julienne , Thomas Bogendoerfer Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Vladimir Kondratiev , =?utf-8?q?Gr=C3=A9?= =?utf-8?q?gory_Clement?= , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com The private structure used by the rmem driver contains a `size` field that is unused. Remove it. Signed-off-by: Théo Lebrun --- drivers/nvmem/rmem.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/nvmem/rmem.c b/drivers/nvmem/rmem.c index 0dc5c8237c7538efe4597c182d7bdb709b945851..ca89c2689031534ff316a48e03360aeec823b025 100644 --- a/drivers/nvmem/rmem.c +++ b/drivers/nvmem/rmem.c @@ -13,8 +13,6 @@ struct rmem { struct device *dev; struct nvmem_device *nvmem; struct reserved_mem *mem; - - phys_addr_t size; }; static int rmem_read(void *context, unsigned int offset, From patchwork Mon Dec 9 15:59:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 13899996 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 1884B13D8A3; Mon, 9 Dec 2024 15:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759984; cv=none; b=EFniyxY2rjIUrBr9V53RY4fHNBtNKOQGUttSRd+W985JJSj1ak+zsH0yHCvOcs9V6ygb5PQWcQcAX+d+IhoFmgrj+//CLkYxkorpDrHNeoBZnaGUbKkKCf0JtALPhUh+g5KSKitreo0Kvm7lkUz5sYVZBd+hwCAKqBKPIsL1s3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759984; c=relaxed/simple; bh=JQW+GRuAYpqVaYJr8AD+8K+ovcWI6p97DbY7ox6OxzQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pcMtRvjEYTXBD0YFM24rIytSTQgGiGBK5VfP1X97GxPb45Q2sd7jWas9EYt1KiTDu7Nq5pec/PLOoW9bYsyLAKH0PGhTIvlGr/qRJs+aZsRzHtWnTymplfy7EmIUcESf1wtsa78EFtLAJwfjvC69rSTR4oX1DzUN6K0eZkk6YIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ZzeRFr9R; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ZzeRFr9R" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4894B20008; Mon, 9 Dec 2024 15:59:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733759979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uoVHDS/FRQA9f0oimOdFs9drLE+G2Ls+ee4zqWm5bLs=; b=ZzeRFr9RKaARWSc7QImRzvQQ/Caj7f8Xv7FMUX8S9bKpHttnxoAg5vFKMD8UE14hkxmAyD 3MviIT9gjA2V7LpQ7apklQofDimnHyLCFU6EmhpH30hfkCeQuwZFTh2IuK+kSd49G3VSMT IXJCFLgqyW357LR1GMbZkhLim92zQ8bITgnjTQYHMHo7ZIPVmgGrg+VEdwdL6iFa3xkgXd pnbEDxCFTLjBVa38xCCmrlmNI2r0p5ZWkjGjz+yMY3bMl+O/zI8/kLsEjfKv8qeb1tpeYY la/B/97iauyTN5T5VPA+uX5obdstyIuH6+Mu1nrvSvxDI+MOAjAAj21FN0WECg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 09 Dec 2024 16:59:39 +0100 Subject: [PATCH v2 5/6] nvmem: rmem: add CRC validation for Mobileye EyeQ5 NVMEM Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-rmem-v2-5-cbc0e8c08a21@bootlin.com> References: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> In-Reply-To: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Saenz Julienne , Thomas Bogendoerfer Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Vladimir Kondratiev , =?utf-8?q?Gr=C3=A9?= =?utf-8?q?gory_Clement?= , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com Mobileye EyeQ5 has a non-volatile memory region which gets used to store MAC addresses. Its format includes a prefix 12-byte header and a suffix 4-byte CRC. Add an optional ->checksum() callback inside match data; it runs CRC32 onto the content. Signed-off-by: Théo Lebrun --- drivers/nvmem/rmem.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/drivers/nvmem/rmem.c b/drivers/nvmem/rmem.c index ca89c2689031534ff316a48e03360aeec823b025..1f0caf1d2dc1b3d42e5ac79b55222beb59fdd30d 100644 --- a/drivers/nvmem/rmem.c +++ b/drivers/nvmem/rmem.c @@ -3,11 +3,13 @@ * Copyright (C) 2020 Nicolas Saenz Julienne */ +#include #include #include #include #include #include +#include struct rmem { struct device *dev; @@ -15,6 +17,18 @@ struct rmem { struct reserved_mem *mem; }; +struct rmem_match_data { + int (*checksum)(struct rmem *priv); +}; + +struct __packed rmem_eyeq5_header { + u32 magic; + u32 version; + u32 size; +}; + +#define RMEM_EYEQ5_MAGIC ((u32)0xDABBAD00) + static int rmem_read(void *context, unsigned int offset, void *val, size_t bytes) { @@ -47,10 +61,66 @@ static int rmem_read(void *context, unsigned int offset, return 0; } +static int rmem_eyeq5_checksum(struct rmem *priv) +{ + struct rmem_eyeq5_header header; + void *buf __free(kfree) = NULL; + u32 computed_crc, *target_crc; + size_t data_size; + int ret; + + ret = rmem_read(priv, 0, &header, sizeof(header)); + if (ret) + return ret; + + if (header.magic != RMEM_EYEQ5_MAGIC) + return -EINVAL; + + /* + * Avoid massive kmalloc() if header read is invalid; + * the check would be done by the next rmem_read() anyway. + */ + if (header.size > priv->mem->size) + return -EINVAL; + + /* + * 0 +-------------------+ + * | Header (12 bytes) | \ + * +-------------------+ | + * | | | data to be CRCed + * | ... | | + * | | / + * data_size +-------------------+ + * | CRC (4 bytes) | + * header.size +-------------------+ + */ + + buf = kmalloc(header.size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret = rmem_read(priv, 0, buf, header.size); + if (ret) + return ret; + + data_size = header.size - sizeof(*target_crc); + target_crc = buf + data_size; + computed_crc = crc32(U32_MAX, buf, data_size) ^ U32_MAX; + + if (computed_crc == *target_crc) + return 0; + + dev_err(priv->dev, + "checksum failed: computed %#x, expected %#x, header (%#x, %#x, %#x)\n", + computed_crc, *target_crc, header.magic, header.version, header.size); + return -EINVAL; +} + static int rmem_probe(struct platform_device *pdev) { struct nvmem_config config = { }; struct device *dev = &pdev->dev; + const struct rmem_match_data *match_data = device_get_match_data(dev); struct reserved_mem *mem; struct rmem *priv; @@ -73,10 +143,21 @@ static int rmem_probe(struct platform_device *pdev) config.size = mem->size; config.reg_read = rmem_read; + if (match_data && match_data->checksum) { + int ret = match_data->checksum(priv); + if (ret) + return ret; + } + return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config)); } +static const struct rmem_match_data rmem_eyeq5_match_data = { + .checksum = rmem_eyeq5_checksum, +}; + static const struct of_device_id rmem_match[] = { + { .compatible = "mobileye,eyeq5-bootloader-config", .data = &rmem_eyeq5_match_data }, { .compatible = "nvmem-rmem", }, { /* sentinel */ }, }; From patchwork Mon Dec 9 15:59:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 13899995 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 187FA13D897; Mon, 9 Dec 2024 15:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759984; cv=none; b=Ily2CV7DjYrvjO0kQ7CUH+nrmU6jLqhB05GmUYlf5QUa7HSOvZFrpaDQwpkjIK9DIXwwwzNA1xAkZs9VI7S28ktMm8De83x4U5gB1O9oyQtujta0+CBEExhKq5xhX0QSWzkniRcgIucdXOVah6S5tP+jQ0TmRO8xWPUNlcyLPaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733759984; c=relaxed/simple; bh=pVnB3J68SJ5ZbxJrKUNajMzxZzFavA5FR2dTH5pwM0I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j5sQ9uMg62kue1UI8DN4/WxfqmCjFC72sUem1LDkA2Bv6Oe78XSr6kJqM2lGFpd3Dvo5SEP+zFjtvBhvQHfcjjq47vny2L3v/DHaR4b/gYCMGkYqTJaZGT46YVg3he0eMrg/b1HDN4nYiw6QmE55WAR9UGAte8lfNnEeCYuwhnM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ErIC4RNU; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ErIC4RNU" Received: by mail.gandi.net (Postfix) with ESMTPSA id E89DC2000D; Mon, 9 Dec 2024 15:59:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733759980; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o69Mz00pbhAuPCU0BiftNOE1d7MIT8r8LNe86G5wyqg=; b=ErIC4RNUSyyVT6gZ+EQwmUpuNvrFvDhI/tUxqaO29yHADBhhuR6jX61xiK+jJa6rPKUiPU OTVg51JP84jw1eecIUmyXosGZhnhCA7KYVaio/9rhLxyqx6XSduYqnRZOpeyeJyPmmh7wo HL4m2SQlr48RWsDei+6hh4gL592F5b7ilS+iFn8R6HI9s7RfSl4zYGH/Hq2xbSjc5RL8Qu Bny6aSCS3+wLnwHhXRpFO7ajeJbMNOAG+wFyiDjZh+3W1CUP+vDM0nX80gIfASDPBh1wTv jCBMAcdpgW7tW0JUfKHEf91n5G71aHfjAe9G6W+/qSrcMgOfIEfBSeC4eXKjVw== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 09 Dec 2024 16:59:40 +0100 Subject: [PATCH v2 6/6] MIPS: mobileye: eyeq5: add bootloader config reserved memory Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-rmem-v2-6-cbc0e8c08a21@bootlin.com> References: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> In-Reply-To: <20241209-rmem-v2-0-cbc0e8c08a21@bootlin.com> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Saenz Julienne , Thomas Bogendoerfer Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Vladimir Kondratiev , =?utf-8?q?Gr=C3=A9?= =?utf-8?q?gory_Clement?= , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com Add a new reserved-memory node, containing bootloader config with MAC addresses for both ethernet instances of the SoC. Signed-off-by: Théo Lebrun --- arch/mips/boot/dts/mobileye/eyeq5.dtsi | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/mips/boot/dts/mobileye/eyeq5.dtsi b/arch/mips/boot/dts/mobileye/eyeq5.dtsi index 5d73e8320b8efc1b4f68923482bf188c4345f1cb..a84e6e720619ef99e1405ae6296d8bad1aa3fa23 100644 --- a/arch/mips/boot/dts/mobileye/eyeq5.dtsi +++ b/arch/mips/boot/dts/mobileye/eyeq5.dtsi @@ -49,6 +49,28 @@ mini_coredump0_reserved: mini-coredump0@806200000 { mhm_reserved_0: the-mhm-reserved-0@0 { reg = <0x8 0x00000000 0x0 0x0000800>; }; + + nvram@461fe00 { + compatible = "mobileye,eyeq5-bootloader-config", "nvmem-rmem"; + reg = <0x0 0x0461fe00 0x0 0x200>; + #address-cells = <1>; + #size-cells = <1>; + no-map; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + eth0_mac: mac@7c { + reg = <0x7c 0x6>; + }; + + eth1_mac: mac@82 { + reg = <0x82 0x6>; + }; + }; + }; }; aliases {