gruhandles.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /*
  2. * SN Platform GRU Driver
  3. *
  4. * GRU HANDLE DEFINITION
  5. *
  6. * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #ifndef __GRUHANDLES_H__
  23. #define __GRUHANDLES_H__
  24. #include "gru_instructions.h"
  25. /*
  26. * Manifest constants for GRU Memory Map
  27. */
  28. #define GRU_GSEG0_BASE 0
  29. #define GRU_MCS_BASE (64 * 1024 * 1024)
  30. #define GRU_SIZE (128UL * 1024 * 1024)
  31. /* Handle & resource counts */
  32. #define GRU_NUM_CB 128
  33. #define GRU_NUM_DSR_BYTES (32 * 1024)
  34. #define GRU_NUM_TFM 16
  35. #define GRU_NUM_TGH 24
  36. #define GRU_NUM_CBE 128
  37. #define GRU_NUM_TFH 128
  38. #define GRU_NUM_CCH 16
  39. /* Maximum resource counts that can be reserved by user programs */
  40. #define GRU_NUM_USER_CBR GRU_NUM_CBE
  41. #define GRU_NUM_USER_DSR_BYTES GRU_NUM_DSR_BYTES
  42. /* Bytes per handle & handle stride. Code assumes all cb, tfh, cbe handles
  43. * are the same */
  44. #define GRU_HANDLE_BYTES 64
  45. #define GRU_HANDLE_STRIDE 256
  46. /* Base addresses of handles */
  47. #define GRU_TFM_BASE (GRU_MCS_BASE + 0x00000)
  48. #define GRU_TGH_BASE (GRU_MCS_BASE + 0x08000)
  49. #define GRU_CBE_BASE (GRU_MCS_BASE + 0x10000)
  50. #define GRU_TFH_BASE (GRU_MCS_BASE + 0x18000)
  51. #define GRU_CCH_BASE (GRU_MCS_BASE + 0x20000)
  52. /* User gseg constants */
  53. #define GRU_GSEG_STRIDE (4 * 1024 * 1024)
  54. #define GSEG_BASE(a) ((a) & ~(GRU_GSEG_PAGESIZE - 1))
  55. /* Data segment constants */
  56. #define GRU_DSR_AU_BYTES 1024
  57. #define GRU_DSR_CL (GRU_NUM_DSR_BYTES / GRU_CACHE_LINE_BYTES)
  58. #define GRU_DSR_AU_CL (GRU_DSR_AU_BYTES / GRU_CACHE_LINE_BYTES)
  59. #define GRU_DSR_AU (GRU_NUM_DSR_BYTES / GRU_DSR_AU_BYTES)
  60. /* Control block constants */
  61. #define GRU_CBR_AU_SIZE 2
  62. #define GRU_CBR_AU (GRU_NUM_CBE / GRU_CBR_AU_SIZE)
  63. /* Convert resource counts to the number of AU */
  64. #define GRU_DS_BYTES_TO_AU(n) DIV_ROUND_UP(n, GRU_DSR_AU_BYTES)
  65. #define GRU_CB_COUNT_TO_AU(n) DIV_ROUND_UP(n, GRU_CBR_AU_SIZE)
  66. /* UV limits */
  67. #define GRU_CHIPLETS_PER_HUB 2
  68. #define GRU_HUBS_PER_BLADE 1
  69. #define GRU_CHIPLETS_PER_BLADE (GRU_HUBS_PER_BLADE * GRU_CHIPLETS_PER_HUB)
  70. /* User GRU Gseg offsets */
  71. #define GRU_CB_BASE 0
  72. #define GRU_CB_LIMIT (GRU_CB_BASE + GRU_HANDLE_STRIDE * GRU_NUM_CBE)
  73. #define GRU_DS_BASE 0x20000
  74. #define GRU_DS_LIMIT (GRU_DS_BASE + GRU_NUM_DSR_BYTES)
  75. /* Convert a GRU physical address to the chiplet offset */
  76. #define GSEGPOFF(h) ((h) & (GRU_SIZE - 1))
  77. /* Convert an arbitrary handle address to the beginning of the GRU segment */
  78. #define GRUBASE(h) ((void *)((unsigned long)(h) & ~(GRU_SIZE - 1)))
  79. /* Test a valid handle address to determine the type */
  80. #define TYPE_IS(hn, h) ((h) >= GRU_##hn##_BASE && (h) < \
  81. GRU_##hn##_BASE + GRU_NUM_##hn * GRU_HANDLE_STRIDE && \
  82. (((h) & (GRU_HANDLE_STRIDE - 1)) == 0))
  83. /* General addressing macros. */
  84. static inline void *get_gseg_base_address(void *base, int ctxnum)
  85. {
  86. return (void *)(base + GRU_GSEG0_BASE + GRU_GSEG_STRIDE * ctxnum);
  87. }
  88. static inline void *get_gseg_base_address_cb(void *base, int ctxnum, int line)
  89. {
  90. return (void *)(get_gseg_base_address(base, ctxnum) +
  91. GRU_CB_BASE + GRU_HANDLE_STRIDE * line);
  92. }
  93. static inline void *get_gseg_base_address_ds(void *base, int ctxnum, int line)
  94. {
  95. return (void *)(get_gseg_base_address(base, ctxnum) + GRU_DS_BASE +
  96. GRU_CACHE_LINE_BYTES * line);
  97. }
  98. static inline struct gru_tlb_fault_map *get_tfm(void *base, int ctxnum)
  99. {
  100. return (struct gru_tlb_fault_map *)(base + GRU_TFM_BASE +
  101. ctxnum * GRU_HANDLE_STRIDE);
  102. }
  103. static inline struct gru_tlb_global_handle *get_tgh(void *base, int ctxnum)
  104. {
  105. return (struct gru_tlb_global_handle *)(base + GRU_TGH_BASE +
  106. ctxnum * GRU_HANDLE_STRIDE);
  107. }
  108. static inline struct gru_control_block_extended *get_cbe(void *base, int ctxnum)
  109. {
  110. return (struct gru_control_block_extended *)(base + GRU_CBE_BASE +
  111. ctxnum * GRU_HANDLE_STRIDE);
  112. }
  113. static inline struct gru_tlb_fault_handle *get_tfh(void *base, int ctxnum)
  114. {
  115. return (struct gru_tlb_fault_handle *)(base + GRU_TFH_BASE +
  116. ctxnum * GRU_HANDLE_STRIDE);
  117. }
  118. static inline struct gru_context_configuration_handle *get_cch(void *base,
  119. int ctxnum)
  120. {
  121. return (struct gru_context_configuration_handle *)(base +
  122. GRU_CCH_BASE + ctxnum * GRU_HANDLE_STRIDE);
  123. }
  124. static inline unsigned long get_cb_number(void *cb)
  125. {
  126. return (((unsigned long)cb - GRU_CB_BASE) % GRU_GSEG_PAGESIZE) /
  127. GRU_HANDLE_STRIDE;
  128. }
  129. /* byte offset to a specific GRU chiplet. (p=pnode, c=chiplet (0 or 1)*/
  130. static inline unsigned long gru_chiplet_paddr(unsigned long paddr, int pnode,
  131. int chiplet)
  132. {
  133. return paddr + GRU_SIZE * (2 * pnode + chiplet);
  134. }
  135. static inline void *gru_chiplet_vaddr(void *vaddr, int pnode, int chiplet)
  136. {
  137. return vaddr + GRU_SIZE * (2 * pnode + chiplet);
  138. }
  139. static inline struct gru_control_block_extended *gru_tfh_to_cbe(
  140. struct gru_tlb_fault_handle *tfh)
  141. {
  142. unsigned long cbe;
  143. cbe = (unsigned long)tfh - GRU_TFH_BASE + GRU_CBE_BASE;
  144. return (struct gru_control_block_extended*)cbe;
  145. }
  146. /*
  147. * Global TLB Fault Map
  148. * Bitmap of outstanding TLB misses needing interrupt/polling service.
  149. *
  150. */
  151. struct gru_tlb_fault_map {
  152. unsigned long fault_bits[BITS_TO_LONGS(GRU_NUM_CBE)];
  153. unsigned long fill0[2];
  154. unsigned long done_bits[BITS_TO_LONGS(GRU_NUM_CBE)];
  155. unsigned long fill1[2];
  156. };
  157. /*
  158. * TGH - TLB Global Handle
  159. * Used for TLB flushing.
  160. *
  161. */
  162. struct gru_tlb_global_handle {
  163. unsigned int cmd:1; /* DW 0 */
  164. unsigned int delresp:1;
  165. unsigned int opc:1;
  166. unsigned int fill1:5;
  167. unsigned int fill2:8;
  168. unsigned int status:2;
  169. unsigned long fill3:2;
  170. unsigned int state:3;
  171. unsigned long fill4:1;
  172. unsigned int cause:3;
  173. unsigned long fill5:37;
  174. unsigned long vaddr:64; /* DW 1 */
  175. unsigned int asid:24; /* DW 2 */
  176. unsigned int fill6:8;
  177. unsigned int pagesize:5;
  178. unsigned int fill7:11;
  179. unsigned int global:1;
  180. unsigned int fill8:15;
  181. unsigned long vaddrmask:39; /* DW 3 */
  182. unsigned int fill9:9;
  183. unsigned int n:10;
  184. unsigned int fill10:6;
  185. unsigned int ctxbitmap:16; /* DW4 */
  186. unsigned long fill11[3];
  187. };
  188. enum gru_tgh_cmd {
  189. TGHCMD_START
  190. };
  191. enum gru_tgh_opc {
  192. TGHOP_TLBNOP,
  193. TGHOP_TLBINV
  194. };
  195. enum gru_tgh_status {
  196. TGHSTATUS_IDLE,
  197. TGHSTATUS_EXCEPTION,
  198. TGHSTATUS_ACTIVE
  199. };
  200. enum gru_tgh_state {
  201. TGHSTATE_IDLE,
  202. TGHSTATE_PE_INVAL,
  203. TGHSTATE_INTERRUPT_INVAL,
  204. TGHSTATE_WAITDONE,
  205. TGHSTATE_RESTART_CTX,
  206. };
  207. enum gru_tgh_cause {
  208. TGHCAUSE_RR_ECC,
  209. TGHCAUSE_TLB_ECC,
  210. TGHCAUSE_LRU_ECC,
  211. TGHCAUSE_PS_ECC,
  212. TGHCAUSE_MUL_ERR,
  213. TGHCAUSE_DATA_ERR,
  214. TGHCAUSE_SW_FORCE
  215. };
  216. /*
  217. * TFH - TLB Global Handle
  218. * Used for TLB dropins into the GRU TLB.
  219. *
  220. */
  221. struct gru_tlb_fault_handle {
  222. unsigned int cmd:1; /* DW 0 - low 32*/
  223. unsigned int delresp:1;
  224. unsigned int fill0:2;
  225. unsigned int opc:3;
  226. unsigned int fill1:9;
  227. unsigned int status:2;
  228. unsigned int fill2:2;
  229. unsigned int state:3;
  230. unsigned int fill3:1;
  231. unsigned int cause:6;
  232. unsigned int cb_int:1;
  233. unsigned int fill4:1;
  234. unsigned int indexway:12; /* DW 0 - high 32 */
  235. unsigned int fill5:4;
  236. unsigned int ctxnum:4;
  237. unsigned int fill6:12;
  238. unsigned long missvaddr:64; /* DW 1 */
  239. unsigned int missasid:24; /* DW 2 */
  240. unsigned int fill7:8;
  241. unsigned int fillasid:24;
  242. unsigned int dirty:1;
  243. unsigned int gaa:2;
  244. unsigned long fill8:5;
  245. unsigned long pfn:41; /* DW 3 */
  246. unsigned int fill9:7;
  247. unsigned int pagesize:5;
  248. unsigned int fill10:11;
  249. unsigned long fillvaddr:64; /* DW 4 */
  250. unsigned long fill11[3];
  251. };
  252. enum gru_tfh_opc {
  253. TFHOP_NOOP,
  254. TFHOP_RESTART,
  255. TFHOP_WRITE_ONLY,
  256. TFHOP_WRITE_RESTART,
  257. TFHOP_EXCEPTION,
  258. TFHOP_USER_POLLING_MODE = 7,
  259. };
  260. enum tfh_status {
  261. TFHSTATUS_IDLE,
  262. TFHSTATUS_EXCEPTION,
  263. TFHSTATUS_ACTIVE,
  264. };
  265. enum tfh_state {
  266. TFHSTATE_INACTIVE,
  267. TFHSTATE_IDLE,
  268. TFHSTATE_MISS_UPM,
  269. TFHSTATE_MISS_FMM,
  270. TFHSTATE_HW_ERR,
  271. TFHSTATE_WRITE_TLB,
  272. TFHSTATE_RESTART_CBR,
  273. };
  274. /* TFH cause bits */
  275. enum tfh_cause {
  276. TFHCAUSE_NONE,
  277. TFHCAUSE_TLB_MISS,
  278. TFHCAUSE_TLB_MOD,
  279. TFHCAUSE_HW_ERROR_RR,
  280. TFHCAUSE_HW_ERROR_MAIN_ARRAY,
  281. TFHCAUSE_HW_ERROR_VALID,
  282. TFHCAUSE_HW_ERROR_PAGESIZE,
  283. TFHCAUSE_INSTRUCTION_EXCEPTION,
  284. TFHCAUSE_UNCORRECTIBLE_ERROR,
  285. };
  286. /* GAA values */
  287. #define GAA_RAM 0x0
  288. #define GAA_NCRAM 0x2
  289. #define GAA_MMIO 0x1
  290. #define GAA_REGISTER 0x3
  291. /* GRU paddr shift for pfn. (NOTE: shift is NOT by actual pagesize) */
  292. #define GRU_PADDR_SHIFT 12
  293. /*
  294. * Context Configuration handle
  295. * Used to allocate resources to a GSEG context.
  296. *
  297. */
  298. struct gru_context_configuration_handle {
  299. unsigned int cmd:1; /* DW0 */
  300. unsigned int delresp:1;
  301. unsigned int opc:3;
  302. unsigned int unmap_enable:1;
  303. unsigned int req_slice_set_enable:1;
  304. unsigned int req_slice:2;
  305. unsigned int cb_int_enable:1;
  306. unsigned int tlb_int_enable:1;
  307. unsigned int tfm_fault_bit_enable:1;
  308. unsigned int tlb_int_select:4;
  309. unsigned int status:2;
  310. unsigned int state:2;
  311. unsigned int reserved2:4;
  312. unsigned int cause:4;
  313. unsigned int tfm_done_bit_enable:1;
  314. unsigned int unused:3;
  315. unsigned int dsr_allocation_map;
  316. unsigned long cbr_allocation_map; /* DW1 */
  317. unsigned int asid[8]; /* DW 2 - 5 */
  318. unsigned short sizeavail[8]; /* DW 6 - 7 */
  319. } __attribute__ ((packed));
  320. enum gru_cch_opc {
  321. CCHOP_START = 1,
  322. CCHOP_ALLOCATE,
  323. CCHOP_INTERRUPT,
  324. CCHOP_DEALLOCATE,
  325. CCHOP_INTERRUPT_SYNC,
  326. };
  327. enum gru_cch_status {
  328. CCHSTATUS_IDLE,
  329. CCHSTATUS_EXCEPTION,
  330. CCHSTATUS_ACTIVE,
  331. };
  332. enum gru_cch_state {
  333. CCHSTATE_INACTIVE,
  334. CCHSTATE_MAPPED,
  335. CCHSTATE_ACTIVE,
  336. CCHSTATE_INTERRUPTED,
  337. };
  338. /* CCH Exception cause */
  339. enum gru_cch_cause {
  340. CCHCAUSE_REGION_REGISTER_WRITE_ERROR = 1,
  341. CCHCAUSE_ILLEGAL_OPCODE = 2,
  342. CCHCAUSE_INVALID_START_REQUEST = 3,
  343. CCHCAUSE_INVALID_ALLOCATION_REQUEST = 4,
  344. CCHCAUSE_INVALID_DEALLOCATION_REQUEST = 5,
  345. CCHCAUSE_INVALID_INTERRUPT_REQUEST = 6,
  346. CCHCAUSE_CCH_BUSY = 7,
  347. CCHCAUSE_NO_CBRS_TO_ALLOCATE = 8,
  348. CCHCAUSE_BAD_TFM_CONFIG = 9,
  349. CCHCAUSE_CBR_RESOURCES_OVERSUBSCRIPED = 10,
  350. CCHCAUSE_DSR_RESOURCES_OVERSUBSCRIPED = 11,
  351. CCHCAUSE_CBR_DEALLOCATION_ERROR = 12,
  352. };
  353. /*
  354. * CBE - Control Block Extended
  355. * Maintains internal GRU state for active CBs.
  356. *
  357. */
  358. struct gru_control_block_extended {
  359. unsigned int reserved0:1; /* DW 0 - low */
  360. unsigned int imacpy:3;
  361. unsigned int reserved1:4;
  362. unsigned int xtypecpy:3;
  363. unsigned int iaa0cpy:2;
  364. unsigned int iaa1cpy:2;
  365. unsigned int reserved2:1;
  366. unsigned int opccpy:8;
  367. unsigned int exopccpy:8;
  368. unsigned int idef2cpy:22; /* DW 0 - high */
  369. unsigned int reserved3:10;
  370. unsigned int idef4cpy:22; /* DW 1 */
  371. unsigned int reserved4:10;
  372. unsigned int idef4upd:22;
  373. unsigned int reserved5:10;
  374. unsigned long idef1upd:64; /* DW 2 */
  375. unsigned long idef5cpy:64; /* DW 3 */
  376. unsigned long idef6cpy:64; /* DW 4 */
  377. unsigned long idef3upd:64; /* DW 5 */
  378. unsigned long idef5upd:64; /* DW 6 */
  379. unsigned int idef2upd:22; /* DW 7 */
  380. unsigned int reserved6:10;
  381. unsigned int ecause:20;
  382. unsigned int cbrstate:4;
  383. unsigned int cbrexecstatus:8;
  384. };
  385. /* CBE fields for active BCOPY instructions */
  386. #define cbe_baddr0 idef1upd
  387. #define cbe_baddr1 idef3upd
  388. #define cbe_src_cl idef6cpy
  389. #define cbe_nelemcur idef5upd
  390. enum gru_cbr_state {
  391. CBRSTATE_INACTIVE,
  392. CBRSTATE_IDLE,
  393. CBRSTATE_PE_CHECK,
  394. CBRSTATE_QUEUED,
  395. CBRSTATE_WAIT_RESPONSE,
  396. CBRSTATE_INTERRUPTED,
  397. CBRSTATE_INTERRUPTED_MISS_FMM,
  398. CBRSTATE_BUSY_INTERRUPT_MISS_FMM,
  399. CBRSTATE_INTERRUPTED_MISS_UPM,
  400. CBRSTATE_BUSY_INTERRUPTED_MISS_UPM,
  401. CBRSTATE_REQUEST_ISSUE,
  402. CBRSTATE_BUSY_INTERRUPT,
  403. };
  404. /* CBE cbrexecstatus bits - defined in gru_instructions.h*/
  405. /* CBE ecause bits - defined in gru_instructions.h */
  406. /*
  407. * Convert a processor pagesize into the strange encoded pagesize used by the
  408. * GRU. Processor pagesize is encoded as log of bytes per page. (or PAGE_SHIFT)
  409. * pagesize log pagesize grupagesize
  410. * 4k 12 0
  411. * 16k 14 1
  412. * 64k 16 2
  413. * 256k 18 3
  414. * 1m 20 4
  415. * 2m 21 5
  416. * 4m 22 6
  417. * 16m 24 7
  418. * 64m 26 8
  419. * ...
  420. */
  421. #define GRU_PAGESIZE(sh) ((((sh) > 20 ? (sh) + 2 : (sh)) >> 1) - 6)
  422. #define GRU_SIZEAVAIL(sh) (1UL << GRU_PAGESIZE(sh))
  423. /* minimum TLB purge count to ensure a full purge */
  424. #define GRUMAXINVAL 1024UL
  425. int cch_allocate(struct gru_context_configuration_handle *cch);
  426. int cch_start(struct gru_context_configuration_handle *cch);
  427. int cch_interrupt(struct gru_context_configuration_handle *cch);
  428. int cch_deallocate(struct gru_context_configuration_handle *cch);
  429. int cch_interrupt_sync(struct gru_context_configuration_handle *cch);
  430. int tgh_invalidate(struct gru_tlb_global_handle *tgh, unsigned long vaddr,
  431. unsigned long vaddrmask, int asid, int pagesize, int global, int n,
  432. unsigned short ctxbitmap);
  433. int tfh_write_only(struct gru_tlb_fault_handle *tfh, unsigned long paddr,
  434. int gaa, unsigned long vaddr, int asid, int dirty, int pagesize);
  435. void tfh_write_restart(struct gru_tlb_fault_handle *tfh, unsigned long paddr,
  436. int gaa, unsigned long vaddr, int asid, int dirty, int pagesize);
  437. void tfh_user_polling_mode(struct gru_tlb_fault_handle *tfh);
  438. void tfh_exception(struct gru_tlb_fault_handle *tfh);
  439. #endif /* __GRUHANDLES_H__ */