From patchwork Tue Dec 3 13:55:44 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: 13892519 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 B8F591F12E0; Tue, 3 Dec 2024 13:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234159; cv=none; b=Ll9UCL4yDIcNaQ/qFjC82iVyIPO2UXKly8GOOQeepO91QYt2J9n9I4jpIKpq2B6CP3W134k1JfAFr8IvyYx8bonUxuXSwaS+Y4oHLtGaIluYu3pLk3DOkeca9Nl62w6TxB9WszZmUAxhEc689LNEQyZov94feX2021HUMma0gCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234159; c=relaxed/simple; bh=WD2pcUsyR0upLOY68yPUH/zihPiSwjXCHeCuOd7afPs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=P9i0wg37daxLkFDefd+ifEBJr1wXKyfIDdLlXFBWX1/KwO6g9MmldtsK3vGdoGQHY6u6jcf2s35ZhOQA5Y+OpWDmoukRUcUD1VD0WQu8lVW7GoJ1676XQ3ED5O//FphZfKZ/er2raM54KHJoRuM8GIYpKJDYxE7+JTWiRBF1LrA= 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=HSqCII8a; arc=none smtp.client-ip=217.70.183.195 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="HSqCII8a" Received: by mail.gandi.net (Postfix) with ESMTPSA id 32EE260002; Tue, 3 Dec 2024 13:55:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733234148; 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=RSAkpiI3SH9b1GWZEbN5u/HHHSzZvKkCgjFgcbGhZsk=; b=HSqCII8aaLodB5Kcmh20iVxBXp78ebeJAeo4oCwNM4j/JH+NOVHmyPSYNE50uCDB2SrR2+ 8zFu1bfVNxyOJVnzcX2IPGPYzksHFOWtD9ccsAOQYjyDfMnO69auMAMO7/jTA0Mg3vLldr oDwsSYLSuU77FTfBrObq5lsqwSmYAG0jtCczQKEBcWSS3fLnUxEaAqaReDJLZkJmt0rGpF IwpGUO6HLTcOQinXV8mlYjcJPd9JVwMGDMJFnQBesHtCdd/V5K3eTSVcWvXhZ0Plytcu+T /CAjqWL6/QzLBQSuSBGwH4cXNpkxEbWff0s2y2X5x1fh2xjCbOADQBllAvY/kg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 03 Dec 2024 14:55:44 +0100 Subject: [PATCH 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: <20241203-rmem-v1-1-24f4970cf14e@bootlin.com> References: <20241203-rmem-v1-0-24f4970cf14e@bootlin.com> In-Reply-To: <20241203-rmem-v1-0-24f4970cf14e@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. Signed-off-by: Théo Lebrun Acked-by: Rob Herring (Arm) --- 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 Tue Dec 3 13:55:45 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: 13892521 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 B8FAF1F12F2; Tue, 3 Dec 2024 13:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234159; cv=none; b=VIMjARt0tRcYgi6D6JpddAIsidewn9SFEkH9RM3jBJCAEW8EtGt6c6BibBRnnQCxCUDZw1GybFiFTaawZ14Kw/m5qJAzXmeRQVS8gkFLz5SkjRijZGkkSYKaQ52L2jOowhy96HyAIeDnWajpnsPw/ZG8/qz61c31yWSFToQ+2yA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234159; c=relaxed/simple; bh=BCAbN9+hhUpSq62Zs2Q0dGIwhF6v/NoYlHMxxEJlrjQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AveiruckCPwHoQ+yFoWf5IViyco/Fcwa66GHS/VCWZltbOXykMOAi73If/l/tgL/CbbAyejTlMSXCPpkab24nl/wjYL6rAsXK4oODs2toKikFHDT5dcAokIyCQD9lhbkf38fiNu5KSw7NOQKBlvH/4PMVGBybw1JFqwPJxCQk1k= 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=na/Hj1X2; arc=none smtp.client-ip=217.70.183.195 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="na/Hj1X2" Received: by mail.gandi.net (Postfix) with ESMTPSA id DDB426000D; Tue, 3 Dec 2024 13:55:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733234149; 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=na/Hj1X2WAZC1lPJAACPkXP56t/lAHgg3qTsml9maFnMhWJJTeR6Udxd5OqaeQUI7dUhUP J/c+xIB19Dsm1NZFK1xxw9HsmwzuOEMDh/pVK2HWnnePVT9XKJVNllKqDp+KyQMMnbeX0X xTTfTLhoDUf4Yz8Nybfm5S7jWXaaZ2+woARWxGF05tTrf3YLErmP7kd7Yi2FQeZSdYEBDI E2j02SWu+8LI1dwwKCV3PxGZfuEmfDmk21GVS4zepoW5ihfGFazkNqTuvQTqQ1o4b7LYGk v0mwlVVRMnsZ/Wo3x7KCcot/1UmJ4MXZ580x3XObZ1i2S4wU5/KS1HL4Zw5Nww== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 03 Dec 2024 14:55:45 +0100 Subject: [PATCH 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: <20241203-rmem-v1-2-24f4970cf14e@bootlin.com> References: <20241203-rmem-v1-0-24f4970cf14e@bootlin.com> In-Reply-To: <20241203-rmem-v1-0-24f4970cf14e@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 Tue Dec 3 13:55:46 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: 13892520 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 700A2189F3F; Tue, 3 Dec 2024 13:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234159; cv=none; b=in0tFqrdXVU1AvgmtqQoDWpXE6Y5qdr3mUMAxR1VD5A1Kn2bVf01bz96ioBMcgsUDFcmWGYvsltXVpFcarPr6w9KvcLvpflQdUAJ/9lQXCRxKdUCq+GuuK228eBm7hyLmcz91JMRFu3zCW/eJD0WOpeIsScBWOEUQQB0UlQWlGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234159; c=relaxed/simple; bh=/Wb5mnMykMP2xH0s1vcKryQucphSiN86XrEBmBaWTAw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RhW+M4bYa0xtX5FQ/Ygj2VUr4Z2EjDUIQFAdjQSa7HkJLVMSS45aiMXBDk2P+s/gD90mqRz3SJyKB0hOC5v/2lVQVEzBxlclLwokJkOVnsxibb9WWxbOiQJUhLTfScDZ9GS5CJCMu6rnwx5nUP9233GSbDFGtoBFU5d1qG2BLMw= 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=pGVkKslm; arc=none smtp.client-ip=217.70.183.195 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="pGVkKslm" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8418860006; Tue, 3 Dec 2024 13:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733234150; 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=pGVkKslmTGSKjlVYV0LAVQRfXbyomRirzBJoAHPcXsiR1XjLKX7ZkFRCekeQAV0KliH9Ry r7wF13aTnIaOJqj+7ZIIxkvGt52cbVFY4Oe4wBmnpgMTEelKRuFRY9Am5bjAWo/QAqpNiA ZFjR1xB8bSkyUXxu416Hxl1vqprxms9FtohjTfh2WFIrJoOTllba2DFAmMpZqI/OPT5uuY 1P+n4zGxZRMbmPy3rad7lPJZpJLdwnXG0MfTuRxth2Ajx3mKC2/RDc+MJqhRF0GqzeSFex e4qk2kPQIzmWmSse/4lD6FmZqFvZkGYZAwgCMef5ib2ArJodRCtptBD2U6QzSg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 03 Dec 2024 14:55:46 +0100 Subject: [PATCH 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: <20241203-rmem-v1-3-24f4970cf14e@bootlin.com> References: <20241203-rmem-v1-0-24f4970cf14e@bootlin.com> In-Reply-To: <20241203-rmem-v1-0-24f4970cf14e@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 Tue Dec 3 13:55:47 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: 13892522 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 42F401F130D; Tue, 3 Dec 2024 13:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234160; cv=none; b=a2pXCsZ3swpJuNw6GqCEw3cmjTcuVd95NfmeC0stg0JhbpwYg/hsn+gpr5+xkNm6epC4THlv0lvRhbOJ/bySpaJ3kUZ5ZcOIYacZWJSKK7FhXeFgX4uG8XgpEf3MxCmhv66KkMITr4+zbjN9dLVVEx+7FXQRow9R7viIzOlLJxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234160; c=relaxed/simple; bh=MdWR4geCX0sDA47jJ/SqTV1HnlhBmPs5PiPUOZHai9E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c2CzGomfId6c1EwJJahbPfahtv+lFRY5R2Vy1knhbmXVJdf9+UPUrua8gz3saFqPEHnNVakYl6yxaiU3JQPWTnbbDF7A7DjFhN2mF/etczbAWD4VL2ZKoPspQSjo9qefkXQ/fZjBOuGtF1yFC0w2R/t8yqnaArFrlk6Om1ZgMLw= 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=nFH216YS; arc=none smtp.client-ip=217.70.183.195 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="nFH216YS" Received: by mail.gandi.net (Postfix) with ESMTPSA id 303C06000F; Tue, 3 Dec 2024 13:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733234150; 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=nFH216YSECAavBAAEQy/JmLluUlIAnzZEj22CFez7JpTc9nkNDJhZ5pbysztC9wS1YrAJ8 aNl/izHmVFbLPIiMu72g/6aiOuy7XiiylRuL/W1b82wpBPFg0WWHI5j6Bi09svyoCA9gxZ hYWJMEUesH9ec5+M7DgekzTUzQlfAChM/7evbR80gQbZsUT5XVKoSJjeyab1rfs7SUeA27 YAMk9wCgafb7ZzIVAEHQwwRwBsw9H8SkY5mTPl21wswuFkLCUK6oF3nBgpsnapumi4uavQ ahooxJA2nw1J3ly43fyPopYJxFm8sag0Qcu3PViAjmcvMIPacxNdNFfXOG8hAA== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 03 Dec 2024 14:55:47 +0100 Subject: [PATCH 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: <20241203-rmem-v1-4-24f4970cf14e@bootlin.com> References: <20241203-rmem-v1-0-24f4970cf14e@bootlin.com> In-Reply-To: <20241203-rmem-v1-0-24f4970cf14e@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 Tue Dec 3 13:55:48 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: 13892523 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 42F9A1F130E; Tue, 3 Dec 2024 13:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234160; cv=none; b=cfVlQfBTRr86hf1LPDkvDpUPx8aWfdP8Th7iK2skicbJdXDz90ODg6SyiNRBIjRBl4YUYa/0tRxRblKAIblFiCPB3JsvUEZecMD5TI7voTloORtlP5OFw3Nj7M3ctLRTd/XrK5roGkkayI0bZX0hvnKQ3G/Kf3dqiCrVwBZlee8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234160; c=relaxed/simple; bh=lKeQ9AtKmtT3/g6/89CnJT2/810ZwKky7x2wGzEisZY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cFAYzcEyzrnfYDnxiNv9ZHW/75UmyvY+qwADBMfFcfp/f+wy87x4RYBulcFIgdKt99opV1vNRCEC22rEbdGR3zMzkRn3rNsI32VsdeMr5nlKbKrlxbmM6+yZO74KfTv85IEWWQDR5kOCEXQFzE7AhDQ87FBADeT8yty2MR/IPI8= 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=DieYce3V; arc=none smtp.client-ip=217.70.183.195 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="DieYce3V" Received: by mail.gandi.net (Postfix) with ESMTPSA id C9E9B60010; Tue, 3 Dec 2024 13:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733234151; 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=jsABzj1Vfkjzo1UXnSDoTFRCNe+h1i3gV/KNPBs/irU=; b=DieYce3VkYHzLoO+PC9eGa31KQ6wBRNn/L8eFhyXMtAAQhXPZorJUVIUnzkqZTfh0VWG2t rPJWTtFoefA9cSwPeGftVWZl6jgTvJczPqcJtrZagXun79wcqK4RuPN4L9l9CPaAjJM4zl 99Jm/r6wrNiwiQ5FzLxfzzjawscumEAsLFz1aHlvjHHyY92RqtfkXZQtunooa+VnV9EmVp 5weaRlG33b6Bpvpu2nHDdfk8vZbsgxAMcOAdLaXzxV2aLF1sTx3xmu78T5bTMfdXHQIUpI rHxQndz8ESUlm9PMV5FHVC3L4TbbITkJUXLie6nr50dxsc7xYNtufxjUggs2wg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 03 Dec 2024 14:55:48 +0100 Subject: [PATCH 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: <20241203-rmem-v1-5-24f4970cf14e@bootlin.com> References: <20241203-rmem-v1-0-24f4970cf14e@bootlin.com> In-Reply-To: <20241203-rmem-v1-0-24f4970cf14e@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 | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/drivers/nvmem/rmem.c b/drivers/nvmem/rmem.c index ca89c2689031534ff316a48e03360aeec823b025..04796f4fa8ae708387013fa260afb901a14e24ff 100644 --- a/drivers/nvmem/rmem.c +++ b/drivers/nvmem/rmem.c @@ -3,6 +3,7 @@ * Copyright (C) 2020 Nicolas Saenz Julienne */ +#include #include #include #include @@ -15,6 +16,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 +60,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 +142,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 Tue Dec 3 13:55:49 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: 13892524 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 587221F4725; Tue, 3 Dec 2024 13:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234162; cv=none; b=h4kjEZAIjFepZ9WFDOrDKCpaPZAaUmxuVqSmNDJX8iV/mGox/A3Aqi8XGmG4nX2mLBP+Mc+LXBkYWVEjnw4VXea8OSgOVYZEcT+w3GskDTggGTqTNOrGlw8WFbmArQfYNDYnF8rYtPaE6M0XYjMtKNBN+M0anwULO1VRqcsVuN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733234162; c=relaxed/simple; bh=pVnB3J68SJ5ZbxJrKUNajMzxZzFavA5FR2dTH5pwM0I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uoibZH4sweHxixtj1bs4CZ711f/8SdFoiBtN7JZfYSUNtpZGCOdhMyyjCqyWOVleoRGPHfXX5NPq58jEkJeoES6wBcWT3+W9ouLUNeoj8qkQzKHLPoWWSuc+0Z/3lqs3tpQzFKrWBlD8JcSFV5luV+eggw/C+whAv/3zLpX7TQg= 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=GxS41E/f; arc=none smtp.client-ip=217.70.183.195 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="GxS41E/f" Received: by mail.gandi.net (Postfix) with ESMTPSA id 785EE60012; Tue, 3 Dec 2024 13:55:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733234152; 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=GxS41E/fP4BUArZNLoPs+47NgNxZSk/SrDSF4rQwN3DJCqlfWXxiePM3CERDbbxvS5LGXR GqZS8SsUytpbJPkH1/tjzrwLBKjh5ysd4arKAHn3ru9CEdbLCCaaPkFF0Tkle1FQSfHdxk KDoslF8vQ7WXGWtYmEDV00oSU0s2fHdOKvyevQGaUaTSE4ZkwILDFy/8ZQRi2dZK8gqVod oxCPN+lGsYsFQ6pjQGLqi1cQvoY/JPjGx1+pfkArHszoKz/qy3hj3RFUxYv3cVBX6mXbdD w21RwZXjEMygK5KyiPODPs/FfvZlSVCI9koJkiMvliHiUIn5t8SVlS5LdFch7g== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 03 Dec 2024 14:55:49 +0100 Subject: [PATCH 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: <20241203-rmem-v1-6-24f4970cf14e@bootlin.com> References: <20241203-rmem-v1-0-24f4970cf14e@bootlin.com> In-Reply-To: <20241203-rmem-v1-0-24f4970cf14e@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 {