xref: /illumos-gate/usr/src/uts/sun4u/sys/iommu.h (revision cd21e7c5)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright (c) 1991-2000 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
26*cd21e7c5SGarrett D'Amore /*
27*cd21e7c5SGarrett D'Amore  * Copyright 2012 Garrett D'Amore <garrett@damore.org>.  All rights reserved.
28*cd21e7c5SGarrett D'Amore  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _SYS_IOMMU_H
317c478bd9Sstevel@tonic-gate #define	_SYS_IOMMU_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_ASM)
347c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
357c478bd9Sstevel@tonic-gate #include <sys/sysiosbus.h>
367c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
377c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) && !defined(_ASM) */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifndef _ASM
447c478bd9Sstevel@tonic-gate /* constants for DVMA */
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * It takes an 8byte TSB entry to map i an 8k page, so the conversion
477c478bd9Sstevel@tonic-gate  * from tsb size to dvma mapping is to multiply by 1000 or 0x400
487c478bd9Sstevel@tonic-gate  * left shift by 10 does this
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate #define	IOMMU_TSB_TO_RNG	0xa
517c478bd9Sstevel@tonic-gate #define	IOMMU_TSB_SIZE_8M	0x2000
527c478bd9Sstevel@tonic-gate #define	IOMMU_TSB_SIZE_16M	0x4000
537c478bd9Sstevel@tonic-gate #define	IOMMU_TSB_SIZE_32M	0x8000
547c478bd9Sstevel@tonic-gate #define	IOMMU_TSB_SIZE_64M	0x10000
557c478bd9Sstevel@tonic-gate #define	IOMMU_TSB_SIZE_128M	0x20000
567c478bd9Sstevel@tonic-gate #define	IOMMU_TSB_SIZE_256M	0x40000
577c478bd9Sstevel@tonic-gate #define	IOMMU_TSB_SIZE_512M	0x80000
587c478bd9Sstevel@tonic-gate #define	IOMMU_TSB_SIZE_1G	0x100000
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #define	IOMMU_PAGESIZE		0x2000		/* 8k page */
617c478bd9Sstevel@tonic-gate #define	IOMMU_PAGEMASK		0x1fff
627c478bd9Sstevel@tonic-gate #define	IOMMU_PAGEOFFSET	(IOMMU_PAGESIZE - 1)
637c478bd9Sstevel@tonic-gate #define	IOMMU_N_TTES		(IOMMU_DVMA_RANGE/IOMMU_PAGESIZE)
647c478bd9Sstevel@tonic-gate #define	IOMMU_TSB_TBL_SIZE	(IOMMU_N_TTES << 3)	/* 8B for each entry */
657c478bd9Sstevel@tonic-gate #define	IOMMU_PAGESHIFT		13
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #define	OFF_IOMMU_CTRL_REG	0x2400
687c478bd9Sstevel@tonic-gate #define	IOMMU_CTRL_REG_SIZE	(NATURAL_REG_SIZE)
697c478bd9Sstevel@tonic-gate #define	OFF_TSB_BASE_ADDR	0x2408
707c478bd9Sstevel@tonic-gate #define	TSB_BASE_ADDR_SIZE	(NATURAL_REG_SIZE)
717c478bd9Sstevel@tonic-gate #define	OFF_IOMMU_FLUSH_REG	0x2410
727c478bd9Sstevel@tonic-gate #define	IOMMU_FLUSH_REG		(NATURAL_REG_SIZE)
737c478bd9Sstevel@tonic-gate #define	OFF_IOMMU_TLB_TAG	0x4580
747c478bd9Sstevel@tonic-gate #define	OFF_IOMMU_TLB_DATA	0x4600
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	TSB_SIZE		3		/* 64M of DVMA */
777c478bd9Sstevel@tonic-gate #define	TSB_SIZE_SHIFT		16
787c478bd9Sstevel@tonic-gate #define	IOMMU_TLB_ENTRIES	16
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate #define	IOMMU_DISABLE		0		/* Turns off the IOMMU */
817c478bd9Sstevel@tonic-gate #define	IOMMU_ENABLE		1		/* Turns on the IOMMU */
827c478bd9Sstevel@tonic-gate #define	IOMMU_TLB_VALID		0x40000000ull
837c478bd9Sstevel@tonic-gate #define	IOMMU_DIAG_ENABLE	0x2ull
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * Bit positions in the TLB entries
877c478bd9Sstevel@tonic-gate  */
887c478bd9Sstevel@tonic-gate #define	IOMMU_TLBTAG_WRITABLE	(1 << 21)
897c478bd9Sstevel@tonic-gate #define	IOMMU_TLBTAB_STREAM	(1 << 20)
907c478bd9Sstevel@tonic-gate #define	IOMMU_TLBTAG_SIZE	(1 << 19)
917c478bd9Sstevel@tonic-gate #define	IOMMU_TLBTAG_VA_MASK	0x7ffff	/* 19-bit vpn */
927c478bd9Sstevel@tonic-gate #define	IOMMU_TLBTAG_VA_SHIFT	13
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate #define	IOMMU_TLBDATA_VALID	(1 << 30)
957c478bd9Sstevel@tonic-gate #define	IOMMU_TLBDATA_LOCAL	(1 << 29)
967c478bd9Sstevel@tonic-gate #define	IOMMU_TLBDATA_CACHEABLE	(1 << 28)
977c478bd9Sstevel@tonic-gate #define	IOMMU_TLBDATA_PA_MASK	0xfffffff /* 28-bit ppn */
987c478bd9Sstevel@tonic-gate #define	IOMMU_TLBDATA_PA_SHIFT	13
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * define IOPTEs
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate #define	IOTTE_PFN_MSK	0x1ffffffe000ull
1047c478bd9Sstevel@tonic-gate #define	IOTTE_CACHE	0x10ull
1057c478bd9Sstevel@tonic-gate #define	IOTTE_WRITE	0x2ull
1067c478bd9Sstevel@tonic-gate #define	IOTTE_STREAM	0x1000000000000000ull
1077c478bd9Sstevel@tonic-gate #define	IOTTE_INTRA	0x800000000000000ull
1087c478bd9Sstevel@tonic-gate #define	IOTTE_64K_PAGE	0x2000000000000000ull
1097c478bd9Sstevel@tonic-gate #endif	/* _ASM */
1107c478bd9Sstevel@tonic-gate #define	IOTTE_VALID	0x8000000000000000ull
1117c478bd9Sstevel@tonic-gate #define	IOTTE_PFN_SHIFT 13
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * IOMMU pages to bytes, and back (with and without rounding)
1157c478bd9Sstevel@tonic-gate  */
1167c478bd9Sstevel@tonic-gate #define	iommu_ptob(x)	((x) << IOMMU_PAGESHIFT)
1177c478bd9Sstevel@tonic-gate #define	iommu_btop(x)	(((ioaddr_t)(x)) >> IOMMU_PAGESHIFT)
1187c478bd9Sstevel@tonic-gate #define	iommu_btopr(x)	\
1197c478bd9Sstevel@tonic-gate 	((((ioaddr_t)(x) + IOMMU_PAGEOFFSET) >> IOMMU_PAGESHIFT))
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_ASM)
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /* sbus nexus private dma mapping structure. */
1247c478bd9Sstevel@tonic-gate struct dma_impl_priv {
1257c478bd9Sstevel@tonic-gate 	ddi_dma_impl_t mp;
1267c478bd9Sstevel@tonic-gate 	struct sbus_soft_state *softsp;
1277c478bd9Sstevel@tonic-gate 	volatile int sync_flag;
1287c478bd9Sstevel@tonic-gate 	uint64_t phys_sync_flag;
1297c478bd9Sstevel@tonic-gate };
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate extern int iommu_init(struct sbus_soft_state *, caddr_t);
1327c478bd9Sstevel@tonic-gate extern int iommu_resume_init(struct sbus_soft_state *);
1337c478bd9Sstevel@tonic-gate extern int iommu_dma_mctl(dev_info_t *, dev_info_t *, ddi_dma_handle_t,
1347c478bd9Sstevel@tonic-gate 	enum ddi_dma_ctlops, off_t *, size_t *, caddr_t *, uint_t);
1357c478bd9Sstevel@tonic-gate extern int iommu_dma_allochdl(dev_info_t *, dev_info_t *, ddi_dma_attr_t *,
1367c478bd9Sstevel@tonic-gate 	int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *);
1377c478bd9Sstevel@tonic-gate extern int iommu_dma_freehdl(dev_info_t *, dev_info_t *, ddi_dma_handle_t);
1387c478bd9Sstevel@tonic-gate extern int iommu_dma_bindhdl(dev_info_t *, dev_info_t *, ddi_dma_handle_t,
1397c478bd9Sstevel@tonic-gate 	struct ddi_dma_req *, ddi_dma_cookie_t *, uint_t *);
1407c478bd9Sstevel@tonic-gate extern int iommu_dma_unbindhdl(dev_info_t *, dev_info_t *, ddi_dma_handle_t);
1417c478bd9Sstevel@tonic-gate extern int iommu_dma_flush(dev_info_t *, dev_info_t *, ddi_dma_handle_t,
1427c478bd9Sstevel@tonic-gate 	off_t, size_t, uint_t);
1437c478bd9Sstevel@tonic-gate extern int iommu_dma_win(dev_info_t *, dev_info_t *, ddi_dma_handle_t,
1447c478bd9Sstevel@tonic-gate 	uint_t, off_t *, size_t *, ddi_dma_cookie_t *, uint_t *);
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate extern void iommu_dvma_kaddr_load(ddi_dma_handle_t h, caddr_t a, uint_t len,
1477c478bd9Sstevel@tonic-gate     uint_t index, ddi_dma_cookie_t *cp);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate extern void iommu_dvma_unload(ddi_dma_handle_t h, uint_t objindex, uint_t view);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate extern void iommu_dvma_sync(ddi_dma_handle_t h, uint_t objindex, uint_t view);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #endif /* _KERNEL && !_ASM */
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate #endif
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #endif	/* _SYS_IOMMU_H */
160