^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * This is a module to test the HMM (Heterogeneous Memory Management) API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * of the kernel. It allows a userspace program to expose its entire address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * space through the HMM test module device file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef _LIB_TEST_HMM_UAPI_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define _LIB_TEST_HMM_UAPI_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Structure to pass to the HMM test driver to mimic a device accessing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * system memory and ZONE_DEVICE private memory through device page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * @addr: (in) user address the device will read/write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * @ptr: (in) user address where device data is copied to/from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * @npages: (in) number of pages to read/write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * @cpages: (out) number of pages copied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * @faults: (out) number of device page faults seen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct hmm_dmirror_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) __u64 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) __u64 ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) __u64 npages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) __u64 cpages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) __u64 faults;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* Expose the address space of the calling process through hmm device file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define HMM_DMIRROR_READ _IOWR('H', 0x00, struct hmm_dmirror_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define HMM_DMIRROR_WRITE _IOWR('H', 0x01, struct hmm_dmirror_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define HMM_DMIRROR_MIGRATE _IOWR('H', 0x02, struct hmm_dmirror_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define HMM_DMIRROR_SNAPSHOT _IOWR('H', 0x03, struct hmm_dmirror_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * HMM_DMIRROR_PROT_ERROR: no valid mirror PTE for this page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * HMM_DMIRROR_PROT_NONE: unpopulated PTE or PTE with no access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * HMM_DMIRROR_PROT_READ: read-only PTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * HMM_DMIRROR_PROT_WRITE: read/write PTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * HMM_DMIRROR_PROT_PMD: PMD sized page is fully mapped by same permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * HMM_DMIRROR_PROT_PUD: PUD sized page is fully mapped by same permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * HMM_DMIRROR_PROT_ZERO: special read-only zero page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL: Migrated device private page on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * device the ioctl() is made
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE: Migrated device private page on some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * other device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) HMM_DMIRROR_PROT_ERROR = 0xFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) HMM_DMIRROR_PROT_NONE = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) HMM_DMIRROR_PROT_READ = 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) HMM_DMIRROR_PROT_WRITE = 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) HMM_DMIRROR_PROT_PMD = 0x04,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) HMM_DMIRROR_PROT_PUD = 0x08,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) HMM_DMIRROR_PROT_ZERO = 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL = 0x20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE = 0x30,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #endif /* _LIB_TEST_HMM_UAPI_H */