1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright 2016-17 IBM Corp.
6 #ifndef _ASM_POWERPC_VAS_H
7 #define _ASM_POWERPC_VAS_H
8 #include <linux/sched/mm.h>
9 #include <linux/mmu_context.h>
10 #include <asm/icswx.h>
11 #include <uapi/asm/vas-api.h>
14 * Min and max FIFO sizes are based on Version 1.05 Section 3.1.4.25
15 * (Local FIFO Size Register) of the VAS workbook.
17 #define VAS_RX_FIFO_SIZE_MIN (1 << 10) /* 1KB */
18 #define VAS_RX_FIFO_SIZE_MAX (8 << 20) /* 8MB */
21 * Threshold Control Mode: Have paste operation fail if the number of
22 * requests in receive FIFO exceeds a threshold.
24 * NOTE: No special error code yet if paste is rejected because of these
25 * limits. So users can't distinguish between this and other errors.
27 #define VAS_THRESH_DISABLED 0
28 #define VAS_THRESH_FIFO_GT_HALF_FULL 1
29 #define VAS_THRESH_FIFO_GT_QTR_FULL 2
30 #define VAS_THRESH_FIFO_GT_EIGHTH_FULL 3
33 * VAS window Linux status bits
35 #define VAS_WIN_ACTIVE 0x0 /* Used in platform independent */
37 /* Window is closed in the hypervisor due to lost credit */
38 #define VAS_WIN_NO_CRED_CLOSE 0x00000001
39 /* Window is closed due to migration */
40 #define VAS_WIN_MIGRATE_CLOSE 0x00000002
45 #define GET_FIELD(m, v) (((v) & (m)) >> MASK_LSH(m))
46 #define MASK_LSH(m) (__builtin_ffsl(m) - 1)
47 #define SET_FIELD(m, v, val) \
48 (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_LSH(m)) & (m)))
51 * Co-processor Engine type.
56 VAS_COP_TYPE_842_HIPRI
,
58 VAS_COP_TYPE_GZIP_HIPRI
,
64 * User space VAS windows are opened by tasks and take references
65 * to pid and mm until windows are closed.
66 * Stores pid, mm, and tgid for each window.
68 struct vas_user_win_ref
{
69 struct pid
*pid
; /* PID of owner */
70 struct pid
*tgid
; /* Thread group ID of owner */
71 struct mm_struct
*mm
; /* Linux process mm_struct */
72 struct mutex mmap_mutex
; /* protects paste address mmap() */
73 /* with DLPAR close/open windows */
74 struct vm_area_struct
*vma
; /* Save VMA and used in DLPAR ops */
78 * Common VAS window struct on PowerNV and PowerVM
82 u32 wcreds_max
; /* Window credits */
83 u32 status
; /* Window status used in OS */
84 enum vas_cop_type cop
;
85 struct vas_user_win_ref task_ref
;
87 struct dentry
*dbgdir
;
91 * User space window operations used for powernv and powerVM
93 struct vas_user_win_ops
{
94 struct vas_window
* (*open_win
)(int vas_id
, u64 flags
,
96 u64 (*paste_addr
)(struct vas_window
*);
97 int (*close_win
)(struct vas_window
*);
100 static inline void put_vas_user_win_ref(struct vas_user_win_ref
*ref
)
102 /* Drop references to pid, tgid, and mm */
109 static inline void vas_user_win_add_mm_context(struct vas_user_win_ref
*ref
)
111 mm_context_add_vas_window(ref
->mm
);
113 * Even a process that has no foreign real address mapping can
114 * use an unpaired COPY instruction (to no real effect). Issue
115 * CP_ABORT to clear any pending COPY and prevent a covert
118 * __switch_to() will issue CP_ABORT on future context switches
119 * if process / thread has any open VAS window (Use
120 * current->mm->context.vas_windows).
122 asm volatile(PPC_CP_ABORT
);
126 * Receive window attributes specified by the (in-kernel) owner of window.
128 struct vas_rx_win_attr
{
137 bool tx_win_ord_mode
;
138 bool rx_win_ord_mode
;
156 * Window attributes specified by the in-kernel owner of a send window.
158 struct vas_tx_win_attr
{
159 enum vas_cop_type cop
;
162 int pidr
; /* hardware PID (from SPRN_PID) */
164 int rsvd_txbuf_count
;
170 bool rsvd_txbuf_enable
;
173 bool tx_win_ord_mode
;
174 bool rx_win_ord_mode
;
177 #ifdef CONFIG_PPC_POWERNV
179 * Helper to map a chip id to VAS id.
180 * For POWER9, this is a 1:1 mapping. In the future this maybe a 1:N
181 * mapping in which case, we will need to update this helper.
183 * Return the VAS id or -1 if no matching vasid is found.
185 int chip_to_vas_id(int chipid
);
188 * Helper to initialize receive window attributes to defaults for an
191 void vas_init_rx_win_attr(struct vas_rx_win_attr
*rxattr
, enum vas_cop_type cop
);
194 * Open a VAS receive window for the instance of VAS identified by @vasid
195 * Use @attr to initialize the attributes of the window.
197 * Return a handle to the window or ERR_PTR() on error.
199 struct vas_window
*vas_rx_win_open(int vasid
, enum vas_cop_type cop
,
200 struct vas_rx_win_attr
*attr
);
203 * Helper to initialize send window attributes to defaults for an NX window.
205 extern void vas_init_tx_win_attr(struct vas_tx_win_attr
*txattr
,
206 enum vas_cop_type cop
);
209 * Open a VAS send window for the instance of VAS identified by @vasid
210 * and the co-processor type @cop. Use @attr to initialize attributes
213 * Note: The instance of VAS must already have an open receive window for
214 * the coprocessor type @cop.
216 * Return a handle to the send window or ERR_PTR() on error.
218 struct vas_window
*vas_tx_win_open(int vasid
, enum vas_cop_type cop
,
219 struct vas_tx_win_attr
*attr
);
222 * Close the send or receive window identified by @win. For receive windows
223 * return -EAGAIN if there are active send windows attached to this receive
226 int vas_win_close(struct vas_window
*win
);
229 * Copy the co-processor request block (CRB) @crb into the local L2 cache.
231 int vas_copy_crb(void *crb
, int offset
);
234 * Paste a previously copied CRB (see vas_copy_crb()) from the L2 cache to
235 * the hardware address associated with the window @win. @re is expected/
236 * assumed to be true for NX windows.
238 int vas_paste_crb(struct vas_window
*win
, int offset
, bool re
);
240 int vas_register_api_powernv(struct module
*mod
, enum vas_cop_type cop_type
,
242 void vas_unregister_api_powernv(void);
245 #ifdef CONFIG_PPC_PSERIES
247 /* VAS Capabilities */
248 #define VAS_GZIP_QOS_FEAT 0x1
249 #define VAS_GZIP_DEF_FEAT 0x2
250 #define VAS_GZIP_QOS_FEAT_BIT PPC_BIT(VAS_GZIP_QOS_FEAT) /* Bit 1 */
251 #define VAS_GZIP_DEF_FEAT_BIT PPC_BIT(VAS_GZIP_DEF_FEAT) /* Bit 2 */
253 /* NX Capabilities */
254 #define VAS_NX_GZIP_FEAT 0x1
255 #define VAS_NX_GZIP_FEAT_BIT PPC_BIT(VAS_NX_GZIP_FEAT) /* Bit 1 */
258 * These structs are used to retrieve overall VAS capabilities that
259 * the hypervisor provides.
261 struct hv_vas_all_caps
{
264 } __packed
__aligned(0x1000);
266 struct vas_all_caps
{
271 int h_query_vas_capabilities(const u64 hcall
, u8 query_type
, u64 result
);
272 int vas_register_api_pseries(struct module
*mod
,
273 enum vas_cop_type cop_type
, const char *name
);
274 void vas_unregister_api_pseries(void);
278 * Register / unregister coprocessor type to VAS API which will be exported
279 * to user space. Applications can use this API to open / close window
280 * which can be used to send / receive requests directly to cooprcessor.
282 * Only NX GZIP coprocessor type is supported now, but this API can be
283 * used for others in future.
285 int vas_register_coproc_api(struct module
*mod
, enum vas_cop_type cop_type
,
287 const struct vas_user_win_ops
*vops
);
288 void vas_unregister_coproc_api(void);
290 int get_vas_user_win_ref(struct vas_user_win_ref
*task_ref
);
291 void vas_update_csb(struct coprocessor_request_block
*crb
,
292 struct vas_user_win_ref
*task_ref
);
293 void vas_dump_crb(struct coprocessor_request_block
*crb
);
294 #endif /* __ASM_POWERPC_VAS_H */