162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  Copyright IBM Corp. 2022
462306a36Sopenharmony_ci *  Author(s): Steffen Eiden <seiden@linux.ibm.com>
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef __S390_ASM_UVDEVICE_H
762306a36Sopenharmony_ci#define __S390_ASM_UVDEVICE_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/types.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_cistruct uvio_ioctl_cb {
1262306a36Sopenharmony_ci	__u32 flags;
1362306a36Sopenharmony_ci	__u16 uv_rc;			/* UV header rc value */
1462306a36Sopenharmony_ci	__u16 uv_rrc;			/* UV header rrc value */
1562306a36Sopenharmony_ci	__u64 argument_addr;		/* Userspace address of uvio argument */
1662306a36Sopenharmony_ci	__u32 argument_len;
1762306a36Sopenharmony_ci	__u8  reserved14[0x40 - 0x14];	/* must be zero */
1862306a36Sopenharmony_ci};
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define UVIO_ATT_USER_DATA_LEN		0x100
2162306a36Sopenharmony_ci#define UVIO_ATT_UID_LEN		0x10
2262306a36Sopenharmony_cistruct uvio_attest {
2362306a36Sopenharmony_ci	__u64 arcb_addr;				/* 0x0000 */
2462306a36Sopenharmony_ci	__u64 meas_addr;				/* 0x0008 */
2562306a36Sopenharmony_ci	__u64 add_data_addr;				/* 0x0010 */
2662306a36Sopenharmony_ci	__u8  user_data[UVIO_ATT_USER_DATA_LEN];	/* 0x0018 */
2762306a36Sopenharmony_ci	__u8  config_uid[UVIO_ATT_UID_LEN];		/* 0x0118 */
2862306a36Sopenharmony_ci	__u32 arcb_len;					/* 0x0128 */
2962306a36Sopenharmony_ci	__u32 meas_len;					/* 0x012c */
3062306a36Sopenharmony_ci	__u32 add_data_len;				/* 0x0130 */
3162306a36Sopenharmony_ci	__u16 user_data_len;				/* 0x0134 */
3262306a36Sopenharmony_ci	__u16 reserved136;				/* 0x0136 */
3362306a36Sopenharmony_ci};
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/**
3662306a36Sopenharmony_ci * uvio_uvdev_info - Information of supported functions
3762306a36Sopenharmony_ci * @supp_uvio_cmds - supported IOCTLs by this device
3862306a36Sopenharmony_ci * @supp_uv_cmds - supported UVCs corresponding to the IOCTL
3962306a36Sopenharmony_ci *
4062306a36Sopenharmony_ci * UVIO request to get information about supported request types by this
4162306a36Sopenharmony_ci * uvdevice and the Ultravisor.  Everything is output. Bits are in LSB0
4262306a36Sopenharmony_ci * ordering.  If the bit is set in both, @supp_uvio_cmds and @supp_uv_cmds, the
4362306a36Sopenharmony_ci * uvdevice and the Ultravisor support that call.
4462306a36Sopenharmony_ci *
4562306a36Sopenharmony_ci * Note that bit 0 (UVIO_IOCTL_UVDEV_INFO_NR) is always zero for `supp_uv_cmds`
4662306a36Sopenharmony_ci * as there is no corresponding UV-call.
4762306a36Sopenharmony_ci */
4862306a36Sopenharmony_cistruct uvio_uvdev_info {
4962306a36Sopenharmony_ci	/*
5062306a36Sopenharmony_ci	 * If bit `n` is set, this device supports the IOCTL with nr `n`.
5162306a36Sopenharmony_ci	 */
5262306a36Sopenharmony_ci	__u64 supp_uvio_cmds;
5362306a36Sopenharmony_ci	/*
5462306a36Sopenharmony_ci	 * If bit `n` is set, the Ultravisor(UV) supports the UV-call
5562306a36Sopenharmony_ci	 * corresponding to the IOCTL with nr `n` in the calling contextx (host
5662306a36Sopenharmony_ci	 * or guest).  The value is only valid if the corresponding bit in
5762306a36Sopenharmony_ci	 * @supp_uvio_cmds is set as well.
5862306a36Sopenharmony_ci	 */
5962306a36Sopenharmony_ci	__u64 supp_uv_cmds;
6062306a36Sopenharmony_ci};
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/*
6362306a36Sopenharmony_ci * The following max values define an upper length for the IOCTL in/out buffers.
6462306a36Sopenharmony_ci * However, they do not represent the maximum the Ultravisor allows which is
6562306a36Sopenharmony_ci * often way smaller. By allowing larger buffer sizes we hopefully do not need
6662306a36Sopenharmony_ci * to update the code with every machine update. It is therefore possible for
6762306a36Sopenharmony_ci * userspace to request more memory than actually used by kernel/UV.
6862306a36Sopenharmony_ci */
6962306a36Sopenharmony_ci#define UVIO_ATT_ARCB_MAX_LEN		0x100000
7062306a36Sopenharmony_ci#define UVIO_ATT_MEASUREMENT_MAX_LEN	0x8000
7162306a36Sopenharmony_ci#define UVIO_ATT_ADDITIONAL_MAX_LEN	0x8000
7262306a36Sopenharmony_ci#define UVIO_ADD_SECRET_MAX_LEN		0x100000
7362306a36Sopenharmony_ci#define UVIO_LIST_SECRETS_LEN		0x1000
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define UVIO_DEVICE_NAME "uv"
7662306a36Sopenharmony_ci#define UVIO_TYPE_UVC 'u'
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_cienum UVIO_IOCTL_NR {
7962306a36Sopenharmony_ci	UVIO_IOCTL_UVDEV_INFO_NR = 0x00,
8062306a36Sopenharmony_ci	UVIO_IOCTL_ATT_NR,
8162306a36Sopenharmony_ci	UVIO_IOCTL_ADD_SECRET_NR,
8262306a36Sopenharmony_ci	UVIO_IOCTL_LIST_SECRETS_NR,
8362306a36Sopenharmony_ci	UVIO_IOCTL_LOCK_SECRETS_NR,
8462306a36Sopenharmony_ci	/* must be the last entry */
8562306a36Sopenharmony_ci	UVIO_IOCTL_NUM_IOCTLS
8662306a36Sopenharmony_ci};
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#define UVIO_IOCTL(nr)		_IOWR(UVIO_TYPE_UVC, nr, struct uvio_ioctl_cb)
8962306a36Sopenharmony_ci#define UVIO_IOCTL_UVDEV_INFO	UVIO_IOCTL(UVIO_IOCTL_UVDEV_INFO_NR)
9062306a36Sopenharmony_ci#define UVIO_IOCTL_ATT		UVIO_IOCTL(UVIO_IOCTL_ATT_NR)
9162306a36Sopenharmony_ci#define UVIO_IOCTL_ADD_SECRET	UVIO_IOCTL(UVIO_IOCTL_ADD_SECRET_NR)
9262306a36Sopenharmony_ci#define UVIO_IOCTL_LIST_SECRETS	UVIO_IOCTL(UVIO_IOCTL_LIST_SECRETS_NR)
9362306a36Sopenharmony_ci#define UVIO_IOCTL_LOCK_SECRETS	UVIO_IOCTL(UVIO_IOCTL_LOCK_SECRETS_NR)
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci#define UVIO_SUPP_CALL(nr)	(1ULL << (nr))
9662306a36Sopenharmony_ci#define UVIO_SUPP_UDEV_INFO	UVIO_SUPP_CALL(UVIO_IOCTL_UDEV_INFO_NR)
9762306a36Sopenharmony_ci#define UVIO_SUPP_ATT		UVIO_SUPP_CALL(UVIO_IOCTL_ATT_NR)
9862306a36Sopenharmony_ci#define UVIO_SUPP_ADD_SECRET	UVIO_SUPP_CALL(UVIO_IOCTL_ADD_SECRET_NR)
9962306a36Sopenharmony_ci#define UVIO_SUPP_LIST_SECRETS	UVIO_SUPP_CALL(UVIO_IOCTL_LIST_SECRETS_NR)
10062306a36Sopenharmony_ci#define UVIO_SUPP_LOCK_SECRETS	UVIO_SUPP_CALL(UVIO_IOCTL_LOCK_SECRETS_NR)
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci#endif /* __S390_ASM_UVDEVICE_H */
103