Lines Matching refs:window

26  * Compute the paste address region for the window @window using the
29 void vas_win_paste_addr(struct vas_window *window, u64 *addr, int *len)
34 base = window->vinst->paste_base_addr;
35 shift = window->vinst->paste_win_id_shift;
36 winid = window->winid;
45 static inline void get_hvwc_mmio_bar(struct vas_window *window,
50 pbaddr = window->vinst->hvwc_bar_start;
51 *start = pbaddr + window->winid * VAS_HVWC_SIZE;
55 static inline void get_uwc_mmio_bar(struct vas_window *window,
60 pbaddr = window->vinst->uwc_bar_start;
61 *start = pbaddr + window->winid * VAS_UWC_SIZE;
66 * Map the paste bus address of the given send window into kernel address
77 name = kasprintf(GFP_KERNEL, "window-v%d-w%d", txwin->vinst->vas_id,
133 * Unmap the paste address region for a window.
135 static void unmap_paste_region(struct vas_window *window)
140 if (window->paste_kaddr) {
141 vas_win_paste_addr(window, &busaddr_start, &len);
142 unmap_region(window->paste_kaddr, busaddr_start, len);
143 window->paste_kaddr = NULL;
144 kfree(window->paste_addr_name);
145 window->paste_addr_name = NULL;
150 * Unmap the MMIO regions for a window. Hold the vas_mutex so we don't
151 * unmap when the window's debugfs dir is in use. This serializes close
152 * of a window even on another VAS instance but since its not a critical
156 static void unmap_winctx_mmio_bars(struct vas_window *window)
165 hvwc_map = window->hvwc_map;
166 window->hvwc_map = NULL;
168 uwc_map = window->uwc_map;
169 window->uwc_map = NULL;
174 get_hvwc_mmio_bar(window, &busaddr_start, &len);
179 get_uwc_mmio_bar(window, &busaddr_start, &len);
186 * OS/User Window Context (UWC) MMIO Base Address Region for the given window.
187 * Map these bus addresses and save the mapped kernel addresses in @window.
189 static int map_winctx_mmio_bars(struct vas_window *window)
194 get_hvwc_mmio_bar(window, &start, &len);
195 window->hvwc_map = map_mmio_region("HVWCM_Window", start, len);
197 get_uwc_mmio_bar(window, &start, &len);
198 window->uwc_map = map_mmio_region("UWCM_Window", start, len);
200 if (!window->hvwc_map || !window->uwc_map) {
201 unmap_winctx_mmio_bars(window);
210 * the window identified by @window.
212 * NOTE: We cannot really use a for loop to reset window context. Not all
213 * offsets in a window context are valid registers and the valid
217 static void reset_window_regs(struct vas_window *window)
219 write_hvwc_reg(window, VREG(LPID), 0ULL);
220 write_hvwc_reg(window, VREG(PID), 0ULL);
221 write_hvwc_reg(window, VREG(XLATE_MSR), 0ULL);
222 write_hvwc_reg(window, VREG(XLATE_LPCR), 0ULL);
223 write_hvwc_reg(window, VREG(XLATE_CTL), 0ULL);
224 write_hvwc_reg(window, VREG(AMR), 0ULL);
225 write_hvwc_reg(window, VREG(SEIDR), 0ULL);
226 write_hvwc_reg(window, VREG(FAULT_TX_WIN), 0ULL);
227 write_hvwc_reg(window, VREG(OSU_INTR_SRC_RA), 0ULL);
228 write_hvwc_reg(window, VREG(HV_INTR_SRC_RA), 0ULL);
229 write_hvwc_reg(window, VREG(PSWID), 0ULL);
230 write_hvwc_reg(window, VREG(LFIFO_BAR), 0ULL);
231 write_hvwc_reg(window, VREG(LDATA_STAMP_CTL), 0ULL);
232 write_hvwc_reg(window, VREG(LDMA_CACHE_CTL), 0ULL);
233 write_hvwc_reg(window, VREG(LRFIFO_PUSH), 0ULL);
234 write_hvwc_reg(window, VREG(CURR_MSG_COUNT), 0ULL);
235 write_hvwc_reg(window, VREG(LNOTIFY_AFTER_COUNT), 0ULL);
236 write_hvwc_reg(window, VREG(LRX_WCRED), 0ULL);
237 write_hvwc_reg(window, VREG(LRX_WCRED_ADDER), 0ULL);
238 write_hvwc_reg(window, VREG(TX_WCRED), 0ULL);
239 write_hvwc_reg(window, VREG(TX_WCRED_ADDER), 0ULL);
240 write_hvwc_reg(window, VREG(LFIFO_SIZE), 0ULL);
241 write_hvwc_reg(window, VREG(WINCTL), 0ULL);
242 write_hvwc_reg(window, VREG(WIN_STATUS), 0ULL);
243 write_hvwc_reg(window, VREG(WIN_CTX_CACHING_CTL), 0ULL);
244 write_hvwc_reg(window, VREG(TX_RSVD_BUF_COUNT), 0ULL);
245 write_hvwc_reg(window, VREG(LRFIFO_WIN_PTR), 0ULL);
246 write_hvwc_reg(window, VREG(LNOTIFY_CTL), 0ULL);
247 write_hvwc_reg(window, VREG(LNOTIFY_PID), 0ULL);
248 write_hvwc_reg(window, VREG(LNOTIFY_LPID), 0ULL);
249 write_hvwc_reg(window, VREG(LNOTIFY_TID), 0ULL);
250 write_hvwc_reg(window, VREG(LNOTIFY_SCOPE), 0ULL);
251 write_hvwc_reg(window, VREG(NX_UTIL_ADDER), 0ULL);
256 * The send and receive window credit adder registers are also
261 * write_uwc_reg(window, VREG(TX_WCRED_ADDER), 0ULL);
262 * write_uwc_reg(window, VREG(LRX_WCRED_ADDER), 0ULL);
267 * Initialize window context registers related to Address Translation.
273 static void init_xlate_regs(struct vas_window *window, bool user_win)
288 write_hvwc_reg(window, VREG(XLATE_MSR), val);
303 write_hvwc_reg(window, VREG(XLATE_LPCR), val);
314 write_hvwc_reg(window, VREG(XLATE_CTL), val);
321 write_hvwc_reg(window, VREG(AMR), val);
325 write_hvwc_reg(window, VREG(SEIDR), val);
329 * Initialize Reserved Send Buffer Count for the send window. It involves
346 * Initialize window context registers for a receive window.
347 * Except for caching control and marking window open, the registers
360 static void init_winctx_regs(struct vas_window *window,
366 reset_window_regs(window);
370 write_hvwc_reg(window, VREG(LPID), val);
374 write_hvwc_reg(window, VREG(PID), val);
376 init_xlate_regs(window, winctx->user_win);
380 write_hvwc_reg(window, VREG(FAULT_TX_WIN), val);
383 write_hvwc_reg(window, VREG(OSU_INTR_SRC_RA), 0ULL);
387 write_hvwc_reg(window, VREG(HV_INTR_SRC_RA), val);
391 write_hvwc_reg(window, VREG(PSWID), val);
393 write_hvwc_reg(window, VREG(SPARE1), 0ULL);
394 write_hvwc_reg(window, VREG(SPARE2), 0ULL);
395 write_hvwc_reg(window, VREG(SPARE3), 0ULL);
408 write_hvwc_reg(window, VREG(LFIFO_BAR), val);
412 write_hvwc_reg(window, VREG(LDATA_STAMP_CTL), val);
417 write_hvwc_reg(window, VREG(LDMA_CACHE_CTL), val);
419 write_hvwc_reg(window, VREG(LRFIFO_PUSH), 0ULL);
420 write_hvwc_reg(window, VREG(CURR_MSG_COUNT), 0ULL);
421 write_hvwc_reg(window, VREG(LNOTIFY_AFTER_COUNT), 0ULL);
425 write_hvwc_reg(window, VREG(LRX_WCRED), val);
429 write_hvwc_reg(window, VREG(TX_WCRED), val);
431 write_hvwc_reg(window, VREG(LRX_WCRED_ADDER), 0ULL);
432 write_hvwc_reg(window, VREG(TX_WCRED_ADDER), 0ULL);
438 write_hvwc_reg(window, VREG(LFIFO_SIZE), val);
440 /* Update window control and caching control registers last so
441 * we mark the window open only after fully initializing it and
445 write_hvwc_reg(window, VREG(WIN_STATUS), 0ULL);
447 init_rsvd_tx_buf_count(window, winctx);
449 /* for a send window, point to the matching receive window */
452 write_hvwc_reg(window, VREG(LRFIFO_WIN_PTR), val);
454 write_hvwc_reg(window, VREG(SPARE4), 0ULL);
461 write_hvwc_reg(window, VREG(LNOTIFY_CTL), val);
465 write_hvwc_reg(window, VREG(LNOTIFY_PID), val);
469 write_hvwc_reg(window, VREG(LNOTIFY_LPID), val);
473 write_hvwc_reg(window, VREG(LNOTIFY_TID), val);
478 write_hvwc_reg(window, VREG(LNOTIFY_SCOPE), val);
482 write_hvwc_reg(window, VREG(SPARE5), 0ULL);
483 write_hvwc_reg(window, VREG(NX_UTIL_ADDER), 0ULL);
484 write_hvwc_reg(window, VREG(SPARE6), 0ULL);
486 /* Finally, push window context to memory and... */
489 write_hvwc_reg(window, VREG(WIN_CTX_CACHING_CTL), val);
491 /* ... mark the window open for business */
502 write_hvwc_reg(window, VREG(WINCTL), val);
522 static void vas_window_free(struct vas_window *window)
524 int winid = window->winid;
525 struct vas_instance *vinst = window->vinst;
527 unmap_winctx_mmio_bars(window);
529 vas_window_free_dbgdir(window);
531 kfree(window);
539 struct vas_window *window;
545 window = kzalloc(sizeof(*window), GFP_KERNEL);
546 if (!window)
549 window->vinst = vinst;
550 window->winid = winid;
552 if (map_winctx_mmio_bars(window))
555 vas_window_init_dbgdir(window);
557 return window;
560 kfree(window);
567 /* Better not be a send window! */
574 * Find the user space receive window given the @pswid.
577 * - The window must refer to an OPEN, FTW, RECEIVE window.
600 * Get the VAS receive window associated with NX engine identified
628 * looking up a window by its id. It is used to look up send windows
634 * entries and is used to look up a receive window by its
637 * Here, we save @window in the ->windows[] table. If it is a receive
638 * window, we also save the window in the ->rxwin[] table.
641 struct vas_window *window)
643 int id = window->winid;
648 * There should only be one receive window for a coprocessor type
649 * unless its a user (FTW) window.
651 if (!window->user_win && !window->tx_win) {
652 WARN_ON_ONCE(vinst->rxwin[window->cop]);
653 vinst->rxwin[window->cop] = window;
657 vinst->windows[id] = window;
663 * Clear this window from the table(s) of windows for this VAS instance.
666 static void clear_vinst_win(struct vas_window *window)
668 int id = window->winid;
669 struct vas_instance *vinst = window->vinst;
673 if (!window->user_win && !window->tx_win) {
674 WARN_ON_ONCE(!vinst->rxwin[window->cop]);
675 vinst->rxwin[window->cop] = NULL;
678 WARN_ON_ONCE(vinst->windows[id] != window);
778 /* cannot be fault or user window if it is nx */
789 /* cannot be both fault and user window */
808 /* Rx window must be one of NX or Fault or User window. */
872 pr_devel("Unable to allocate memory for Rx window\n");
951 * IRQ and fault window setup is successful. Set fault window
952 * for the send window so that ready to handle faults.
1008 * receive window (applicable only to FTW windows), use the vasid
1009 * from that receive window.
1044 * If its a kernel send window, map the window address into the
1046 * mmap() to map the window into their address space.
1059 * Interrupt hanlder or fault window setup failed. Means
1061 * opening for user space tx window.
1071 * when the window is free by parent thread.
1094 * Process closes window during exit. In the case of
1096 * window and can exit without closing it. so takes tgid
1097 * reference until window closed to make sure tgid is not
1108 * if process / thread has any open VAS window (Use
1178 * If credit checking is enabled for this window, poll for the return
1179 * of window credits (i.e for NX engines to process any outstanding CRBs).
1181 * window, we should not have to wait for too long.
1190 static void poll_window_credits(struct vas_window *window)
1196 val = read_hvwc_reg(window, VREG(WINCTL));
1197 if (window->tx_win)
1205 if (window->tx_win) {
1206 val = read_hvwc_reg(window, VREG(TX_WCRED));
1209 val = read_hvwc_reg(window, VREG(LRX_WCRED));
1216 * TODO: Scan fault FIFO and invalidate CRBs points to this window
1220 if (creds < window->wcreds_max) {
1226 * Process can not close send window until all credits are
1231 vas_window_pid(window), window->winid,
1239 * Wait for the window to go to "not-busy" state. It should only take a
1240 * short time to queue a CRB, so window should not be busy for too long.
1243 static void poll_window_busy_state(struct vas_window *window)
1250 val = read_hvwc_reg(window, VREG(WIN_STATUS));
1263 vas_window_pid(window), window->winid, count);
1270 * Have the hardware cast a window out of cache and wait for it to
1273 * NOTE: It can take a relatively long time to cast the window context
1278 * - we re-initialize the window context when it is reassigned.
1283 * job to a worker thread, so the window close can proceed quickly.
1285 static void poll_window_castout(struct vas_window *window)
1291 * Unpin and close a window so no new requests are accepted and the
1292 * hardware can evict this window from cache if necessary.
1294 static void unpin_close_window(struct vas_window *window)
1298 val = read_hvwc_reg(window, VREG(WINCTL));
1301 write_hvwc_reg(window, VREG(WINCTL), val);
1305 * Close a window.
1307 * See Section 1.12.1 of VAS workbook v1.05 for details on closing window:
1311 * - Poll for return of window Credits (implies FIFO empty for Rx win?)
1312 * - Unpin and cast window context out of cache
1316 int vas_win_close(struct vas_window *window)
1318 if (!window)
1321 if (!window->tx_win && atomic_read(&window->num_txwins) != 0) {
1322 pr_devel("Attempting to close an active Rx window!\n");
1327 unmap_paste_region(window);
1329 poll_window_busy_state(window);
1331 unpin_close_window(window);
1333 poll_window_credits(window);
1335 clear_vinst_win(window);
1337 poll_window_castout(window);
1339 /* if send window, drop reference to matching receive window */
1340 if (window->tx_win) {
1341 if (window->user_win) {
1343 put_pid(window->pid);
1344 put_pid(window->tgid);
1345 if (window->mm) {
1346 mm_context_remove_vas_window(window->mm);
1347 mmdrop(window->mm);
1350 put_rx_win(window->rxwin);
1353 vas_window_free(window);
1360 * Return credit for the given window.
1361 * Send windows and fault window uses credit mechanism as follows:
1364 * - The default number of credits available for each send window is
1371 * credit on the specific send window after processing the fault CRB.
1373 * Fault window:
1378 * - The kernel with return credit on fault window after reading entry
1381 void vas_return_credit(struct vas_window *window, bool tx)
1386 if (tx) { /* send window */
1388 write_hvwc_reg(window, VREG(TX_WCRED_ADDER), val);
1391 write_hvwc_reg(window, VREG(LRX_WCRED_ADDER), val);
1398 struct vas_window *window;
1412 * If application closes the window before the hardware
1414 * for the pending requests. so the window must be active
1420 window = vinst->windows[winid];
1422 if (!window) {
1423 pr_err("PSWID decode: Could not find window for winid %d pswid %d vinst 0x%p\n",
1429 * Do some sanity checks on the decoded window. Window should be
1430 * NX GZIP user send window. FTW windows should not incur faults
1434 if (!window->tx_win || !window->user_win || !window->nx_win ||
1435 window->cop == VAS_COP_TYPE_FAULT ||
1436 window->cop == VAS_COP_TYPE_FTW) {
1438 winid, window->tx_win, window->user_win,
1439 window->nx_win, window->cop);
1443 return window;