Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Documentation/devicetree/bindings/security/loongson_se/se.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/security/loongson_se/se.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Loongson SE module

description:
Loongson SE module
maintainers:
- Qunqin Zhao <zhaoqunqin@loongson.cn>

allOf:
- $ref: se.yaml#

properties:
compatible:
const: loongson,ls3c6000se

reg:
maxItems: 2

interrupts:
maxItems: 2

required:
- compatible
- reg
- interrupts

additionalProperties: false
8 changes: 8 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -12446,6 +12446,14 @@ S: Maintained
F: Documentation/devicetree/bindings/pinctrl/loongson,ls2k-pinctrl.yaml
F: drivers/pinctrl/pinctrl-loongson2.c

LOONGSON SE DRIVER
M: Qunqin Zhao <zhaoqunqin@loongson.cn>
S: Maintained
F: Documentation/devicetree/bindings/security/loongson_se/se.yaml
F: arch/loongarch/include/asm/se.h
F: drivers/char/loongson_se.c
F: drivers/char/lsse_sdf_cdev.c

LOONGSON-2 SOC SERIES THERMAL DRIVER
M: zhanghongchen <zhanghongchen@loongson.cn>
M: Yinbo Zhu <zhuyinbo@loongson.cn>
Expand Down
147 changes: 147 additions & 0 deletions arch/loongarch/include/asm/se.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2012 IBM Corporation
*
* Copyright 2023 Loongson Technology, Inc.
* Yinggang Gu <guyinggang@loongson.cn>
*
* Device driver for Loongson SE module.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2 of the
* License.
*
*/
#ifndef __LOONGSON_SE_H__
#define __LOONGSON_SE_H__

#define SE_MAILBOX_S 0x0
#define SE_MAILBOX_L 0x20
#define SE_S2LINT_STAT 0x88
#define SE_S2LINT_EN 0x8c
#define SE_S2LINT_SET 0x90
#define SE_S2LINT_CL 0x94
#define SE_L2SINT_STAT 0x98
#define SE_L2SINT_EN 0x9c
#define SE_L2SINT_SET 0xa0
#define SE_L2SINT_CL 0xa4

/* INT bit definition */
#define SE_INT_SETUP BIT(0)
#define SE_INT_SM2 BIT(0)
#define SE_INT_SM3 BIT(0)
#define SE_INT_SM4 BIT(0)
#define SE_INT_RNG BIT(0)
#define SE_INT_TPM BIT(5)
#define SE_INT_ALL 0xffffffff

#define SE_CMD_START 0x0
#define SE_CMD_STOP 0x1
#define SE_CMD_GETVER 0x2
#define SE_CMD_SETBUF 0x3
#define SE_CMD_SETMSG 0x4

#define SE_CMD_RNG 0x100

#define SE_CMD_SM2_SIGN 0x200
#define SE_CMD_SM2_VSIGN 0x201

#define SE_CMD_SM3_DIGEST 0x300
#define SE_CMD_SM3_UPDATE 0x301
#define SE_CMD_SM3_FINISH 0x302

#define SE_CMD_SM4_ECB_ENCRY 0x400
#define SE_CMD_SM4_ECB_DECRY 0x401
#define SE_CMD_SM4_CBC_ENCRY 0x402
#define SE_CMD_SM4_CBC_DECRY 0x403
#define SE_CMD_SM4_CTR 0x404

#define SE_CMD_TPM 0x500
#define SE_CMD_ZUC_INIT_READ 0x600
#define SE_CMD_ZUC_READ 0x601

#define SE_CMD_SDF 0x700

#define SE_CH_MAX 32

#define SE_CH_RNG 1
#define SE_CH_SM2 2
#define SE_CH_SM3 3
#define SE_CH_SM4 4
#define SE_CH_TPM 5
#define SE_CH_ZUC 6
#define SE_CH_SDF 7

struct se_msg {
u32 cmd;
u32 data_off;
u32 data_len;
u32 info[5];
};

struct se_cmd {
u32 cmd;
u32 info[7];
};

struct se_res {
u32 cmd;
u32 cmd_ret;
u32 info[6];
};

struct se_mailbox_data {
u32 int_bit;
union {
u32 mailbox[8];
struct se_cmd gcmd;
struct se_res res;
} u;
};

struct lsse_ch {
u32 id;
u32 int_bit;
struct loongson_se *se;
void *priv;
spinlock_t ch_lock;
void *smsg;
void *rmsg;
int msg_size;
void *data_buffer;
dma_addr_t data_addr;
int data_size;

void (*complete)(struct lsse_ch *se_ch);
};

struct loongson_se {
struct device *dev;
void __iomem *base;
u32 version;
u32 ch_status;
spinlock_t cmd_lock;
spinlock_t dev_lock;

/* Interaction memory */
void *mem_base;
dma_addr_t mem_addr;
unsigned long *mem_map;
int mem_map_size;
void *smsg;
void *rmsg;

/* Synchronous CMD */
struct completion cmd_completion;

/* Virtual Channel */
struct lsse_ch chs[SE_CH_MAX];
};

struct lsse_ch *se_init_ch(int id, int data_size, int msg_size, void *priv,
void (*complete)(struct lsse_ch *se_ch));
void se_deinit_ch(struct lsse_ch *ch);
int se_send_ch_request(struct lsse_ch *ch);

#endif
20 changes: 20 additions & 0 deletions drivers/char/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,26 @@ config UV_MMTIMER
The uv_mmtimer device allows direct userspace access to the
UV system timer.

config LOONGSON_SE
tristate "LOONGSON SECURITY MODULE Interface"
depends on LOONGARCH
default m
help
If you have LOONGSON security module (SE) support say Yes and it
will be accessible from within Linux.
To compile this driver as a module, choose M here,the module will
be called loongson-se.

config LOONGSON_SE_SDF
tristate "LOONGSON SECURITY MODULE SDF Interface"
depends on LOONGARCH && LOONGSON_SE
default m
help
If you want to use LOONGSON security module (SE) as SDF say Yes
and it will be accessible from within Linux.
To compile this driver as a module, choose M here,the module will
be called loongson-se.

source "drivers/char/tpm/Kconfig"

config TELCLOCK
Expand Down
2 changes: 2 additions & 0 deletions drivers/char/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
obj-$(CONFIG_TELCLOCK) += tlclk.o
obj-$(CONFIG_LOONGSON_SE) += loongson_se.o
obj-$(CONFIG_LOONGSON_SE_SDF) += lsse_sdf_cdev.o

obj-$(CONFIG_MWAVE) += mwave/
obj-y += agp/
Expand Down
Loading
Loading