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