iommuvar.h revision 1.15
1/* $OpenBSD: iommuvar.h,v 1.15 2009/05/04 16:48:37 oga Exp $ */ 2/* $NetBSD: iommuvar.h,v 1.9 2001/10/07 20:30:41 eeh Exp $ */ 3 4/* 5 * Copyright (c) 2003 Henric Jungheim 6 * Copyright (c) 1999 Matthew R. Green 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33#ifndef _SPARC64_DEV_IOMMUVAR_H_ 34#define _SPARC64_DEV_IOMMUVAR_H_ 35 36#ifndef _SYS_TREE_H_ 37#include <sys/tree.h> 38#endif 39 40#include <sys/mutex.h> 41 42/* 43 * per-Streaming Buffer state 44 */ 45struct strbuf_ctl { 46 bus_space_tag_t sb_bustag; /* streaming buffer registers */ 47 bus_space_handle_t sb_sb; /* Handle for our regs */ 48 struct iommu_state *sb_iommu; /* Associated IOMMU */ 49 /* 50 * Since implementing the per-map IOMMU state, these per-STC 51 * flush areas are not used other than as a boolean flag to indicate 52 * the presence of a working and enabled STC. For inconsistency's 53 * sake, the "sb" pointers of iommu_state are sometimes used for the 54 * same purpose. This should be consolidated. DEFINATELY, since 55 * mutex operations must happen at this level. 56 */ 57 struct mutex sb_mtx; /* one flush at a time */ 58 59 paddr_t sb_flushpa; /* to flush streaming buffers */ 60 volatile int64_t *sb_flush; 61}; 62 63/* 64 * per-map STC flush area 65 */ 66struct strbuf_flush { 67 char sbf_area[0x80]; /* Holds 64-byte long/aligned buffer */ 68 void *sbf_flush; /* Kernel virtual address of buffer */ 69 paddr_t sbf_flushpa; /* Physical address of buffer area */ 70}; 71 72/* 73 * per-map DVMA page table 74 */ 75struct iommu_page_entry { 76 SPLAY_ENTRY(iommu_page_entry) ipe_node; 77 paddr_t ipe_pa; 78 bus_addr_t ipe_va; 79}; 80struct iommu_page_map { 81 SPLAY_HEAD(iommu_page_tree, iommu_page_entry) ipm_tree; 82 int ipm_maxpage; /* Size of allocated page map */ 83 int ipm_pagecnt; /* Number of entries in use */ 84 struct iommu_page_entry ipm_map[1]; 85}; 86 87/* 88 * per-map IOMMU state 89 * 90 * This is what bus_dvmamap_t'c _dm_cookie should be pointing to. 91 */ 92struct iommu_map_state { 93 struct strbuf_flush ims_flush; /* flush should be first (alignment) */ 94 struct strbuf_ctl *ims_sb; /* Link to parent */ 95 struct iommu_state *ims_iommu; 96 int ims_flags; 97 struct iommu_page_map ims_map; /* map must be last (array at end) */ 98}; 99#define IOMMU_MAP_STREAM 1 100 101/* 102 * per-IOMMU state 103 */ 104struct iommu_state { 105 paddr_t is_ptsb; /* TSB physical address */ 106 int64_t *is_tsb; /* TSB virtual address */ 107 int is_tsbsize; /* 0 = 8K, ... */ 108 u_int is_dvmabase; 109 u_int is_dvmaend; 110 int64_t is_cr; /* Control register value */ 111 struct mutex is_mtx; 112 struct extent *is_dvmamap; /* DVMA map for this instance */ 113 int is_flags; 114#define IOMMU_FLUSH_CACHE 0x00000001 115 116 struct strbuf_ctl *is_sb[2]; /* Streaming buffers if any */ 117 118 /* copies of our parents state, to allow us to be self contained */ 119 bus_space_tag_t is_bustag; /* our bus tag */ 120 bus_space_handle_t is_iommu; /* IOMMU registers */ 121 uint64_t is_devhandle; 122}; 123 124/* interfaces for PCI/SBus code */ 125void iommu_init(char *, struct iommu_state *, int, u_int32_t); 126void iommu_reset(struct iommu_state *); 127paddr_t iommu_extract(struct iommu_state *, bus_addr_t); 128int64_t iommu_lookup_tte(struct iommu_state *, bus_addr_t); 129int64_t iommu_fetch_tte(struct iommu_state *, paddr_t); 130/* bus_dma_tag_t implementation functions */ 131int iommu_dvmamap_create(bus_dma_tag_t, bus_dma_tag_t, struct strbuf_ctl *, 132 bus_size_t, int, bus_size_t, bus_size_t, int, bus_dmamap_t *); 133void iommu_dvmamap_destroy(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t); 134int iommu_dvmamap_load(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, void *, 135 bus_size_t, struct proc *, int); 136void iommu_dvmamap_unload(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t); 137int iommu_dvmamap_load_raw(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, 138 bus_dma_segment_t *, int, bus_size_t, int); 139void iommu_dvmamap_sync(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, 140 bus_addr_t, bus_size_t, int); 141int iommu_dvmamem_alloc(bus_dma_tag_t, bus_dma_tag_t, bus_size_t, 142 bus_size_t, bus_size_t, bus_dma_segment_t *, int, int *, int); 143void iommu_dvmamem_free(bus_dma_tag_t, bus_dma_tag_t, bus_dma_segment_t *, 144 int); 145 146#define IOMMUREG_READ(is, reg) \ 147 bus_space_read_8((is)->is_bustag, \ 148 (is)->is_iommu, \ 149 IOMMUREG(reg)) 150 151#define IOMMUREG_WRITE(is, reg, v) \ 152 bus_space_write_8((is)->is_bustag, \ 153 (is)->is_iommu, \ 154 IOMMUREG(reg), \ 155 (v)) 156 157#endif /* _SPARC64_DEV_IOMMUVAR_H_ */ 158 159