gruhandles.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. /* General addressing macros. */
  80. static inline void *get_gseg_base_address(void *base, int ctxnum)
  81. {
  82. return (void *)(base + GRU_GSEG0_BASE + GRU_GSEG_STRIDE * ctxnum);
  83. }
  84. static inline void *get_gseg_base_address_cb(void *base, int ctxnum, int line)
  85. {
  86. return (void *)(get_gseg_base_address(base, ctxnum) +
  87. GRU_CB_BASE + GRU_HANDLE_STRIDE * line);
  88. }
  89. static inline void *get_gseg_base_address_ds(void *base, int ctxnum, int line)
  90. {
  91. return (void *)(get_gseg_base_address(base, ctxnum) + GRU_DS_BASE +
  92. GRU_CACHE_LINE_BYTES * line);
  93. }
  94. static inline struct gru_tlb_fault_map *get_tfm(void *base, int ctxnum)
  95. {
  96. return (struct gru_tlb_fault_map *)(base + GRU_TFM_BASE +
  97. ctxnum * GRU_HANDLE_STRIDE);
  98. }
  99. static inline struct gru_tlb_global_handle *get_tgh(void *base, int ctxnum)
  100. {
  101. return (struct gru_tlb_global_handle *)(base + GRU_TGH_BASE +
  102. ctxnum * GRU_HANDLE_STRIDE);
  103. }
  104. static inline struct gru_control_block_extended *get_cbe(void *base, int ctxnum)
  105. {
  106. return (struct gru_control_block_extended *)(base + GRU_CBE_BASE +
  107. ctxnum * GRU_HANDLE_STRIDE);
  108. }
  109. static inline struct gru_tlb_fault_handle *get_tfh(void *base, int ctxnum)
  110. {
  111. return (struct gru_tlb_fault_handle *)(base + GRU_TFH_BASE +
  112. ctxnum * GRU_HANDLE_STRIDE);
  113. }
  114. static inline struct gru_context_configuration_handle *get_cch(void *base,
  115. int ctxnum)
  116. {
  117. return (struct gru_context_configuration_handle *)(base +
  118. GRU_CCH_BASE + ctxnum * GRU_HANDLE_STRIDE);
  119. }
  120. static inline unsigned long get_cb_number(void *cb)
  121. {
  122. return (((unsigned long)cb - GRU_CB_BASE) % GRU_GSEG_PAGESIZE) /
  123. GRU_HANDLE_STRIDE;
  124. }
  125. /* byte offset to a specific GRU chiplet. (p=pnode, c=chiplet (0 or 1)*/
  126. static inline unsigned long gru_chiplet_paddr(unsigned long paddr, int pnode,
  127. int chiplet)
  128. {
  129. return paddr + GRU_SIZE * (2 * pnode + chiplet);
  130. }
  131. static inline void *gru_chiplet_vaddr(void *vaddr, int pnode, int chiplet)
  132. {
  133. return vaddr + GRU_SIZE * (2 * pnode + chiplet);
  134. }
  135. /*
  136. * Global TLB Fault Map
  137. * Bitmap of outstanding TLB misses needing interrupt/polling service.
  138. *
  139. */
  140. struct gru_tlb_fault_map {
  141. unsigned long fault_bits[BITS_TO_LONGS(GRU_NUM_CBE)];
  142. unsigned long fill0[2];
  143. unsigned long done_bits[BITS_TO_LONGS(GRU_NUM_CBE)];
  144. unsigned long fill1[2];
  145. };
  146. /*
  147. * TGH - TLB Global Handle
  148. * Used for TLB flushing.
  149. *
  150. */
  151. struct gru_tlb_global_handle {
  152. unsigned int cmd:1; /* DW 0 */
  153. unsigned int delresp:1;
  154. unsigned int opc:1;
  155. unsigned int fill1:5;
  156. unsigned int fill2:8;
  157. unsigned int status:2;
  158. unsigned long fill3:2;
  159. unsigned int state:3;
  160. unsigned long fill4:1;
  161. unsigned int cause:3;
  162. unsigned long fill5:37;
  163. unsigned long vaddr:64; /* DW 1 */
  164. unsigned int asid:24; /* DW 2 */
  165. unsigned int fill6:8;
  166. unsigned int pagesize:5;
  167. unsigned int fill7:11;
  168. unsigned int global:1;
  169. unsigned int fill8:15;
  170. unsigned long vaddrmask:39; /* DW 3 */
  171. unsigned int fill9:9;
  172. unsigned int n:10;
  173. unsigned int fill10:6;
  174. unsigned int ctxbitmap:16; /* DW4 */
  175. unsigned long fill11[3];
  176. };
  177. enum gru_tgh_cmd {
  178. TGHCMD_START
  179. };
  180. enum gru_tgh_opc {
  181. TGHOP_TLBNOP,
  182. TGHOP_TLBINV
  183. };
  184. enum gru_tgh_status {
  185. TGHSTATUS_IDLE,
  186. TGHSTATUS_EXCEPTION,
  187. TGHSTATUS_ACTIVE
  188. };
  189. enum gru_tgh_state {
  190. TGHSTATE_IDLE,
  191. TGHSTATE_PE_INVAL,
  192. TGHSTATE_INTERRUPT_INVAL,
  193. TGHSTATE_WAITDONE,
  194. TGHSTATE_RESTART_CTX,
  195. };
  196. /*
  197. * TFH - TLB Global Handle
  198. * Used for TLB dropins into the GRU TLB.
  199. *
  200. */
  201. struct gru_tlb_fault_handle {
  202. unsigned int cmd:1; /* DW 0 - low 32*/
  203. unsigned int delresp:1;
  204. unsigned int fill0:2;
  205. unsigned int opc:3;
  206. unsigned int fill1:9;
  207. unsigned int status:2;
  208. unsigned int fill2:2;
  209. unsigned int state:3;
  210. unsigned int fill3:1;
  211. unsigned int cause:6;
  212. unsigned int cb_int:1;
  213. unsigned int fill4:1;
  214. unsigned int indexway:12; /* DW 0 - high 32 */
  215. unsigned int fill5:4;
  216. unsigned int ctxnum:4;
  217. unsigned int fill6:12;
  218. unsigned long missvaddr:64; /* DW 1 */
  219. unsigned int missasid:24; /* DW 2 */
  220. unsigned int fill7:8;
  221. unsigned int fillasid:24;
  222. unsigned int dirty:1;
  223. unsigned int gaa:2;
  224. unsigned long fill8:5;
  225. unsigned long pfn:41; /* DW 3 */
  226. unsigned int fill9:7;
  227. unsigned int pagesize:5;
  228. unsigned int fill10:11;
  229. unsigned long fillvaddr:64; /* DW 4 */
  230. unsigned long fill11[3];
  231. };
  232. enum gru_tfh_opc {
  233. TFHOP_NOOP,
  234. TFHOP_RESTART,
  235. TFHOP_WRITE_ONLY,
  236. TFHOP_WRITE_RESTART,
  237. TFHOP_EXCEPTION,
  238. TFHOP_USER_POLLING_MODE = 7,
  239. };
  240. enum tfh_status {
  241. TFHSTATUS_IDLE,
  242. TFHSTATUS_EXCEPTION,
  243. TFHSTATUS_ACTIVE,
  244. };
  245. enum tfh_state {
  246. TFHSTATE_INACTIVE,
  247. TFHSTATE_IDLE,
  248. TFHSTATE_MISS_UPM,
  249. TFHSTATE_MISS_FMM,
  250. TFHSTATE_HW_ERR,
  251. TFHSTATE_WRITE_TLB,
  252. TFHSTATE_RESTART_CBR,
  253. };
  254. /* TFH cause bits */
  255. enum tfh_cause {
  256. TFHCAUSE_NONE,
  257. TFHCAUSE_TLB_MISS,
  258. TFHCAUSE_TLB_MOD,
  259. TFHCAUSE_HW_ERROR_RR,
  260. TFHCAUSE_HW_ERROR_MAIN_ARRAY,
  261. TFHCAUSE_HW_ERROR_VALID,
  262. TFHCAUSE_HW_ERROR_PAGESIZE,
  263. TFHCAUSE_INSTRUCTION_EXCEPTION,
  264. TFHCAUSE_UNCORRECTIBLE_ERROR,
  265. };
  266. /* GAA values */
  267. #define GAA_RAM 0x0
  268. #define GAA_NCRAM 0x2
  269. #define GAA_MMIO 0x1
  270. #define GAA_REGISTER 0x3
  271. /* GRU paddr shift for pfn. (NOTE: shift is NOT by actual pagesize) */
  272. #define GRU_PADDR_SHIFT 12
  273. /*
  274. * Context Configuration handle
  275. * Used to allocate resources to a GSEG context.
  276. *
  277. */
  278. struct gru_context_configuration_handle {
  279. unsigned int cmd:1; /* DW0 */
  280. unsigned int delresp:1;
  281. unsigned int opc:3;
  282. unsigned int unmap_enable:1;
  283. unsigned int req_slice_set_enable:1;
  284. unsigned int req_slice:2;
  285. unsigned int cb_int_enable:1;
  286. unsigned int tlb_int_enable:1;
  287. unsigned int tfm_fault_bit_enable:1;
  288. unsigned int tlb_int_select:4;
  289. unsigned int status:2;
  290. unsigned int state:2;
  291. unsigned int reserved2:4;
  292. unsigned int cause:4;
  293. unsigned int tfm_done_bit_enable:1;
  294. unsigned int unused:3;
  295. unsigned int dsr_allocation_map;
  296. unsigned long cbr_allocation_map; /* DW1 */
  297. unsigned int asid[8]; /* DW 2 - 5 */
  298. unsigned short sizeavail[8]; /* DW 6 - 7 */
  299. } __attribute__ ((packed));
  300. enum gru_cch_opc {
  301. CCHOP_START = 1,
  302. CCHOP_ALLOCATE,
  303. CCHOP_INTERRUPT,
  304. CCHOP_DEALLOCATE,
  305. CCHOP_INTERRUPT_SYNC,
  306. };
  307. enum gru_cch_status {
  308. CCHSTATUS_IDLE,
  309. CCHSTATUS_EXCEPTION,
  310. CCHSTATUS_ACTIVE,
  311. };
  312. enum gru_cch_state {
  313. CCHSTATE_INACTIVE,
  314. CCHSTATE_MAPPED,
  315. CCHSTATE_ACTIVE,
  316. CCHSTATE_INTERRUPTED,
  317. };
  318. /* CCH Exception cause */
  319. enum gru_cch_cause {
  320. CCHCAUSE_REGION_REGISTER_WRITE_ERROR = 1,
  321. CCHCAUSE_ILLEGAL_OPCODE = 2,
  322. CCHCAUSE_INVALID_START_REQUEST = 3,
  323. CCHCAUSE_INVALID_ALLOCATION_REQUEST = 4,
  324. CCHCAUSE_INVALID_DEALLOCATION_REQUEST = 5,
  325. CCHCAUSE_INVALID_INTERRUPT_REQUEST = 6,
  326. CCHCAUSE_CCH_BUSY = 7,
  327. CCHCAUSE_NO_CBRS_TO_ALLOCATE = 8,
  328. CCHCAUSE_BAD_TFM_CONFIG = 9,
  329. CCHCAUSE_CBR_RESOURCES_OVERSUBSCRIPED = 10,
  330. CCHCAUSE_DSR_RESOURCES_OVERSUBSCRIPED = 11,
  331. CCHCAUSE_CBR_DEALLOCATION_ERROR = 12,
  332. };
  333. /*
  334. * CBE - Control Block Extended
  335. * Maintains internal GRU state for active CBs.
  336. *
  337. */
  338. struct gru_control_block_extended {
  339. unsigned int reserved0:1; /* DW 0 - low */
  340. unsigned int imacpy:3;
  341. unsigned int reserved1:4;
  342. unsigned int xtypecpy:3;
  343. unsigned int iaa0cpy:2;
  344. unsigned int iaa1cpy:2;
  345. unsigned int reserved2:1;
  346. unsigned int opccpy:8;
  347. unsigned int exopccpy:8;
  348. unsigned int idef2cpy:22; /* DW 0 - high */
  349. unsigned int reserved3:10;
  350. unsigned int idef4cpy:22; /* DW 1 */
  351. unsigned int reserved4:10;
  352. unsigned int idef4upd:22;
  353. unsigned int reserved5:10;
  354. unsigned long idef1upd:64; /* DW 2 */
  355. unsigned long idef5cpy:64; /* DW 3 */
  356. unsigned long idef6cpy:64; /* DW 4 */
  357. unsigned long idef3upd:64; /* DW 5 */
  358. unsigned long idef5upd:64; /* DW 6 */
  359. unsigned int idef2upd:22; /* DW 7 */
  360. unsigned int reserved6:10;
  361. unsigned int ecause:20;
  362. unsigned int cbrstate:4;
  363. unsigned int cbrexecstatus:8;
  364. };
  365. enum gru_cbr_state {
  366. CBRSTATE_INACTIVE,
  367. CBRSTATE_IDLE,
  368. CBRSTATE_PE_CHECK,
  369. CBRSTATE_QUEUED,
  370. CBRSTATE_WAIT_RESPONSE,
  371. CBRSTATE_INTERRUPTED,
  372. CBRSTATE_INTERRUPTED_MISS_FMM,
  373. CBRSTATE_BUSY_INTERRUPT_MISS_FMM,
  374. CBRSTATE_INTERRUPTED_MISS_UPM,
  375. CBRSTATE_BUSY_INTERRUPTED_MISS_UPM,
  376. CBRSTATE_REQUEST_ISSUE,
  377. CBRSTATE_BUSY_INTERRUPT,
  378. };
  379. /* CBE cbrexecstatus bits - defined in gru_instructions.h*/
  380. /* CBE ecause bits - defined in gru_instructions.h */
  381. /*
  382. * Convert a processor pagesize into the strange encoded pagesize used by the
  383. * GRU. Processor pagesize is encoded as log of bytes per page. (or PAGE_SHIFT)
  384. * pagesize log pagesize grupagesize
  385. * 4k 12 0
  386. * 16k 14 1
  387. * 64k 16 2
  388. * 256k 18 3
  389. * 1m 20 4
  390. * 2m 21 5
  391. * 4m 22 6
  392. * 16m 24 7
  393. * 64m 26 8
  394. * ...
  395. */
  396. #define GRU_PAGESIZE(sh) ((((sh) > 20 ? (sh) + 2 : (sh)) >> 1) - 6)
  397. #define GRU_SIZEAVAIL(sh) (1UL << GRU_PAGESIZE(sh))
  398. /* minimum TLB purge count to ensure a full purge */
  399. #define GRUMAXINVAL 1024UL
  400. int cch_allocate(struct gru_context_configuration_handle *cch);
  401. int cch_start(struct gru_context_configuration_handle *cch);
  402. int cch_interrupt(struct gru_context_configuration_handle *cch);
  403. int cch_deallocate(struct gru_context_configuration_handle *cch);
  404. int cch_interrupt_sync(struct gru_context_configuration_handle *cch);
  405. int tgh_invalidate(struct gru_tlb_global_handle *tgh, unsigned long vaddr,
  406. unsigned long vaddrmask, int asid, int pagesize, int global, int n,
  407. unsigned short ctxbitmap);
  408. void tfh_write_only(struct gru_tlb_fault_handle *tfh, unsigned long pfn,
  409. unsigned long vaddr, int asid, int dirty, int pagesize);
  410. void tfh_write_restart(struct gru_tlb_fault_handle *tfh, unsigned long paddr,
  411. int gaa, unsigned long vaddr, int asid, int dirty, int pagesize);
  412. void tfh_restart(struct gru_tlb_fault_handle *tfh);
  413. void tfh_user_polling_mode(struct gru_tlb_fault_handle *tfh);
  414. void tfh_exception(struct gru_tlb_fault_handle *tfh);
  415. #endif /* __GRUHANDLES_H__ */