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