iommuvar.h revision 100188
186230Stmm/*
286230Stmm * Copyright (c) 1999 Matthew R. Green
386230Stmm * All rights reserved.
486230Stmm *
586230Stmm * Redistribution and use in source and binary forms, with or without
686230Stmm * modification, are permitted provided that the following conditions
786230Stmm * are met:
886230Stmm * 1. Redistributions of source code must retain the above copyright
986230Stmm *    notice, this list of conditions and the following disclaimer.
1086230Stmm * 2. Redistributions in binary form must reproduce the above copyright
1186230Stmm *    notice, this list of conditions and the following disclaimer in the
1286230Stmm *    documentation and/or other materials provided with the distribution.
1386230Stmm * 3. The name of the author may not be used to endorse or promote products
1486230Stmm *    derived from this software without specific prior written permission.
1586230Stmm *
1686230Stmm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1786230Stmm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1886230Stmm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1986230Stmm * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2086230Stmm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2186230Stmm * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2286230Stmm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2386230Stmm * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2486230Stmm * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2586230Stmm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2686230Stmm * SUCH DAMAGE.
2786230Stmm *
2890616Stmm *	from: NetBSD: iommuvar.h,v 1.9 2001/07/20 00:07:13 eeh Exp
2986230Stmm *
3086230Stmm * $FreeBSD: head/sys/sparc64/include/iommuvar.h 100188 2002-07-16 18:17:03Z tmm $
3186230Stmm */
3286230Stmm
3386230Stmm#ifndef _MACHINE_IOMMUVAR_H_
3486230Stmm#define _MACHINE_IOMMUVAR_H_
3586230Stmm
3690616Stmm#define	IO_PAGE_SIZE		PAGE_SIZE_8K
3790616Stmm#define	IO_PAGE_MASK		PAGE_MASK_8K
3890616Stmm#define	IO_PAGE_SHIFT		PAGE_SHIFT_8K
3990616Stmm#define	round_io_page(x)	round_page(x)
4090616Stmm#define	trunc_io_page(x)	trunc_page(x)
4190616Stmm
4286230Stmm/*
4386230Stmm * per-IOMMU state
4486230Stmm */
4586230Stmmstruct iommu_state {
4686230Stmm	int			is_tsbsize;	/* 0 = 8K, ... */
4786230Stmm	u_int64_t		is_dvmabase;
4890616Stmm	int64_t			is_cr;		/* IOMMU control register value */
4986230Stmm
5090616Stmm	vm_offset_t		is_flushpa[2];
5190616Stmm	volatile int64_t	*is_flushva[2];
5290616Stmm	/*
5390616Stmm	 * When a flush is completed, 64 bytes will be stored at the given
5490616Stmm	 * location, the first double word being 1, to indicate completion.
5590616Stmm	 * The lower 6 address bits are ignored, so the addresses need to be
5690616Stmm	 * suitably aligned; over-allocate a large enough margin to be able
5790616Stmm	 * to adjust it.
5890616Stmm	 * Two such buffers are needed.
5990616Stmm	 * Needs to be volatile or egcs optimizes away loads.
6090616Stmm	 */
6190616Stmm	volatile char		is_flush[STRBUF_FLUSHSYNC_NBYTES * 3 - 1];
6286230Stmm
6386230Stmm	/* copies of our parents state, to allow us to be self contained */
6486230Stmm	bus_space_tag_t		is_bustag;	/* our bus tag */
6590616Stmm	bus_space_handle_t	is_bushandle;
6690616Stmm	bus_addr_t		is_iommu;	/* IOMMU registers */
6790616Stmm	bus_addr_t		is_sb[2];	/* streaming buffer */
6890616Stmm	bus_addr_t		is_dtag;	/* tag diagnostics access */
6990616Stmm	bus_addr_t		is_ddram;	/* data ram diag. access */
7090616Stmm	bus_addr_t		is_dqueue;	/* LRU queue diag. access */
71100188Stmm	bus_addr_t		is_dva;		/* VA diag. register */
7290616Stmm	bus_addr_t		is_dtcmp;	/* tag compare diag. access */
73100188Stmm
74100188Stmm	STAILQ_ENTRY(iommu_state)	is_link;
7586230Stmm};
7686230Stmm
7786230Stmm/* interfaces for PCI/SBUS code */
78100188Stmmvoid iommu_init(char *, struct iommu_state *, int, u_int32_t, int);
7992844Salfredvoid iommu_reset(struct iommu_state *);
8092844Salfredvoid iommu_enter(struct iommu_state *, vm_offset_t, vm_offset_t, int);
8192844Salfredvoid iommu_remove(struct iommu_state *, vm_offset_t, size_t);
8293053Stmmvoid iommu_decode_fault(struct iommu_state *, vm_offset_t);
8386230Stmm
8493070Stmmint iommu_dvmamap_create(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
8593070Stmm    int, bus_dmamap_t *);
8693070Stmmint iommu_dvmamap_destroy(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
8792844Salfred    bus_dmamap_t);
8893070Stmmint iommu_dvmamap_load(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
8993070Stmm    bus_dmamap_t, void *, bus_size_t, bus_dmamap_callback_t *, void *, int);
9093070Stmmvoid iommu_dvmamap_unload(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
9192844Salfred    bus_dmamap_t);
9293070Stmmvoid iommu_dvmamap_sync(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
9393070Stmm    bus_dmamap_t, bus_dmasync_op_t);
9493070Stmmint iommu_dvmamem_alloc(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
9593070Stmm    void **, int, bus_dmamap_t *);
9693070Stmmvoid iommu_dvmamem_free(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
9793070Stmm    void *, bus_dmamap_t);
9886230Stmm
9986230Stmm#endif /* !_MACHINE_IOMMUVAR_H_ */
100