cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

cxl_mem.h (6489B)


      1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
      2/*
      3 * CXL IOCTLs for Memory Devices
      4 */
      5
      6#ifndef _UAPI_CXL_MEM_H_
      7#define _UAPI_CXL_MEM_H_
      8
      9#include <linux/types.h>
     10
     11/**
     12 * DOC: UAPI
     13 *
     14 * Not all of all commands that the driver supports are always available for use
     15 * by userspace. Userspace must check the results from the QUERY command in
     16 * order to determine the live set of commands.
     17 */
     18
     19#define CXL_MEM_QUERY_COMMANDS _IOR(0xCE, 1, struct cxl_mem_query_commands)
     20#define CXL_MEM_SEND_COMMAND _IOWR(0xCE, 2, struct cxl_send_command)
     21
     22#define CXL_CMDS                                                          \
     23	___C(INVALID, "Invalid Command"),                                 \
     24	___C(IDENTIFY, "Identify Command"),                               \
     25	___C(RAW, "Raw device command"),                                  \
     26	___C(GET_SUPPORTED_LOGS, "Get Supported Logs"),                   \
     27	___C(GET_FW_INFO, "Get FW Info"),                                 \
     28	___C(GET_PARTITION_INFO, "Get Partition Information"),            \
     29	___C(GET_LSA, "Get Label Storage Area"),                          \
     30	___C(GET_HEALTH_INFO, "Get Health Info"),                         \
     31	___C(GET_LOG, "Get Log"),                                         \
     32	___C(SET_PARTITION_INFO, "Set Partition Information"),            \
     33	___C(SET_LSA, "Set Label Storage Area"),                          \
     34	___C(GET_ALERT_CONFIG, "Get Alert Configuration"),                \
     35	___C(SET_ALERT_CONFIG, "Set Alert Configuration"),                \
     36	___C(GET_SHUTDOWN_STATE, "Get Shutdown State"),                   \
     37	___C(SET_SHUTDOWN_STATE, "Set Shutdown State"),                   \
     38	___C(GET_POISON, "Get Poison List"),                              \
     39	___C(INJECT_POISON, "Inject Poison"),                             \
     40	___C(CLEAR_POISON, "Clear Poison"),                               \
     41	___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"),         \
     42	___C(SCAN_MEDIA, "Scan Media"),                                   \
     43	___C(GET_SCAN_MEDIA, "Get Scan Media Results"),                   \
     44	___C(MAX, "invalid / last command")
     45
     46#define ___C(a, b) CXL_MEM_COMMAND_ID_##a
     47enum { CXL_CMDS };
     48
     49#undef ___C
     50#define ___C(a, b) { b }
     51static const struct {
     52	const char *name;
     53} cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS };
     54
     55/*
     56 * Here's how this actually breaks out:
     57 * cxl_command_names[] = {
     58 *	[CXL_MEM_COMMAND_ID_INVALID] = { "Invalid Command" },
     59 *	[CXL_MEM_COMMAND_ID_IDENTIFY] = { "Identify Command" },
     60 *	...
     61 *	[CXL_MEM_COMMAND_ID_MAX] = { "invalid / last command" },
     62 * };
     63 */
     64
     65#undef ___C
     66
     67/**
     68 * struct cxl_command_info - Command information returned from a query.
     69 * @id: ID number for the command.
     70 * @flags: Flags that specify command behavior.
     71 * @size_in: Expected input size, or ~0 if variable length.
     72 * @size_out: Expected output size, or ~0 if variable length.
     73 *
     74 * Represents a single command that is supported by both the driver and the
     75 * hardware. This is returned as part of an array from the query ioctl. The
     76 * following would be a command that takes a variable length input and returns 0
     77 * bytes of output.
     78 *
     79 *  - @id = 10
     80 *  - @flags = 0
     81 *  - @size_in = ~0
     82 *  - @size_out = 0
     83 *
     84 * See struct cxl_mem_query_commands.
     85 */
     86struct cxl_command_info {
     87	__u32 id;
     88
     89	__u32 flags;
     90#define CXL_MEM_COMMAND_FLAG_MASK GENMASK(0, 0)
     91
     92	__u32 size_in;
     93	__u32 size_out;
     94};
     95
     96/**
     97 * struct cxl_mem_query_commands - Query supported commands.
     98 * @n_commands: In/out parameter. When @n_commands is > 0, the driver will
     99 *		return min(num_support_commands, n_commands). When @n_commands
    100 *		is 0, driver will return the number of total supported commands.
    101 * @rsvd: Reserved for future use.
    102 * @commands: Output array of supported commands. This array must be allocated
    103 *            by userspace to be at least min(num_support_commands, @n_commands)
    104 *
    105 * Allow userspace to query the available commands supported by both the driver,
    106 * and the hardware. Commands that aren't supported by either the driver, or the
    107 * hardware are not returned in the query.
    108 *
    109 * Examples:
    110 *
    111 *  - { .n_commands = 0 } // Get number of supported commands
    112 *  - { .n_commands = 15, .commands = buf } // Return first 15 (or less)
    113 *    supported commands
    114 *
    115 *  See struct cxl_command_info.
    116 */
    117struct cxl_mem_query_commands {
    118	/*
    119	 * Input: Number of commands to return (space allocated by user)
    120	 * Output: Number of commands supported by the driver/hardware
    121	 *
    122	 * If n_commands is 0, kernel will only return number of commands and
    123	 * not try to populate commands[], thus allowing userspace to know how
    124	 * much space to allocate
    125	 */
    126	__u32 n_commands;
    127	__u32 rsvd;
    128
    129	struct cxl_command_info __user commands[]; /* out: supported commands */
    130};
    131
    132/**
    133 * struct cxl_send_command - Send a command to a memory device.
    134 * @id: The command to send to the memory device. This must be one of the
    135 *	commands returned by the query command.
    136 * @flags: Flags for the command (input).
    137 * @raw: Special fields for raw commands
    138 * @raw.opcode: Opcode passed to hardware when using the RAW command.
    139 * @raw.rsvd: Must be zero.
    140 * @rsvd: Must be zero.
    141 * @retval: Return value from the memory device (output).
    142 * @in: Parameters associated with input payload.
    143 * @in.size: Size of the payload to provide to the device (input).
    144 * @in.rsvd: Must be zero.
    145 * @in.payload: Pointer to memory for payload input, payload is little endian.
    146 * @out: Parameters associated with output payload.
    147 * @out.size: Size of the payload received from the device (input/output). This
    148 *	      field is filled in by userspace to let the driver know how much
    149 *	      space was allocated for output. It is populated by the driver to
    150 *	      let userspace know how large the output payload actually was.
    151 * @out.rsvd: Must be zero.
    152 * @out.payload: Pointer to memory for payload output, payload is little endian.
    153 *
    154 * Mechanism for userspace to send a command to the hardware for processing. The
    155 * driver will do basic validation on the command sizes. In some cases even the
    156 * payload may be introspected. Userspace is required to allocate large enough
    157 * buffers for size_out which can be variable length in certain situations.
    158 */
    159struct cxl_send_command {
    160	__u32 id;
    161	__u32 flags;
    162	union {
    163		struct {
    164			__u16 opcode;
    165			__u16 rsvd;
    166		} raw;
    167		__u32 rsvd;
    168	};
    169	__u32 retval;
    170
    171	struct {
    172		__u32 size;
    173		__u32 rsvd;
    174		__u64 payload;
    175	} in;
    176
    177	struct {
    178		__u32 size;
    179		__u32 rsvd;
    180		__u64 payload;
    181	} out;
    182};
    183
    184#endif