firmware: imx: NXP Secure-Enclave FW Driver
Subsystems (2)
v5 cover firmware: imx: NXP Secure-Enclave FW Driver
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.
- exchange init-fw message with enclave's fw
- enabled TRNG
- 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):
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 to constrain ele_fw
dma-range
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
firmware: imx: enclave api to read-common-fuses
MAINTAINERS: Added maintainer details
Documentation/ABI/testing/se-cdev | 29 + .../bindings/firmware/fsl,imx-se-fw.yaml | 121 ++ MAINTAINERS | 10 + arch/arm64/boot/dts/freescale/imx8ulp-evk.dts | 15 + arch/arm64/boot/dts/freescale/imx8ulp.dtsi | 11 +- .../boot/dts/freescale/imx93-11x11-evk.dts | 15 + arch/arm64/boot/dts/freescale/imx93.dtsi | 10 +- drivers/firmware/imx/Kconfig | 21 + drivers/firmware/imx/Makefile | 3 + drivers/firmware/imx/ele_base_msg.c | 272 ++++ drivers/firmware/imx/ele_common.c | 188 +++ drivers/firmware/imx/ele_common.h | 31 + drivers/firmware/imx/ele_fw_api.c | 110 ++ drivers/firmware/imx/ele_trng.c | 48 + drivers/firmware/imx/se_fw.c | 1274 +++++++++++++++++ drivers/firmware/imx/se_fw.h | 176 +++ include/linux/firmware/imx/ele_base_msg.h | 66 + include/linux/firmware/imx/ele_fw_api.h | 24 + include/linux/firmware/imx/ele_mu_ioctl.h | 52 + 19 files changed, 2474 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_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_fw_api.h create mode 100644 include/linux/firmware/imx/ele_mu_ioctl.h
Signature · 1 line
2.34.1
PATCH v5 1/11 dt-bindings: arm: fsl: add imx-se-fw binding doc
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.
--- .../bindings/firmware/fsl,imx-se-fw.yaml | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +121 -0
@@ -0,0 +1,121 @@ +# 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. + + 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 + | + | + +---------+ +-------------+ | + | ele_mu.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. + + A user can be registered as receiver of command from the ELE. + Create char devices in /dev as channels of the form /dev/ele_muXchY with X + the id of the driver and Y for each users. It allows to send and receive + messages to the NXP EdgeLock Enclave IP firmware on NXP SoC, where current + possible value, i.e., supported SoC(s) are imx8ulp, imx93. + +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 + + fsl,mu-did: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + By design, Domain is a clean separated processing island with separate power, + clocking and peripheral; but with a tightly integrated bus fabric for efficient + communication. The Domain to which this message-unit is associated, is identified + via Domain ID or did. + + sram-pool: + items: + - description: SRAM memory instance. + + memory-region: + items: + - description: Reserved memory region that can be accessed by firmware. Used for + exchanging the buffers between driver and firmware. + +required: + - compatible + - mboxes + - mbox-names + - mu-id + +additionalProperties: false + +examples: + - | + ele_fw: se-fw { + compatible = "fsl,imx8ulp-se-fw"; + mbox-names = "tx", "rx"; + mboxes = <&s4muap 0 0>, <&s4muap 1 0>; + fsl,mu-id = <2>; + };
Signature · 1 line
2.34.1
Rob Herring
maintainerRe: [PATCH v5 01/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 | 121 ++++++++++++++++++ 1 file changed, 121 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/firmware/fsl,imx-se-fw.example.dtb: se-fw: 'mu-id' is a required property
from schema $id: http://devicetree.org/schemas/firmware/fsl,imx-se-fw.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.example.dtb: se-fw: 'fsl,mu-id' does not match any of the regexes: 'pinctrl-[0-9]+'
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.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RE: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
Quoted 103 lines
-----Original Message-----
From: Rob Herring <[email protected]>
Sent: Wednesday, August 23, 2023 1:59 PM
To: Pankaj Gupta <[email protected]>
Cc: [email protected]; Bough Chen <[email protected]>; [email protected]; Peng Fan <[email protected]>; [email protected]; Varun Sethi <[email protected]>; Sahil Malhotra <[email protected]>; [email protected]; [email protected]; [email protected]; Gaurav Jain <[email protected]>; dl-linux-imx <[email protected]>; [email protected]; Jacky Bai <[email protected]>; [email protected]; Aisheng Dong <[email protected]>; Clark Wang <[email protected]>; [email protected]; [email protected]; Wei Fang <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding docCaution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
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 9 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 | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yamlMy bot found errors running 'make DT_CHECKER_FLAGS=-m
dt_binding_check'
on your patch (DT_CHECKER_FLAGSis new in v5.13):yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review- ci/linux/Documentation/devicetree/bindings/firmware/fsl,imx-se- fw.example.dtb: se-fw: 'mu-id' is a required property
from schema $id:
https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdevicetr
ee.org%2Fschemas%2Ffirmware%2Ffsl%2Cimx-se- fw.yaml%23&data=05%7C01%7Cpankaj.gupta%40nxp.com%7C7e28c89d24c6 4b9c000108dba3b2f2d0%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7 C0%7C638283761210875688%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4 wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C %7C%7C&sdata=SFldwBvByjOkEf%2FlzBmMJ3oZI9cBdWJe1ZmSh2AsflA%3D&r eserved=0
/builds/robherring/dt-review- ci/linux/Documentation/devicetree/bindings/firmware/fsl,imx-se- fw.example.dtb: se-fw: 'fsl,mu-id' does not match any of the regexes: 'pinctrl- [0-9]+'
from schema $id:
https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdevicetr
ee.org%2Fschemas%2Ffirmware%2Ffsl%2Cimx-se- fw.yaml%23&data=05%7C01%7Cpankaj.gupta%40nxp.com%7C7e28c89d24c6 4b9c000108dba3b2f2d0%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7 C0%7C638283761210875688%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4 wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C %7C%7C&sdata=SFldwBvByjOkEf%2FlzBmMJ3oZI9cBdWJe1ZmSh2AsflA%3D&r eserved=0doc reference errors (make refcheckdocs):
See
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchw
ork.ozlabs.org%2Fproject%2Fdevicetree- bindings%2Fpatch%2F20230823073330.1712721-2- pankaj.gupta%40nxp.com&data=05%7C01%7Cpankaj.gupta%40nxp.com%7C7 e28c89d24c64b9c000108dba3b2f2d0%7C686ea1d3bc2b4c6fa92cd99c5c30 1635%7C0%7C0%7C638283761210875688%7CUnknown%7CTWFpbGZsb3d8 eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D %7C3000%7C%7C%7C&sdata=afDClssaony%2B7aLwRX8VWJ1QyPrfZJJnEOcyU LYxR4g%3D&reserved=0The 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:
Quoted 5 lines
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that
DT_SCHEMA_FILEScan be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Accepted.
Re-submitting the patch V6 by end of this, after fixing it.
Rob Herring
maintainerRe: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
In reply to Pankaj GuptaQuoted 10 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.
Quoted 7 lines
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]>---
v5? Where's the changelog for *this* patch?
Quoted 67 lines
.../bindings/firmware/fsl,imx-se-fw.yaml | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yamlDocumentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +57
-0@@ -0,0 +1,121 @@ +# 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. + + 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 + | + | + +---------+ +-------------+ | + | ele_mu.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 |
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 67
Quoted 10 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +10
-0+ | + + When a user sends a command to the firmware, it registers its device_ctx + as waiter of a response from firmware. + + A user can be registered as receiver of command from the ELE. + Create char devices in /dev as channels of the form /dev/ele_muXchY with X + the id of the driver and Y for each users. It allows to send and receive + messages to the NXP EdgeLock Enclave IP firmware on NXP SoC, where current + possible value, i.e., supported SoC(s) are imx8ulp, imx93.
Looks like a bunch of Linux details which don't belong in the binding.
Why do you need your own custom interface to userspace? No one else has a similar feature in their platforms? Something like virtio or rpmsg doesn't work?
Quoted 20 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +20
-0+ +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
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 97
Quoted 10 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +10
-0+ + fsl,mu-did: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + By design, Domain is a clean separated processing island with separate power, + clocking and peripheral; but with a tightly integrated bus fabric for efficient + communication. The Domain to which this message-unit is associated, is identified + via Domain ID or did. + + sram-pool:
I believe 'sram' is the somewhat standard property to refer to an SRAM region.
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 99
Quoted 2 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +2
-0+ items: + - description: SRAM memory instance.
Used for what?
Quoted 25 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +22
-0+ + memory-region: + items: + - description: Reserved memory region that can be accessed by firmware. Used for + exchanging the buffers between driver and firmware. + +required: + - compatible + - mboxes + - mbox-names + - mu-id + +additionalProperties: false + +examples: + - | + ele_fw: se-fw { + compatible = "fsl,imx8ulp-se-fw"; + mbox-names = "tx", "rx"; + mboxes = <&s4muap 0 0>, <&s4muap 1 0>; + fsl,mu-id = <2>; + };Signature · 1 line
2.34.1
Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
Quoted 19 lines · Rob Herring
Quoted 6 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +6
-0+ | + +------------------------------------------------------ | + | | | | + userspace /dev/ele_muXch0 | | | + /dev/ele_muXch1 | | + /dev/ele_muXchY |Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 67
Quoted 10 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +10
-0+ | + + When a user sends a command to the firmware, it registers its device_ctx + as waiter of a response from firmware. + + A user can be registered as receiver of command from the ELE. + Create char devices in /dev as channels of the form /dev/ele_muXchY with X + the id of the driver and Y for each users. It allows to send and receive + messages to the NXP EdgeLock Enclave IP firmware on NXP SoC, where current + possible value, i.e., supported SoC(s) are imx8ulp, imx93.Looks like a bunch of Linux details which don't belong in the binding.
Quoted 3 lines
Why do you need your own custom interface to userspace? No one else has a similar feature in their platforms? Something like virtio or rpmsg doesn't work?
+Cc Greg,
I doubt they care. This is some stub-driver to pass messages from user-space to the firmware. The interface is undocumented, without examples and no user-space user.
Best regards,
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
A message that is not in the archive (sent off-list or not yet received): DU2PR04MB86302A2639CA64D8DF08BF0495E3A@DU2PR04MB8630.eurprd04.prod.outlook.com
RE: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
Please find comments inline.
Regards
Varun
Quoted 59 lines
-----Original Message-----
From: Pankaj Gupta <[email protected]>
Sent: Friday, August 25, 2023 12:56 PM
To: Varun Sethi <[email protected]>
Subject: FW: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Friday, August 25, 2023 12:16 AM
To: Rob Herring <[email protected]>; Pankaj Gupta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jacky Bai <[email protected]>; Clark Wang <[email protected]>; Wei Fang <[email protected]>; Peng Fan <[email protected]>; Bough Chen <[email protected]>; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; linux- [email protected]; Gaurav Jain <[email protected]>; [email protected]; Sahil Malhotra <[email protected]>; Aisheng Dong <[email protected]>; Varun Sethi <[email protected]>; Greg Kroah-Hartman <[email protected]>
Subject: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding docCaution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
Quoted 8 lines · Rob Herring
Quoted 8 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +8
-0+ | + +------------------------------------------------------ | + | | | | + userspace /dev/ele_muXch0 | | | + /dev/ele_muXch1 | | + /dev/ele_muXchY | + | +Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ When a user sends a command to the firmware, it registers its + device_ctx as waiter of a response from firmware. + + A user can be registered as receiver of command from the ELE. + Create char devices in /dev as channels of the form + /dev/ele_muXchY with X the id of the driver and Y for each users. + It allows to send and receive messages to the NXP EdgeLock Enclave + IP firmware on NXP SoC, where current possible value, i.e., supportedSoC(s) are imx8ulp, imx93.
Quoted 6 lines
Looks like a bunch of Linux details which don't belong in the binding.
Why do you need your own custom interface to userspace? No one else has a similar feature in their platforms? Something like virtio or rpmsg doesn't work?
Quoted 8 lines
+Cc Greg,
I doubt they care. This is some stub-driver to pass messages from user-space to the firmware. The interface is undocumented, without examples and no user-space user.
Best regards,
Krzysztof
[Varun] The goal of the driver is to pass messages between firmware and user space/kernel consumers.
At the same time driver also enables firmware to use the storage via Linux user space. We do have
middleware applications that utilize the driver. These applications leverage cryptographic operations and trust
provisioning capabilities offered by the firmware. We can provide references to the middleware applications in the next
version of the patch. We do plan to enable the kernel crypto API interface to leverage operations provided by the firmware.
The operations that are exposed by the firmware are performance-sensitive and session-based (thus serialized). So, the Virtio/rpmsg model
is not suited for our implementation. Also, the secure enclave IP, with which the driver facilitates the communication is an opaque block
that doesn't fit the rpmsg model.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
In reply to Krzysztof KozlowskiQuoted 24 lines · Krzysztof Kozlowski
Quoted 19 lines · Rob Herring
Quoted 6 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +6
-0+ | + +------------------------------------------------------ | + | | | | + userspace /dev/ele_muXch0 | | | + /dev/ele_muXch1 | | + /dev/ele_muXchY |Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml line 67
Quoted 10 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +10
-0+ | + + When a user sends a command to the firmware, it registers its device_ctx + as waiter of a response from firmware. + + A user can be registered as receiver of command from the ELE. + Create char devices in /dev as channels of the form /dev/ele_muXchY with X + the id of the driver and Y for each users. It allows to send and receive + messages to the NXP EdgeLock Enclave IP firmware on NXP SoC, where current + possible value, i.e., supported SoC(s) are imx8ulp, imx93.Looks like a bunch of Linux details which don't belong in the binding.
Quoted 3 lines
Why do you need your own custom interface to userspace? No one else has a similar feature in their platforms? Something like virtio or rpmsg doesn't work?
Quoted 5 lines
+Cc Greg,
I doubt they care. This is some stub-driver to pass messages from user-space to the firmware. The interface is undocumented, without examples and no user-space user.
Great, no user? Let's delete the code then :)
thanks,
greg k-h
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RE: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
Hi Greg,
Quoted 20 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Friday, August 25, 2023 12:54 AM
To: Krzysztof Kozlowski <[email protected]>
Cc: Rob Herring <[email protected]>; Pankaj Gupta <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jacky Bai <[email protected]>; Clark Wang <[email protected]>; Wei Fang <[email protected]>; Peng Fan <[email protected]>; Bough Chen <[email protected]>; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; linux- [email protected]; Gaurav Jain <[email protected]>; [email protected]; Sahil Malhotra <[email protected]>; Aisheng Dong <[email protected]>; Varun Sethi <[email protected]>
Subject: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
Quoted 1 line
Caution: This is an external email. Please take care when clicking links
or
Quoted 30 lines
opening attachments. When in doubt, report the message using the 'Report this email' button
Quoted 17 lines · Krzysztof Kozlowski
Quoted 8 lines · Rob Herring
Quoted 8 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +8
-0+ | + +------------------------------------------------------ | + | | | | + userspace /dev/ele_muXch0 | | | + /dev/ele_muXch1 | | + /dev/ele_muXchY | + | +Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ When a user sends a command to the firmware, it registers its + device_ctx as waiter of a response from firmware. + + A user can be registered as receiver of command from the ELE. + Create char devices in /dev as channels of the form + /dev/ele_muXchY with X the id of the driver and Y for each + users. It allows to send and receive messages to the NXP + EdgeLock Enclave IP firmware on NXP SoC, where current possiblevalue, i.e., supported SoC(s) are imx8ulp, imx93.
Quoted 7 lines
Quoted 6 lines
Looks like a bunch of Linux details which don't belong in the binding.
Why do you need your own custom interface to userspace? No one else has a similar feature in their platforms? Something like virtio or rpmsg doesn't work?
Quoted 8 lines
Quoted 5 lines
+Cc Greg,
I doubt they care. This is some stub-driver to pass messages from user-space to the firmware. The interface is undocumented, without examples and no user-space user.
Great, no user? Let's delete the code then :)
[Varun] We do have middleware applications that utilize the driver. Following
are the links:
https://github.com/nxp-imx/imx-secure-enclave
https://github.com/nxp-imx/imx-smw
Also, we plan to enable the kernel crypto API interface to leverage operations provided by the firmware.
Regards
Varun
Re: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
Quoted 60 lines · Varun Sethi
Hi Greg,
Quoted 20 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Friday, August 25, 2023 12:54 AM
To: Krzysztof Kozlowski <[email protected]>
Cc: Rob Herring <[email protected]>; Pankaj Gupta <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jacky Bai <[email protected]>; Clark Wang <[email protected]>; Wei Fang <[email protected]>; Peng Fan <[email protected]>; Bough Chen <[email protected]>; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; linux- [email protected]; Gaurav Jain <[email protected]>; [email protected]; Sahil Malhotra <[email protected]>; Aisheng Dong <[email protected]>; Varun Sethi <[email protected]>
Subject: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding docQuoted 1 line
Caution: This is an external email. Please take care when clicking links
or
Quoted 36 lines
opening attachments. When in doubt, report the message using the 'Report this email' button
Quoted 17 lines · Krzysztof Kozlowski
Quoted 8 lines · Rob Herring
Quoted 8 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +8
-0+ | + +------------------------------------------------------ | + | | | | + userspace /dev/ele_muXch0 | | | + /dev/ele_muXch1 | | + /dev/ele_muXchY | + | +Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ When a user sends a command to the firmware, it registers its + device_ctx as waiter of a response from firmware. + + A user can be registered as receiver of command from the ELE. + Create char devices in /dev as channels of the form + /dev/ele_muXchY with X the id of the driver and Y for each + users. It allows to send and receive messages to the NXP + EdgeLock Enclave IP firmware on NXP SoC, where current possiblevalue, i.e., supported SoC(s) are imx8ulp, imx93.
Quoted 12 lines
Quoted 6 lines
Looks like a bunch of Linux details which don't belong in the binding.
Why do you need your own custom interface to userspace? No one else has a similar feature in their platforms? Something like virtio or rpmsg doesn't work?
+Cc Greg,
I doubt they care. This is some stub-driver to pass messages from user-space to the firmware. The interface is undocumented, without examples and no user-space user.
Quoted 8 lines
Quoted 2 lines
Great, no user? Let's delete the code then :)
[Varun] We do have middleware applications that utilize the driver. Following
are the links:
https://github.com/nxp-imx/imx-secure-enclave
https://github.com/nxp-imx/imx-smw
Why this is not explained in the cover letter and in the patch adding the interfaces? You still need to document and explain the interface.
Best regards,
Krzysztof
RE: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc
Hi Krzysztof,
Quoted 10 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Monday, August 28, 2023 12:25 PM
To: Varun Sethi <[email protected]>; Greg Kroah-Hartman <[email protected]>; Krzysztof Kozlowski <[email protected]>
Cc: Rob Herring <[email protected]>; Pankaj Gupta <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jacky Bai <[email protected]>; Clark Wang <[email protected]>; Wei Fang <[email protected]>; Peng Fan
Quoted 8 lines
<[email protected]>; Bough Chen <[email protected]>; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; linux- [email protected]; Gaurav Jain <[email protected]>; [email protected]; Sahil Malhotra <[email protected]>; Aisheng Dong <[email protected]>
Subject: Re: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add
imx-se-fw
Quoted 3 lines
binding doc
Caution: This is an external email. Please take care when clicking links
or
Quoted 24 lines
opening attachments. When in doubt, report the message using the 'Report this email' button
Quoted 8 lines · Varun Sethi
Hi Greg,
Quoted 6 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Friday, August 25, 2023 12:54 AM
To: Krzysztof Kozlowski <[email protected]>
Cc: Rob Herring <[email protected]>; Pankaj Gupta <[email protected]>; [email protected];Quoted 10 lines
Quoted 10 lines
[email protected]; [email protected]; [email protected]; [email protected]; Jacky Bai <[email protected]>; Clark Wang <[email protected]>; Wei Fang <[email protected]>; Peng Fan <[email protected]>; Bough Chen <[email protected]>; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; linux- [email protected]; Gaurav Jain <[email protected]>; [email protected]; Sahil Malhotra <[email protected]>; Aisheng Dong <[email protected]>;
Quoted 33 lines
Varun
Quoted 32 lines
Quoted 6 lines
Sethi <[email protected]>
Subject: [EXT] Re: [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding docCaution: This is an external email. Please take care when clicking links
or
Quoted 25 lines
opening attachments. When in doubt, report the message using the 'Report this email' button
Quoted 17 lines · Krzysztof Kozlowski
Quoted 8 lines · Rob Herring
Quoted 8 lines
Documentation/devicetree/bindings/firmware/fsl,imx-se-fw.yaml new file +8
-0+ | + +------------------------------------------------------ | + | | | | + userspace /dev/ele_muXch0 | | | + /dev/ele_muXch1 | | + /dev/ele_muXchY | + | +Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ When a user sends a command to the firmware, it registers its + device_ctx as waiter of a response from firmware. + + A user can be registered as receiver of command from the ELE. + Create char devices in /dev as channels of the form + /dev/ele_muXchY with X the id of the driver and Y for each + users. It allows to send and receive messages to the NXP + EdgeLock Enclave IP firmware on NXP SoC, where current possiblevalue, i.e., supported SoC(s) are imx8ulp, imx93.
Quoted 2 lines
Quoted 2 lines
Looks like a bunch of Linux details which don't belong in the
binding.
Quoted 40 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Why do you need your own custom interface to userspace? No one
else
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
has a similar feature in their platforms? Something like virtio or rpmsg doesn't work?
+Cc Greg,
I doubt they care. This is some stub-driver to pass messages from user-space to the firmware. The interface is undocumented, without examples and no user-space user.
Quoted 7 lines
Quoted 2 lines
Great, no user? Let's delete the code then :)
[Varun] We do have middleware applications that utilize the driver. Following
are the links:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgith
ub.com%2Fnxp-imx%2Fimx-secure-enclave&data=05%7C01%7CV.Sethi%40nxp.com
Quoted 1 line
%7Ceda172f10a684cc926a908dba793b776%7C686ea1d3bc2b4c6fa92cd99c5c
301635
Quoted 1 line
%7C0%7C0%7C638288025110398317%7CUnknown%7CTWFpbGZsb3d8eyJW
IjoiMC4wLjAw
Quoted 1 line
MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C% 7C&sda
Quoted 1 line
ta=jJ%2FZl1myldPaciswIps2dDuuzp%2BqXGZDnvh07yD%2BEFU%3D&reserve d=0
Quoted 2 lines
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgith
ub.com%2Fnxp-imx%2Fimx-smw&data=05%7C01%7CV.Sethi%40nxp.com%7Ceda172f1
Quoted 1 line
0a684cc926a908dba793b776%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7 C0%7C
Quoted 1 line
638288025110398317%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwM DAiLCJQIjo
Quoted 1 line
Quoted 8 lines
iV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=U VjBwmzZ
Quoted 2 lines
myHu%2Fmy6WZiQcz2qksA67W1BtwFIJ8%2Ft7nQ%3D&reserved=0
Why this is not explained in the cover letter and in the patch adding the interfaces? You still need to document and explain the interface.
[Varun] Following information would be added in the next version of the patchset:
1. Details of the users for this driver.
2. The ABI document would be enhanced to provide information about the interfaces leveraged
by the user space middleware applications.
Please let me know if this would be sufficient.
Regards
Varun Sethi
PATCH v5 2/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 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/freescale/imx8ulp.dtsi +10 -1
@@ -114,7 +114,7 @@ sosc: clock-sosc { #clock-cells = <0>; }; - sram@2201f000 { + sram0: sram@2201f000 { compatible = "mmio-sram"; reg = <0x0 0x2201f000 0x0 0x1000>;
@@ -507,4 +507,13 @@ 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>; + fsl,mu-id = <2>; + sram-pool = <&sram0>; + }; + };
Signature · 1 line
2.34.1
PATCH v5 3/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; + }; + }; clock_ext_rmii: clock-ext-rmii { compatible = "fixed-clock";
@@ -53,6 +64,10 @@ &usdhc0 { status = "okay"; }; +&ele_fw2 { + memory-region = <&ele_reserved>; +}; + &fec { pinctrl-names = "default", "sleep"; pinctrl-0 = <&pinctrl_enet>;
Signature · 1 line
2.34.1
PATCH v5 4/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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/freescale/imx93.dtsi +9 -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>
@@ -864,4 +864,12 @@ 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>; + fsl,mu-id = <2>; + }; };
Signature · 1 line
2.34.1
PATCH v5 5/11 arm64: dts: imx93-11x11-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:
- 0x80000000 0x9FFFFFFF
ELE-MU 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/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";
@@ -22,6 +26,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
PATCH v5 6/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.
--- Documentation/ABI/testing/se-cdev | 29 + drivers/firmware/imx/Kconfig | 12 + drivers/firmware/imx/Makefile | 2 + drivers/firmware/imx/ele_base_msg.c | 62 ++ drivers/firmware/imx/ele_common.c | 34 + drivers/firmware/imx/ele_common.h | 21 + drivers/firmware/imx/se_fw.c | 1201 +++++++++++++++++++++ drivers/firmware/imx/se_fw.h | 168 +++ include/linux/firmware/imx/ele_base_msg.h | 37 + include/linux/firmware/imx/ele_mu_ioctl.h | 52 + 10 files changed, 1618 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 +29 -0
@@ -0,0 +1,29 @@ +What: /dev/<se>_mu[0-9]+_ch[0-9]+ +Date: August 2023 +KernelVersion: 6.5 +Contact: [email protected], [email protected] +Description: + NXP offers multiple secure-enclaves like EdgeLock Enclave(ELE), SECO + The character device files /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> + + The following file operations are supported: + + open(2) + Currently the only useful flags are O_RDWR. + + ioctl(2) + Initiate various actions. + + See the inline documentation in [include]<linux/firmware/imx/ele_mu_ioctl.h> + for descriptions of all ioctls. + + close(2) + Stops and free up the I/O contexts that was associated + with the file descriptor. + +Users: TBD
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
@@ -2,3 +2,5 @@ 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 obj-$(CONFIG_IMX_SCU_PD) += scu-pd.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 +62 -0
62 lines not on this page · raw message
drivers/firmware/imx/ele_common.c new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2021-2023 NXP +*/ + +#include "se_fw.h" + +int imx_ele_msg_send_rcv (struct ele_mu_priv *priv) +{ +unsigned int wait; +int err; + +mutex_lock (&priv->mu_cmd_lock); +mutex_lock (&priv->mu_lock); + + err =mbox_send_message (priv->tx_chan, &priv->tx_msg); +if (err <0 ) { +pr_err ("Error: mbox_send_message failure.\n" ); +mutex_unlock (&priv->mu_lock); +return err; + } +mutex_unlock (&priv->mu_lock); + + wait =msecs_to_jiffies (1000 ); +if (!wait_for_completion_timeout (&priv->done, wait)) { +pr_err ("Error: wait_for_completion timed out.\n" ); + err = -ETIMEDOUT ; + } + +mutex_unlock (&priv->mu_cmd_lock); + +return err; +} +
drivers/firmware/imx/ele_common.h new file +21 -0
@@ -0,0 +1,21 @@ +/* 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); +#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 +1201 -0
1,201 lines not on this page · raw message
drivers/firmware/imx/se_fw.h new file +168 -0
168 lines not on this page · raw message
include/linux/firmware/imx/ele_base_msg.h new file +37 -0
@@ -0,0 +1,37 @@ +/* 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 MESSAGING_VERSION_7 0x7 +#define ELE_NONE_VAL 0x0 + +#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_GET_INFO_REQ 0xDA +#define ELE_GET_INFO_REQ_MSG_SZ 0x02 + +#define ELE_BASE_API_VERSION 0x6 +#define ELE_SUCCESS_IND 0xD6 +#define ELE_FAILURE_IND 0x29 + +int ele_get_info (struct device *dev,phys_addr_t addr,u32 data_size); + +#endif
include/linux/firmware/imx/ele_mu_ioctl.h new file +52 -0
52 lines not on this page · raw message
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 06/11] firmware: imx: add driver for NXP EdgeLock Enclave
Quoted 9 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.
Reported-by kernel test robot <[email protected]>
Wrong tag. Bot did not report this driver.
Quoted 1 line
Drop.
Quoted 2 lines
Signed-off-by Pankaj Gupta <[email protected]>---
...
Quoted 8 lines
drivers/firmware/imx/se_fw.c new file +8
-0+ +static int se_fw_probe (struct platform_device *pdev) +{ +struct ele_mu_device_ctx *dev_ctx; +struct device *dev = &pdev->dev; +struct ele_mu_priv *priv; +const struct of_device_id *of_id =of_match_device (se_fw_match, dev); +struct imx_info *info =NULL ;
drivers/firmware/imx/se_fw.c line 981
Quoted 10 lines
drivers/firmware/imx/se_fw.c new file +10
-0+char *devname; +int ret; +int i; +struct device_node *np; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) { + ret = -ENOMEM ; +dev_err (dev,"Fail allocate mem for private data\n" ); +return ret;
No, really, I asked to clean this driver from such crap. It is crap because automated tools point it. It's a requirement to run them, which you did not.
You must run coccicheck, smatch, sparse, W=1 builds and several build tests. All of them must pass without single warning.
Quoted 141 lines
drivers/firmware/imx/se_fw.c new file +141
-0+ } +memset (priv,0x0 ,sizeof (*priv)); + priv->dev = dev; +dev_set_drvdata (dev, priv); + +/* +* Get the address of MU. +*/ + np = pdev->dev.of_node; +if (!np) { +dev_err (dev,"Cannot find MU User entry in device tree\n" ); + ret = -EOPNOTSUPP ; + goto exit; + } + +/* Initialize the mutex. */ +mutex_init (&priv->mu_cmd_lock); +mutex_init (&priv->mu_lock); + + priv->cmd_receiver_dev =NULL ; + priv->waiting_rsp_dev =NULL ; + +/* Mailbox client configuration */ + priv->ele_mb_cl.dev = dev; + priv->ele_mb_cl.tx_block = false; + priv->ele_mb_cl.knows_txdone = true; + priv->ele_mb_cl.rx_callback = ele_mu_rx_callback; + + ret =ele_mu_request_channel (dev, &priv->tx_chan, + &priv->ele_mb_cl,"tx" ); +if (ret) { +if (ret != -EPROBE_DEFER ) +dev_err (dev,"Failed to request tx channel\n" ); + + goto exit; + } + + ret =ele_mu_request_channel (dev, &priv->rx_chan, + &priv->ele_mb_cl,"rx" ); +if (ret) { +if (ret != -EPROBE_DEFER ) +dev_err (dev,"Failed to request rx channel\n" ); + + goto exit; + } + + ret =of_property_read_u32 (np,"fsl,mu-id" , &priv->ele_mu_id); +if (ret) { + ret = -EINVAL ; +dev_err (dev,"Not able to read mu-id.\n" ); + goto exit; + } + + info = (struct imx_info *)of_id->data; + priv->ele_mu_did = info->mu_did; + priv->max_dev_ctx = info->max_dev_ctx; + priv->cmd_tag = info->cmd_tag; + priv->rsp_tag = info->rsp_tag; + priv->success_tag = info->success_tag; + + priv->ctxs =devm_kzalloc (dev,sizeof (dev_ctx) * priv->max_dev_ctx, +GFP_KERNEL ); + +if (!priv->ctxs) { + ret = -ENOMEM ; +dev_err (dev,"Fail allocate mem for private dev-ctxs.\n" ); + goto exit; + } + +/* Create users */ +for (i =0 ; i < priv->max_dev_ctx; i++) { + dev_ctx =devm_kzalloc (dev,sizeof (*dev_ctx),GFP_KERNEL ); +if (!dev_ctx) { + ret = -ENOMEM ; +dev_err (dev, +"Fail to allocate memory for device context\n" ); + goto exit; + } + + dev_ctx->dev = dev; + dev_ctx->status =MU_FREE ; + dev_ctx->priv = priv; + + priv->ctxs[i] = dev_ctx; + +/* Default value invalid for an header. */ +init_waitqueue_head (&dev_ctx->wq); + +INIT_LIST_HEAD (&dev_ctx->pending_out); +INIT_LIST_HEAD (&dev_ctx->pending_in); +sema_init (&dev_ctx->fops_lock,1 ); + + devname =devm_kasprintf (dev,GFP_KERNEL ,"%s_mu%d_ch%d" , + info->se_name, + priv->ele_mu_id, i); +if (!devname) { + ret = -ENOMEM ; +dev_err (dev, +"Fail to allocate memory for misc dev name\n" ); + goto exit; + } + + dev_ctx->miscdev.name = devname; + dev_ctx->miscdev.minor =MISC_DYNAMIC_MINOR ; + dev_ctx->miscdev.fops = &ele_mu_fops; + dev_ctx->miscdev.parent = dev; + ret =misc_register (&dev_ctx->miscdev); +if (ret) { +dev_err (dev,"failed to register misc device %d\n" , + ret); + goto exit; + } + + ret =devm_add_action (dev, if_misc_deregister, + &dev_ctx->miscdev); +if (ret) { +dev_err (dev, +"failed[%d] to add action to the misc-dev\n" , + ret); + goto exit; + } + } + +init_completion (&priv->done); +spin_lock_init (&priv->lock); + +list_add_tail (&priv->priv_data, &priv_data_list); +dev_set_drvdata (dev, priv); + +if (info->reserved_dma_ranges) { + ret =of_reserved_mem_device_init (dev); +if (ret) { +dev_err (dev, +"failed to init reserved memory region %d\n" , + ret); + priv->flags &= (~RESERVED_DMA_POOL ); + goto exit; + } + priv->flags |=RESERVED_DMA_POOL ; + } +
drivers/firmware/imx/se_fw.c line 1132
Quoted 10 lines
drivers/firmware/imx/se_fw.c new file +10
-0+if (info->socdev) { + ret =imx_soc_device_register (dev, info); +if (ret) { +dev_err (dev, +"failed[%d] to register SoC device\n" , ret); + goto exit; + } + } + + pr_info("i.MX secure-enclave: %s's mu#%d interface to firmware, configured.\n",
dev_info
Quoted 13 lines
drivers/firmware/imx/se_fw.c new file +13
-0+ info->se_name, + priv->ele_mu_id); +return devm_of_platform_populate (dev); + +exit: +/* if execution control reaches here, ele-mu probe fail. +* hence doing the cleanup +*/ +return se_probe_cleanup (pdev); +} + +struct device *get_se_dev (uint32_t mu_id) +{
drivers/firmware/imx/se_fw.c line 1155
Quoted 10 lines
drivers/firmware/imx/se_fw.c new file +10
-0+struct ele_mu_priv *priv; + +list_for_each_entry (priv, &priv_data_list, priv_data) { +if (priv->ele_mu_id == mu_id) +return priv->dev; + } + +return NULL ; +} +EXPORT_SYMBOL (get_se_dev);
Uhu, that's GPL. Anyway, this needs to be documented.
Quoted 56 lines
drivers/firmware/imx/se_fw.c new file +46
-0+ +static int se_fw_remove (struct platform_device *pdev) +{ +se_probe_cleanup (pdev); + +return 0 ; +} + +#ifdef CONFIG_PM_SLEEP +static int se_fw_suspend (struct device *dev) +{ +return 0 ; +} + +static int se_fw_resume (struct device *dev) +{ +struct ele_mu_priv *priv =dev_get_drvdata (dev); +int i; + +for (i =0 ; i < priv->max_dev_ctx; i++) +wake_up_interruptible (&priv->ctxs[i]->wq); + +return 0 ; +} +#endif + +static const struct dev_pm_ops se_fw_pm = { +SET_SYSTEM_SLEEP_PM_OPS (se_fw_suspend, se_fw_resume) +}; + +static struct platform_driver se_fw_driver = { + .driver = { + .name ="fsl-se-fw" , + .of_match_table = se_fw_match, + .pm = &se_fw_pm, + }, + .probe = se_fw_probe, + .remove = se_fw_remove, +}; +MODULE_DEVICE_TABLE (of, se_fw_match); + +module_platform_driver (se_fw_driver); + +MODULE_AUTHOR ("Pankaj Gupta <[email protected]>" ); +MODULE_DESCRIPTION ("iMX Secure Enclave FW Driver." ); +MODULE_LICENSE ("GPL v2" );drivers/firmware/imx/se_fw.h new file +4
-0@@ -0,0 +1,168 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2021-2023 NXP +*/
drivers/firmware/imx/se_fw.h line 14
Quoted 10 lines
drivers/firmware/imx/se_fw.h new file +10
-0+ +#ifndef SE_MU_H +#define SE_MU_H + +#include <linux/miscdevice.h> +#include <linux/semaphore.h> +#include <linux/mailbox_client.h> + +/* macro to log operation of a misc device */ +#define miscdev_dbg(p_miscdev, fmt, va_args...) \
No, drop. Don't create your own abstraction layers over common Linux code.
drivers/firmware/imx/se_fw.h line 21
Quoted 7 lines
drivers/firmware/imx/se_fw.h new file +7
-0+ ({ \ +struct miscdevice *_p_miscdev = p_miscdev; \ + dev_dbg((_p_miscdev)->parent, "%s: " fmt, (_p_miscdev)->name, \ + ##va_args); \ + }) + +#define miscdev_info(p_miscdev, fmt, va_args...) \
No, drop.
drivers/firmware/imx/se_fw.h line 28
Quoted 7 lines
drivers/firmware/imx/se_fw.h new file +7
-0+ ({ \ +struct miscdevice *_p_miscdev = p_miscdev; \ + dev_info((_p_miscdev)->parent, "%s: " fmt, (_p_miscdev)->name, \ + ##va_args); \ + }) + +#define miscdev_err(p_miscdev, fmt, va_args...) \
No, drop.
drivers/firmware/imx/se_fw.h line 40
Quoted 12 lines
drivers/firmware/imx/se_fw.h new file +12
-0+ ({ \ +struct miscdevice *_p_miscdev = p_miscdev; \ + dev_err((_p_miscdev)->parent, "%s: " fmt, (_p_miscdev)->name, \ + ##va_args); \ + }) +/* macro to log operation of a device context */ +#define devctx_dbg(p_devctx, fmt, va_args...) \ + miscdev_dbg(&((p_devctx)->miscdev), fmt, ##va_args) +#define devctx_info(p_devctx, fmt, va_args...) \ + miscdev_info(&((p_devctx)->miscdev), fmt, ##va_args) +#define devctx_err(p_devctx, fmt, va_args...) \ + miscdev_err((&(p_devctx)->miscdev), fmt, ##va_args)
No, drop all these.
Quoted 217 lines
drivers/firmware/imx/se_fw.h new file +128
-0+ +#define MAX_MESSAGE_SIZE 31 +#define MAX_RECV_SIZE MAX_MESSAGE_SIZE +#define MAX_RECV_SIZE_BYTES (MAX_RECV_SIZE << 2) +#define MAX_MESSAGE_SIZE_BYTES (MAX_MESSAGE_SIZE << 2) + +#define ELE_MSG_DATA_NUM 10 + +#define MSG_TAG (x) (((x) & 0xff000000) >> 24) +#define MSG_COMMAND (x) (((x) & 0x00ff0000) >> 16) +#define MSG_SIZE (x) (((x) & 0x0000ff00) >> 8) +#define MSG_VER (x) ((x) & 0x000000ff) +#define RES_STATUS (x) ((x) & 0x000000ff) +#define MAX_DATA_SIZE_PER_USER (65 * 1024) +#define S4_DEFAULT_MUAP_INDEX (2) +#define S4_MUAP_DEFAULT_MAX_USERS (4) + +#define DEFAULT_MESSAGING_TAG_COMMAND (0x17u) +#define DEFAULT_MESSAGING_TAG_RESPONSE (0xe1u) + +#define ELE_MU_IO_FLAGS_USE_SEC_MEM (0x02u) +#define ELE_MU_IO_FLAGS_USE_SHORT_ADDR (0x04u) + +struct ele_imem_buf { +u8 *buf; +phys_addr_t phyaddr; +u32 size; +}; + +struct ele_buf_desc { +u8 *shared_buf_ptr; +u8 *usr_buf_ptr; +u32 size; +struct list_head link; +}; + +/* Status of a char device */ +enum mu_device_status_t { +MU_FREE , +MU_OPENED +}; + +struct ele_shared_mem { +dma_addr_t dma_addr; +u32 size; +u32 pos; +u8 *ptr; +}; + +/* Private struct for each char device instance. */ +struct ele_mu_device_ctx { +struct device *dev; +struct ele_mu_priv *priv; +struct miscdevice miscdev; + +enum mu_device_status_t status; +wait_queue_head_t wq; +struct semaphore fops_lock; + +u32 pending_hdr; +struct list_head pending_in; +struct list_head pending_out; + +struct ele_shared_mem secure_mem; +struct ele_shared_mem non_secure_mem; + +u32 temp_cmd[MAX_MESSAGE_SIZE ]; +u32 temp_resp[MAX_RECV_SIZE ]; +u32 temp_resp_size; +struct notifier_block ele_notify; +}; + +/* Header of the messages exchange with the EdgeLock Enclave */ +struct mu_hdr { +u8 ver; +u8 size; +u8 command; +u8 tag; +} __packed; + +#define ELE_MU_HDR_SZ 4 +#define TAG_OFFSET (ELE_MU_HDR_SZ - 1) +#define CMD_OFFSET (ELE_MU_HDR_SZ - 2) +#define SZ_OFFSET (ELE_MU_HDR_SZ - 3) +#define VER_OFFSET (ELE_MU_HDR_SZ - 4) + +struct ele_api_msg { +u32 header;/* u8 Tag; u8 Command; u8 Size; u8 Ver; */ +u32 data[ELE_MSG_DATA_NUM ]; +}; + +struct ele_mu_priv { +struct list_head priv_data; +struct ele_mu_device_ctx *cmd_receiver_dev; +struct ele_mu_device_ctx *waiting_rsp_dev; +/* +* prevent parallel access to the MU registers +* e.g. a user trying to send a command while the other one is +* sending a response. +*/ +struct mutex mu_lock; +/* +* prevent a command to be sent on the MU while another one is still +* processing. (response to a command is allowed) +*/ +struct mutex mu_cmd_lock; +struct device *dev; +u8 ele_mu_did; +u32 ele_mu_id; +u8 cmd_tag; +u8 rsp_tag; +u8 success_tag; + +struct mbox_client ele_mb_cl; +struct mbox_chan *tx_chan, *rx_chan; +struct ele_api_msg tx_msg, rx_msg; +struct completion done; +spinlock_t lock; +/* Flag to retain the state of initialization done at +* the time of ele-mu probe. +*/ +uint32_t flags; +u8 max_dev_ctx; +struct ele_mu_device_ctx **ctxs; +struct ele_imem_buf imem; +}; + +#endif include/linux/firmware/imx/ele_base_msg.h new file +37
-0@@ -0,0 +1,37 @@ +/* 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 MESSAGING_VERSION_7 0x7 +#define ELE_NONE_VAL 0x0 + +#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_GET_INFO_REQ 0xDA +#define ELE_GET_INFO_REQ_MSG_SZ 0x02 + +#define ELE_BASE_API_VERSION 0x6 +#define ELE_SUCCESS_IND 0xD6 +#define ELE_FAILURE_IND 0x29 + +int ele_get_info (struct device *dev,phys_addr_t addr,u32 data_size); + +#endif include/linux/firmware/imx/ele_mu_ioctl.h new file +40
-0@@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause*/ +/* +* Copyright 2019-2023 NXP +*/ + +#ifndef ELE_MU_IOCTL_H +#define ELE_MU_IOCTL_H + +/* IOCTL definitions. */ + +struct ele_mu_ioctl_setup_iobuf { +u8 *user_buf; +u32 length; +u32 flags; +u64 ele_addr; +}; + +struct ele_mu_ioctl_shared_mem_cfg { +u32 base_offset; +u32 size; +}; + +struct ele_mu_ioctl_get_mu_info { +u8 ele_mu_id; +u8 interrupt_idx; +u8 tz; +u8 did; +}; + +struct ele_mu_ioctl_signed_message { +u8 *message; +u32 msg_size; +u32 error_code; +}; + +#define ELE_MU_IO_FLAGS_IS_OUTPUT (0x00u) +#define ELE_MU_IO_FLAGS_IS_INPUT (0x01u) +#define ELE_MU_IO_FLAGS_USE_SEC_MEM (0x02u) +#define ELE_MU_IO_FLAGS_USE_SHORT_ADDR (0x04u) +#define ELE_MU_IO_FLAGS_IS_IN_OUT (0x08u)
include/linux/firmware/imx/ele_mu_ioctl.h line 50
Quoted 10 lines
include/linux/firmware/imx/ele_mu_ioctl.h new file +10
-0+ +#define ELE_MU_IOCTL 0x0A/* like MISC_MAJOR. */ +#define ELE_MU_IOCTL_ENABLE_CMD_RCV _IO(ELE_MU_IOCTL, 0x01) +#define ELE_MU_IOCTL_SHARED_BUF_CFG _IOW(ELE_MU_IOCTL, 0x02, \ + struct ele_mu_ioctl_shared_mem_cfg) +#define ELE_MU_IOCTL_SETUP_IOBUF _IOWR(ELE_MU_IOCTL, 0x03, \ + struct ele_mu_ioctl_setup_iobuf) +#define ELE_MU_IOCTL_GET_MU_INFO _IOR(ELE_MU_IOCTL, 0x04, \ + struct ele_mu_ioctl_get_mu_info) +#define ELE_MU_IOCTL_SIGNED_MESSAGE _IOWR(ELE_MU_IOCTL, 0x05, \
No documentation.
Plus you just created some completely vendor-specific interface for the firmware. I don't think this is suitable for upstream. Find respective existing interface and use it.
Your Cc list is absolutely huge, but these are NXP people, not community folks. Please reverse it and include instead other maintainers, not 10 NXP people.
I'll be NAKing for these reasons till you fix it.
Best regards,
Krzysztof
Re: [PATCH v5 06/11] firmware: imx: add driver for NXP EdgeLock Enclave
In reply to Pankaj GuptaHi Pankaj,
Am 23.08.23 um 09:33 schrieb Pankaj Gupta:
Quoted 31 lines
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.
Reported-by kernel test robot <[email protected]>Signed-off-by Pankaj Gupta <[email protected]>--- Documentation/ABI/testing/se-cdev | 29 + drivers/firmware/imx/Kconfig | 12 + drivers/firmware/imx/Makefile | 2 + drivers/firmware/imx/ele_base_msg.c | 62 ++ drivers/firmware/imx/ele_common.c | 34 + drivers/firmware/imx/ele_common.h | 21 + drivers/firmware/imx/se_fw.c | 1201 +++++++++++++++++++++ drivers/firmware/imx/se_fw.h | 168 +++ include/linux/firmware/imx/ele_base_msg.h | 37 + include/linux/firmware/imx/ele_mu_ioctl.h | 52 + 10 files changed, 1618 insertions(+)create mode 100644
Documentation/ABI/testing/se-cdevcreate mode 100644drivers/firmware/imx/ele_base_msg.ccreate mode 100644drivers/firmware/imx/ele_common.ccreate mode 100644drivers/firmware/imx/ele_common.hcreate mode 100644drivers/firmware/imx/se_fw.ccreate mode 100644drivers/firmware/imx/se_fw.hcreate mode 100644include/linux/firmware/imx/ele_base_msg.hcreate mode 100644include/linux/firmware/imx/ele_mu_ioctl.h
...
Quoted 21 lines
drivers/firmware/imx/ele_base_msg.c new file +21
-0+ +int ele_get_info (struct device *dev,phys_addr_t addr,u32 data_size) +{ +struct ele_mu_priv *priv =dev_get_drvdata (dev); +int ret; +unsigned int tag, command, size, ver, status; + + ret =plat_fill_cmd_msg_hdr (priv, + (struct mu_hdr *)&priv->tx_msg.header, +ELE_GET_INFO_REQ ,16 ); +if (ret) +return ret; + + priv->tx_msg.data[0 ] =upper_32_bits (addr); + priv->tx_msg.data[1 ] =lower_32_bits (addr); + priv->tx_msg.data[2 ] = data_size; + ret =imx_ele_msg_send_rcv (priv); +if (ret <0 ) +return ret; + + tag =MSG_TAG (priv->rx_msg.header);
drivers/firmware/imx/ele_base_msg.c line 59
Quoted 10 lines
drivers/firmware/imx/ele_base_msg.c new file +10
-0+ command =MSG_COMMAND (priv->rx_msg.header); + size =MSG_SIZE (priv->rx_msg.header); + ver =MSG_VER (priv->rx_msg.header); + status =RES_STATUS (priv->rx_msg.data[0 ]); +if (tag == priv->rsp_tag && + command ==ELE_GET_INFO_REQ && + size ==ELE_GET_INFO_REQ_MSG_SZ && + ver ==ELE_BASE_API_VERSION && + status == priv->success_tag) +return 0 ;
except of the coding style, i won't recommend this error handling. In case a user report a failure of ele_get_info(), we need to figure out which of these conditions failed. Why not check the conditions step by step and give a detailed error message.
The same applies to the rest of the series.
Best regards
drivers/firmware/imx/ele_base_msg.c line 62
Quoted 4 lines
drivers/firmware/imx/ele_base_msg.c new file +3
-0+ +return -EINVAL ; +}
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 06/11] firmware: imx: add driver for NXP EdgeLock Enclave
Quoted 12 lines
Am 23.08.23 um 09:33 schrieb Pankaj Gupta:
Quoted 11 lines
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.
Reported-by kernel test robot <[email protected]>Signed-off-by Pankaj Gupta <[email protected]>
In passing, LKP did not report that support for your firmware was missing, please remove the Reported-by & Closes tags.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 7/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 | 56 +++++++++++++++++++++++++ drivers/firmware/imx/se_fw.c | 11 +++++ include/linux/firmware/imx/ele_fw_api.h | 19 +++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/imx/ele_fw_api.c create mode 100644 include/linux/firmware/imx/ele_fw_api.h
drivers/firmware/imx/Makefile +1 -1
@@ -2,5 +2,5 @@ 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 obj-$(CONFIG_IMX_SCU_PD) += scu-pd.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 +56 -0
56 lines not on this page · raw message
drivers/firmware/imx/se_fw.c +11 -0
@@ -8,6 +8,7 @@#include <linux/dev_printk.h> #include <linux/errno.h> #include <linux/export.h> +#include <linux/firmware/imx/ele_fw_api.h> #include <linux/firmware/imx/ele_base_msg.h> #include <linux/firmware/imx/ele_mu_ioctl.h> #include <linux/genalloc.h>
@@ -41,6 +42,7 @@ struct imx_info {uint8_t *se_name;uint8_t *pool_name;bool reserved_dma_ranges; +bool init_fw; };static LIST_HEAD (priv_data_list);
@@ -55,6 +57,7 @@ static const struct imx_info imx8ulp_info = { .se_name = "ele", .pool_name = "sram-pool", .reserved_dma_ranges = true, + .init_fw = false, };static const struct imx_info imx93_info = {
@@ -67,6 +70,7 @@ static const struct imx_info imx93_info = { .se_name = "ele", .pool_name = NULL, .reserved_dma_ranges = true, + .init_fw = true, };static const struct of_device_id se_fw_match[] = {
@@ -1120,6 +1124,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) {
include/linux/firmware/imx/ele_fw_api.h new file +19 -0
@@ -0,0 +1,19 @@ +/* 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_RSP_SZ 0x2 + + +int ele_init_fw (struct device *dev); + +#endif /* ELE_FW_API_H */
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 07/11] firmware: imx: init-fw api exchange on imx93
Quoted 54 lines · Pankaj Gupta
On imx93 platforms, exchange init-fw message with enclave's firmware is to be done.
Signed-off-by Pankaj Gupta <[email protected]>--- drivers/firmware/imx/Makefile | 2 +- drivers/firmware/imx/ele_fw_api.c | 56 +++++++++++++++++++++++++ drivers/firmware/imx/se_fw.c | 11 +++++ include/linux/firmware/imx/ele_fw_api.h | 19 +++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/imx/ele_fw_api.c create mode 100644 include/linux/firmware/imx/ele_fw_api.hdrivers/firmware/imx/Makefile +1
-1@@ -2,5 +2,5 @@ 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 obj-$(CONFIG_IMX_SCU_PD) += scu-pd.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.odrivers/firmware/imx/ele_fw_api.c new file +24
-0@@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright 2023 NXP +*/ + +#include <linux/dma-mapping.h> +#include <linux/firmware/imx/ele_fw_api.h> + +#include "ele_common.h" + +/* Fill a command message header with a given command ID and length in bytes. */ +static int plat_fill_cmd_msg_hdr (struct ele_mu_priv *priv, +struct mu_hdr *hdr, +uint8_t cmd,uint32_t len) +{ +int err =0 ; + + hdr->tag = priv->cmd_tag; + hdr->ver =MESSAGING_VERSION_7 ; + hdr->command = cmd; + hdr->size = (uint8_t )(len /sizeof (uint32_t )); + +return err; +}
drivers/firmware/imx/ele_fw_api.c line 34
Quoted 10 lines
drivers/firmware/imx/ele_fw_api.c new file +10
-0+ +int ele_init_fw (struct device *dev) +{ +struct ele_mu_priv *priv =dev_get_drvdata (dev); +int ret; +unsigned int tag, command, size, ver, status; + + ret =plat_fill_cmd_msg_hdr (priv, + (struct mu_hdr *)&priv->tx_msg.header, +ELE_INIT_FW_REQ ,4 );
This is some weird code. Why do you store TX and RX messages in state container? This should be local to the function.
Quoted 9 lines
drivers/firmware/imx/ele_fw_api.c new file +9
-0+if (ret) +return ret; + + ret =imx_ele_msg_send_rcv (priv); +if (ret <0 ) +return ret; + + tag =MSG_TAG (priv->rx_msg.header); + command =MSG_COMMAND (priv->rx_msg.header);
drivers/firmware/imx/ele_fw_api.c line 53
Quoted 10 lines
drivers/firmware/imx/ele_fw_api.c new file +10
-0+ size =MSG_SIZE (priv->rx_msg.header); + ver =MSG_VER (priv->rx_msg.header); + status =RES_STATUS (priv->rx_msg.data[0 ]); + +if (tag == priv->rsp_tag + && command ==ELE_INIT_FW_REQ + && size ==ELE_INIT_FW_RSP_SZ + && ver ==MESSAGING_VERSION_7 + && status == priv->success_tag) +return 0 ;
Your coding style here and in all other places like this is unreadable. Fix alignment.
include/linux/firmware/imx/ele_fw_api.h
Quoted 58 lines
drivers/firmware/imx/ele_fw_api.c new file +3
-0+ +return -EINVAL ; +}drivers/firmware/imx/se_fw.c +11
-0@@ -8,6 +8,7 @@#include <linux/dev_printk.h> #include <linux/errno.h> #include <linux/export.h> +#include <linux/firmware/imx/ele_fw_api.h> #include <linux/firmware/imx/ele_base_msg.h> #include <linux/firmware/imx/ele_mu_ioctl.h> #include <linux/genalloc.h> @@ -41,6 +42,7 @@ struct imx_info {uint8_t *se_name;uint8_t *pool_name;bool reserved_dma_ranges; +bool init_fw; };static LIST_HEAD (priv_data_list);@@ -55,6 +57,7 @@ static const struct imx_info imx8ulp_info = { .se_name = "ele", .pool_name = "sram-pool", .reserved_dma_ranges = true, + .init_fw = false, };static const struct imx_info imx93_info = {@@ -67,6 +70,7 @@ static const struct imx_info imx93_info = { .se_name = "ele", .pool_name = NULL, .reserved_dma_ranges = true, + .init_fw = true, };static const struct of_device_id se_fw_match[] = {@@ -1120,6 +1124,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) {include/linux/firmware/imx/ele_fw_api.h new file +0
-0
There is no need this to be Linux-wide. Keep it next to the driver.
Best regards,
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 8/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 | 3 +- drivers/firmware/imx/ele_base_msg.c | 88 +++++++++++++++++++++++ drivers/firmware/imx/ele_common.c | 44 +++++++++++- drivers/firmware/imx/ele_common.h | 2 + drivers/firmware/imx/ele_fw_api.c | 54 ++++++++++++++ drivers/firmware/imx/ele_trng.c | 48 +++++++++++++ drivers/firmware/imx/se_fw.c | 23 +++++- include/linux/firmware/imx/ele_base_msg.h | 11 +++ include/linux/firmware/imx/ele_fw_api.h | 5 ++ 10 files changed, 283 insertions(+), 4 deletions(-) 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 +2 -1
@@ -2,5 +2,6 @@ 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 obj-$(CONFIG_IMX_SCU_PD) += scu-pd.o -sec_enclave-objs = se_fw.o ele_common.o ele_base_msg.o ele_fw_api.o +sec_enclave-objs = ele_common.o se_fw.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 +88 -0
91 lines not on this page · raw message
drivers/firmware/imx/ele_common.c +42 -2
54 lines not on this page · raw message
drivers/firmware/imx/ele_common.h +2 -0
@@ -18,4 +18,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 +54 -0
57 lines not on this page · raw message
drivers/firmware/imx/ele_trng.c new file +48 -0
48 lines not on this page · raw message
drivers/firmware/imx/se_fw.c +22 -1
@@ -21,10 +21,10 @@#include <linux/of_reserved_mem.h> #include <linux/platform_device.h> #include <linux/slab.h> -#include <linux/delay.h> #include <linux/sys_soc.h> #include "se_fw.h" +#include "ele_common.h" #define SOC_ID_OF_IMX8ULP 0x084D#define SOC_ID_OF_IMX93 0x9300
@@ -43,6 +43,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; };static LIST_HEAD (priv_data_list);
@@ -58,6 +61,8 @@ static const struct imx_info imx8ulp_info = { .pool_name = "sram-pool", .reserved_dma_ranges = true, .init_fw = false, + .start_rng = true, + .enable_ele_trng = false, };static const struct imx_info imx93_info = {
@@ -71,6 +76,8 @@ static const struct imx_info imx93_info = { .pool_name = NULL, .reserved_dma_ranges = true, .init_fw = true, + .start_rng = true, + .enable_ele_trng = true, };static const struct of_device_id se_fw_match[] = {
@@ -1140,9 +1147,23 @@ static int se_fw_probe(struct platform_device *pdev) } } +/* 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" ); + } +pr_info ("i.MX secure-enclave: %s's mu#%d interface to firmware, configured.\n" , info->se_name, priv->ele_mu_id); +return devm_of_platform_populate (dev); exit:
include/linux/firmware/imx/ele_base_msg.h +11 -0
@@ -28,10 +28,21 @@#define ELE_GET_INFO_REQ 0xDA#define ELE_GET_INFO_REQ_MSG_SZ 0x02 +#define ELE_START_RNG_REQ 0xA3 +#define ELE_START_RNG_REQ_MSG_SZ 0x02 + +#define ELE_GET_TRNG_STATE_REQ 0xA4 +#define ELE_GET_TRNG_STATE_REQ_MSG_SZ 0x03 +#define ELE_TRNG_STATE_OK 0x203 +#define ELE_GET_TRNG_STATE_RETRY_COUNT 0x5 +#define CSAL_TRNG_STATE_MASK 0x0000ffff +#define ELE_BASE_API_VERSION 0x6#define ELE_SUCCESS_IND 0xD6#define ELE_FAILURE_IND 0x29int ele_get_info (struct device *dev,phys_addr_t addr,u32 data_size); +int ele_start_rng (struct device *dev); +int ele_get_trng_state (struct device *dev);#endif
include/linux/firmware/imx/ele_fw_api.h +5 -0
@@ -13,7 +13,12 @@#define ELE_INIT_FW_REQ 0x17#define ELE_INIT_FW_RSP_SZ 0x2 +#define ELE_GET_RANDOM_REQ 0xCD +#define ELE_GET_RANDOM_REQ_SZ 0x2 +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 */
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 08/11] firmware: imx: enable trng
Quoted 4 lines · Pankaj Gupta
Enabled trng on imx93 platform through enclave fw.
Signed-off-by Gaurav Jain <[email protected]>Signed-off-by Pankaj Gupta <[email protected]>
Quoted 14 lines
--- drivers/firmware/imx/Kconfig | 9 +++ drivers/firmware/imx/Makefile | 3 +- drivers/firmware/imx/ele_base_msg.c | 88 +++++++++++++++++++++++ drivers/firmware/imx/ele_common.c | 44 +++++++++++- drivers/firmware/imx/ele_common.h | 2 + drivers/firmware/imx/ele_fw_api.c | 54 ++++++++++++++ drivers/firmware/imx/ele_trng.c | 48 +++++++++++++ drivers/firmware/imx/se_fw.c | 23 +++++- include/linux/firmware/imx/ele_base_msg.h | 11 +++ include/linux/firmware/imx/ele_fw_api.h | 5 ++ 10 files changed, 283 insertions(+), 4 deletions(-) create mode 100644 drivers/firmware/imx/ele_trng.c
firmware is not a place for RNG driver. You did not even CC RNG folks...
Quoted 13 lines
drivers/firmware/imx/ele_trng.c new file +13
-0+ +int ele_trng_init (struct device *dev) +{ +struct ele_trng *trng; +int ret; + + trng =devm_kzalloc (dev,sizeof (*trng),GFP_KERNEL ); +if (!trng) +return -ENOMEM ; + + trng->dev = dev; + trng->rng.name ="ele-trng" ; + trng->rng.read = ele_get_hwrng;
drivers/firmware/imx/ele_trng.c line 38
Quoted 10 lines
drivers/firmware/imx/ele_trng.c new file +10
-0+ trng->rng.priv = (unsigned long )trng; + trng->rng.quality =1024 ; + +dev_dbg (dev,"registering ele-trng\n" ); + + ret =devm_hwrng_register (dev, &trng->rng); +if (ret) +return ret; + +dev_info (dev,"Successfully registered ele-trng\n" );
Drop all simple trace replacements. Use tracing.
Quoted 62 lines
drivers/firmware/imx/ele_trng.c new file +10
-0+return 0 ; +} + +int ele_get_hwrng (struct hwrng *rng, +void *data,size_t len,bool wait) +{ +struct ele_trng *trng = (struct ele_trng *)rng->priv; + +return ele_get_random (trng->dev, data, len); +}drivers/firmware/imx/se_fw.c +12
-1@@ -21,10 +21,10 @@#include <linux/of_reserved_mem.h> #include <linux/platform_device.h> #include <linux/slab.h> -#include <linux/delay.h> #include <linux/sys_soc.h> #include "se_fw.h" +#include "ele_common.h" #define SOC_ID_OF_IMX8ULP 0x084D#define SOC_ID_OF_IMX93 0x9300@@ -43,6 +43,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; };static LIST_HEAD (priv_data_list);@@ -58,6 +61,8 @@ static const struct imx_info imx8ulp_info = { .pool_name = "sram-pool", .reserved_dma_ranges = true, .init_fw = false, + .start_rng = true, + .enable_ele_trng = false, };static const struct imx_info imx93_info = {@@ -71,6 +76,8 @@ static const struct imx_info imx93_info = { .pool_name = NULL, .reserved_dma_ranges = true, .init_fw = true, + .start_rng = true, + .enable_ele_trng = true, };static const struct of_device_id se_fw_match[] = {@@ -1140,9 +1147,23 @@ static int se_fw_probe(struct platform_device *pdev) } } +/* start ele rng */ +if (info->start_rng) { + ret =ele_do_start_rng (dev); +if (ret)
drivers/firmware/imx/se_fw.c static int se_fw_probe(struct platform_device *pdev) · line 1163
Quoted 10 lines
drivers/firmware/imx/se_fw.c +9
-0+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" ); + } + pr_info("i.MX secure-enclave: %s's mu#%d interface to firmware, configured.\n",
dev_info
drivers/firmware/imx/se_fw.c static int se_fw_probe(struct platform_device *pdev) · line 1166
Quoted 3 lines
drivers/firmware/imx/se_fw.c +1
-0info->se_name, priv->ele_mu_id); +
Not related.
drivers/firmware/imx/se_fw.c static int se_fw_probe(struct platform_device *pdev) · line 1168
Quoted 2 lines
drivers/firmware/imx/se_fw.c +0
-0return devm_of_platform_populate (dev);
Best regards,
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 9/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 | 42 ++++++++ drivers/firmware/imx/ele_common.c | 114 ++++++++++++++++++++++ drivers/firmware/imx/ele_common.h | 8 ++ drivers/firmware/imx/se_fw.c | 45 ++++++++- drivers/firmware/imx/se_fw.h | 8 ++ include/linux/firmware/imx/ele_base_msg.h | 15 ++- 6 files changed, 228 insertions(+), 4 deletions(-)
drivers/firmware/imx/ele_base_msg.c +42 -0
@@ -148,3 +148,45 @@ int ele_start_rng(struct device *dev)return -EINVAL ; } + +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 tag, command, size, ver, status; + + ret =plat_fill_cmd_msg_hdr (priv, + (struct mu_hdr *)&priv->tx_msg.header, +ELE_SERVICE_SWAP_REQ ,24 ); +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,24 ); + ret =imx_ele_msg_send_rcv (priv); +if (ret <0 ) +return ret; + + tag =MSG_TAG (priv->rx_msg.header); + command =MSG_COMMAND (priv->rx_msg.header); + size =MSG_SIZE (priv->rx_msg.header); + ver =MSG_VER (priv->rx_msg.header); + status =RES_STATUS (priv->rx_msg.data[0 ]); +if (tag == priv->rsp_tag && + command ==ELE_SERVICE_SWAP_REQ && + size ==ELE_SERVICE_SWAP_REQ_MSG_SZ && + ver ==ELE_BASE_API_VERSION && + status == priv->success_tag) { +if (flag ==ELE_IMEM_EXPORT ) +return priv->rx_msg.data[1 ]; +else +return 0 ; + } + +return -EINVAL ; +}
drivers/firmware/imx/ele_common.c +114 -0
123 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);#ifdef CONFIG_IMX_ELE_TRNG int ele_trng_init (struct device *dev);
@@ -20,4 +21,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 +43 -2
104 lines not on this page · raw message
drivers/firmware/imx/se_fw.h +8 -0
@@ -165,4 +165,12 @@ struct ele_mu_priv { struct ele_imem_buf imem; }; +phys_addr_t get_phy_buf_mem_pool (struct device *dev, +char *mem_pool_name, +u32 **buf, +uint32_t size); +void free_phybuf_mem_pool (struct device *dev, +char *mem_pool_name, +u32 *buf, +uint32_t size);#endif
include/linux/firmware/imx/ele_base_msg.h +13 -2
@@ -37,12 +37,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 0x03 +#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 +#define ELE_BASE_API_VERSION 0x6 -#define ELE_SUCCESS_IND 0xD6 -#define ELE_FAILURE_IND 0x29int ele_get_info (struct device *dev,phys_addr_t addr,u32 data_size);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 · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 09/11] firmware: imx: enclave-fw: add handling for save/restore IMEM region
Quoted 11 lines · Pankaj Gupta
Some 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.
Signed-off-by Gaurav Jain <[email protected]>Signed-off-by Pankaj Gupta <[email protected]>
drivers/firmware/imx/se_fw.c static int se_probe_cleanup(struct platform_device *pdev) · line 967
Quoted 6 lines
drivers/firmware/imx/se_fw.c +3
-0@@ -959,6 +962,17 @@ static int se_probe_cleanup(struct platform_device *pdev) priv->flags &= (~RESERVED_DMA_POOL ); } +/* free the buffer in ele-mu remove, previously allocated +* in ele-mu probe to store encrypted IMEM +*/
Use Linux coding style comments.
Quoted 32 lines
drivers/firmware/imx/se_fw.c +21
-0+if (priv->imem.buf) { +dmam_free_coherent (&pdev->dev, +ELE_IMEM_SIZE , + priv->imem.buf, + priv->imem.phyaddr); + priv->imem.buf =NULL ; + } +if (priv->ctxs) {for (i =0 ; i < priv->max_dev_ctx; i++) {if (priv->ctxs[i])@@ -1160,6 +1174,19 @@ 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; + } + } +pr_info ("i.MX secure-enclave: %s's mu#%d interface to firmware, configured.\n" , info->se_name, priv->ele_mu_id);
drivers/firmware/imx/se_fw.c static int se_fw_remove(struct platform_device *pdev) · line 1227
Quoted 5 lines
drivers/firmware/imx/se_fw.c +2
-0@@ -1196,17 +1223,31 @@ 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 of_device_id *of_id =of_match_device (se_fw_match, dev);
No.
drivers/firmware/imx/se_fw.c static int se_fw_remove(struct platform_device *pdev) · line 1240
Quoted 13 lines
drivers/firmware/imx/se_fw.c +7
-0+struct imx_info *info = (of_id !=NULL ) ? (struct imx_info *)of_id->data + :NULL ; + +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 of_device_id *of_id =of_match_device (se_fw_match, dev);
Why do you keep matching device every time? Don't.
Quoted 41 lines
drivers/firmware/imx/se_fw.c +5
-0+struct imx_info *info = (of_id !=NULL ) ? (struct imx_info *)of_id->data + :NULL ;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 drivers/firmware/imx/se_fw.h +8
-0@@ -165,4 +165,12 @@ struct ele_mu_priv { struct ele_imem_buf imem; }; +phys_addr_t get_phy_buf_mem_pool (struct device *dev, +char *mem_pool_name, +u32 **buf, +uint32_t size); +void free_phybuf_mem_pool (struct device *dev, +char *mem_pool_name, +u32 *buf, +uint32_t size);#endif include/linux/firmware/imx/ele_base_msg.h +3
-0@@ -37,12 +37,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 0x03 +#define ELE_IMEM_SIZE 0x10000
include/linux/firmware/imx/ele_base_msg.h line 42
Quoted 10 lines
include/linux/firmware/imx/ele_base_msg.h +7
-2+#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 +#define ELE_BASE_API_VERSION 0x6 -#define ELE_SUCCESS_IND 0xD6 -#define ELE_FAILURE_IND 0x29
No, you just added them. Don't add wrong code to remove it in next patch.
Best regards,
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 10/11 firmware: imx: enclave api to read-common-fuses
In reply to Pankaj GuptaAdded an API to read the common fuses only accessible to enclave-firmware.
--- drivers/firmware/imx/ele_base_msg.c | 80 +++++++++++++++++++++++ include/linux/firmware/imx/ele_base_msg.h | 7 ++ 2 files changed, 87 insertions(+)
drivers/firmware/imx/ele_base_msg.c +80 -0
@@ -190,3 +190,83 @@ int ele_service_swap(struct device *dev,return -EINVAL ; } + +static int read_otp_uniq_id (struct ele_mu_priv *priv,u32 *value) +{ +unsigned int tag, command, size, ver, status; + + tag =MSG_TAG (priv->rx_msg.header); + command =MSG_COMMAND (priv->rx_msg.header); + size =MSG_SIZE (priv->rx_msg.header); + ver =MSG_VER (priv->rx_msg.header); + status =RES_STATUS (priv->rx_msg.data[0 ]); + +if (tag == priv->rsp_tag && + command ==ELE_READ_FUSE_REQ && + size ==ELE_READ_FUSE_RSP_MSG_SZ && + ver ==ELE_BASE_API_VERSION && + status == priv->success_tag) { + value[0 ] = priv->rx_msg.data[1 ]; + value[1 ] = priv->rx_msg.data[2 ]; + value[2 ] = priv->rx_msg.data[3 ]; + value[3 ] = priv->rx_msg.data[4 ]; +return 0 ; + } + +return -EINVAL ; +} + +static int read_fuse_word (struct ele_mu_priv *priv,u32 *value) +{ +unsigned int tag, command, size, ver, status; + + tag =MSG_TAG (priv->rx_msg.header); + command =MSG_COMMAND (priv->rx_msg.header); + size =MSG_SIZE (priv->rx_msg.header); + ver =MSG_VER (priv->rx_msg.header); + status =RES_STATUS (priv->rx_msg.data[0 ]); + +if (tag == priv->rsp_tag && + command ==ELE_READ_FUSE_REQ && + size ==ELE_READ_FUSE_REQ_MSG_SZ && + ver ==ELE_BASE_API_VERSION && + status == priv->success_tag) { + value[0 ] = priv->rx_msg.data[1 ]; +return 0 ; + } + +return -EINVAL ; +} + +int read_common_fuse (struct device *dev, +uint16_t fuse_id,u32 *value) +{ +struct ele_mu_priv *priv =dev_get_drvdata (dev); +int err; + + err =plat_fill_cmd_msg_hdr (priv, + (struct mu_hdr *)&priv->tx_msg.header, +ELE_READ_FUSE_REQ ,8 ); +if (err) { +pr_err ("Error: plat_fill_cmd_msg_hdr failed.\n" ); +return err; + } + + priv->tx_msg.data[0 ] = fuse_id; + err =imx_ele_msg_send_rcv (priv); +if (err <0 ) +return err; + +switch (fuse_id) { +case OTP_UNIQ_ID : + err =read_otp_uniq_id (priv, value); +break ; +default : + err =read_fuse_word (priv, value); +break ; + } + +return err; +} +EXPORT_SYMBOL_GPL (read_common_fuse); +
include/linux/firmware/imx/ele_base_msg.h +7 -0
@@ -47,6 +47,13 @@#define ELE_IMEM_EXPORT 0x1#define ELE_IMEM_IMPORT 0x2 +#define ELE_READ_FUSE_REQ 0x97 +#define ELE_READ_FUSE_RSP_MSG_SZ 0x07 +#define ELE_READ_FUSE_REQ_MSG_SZ 0x03 + +#define OTP_UNIQ_ID 0x01 +#define OTFAD_CONFIG 0x2 +#define ELE_BASE_API_VERSION 0x6int ele_get_info (struct device *dev,phys_addr_t addr,u32 data_size);
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 10/11] firmware: imx: enclave api to read-common-fuses
Quoted 4 lines · Pankaj Gupta
Added an API to read the common fuses only accessible to enclave-firmware.
Signed-off-by Pankaj Gupta <[email protected]>
...
Quoted 21 lines
drivers/firmware/imx/ele_base_msg.c +21
-0+int read_common_fuse (struct device *dev, +uint16_t fuse_id,u32 *value) +{ +struct ele_mu_priv *priv =dev_get_drvdata (dev); +int err; + + err =plat_fill_cmd_msg_hdr (priv, + (struct mu_hdr *)&priv->tx_msg.header, +ELE_READ_FUSE_REQ ,8 ); +if (err) { +pr_err ("Error: plat_fill_cmd_msg_hdr failed.\n" ); +return err; + } + + priv->tx_msg.data[0 ] = fuse_id; + err =imx_ele_msg_send_rcv (priv); +if (err <0 ) +return err; + +switch (fuse_id) { +case OTP_UNIQ_ID :
drivers/firmware/imx/ele_base_msg.c int ele_service_swap(struct device *dev, · line 271
Quoted 10 lines
drivers/firmware/imx/ele_base_msg.c +10
-0+ err =read_otp_uniq_id (priv, value); +break ; +default : + err =read_fuse_word (priv, value); +break ; + } + +return err; +} +EXPORT_SYMBOL_GPL (read_common_fuse);
Missing kerneldoc, missing user. Sorry, this cannot be accepted. Don't add such dead code.
Best regards,
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 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
@@ -13620,6 +13620,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 · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel