Path: blob/master/drivers/misc/sgi-gru/gruhandles.h
15111 views
/*1* SN Platform GRU Driver2*3* GRU HANDLE DEFINITION4*5* Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA20*/2122#ifndef __GRUHANDLES_H__23#define __GRUHANDLES_H__24#include "gru_instructions.h"2526/*27* Manifest constants for GRU Memory Map28*/29#define GRU_GSEG0_BASE 030#define GRU_MCS_BASE (64 * 1024 * 1024)31#define GRU_SIZE (128UL * 1024 * 1024)3233/* Handle & resource counts */34#define GRU_NUM_CB 12835#define GRU_NUM_DSR_BYTES (32 * 1024)36#define GRU_NUM_TFM 1637#define GRU_NUM_TGH 2438#define GRU_NUM_CBE 12839#define GRU_NUM_TFH 12840#define GRU_NUM_CCH 164142/* Maximum resource counts that can be reserved by user programs */43#define GRU_NUM_USER_CBR GRU_NUM_CBE44#define GRU_NUM_USER_DSR_BYTES GRU_NUM_DSR_BYTES4546/* Bytes per handle & handle stride. Code assumes all cb, tfh, cbe handles47* are the same */48#define GRU_HANDLE_BYTES 6449#define GRU_HANDLE_STRIDE 2565051/* Base addresses of handles */52#define GRU_TFM_BASE (GRU_MCS_BASE + 0x00000)53#define GRU_TGH_BASE (GRU_MCS_BASE + 0x08000)54#define GRU_CBE_BASE (GRU_MCS_BASE + 0x10000)55#define GRU_TFH_BASE (GRU_MCS_BASE + 0x18000)56#define GRU_CCH_BASE (GRU_MCS_BASE + 0x20000)5758/* User gseg constants */59#define GRU_GSEG_STRIDE (4 * 1024 * 1024)60#define GSEG_BASE(a) ((a) & ~(GRU_GSEG_PAGESIZE - 1))6162/* Data segment constants */63#define GRU_DSR_AU_BYTES 102464#define GRU_DSR_CL (GRU_NUM_DSR_BYTES / GRU_CACHE_LINE_BYTES)65#define GRU_DSR_AU_CL (GRU_DSR_AU_BYTES / GRU_CACHE_LINE_BYTES)66#define GRU_DSR_AU (GRU_NUM_DSR_BYTES / GRU_DSR_AU_BYTES)6768/* Control block constants */69#define GRU_CBR_AU_SIZE 270#define GRU_CBR_AU (GRU_NUM_CBE / GRU_CBR_AU_SIZE)7172/* Convert resource counts to the number of AU */73#define GRU_DS_BYTES_TO_AU(n) DIV_ROUND_UP(n, GRU_DSR_AU_BYTES)74#define GRU_CB_COUNT_TO_AU(n) DIV_ROUND_UP(n, GRU_CBR_AU_SIZE)7576/* UV limits */77#define GRU_CHIPLETS_PER_HUB 278#define GRU_HUBS_PER_BLADE 179#define GRU_CHIPLETS_PER_BLADE (GRU_HUBS_PER_BLADE * GRU_CHIPLETS_PER_HUB)8081/* User GRU Gseg offsets */82#define GRU_CB_BASE 083#define GRU_CB_LIMIT (GRU_CB_BASE + GRU_HANDLE_STRIDE * GRU_NUM_CBE)84#define GRU_DS_BASE 0x2000085#define GRU_DS_LIMIT (GRU_DS_BASE + GRU_NUM_DSR_BYTES)8687/* Convert a GRU physical address to the chiplet offset */88#define GSEGPOFF(h) ((h) & (GRU_SIZE - 1))8990/* Convert an arbitrary handle address to the beginning of the GRU segment */91#define GRUBASE(h) ((void *)((unsigned long)(h) & ~(GRU_SIZE - 1)))9293/* Test a valid handle address to determine the type */94#define TYPE_IS(hn, h) ((h) >= GRU_##hn##_BASE && (h) < \95GRU_##hn##_BASE + GRU_NUM_##hn * GRU_HANDLE_STRIDE && \96(((h) & (GRU_HANDLE_STRIDE - 1)) == 0))979899/* General addressing macros. */100static inline void *get_gseg_base_address(void *base, int ctxnum)101{102return (void *)(base + GRU_GSEG0_BASE + GRU_GSEG_STRIDE * ctxnum);103}104105static inline void *get_gseg_base_address_cb(void *base, int ctxnum, int line)106{107return (void *)(get_gseg_base_address(base, ctxnum) +108GRU_CB_BASE + GRU_HANDLE_STRIDE * line);109}110111static inline void *get_gseg_base_address_ds(void *base, int ctxnum, int line)112{113return (void *)(get_gseg_base_address(base, ctxnum) + GRU_DS_BASE +114GRU_CACHE_LINE_BYTES * line);115}116117static inline struct gru_tlb_fault_map *get_tfm(void *base, int ctxnum)118{119return (struct gru_tlb_fault_map *)(base + GRU_TFM_BASE +120ctxnum * GRU_HANDLE_STRIDE);121}122123static inline struct gru_tlb_global_handle *get_tgh(void *base, int ctxnum)124{125return (struct gru_tlb_global_handle *)(base + GRU_TGH_BASE +126ctxnum * GRU_HANDLE_STRIDE);127}128129static inline struct gru_control_block_extended *get_cbe(void *base, int ctxnum)130{131return (struct gru_control_block_extended *)(base + GRU_CBE_BASE +132ctxnum * GRU_HANDLE_STRIDE);133}134135static inline struct gru_tlb_fault_handle *get_tfh(void *base, int ctxnum)136{137return (struct gru_tlb_fault_handle *)(base + GRU_TFH_BASE +138ctxnum * GRU_HANDLE_STRIDE);139}140141static inline struct gru_context_configuration_handle *get_cch(void *base,142int ctxnum)143{144return (struct gru_context_configuration_handle *)(base +145GRU_CCH_BASE + ctxnum * GRU_HANDLE_STRIDE);146}147148static inline unsigned long get_cb_number(void *cb)149{150return (((unsigned long)cb - GRU_CB_BASE) % GRU_GSEG_PAGESIZE) /151GRU_HANDLE_STRIDE;152}153154/* byte offset to a specific GRU chiplet. (p=pnode, c=chiplet (0 or 1)*/155static inline unsigned long gru_chiplet_paddr(unsigned long paddr, int pnode,156int chiplet)157{158return paddr + GRU_SIZE * (2 * pnode + chiplet);159}160161static inline void *gru_chiplet_vaddr(void *vaddr, int pnode, int chiplet)162{163return vaddr + GRU_SIZE * (2 * pnode + chiplet);164}165166static inline struct gru_control_block_extended *gru_tfh_to_cbe(167struct gru_tlb_fault_handle *tfh)168{169unsigned long cbe;170171cbe = (unsigned long)tfh - GRU_TFH_BASE + GRU_CBE_BASE;172return (struct gru_control_block_extended*)cbe;173}174175176177178/*179* Global TLB Fault Map180* Bitmap of outstanding TLB misses needing interrupt/polling service.181*182*/183struct gru_tlb_fault_map {184unsigned long fault_bits[BITS_TO_LONGS(GRU_NUM_CBE)];185unsigned long fill0[2];186unsigned long done_bits[BITS_TO_LONGS(GRU_NUM_CBE)];187unsigned long fill1[2];188};189190/*191* TGH - TLB Global Handle192* Used for TLB flushing.193*194*/195struct gru_tlb_global_handle {196unsigned int cmd:1; /* DW 0 */197unsigned int delresp:1;198unsigned int opc:1;199unsigned int fill1:5;200201unsigned int fill2:8;202203unsigned int status:2;204unsigned long fill3:2;205unsigned int state:3;206unsigned long fill4:1;207208unsigned int cause:3;209unsigned long fill5:37;210211unsigned long vaddr:64; /* DW 1 */212213unsigned int asid:24; /* DW 2 */214unsigned int fill6:8;215216unsigned int pagesize:5;217unsigned int fill7:11;218219unsigned int global:1;220unsigned int fill8:15;221222unsigned long vaddrmask:39; /* DW 3 */223unsigned int fill9:9;224unsigned int n:10;225unsigned int fill10:6;226227unsigned int ctxbitmap:16; /* DW4 */228unsigned long fill11[3];229};230231enum gru_tgh_cmd {232TGHCMD_START233};234235enum gru_tgh_opc {236TGHOP_TLBNOP,237TGHOP_TLBINV238};239240enum gru_tgh_status {241TGHSTATUS_IDLE,242TGHSTATUS_EXCEPTION,243TGHSTATUS_ACTIVE244};245246enum gru_tgh_state {247TGHSTATE_IDLE,248TGHSTATE_PE_INVAL,249TGHSTATE_INTERRUPT_INVAL,250TGHSTATE_WAITDONE,251TGHSTATE_RESTART_CTX,252};253254enum gru_tgh_cause {255TGHCAUSE_RR_ECC,256TGHCAUSE_TLB_ECC,257TGHCAUSE_LRU_ECC,258TGHCAUSE_PS_ECC,259TGHCAUSE_MUL_ERR,260TGHCAUSE_DATA_ERR,261TGHCAUSE_SW_FORCE262};263264265/*266* TFH - TLB Global Handle267* Used for TLB dropins into the GRU TLB.268*269*/270struct gru_tlb_fault_handle {271unsigned int cmd:1; /* DW 0 - low 32*/272unsigned int delresp:1;273unsigned int fill0:2;274unsigned int opc:3;275unsigned int fill1:9;276277unsigned int status:2;278unsigned int fill2:2;279unsigned int state:3;280unsigned int fill3:1;281282unsigned int cause:6;283unsigned int cb_int:1;284unsigned int fill4:1;285286unsigned int indexway:12; /* DW 0 - high 32 */287unsigned int fill5:4;288289unsigned int ctxnum:4;290unsigned int fill6:12;291292unsigned long missvaddr:64; /* DW 1 */293294unsigned int missasid:24; /* DW 2 */295unsigned int fill7:8;296unsigned int fillasid:24;297unsigned int dirty:1;298unsigned int gaa:2;299unsigned long fill8:5;300301unsigned long pfn:41; /* DW 3 */302unsigned int fill9:7;303unsigned int pagesize:5;304unsigned int fill10:11;305306unsigned long fillvaddr:64; /* DW 4 */307308unsigned long fill11[3];309};310311enum gru_tfh_opc {312TFHOP_NOOP,313TFHOP_RESTART,314TFHOP_WRITE_ONLY,315TFHOP_WRITE_RESTART,316TFHOP_EXCEPTION,317TFHOP_USER_POLLING_MODE = 7,318};319320enum tfh_status {321TFHSTATUS_IDLE,322TFHSTATUS_EXCEPTION,323TFHSTATUS_ACTIVE,324};325326enum tfh_state {327TFHSTATE_INACTIVE,328TFHSTATE_IDLE,329TFHSTATE_MISS_UPM,330TFHSTATE_MISS_FMM,331TFHSTATE_HW_ERR,332TFHSTATE_WRITE_TLB,333TFHSTATE_RESTART_CBR,334};335336/* TFH cause bits */337enum tfh_cause {338TFHCAUSE_NONE,339TFHCAUSE_TLB_MISS,340TFHCAUSE_TLB_MOD,341TFHCAUSE_HW_ERROR_RR,342TFHCAUSE_HW_ERROR_MAIN_ARRAY,343TFHCAUSE_HW_ERROR_VALID,344TFHCAUSE_HW_ERROR_PAGESIZE,345TFHCAUSE_INSTRUCTION_EXCEPTION,346TFHCAUSE_UNCORRECTIBLE_ERROR,347};348349/* GAA values */350#define GAA_RAM 0x0351#define GAA_NCRAM 0x2352#define GAA_MMIO 0x1353#define GAA_REGISTER 0x3354355/* GRU paddr shift for pfn. (NOTE: shift is NOT by actual pagesize) */356#define GRU_PADDR_SHIFT 12357358/*359* Context Configuration handle360* Used to allocate resources to a GSEG context.361*362*/363struct gru_context_configuration_handle {364unsigned int cmd:1; /* DW0 */365unsigned int delresp:1;366unsigned int opc:3;367unsigned int unmap_enable:1;368unsigned int req_slice_set_enable:1;369unsigned int req_slice:2;370unsigned int cb_int_enable:1;371unsigned int tlb_int_enable:1;372unsigned int tfm_fault_bit_enable:1;373unsigned int tlb_int_select:4;374375unsigned int status:2;376unsigned int state:2;377unsigned int reserved2:4;378379unsigned int cause:4;380unsigned int tfm_done_bit_enable:1;381unsigned int unused:3;382383unsigned int dsr_allocation_map;384385unsigned long cbr_allocation_map; /* DW1 */386387unsigned int asid[8]; /* DW 2 - 5 */388unsigned short sizeavail[8]; /* DW 6 - 7 */389} __attribute__ ((packed));390391enum gru_cch_opc {392CCHOP_START = 1,393CCHOP_ALLOCATE,394CCHOP_INTERRUPT,395CCHOP_DEALLOCATE,396CCHOP_INTERRUPT_SYNC,397};398399enum gru_cch_status {400CCHSTATUS_IDLE,401CCHSTATUS_EXCEPTION,402CCHSTATUS_ACTIVE,403};404405enum gru_cch_state {406CCHSTATE_INACTIVE,407CCHSTATE_MAPPED,408CCHSTATE_ACTIVE,409CCHSTATE_INTERRUPTED,410};411412/* CCH Exception cause */413enum gru_cch_cause {414CCHCAUSE_REGION_REGISTER_WRITE_ERROR = 1,415CCHCAUSE_ILLEGAL_OPCODE = 2,416CCHCAUSE_INVALID_START_REQUEST = 3,417CCHCAUSE_INVALID_ALLOCATION_REQUEST = 4,418CCHCAUSE_INVALID_DEALLOCATION_REQUEST = 5,419CCHCAUSE_INVALID_INTERRUPT_REQUEST = 6,420CCHCAUSE_CCH_BUSY = 7,421CCHCAUSE_NO_CBRS_TO_ALLOCATE = 8,422CCHCAUSE_BAD_TFM_CONFIG = 9,423CCHCAUSE_CBR_RESOURCES_OVERSUBSCRIPED = 10,424CCHCAUSE_DSR_RESOURCES_OVERSUBSCRIPED = 11,425CCHCAUSE_CBR_DEALLOCATION_ERROR = 12,426};427/*428* CBE - Control Block Extended429* Maintains internal GRU state for active CBs.430*431*/432struct gru_control_block_extended {433unsigned int reserved0:1; /* DW 0 - low */434unsigned int imacpy:3;435unsigned int reserved1:4;436unsigned int xtypecpy:3;437unsigned int iaa0cpy:2;438unsigned int iaa1cpy:2;439unsigned int reserved2:1;440unsigned int opccpy:8;441unsigned int exopccpy:8;442443unsigned int idef2cpy:22; /* DW 0 - high */444unsigned int reserved3:10;445446unsigned int idef4cpy:22; /* DW 1 */447unsigned int reserved4:10;448unsigned int idef4upd:22;449unsigned int reserved5:10;450451unsigned long idef1upd:64; /* DW 2 */452453unsigned long idef5cpy:64; /* DW 3 */454455unsigned long idef6cpy:64; /* DW 4 */456457unsigned long idef3upd:64; /* DW 5 */458459unsigned long idef5upd:64; /* DW 6 */460461unsigned int idef2upd:22; /* DW 7 */462unsigned int reserved6:10;463464unsigned int ecause:20;465unsigned int cbrstate:4;466unsigned int cbrexecstatus:8;467};468469/* CBE fields for active BCOPY instructions */470#define cbe_baddr0 idef1upd471#define cbe_baddr1 idef3upd472#define cbe_src_cl idef6cpy473#define cbe_nelemcur idef5upd474475enum gru_cbr_state {476CBRSTATE_INACTIVE,477CBRSTATE_IDLE,478CBRSTATE_PE_CHECK,479CBRSTATE_QUEUED,480CBRSTATE_WAIT_RESPONSE,481CBRSTATE_INTERRUPTED,482CBRSTATE_INTERRUPTED_MISS_FMM,483CBRSTATE_BUSY_INTERRUPT_MISS_FMM,484CBRSTATE_INTERRUPTED_MISS_UPM,485CBRSTATE_BUSY_INTERRUPTED_MISS_UPM,486CBRSTATE_REQUEST_ISSUE,487CBRSTATE_BUSY_INTERRUPT,488};489490/* CBE cbrexecstatus bits - defined in gru_instructions.h*/491/* CBE ecause bits - defined in gru_instructions.h */492493/*494* Convert a processor pagesize into the strange encoded pagesize used by the495* GRU. Processor pagesize is encoded as log of bytes per page. (or PAGE_SHIFT)496* pagesize log pagesize grupagesize497* 4k 12 0498* 16k 14 1499* 64k 16 2500* 256k 18 3501* 1m 20 4502* 2m 21 5503* 4m 22 6504* 16m 24 7505* 64m 26 8506* ...507*/508#define GRU_PAGESIZE(sh) ((((sh) > 20 ? (sh) + 2 : (sh)) >> 1) - 6)509#define GRU_SIZEAVAIL(sh) (1UL << GRU_PAGESIZE(sh))510511/* minimum TLB purge count to ensure a full purge */512#define GRUMAXINVAL 1024UL513514int cch_allocate(struct gru_context_configuration_handle *cch);515int cch_start(struct gru_context_configuration_handle *cch);516int cch_interrupt(struct gru_context_configuration_handle *cch);517int cch_deallocate(struct gru_context_configuration_handle *cch);518int cch_interrupt_sync(struct gru_context_configuration_handle *cch);519int tgh_invalidate(struct gru_tlb_global_handle *tgh, unsigned long vaddr,520unsigned long vaddrmask, int asid, int pagesize, int global, int n,521unsigned short ctxbitmap);522int tfh_write_only(struct gru_tlb_fault_handle *tfh, unsigned long paddr,523int gaa, unsigned long vaddr, int asid, int dirty, int pagesize);524void tfh_write_restart(struct gru_tlb_fault_handle *tfh, unsigned long paddr,525int gaa, unsigned long vaddr, int asid, int dirty, int pagesize);526void tfh_restart(struct gru_tlb_fault_handle *tfh);527void tfh_user_polling_mode(struct gru_tlb_fault_handle *tfh);528void tfh_exception(struct gru_tlb_fault_handle *tfh);529530#endif /* __GRUHANDLES_H__ */531532533