Lines Matching refs:window
27 * Compute the paste address region for the window @window using the
30 void vas_win_paste_addr(struct pnv_vas_window *window, u64 *addr, int *len)
35 base = window->vinst->paste_base_addr;
36 shift = window->vinst->paste_win_id_shift;
37 winid = window->vas_win.winid;
46 static inline void get_hvwc_mmio_bar(struct pnv_vas_window *window,
51 pbaddr = window->vinst->hvwc_bar_start;
52 *start = pbaddr + window->vas_win.winid * VAS_HVWC_SIZE;
56 static inline void get_uwc_mmio_bar(struct pnv_vas_window *window,
61 pbaddr = window->vinst->uwc_bar_start;
62 *start = pbaddr + window->vas_win.winid * VAS_UWC_SIZE;
67 * Map the paste bus address of the given send window into kernel address
78 name = kasprintf(GFP_KERNEL, "window-v%d-w%d", txwin->vinst->vas_id,
134 * Unmap the paste address region for a window.
136 static void unmap_paste_region(struct pnv_vas_window *window)
141 if (window->paste_kaddr) {
142 vas_win_paste_addr(window, &busaddr_start, &len);
143 unmap_region(window->paste_kaddr, busaddr_start, len);
144 window->paste_kaddr = NULL;
145 kfree(window->paste_addr_name);
146 window->paste_addr_name = NULL;
151 * Unmap the MMIO regions for a window. Hold the vas_mutex so we don't
152 * unmap when the window's debugfs dir is in use. This serializes close
153 * of a window even on another VAS instance but since its not a critical
157 static void unmap_winctx_mmio_bars(struct pnv_vas_window *window)
166 hvwc_map = window->hvwc_map;
167 window->hvwc_map = NULL;
169 uwc_map = window->uwc_map;
170 window->uwc_map = NULL;
175 get_hvwc_mmio_bar(window, &busaddr_start, &len);
180 get_uwc_mmio_bar(window, &busaddr_start, &len);
187 * OS/User Window Context (UWC) MMIO Base Address Region for the given window.
188 * Map these bus addresses and save the mapped kernel addresses in @window.
190 static int map_winctx_mmio_bars(struct pnv_vas_window *window)
195 get_hvwc_mmio_bar(window, &start, &len);
196 window->hvwc_map = map_mmio_region("HVWCM_Window", start, len);
198 get_uwc_mmio_bar(window, &start, &len);
199 window->uwc_map = map_mmio_region("UWCM_Window", start, len);
201 if (!window->hvwc_map || !window->uwc_map) {
202 unmap_winctx_mmio_bars(window);
211 * the window identified by @window.
213 * NOTE: We cannot really use a for loop to reset window context. Not all
214 * offsets in a window context are valid registers and the valid
218 static void reset_window_regs(struct pnv_vas_window *window)
220 write_hvwc_reg(window, VREG(LPID), 0ULL);
221 write_hvwc_reg(window, VREG(PID), 0ULL);
222 write_hvwc_reg(window, VREG(XLATE_MSR), 0ULL);
223 write_hvwc_reg(window, VREG(XLATE_LPCR), 0ULL);
224 write_hvwc_reg(window, VREG(XLATE_CTL), 0ULL);
225 write_hvwc_reg(window, VREG(AMR), 0ULL);
226 write_hvwc_reg(window, VREG(SEIDR), 0ULL);
227 write_hvwc_reg(window, VREG(FAULT_TX_WIN), 0ULL);
228 write_hvwc_reg(window, VREG(OSU_INTR_SRC_RA), 0ULL);
229 write_hvwc_reg(window, VREG(HV_INTR_SRC_RA), 0ULL);
230 write_hvwc_reg(window, VREG(PSWID), 0ULL);
231 write_hvwc_reg(window, VREG(LFIFO_BAR), 0ULL);
232 write_hvwc_reg(window, VREG(LDATA_STAMP_CTL), 0ULL);
233 write_hvwc_reg(window, VREG(LDMA_CACHE_CTL), 0ULL);
234 write_hvwc_reg(window, VREG(LRFIFO_PUSH), 0ULL);
235 write_hvwc_reg(window, VREG(CURR_MSG_COUNT), 0ULL);
236 write_hvwc_reg(window, VREG(LNOTIFY_AFTER_COUNT), 0ULL);
237 write_hvwc_reg(window, VREG(LRX_WCRED), 0ULL);
238 write_hvwc_reg(window, VREG(LRX_WCRED_ADDER), 0ULL);
239 write_hvwc_reg(window, VREG(TX_WCRED), 0ULL);
240 write_hvwc_reg(window, VREG(TX_WCRED_ADDER), 0ULL);
241 write_hvwc_reg(window, VREG(LFIFO_SIZE), 0ULL);
242 write_hvwc_reg(window, VREG(WINCTL), 0ULL);
243 write_hvwc_reg(window, VREG(WIN_STATUS), 0ULL);
244 write_hvwc_reg(window, VREG(WIN_CTX_CACHING_CTL), 0ULL);
245 write_hvwc_reg(window, VREG(TX_RSVD_BUF_COUNT), 0ULL);
246 write_hvwc_reg(window, VREG(LRFIFO_WIN_PTR), 0ULL);
247 write_hvwc_reg(window, VREG(LNOTIFY_CTL), 0ULL);
248 write_hvwc_reg(window, VREG(LNOTIFY_PID), 0ULL);
249 write_hvwc_reg(window, VREG(LNOTIFY_LPID), 0ULL);
250 write_hvwc_reg(window, VREG(LNOTIFY_TID), 0ULL);
251 write_hvwc_reg(window, VREG(LNOTIFY_SCOPE), 0ULL);
252 write_hvwc_reg(window, VREG(NX_UTIL_ADDER), 0ULL);
257 * The send and receive window credit adder registers are also
262 * write_uwc_reg(window, VREG(TX_WCRED_ADDER), 0ULL);
263 * write_uwc_reg(window, VREG(LRX_WCRED_ADDER), 0ULL);
268 * Initialize window context registers related to Address Translation.
274 static void init_xlate_regs(struct pnv_vas_window *window, bool user_win)
289 write_hvwc_reg(window, VREG(XLATE_MSR), val);
304 write_hvwc_reg(window, VREG(XLATE_LPCR), val);
315 write_hvwc_reg(window, VREG(XLATE_CTL), val);
322 write_hvwc_reg(window, VREG(AMR), val);
326 write_hvwc_reg(window, VREG(SEIDR), val);
330 * Initialize Reserved Send Buffer Count for the send window. It involves
347 * Initialize window context registers for a receive window.
348 * Except for caching control and marking window open, the registers
361 static void init_winctx_regs(struct pnv_vas_window *window,
367 reset_window_regs(window);
371 write_hvwc_reg(window, VREG(LPID), val);
375 write_hvwc_reg(window, VREG(PID), val);
377 init_xlate_regs(window, winctx->user_win);
381 write_hvwc_reg(window, VREG(FAULT_TX_WIN), val);
384 write_hvwc_reg(window, VREG(OSU_INTR_SRC_RA), 0ULL);
388 write_hvwc_reg(window, VREG(HV_INTR_SRC_RA), val);
392 write_hvwc_reg(window, VREG(PSWID), val);
394 write_hvwc_reg(window, VREG(SPARE1), 0ULL);
395 write_hvwc_reg(window, VREG(SPARE2), 0ULL);
396 write_hvwc_reg(window, VREG(SPARE3), 0ULL);
409 write_hvwc_reg(window, VREG(LFIFO_BAR), val);
413 write_hvwc_reg(window, VREG(LDATA_STAMP_CTL), val);
418 write_hvwc_reg(window, VREG(LDMA_CACHE_CTL), val);
420 write_hvwc_reg(window, VREG(LRFIFO_PUSH), 0ULL);
421 write_hvwc_reg(window, VREG(CURR_MSG_COUNT), 0ULL);
422 write_hvwc_reg(window, VREG(LNOTIFY_AFTER_COUNT), 0ULL);
426 write_hvwc_reg(window, VREG(LRX_WCRED), val);
430 write_hvwc_reg(window, VREG(TX_WCRED), val);
432 write_hvwc_reg(window, VREG(LRX_WCRED_ADDER), 0ULL);
433 write_hvwc_reg(window, VREG(TX_WCRED_ADDER), 0ULL);
439 write_hvwc_reg(window, VREG(LFIFO_SIZE), val);
441 /* Update window control and caching control registers last so
442 * we mark the window open only after fully initializing it and
446 write_hvwc_reg(window, VREG(WIN_STATUS), 0ULL);
448 init_rsvd_tx_buf_count(window, winctx);
450 /* for a send window, point to the matching receive window */
453 write_hvwc_reg(window, VREG(LRFIFO_WIN_PTR), val);
455 write_hvwc_reg(window, VREG(SPARE4), 0ULL);
462 write_hvwc_reg(window, VREG(LNOTIFY_CTL), val);
466 write_hvwc_reg(window, VREG(LNOTIFY_PID), val);
470 write_hvwc_reg(window, VREG(LNOTIFY_LPID), val);
474 write_hvwc_reg(window, VREG(LNOTIFY_TID), val);
479 write_hvwc_reg(window, VREG(LNOTIFY_SCOPE), val);
483 write_hvwc_reg(window, VREG(SPARE5), 0ULL);
484 write_hvwc_reg(window, VREG(NX_UTIL_ADDER), 0ULL);
485 write_hvwc_reg(window, VREG(SPARE6), 0ULL);
487 /* Finally, push window context to memory and... */
490 write_hvwc_reg(window, VREG(WIN_CTX_CACHING_CTL), val);
492 /* ... mark the window open for business */
503 write_hvwc_reg(window, VREG(WINCTL), val);
523 static void vas_window_free(struct pnv_vas_window *window)
525 struct vas_instance *vinst = window->vinst;
526 int winid = window->vas_win.winid;
528 unmap_winctx_mmio_bars(window);
530 vas_window_free_dbgdir(window);
532 kfree(window);
540 struct pnv_vas_window *window;
546 window = kzalloc(sizeof(*window), GFP_KERNEL);
547 if (!window)
550 window->vinst = vinst;
551 window->vas_win.winid = winid;
553 if (map_winctx_mmio_bars(window))
556 vas_window_init_dbgdir(window);
558 return window;
561 kfree(window);
568 /* Better not be a send window! */
575 * Find the user space receive window given the @pswid.
578 * - The window must refer to an OPEN, FTW, RECEIVE window.
602 * Get the VAS receive window associated with NX engine identified
630 * looking up a window by its id. It is used to look up send windows
636 * entries and is used to look up a receive window by its
639 * Here, we save @window in the ->windows[] table. If it is a receive
640 * window, we also save the window in the ->rxwin[] table.
643 struct pnv_vas_window *window)
645 int id = window->vas_win.winid;
650 * There should only be one receive window for a coprocessor type
651 * unless its a user (FTW) window.
653 if (!window->user_win && !window->tx_win) {
654 WARN_ON_ONCE(vinst->rxwin[window->vas_win.cop]);
655 vinst->rxwin[window->vas_win.cop] = window;
659 vinst->windows[id] = window;
665 * Clear this window from the table(s) of windows for this VAS instance.
668 static void clear_vinst_win(struct pnv_vas_window *window)
670 int id = window->vas_win.winid;
671 struct vas_instance *vinst = window->vinst;
675 if (!window->user_win && !window->tx_win) {
676 WARN_ON_ONCE(!vinst->rxwin[window->vas_win.cop]);
677 vinst->rxwin[window->vas_win.cop] = NULL;
680 WARN_ON_ONCE(vinst->windows[id] != window);
780 /* cannot be fault or user window if it is nx */
791 /* cannot be both fault and user window */
810 /* Rx window must be one of NX or Fault or User window. */
874 pr_devel("Unable to allocate memory for Rx window\n");
953 * IRQ and fault window setup is successful. Set fault window
954 * for the send window so that ready to handle faults.
1011 * receive window (applicable only to FTW windows), use the vasid
1012 * from that receive window.
1047 * If its a kernel send window, map the window address into the
1049 * mmap() to map the window into their address space.
1062 * Interrupt hanlder or fault window setup failed. Means
1064 * opening for user space tx window.
1143 * If credit checking is enabled for this window, poll for the return
1144 * of window credits (i.e for NX engines to process any outstanding CRBs).
1146 * window, we should not have to wait for too long.
1155 static void poll_window_credits(struct pnv_vas_window *window)
1161 val = read_hvwc_reg(window, VREG(WINCTL));
1162 if (window->tx_win)
1170 if (window->tx_win) {
1171 val = read_hvwc_reg(window, VREG(TX_WCRED));
1174 val = read_hvwc_reg(window, VREG(LRX_WCRED));
1181 * TODO: Scan fault FIFO and invalidate CRBs points to this window
1185 if (creds < window->vas_win.wcreds_max) {
1191 * Process can not close send window until all credits are
1196 vas_window_pid(&window->vas_win),
1197 window->vas_win.winid,
1205 * Wait for the window to go to "not-busy" state. It should only take a
1206 * short time to queue a CRB, so window should not be busy for too long.
1209 static void poll_window_busy_state(struct pnv_vas_window *window)
1216 val = read_hvwc_reg(window, VREG(WIN_STATUS));
1229 vas_window_pid(&window->vas_win),
1230 window->vas_win.winid, count);
1237 * Have the hardware cast a window out of cache and wait for it to
1240 * NOTE: It can take a relatively long time to cast the window context
1245 * - we re-initialize the window context when it is reassigned.
1250 * job to a worker thread, so the window close can proceed quickly.
1252 static void poll_window_castout(struct pnv_vas_window *window)
1258 * Unpin and close a window so no new requests are accepted and the
1259 * hardware can evict this window from cache if necessary.
1261 static void unpin_close_window(struct pnv_vas_window *window)
1265 val = read_hvwc_reg(window, VREG(WINCTL));
1268 write_hvwc_reg(window, VREG(WINCTL), val);
1272 * Close a window.
1274 * See Section 1.12.1 of VAS workbook v1.05 for details on closing window:
1278 * - Poll for return of window Credits (implies FIFO empty for Rx win?)
1279 * - Unpin and cast window context out of cache
1285 struct pnv_vas_window *window;
1290 window = container_of(vwin, struct pnv_vas_window, vas_win);
1292 if (!window->tx_win && atomic_read(&window->num_txwins) != 0) {
1293 pr_devel("Attempting to close an active Rx window!\n");
1298 unmap_paste_region(window);
1300 poll_window_busy_state(window);
1302 unpin_close_window(window);
1304 poll_window_credits(window);
1306 clear_vinst_win(window);
1308 poll_window_castout(window);
1310 /* if send window, drop reference to matching receive window */
1311 if (window->tx_win) {
1312 if (window->user_win) {
1316 put_rx_win(window->rxwin);
1319 vas_window_free(window);
1326 * Return credit for the given window.
1327 * Send windows and fault window uses credit mechanism as follows:
1330 * - The default number of credits available for each send window is
1337 * credit on the specific send window after processing the fault CRB.
1339 * Fault window:
1344 * - The kernel with return credit on fault window after reading entry
1347 void vas_return_credit(struct pnv_vas_window *window, bool tx)
1352 if (tx) { /* send window */
1354 write_hvwc_reg(window, VREG(TX_WCRED_ADDER), val);
1357 write_hvwc_reg(window, VREG(LRX_WCRED_ADDER), val);
1364 struct pnv_vas_window *window;
1378 * If application closes the window before the hardware
1380 * for the pending requests. so the window must be active
1386 window = vinst->windows[winid];
1388 if (!window) {
1389 pr_err("PSWID decode: Could not find window for winid %d pswid %d vinst 0x%p\n",
1395 * Do some sanity checks on the decoded window. Window should be
1396 * NX GZIP user send window. FTW windows should not incur faults
1400 if (!window->tx_win || !window->user_win || !window->nx_win ||
1401 window->vas_win.cop == VAS_COP_TYPE_FAULT ||
1402 window->vas_win.cop == VAS_COP_TYPE_FTW) {
1404 winid, window->tx_win, window->user_win,
1405 window->nx_win, window->vas_win.cop);
1409 return window;