firmware: imx: NXP Secure-Enclave FW Driver
Subsystems (3)
v7 cover firmware: imx: NXP Secure-Enclave FW Driver
V7 Changes:
- 2/11 DT Binding: Disposed off comments from .yaml
-- added | to preserve formating.
-- removed extra spaces, restricting under 80 col.
-- replaced the "fsl,sram" property, with standard property "sram". -- Added details about usage of sram.
-- removed the property "mu_id".
-- Added allOf:if:then: for reserved memory.
-- removed label.
- 3,4,5,6/11: DTSI changes:
-- removed the property "mu_id".
-- rename node-name & label
- 7/11 firmware: imx: add driver for NXP EdgeLock Enclave:
-- Removed dev_err for the cases of failure in memory allocation. -- For others, coverted dev_err to dev_dbg.
-- Updated the commit msg about the details for userspace lib
V6 Changes:
- 1/11 (New): Kernel doc: "Documentation/driver-api/firmware/other_interfaces.rst" is added.
- 2/11 DT Binding: Disposed off comments from .yaml
-- replaced the "sram-pool" property, with standard property "fsl,sram". -- removed the additional details from the description.
- 3,4,5,6/11: DTSI changes:
-- Validated using the following commands:
--- make dt_binding_check DT_SCHEMA_FILES=freescale
--- make CHECK_DTBS=y freescale/imx8ulp-evk.dtb;
make CHECK_DTBS=y freescale/imx93-11x11-evk.dtb- 7/11 firmware: imx: add driver for NXP EdgeLock Enclave:
-- Removed:
-- pr_info is removed.
-- macro "devctx_info", "devctx_dbg" & "devctx_err" is removed.
-- Updated ABI:
--- Users: user-space SE-LIB, crypto-api, imx-ocotp-ele driver , smw
--- IOCTLS: Updated the ioctl
--- read/write:
-- Correct message header validation.
--- segregated handling of the error, while msg header parsing.
-- removed TX and RX messages static allocation in state container. -- ran coccicheck: make C=1 CHECK=scripts/coccicheck drivers/firmware/imx/*.* W=1
--- ran on all the patches.
- 8/11 firmware: imx: init-fw api exchange on imx93
-- removed TX and RX messages static allocation in state container. -- moved the header file ele_fw_api.h, to driver/firmware/imx/
-- segregated handling of the error, while msg header parsing.
- 9/11 firmware: imx: enable trng
-- macro "devctx_info", "devctx_dbg" & "devctx_err" is removed.
-- will remove this patch, will send this patch later, including RNG and crypto-maintainers.
- 10/11 firmware: imx: enclave-fw: add handling for save/restore IMEM region -- Linux comment style fixed.
- 10/11(old)(Removed) firmware: imx: enclave api to read-common-fuses
-- This API will be used by imx-ocotp-ele.c.
-- This patch can be sent later, when the changes to imx-ocotp-ele.c will be sent. -- "Documentation/driver-api/firmware/other_interfaces.rst" will be update for the exported symbols:
- read_common_fuses()
- get_se_dev()
v5 Changes:
- 1/7 DT Binding: Disposed off comments from .yaml
-- to use "-", instead of "_".
-- to use generic name, concatinated with soc-id.
-- removed mu-did.
-- renamed the ele-mu to se-fw
-- moved the file from .../arm/freescale/ to .../firmware/
- 2/7 Changed the .dtsi, as per the comments.
-- removed mu-did
-- renamed the ele_mu to se-fw.
-- updated the compatible string.
-- tested the DTB.
- 4/7 Changed the .dtsi, as per the comments.
-- removed mu-did
-- renamed the ele_mu to se-fw.
-- updated the compatible string.
-- tested the DTB.
- 6/7 Changes in driver code:
-- replace pr_err with dev_err
-- removed export symbols, except one, which will be used in other driver. -- Each API, send-recived based on device reference.
-- Divided the commits into smaller commits.
- Base Driver
-- Added ABI file.
- 7/11 (new) firmware: imx: init-fw api exchange on imx93
- 8/11 (new) firmware: imx: enable trng
- 9/11 (new) firmware: imx: enclave-fw: add handling for save/restore IMEM region
- 10/11 (new) firmware: imx: enclave api to read-common-fuses
v4 Changes:
- Post internal review, changed the name from "ele-mu" to "se-fw".
- Disposed-off comments in the dt-binding file.
- Removed the non-hw related dt-bindings from the driver code.
- Corrected the File MAINTAINERS for correct name of yaml file.
v3 Changes:
- update the commit message for documentation.
- Fixed dt-binding checking error for file- fsl,ele_mu.yaml
- Coverity fixes in the ele_mu.c
v2 Changes:
- Fixed Kernel Test Bot issues.
- Removed ".../devicetree/bindings/mailbox/fsl,muap.txt"
The NXP's i.MX EdgeLock Enclave, a HW IP creating an embedded secure enclave within the SoC boundary to enable features like
- HSM
- SHE
- V2X
Communicates via message unit with linux kernel. This driver is enables communication ensuring well defined message sequence protocol between Application Core and enclave's firmware.
Driver configures multiple misc-device on the MU, for multiple user-space applications can communicate on single MU.
It exists on some i.MX processors. e.g. i.MX8ULP, i.MX93 etc.
Pankaj Gupta (11):
Documentation/firmware: added imx/se-fw to other_interfaces
dt-bindings: arm: fsl: add imx-se-fw binding doc
arm64: dts: imx8ulp-evk: added nxp secure enclave firmware
arm64: dts: imx8ulp-evk: reserved mem-ranges to constrain ele_fw
dma-range
arm64: dts: imx93-11x11-evk: added nxp secure enclave fw
arm64: dts: imx93-11x11-evk: reserved mem-ranges
firmware: imx: add driver for NXP EdgeLock Enclave
firmware: imx: init-fw api exchange on imx93
firmware: imx: enable trng
firmware: imx: enclave-fw: add handling for save/restore IMEM region
MAINTAINERS: Added maintainer details
Documentation/ABI/testing/se-cdev | 41 + .../bindings/firmware/fsl,imx-se-fw.yaml | 83 + .../driver-api/firmware/other_interfaces.rst | 67 + MAINTAINERS | 10 + arch/arm64/boot/dts/freescale/imx8ulp-evk.dts | 15 + arch/arm64/boot/dts/freescale/imx8ulp.dtsi | 10 +- .../boot/dts/freescale/imx93-11x11-evk.dts | 15 + arch/arm64/boot/dts/freescale/imx93.dtsi | 8 +- drivers/firmware/imx/Kconfig | 21 + drivers/firmware/imx/Makefile | 3 + drivers/firmware/imx/ele_base_msg.c | 271 ++++ drivers/firmware/imx/ele_common.c | 294 ++++ drivers/firmware/imx/ele_common.h | 40 + drivers/firmware/imx/ele_fw_api.c | 118 ++ drivers/firmware/imx/ele_fw_api.h | 26 + drivers/firmware/imx/ele_trng.c | 47 + drivers/firmware/imx/se_fw.c | 1376 +++++++++++++++++ drivers/firmware/imx/se_fw.h | 154 ++ include/linux/firmware/imx/ele_base_msg.h | 67 + include/linux/firmware/imx/ele_mu_ioctl.h | 74 + 20 files changed, 2738 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/se-cdev create mode 100644 Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml create mode 100644 drivers/firmware/imx/ele_base_msg.c create mode 100644 drivers/firmware/imx/ele_common.c create mode 100644 drivers/firmware/imx/ele_common.h create mode 100644 drivers/firmware/imx/ele_fw_api.c create mode 100644 drivers/firmware/imx/ele_fw_api.h create mode 100644 drivers/firmware/imx/ele_trng.c create mode 100644 drivers/firmware/imx/se_fw.c create mode 100644 drivers/firmware/imx/se_fw.h create mode 100644 include/linux/firmware/imx/ele_base_msg.h create mode 100644 include/linux/firmware/imx/ele_mu_ioctl.h
Signature · 1 line
2.34.1
PATCH v7 1/11 Documentation/firmware: added imx/se-fw to other_interfaces
Documented i.MX SoC's Service layer and C_DEV driver for SoC(s) enabled with hardware IP for secure-enclaves like:
- edgelock enclave on i.MX93 & i.MX8ULP
--- .../driver-api/firmware/other_interfaces.rst | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+)
Documentation/driver-api/firmware/other_interfaces.rst +67 -0
@@ -49,3 +49,70 @@ of the requests on to a secure monitor (EL3). .. kernel-doc:: drivers/firmware/stratix10-svc.c :export: + +NXP i.MX Secure Enclave Enabled SoC Service layer and C_DEV driver +------------------------------------------------------------------ +The NXP's i.MX HW IP like EdgeLock-Enclave, creating an embedded secure +enclave within the SoC boundary to enable features like + - HSM + - SHE + - V2X + +SoC enabled with the NXP i.MX secure enclave IP(s) like EdgeLock-Enclave(ELE), +are: i.MX93, i.MX8ULP. + +This driver exposes two interfaces: +- service layer: This layer takes the two mutex locks: + "mu_cmd_lock" is taken to ensure one service is processed at a time. This + lock is not unlocked, till one service processing is complete. Multiple + messages can be exchanged with FW as part of one service processing. + "mu_lock" is taken to ensure one message is sent over MU at a time. This + lock is unlocked, post sending the message. + +- c_dev: + This driver configures multiple misc-devices on the MU, to exchange + messages from User-space application and NXP's Edgelocke Enclave firmware. + The driver ensures that the messages must follow the following protocol + defined. + + Non-Secure + Secure + | + | + +---------+ +-------------+ | + | se_fw.c +<---->+imx-mailbox.c| | + | | | mailbox.c +<-->+------+ +------+ + +---+-----+ +-------------+ | MU X +<-->+ ELE | + | +------+ +------+ + +----------------+ | + | | | + v v | + logical logical | + receiver waiter | + + + | + | | | + | | | + | +----+------+ | + | | | | + | | | | + device_ctx device_ctx device_ctx | + | + User 0 User 1 User Y | + +------+ +------+ +------+ | + |misc.c| |misc.c| |misc.c| | + kernel space +------+ +------+ +------+ | + | + +------------------------------------------------------ | + | | | | + userspace /dev/ele_muXch0 | | | + /dev/ele_muXch1 | | + /dev/ele_muXchY | + | + +When a user sends a command to the firmware, it registers its device_ctx +as waiter of a response from firmware. + +Enclave's Firmware owns the storage management, over linux filesystem. +For this c_dev provisions a dedicated slave device called "receiver". + +.. kernel-doc:: drivers/firmware/imx/se_fw.c + :export:
Signature · 1 line
2.34.1
Re: [PATCH v7 01/11] Documentation/firmware: added imx/se-fw to other_interfaces
Quoted 5 lines · Pankaj Gupta
Documented i.MX SoC's Service layer and
C_DEVdriver for SoC(s) enabled with hardware IP for secure-enclaves like:
- edgelock enclave on i.MX93 & i.MX8ULPSigned-off-by Pankaj Gupta <[email protected]>
I asked to explain user-space tools as well. I don't see them mentioned/documented in none of the commits.
Best regards,
Krzysztof
Re: [PATCH v7 01/11] Documentation/firmware: added imx/se-fw to other_interfaces
Quoted 9 lines · Krzysztof Kozlowski
Quoted 5 lines · Pankaj Gupta
Documented i.MX SoC's Service layer and
C_DEVdriver for SoC(s) enabled with hardware IP for secure-enclaves like:
- edgelock enclave on i.MX93 & i.MX8ULPSigned-off-by Pankaj Gupta <[email protected]>I asked to explain user-space tools as well. I don't see them mentioned/documented in none of the commits.
Hm, I lost somehow or I did not get your patch #7, so maybe that's the place where they are mentioned.
Best regards,
Krzysztof
PATCH v7 2/11 dt-bindings: arm: fsl: add imx-se-fw binding doc
In reply to Pankaj GuptaThe NXP's i.MX EdgeLock Enclave, a HW IP creating an embedded secure enclave within the SoC boundary to enable features like
- HSM
- SHE
- V2X
Communicates via message unit with linux kernel. This driver is enables communication ensuring well defined message sequence protocol between Application Core and enclave's firmware.
Driver configures multiple misc-device on the MU, for multiple user-space applications can communicate on single MU.
It exists on some i.MX processors. e.g. i.MX8ULP, i.MX93 etc.
--- .../bindings/firmware/fsl,imx-se-fw.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +83 -0
@@ -0,0 +1,83 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/firmware/fsl,imx-se-fw.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP i.MX EdgeLock Enclave Firmware (ELEFW) + +maintainers: + - Pankaj Gupta <[email protected]> + +description: + The NXP's i.MX EdgeLock Enclave, a HW IP creating an embedded + secure enclave within the SoC boundary to enable features like + - HSM + - SHE + - V2X + + It uses message unit to communicate and coordinate to pass messages + (e.g., data, status and control) through its interfaces. + +properties: + compatible: + enum: + - fsl,imx8ulp-se-fw + - fsl,imx93-se-fw + + mboxes: + description: + All MU channels must be within the same MU instance. Cross instances are + not allowed. Users need to ensure that used MU instance does not conflict + with other execution environments. + items: + - description: TX0 MU channel + - description: RX0 MU channel + + mbox-names: + items: + - const: tx + - const: rx + + memory-region: + items: + - description: Reserved memory region that can be accessed by firmware. Used for + exchanging the buffers between driver and firmware. + + sram: + description: Phandle to the device SRAM + $ref: /schemas/types.yaml#/definitions/phandle-array + +required: + - compatible + - mboxes + - mbox-names + +allOf: + # memory-region + - if: + properties: + compatible: + contains: + enum: + - fsl,imx8ulp-se-fw + - fsl,imx93-se-fw + then: + required: + - memory-region + else: + not: + required: + - memory-region + +additionalProperties: false + +examples: + - | + se-fw2 { + compatible = "fsl,imx8ulp-se-fw"; + mbox-names = "tx", "rx"; + mboxes = <&s4muap 0 0>, <&s4muap 1 0>; + }; + +...
Signature · 1 line
2.34.1
Rob Herring
maintainerRe: [PATCH v7 02/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
Quoted 13 lines · Pankaj Gupta
The NXP's i.MX EdgeLock Enclave, a HW IP creating an embedded secure enclave within the SoC boundary to enable features like
- HSM
- SHE
- V2XCommunicates via message unit with linux kernel. This driver is enables communication ensuring well defined message sequence protocol between Application Core and enclave's firmware.
Driver configures multiple misc-device on the MU, for multiple user-space applications can communicate on single MU.
Quoted 8 lines
It exists on some i.MX processors. e.g. i.MX8ULP, i.MX93 etc.
Signed-off-by Pankaj Gupta <[email protected]>--- .../bindings/firmware/fsl,imx-se-fw.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/dma/stericsson,dma40.example.dtb: dma-controller@801c0000: sram:0: [4294967295, 4294967295] is too long
from schema $id: http://devicetree.org/schemas/dma/stericsson,dma40.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.example.dtb: se-fw2: 'memory-region' is a required property
from schema $id: http://devicetree.org/schemas/firmware/fsl,imx-se-fw.yaml#
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v7 02/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
In reply to Pankaj GuptaQuoted 29 lines · Pankaj Gupta
The NXP's i.MX EdgeLock Enclave, a HW IP creating an embedded secure enclave within the SoC boundary to enable features like
- HSM
- SHE
- V2XCommunicates via message unit with linux kernel. This driver is enables communication ensuring well defined message sequence protocol between Application Core and enclave's firmware.
Driver configures multiple misc-device on the MU, for multiple user-space applications can communicate on single MU.
It exists on some i.MX processors. e.g. i.MX8ULP, i.MX93 etc.
Signed-off-by Pankaj Gupta <[email protected]>--- .../bindings/firmware/fsl,imx-se-fw.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yamlDocumentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +2
-0@@ -0,0 +1,83 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 12
Quoted 10 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +10
-0+--- +$id: http://devicetree.org/schemas/firmware/fsl,imx-se-fw.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP i.MX EdgeLock Enclave Firmware (ELEFW) + +maintainers: + - Pankaj Gupta <[email protected]> + +description:
This is a friendly reminder during the review process.
It seems my or other reviewer's previous comments were not fully addressed. Maybe the feedback got lost between the quotes, maybe you just forgot to apply it. Please go back to the previous discussion and either implement all requested changes or keep discussing them.
Thank you.
Also - not tested
Quoted 26 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +26
-0+ The NXP's i.MX EdgeLock Enclave, a HW IP creating an embedded + secure enclave within the SoC boundary to enable features like + - HSM + - SHE + - V2X + + It uses message unit to communicate and coordinate to pass messages + (e.g., data, status and control) through its interfaces. + +properties: + compatible: + enum: + - fsl,imx8ulp-se-fw + - fsl,imx93-se-fw + + mboxes: + description: + All MU channels must be within the same MU instance. Cross instances are + not allowed. Users need to ensure that used MU instance does not conflict + with other execution environments. + items: + - description: TX0 MU channel + - description: RX0 MU channel + + mbox-names: + items:
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 48
Quoted 10 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +10
-0+ - const: tx + - const: rx + + memory-region: + items: + - description: Reserved memory region that can be accessed by firmware. Used for + exchanging the buffers between driver and firmware. + + sram: + description: Phandle to the device SRAM
Nothing improved
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 49
Quoted 1 line
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +1
-0+ $ref: /schemas/types.yaml#/definitions/phandle-array
How many items? What's inside?
Quoted 12 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +12
-0+ +required: + - compatible + - mboxes + - mbox-names + +allOf: + # memory-region + - if: + properties: + compatible: + contains:
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 71
Quoted 10 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +10
-0+ enum: + - fsl,imx8ulp-se-fw + - fsl,imx93-se-fw + then: + required: + - memory-region + else: + not: + required: + - memory-region
That's not the syntax. Test it.
You wanted :false
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 77
Quoted 6 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +6
-0+ +additionalProperties: false + +examples: + - | + se-fw2 {
And how suddenly "2" appeared here? Anyway:
Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 80
Quoted 3 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +3
-0+ compatible = "fsl,imx8ulp-se-fw"; + mbox-names = "tx", "rx"; + mboxes = <&s4muap 0 0>, <&s4muap 1 0>;
Add complete example, so you miss sram.
This code is not going well. :( I understand some discussions on properties but lack of testing? At v7 of patchset still not tested?
Best regards,
Krzysztof
PATCH v7 3/11 arm64: dts: imx8ulp-evk: added nxp secure enclave firmware
In reply to Pankaj GuptaAdded support for NXP secure enclave called EdgeLock Enclave firmware (se-fw) for imx8ulp-evk.
--- arch/arm64/boot/dts/freescale/imx8ulp.dtsi | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/freescale/imx8ulp.dtsi +9 -1
@@ -152,7 +152,7 @@ sosc: clock-sosc { #clock-cells = <0>; }; - sram@2201f000 { + sram0: sram@2201f000 { compatible = "mmio-sram"; reg = <0x0 0x2201f000 0x0 0x1000>;
@@ -578,4 +578,12 @@ gpiod: gpio@2e200080 { gpio-ranges = <&iomuxc1 0 0 24>; }; }; + + ele_fw2: se-fw2 { + compatible = "fsl,imx8ulp-se-fw"; + mbox-names = "tx", "rx"; + mboxes = <&s4muap 0 0>, <&s4muap 1 0>; + sram = <&sram0>; + }; + };
Signature · 1 line
2.34.1
Re: [PATCH v7 03/11] arm64: dts: imx8ulp-evk: added nxp secure enclave firmware
Quoted 22 lines · Pankaj Gupta
Added support for NXP secure enclave called EdgeLock Enclave firmware (se-fw) for imx8ulp-evk.
Signed-off-by Pankaj Gupta <[email protected]>--- arch/arm64/boot/dts/freescale/imx8ulp.dtsi | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)arch/arm64/boot/dts/freescale/imx8ulp.dtsi +1
-1@@ -152,7 +152,7 @@ sosc: clock-sosc { #clock-cells = <0>; }; - sram@2201f000 { + sram0: sram@2201f000 { compatible = "mmio-sram"; reg = <0x0 0x2201f000 0x0 0x1000>;
arch/arm64/boot/dts/freescale/imx8ulp.dtsi gpiod: gpio@2e200080 { · line 582
Quoted 5 lines
arch/arm64/boot/dts/freescale/imx8ulp.dtsi +2
-0@@ -578,4 +578,12 @@ gpiod: gpio@2e200080 { gpio-ranges = <&iomuxc1 0 0 24>; }; }; + + ele_fw2: se-fw2 {
Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
Best regards,
Krzysztof
PATCH v7 4/11 arm64: dts: imx8ulp-evk: reserved mem-ranges to constrain ele_fw dma-range
In reply to Pankaj GuptaEdgeLock Enclave are has a hardware limitation of restricted access to the DDR memory range:
- 0x90000000 - 0xAFFFFFFF
ELE-FW driver requireis 1MB of memory. In this patch the we are reserving 1MB of ddr memory region from the lower 32-bit range.
--- arch/arm64/boot/dts/freescale/imx8ulp-evk.dts | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm64/boot/dts/freescale/imx8ulp-evk.dts +15 -0
@@ -19,6 +19,17 @@ memory@80000000 { device_type = "memory"; reg = <0x0 0x80000000 0 0x80000000>; }; + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + ele_reserved: ele-reserved@90000000 { + compatible = "shared-dma-pool"; + reg = <0 0x90000000 0 0x100000>; + no-map; + }; + }; reserved-memory { #address-cells = <2>;
@@ -146,6 +157,10 @@ &usdhc0 { status = "okay"; }; +&ele_fw2 { + memory-region = <&ele_reserved>; +}; + &fec { pinctrl-names = "default", "sleep"; pinctrl-0 = <&pinctrl_enet>;
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v7 5/11 arm64: dts: imx93-11x11-evk: added nxp secure enclave fw
In reply to Pankaj GuptaAdded support for NXP secure enclave called EdgeLock Enclave firmware (se-fw) for imx93-11x11-evk.
--- arch/arm64/boot/dts/freescale/imx93.dtsi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/freescale/imx93.dtsi +7 -1
@@ -1,6 +1,6 @@ // SPDX-License-Identifier: (GPL-2.0+ OR MIT) /* - * Copyright 2022 NXP + * Copyright 2022-2023 NXP */ #include <dt-bindings/clock/imx93-clock.h>
@@ -925,4 +925,10 @@ ddr-pmu@4e300dc0 { interrupts = <GIC_SPI 90 IRQ_TYPE_LEVEL_HIGH>; }; }; + + ele_fw2: se-fw2 { + compatible = "fsl,imx93-se-fw"; + mbox-names = "tx", "rx"; + mboxes = <&s4muap 0 0>, <&s4muap 1 0>; + }; };
Signature · 1 line
2.34.1
Re: [PATCH v7 05/11] arm64: dts: imx93-11x11-evk: added nxp secure enclave fw
Quoted 21 lines · Pankaj Gupta
Added support for NXP secure enclave called EdgeLock Enclave firmware (se-fw) for imx93-11x11-evk.
Signed-off-by Pankaj Gupta <[email protected]>--- arch/arm64/boot/dts/freescale/imx93.dtsi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/arm64/boot/dts/freescale/imx93.dtsi +1
-1@@ -1,6 +1,6 @@ // SPDX-License-Identifier: (GPL-2.0+ OR MIT) /* - * Copyright 2022 NXP + * Copyright 2022-2023 NXP */ #include <dt-bindings/clock/imx93-clock.h>
arch/arm64/boot/dts/freescale/imx93.dtsi ddr-pmu@4e300dc0 { · line 929
Quoted 5 lines
arch/arm64/boot/dts/freescale/imx93.dtsi +2
-0@@ -925,4 +925,10 @@ ddr-pmu@4e300dc0 { interrupts = <GIC_SPI 90 IRQ_TYPE_LEVEL_HIGH>; }; }; + + ele_fw2: se-fw2 {
Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
Why do you even need label?
Best regards,
Krzysztof
PATCH v7 6/11 arm64: dts: imx93-11x11-evk: reserved mem-ranges
In reply to Pankaj GuptaEdgeLock Enclave are has a hardware limitation of restricted access to the DDR memory range:
- 0x80000000 0x9FFFFFFF
ELE-MU driver requireis 1MB of memory. In this patch, reserving 1MB of ddr memory region from the lower 32-bit range.
--- arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts +15 -0
@@ -7,6 +7,10 @@ #include "imx93.dtsi" +&ele_fw2 { + memory-region = <&ele_reserved>; +}; + / { model = "NXP i.MX93 11X11 EVK board"; compatible = "fsl,imx93-11x11-evk", "fsl,imx93";
@@ -68,6 +72,17 @@ reg_vref_1v8: regulator-adc-vref { regulator-max-microvolt = <1800000>; }; + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + ele_reserved: ele-reserved@a4120000 { + compatible = "shared-dma-pool"; + reg = <0 0xa4120000 0 0x100000>; + no-map; + }; + }; + reg_usdhc2_vmmc: regulator-usdhc2 { compatible = "regulator-fixed"; pinctrl-names = "default";
Signature · 1 line
2.34.1
Re: [PATCH v7 06/11] arm64: dts: imx93-11x11-evk: reserved mem-ranges
Quoted 18 lines · Pankaj Gupta
EdgeLock Enclave are has a hardware limitation of restricted access to the DDR memory range:
-0x800000000x9FFFFFFFELE-MU driver requireis 1MB of memory. In this patch, reserving 1MB of ddr memory region from the lower 32-bit range.
Signed-off-by Dong Aisheng <[email protected]>Signed-off-by Pankaj Gupta <[email protected]>--- arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts +0
-0
arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts line 10
Quoted 4 lines
arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts +1
-0@@ -7,6 +7,10 @@ #include "imx93.dtsi" +&ele_fw2 {
OK, this explains the label in imx93.dtsi, but then node in the imx93.dtsi is incomplete and should be disabled. Everything which is incomplete should be disabled in DTSI by default. At v7 of your patchset I really would expect some internal review happening.
Quoted 7 lines
arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts +3
-0+ memory-region = <&ele_reserved>; +}; + / { model = "NXP i.MX93 11X11 EVK board"; compatible = "fsl,imx93-11x11-evk", "fsl,imx93";
arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts reg_vref_1v8: regulator-adc-vref { · line 79
Quoted 8 lines
arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts +5
-0@@ -68,6 +72,17 @@ reg_vref_1v8: regulator-adc-vref { regulator-max-microvolt = <1800000>; }; + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + ele_reserved: ele-reserved@a4120000 {
Names in reserved memory should match the purpose, so "reserved" is here redundant. Just "ele".
arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts reg_vref_1v8: regulator-adc-vref { · line 88
Quoted 9 lines
arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts +6
-0+ compatible = "shared-dma-pool"; + reg = <0 0xa4120000 0 0x100000>; + no-map; + }; + }; + reg_usdhc2_vmmc: regulator-usdhc2 { compatible = "regulator-fixed"; pinctrl-names = "default";
Best regards,
Krzysztof
PATCH v7 7/11 firmware: imx: add driver for NXP EdgeLock Enclave
In reply to Pankaj GuptaThe Edgelock Enclave , is the secure enclave embedded in the SoC to support the features like HSM, SHE & V2X, using message based communication channel.
ELE FW communicates on a dedicated MU with application core where kernel is running. It exists on specific i.MX processors. e.g. i.MX8ULP, i.MX93.
User-space library using this driver:
- i.MX Secure Enclave library:
-- URL: https://github.com/nxp-imx/imx-secure-enclave.git,
- i.MX Secure Middle-Ware:
-- URL: https://github.com/nxp-imx/imx-smw.git
--- Documentation/ABI/testing/se-cdev | 41 + drivers/firmware/imx/Kconfig | 12 + drivers/firmware/imx/Makefile | 2 + drivers/firmware/imx/ele_base_msg.c | 101 ++ drivers/firmware/imx/ele_common.c | 139 +++ drivers/firmware/imx/ele_common.h | 30 + drivers/firmware/imx/se_fw.c | 1308 +++++++++++++++++++++ drivers/firmware/imx/se_fw.h | 154 +++ include/linux/firmware/imx/ele_base_msg.h | 40 + include/linux/firmware/imx/ele_mu_ioctl.h | 74 ++ 10 files changed, 1901 insertions(+) create mode 100644 Documentation/ABI/testing/se-cdev create mode 100644 drivers/firmware/imx/ele_base_msg.c create mode 100644 drivers/firmware/imx/ele_common.c create mode 100644 drivers/firmware/imx/ele_common.h create mode 100644 drivers/firmware/imx/se_fw.c create mode 100644 drivers/firmware/imx/se_fw.h create mode 100644 include/linux/firmware/imx/ele_base_msg.h create mode 100644 include/linux/firmware/imx/ele_mu_ioctl.h
Documentation/ABI/testing/se-cdev new file +41 -0
@@ -0,0 +1,41 @@ +What: /dev/<se>_mu[0-9]+_ch[0-9]+ +Date: August 2023 +KernelVersion: 6.6 +Contact: [email protected], [email protected] +Description: + NXP offers multiple hardware IP(s) for secure-enclaves like EdgeLock- + Enclave(ELE), SECO. The character device file-descriptors + /dev/<se>_mu*_ch* are the interface between user-space NXP's secure- + enclave shared-library and the kernel driver. + + The ioctl(2)-based ABI is defined and documented in + [include]<linux/firmware/imx/ele_mu_ioctl.h> + ioctl(s) are used primarily for: + - shared memory management + - allocation of I/O buffers + - get mu info + - setting a dev-ctx as receiver that is slave to fw + + The following file operations are supported: + + open(2) + Currently the only useful flags are O_RDWR. + + read(2) + Every read() from the opened character device context is waiting on + wakeup_intruptible, that gets set by the registered mailbox callback + function; indicating a message received from the firmware on message- + unit. + + write(2) + Every write() to the opened character device context needs to acquire + mailbox_lock, before sending message on to the message unit. + + close(2) + Stops and free up the I/O contexts that was associated + with the file descriptor. + +Users: https://github.com/nxp-imx/imx-secure-enclave.git, + https://github.com/nxp-imx/imx-smw.git + crypto/skcipher, + drivers/nvmem/imx-ocotp-ele.c
drivers/firmware/imx/Kconfig +12 -0
@@ -28,3 +28,15 @@ config IMX_SCU_PD depends on IMX_SCU help The System Controller Firmware (SCFW) based power domain driver. + +config IMX_SEC_ENCLAVE + tristate "i.MX Embedded Secure Enclave - EdgeLock Enclave Firmware driver." + depends on IMX_MBOX && ARCH_MXC && ARM64 + default m if ARCH_MXC + + help + It is possible to use APIs exposed by the iMX Secure Enclave HW IP called: + - EdgeLock Enclave Firmware (for i.MX8ULP, i.MX93), + like base, HSM, V2X & SHE using the SAB protocol via the shared Messaging + Unit. This driver exposes these interfaces via a set of file descriptors + allowing to configure shared memory, send and receive messages.
drivers/firmware/imx/Makefile +2 -0
@@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_IMX_DSP) += imx-dsp.o obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o +sec_enclave-objs = se_fw.o ele_common.o ele_base_msg.o +obj-${CONFIG_IMX_SEC_ENCLAVE} += sec_enclave.o
drivers/firmware/imx/ele_base_msg.c new file +101 -0
101 lines not on this page · raw message
drivers/firmware/imx/ele_common.c new file +139 -0
139 lines not on this page · raw message
drivers/firmware/imx/ele_common.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2023 NXP +*/ + + +#ifndef __ELE_COMMON_H__ +#define __ELE_COMMON_H__ + +#include "se_fw.h" + +int imx_ele_msg_send_rcv (struct ele_mu_priv *priv); +void imx_se_free_tx_rx_buf (struct ele_mu_priv *priv); +int imx_se_alloc_tx_rx_buf (struct ele_mu_priv *priv); +int validate_rsp_hdr (struct ele_mu_priv *priv,unsigned int header, +uint8_t msg_id,uint8_t sz,bool is_base_api); +int plat_fill_cmd_msg_hdr (struct ele_mu_priv *priv, +struct mu_hdr *hdr, +uint8_t cmd, +uint32_t len, +bool is_base_api); +#ifdef CONFIG_IMX_ELE_TRNG +int ele_trng_init (struct device *dev); +#else +static inline int ele_trng_init (struct device *dev) +{ +return 0 ; +} +#endif +#endif
drivers/firmware/imx/se_fw.c new file +1308 -0
1,308 lines not on this page · raw message
drivers/firmware/imx/se_fw.h new file +154 -0
154 lines not on this page · raw message
include/linux/firmware/imx/ele_base_msg.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2021-2023 NXP +* +* Header file for the ELE Base API(s). +*/ + +#ifndef ELE_BASE_MSG_H +#define ELE_BASE_MSG_H + +#include <linux/types.h> + +#define WORD_SZ 4 +#define ELE_NONE_VAL 0x0 + +#define ELE_SUCCESS_IND 0xD6 + +#define ELE_GET_INFO_REQ 0xDA +#define ELE_GET_INFO_REQ_MSG_SZ 0x10 +#define ELE_GET_INFO_RSP_MSG_SZ 0x08 + +#define ELE_GET_INFO_BUFF_SZ 0x100 +#define ELE_GET_INFO_READ_SZ 0xA0 +#define DEVICE_GET_INFO_SZ 0x100 + +#define GET_INFO_SOC_INFO_WORD_OFFSET 1 +#define GET_INFO_UUID_WORD_OFFSET 3 +#define GET_INFO_SL_NUM_MSB_WORD_OFF \ + (GET_INFO_UUID_WORD_OFFSET + 3) +#define GET_INFO_SL_NUM_LSB_WORD_OFF \ + (GET_INFO_UUID_WORD_OFFSET + 0) + +#define ELE_PING_REQ 0x01 +#define ELE_PING_REQ_SZ 0x04 +#define ELE_PING_RSP_SZ 0x08 + +int ele_get_info (struct device *dev,phys_addr_t addr,u32 data_size); +int ele_ping (struct device *dev); + +#endif
include/linux/firmware/imx/ele_mu_ioctl.h new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v7 07/11] firmware: imx: add driver for NXP EdgeLock Enclave
Quoted 8 lines · Pankaj Gupta
The Edgelock Enclave , is the secure enclave embedded in the SoC to support the features like HSM, SHE & V2X, using message based communication channel.
ELE FW communicates on a dedicated MU with application core where kernel is running. It exists on specific i.MX processors. e.g. i.MX8ULP, i.MX93.
Quoted 5 lines
User-space library using this driver:
- i.MX Secure Enclave library:
-- URL: https://github.com/nxp-imx/imx-secure-enclave.git,
- i.MX Secure Middle-Ware:
-- URL: https://github.com/nxp-imx/imx-smw.git
OK, I got your patch #7. Thanks for documenting the user-space.
Quoted 2 lines
Signed-off-by Pankaj Gupta <[email protected]>
...
Quoted 14 lines
drivers/firmware/imx/ele_common.c new file +8
-0@@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2023 NXP +*/ + +#include "ele_common.h" +#include "se_fw.h" +
drivers/firmware/imx/ele_common.c line 18
Quoted 10 lines
drivers/firmware/imx/ele_common.c new file +10
-0+int imx_se_alloc_tx_rx_buf (struct ele_mu_priv *priv) +{ +int ret =0 ; + + priv->tx_msg =devm_kzalloc (priv->dev, +sizeof (*priv->tx_msg), +GFP_KERNEL ); +if (!priv->tx_msg) { + ret = -ENOMEM ; +dev_err (priv->dev,"Fail allocate mem for tx_msg.\n" );
No improvements. I assume rest of feedback could still be ignored. I am not going to check. It's your duty to implement the comments, not mine to check every line whether you did it or not. Trust does not work like that.
Best regards,
Krzysztof
PATCH v7 8/11 firmware: imx: init-fw api exchange on imx93
In reply to Pankaj GuptaOn imx93 platforms, exchange init-fw message with enclave's firmware is to be done.
--- drivers/firmware/imx/Makefile | 2 +- drivers/firmware/imx/ele_fw_api.c | 51 +++++++++++++++++++++++++++++++ drivers/firmware/imx/ele_fw_api.h | 20 ++++++++++++ drivers/firmware/imx/se_fw.c | 13 +++++++- 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 drivers/firmware/imx/ele_fw_api.c create mode 100644 drivers/firmware/imx/ele_fw_api.h
drivers/firmware/imx/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_IMX_DSP) += imx-dsp.o obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o -sec_enclave-objs = se_fw.o ele_common.o ele_base_msg.o +sec_enclave-objs = se_fw.o ele_common.o ele_base_msg.o ele_fw_api.o obj-${CONFIG_IMX_SEC_ENCLAVE} += sec_enclave.o
drivers/firmware/imx/ele_fw_api.c new file +51 -0
51 lines not on this page · raw message
drivers/firmware/imx/ele_fw_api.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2023 NXP +*/ + +#ifndef ELE_FW_API_H +#define ELE_FW_API_H + +#include <linux/hw_random.h> + +#define MESSAGING_VERSION_7 0x7 + +#define ELE_INIT_FW_REQ 0x17 +#define ELE_INIT_FW_REQ_SZ 0x04 +#define ELE_INIT_FW_RSP_SZ 0x08 + + +int ele_init_fw (struct device *dev); + +#endif /* ELE_FW_API_H */
drivers/firmware/imx/se_fw.c +12 -1
@@ -24,6 +24,7 @@#include <linux/sys_soc.h> #include "se_fw.h" +#include "ele_fw_api.h" #define SOC_ID_OF_IMX8ULP 0x084D#define SOC_ID_OF_IMX93 0x9300
@@ -46,6 +47,7 @@ struct imx_info {uint8_t *mbox_rx_name;uint8_t *pool_name;bool reserved_dma_ranges; +bool init_fw; };struct imx_info_list {
@@ -73,6 +75,7 @@ static const struct imx_info_list imx8ulp_info = { .mbox_rx_name = "rx", .pool_name = "sram", .reserved_dma_ranges = true, + .init_fw = false, }, }, };
@@ -95,8 +98,9 @@ static const struct imx_info_list imx93_info = { .mbox_rx_name = "rx", .pool_name = NULL, .reserved_dma_ranges = true, + .init_fw = true, }, - }, + }, }; static const struct of_device_id se_fw_match[] = {
@@ -1236,6 +1240,13 @@ static int se_fw_probe(struct platform_device *pdev) priv->flags |=RESERVED_DMA_POOL ; } +if (info->init_fw) { +/* start initializing ele fw */ + ret =ele_init_fw (dev); +if (ret) +dev_err (dev,"Failed to initialize ele fw.\n" ); + } +if (info->socdev) { ret =imx_soc_device_register (dev, info);if (ret) {
Signature · 1 line
2.34.1
PATCH v7 9/11 firmware: imx: enable trng
In reply to Pankaj GuptaEnabled trng on imx93 platform through enclave fw.
--- drivers/firmware/imx/Kconfig | 9 ++ drivers/firmware/imx/Makefile | 1 + drivers/firmware/imx/ele_base_msg.c | 117 ++++++++++++++++++++++ drivers/firmware/imx/ele_common.c | 40 ++++++++ drivers/firmware/imx/ele_common.h | 2 + drivers/firmware/imx/ele_fw_api.c | 67 +++++++++++++ drivers/firmware/imx/ele_fw_api.h | 6 ++ drivers/firmware/imx/ele_trng.c | 47 +++++++++ drivers/firmware/imx/se_fw.c | 21 ++++ include/linux/firmware/imx/ele_base_msg.h | 13 +++ 10 files changed, 323 insertions(+) create mode 100644 drivers/firmware/imx/ele_trng.c
drivers/firmware/imx/Kconfig +9 -0
@@ -40,3 +40,12 @@ config IMX_SEC_ENCLAVE like base, HSM, V2X & SHE using the SAB protocol via the shared Messaging Unit. This driver exposes these interfaces via a set of file descriptors allowing to configure shared memory, send and receive messages. + +config IMX_ELE_TRNG + tristate "i.MX ELE True Random Number Generator" + default y + select CRYPTO_RNG + select HW_RANDOM + help + This driver provides kernel-side support for the Random Number generation, + through NXP hardware IP for secure-enclave called EdgeLock Enclave.
drivers/firmware/imx/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-$(CONFIG_IMX_DSP) += imx-dsp.o obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o sec_enclave-objs = se_fw.o ele_common.o ele_base_msg.o ele_fw_api.o obj-${CONFIG_IMX_SEC_ENCLAVE} += sec_enclave.o +sec_enclave-${CONFIG_IMX_ELE_TRNG} += ele_trng.o
drivers/firmware/imx/ele_base_msg.c +117 -0
120 lines not on this page · raw message
drivers/firmware/imx/ele_common.c +40 -0
@@ -3,6 +3,10 @@* Copyright 2023 NXP */ +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/firmware/imx/ele_base_msg.h> +#include "ele_common.h" #include "se_fw.h"
@@ -137,3 +141,39 @@ int validate_rsp_hdr(struct ele_mu_priv *priv, unsigned int header,return ret; } + +int ele_do_start_rng (struct device *dev) +{ +int ret; +int count =ELE_GET_TRNG_STATE_RETRY_COUNT ; + + ret =ele_get_trng_state (dev); +if (ret <0 ) { +dev_err (dev,"Failed to get trng state\n" ); +return ret; + }else if (ret !=ELE_TRNG_STATE_OK ) { +/* call start rng */ + ret =ele_start_rng (dev); +if (ret) { +dev_err (dev,"Failed to start rng\n" ); +return ret; + } + +/* poll get trng state API, ELE_GET_TRNG_STATE_RETRY_COUNT times +* or while trng state != 0x203 +*/ +do { +msleep (10 ); + ret =ele_get_trng_state (dev); +if (ret <0 ) { +dev_err (dev,"Failed to get trng state\n" ); +return ret; + } + count--; + }while ((ret !=ELE_TRNG_STATE_OK ) && count); +if (ret !=ELE_TRNG_STATE_OK ) +return -EIO ; + } + +return 0 ; +}
drivers/firmware/imx/ele_common.h +2 -0
@@ -27,4 +27,6 @@ static inline int ele_trng_init(struct device *dev)return 0 ; }#endif + +int ele_do_start_rng (struct device *dev);#endif
drivers/firmware/imx/ele_fw_api.c +67 -0
70 lines not on this page · raw message
drivers/firmware/imx/ele_fw_api.h +6 -0
@@ -14,7 +14,13 @@#define ELE_INIT_FW_REQ_SZ 0x04#define ELE_INIT_FW_RSP_SZ 0x08 +#define ELE_GET_RANDOM_REQ 0xCD +#define ELE_GET_RANDOM_REQ_SZ 0x10 +#define ELE_GET_RANDOM_RSP_SZ 0x08 +int ele_init_fw (struct device *dev); +int ele_get_random (struct device *dev,void *data,size_t len); +int ele_get_hwrng (struct hwrng *rng,void *data,size_t len,bool wait);#endif /* ELE_FW_API_H */
drivers/firmware/imx/ele_trng.c new file +47 -0
47 lines not on this page · raw message
drivers/firmware/imx/se_fw.c +21 -0
@@ -24,6 +24,7 @@#include <linux/sys_soc.h> #include "se_fw.h" +#include "ele_common.h" #include "ele_fw_api.h" #define SOC_ID_OF_IMX8ULP 0x084D
@@ -48,6 +49,9 @@ struct imx_info {uint8_t *pool_name;bool reserved_dma_ranges;bool init_fw; +/* platform specific flag to enable/disable the ELE True RNG */ +bool start_rng; +bool enable_ele_trng; };struct imx_info_list {
@@ -76,6 +80,8 @@ static const struct imx_info_list imx8ulp_info = { .pool_name = "sram", .reserved_dma_ranges = true, .init_fw = false, + .start_rng = true, + .enable_ele_trng = false, }, }, };
@@ -99,6 +105,8 @@ static const struct imx_info_list imx93_info = { .pool_name = NULL, .reserved_dma_ranges = true, .init_fw = true, + .start_rng = true, + .enable_ele_trng = true, }, }, };
@@ -1260,6 +1268,19 @@ static int se_fw_probe(struct platform_device *pdev)if (ret)dev_err (dev,"Failed[%d] to ping the fw.\n" , ret); +/* start ele rng */ +if (info->start_rng) { + ret =ele_do_start_rng (dev); +if (ret) +dev_err (dev,"Failed to start ele rng\n" ); + } + +if (!ret && info->enable_ele_trng) { + ret =ele_trng_init (dev); +if (ret) +dev_err (dev,"Failed to init ele-trng\n" ); + } +dev_info (dev,"i.MX secure-enclave: %s interface to firmware, configured.\n" , info->pdev_name[1 ]);
include/linux/firmware/imx/ele_base_msg.h +13 -0
@@ -34,7 +34,20 @@#define ELE_PING_REQ_SZ 0x04#define ELE_PING_RSP_SZ 0x08 +#define ELE_START_RNG_REQ 0xA3 +#define ELE_START_RNG_REQ_MSG_SZ 0x04 +#define ELE_START_RNG_RSP_MSG_SZ 0x08 + +#define ELE_GET_TRNG_STATE_REQ 0xA4 +#define ELE_GET_TRNG_STATE_REQ_MSG_SZ 0x04 +#define ELE_GET_TRNG_STATE_RSP_MSG_SZ 0x0C +#define ELE_TRNG_STATE_OK 0x203 +#define ELE_GET_TRNG_STATE_RETRY_COUNT 0x5 +#define CSAL_TRNG_STATE_MASK 0x0000ffff +int ele_get_info (struct device *dev,phys_addr_t addr,u32 data_size);int ele_ping (struct device *dev); +int ele_start_rng (struct device *dev); +int ele_get_trng_state (struct device *dev);#endif
Signature · 1 line
2.34.1
PATCH v7 10/11 firmware: imx: enclave-fw: add handling for save/restore IMEM region
In reply to Pankaj GuptaSome IMEM region is lost during kernel power down. Due to this, firmware's functionaity cannot work correctly.
Saving encrypted IMEM region in kernel memory during power down, and restore IMEM region on resume.
--- drivers/firmware/imx/ele_base_msg.c | 53 ++++++++++ drivers/firmware/imx/ele_common.c | 115 ++++++++++++++++++++++ drivers/firmware/imx/ele_common.h | 8 ++ drivers/firmware/imx/se_fw.c | 36 +++++++ include/linux/firmware/imx/ele_base_msg.h | 14 +++ 5 files changed, 226 insertions(+)
drivers/firmware/imx/ele_base_msg.c +53 -0
@@ -216,3 +216,56 @@ int ele_start_rng(struct device *dev)return ret; } + +int ele_service_swap (struct device *dev, +phys_addr_t addr, +u32 addr_size,u16 flag) +{ +struct ele_mu_priv *priv =dev_get_drvdata (dev); +int ret; +unsigned int status; + + ret =imx_se_alloc_tx_rx_buf (priv); +if (ret) +return ret; + + ret =plat_fill_cmd_msg_hdr (priv, + (struct mu_hdr *)&priv->tx_msg->header, +ELE_SERVICE_SWAP_REQ , +ELE_SERVICE_SWAP_REQ_MSG_SZ , + true); +if (ret) +return ret; + + priv->tx_msg->data[0 ] = flag; + priv->tx_msg->data[1 ] = addr_size; + priv->tx_msg->data[2 ] =ELE_NONE_VAL ; + priv->tx_msg->data[3 ] =lower_32_bits (addr); + priv->tx_msg->data[4 ] =plat_add_msg_crc ((uint32_t *)&priv->tx_msg[0 ], +ELE_SERVICE_SWAP_REQ_MSG_SZ ); + ret =imx_ele_msg_send_rcv (priv); +if (ret <0 ) +return ret; + + ret =validate_rsp_hdr (priv, + priv->rx_msg->header, +ELE_SERVICE_SWAP_REQ , +ELE_SERVICE_SWAP_RSP_MSG_SZ , + true); +if (ret) +return ret; + + status =RES_STATUS (priv->rx_msg->data[0 ]); +if (status != priv->success_tag) { +dev_err (dev,"Command Id[%d], Response Failure = 0x%x" , +ELE_SERVICE_SWAP_REQ , status); + ret =-1 ; + }else { +if (flag ==ELE_IMEM_EXPORT ) + ret = priv->rx_msg->data[1 ]; +else + ret =0 ; + } + +return ret; +}
drivers/firmware/imx/ele_common.c +115 -0
124 lines not on this page · raw message
drivers/firmware/imx/ele_common.h +8 -0
@@ -9,6 +9,7 @@#include "se_fw.h" +uint32_t plat_add_msg_crc (uint32_t *msg,uint32_t msg_len);int imx_ele_msg_send_rcv (struct ele_mu_priv *priv);void imx_se_free_tx_rx_buf (struct ele_mu_priv *priv);int imx_se_alloc_tx_rx_buf (struct ele_mu_priv *priv);
@@ -29,4 +30,11 @@ static inline int ele_trng_init(struct device *dev)#endif int ele_do_start_rng (struct device *dev); + +#ifdef CONFIG_PM_SLEEP +int save_imem (struct device *dev); +int restore_imem (struct device *dev, +uint8_t *pool_name);#endif + +#endif /*__ELE_COMMON_H__ */
drivers/firmware/imx/se_fw.c +36 -0
@@ -52,6 +52,7 @@ struct imx_info {/* platform specific flag to enable/disable the ELE True RNG */ bool start_rng;bool enable_ele_trng; +bool imem_mgmt; };struct imx_info_list {
@@ -82,6 +83,7 @@ static const struct imx_info_list imx8ulp_info = { .init_fw = false, .start_rng = true, .enable_ele_trng = false, + .imem_mgmt = true, }, }, };
@@ -107,6 +109,7 @@ static const struct imx_info_list imx93_info = { .init_fw = true, .start_rng = true, .enable_ele_trng = true, + .imem_mgmt = false, }, }, };
@@ -1062,6 +1065,17 @@ static int se_probe_cleanup(struct platform_device *pdev)if (priv->rx_chan)mbox_free_channel (priv->rx_chan); +/* free the buffer in ele-mu remove, previously allocated +* in ele-mu probe to store encrypted IMEM +*/ +if (priv->imem.buf) { +dmam_free_coherent (&pdev->dev, +ELE_IMEM_SIZE , + priv->imem.buf, + priv->imem.phyaddr); + priv->imem.buf =NULL ; + } +if (priv->flags &RESERVED_DMA_POOL ) {of_reserved_mem_device_release (dev); priv->flags &= (~RESERVED_DMA_POOL );
@@ -1281,6 +1295,18 @@ static int se_fw_probe(struct platform_device *pdev)dev_err (dev,"Failed to init ele-trng\n" ); } +if (info->imem_mgmt) { +/* allocate buffer where ELE store encrypted IMEM */ + priv->imem.buf =dmam_alloc_coherent (dev,ELE_IMEM_SIZE , + &priv->imem.phyaddr, +GFP_KERNEL ); +if (!priv->imem.buf) { +dev_err (dev, +"dmam-alloc-failed: To store encr-IMEM.\n" ); + ret = -ENOMEM ; + goto exit; + } + }dev_info (dev,"i.MX secure-enclave: %s interface to firmware, configured.\n" , info->pdev_name[1 ]);
@@ -1303,17 +1329,27 @@ static int se_fw_remove(struct platform_device *pdev)#ifdef CONFIG_PM_SLEEP static int se_fw_suspend (struct device *dev) { +struct ele_mu_priv *priv =dev_get_drvdata (dev); +const struct imx_info *info = priv->info; + +if (info && info->imem_mgmt) + priv->imem.size =save_imem (dev); +return 0 ; }static int se_fw_resume (struct device *dev) {struct ele_mu_priv *priv =dev_get_drvdata (dev); +const struct imx_info *info = priv->info;int i;for (i =0 ; i < priv->max_dev_ctx; i++)wake_up_interruptible (&priv->ctxs[i]->wq); +if (info && info->imem_mgmt) +restore_imem (dev, info->pool_name); +return 0 ; }#endif
include/linux/firmware/imx/ele_base_msg.h +14 -0
@@ -45,9 +45,23 @@#define ELE_GET_TRNG_STATE_RETRY_COUNT 0x5#define CSAL_TRNG_STATE_MASK 0x0000ffff +#define ELE_SERVICE_SWAP_REQ 0xDF +#define ELE_SERVICE_SWAP_REQ_MSG_SZ 0x18 +#define ELE_SERVICE_SWAP_RSP_MSG_SZ 0x0C +#define ELE_IMEM_SIZE 0x10000 +#define ELE_IMEM_STATE_OK 0xCA +#define ELE_IMEM_STATE_BAD 0xFE +#define ELE_IMEM_STATE_WORD 0x27 +#define ELE_IMEM_STATE_MASK 0x00ff0000 +#define ELE_IMEM_EXPORT 0x1 +#define ELE_IMEM_IMPORT 0x2 +int ele_get_info (struct device *dev,phys_addr_t addr,u32 data_size);int ele_ping (struct device *dev);int ele_start_rng (struct device *dev);int ele_get_trng_state (struct device *dev); +int ele_service_swap (struct device *dev, +phys_addr_t addr, +u32 addr_size,u16 flag);#endif
Signature · 1 line
2.34.1
PATCH v7 11/11 MAINTAINERS: Added maintainer details
In reply to Pankaj GuptaMAINTAINERS: Added maintainer details for se-fw driver.
--- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
@@ -13758,6 +13758,16 @@ F: mm/ F: tools/mm/ F: tools/testing/selftests/mm/ +NXP EDGELOCK(SECURE) ENCLAVE FIRMWARE DRIVER +M: Pankaj Gupta <[email protected]> +R: NXP Linux Team <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/arm/freescale/fsl,se-fw.yaml +F: drivers/firmware/imx/ele*.* +F: drivers/firmware/imx/se*.* +F: include/linux/firmware/imx/ele*.* + MEMORY TECHNOLOGY DEVICES (MTD) M: Miquel Raynal <[email protected]> M: Richard Weinberger <[email protected]>
Signature · 1 line
2.34.1
Hi all,
We took a step back.
We are doing internal review ongoing on this patch-set.
Thanks everybody helping me improving the patch series. Thanks. Krzysztof for your guidance for the entire patch-set.
Regards
Pankaj
Quoted 205 lines
-----Original Message-----
From: Pankaj Gupta <[email protected]>
Sent: Monday, October 30, 2023 3:29 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Gaurav Jain <[email protected]>; [email protected]; Varun Sethi <[email protected]>
Cc: Pankaj Gupta <[email protected]>
Subject: [PATCH v7 00/11] firmware: imx: NXP Secure-Enclave FW DriverV7 Changes:
- 2/11 DT Binding: Disposed off comments from .yaml
-- added | to preserve formating.
-- removed extra spaces, restricting under 80 col.
-- replaced the "fsl,sram" property, with standard property "sram". -- Added details about usage of sram.
-- removed the property "mu_id".
-- Added allOf:if:then: for reserved memory.
-- removed label.- 3,4,5,6/11: DTSI changes:
-- removed the property "mu_id".
-- rename node-name & label- 7/11 firmware: imx: add driver for NXP EdgeLock Enclave:
-- Removeddev_errfor the cases of failure in memory allocation. -- For others, coverteddev_errtodev_dbg.
-- Updated the commit msg about the details for userspace libV6 Changes:
- 1/11 (New): Kernel doc: "
Documentation/driver-api/firmware/other_interfaces.rst" is added.- 2/11 DT Binding: Disposed off comments from .yaml
-- replaced the "sram-pool" property, with standard property
"fsl,sram".
-- removed the additional details from the description.- 3,4,5,6/11: DTSI changes:
-- Validated using the following commands: --- make dt_binding_check DT_SCHEMA_FILES=freescale --- make CHECK_DTBS=y freescale/imx8ulp-evk.dtb; make CHECK_DTBS=y freescale/imx93-11x11-evk.dtb- 7/11 firmware: imx: add driver for NXP EdgeLock Enclave:
-- Removed: Reported-by: kernel test robot <[email protected]> Closes:https://lore.kernel.org/oe-kbuild-all/[email protected]
--pr_infois removed.
-- macro "devctx_info", "devctx_dbg" & "devctx_err" is removed. -- Updated ABI:
--- Users: user-space SE-LIB, crypto-api, imx-ocotp-ele driver , smw
--- IOCTLS: Updated the ioctl
--- read/write:
-- Correct message header validation.
--- segregated handling of the error, while msg header parsing.
-- removed TX and RX messages static allocation in state container. -- ran coccicheck: make C=1 CHECK=scripts/coccicheckdrivers/firmware/imx/*.*W=1
--- ran on all the patches.
- 8/11 firmware: imx: init-fw api exchange on imx93
-- removed TX and RX messages static allocation in state container. -- moved the header fileele_fw_api.h, to driver/firmware/imx/ -- segregated handling of the error, while msg header parsing.- 9/11 firmware: imx: enable trng
-- macro "devctx_info", "devctx_dbg" & "devctx_err" is removed. -- will remove this patch, will send this patch later, including RNG and
crypto-maintainers.- 10/11 firmware: imx: enclave-fw: add handling for save/restore IMEM region -- Linux comment style fixed.
- 10/11(old)(Removed) firmware: imx: enclave api to read-common-fuses -- This API will be used by
imx-ocotp-ele.c.
-- This patch can be sent later, when the changes toimx-ocotp-ele.c
will be sent.
-- "Documentation/driver-api/firmware/other_interfaces.rst" will be
update for the exported symbols:
-read_common_fuses()
-get_se_dev()v5 Changes:
- 1/7 DT Binding: Disposed off comments from .yaml
-- to use "-", instead of "_".
-- to use generic name, concatinated with soc-id.
-- removed mu-did.
-- renamed the ele-mu to se-fw
-- moved the file from .../arm/freescale/ to .../firmware/
- 2/7 Changed the .dtsi, as per the comments.
-- removed mu-did
-- renamed theele_muto se-fw.
-- updated the compatible string.
-- tested the DTB.
- 4/7 Changed the .dtsi, as per the comments.
-- removed mu-did
-- renamed theele_muto se-fw.
-- updated the compatible string.
-- tested the DTB.
- 6/7 Changes in driver code:
-- replacepr_errwithdev_err
-- removed export symbols, except one, which will be used in other
driver.
-- Each API, send-recived based on device reference. -- Divided the commits into smaller commits.
- Base Driver
-- Added ABI file.
- 7/11 (new) firmware: imx: init-fw api exchange on imx93
- 8/11 (new) firmware: imx: enable trng
- 9/11 (new) firmware: imx: enclave-fw: add handling for
save/restore IMEM region
- 10/11 (new) firmware: imx: enclave api to read-common-
fusesv4 Changes:
- Post internal review, changed the name from "ele-mu" to "se-fw".
- Disposed-off comments in the dt-binding file.
- Removed the non-hw related dt-bindings from the driver code.
- Corrected the FileMAINTAINERSfor correct name of yaml file.v3 Changes:
- update the commit message for documentation.
- Fixed dt-binding checking error for file- fsl,ele_mu.yaml
- Coverity fixes in theele_mu.cv2 Changes:
- Fixed Kernel Test Bot issues.
- Removed ".../devicetree/bindings/mailbox/fsl,muap.txt"The NXP's i.MX EdgeLock Enclave, a HW IP creating an embedded secure enclave within the SoC boundary to enable features like
- HSM
- SHE
- V2XCommunicates via message unit with linux kernel. This driver is enables communication ensuring well defined message sequence protocol between Application Core and enclave's firmware.
Driver configures multiple misc-device on the MU, for multiple user-space applications can communicate on single MU.
It exists on some i.MX processors. e.g. i.MX8ULP, i.MX93 etc.
Pankaj Gupta (11):
Documentation/firmware: added imx/se-fw toother_interfaces
dt-bindings: arm: fsl: add imx-se-fw binding doc
arm64: dts: imx8ulp-evk: added nxp secure enclave firmware
arm64: dts: imx8ulp-evk: reserved mem-ranges to constrainele_fw
dma-range
arm64: dts: imx93-11x11-evk: added nxp secure enclave fw
arm64: dts: imx93-11x11-evk: reserved mem-ranges
firmware: imx: add driver for NXP EdgeLock Enclave
firmware: imx: init-fw api exchange on imx93
firmware: imx: enable trng
firmware: imx: enclave-fw: add handling for save/restore IMEM region
MAINTAINERS: Added maintainer detailsDocumentation/ABI/testing/se-cdev | 41 + .../bindings/firmware/fsl,imx-se-fw.yaml | 83 + .../driver-api/firmware/other_interfaces.rst | 67 + MAINTAINERS | 10 + arch/arm64/boot/dts/freescale/imx8ulp-evk.dts | 15 + arch/arm64/boot/dts/freescale/imx8ulp.dtsi | 10 +- .../boot/dts/freescale/imx93-11x11-evk.dts | 15 + arch/arm64/boot/dts/freescale/imx93.dtsi | 8 +- drivers/firmware/imx/Kconfig | 21 + drivers/firmware/imx/Makefile | 3 + drivers/firmware/imx/ele_base_msg.c | 271 ++++ drivers/firmware/imx/ele_common.c | 294 ++++ drivers/firmware/imx/ele_common.h | 40 + drivers/firmware/imx/ele_fw_api.c | 118 ++ drivers/firmware/imx/ele_fw_api.h | 26 + drivers/firmware/imx/ele_trng.c | 47 + drivers/firmware/imx/se_fw.c | 1376 +++++++++++++++++ drivers/firmware/imx/se_fw.h | 154 ++ include/linux/firmware/imx/ele_base_msg.h | 67 + include/linux/firmware/imx/ele_mu_ioctl.h | 74 + 20 files changed, 2738 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/se-cdev create mode 100644 Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml create mode 100644 drivers/firmware/imx/ele_base_msg.c create mode 100644 drivers/firmware/imx/ele_common.c create mode100644
drivers/firmware/imx/ele_common.hcreate mode 100644drivers/firmware/imx/ele_fw_api.ccreate mode 100644drivers/firmware/imx/ele_fw_api.hcreate mode 100644drivers/firmware/imx/ele_trng.ccreate mode 100644drivers/firmware/imx/se_fw.ccreate mode 100644drivers/firmware/imx/se_fw.hcreate mode 100644include/linux/firmware/imx/ele_base_msg.hcreate mode 100644 include/linux/firmware/imx/ele_mu_ioctl.h--
2.34.1