Skip to content

drivers/crypto: add Qualcomm Hardware Key Manager (HWKM) driver#10

Open
qc-azarrabi wants to merge 4 commits into
qualcomm-linux:qcom-nextfrom
qc-azarrabi:hwkm-hal
Open

drivers/crypto: add Qualcomm Hardware Key Manager (HWKM) driver#10
qc-azarrabi wants to merge 4 commits into
qualcomm-linux:qcom-nextfrom
qc-azarrabi:hwkm-hal

Conversation

@qc-azarrabi

Copy link
Copy Markdown

This patch adds a new driver for the Qualcomm Hardware Key Manager (HWKM), a hardware IP block found on Qualcomm SoCs that provides hardware-enforced key storage and cryptographic key derivation.

Background

HWKM maintains a key table whose slots are never accessible in plaintext to software above the security level at which a key was provisioned. Each slot carries a hardware-enforced policy word that controls which operations, algorithms, and security domains may use it. The communicates with the hardware is through a command/response FIFO interface.

What this patch does

The driver implements the full HWKM command set:

  • NIST_KEYGEN - generate a fresh key into a slot via the HW PRNG.
  • SYSTEM_KDF - derive a child key from a KDK slot using the hardware KDF, with optional BSVE binding.
  • KEY_WRAP_EXPORT / KEY_UNWRAP_IMPORT - wrap/unwrap key blobs under a wrapping key slot.
  • KEY_SLOT_CLEAR - clear a slot and invalidate its policy.
  • KEY_SLOT_RDWR - read or write raw key material for SW_KEY slots.
  • SET_TPKEY - install a slot as the active transport protection key.

Design notes

Commands are modelled as "transactions" - struct hwkm_transaction - that carry both the request and the response. Transactions are queued on a handle - struct hwkm_handle - and executed in FIFO order by hwkm_run_cmd_queue(). This makes multi-step sequences (e.g. clear + derive + read + clear for HUK derivation) easy to express.

Footnote

Only the KM_MASTER destination is currently supported. Slave instances (e.g. GPCE or ICE) can be added by extending hwkm_key_destination and run_transaction().

@b49020 b49020 requested a review from ldts April 27, 2026 04:19
@b49020

b49020 commented Apr 27, 2026

Copy link
Copy Markdown
Member

@T0nyJH fyi..

*
* Return: TEE_SUCCESS on success, or a TEE_ERROR_* code on failure.
*/
TEE_Result tee_otp_get_hw_unique_key(struct tee_hw_unique_key *hwkey)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of repeating the same pattern for each phase, is it possible that we can extract the pattern into a static function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored.

@b49020

b49020 commented Apr 28, 2026

Copy link
Copy Markdown
Member

Please rebase to the tip of qcom-next as it has been rebased to tip of upstream master to include the merged PAS patch-set as well as latest fuse driver patch-set from Selvam.

@qc-azarrabi qc-azarrabi force-pushed the hwkm-hal branch 2 times, most recently from 675fed5 to 9355517 Compare May 13, 2026 01:50
zelvam95 added 3 commits June 8, 2026 13:02
Implement a diagnostic ring buffer driver that preserves crash
logs in IMEM across reboots for post-mortem analysis. The driver
provides a write-only circular buffer that captures console output
during normal operation and crash scenarios.

Key features:
- Write-only circular buffer in IMEM for crash log preservation
- DLOAD mode detection to disable logging during download mode
- Automatic buffer wraparound with overflow tracking

Signed-off-by: Selvam Sathappan Periakaruppan <speriaka@qti.qualcomm.com>
Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez@oss.qualcomm.com>
Integrate the diagnostic ring buffer driver into the platform:

- Add IMEM memory region definitions (platform_config.h)
  * Kodiak: 0x14680000, size 0x19000
  * Lemans: 0x14680000, size 0x32000

- Enable CFG_QCOM_DIAG_LOG in debug builds (conf.mk)
  * Automatically enabled when CFG_TEE_CORE_DEBUG=y

- Hook into trace infrastructure
  * Initialize DIAG during plat_trace_init()
  * Mirror console output via plat_trace_ext_puts()

This enables crash log preservation for debugging production
issues when debug builds are deployed.

Signed-off-by: Selvam Sathappan Periakaruppan <speriaka@qti.qualcomm.com>
Introduce an architecture-centric structure for Qualcomm platform
configuration to improve scalability and maintainability.

Chipsets are now grouped by architecture family (e.g., Kodiak and Lemans
under HOYA). Configuration is split into three levels:

1. Platform-wide (conf.mk): Maps chipsets to architecture families
2. Architecture-level (hoya/arch.mk, hoya/arch_config.h): Base platform
   requirements common across all chipsets in the family (CPU, cores,
   TZDRAM, RAMBLUR, PRNG)
3. Chipset-specific (hoya/kodiak/target.mk, hoya/lemans/target.mk):
   Advanced features like clock drivers, diagnostic logging, and fuse
   provisioning

The conf.mk uses variable-based includes to automatically load the
correct architecture and chipset configurations, eliminating conditional
logic from architecture files.

This structure allows new chipsets to start with minimal base platform
support and incrementally add advanced features. It also simplifies
adding new architecture families in the future.

No functional changes - pure refactoring with identical configuration
values and hardware addresses.

Signed-off-by: Selvam Sathappan Periakaruppan <speriaka@qti.qualcomm.com>
@qc-azarrabi qc-azarrabi force-pushed the hwkm-hal branch 2 times, most recently from ec87d72 to 2fad7a2 Compare June 10, 2026 05:18
Add a driver for the Qualcomm Hardware Key Manager (HWKM), a hardware
IP block present on Qualcomm SoCs that manages cryptographic key slots
in a tamper-resistant key table. Keys stored in HWKM slots are never
exposed in plaintext to software above the security level they were
provisioned at; the hardware enforces per-slot access-control and
usage policies.

The driver exposes the following functionality to OP-TEE:

  - Hardware Unique Key (HUK): implements tee_otp_get_hw_unique_key()
    by deriving a device-unique key from the TZ UKDK L2 slot via the
    SYSTEM_KDF command, using a fixed software context string and the
    SWC BSVE binding. The derived key is cached in the driver context
    after the first call.

  - Full command set: NIST_KEYGEN, SYSTEM_KDF, KEY_WRAP_EXPORT,
    KEY_UNWRAP_IMPORT, KEY_SLOT_CLEAR, KEY_SLOT_RDWR, and SET_TPKEY
    are all implemented and exposed through a transaction queue API.

Signed-off-by: Amirreza Zarrabi <amirreza.zarrabi@oss.qualcomm.com>
#define PAS_ID_TURING 18

#define HWKM_MASTER_BASE UL(0x010c0000)
#define HWKM_MASTER_SIZE UL(0x00020000)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the base addresses seems to be common for Hoya architecture, can you rather move the defines to core/arch/arm/plat-qcom/hoya/arch_config.h?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do.

@b49020

b49020 commented Jun 10, 2026

Copy link
Copy Markdown
Member

@qc-azarrabi please split this patch into 3 logical commits:

  • Add preparatory clock patch for HWKM
  • HWKM driver patch
  • Platform enablement patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants