forked from torvalds/linux
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a straightforward IOCTL that provides a mechanism for userspace to query the supported memory device commands. CXL commands as they appear to userspace are described as part of the UAPI kerneldoc. The command list returned via this IOCTL will contain the full set of commands that the driver supports, however, some of those commands may not be available for use by userspace. Memory device commands are specified in 8.2.9 of the CXL 2.0 specification. They are submitted through a mailbox mechanism specified in 8.2.8.4. Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
- Loading branch information
1 parent
659d84f
commit 906dc07
Showing
5 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ | ||
/* | ||
* CXL IOCTLs for Memory Devices | ||
*/ | ||
|
||
#ifndef _UAPI_CXL_MEM_H_ | ||
#define _UAPI_CXL_MEM_H_ | ||
|
||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* DOC: UAPI | ||
* | ||
* CXL memory devices expose UAPI to have a standard user interface. | ||
* Userspace can refer to these structure definitions and UAPI formats | ||
* to communicate to driver. The commands themselves are somewhat obfuscated | ||
* with macro magic. They have the form CXL_MEM_COMMAND_ID_<name>. | ||
* | ||
* For example "CXL_MEM_COMMAND_ID_INVALID" | ||
* | ||
* Not all of all commands that the driver supports are always available for use | ||
* by userspace. Userspace must check the results from the QUERY command in | ||
* order to determine the live set of commands. | ||
*/ | ||
|
||
#define CXL_MEM_QUERY_COMMANDS _IOR(0xCE, 1, struct cxl_mem_query_commands) | ||
|
||
#undef CMDS | ||
#define CMDS \ | ||
C(INVALID, "Invalid Command"), \ | ||
C(IDENTIFY, "Identify Command"), \ | ||
C(MAX, "Last command") | ||
#undef C | ||
#define C(a, b) CXL_MEM_COMMAND_ID_##a | ||
|
||
enum { CMDS }; | ||
|
||
/** | ||
* struct cxl_command_info - Command information returned from a query. | ||
* @id: ID number for the command. | ||
* @flags: Flags that specify command behavior. | ||
* | ||
* * %CXL_MEM_COMMAND_FLAG_KERNEL: This command is reserved for exclusive | ||
* kernel use. | ||
* * %CXL_MEM_COMMAND_FLAG_MUTEX: This command may require coordination with | ||
* the kernel in order to complete successfully. | ||
* | ||
* @size_in: Expected input size, or -1 if variable length. | ||
* @size_out: Expected output size, or -1 if variable length. | ||
* | ||
* Represents a single command that is supported by both the driver and the | ||
* hardware. The is returned as part of an array from the query ioctl. The | ||
* following would be a command named "foobar" that takes a variable length | ||
* input and returns 0 bytes of output. | ||
* | ||
* - @id = 10 | ||
* - @flags = CXL_MEM_COMMAND_FLAG_MUTEX | ||
* - @size_in = -1 | ||
* - @size_out = 0 | ||
* | ||
* See struct cxl_mem_query_commands. | ||
*/ | ||
struct cxl_command_info { | ||
__u32 id; | ||
|
||
__u32 flags; | ||
#define CXL_MEM_COMMAND_FLAG_NONE 0 | ||
#define CXL_MEM_COMMAND_FLAG_KERNEL BIT(0) | ||
#define CXL_MEM_COMMAND_FLAG_MUTEX BIT(1) | ||
|
||
__s32 size_in; | ||
__s32 size_out; | ||
}; | ||
|
||
/** | ||
* struct cxl_mem_query_commands - Query supported commands. | ||
* @n_commands: In/out parameter. When @n_commands is > 0, the driver will | ||
* return min(num_support_commands, n_commands). When @n_commands | ||
* is 0, driver will return the number of total supported commands. | ||
* @rsvd: Reserved for future use. | ||
* @commands: Output array of supported commands. This array must be allocated | ||
* by userspace to be at least min(num_support_commands, @n_commands) | ||
* | ||
* Allow userspace to query the available commands supported by both the driver, | ||
* and the hardware. Commands that aren't supported by either the driver, or the | ||
* hardware are not returned in the query. | ||
* | ||
* Examples: | ||
* | ||
* - { .n_commands = 0 } // Get number of supported commands | ||
* - { .n_commands = 15, .commands = buf } // Return first 15 (or less) | ||
* supported commands | ||
* | ||
* See struct cxl_command_info. | ||
*/ | ||
struct cxl_mem_query_commands { | ||
/* | ||
* Input: Number of commands to return (space allocated by user) | ||
* Output: Number of commands supported by the driver/hardware | ||
* | ||
* If n_commands is 0, kernel will only return number of commands and | ||
* not try to populate commands[], thus allowing userspace to know how | ||
* much space to allocate | ||
*/ | ||
__u32 n_commands; | ||
__u32 rsvd; | ||
|
||
struct cxl_command_info __user commands[]; /* out: supported commands */ | ||
}; | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
|
||
#endif |