Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools headers: Import iosubmit_cmds512()

Import iosubmit_cmds512() from arch/x86/include/asm/io.h into tools/ so
it can be used by VFIO selftests to interact with Intel DSA devices.

Also pull in movdir64b() from arch/x86/include/asm/special_insns.h into
tools/, which is the underlying instruction used by iosubmit_cmds512().

Changes made when importing: None

Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: David Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20250822212518.4156428-21-dmatlack@google.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

David Matlack and committed by
Alex Williamson
3fe30577 2223587d

+53
+26
tools/arch/x86/include/asm/io.h
··· 4 4 5 5 #include <linux/compiler.h> 6 6 #include <linux/types.h> 7 + #include "special_insns.h" 7 8 8 9 #define build_mmio_read(name, size, type, reg, barrier) \ 9 10 static inline type name(const volatile void __iomem *addr) \ ··· 72 71 #endif /* __x86_64__ */ 73 72 74 73 #include <asm-generic/io.h> 74 + 75 + /** 76 + * iosubmit_cmds512 - copy data to single MMIO location, in 512-bit units 77 + * @dst: destination, in MMIO space (must be 512-bit aligned) 78 + * @src: source 79 + * @count: number of 512 bits quantities to submit 80 + * 81 + * Submit data from kernel space to MMIO space, in units of 512 bits at a 82 + * time. Order of access is not guaranteed, nor is a memory barrier 83 + * performed afterwards. 84 + * 85 + * Warning: Do not use this helper unless your driver has checked that the CPU 86 + * instruction is supported on the platform. 87 + */ 88 + static inline void iosubmit_cmds512(void __iomem *dst, const void *src, 89 + size_t count) 90 + { 91 + const u8 *from = src; 92 + const u8 *end = from + count * 64; 93 + 94 + while (from < end) { 95 + movdir64b(dst, from); 96 + from += 64; 97 + } 98 + } 75 99 76 100 #endif /* _TOOLS_ASM_X86_IO_H */
+27
tools/arch/x86/include/asm/special_insns.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _TOOLS_ASM_X86_SPECIAL_INSNS_H 3 + #define _TOOLS_ASM_X86_SPECIAL_INSNS_H 4 + 5 + /* The dst parameter must be 64-bytes aligned */ 6 + static inline void movdir64b(void *dst, const void *src) 7 + { 8 + const struct { char _[64]; } *__src = src; 9 + struct { char _[64]; } *__dst = dst; 10 + 11 + /* 12 + * MOVDIR64B %(rdx), rax. 13 + * 14 + * Both __src and __dst must be memory constraints in order to tell the 15 + * compiler that no other memory accesses should be reordered around 16 + * this one. 17 + * 18 + * Also, both must be supplied as lvalues because this tells 19 + * the compiler what the object is (its size) the instruction accesses. 20 + * I.e., not the pointers but what they point to, thus the deref'ing '*'. 21 + */ 22 + asm volatile(".byte 0x66, 0x0f, 0x38, 0xf8, 0x02" 23 + : "+m" (*__dst) 24 + : "m" (*__src), "a" (__dst), "d" (__src)); 25 + } 26 + 27 + #endif /* _TOOLS_ASM_X86_SPECIAL_INSNS_H */