1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_PX_MMU_H 28*7c478bd9Sstevel@tonic-gate #define _SYS_PX_MMU_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 33*7c478bd9Sstevel@tonic-gate extern "C" { 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <sys/vmem.h> 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate typedef uint64_t px_dvma_addr_t; 39*7c478bd9Sstevel@tonic-gate typedef uint64_t px_dma_bypass_addr_t; 40*7c478bd9Sstevel@tonic-gate typedef uint64_t px_dma_peer_addr_t; 41*7c478bd9Sstevel@tonic-gate typedef uint16_t px_dvma_context_t; 42*7c478bd9Sstevel@tonic-gate typedef uint64_t px_window_t; 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate /* 45*7c478bd9Sstevel@tonic-gate * boiler plate for tte (everything except the pfn) 46*7c478bd9Sstevel@tonic-gate */ 47*7c478bd9Sstevel@tonic-gate #define PX_GET_TTE_ATTR(flags)\ 48*7c478bd9Sstevel@tonic-gate (((flags & DDI_DMA_READ) ? PCI_MAP_ATTR_WRITE : 0) | \ 49*7c478bd9Sstevel@tonic-gate ((flags & DDI_DMA_WRITE) ? PCI_MAP_ATTR_READ : 0)) 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate /* 52*7c478bd9Sstevel@tonic-gate * mmu block soft state structure: 53*7c478bd9Sstevel@tonic-gate * 54*7c478bd9Sstevel@tonic-gate * Each px node may share an mmu block structure with its peer 55*7c478bd9Sstevel@tonic-gate * node of have its own private mmu block structure. 56*7c478bd9Sstevel@tonic-gate */ 57*7c478bd9Sstevel@tonic-gate typedef struct px_mmu { 58*7c478bd9Sstevel@tonic-gate px_t *mmu_px_p; /* link back to px soft state */ 59*7c478bd9Sstevel@tonic-gate int mmu_inst; 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* 62*7c478bd9Sstevel@tonic-gate * address ranges of dvma space: 63*7c478bd9Sstevel@tonic-gate */ 64*7c478bd9Sstevel@tonic-gate px_dvma_addr_t mmu_dvma_base; 65*7c478bd9Sstevel@tonic-gate px_dvma_addr_t mmu_dvma_end; 66*7c478bd9Sstevel@tonic-gate px_dvma_addr_t mmu_dvma_fast_end; 67*7c478bd9Sstevel@tonic-gate px_dvma_addr_t dvma_base_pg; /* = MMU_BTOP(mmu_dvma_base) */ 68*7c478bd9Sstevel@tonic-gate px_dvma_addr_t dvma_end_pg; /* = MMU_BTOP(mmu_dvma_end) */ 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* 71*7c478bd9Sstevel@tonic-gate * virtual memory map and callback id for dvma space: 72*7c478bd9Sstevel@tonic-gate */ 73*7c478bd9Sstevel@tonic-gate vmem_t *mmu_dvma_map; 74*7c478bd9Sstevel@tonic-gate uintptr_t mmu_dvma_clid; 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate /* 77*7c478bd9Sstevel@tonic-gate * fields for fast dvma interfaces: 78*7c478bd9Sstevel@tonic-gate */ 79*7c478bd9Sstevel@tonic-gate ulong_t mmu_dvma_reserve; 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate /* 82*7c478bd9Sstevel@tonic-gate * dvma fast track page cache byte map 83*7c478bd9Sstevel@tonic-gate */ 84*7c478bd9Sstevel@tonic-gate uint8_t *mmu_dvma_cache_locks; 85*7c478bd9Sstevel@tonic-gate uint_t mmu_dvma_addr_scan_start; 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate /* dvma debug */ 88*7c478bd9Sstevel@tonic-gate kmutex_t dvma_debug_lock; 89*7c478bd9Sstevel@tonic-gate uint32_t dvma_alloc_rec_index; 90*7c478bd9Sstevel@tonic-gate uint32_t dvma_free_rec_index; 91*7c478bd9Sstevel@tonic-gate uint32_t dvma_active_count; 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate struct px_dvma_rec *dvma_alloc_rec; 94*7c478bd9Sstevel@tonic-gate struct px_dvma_rec *dvma_free_rec; 95*7c478bd9Sstevel@tonic-gate struct px_dvma_rec *dvma_active_list; 96*7c478bd9Sstevel@tonic-gate } px_mmu_t; 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate typedef struct px_dvma_range_prop { 99*7c478bd9Sstevel@tonic-gate uint32_t dvma_base; 100*7c478bd9Sstevel@tonic-gate uint32_t dvma_len; 101*7c478bd9Sstevel@tonic-gate } px_dvma_range_prop_t; 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate #define MMU_PAGE_INDEX(mmu_p, dvma_pg) ((dvma_pg) - (mmu_p)->dvma_base_pg) 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate /* dvma debug */ 106*7c478bd9Sstevel@tonic-gate #define DVMA_DBG_ON(mmu_p) \ 107*7c478bd9Sstevel@tonic-gate ((1ull << (mmu_p)->mmu_inst) & px_dvma_debug_on) 108*7c478bd9Sstevel@tonic-gate #define DVMA_DBG_OFF(mmu_p) \ 109*7c478bd9Sstevel@tonic-gate ((1ull << (mmu_p)->mmu_inst) & px_dvma_debug_off) 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate extern void px_dvma_debug_fini(px_mmu_t *mmu_p); 112*7c478bd9Sstevel@tonic-gate extern void px_dvma_alloc_debug(px_mmu_t *mmu_p, char *address, uint_t len, 113*7c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp); 114*7c478bd9Sstevel@tonic-gate extern void px_dvma_free_debug(px_mmu_t *mmu_p, char *address, uint_t len, 115*7c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp); 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate /* DVMA routines */ 118*7c478bd9Sstevel@tonic-gate extern int px_mmu_map_pages(px_mmu_t *mmu_p, ddi_dma_impl_t *mp, 119*7c478bd9Sstevel@tonic-gate px_dvma_addr_t dvma_pg, size_t npages, size_t pfn_index); 120*7c478bd9Sstevel@tonic-gate extern int px_mmu_map_window(px_mmu_t *mmu_p, ddi_dma_impl_t *mp, 121*7c478bd9Sstevel@tonic-gate px_window_t window); 122*7c478bd9Sstevel@tonic-gate extern void px_mmu_unmap_pages(px_mmu_t *mmu_p, px_dvma_addr_t dvma_pg, 123*7c478bd9Sstevel@tonic-gate uint_t npages); 124*7c478bd9Sstevel@tonic-gate extern void px_mmu_unmap_window(px_mmu_t *mmu_p, ddi_dma_impl_t *mp); 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate /* MMU initialization routines */ 127*7c478bd9Sstevel@tonic-gate extern int px_mmu_attach(px_t *px_p); 128*7c478bd9Sstevel@tonic-gate extern void px_mmu_detach(px_t *px_p); 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate #endif 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate #endif /* _SYS_PX_MMU_H */ 135