10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51501Sgovinda * Common Development and Distribution License (the "License"). 61501Sgovinda * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 221501Sgovinda * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_PX_MMU_H 270Sstevel@tonic-gate #define _SYS_PX_MMU_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/vmem.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate typedef uint64_t px_dvma_addr_t; 380Sstevel@tonic-gate typedef uint64_t px_dma_bypass_addr_t; 390Sstevel@tonic-gate typedef uint64_t px_dma_peer_addr_t; 400Sstevel@tonic-gate typedef uint16_t px_dvma_context_t; 410Sstevel@tonic-gate typedef uint64_t px_window_t; 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * boiler plate for tte (everything except the pfn) 450Sstevel@tonic-gate */ 46*1772Sjl139090 #define PX_GET_TTE_ATTR(flags, attr)\ 470Sstevel@tonic-gate (((flags & DDI_DMA_READ) ? PCI_MAP_ATTR_WRITE : 0) | \ 48*1772Sjl139090 ((flags & DDI_DMA_WRITE) ? PCI_MAP_ATTR_READ : 0) | \ 49*1772Sjl139090 ((attr & DDI_DMA_RELAXED_ORDERING) ? PCI_MAP_ATTR_RO : 0)) 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* 520Sstevel@tonic-gate * mmu block soft state structure: 530Sstevel@tonic-gate * 540Sstevel@tonic-gate * Each px node may share an mmu block structure with its peer 550Sstevel@tonic-gate * node of have its own private mmu block structure. 560Sstevel@tonic-gate */ 570Sstevel@tonic-gate typedef struct px_mmu { 580Sstevel@tonic-gate px_t *mmu_px_p; /* link back to px soft state */ 590Sstevel@tonic-gate int mmu_inst; 600Sstevel@tonic-gate 610Sstevel@tonic-gate /* 620Sstevel@tonic-gate * address ranges of dvma space: 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate px_dvma_addr_t mmu_dvma_base; 650Sstevel@tonic-gate px_dvma_addr_t mmu_dvma_end; 660Sstevel@tonic-gate px_dvma_addr_t mmu_dvma_fast_end; 670Sstevel@tonic-gate px_dvma_addr_t dvma_base_pg; /* = MMU_BTOP(mmu_dvma_base) */ 680Sstevel@tonic-gate px_dvma_addr_t dvma_end_pg; /* = MMU_BTOP(mmu_dvma_end) */ 690Sstevel@tonic-gate 700Sstevel@tonic-gate /* 710Sstevel@tonic-gate * virtual memory map and callback id for dvma space: 720Sstevel@tonic-gate */ 730Sstevel@tonic-gate vmem_t *mmu_dvma_map; 740Sstevel@tonic-gate uintptr_t mmu_dvma_clid; 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* 770Sstevel@tonic-gate * fields for fast dvma interfaces: 780Sstevel@tonic-gate */ 790Sstevel@tonic-gate ulong_t mmu_dvma_reserve; 800Sstevel@tonic-gate 810Sstevel@tonic-gate /* 820Sstevel@tonic-gate * dvma fast track page cache byte map 830Sstevel@tonic-gate */ 840Sstevel@tonic-gate uint8_t *mmu_dvma_cache_locks; 850Sstevel@tonic-gate uint_t mmu_dvma_addr_scan_start; 860Sstevel@tonic-gate 870Sstevel@tonic-gate /* dvma debug */ 880Sstevel@tonic-gate kmutex_t dvma_debug_lock; 890Sstevel@tonic-gate uint32_t dvma_alloc_rec_index; 900Sstevel@tonic-gate uint32_t dvma_free_rec_index; 910Sstevel@tonic-gate uint32_t dvma_active_count; 920Sstevel@tonic-gate 930Sstevel@tonic-gate struct px_dvma_rec *dvma_alloc_rec; 940Sstevel@tonic-gate struct px_dvma_rec *dvma_free_rec; 950Sstevel@tonic-gate struct px_dvma_rec *dvma_active_list; 960Sstevel@tonic-gate } px_mmu_t; 970Sstevel@tonic-gate 980Sstevel@tonic-gate typedef struct px_dvma_range_prop { 990Sstevel@tonic-gate uint32_t dvma_base; 1000Sstevel@tonic-gate uint32_t dvma_len; 1010Sstevel@tonic-gate } px_dvma_range_prop_t; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate #define MMU_PAGE_INDEX(mmu_p, dvma_pg) ((dvma_pg) - (mmu_p)->dvma_base_pg) 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* dvma debug */ 106909Segillett #define PX_DVMA_DBG_ON(mmu_p) \ 1070Sstevel@tonic-gate ((1ull << (mmu_p)->mmu_inst) & px_dvma_debug_on) 108909Segillett #define PX_DVMA_DBG_OFF(mmu_p) \ 1090Sstevel@tonic-gate ((1ull << (mmu_p)->mmu_inst) & px_dvma_debug_off) 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate extern void px_dvma_debug_fini(px_mmu_t *mmu_p); 1120Sstevel@tonic-gate extern void px_dvma_alloc_debug(px_mmu_t *mmu_p, char *address, uint_t len, 1130Sstevel@tonic-gate ddi_dma_impl_t *mp); 1140Sstevel@tonic-gate extern void px_dvma_free_debug(px_mmu_t *mmu_p, char *address, uint_t len, 1150Sstevel@tonic-gate ddi_dma_impl_t *mp); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* DVMA routines */ 1180Sstevel@tonic-gate extern int px_mmu_map_pages(px_mmu_t *mmu_p, ddi_dma_impl_t *mp, 1190Sstevel@tonic-gate px_dvma_addr_t dvma_pg, size_t npages, size_t pfn_index); 1200Sstevel@tonic-gate extern int px_mmu_map_window(px_mmu_t *mmu_p, ddi_dma_impl_t *mp, 1210Sstevel@tonic-gate px_window_t window); 1221501Sgovinda extern void px_mmu_unmap_pages(px_mmu_t *mmu_p, ddi_dma_impl_t *mp, 1231501Sgovinda px_dvma_addr_t dvma_pg, uint_t npages); 1240Sstevel@tonic-gate extern void px_mmu_unmap_window(px_mmu_t *mmu_p, ddi_dma_impl_t *mp); 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate /* MMU initialization routines */ 1270Sstevel@tonic-gate extern int px_mmu_attach(px_t *px_p); 1280Sstevel@tonic-gate extern void px_mmu_detach(px_t *px_p); 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate #ifdef __cplusplus 1310Sstevel@tonic-gate } 1320Sstevel@tonic-gate #endif 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate #endif /* _SYS_PX_MMU_H */ 135