17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*b0fc0e77Sgovinda * Common Development and Distribution License (the "License"). 6*b0fc0e77Sgovinda * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*b0fc0e77Sgovinda * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 26159cf8a6Swesolows #ifndef _ZULUMOD_H 27159cf8a6Swesolows #define _ZULUMOD_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 327c478bd9Sstevel@tonic-gate extern "C" { 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <sys/int_const.h> 367c478bd9Sstevel@tonic-gate #include <sys/zuluvm.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifndef _ASM 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #include <sys/zulu_hat.h> 417c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #define ZULUVM_VERSION_STR(a) #a 447c478bd9Sstevel@tonic-gate #define ZULUVM_VERSION(a) ZULUVM_VERSION_STR(a) 457c478bd9Sstevel@tonic-gate #define ZULUVM_MOD_VERSION \ 46159cf8a6Swesolows ZULUVM_VERSION(XHAT_PROVIDER_VERSION) "." \ 477c478bd9Sstevel@tonic-gate ZULUVM_VERSION(ZULUVM_INTERFACE_VERSION) 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate #define ZULUDCHKFUNC(_p1, _p2, _p3) \ 507c478bd9Sstevel@tonic-gate ((_p1) != NULL && (_p1)->_p2 != NULL) ? \ 517c478bd9Sstevel@tonic-gate (_p1)->_p2 _p3 : ZULUVM_NO_SUPPORT 527c478bd9Sstevel@tonic-gate #define ZULUDCHKPROC(_p1, _p2, _p3) \ 537c478bd9Sstevel@tonic-gate if ((_p1) != NULL && (_p1)->_p2 != NULL) (_p1)->_p2 _p3 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #define zulud_set_itlb_pc(_devp, _a, _b) \ 567c478bd9Sstevel@tonic-gate ZULUDCHKPROC((_devp)->dops, set_itlb_pc, (_a, _b)) 577c478bd9Sstevel@tonic-gate #define zulud_set_dtlb_pc(_devp, _a, _b) \ 587c478bd9Sstevel@tonic-gate ZULUDCHKPROC((_devp)->dops, set_dtlb_pc, (_a, _b)) 597c478bd9Sstevel@tonic-gate #define zulud_write_tte(_devp, _a, _b, _c, _d, _e, _f) \ 607c478bd9Sstevel@tonic-gate ZULUDCHKFUNC((_devp)->dops, write_tte, (_a, _b, _c, _d, _e, _f)) 617c478bd9Sstevel@tonic-gate #define zulud_tlb_done(_devp, _a, _b, _c) \ 627c478bd9Sstevel@tonic-gate ZULUDCHKPROC((_devp)->dops, tlb_done, (_a, _b, _c)) 637c478bd9Sstevel@tonic-gate #define zulud_demap_page(_devp, _a, _b, _c) \ 647c478bd9Sstevel@tonic-gate ZULUDCHKPROC((_devp)->dops, demap_page, (_a, _b, _c)) 657c478bd9Sstevel@tonic-gate #define zulud_demap_ctx(_devp, _a, _b) \ 667c478bd9Sstevel@tonic-gate ZULUDCHKPROC((_devp)->dops, demap_ctx, (_a, _b)) 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate #endif 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #define ZULUVM_DATA0_IDX 0 717c478bd9Sstevel@tonic-gate #define ZULUVM_DATA1_IDX 1 727c478bd9Sstevel@tonic-gate #define ZULUVM_DATA2_IDX 2 737c478bd9Sstevel@tonic-gate #define ZULUVM_DATA3_IDX 3 747c478bd9Sstevel@tonic-gate #define ZULUVM_DATA4_IDX 4 757c478bd9Sstevel@tonic-gate #define ZULUVM_DATA5_IDX 5 767c478bd9Sstevel@tonic-gate #define ZULUVM_DATA6_IDX 6 777c478bd9Sstevel@tonic-gate #define ZULUVM_DATA7_IDX 7 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate #define ZULUVM_IDX2FLAG(i) (1 << (7 - i)) 807c478bd9Sstevel@tonic-gate #define ZULUVM_DATA0_FLAG ZULUVM_IDX2FLAG(ZULUVM_DATA0_IDX) 817c478bd9Sstevel@tonic-gate #define ZULUVM_DATA1_FLAG ZULUVM_IDX2FLAG(ZULUVM_DATA1_IDX) 827c478bd9Sstevel@tonic-gate #define ZULUVM_DATA2_FLAG ZULUVM_IDX2FLAG(ZULUVM_DATA2_IDX) 837c478bd9Sstevel@tonic-gate #define ZULUVM_DATA3_FLAG ZULUVM_IDX2FLAG(ZULUVM_DATA3_IDX) 847c478bd9Sstevel@tonic-gate #define ZULUVM_DATA4_FLAG ZULUVM_IDX2FLAG(ZULUVM_DATA4_IDX) 857c478bd9Sstevel@tonic-gate #define ZULUVM_DATA5_FLAG ZULUVM_IDX2FLAG(ZULUVM_DATA5_IDX) 867c478bd9Sstevel@tonic-gate #define ZULUVM_DATA6_FLAG ZULUVM_IDX2FLAG(ZULUVM_DATA6_IDX) 877c478bd9Sstevel@tonic-gate #define ZULUVM_DATA7_FLAG ZULUVM_IDX2FLAG(ZULUVM_DATA7_IDX) 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate #define ZULUVM_TLB_ADDR_IDX ZULUVM_DATA0_IDX 907c478bd9Sstevel@tonic-gate #define ZULUVM_TLB_TYPE_IDX ZULUVM_DATA1_IDX 917c478bd9Sstevel@tonic-gate #define ZULUVM_TLB_TTE_IDX ZULUVM_DATA2_IDX 927c478bd9Sstevel@tonic-gate #define ZULUVM_TLB_ERRCODE_IDX ZULUVM_DATA3_IDX 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate #define ZULUVM_DATA_FLAGS (ZULUVM_DATA1_FLAG | \ 957c478bd9Sstevel@tonic-gate ZULUVM_DATA6_FLAG) 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate #define ZULUVM_GET_TLB_TTE(devp) \ 987c478bd9Sstevel@tonic-gate (devp)->zvm.idata[ZULUVM_TLB_TTE_IDX] 997c478bd9Sstevel@tonic-gate #define ZULUVM_GET_TLB_ADDR(devp) \ 1007c478bd9Sstevel@tonic-gate (devp)->zvm.idata[ZULUVM_TLB_ADDR_IDX] 1017c478bd9Sstevel@tonic-gate #define ZULUVM_GET_TLB_TYPE(devp) (ZULUVM_DMA_MASK & \ 1027c478bd9Sstevel@tonic-gate (devp)->zvm.idata[ZULUVM_TLB_TYPE_IDX]) 1037c478bd9Sstevel@tonic-gate #define ZULUVM_GET_TLB_ERRCODE(devp) (int)(0xffffffff & \ 1047c478bd9Sstevel@tonic-gate (devp)->zvm.idata[ZULUVM_TLB_ERRCODE_IDX]) 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #define ZULUVM_MAX_DEV 2 1077c478bd9Sstevel@tonic-gate #define ZULUVM_PIL PIL_2 1087c478bd9Sstevel@tonic-gate #define ZULUVM_NUM_PGSZS 4 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #define ZULUVM_STATE_IDLE 0 1117c478bd9Sstevel@tonic-gate #define ZULUVM_STATE_STOPPED 1 1127c478bd9Sstevel@tonic-gate #define ZULUVM_STATE_CANCELED 2 1137c478bd9Sstevel@tonic-gate #define ZULUVM_STATE_TLB_PENDING 3 1147c478bd9Sstevel@tonic-gate #define ZULUVM_STATE_INTR_QUEUED 4 1157c478bd9Sstevel@tonic-gate #define ZULUVM_STATE_INTR_PENDING 5 1167c478bd9Sstevel@tonic-gate #define ZULUVM_STATE_WRITE_TTE 6 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate #ifndef _ASM 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate typedef struct { 1217c478bd9Sstevel@tonic-gate uint64_t idata[4]; /* mondo pkt copy area */ 1227c478bd9Sstevel@tonic-gate void *arg; /* arg for device calls */ 1237c478bd9Sstevel@tonic-gate uint64_t mmu_pa; /* phy. addr of MMU regs */ 1247c478bd9Sstevel@tonic-gate struct zuluvm_proc *proc1; 1257c478bd9Sstevel@tonic-gate struct zuluvm_proc *proc2; 1267c478bd9Sstevel@tonic-gate volatile uint32_t state; /* state of tlb miss handling */ 127*b0fc0e77Sgovinda uint64_t intr_num; /* our soft intr number */ 1287c478bd9Sstevel@tonic-gate short dmv_intr; /* dmv interrupt handle */ 1297c478bd9Sstevel@tonic-gate #ifdef ZULUVM_STATS 1307c478bd9Sstevel@tonic-gate int cancel; 1317c478bd9Sstevel@tonic-gate int tlb_miss[ZULUVM_NUM_PGSZS]; 1327c478bd9Sstevel@tonic-gate int pagefault; 1337c478bd9Sstevel@tonic-gate int no_mapping; 1347c478bd9Sstevel@tonic-gate int preload; 1357c478bd9Sstevel@tonic-gate int migrate; 1367c478bd9Sstevel@tonic-gate int pagesize; 1377c478bd9Sstevel@tonic-gate int itlb1miss; 1387c478bd9Sstevel@tonic-gate int dtlb1miss; 1397c478bd9Sstevel@tonic-gate int itlb2miss; 1407c478bd9Sstevel@tonic-gate int dtlb2miss; 1417c478bd9Sstevel@tonic-gate int demap_page; 1427c478bd9Sstevel@tonic-gate int demap_ctx; 1437c478bd9Sstevel@tonic-gate #endif 1447c478bd9Sstevel@tonic-gate uint64_t pfnbuf[50]; 1457c478bd9Sstevel@tonic-gate int pfncnt; 1467c478bd9Sstevel@tonic-gate } zuluvm_miss_t; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate #ifdef ZULUVM_STATS 1497c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_MISS(devp, sz) (devp)->zvm.tlb_miss[sz]++ 1507c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_PAGEFAULT(devp) (devp)->zvm.pagefault++ 1517c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_NOMAP(devp) (devp)->zvm.no_mapping++ 1527c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_PRELOAD(devp) (devp)->zvm.preload++ 1537c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_MIGRATE(devp) (devp)->zvm.migrate++ 1547c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_PAGEZISE(devp) (devp)->zvm.pagesize++ 1557c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_CANCEL(devp) (devp)->zvm.cancel++ 1567c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_DEMAP_PAGE(devp) (devp)->zvm.demap_page++ 1577c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_DEMAP_CTX(devp) (devp)->zvm.demap_ctx++ 1587c478bd9Sstevel@tonic-gate #else 1597c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_MISS(devp, sz) 1607c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_PAGEFAULT(devp) 1617c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_NOMAP(devp) 1627c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_PRELOAD(devp) 1637c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_MIGRATE(devp) 1647c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_PAGEZISE(devp) 1657c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_CANCEL(devp) 1667c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_DEMAP_PAGE(devp) 1677c478bd9Sstevel@tonic-gate #define ZULUVM_STATS_DEMAP_CTX(devp) 1687c478bd9Sstevel@tonic-gate #endif 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate #define ZULUVM_MAX_INTR 32 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate typedef struct { 1737c478bd9Sstevel@tonic-gate short offset; 1747c478bd9Sstevel@tonic-gate short ino; 1757c478bd9Sstevel@tonic-gate } zuluvm_intr_t; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate /* 1787c478bd9Sstevel@tonic-gate * This structure contains per device data. 1797c478bd9Sstevel@tonic-gate * It is protected by dev_lck. 1807c478bd9Sstevel@tonic-gate */ 1817c478bd9Sstevel@tonic-gate typedef struct { 1827c478bd9Sstevel@tonic-gate zuluvm_miss_t zvm; /* tlb miss state */ 1837c478bd9Sstevel@tonic-gate volatile uint64_t *imr; /* intr mapping regs */ 1847c478bd9Sstevel@tonic-gate struct zuluvm_proc *procs; /* protected by proc_lck */ 1857c478bd9Sstevel@tonic-gate dev_info_t *dip; /* device driver instance */ 1867c478bd9Sstevel@tonic-gate zulud_ops_t *dops; /* device drv operations */ 1877c478bd9Sstevel@tonic-gate kmutex_t load_lck; /* protects in_intr */ 1887c478bd9Sstevel@tonic-gate kmutex_t dev_lck; /* protects this struct */ 1897c478bd9Sstevel@tonic-gate kmutex_t proc_lck; /* protects active procs */ 1907c478bd9Sstevel@tonic-gate kcondvar_t intr_wait; /* sync for as_free */ 1917c478bd9Sstevel@tonic-gate int intr_flags; 1927c478bd9Sstevel@tonic-gate int in_intr; 1937c478bd9Sstevel@tonic-gate kmutex_t park_lck; /* page fault thread */ 1947c478bd9Sstevel@tonic-gate kcondvar_t park_cv; 1957c478bd9Sstevel@tonic-gate int parking; 1967c478bd9Sstevel@tonic-gate int agentid; /* zulu's agent id */ 1977c478bd9Sstevel@tonic-gate zuluvm_intr_t interrupts[ZULUVM_MAX_INTR]; 1987c478bd9Sstevel@tonic-gate } zuluvm_state_t; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate #define ZULUVM_INTR_OFFSET offsetof(zuluvm_state_t, interrupts) 2017c478bd9Sstevel@tonic-gate #define ZULUVM_INTR2INO(addr) (((zuluvm_intr_t *)(addr))->ino) 2027c478bd9Sstevel@tonic-gate #define ZULUVM_INTR2ZDEV(addr) \ 2037c478bd9Sstevel@tonic-gate (zuluvm_state_t *)((caddr_t)addr - (ZULUVM_INTR2INO(addr) * \ 2047c478bd9Sstevel@tonic-gate sizeof (zuluvm_intr_t)) - ZULUVM_INTR_OFFSET) 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate typedef struct zuluvm_proc { 2077c478bd9Sstevel@tonic-gate struct zulu_hat *zhat; 2087c478bd9Sstevel@tonic-gate zuluvm_state_t *zdev; /* back ptr to dev instance */ 2097c478bd9Sstevel@tonic-gate unsigned short refcnt; /* keep this until ref == 0 */ 2107c478bd9Sstevel@tonic-gate short valid; /* if valid is 0 then don't use */ 2117c478bd9Sstevel@tonic-gate struct zuluvm_proc *next; 2127c478bd9Sstevel@tonic-gate struct zuluvm_proc *prev; 2137c478bd9Sstevel@tonic-gate } zuluvm_proc_t; 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate #define ZULUVM_DO_INTR1 INT32_C(1) 2167c478bd9Sstevel@tonic-gate #define ZULUVM_WAIT_INTR1 INT32_C(2) 2177c478bd9Sstevel@tonic-gate #define ZULUVM_DO_INTR2 INT32_C(4) 2187c478bd9Sstevel@tonic-gate #define ZULUVM_WAIT_INTR2 INT32_C(8) 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate int zuluvm_change_state(uint32_t *state_pa, int new, int assume); 2217c478bd9Sstevel@tonic-gate void zuluvm_demap_page(void *, struct hat *, short, caddr_t, uint_t); 2227c478bd9Sstevel@tonic-gate void zuluvm_demap_ctx(void *, short); 2237c478bd9Sstevel@tonic-gate void zuluvm_dmv_tlbmiss_tl1(void); 2247c478bd9Sstevel@tonic-gate void zuluvm_load_tte(struct zulu_hat *zhat, caddr_t addr, uint64_t pfn, 2257c478bd9Sstevel@tonic-gate int perm, int size); 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate #endif 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* 2317c478bd9Sstevel@tonic-gate * The following defines are copied from the ZFB and ZULU 2327c478bd9Sstevel@tonic-gate * workspaces. We re-define them here since we can't have 2337c478bd9Sstevel@tonic-gate * a dependency onto files outside our consolidation 2347c478bd9Sstevel@tonic-gate */ 2357c478bd9Sstevel@tonic-gate #define ZULUVM_IMR_V_MASK UINT64_C(0x0000000080000000) 2367c478bd9Sstevel@tonic-gate #define ZULUVM_IMR_TARGET_SHIFT INT32_C(26) 2377c478bd9Sstevel@tonic-gate #define ZULUVM_IMR_MAX INT32_C(0x3f) 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate #define ZULUVM_ZFB_MMU_TLB_D_V_MASK 0x8000000000000000 2407c478bd9Sstevel@tonic-gate #define ZULUVM_ZFB_MMU_TLB_D_PA_SHIFT 0xD /* 13 bits */ 2417c478bd9Sstevel@tonic-gate #define ZULUVM_ZFB_MMU_TLB_D_C_MASK 0x20 2427c478bd9Sstevel@tonic-gate #define ZULUVM_ZFB_MMU_TLB_D_SZ_SHIFT 0x3D /* 61 */ 2437c478bd9Sstevel@tonic-gate #define ZULUVM_ZFB_MMU_TLB_D_SZ_MASK 0x6000000000000000 2447c478bd9Sstevel@tonic-gate #define ZULUVM_ZFB_MMU_TLB_D_W_MASK 0x2 2457c478bd9Sstevel@tonic-gate #define ZULUVM_ZFB_MMU_TLB_CR_IMISS_MASK 0x2 2467c478bd9Sstevel@tonic-gate #define ZULUVM_ZFB_MMU_TLB_CR_DMISS_MASK 0x1 2477c478bd9Sstevel@tonic-gate #define ZULUVM_ZFB_MMU_DTLB_PAGE_SZ_2_MASK 0xc /* DTLB2 Page size */ 2487c478bd9Sstevel@tonic-gate #define ZULUVM_ZFB_MMU_DTLB_PAGE_SZ_2_SHIFT 2 2497c478bd9Sstevel@tonic-gate #define ZULUVM_DTLB_PAGE_SZ 0x8 2507c478bd9Sstevel@tonic-gate #define ZULUVM_ITLB_DATA_IN 0x18 2517c478bd9Sstevel@tonic-gate #define ZULUVM_DTLB_DATA_IN 0x28 2527c478bd9Sstevel@tonic-gate #define ZULUVM_TLB_CONTROL 0 2537c478bd9Sstevel@tonic-gate #define ZULUVM_ITLB_MISS_ICR 0x0 2547c478bd9Sstevel@tonic-gate #define ZULUVM_DTLB_MISS_ICR 0x8 2557c478bd9Sstevel@tonic-gate #define ZULUVM_DMA1_TSB_BASE 0x50 2567c478bd9Sstevel@tonic-gate #define ZULUVM_DMA2_TSB_BASE 0x68 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate #endif 2617c478bd9Sstevel@tonic-gate 262159cf8a6Swesolows #endif /* _ZULUMOD_H */ 263