xref: /illumos-gate/usr/src/uts/sun4/io/px/px_mmu.h (revision 25cf1a30)
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
51de45cd9Sgovinda  * Common Development and Distribution License (the "License").
61de45cd9Sgovinda  * 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 /*
221de45cd9Sgovinda  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_PX_MMU_H
277c478bd9Sstevel@tonic-gate #define	_SYS_PX_MMU_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/vmem.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate typedef uint64_t px_dvma_addr_t;
387c478bd9Sstevel@tonic-gate typedef uint64_t px_dma_bypass_addr_t;
397c478bd9Sstevel@tonic-gate typedef uint64_t px_dma_peer_addr_t;
407c478bd9Sstevel@tonic-gate typedef uint16_t px_dvma_context_t;
417c478bd9Sstevel@tonic-gate typedef uint64_t px_window_t;
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * boiler plate for tte (everything except the pfn)
457c478bd9Sstevel@tonic-gate  */
46*25cf1a30Sjl139090 #define	PX_GET_TTE_ATTR(flags, attr)\
477c478bd9Sstevel@tonic-gate 	(((flags & DDI_DMA_READ) ? PCI_MAP_ATTR_WRITE : 0) | \
48*25cf1a30Sjl139090 	((flags & DDI_DMA_WRITE) ? PCI_MAP_ATTR_READ : 0) | \
49*25cf1a30Sjl139090 	((attr & DDI_DMA_RELAXED_ORDERING) ? PCI_MAP_ATTR_RO : 0))
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * mmu block soft state structure:
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  * Each px node may share an mmu block structure with its peer
557c478bd9Sstevel@tonic-gate  * node of have its own private mmu block structure.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate typedef struct px_mmu {
587c478bd9Sstevel@tonic-gate 	px_t *mmu_px_p;	/* link back to px soft state */
597c478bd9Sstevel@tonic-gate 	int mmu_inst;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	/*
627c478bd9Sstevel@tonic-gate 	 * address ranges of dvma space:
637c478bd9Sstevel@tonic-gate 	 */
647c478bd9Sstevel@tonic-gate 	px_dvma_addr_t mmu_dvma_base;
657c478bd9Sstevel@tonic-gate 	px_dvma_addr_t mmu_dvma_end;
667c478bd9Sstevel@tonic-gate 	px_dvma_addr_t mmu_dvma_fast_end;
677c478bd9Sstevel@tonic-gate 	px_dvma_addr_t dvma_base_pg;	/* = MMU_BTOP(mmu_dvma_base) */
687c478bd9Sstevel@tonic-gate 	px_dvma_addr_t dvma_end_pg;	/* = MMU_BTOP(mmu_dvma_end) */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	/*
717c478bd9Sstevel@tonic-gate 	 * virtual memory map and callback id for dvma space:
727c478bd9Sstevel@tonic-gate 	 */
737c478bd9Sstevel@tonic-gate 	vmem_t *mmu_dvma_map;
747c478bd9Sstevel@tonic-gate 	uintptr_t mmu_dvma_clid;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	/*
777c478bd9Sstevel@tonic-gate 	 * fields for fast dvma interfaces:
787c478bd9Sstevel@tonic-gate 	 */
797c478bd9Sstevel@tonic-gate 	ulong_t mmu_dvma_reserve;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	/*
827c478bd9Sstevel@tonic-gate 	 * dvma fast track page cache byte map
837c478bd9Sstevel@tonic-gate 	 */
847c478bd9Sstevel@tonic-gate 	uint8_t *mmu_dvma_cache_locks;
857c478bd9Sstevel@tonic-gate 	uint_t mmu_dvma_addr_scan_start;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	/* dvma debug */
887c478bd9Sstevel@tonic-gate 	kmutex_t dvma_debug_lock;
897c478bd9Sstevel@tonic-gate 	uint32_t dvma_alloc_rec_index;
907c478bd9Sstevel@tonic-gate 	uint32_t dvma_free_rec_index;
917c478bd9Sstevel@tonic-gate 	uint32_t dvma_active_count;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	struct px_dvma_rec *dvma_alloc_rec;
947c478bd9Sstevel@tonic-gate 	struct px_dvma_rec *dvma_free_rec;
957c478bd9Sstevel@tonic-gate 	struct px_dvma_rec *dvma_active_list;
967c478bd9Sstevel@tonic-gate } px_mmu_t;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate typedef struct px_dvma_range_prop {
997c478bd9Sstevel@tonic-gate 	uint32_t dvma_base;
1007c478bd9Sstevel@tonic-gate 	uint32_t dvma_len;
1017c478bd9Sstevel@tonic-gate } px_dvma_range_prop_t;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #define	MMU_PAGE_INDEX(mmu_p, dvma_pg) ((dvma_pg) - (mmu_p)->dvma_base_pg)
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /* dvma debug */
10636fe4a92Segillett #define	PX_DVMA_DBG_ON(mmu_p)  \
1077c478bd9Sstevel@tonic-gate 	((1ull << (mmu_p)->mmu_inst) & px_dvma_debug_on)
10836fe4a92Segillett #define	PX_DVMA_DBG_OFF(mmu_p) \
1097c478bd9Sstevel@tonic-gate 	((1ull << (mmu_p)->mmu_inst) & px_dvma_debug_off)
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate extern	void px_dvma_debug_fini(px_mmu_t *mmu_p);
1127c478bd9Sstevel@tonic-gate extern	void px_dvma_alloc_debug(px_mmu_t *mmu_p, char *address, uint_t len,
1137c478bd9Sstevel@tonic-gate 	ddi_dma_impl_t *mp);
1147c478bd9Sstevel@tonic-gate extern	void px_dvma_free_debug(px_mmu_t *mmu_p, char *address, uint_t len,
1157c478bd9Sstevel@tonic-gate 	ddi_dma_impl_t *mp);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /* DVMA routines */
1187c478bd9Sstevel@tonic-gate extern int px_mmu_map_pages(px_mmu_t *mmu_p, ddi_dma_impl_t *mp,
1197c478bd9Sstevel@tonic-gate     px_dvma_addr_t dvma_pg, size_t npages, size_t pfn_index);
1207c478bd9Sstevel@tonic-gate extern int px_mmu_map_window(px_mmu_t *mmu_p, ddi_dma_impl_t *mp,
1217c478bd9Sstevel@tonic-gate     px_window_t window);
1221de45cd9Sgovinda extern void px_mmu_unmap_pages(px_mmu_t *mmu_p, ddi_dma_impl_t *mp,
1231de45cd9Sgovinda     px_dvma_addr_t dvma_pg, uint_t npages);
1247c478bd9Sstevel@tonic-gate extern void px_mmu_unmap_window(px_mmu_t *mmu_p, ddi_dma_impl_t *mp);
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /* MMU initialization routines */
1277c478bd9Sstevel@tonic-gate extern int px_mmu_attach(px_t *px_p);
1287c478bd9Sstevel@tonic-gate extern void px_mmu_detach(px_t *px_p);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate #endif
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate #endif	/* _SYS_PX_MMU_H */
135