xref: /kernel/linux/linux-6.6/lib/test_hmm_uapi.h (revision 62306a36)
162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * This is a module to test the HMM (Heterogeneous Memory Management) API
462306a36Sopenharmony_ci * of the kernel. It allows a userspace program to expose its entire address
562306a36Sopenharmony_ci * space through the HMM test module device file.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci#ifndef _LIB_TEST_HMM_UAPI_H
862306a36Sopenharmony_ci#define _LIB_TEST_HMM_UAPI_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/types.h>
1162306a36Sopenharmony_ci#include <linux/ioctl.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/*
1462306a36Sopenharmony_ci * Structure to pass to the HMM test driver to mimic a device accessing
1562306a36Sopenharmony_ci * system memory and ZONE_DEVICE private memory through device page tables.
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci * @addr: (in) user address the device will read/write
1862306a36Sopenharmony_ci * @ptr: (in) user address where device data is copied to/from
1962306a36Sopenharmony_ci * @npages: (in) number of pages to read/write
2062306a36Sopenharmony_ci * @cpages: (out) number of pages copied
2162306a36Sopenharmony_ci * @faults: (out) number of device page faults seen
2262306a36Sopenharmony_ci */
2362306a36Sopenharmony_cistruct hmm_dmirror_cmd {
2462306a36Sopenharmony_ci	__u64		addr;
2562306a36Sopenharmony_ci	__u64		ptr;
2662306a36Sopenharmony_ci	__u64		npages;
2762306a36Sopenharmony_ci	__u64		cpages;
2862306a36Sopenharmony_ci	__u64		faults;
2962306a36Sopenharmony_ci};
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/* Expose the address space of the calling process through hmm device file */
3262306a36Sopenharmony_ci#define HMM_DMIRROR_READ		_IOWR('H', 0x00, struct hmm_dmirror_cmd)
3362306a36Sopenharmony_ci#define HMM_DMIRROR_WRITE		_IOWR('H', 0x01, struct hmm_dmirror_cmd)
3462306a36Sopenharmony_ci#define HMM_DMIRROR_MIGRATE_TO_DEV	_IOWR('H', 0x02, struct hmm_dmirror_cmd)
3562306a36Sopenharmony_ci#define HMM_DMIRROR_MIGRATE_TO_SYS	_IOWR('H', 0x03, struct hmm_dmirror_cmd)
3662306a36Sopenharmony_ci#define HMM_DMIRROR_SNAPSHOT		_IOWR('H', 0x04, struct hmm_dmirror_cmd)
3762306a36Sopenharmony_ci#define HMM_DMIRROR_EXCLUSIVE		_IOWR('H', 0x05, struct hmm_dmirror_cmd)
3862306a36Sopenharmony_ci#define HMM_DMIRROR_CHECK_EXCLUSIVE	_IOWR('H', 0x06, struct hmm_dmirror_cmd)
3962306a36Sopenharmony_ci#define HMM_DMIRROR_RELEASE		_IOWR('H', 0x07, struct hmm_dmirror_cmd)
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/*
4262306a36Sopenharmony_ci * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT.
4362306a36Sopenharmony_ci * HMM_DMIRROR_PROT_ERROR: no valid mirror PTE for this page
4462306a36Sopenharmony_ci * HMM_DMIRROR_PROT_NONE: unpopulated PTE or PTE with no access
4562306a36Sopenharmony_ci * HMM_DMIRROR_PROT_READ: read-only PTE
4662306a36Sopenharmony_ci * HMM_DMIRROR_PROT_WRITE: read/write PTE
4762306a36Sopenharmony_ci * HMM_DMIRROR_PROT_PMD: PMD sized page is fully mapped by same permissions
4862306a36Sopenharmony_ci * HMM_DMIRROR_PROT_PUD: PUD sized page is fully mapped by same permissions
4962306a36Sopenharmony_ci * HMM_DMIRROR_PROT_ZERO: special read-only zero page
5062306a36Sopenharmony_ci * HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL: Migrated device private page on the
5162306a36Sopenharmony_ci *					device the ioctl() is made
5262306a36Sopenharmony_ci * HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE: Migrated device private page on some
5362306a36Sopenharmony_ci *					other device
5462306a36Sopenharmony_ci * HMM_DMIRROR_PROT_DEV_COHERENT: Migrate device coherent page on the device
5562306a36Sopenharmony_ci *				  the ioctl() is made
5662306a36Sopenharmony_ci */
5762306a36Sopenharmony_cienum {
5862306a36Sopenharmony_ci	HMM_DMIRROR_PROT_ERROR			= 0xFF,
5962306a36Sopenharmony_ci	HMM_DMIRROR_PROT_NONE			= 0x00,
6062306a36Sopenharmony_ci	HMM_DMIRROR_PROT_READ			= 0x01,
6162306a36Sopenharmony_ci	HMM_DMIRROR_PROT_WRITE			= 0x02,
6262306a36Sopenharmony_ci	HMM_DMIRROR_PROT_PMD			= 0x04,
6362306a36Sopenharmony_ci	HMM_DMIRROR_PROT_PUD			= 0x08,
6462306a36Sopenharmony_ci	HMM_DMIRROR_PROT_ZERO			= 0x10,
6562306a36Sopenharmony_ci	HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL	= 0x20,
6662306a36Sopenharmony_ci	HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE	= 0x30,
6762306a36Sopenharmony_ci	HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL	= 0x40,
6862306a36Sopenharmony_ci	HMM_DMIRROR_PROT_DEV_COHERENT_REMOTE	= 0x50,
6962306a36Sopenharmony_ci};
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_cienum {
7262306a36Sopenharmony_ci	/* 0 is reserved to catch uninitialized type fields */
7362306a36Sopenharmony_ci	HMM_DMIRROR_MEMORY_DEVICE_PRIVATE = 1,
7462306a36Sopenharmony_ci	HMM_DMIRROR_MEMORY_DEVICE_COHERENT,
7562306a36Sopenharmony_ci};
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci#endif /* _LIB_TEST_HMM_UAPI_H */
78