0001
0002
0003
0004
0005
0006 #ifndef _VAS_H
0007 #define _VAS_H
0008 #include <linux/atomic.h>
0009 #include <linux/idr.h>
0010 #include <asm/vas.h>
0011 #include <linux/io.h>
0012 #include <linux/dcache.h>
0013 #include <linux/mutex.h>
0014 #include <linux/stringify.h>
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093 #define VAS_WINDOWS_PER_CHIP (64 << 10)
0094
0095
0096
0097
0098 #define VAS_HVWC_SIZE 512
0099 #define VAS_UWC_SIZE PAGE_SIZE
0100
0101
0102
0103
0104
0105
0106
0107 #define VAS_TX_WCREDS_MAX ((4 << 10) - 1)
0108 #define VAS_WCREDS_DEFAULT (1 << 10)
0109
0110
0111
0112
0113
0114 #define VAS_LPID_OFFSET 0x010
0115 #define VAS_LPID PPC_BITMASK(0, 11)
0116
0117 #define VAS_PID_OFFSET 0x018
0118 #define VAS_PID_ID PPC_BITMASK(0, 19)
0119
0120 #define VAS_XLATE_MSR_OFFSET 0x020
0121 #define VAS_XLATE_MSR_DR PPC_BIT(0)
0122 #define VAS_XLATE_MSR_TA PPC_BIT(1)
0123 #define VAS_XLATE_MSR_PR PPC_BIT(2)
0124 #define VAS_XLATE_MSR_US PPC_BIT(3)
0125 #define VAS_XLATE_MSR_HV PPC_BIT(4)
0126 #define VAS_XLATE_MSR_SF PPC_BIT(5)
0127
0128 #define VAS_XLATE_LPCR_OFFSET 0x028
0129 #define VAS_XLATE_LPCR_PAGE_SIZE PPC_BITMASK(0, 2)
0130 #define VAS_XLATE_LPCR_ISL PPC_BIT(3)
0131 #define VAS_XLATE_LPCR_TC PPC_BIT(4)
0132 #define VAS_XLATE_LPCR_SC PPC_BIT(5)
0133
0134 #define VAS_XLATE_CTL_OFFSET 0x030
0135 #define VAS_XLATE_MODE PPC_BITMASK(0, 1)
0136
0137 #define VAS_AMR_OFFSET 0x040
0138 #define VAS_AMR PPC_BITMASK(0, 63)
0139
0140 #define VAS_SEIDR_OFFSET 0x048
0141 #define VAS_SEIDR PPC_BITMASK(0, 63)
0142
0143 #define VAS_FAULT_TX_WIN_OFFSET 0x050
0144 #define VAS_FAULT_TX_WIN PPC_BITMASK(48, 63)
0145
0146 #define VAS_OSU_INTR_SRC_RA_OFFSET 0x060
0147 #define VAS_OSU_INTR_SRC_RA PPC_BITMASK(8, 63)
0148
0149 #define VAS_HV_INTR_SRC_RA_OFFSET 0x070
0150 #define VAS_HV_INTR_SRC_RA PPC_BITMASK(8, 63)
0151
0152 #define VAS_PSWID_OFFSET 0x078
0153 #define VAS_PSWID_EA_HANDLE PPC_BITMASK(0, 31)
0154
0155 #define VAS_SPARE1_OFFSET 0x080
0156 #define VAS_SPARE2_OFFSET 0x088
0157 #define VAS_SPARE3_OFFSET 0x090
0158 #define VAS_SPARE4_OFFSET 0x130
0159 #define VAS_SPARE5_OFFSET 0x160
0160 #define VAS_SPARE6_OFFSET 0x188
0161
0162 #define VAS_LFIFO_BAR_OFFSET 0x0A0
0163 #define VAS_LFIFO_BAR PPC_BITMASK(8, 53)
0164 #define VAS_PAGE_MIGRATION_SELECT PPC_BITMASK(54, 56)
0165
0166 #define VAS_LDATA_STAMP_CTL_OFFSET 0x0A8
0167 #define VAS_LDATA_STAMP PPC_BITMASK(0, 1)
0168 #define VAS_XTRA_WRITE PPC_BIT(2)
0169
0170 #define VAS_LDMA_CACHE_CTL_OFFSET 0x0B0
0171 #define VAS_LDMA_TYPE PPC_BITMASK(0, 1)
0172 #define VAS_LDMA_FIFO_DISABLE PPC_BIT(2)
0173
0174 #define VAS_LRFIFO_PUSH_OFFSET 0x0B8
0175 #define VAS_LRFIFO_PUSH PPC_BITMASK(0, 15)
0176
0177 #define VAS_CURR_MSG_COUNT_OFFSET 0x0C0
0178 #define VAS_CURR_MSG_COUNT PPC_BITMASK(0, 7)
0179
0180 #define VAS_LNOTIFY_AFTER_COUNT_OFFSET 0x0C8
0181 #define VAS_LNOTIFY_AFTER_COUNT PPC_BITMASK(0, 7)
0182
0183 #define VAS_LRX_WCRED_OFFSET 0x0E0
0184 #define VAS_LRX_WCRED PPC_BITMASK(0, 15)
0185
0186 #define VAS_LRX_WCRED_ADDER_OFFSET 0x190
0187 #define VAS_LRX_WCRED_ADDER PPC_BITMASK(0, 15)
0188
0189 #define VAS_TX_WCRED_OFFSET 0x0F0
0190 #define VAS_TX_WCRED PPC_BITMASK(4, 15)
0191
0192 #define VAS_TX_WCRED_ADDER_OFFSET 0x1A0
0193 #define VAS_TX_WCRED_ADDER PPC_BITMASK(4, 15)
0194
0195 #define VAS_LFIFO_SIZE_OFFSET 0x100
0196 #define VAS_LFIFO_SIZE PPC_BITMASK(0, 3)
0197
0198 #define VAS_WINCTL_OFFSET 0x108
0199 #define VAS_WINCTL_OPEN PPC_BIT(0)
0200 #define VAS_WINCTL_REJ_NO_CREDIT PPC_BIT(1)
0201 #define VAS_WINCTL_PIN PPC_BIT(2)
0202 #define VAS_WINCTL_TX_WCRED_MODE PPC_BIT(3)
0203 #define VAS_WINCTL_RX_WCRED_MODE PPC_BIT(4)
0204 #define VAS_WINCTL_TX_WORD_MODE PPC_BIT(5)
0205 #define VAS_WINCTL_RX_WORD_MODE PPC_BIT(6)
0206 #define VAS_WINCTL_RSVD_TXBUF PPC_BIT(7)
0207 #define VAS_WINCTL_THRESH_CTL PPC_BITMASK(8, 9)
0208 #define VAS_WINCTL_FAULT_WIN PPC_BIT(10)
0209 #define VAS_WINCTL_NX_WIN PPC_BIT(11)
0210
0211 #define VAS_WIN_STATUS_OFFSET 0x110
0212 #define VAS_WIN_BUSY PPC_BIT(1)
0213
0214 #define VAS_WIN_CTX_CACHING_CTL_OFFSET 0x118
0215 #define VAS_CASTOUT_REQ PPC_BIT(0)
0216 #define VAS_PUSH_TO_MEM PPC_BIT(1)
0217 #define VAS_WIN_CACHE_STATUS PPC_BIT(4)
0218
0219 #define VAS_TX_RSVD_BUF_COUNT_OFFSET 0x120
0220 #define VAS_RXVD_BUF_COUNT PPC_BITMASK(58, 63)
0221
0222 #define VAS_LRFIFO_WIN_PTR_OFFSET 0x128
0223 #define VAS_LRX_WIN_ID PPC_BITMASK(0, 15)
0224
0225
0226
0227
0228
0229 #define VAS_LNOTIFY_CTL_OFFSET 0x138
0230 #define VAS_NOTIFY_DISABLE PPC_BIT(0)
0231 #define VAS_INTR_DISABLE PPC_BIT(1)
0232 #define VAS_NOTIFY_EARLY PPC_BIT(2)
0233 #define VAS_NOTIFY_OSU_INTR PPC_BIT(3)
0234
0235 #define VAS_LNOTIFY_PID_OFFSET 0x140
0236 #define VAS_LNOTIFY_PID PPC_BITMASK(0, 19)
0237
0238 #define VAS_LNOTIFY_LPID_OFFSET 0x148
0239 #define VAS_LNOTIFY_LPID PPC_BITMASK(0, 11)
0240
0241 #define VAS_LNOTIFY_TID_OFFSET 0x150
0242 #define VAS_LNOTIFY_TID PPC_BITMASK(0, 15)
0243
0244 #define VAS_LNOTIFY_SCOPE_OFFSET 0x158
0245 #define VAS_LNOTIFY_MIN_SCOPE PPC_BITMASK(0, 1)
0246 #define VAS_LNOTIFY_MAX_SCOPE PPC_BITMASK(2, 3)
0247
0248 #define VAS_NX_UTIL_OFFSET 0x1B0
0249 #define VAS_NX_UTIL PPC_BITMASK(0, 63)
0250
0251
0252 #define VAS_NX_UTIL_SE_OFFSET 0x1B8
0253 #define VAS_NX_UTIL_SE PPC_BITMASK(0, 63)
0254
0255 #define VAS_NX_UTIL_ADDER_OFFSET 0x180
0256 #define VAS_NX_UTIL_ADDER PPC_BITMASK(32, 63)
0257
0258
0259
0260
0261
0262
0263
0264
0265 #define VREG_SFX(n, s) __stringify(n), VAS_##n##s
0266 #define VREG(r) VREG_SFX(r, _OFFSET)
0267
0268
0269
0270
0271 enum vas_notify_scope {
0272 VAS_SCOPE_LOCAL,
0273 VAS_SCOPE_GROUP,
0274 VAS_SCOPE_VECTORED_GROUP,
0275 VAS_SCOPE_UNUSED,
0276 };
0277
0278
0279
0280
0281 enum vas_dma_type {
0282 VAS_DMA_TYPE_INJECT,
0283 VAS_DMA_TYPE_WRITE,
0284 };
0285
0286
0287
0288
0289
0290 enum vas_notify_after_count {
0291 VAS_NOTIFY_AFTER_256 = 0,
0292 VAS_NOTIFY_NONE,
0293 VAS_NOTIFY_AFTER_2
0294 };
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309 #define FIFO_INVALID_ENTRY 0xffffffff
0310 #define CCW0_INVALID 1
0311
0312
0313
0314
0315
0316
0317
0318
0319 struct vas_instance {
0320 int vas_id;
0321 struct ida ida;
0322 struct list_head node;
0323 struct platform_device *pdev;
0324
0325 u64 hvwc_bar_start;
0326 u64 uwc_bar_start;
0327 u64 paste_base_addr;
0328 u64 paste_win_id_shift;
0329
0330 u64 irq_port;
0331 int virq;
0332 int fault_crbs;
0333 int fault_fifo_size;
0334 int fifo_in_progress;
0335 spinlock_t fault_lock;
0336 void *fault_fifo;
0337 struct pnv_vas_window *fault_win;
0338
0339 struct mutex mutex;
0340 struct pnv_vas_window *rxwin[VAS_COP_TYPE_MAX];
0341 struct pnv_vas_window *windows[VAS_WINDOWS_PER_CHIP];
0342
0343 char *name;
0344 char *dbgname;
0345 struct dentry *dbgdir;
0346 };
0347
0348
0349
0350
0351 struct pnv_vas_window {
0352 struct vas_window vas_win;
0353
0354 struct vas_instance *vinst;
0355 bool tx_win;
0356 bool nx_win;
0357 bool user_win;
0358 void *hvwc_map;
0359 void *uwc_map;
0360
0361
0362 void *paste_kaddr;
0363 char *paste_addr_name;
0364 struct pnv_vas_window *rxwin;
0365
0366
0367 atomic_t num_txwins;
0368 };
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378 struct vas_winctx {
0379 u64 rx_fifo;
0380 int rx_fifo_size;
0381 int wcreds_max;
0382 int rsvd_txbuf_count;
0383
0384 bool user_win;
0385 bool nx_win;
0386 bool fault_win;
0387 bool rsvd_txbuf_enable;
0388 bool pin_win;
0389 bool rej_no_credit;
0390 bool tx_wcred_mode;
0391 bool rx_wcred_mode;
0392 bool tx_word_mode;
0393 bool rx_word_mode;
0394 bool data_stamp;
0395 bool xtra_write;
0396 bool notify_disable;
0397 bool intr_disable;
0398 bool fifo_disable;
0399 bool notify_early;
0400 bool notify_os_intr_reg;
0401
0402 int lpid;
0403 int pidr;
0404 int lnotify_lpid;
0405 int lnotify_pid;
0406 int lnotify_tid;
0407 u32 pswid;
0408 int rx_win_id;
0409 int fault_win_id;
0410 int tc_mode;
0411
0412 u64 irq_port;
0413
0414 enum vas_dma_type dma_type;
0415 enum vas_notify_scope min_scope;
0416 enum vas_notify_scope max_scope;
0417 enum vas_notify_after_count notify_after_count;
0418 };
0419
0420 extern struct mutex vas_mutex;
0421
0422 extern struct vas_instance *find_vas_instance(int vasid);
0423 extern void vas_init_dbgdir(void);
0424 extern void vas_instance_init_dbgdir(struct vas_instance *vinst);
0425 extern void vas_window_init_dbgdir(struct pnv_vas_window *win);
0426 extern void vas_window_free_dbgdir(struct pnv_vas_window *win);
0427 extern int vas_setup_fault_window(struct vas_instance *vinst);
0428 extern irqreturn_t vas_fault_thread_fn(int irq, void *data);
0429 extern irqreturn_t vas_fault_handler(int irq, void *dev_id);
0430 extern void vas_return_credit(struct pnv_vas_window *window, bool tx);
0431 extern struct pnv_vas_window *vas_pswid_to_window(struct vas_instance *vinst,
0432 uint32_t pswid);
0433 extern void vas_win_paste_addr(struct pnv_vas_window *window, u64 *addr,
0434 int *len);
0435
0436 static inline int vas_window_pid(struct vas_window *window)
0437 {
0438 return pid_vnr(window->task_ref.pid);
0439 }
0440
0441 static inline void vas_log_write(struct pnv_vas_window *win, char *name,
0442 void *regptr, u64 val)
0443 {
0444 if (val)
0445 pr_debug("%swin #%d: %s reg %p, val 0x%016llx\n",
0446 win->tx_win ? "Tx" : "Rx", win->vas_win.winid,
0447 name, regptr, val);
0448 }
0449
0450 static inline void write_uwc_reg(struct pnv_vas_window *win, char *name,
0451 s32 reg, u64 val)
0452 {
0453 void *regptr;
0454
0455 regptr = win->uwc_map + reg;
0456 vas_log_write(win, name, regptr, val);
0457
0458 out_be64(regptr, val);
0459 }
0460
0461 static inline void write_hvwc_reg(struct pnv_vas_window *win, char *name,
0462 s32 reg, u64 val)
0463 {
0464 void *regptr;
0465
0466 regptr = win->hvwc_map + reg;
0467 vas_log_write(win, name, regptr, val);
0468
0469 out_be64(regptr, val);
0470 }
0471
0472 static inline u64 read_hvwc_reg(struct pnv_vas_window *win,
0473 char *name __maybe_unused, s32 reg)
0474 {
0475 return in_be64(win->hvwc_map+reg);
0476 }
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488 static inline u32 encode_pswid(int vasid, int winid)
0489 {
0490 return ((u32)winid | (vasid << (31 - 7)));
0491 }
0492
0493 static inline void decode_pswid(u32 pswid, int *vasid, int *winid)
0494 {
0495 if (vasid)
0496 *vasid = pswid >> (31 - 7) & 0xFF;
0497
0498 if (winid)
0499 *winid = pswid & 0xFFFF;
0500 }
0501 #endif