xref: /linux/arch/powerpc/platforms/pseries/vas.h (revision 497e6b37b0099dc415578488287fd84fb74433eb)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright 2020-21 IBM Corp.
4  */
5 
6 #ifndef _VAS_H
7 #define _VAS_H
8 #include <asm/vas.h>
9 #include <linux/mutex.h>
10 #include <linux/stringify.h>
11 
12 /*
13  * VAS window modify flags
14  */
15 #define VAS_MOD_WIN_CLOSE	PPC_BIT(0)
16 #define VAS_MOD_WIN_JOBS_KILL	PPC_BIT(1)
17 #define VAS_MOD_WIN_DR		PPC_BIT(3)
18 #define VAS_MOD_WIN_PR		PPC_BIT(4)
19 #define VAS_MOD_WIN_SF		PPC_BIT(5)
20 #define VAS_MOD_WIN_TA		PPC_BIT(6)
21 #define VAS_MOD_WIN_FLAGS	(VAS_MOD_WIN_JOBS_KILL | VAS_MOD_WIN_DR | \
22 				VAS_MOD_WIN_PR | VAS_MOD_WIN_SF)
23 
24 #define VAS_WIN_ACTIVE		0x0
25 #define VAS_WIN_CLOSED		0x1
26 #define VAS_WIN_INACTIVE	0x2	/* Inactive due to HW failure */
27 /* Process of being modified, deallocated, or quiesced */
28 #define VAS_WIN_MOD_IN_PROCESS	0x3
29 
30 #define VAS_COPY_PASTE_USER_MODE	0x00000001
31 #define VAS_COP_OP_USER_MODE		0x00000010
32 
33 #define VAS_GZIP_QOS_CAPABILITIES	0x56516F73477A6970
34 #define VAS_GZIP_DEFAULT_CAPABILITIES	0x56446566477A6970
35 
36 enum vas_migrate_action {
37 	VAS_SUSPEND,
38 	VAS_RESUME,
39 };
40 
41 /*
42  * Co-processor feature - GZIP QoS windows or GZIP default windows
43  */
44 enum vas_cop_feat_type {
45 	VAS_GZIP_QOS_FEAT_TYPE,
46 	VAS_GZIP_DEF_FEAT_TYPE,
47 	VAS_MAX_FEAT_TYPE,
48 };
49 
50 /*
51  * Use to get feature specific capabilities from the
52  * hypervisor.
53  */
54 struct hv_vas_cop_feat_caps {
55 	__be64	descriptor;
56 	u8	win_type;		/* Default or QoS type */
57 	u8	user_mode;
58 	__be16	max_lpar_creds;
59 	__be16	max_win_creds;
60 	union {
61 		__be16	reserved;
62 		__be16	def_lpar_creds; /* Used for default capabilities */
63 	};
64 	__be16	target_lpar_creds;
65 } __packed __aligned(0x1000);
66 
67 /*
68  * Feature specific (QoS or default) capabilities.
69  */
70 struct vas_cop_feat_caps {
71 	u64		descriptor;
72 	u8		win_type;	/* Default or QoS type */
73 	u8		user_mode;	/* User mode copy/paste or COP HCALL */
74 	u16		max_lpar_creds;	/* Max credits available in LPAR */
75 	/* Max credits can be assigned per window */
76 	u16		max_win_creds;
77 	union {
78 		u16	reserved;	/* Used for QoS credit type */
79 		u16	def_lpar_creds; /* Used for default credit type */
80 	};
81 	/* Total LPAR available credits. Can be different from max LPAR */
82 	/* credits due to DLPAR operation */
83 	atomic_t	nr_total_credits;	/* Total credits assigned to LPAR */
84 	atomic_t	nr_used_credits;	/* Used credits so far */
85 };
86 
87 /*
88  * Feature (QoS or Default) specific to store capabilities and
89  * the list of open windows.
90  */
91 struct vas_caps {
92 	struct vas_cop_feat_caps caps;
93 	struct list_head list;	/* List of open windows */
94 	int nr_close_wins;	/* closed windows in the hypervisor for DLPAR */
95 	int nr_open_windows;	/* Number of successful open windows */
96 	u8 feat;		/* Feature type */
97 };
98 
99 /*
100  * To get window information from the hypervisor.
101  */
102 struct hv_vas_win_lpar {
103 	__be16	version;
104 	u8	win_type;
105 	u8	status;
106 	__be16	credits;	/* No of credits assigned to this window */
107 	__be16	reserved;
108 	__be32	pid;		/* LPAR Process ID */
109 	__be32	tid;		/* LPAR Thread ID */
110 	__be64	win_addr;	/* Paste address */
111 	__be32	interrupt;	/* Interrupt when NX request completes */
112 	__be32	fault;		/* Interrupt when NX sees fault */
113 	/* Associativity Domain Identifiers as returned in */
114 	/* H_HOME_NODE_ASSOCIATIVITY */
115 	__be64	domain[6];
116 	__be64	win_util;	/* Number of bytes processed */
117 } __packed __aligned(0x1000);
118 
119 struct pseries_vas_window {
120 	struct vas_window vas_win;
121 	u64 win_addr;		/* Physical paste address */
122 	u8 win_type;		/* QoS or Default window */
123 	u32 complete_irq;	/* Completion interrupt */
124 	u32 fault_irq;		/* Fault interrupt */
125 	u64 domain[6];		/* Associativity domain Ids */
126 				/* this window is allocated */
127 	u64 util;
128 	u32 pid;		/* PID associated with this window */
129 
130 	/* List of windows opened which is used for LPM */
131 	struct list_head win_list;
132 	u64 flags;
133 	char *name;
134 	int fault_virq;
135 	atomic_t pending_faults; /* Number of pending faults */
136 };
137 
138 int sysfs_add_vas_caps(struct vas_cop_feat_caps *caps);
139 int vas_reconfig_capabilties(u8 type, int new_nr_creds);
140 int __init sysfs_pseries_vas_init(struct vas_all_caps *vas_caps);
141 
142 #ifdef CONFIG_PPC_VAS
143 int vas_migration_handler(int action);
144 int pseries_vas_dlpar_cpu(void);
145 #else
146 static inline int vas_migration_handler(int action)
147 {
148 	return 0;
149 }
150 static inline int pseries_vas_dlpar_cpu(void)
151 {
152 	return 0;
153 }
154 #endif
155 #endif /* _VAS_H */
156