iommuvar.h revision 1.8
1/* $OpenBSD: iommuvar.h,v 1.8 2003/03/06 08:26:08 henric 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/* 41 * per-Streaming Buffer state 42 */ 43struct strbuf_ctl { 44 bus_space_tag_t sb_bustag; /* streaming buffer registers */ 45 bus_space_handle_t sb_sb; /* Handle for our regs */ 46 struct iommu_state *sb_iommu; /* Associated IOMMU */ 47 /* 48 * Since implementing the per-map IOMMU state, these per-STC 49 * flush areas are not used other than as a boolean flag to indicate 50 * the presence of a working and enabled STC. For inconsistency's 51 * sake, the "sb" pointers of iommu_state are sometimes used for the 52 * same purpose. This should be consolidated. 53 */ 54 paddr_t sb_flushpa; /* to flush streaming buffers */ 55 volatile int64_t *sb_flush; 56}; 57 58/* 59 * per-map STC flush area 60 */ 61struct strbuf_flush { 62 char sbf_area[0x80]; /* Holds 64-byte long/aligned buffer */ 63 void *sbf_flush; /* Kernel virtual address of buffer */ 64 paddr_t sbf_flushpa; /* Physical address of buffer area */ 65}; 66 67/* 68 * per-map DVMA page table 69 */ 70struct iommu_page_entry { 71 SPLAY_ENTRY(iommu_page_entry) ipe_node; 72 paddr_t ipe_pa; 73 vaddr_t ipe_va; 74}; 75struct iommu_page_map { 76 SPLAY_HEAD(iommu_page_tree, iommu_page_entry) ipm_tree; 77 int ipm_maxpage; /* Size of allocated page map */ 78 int ipm_pagecnt; /* Number of entries in use */ 79 struct iommu_page_entry ipm_map[1]; 80}; 81 82/* 83 * per-map IOMMU state 84 * 85 * This is what bus_dvmamap_t'c _dm_cookie should be pointing to. 86 */ 87struct iommu_map_state { 88 struct strbuf_flush ims_flush; /* flush should be first (alignment) */ 89 struct strbuf_ctl *ims_sb; /* Link to parent */ 90 int ims_flags; 91 struct iommu_page_map ims_map; /* map must be last (array at end) */ 92}; 93#define IOMMU_MAP_STREAM 1 94 95/* 96 * per-IOMMU state 97 */ 98struct iommu_state { 99 paddr_t is_ptsb; /* TSB physical address */ 100 int64_t *is_tsb; /* TSB virtual address */ 101 int is_tsbsize; /* 0 = 8K, ... */ 102 u_int is_dvmabase; 103 u_int is_dvmaend; 104 int64_t is_cr; /* Control register value */ 105 struct extent *is_dvmamap; /* DVMA map for this instance */ 106 107 struct strbuf_ctl *is_sb[2]; /* Streaming buffers if any */ 108 109 /* copies of our parents state, to allow us to be self contained */ 110 bus_space_tag_t is_bustag; /* our bus tag */ 111 bus_space_handle_t is_iommu; /* IOMMU registers */ 112}; 113 114/* interfaces for PCI/SBUS code */ 115void iommu_init(char *, struct iommu_state *, int, u_int32_t); 116void iommu_reset(struct iommu_state *); 117paddr_t iommu_extract(struct iommu_state *, vaddr_t); 118int64_t iommu_lookup_tte(struct iommu_state *, vaddr_t); 119int64_t iommu_fetch_tte(struct iommu_state *, paddr_t); 120int iommu_dvmamap_create(bus_dma_tag_t, struct iommu_state *, 121 struct strbuf_ctl *, bus_size_t, int, bus_size_t, bus_size_t, 122 int, bus_dmamap_t *); 123void iommu_dvmamap_destroy(bus_dma_tag_t, bus_dmamap_t); 124int iommu_dvmamap_load(bus_dma_tag_t, struct iommu_state *, 125 bus_dmamap_t, void *, bus_size_t, struct proc *, int); 126void iommu_dvmamap_unload(bus_dma_tag_t, struct iommu_state *, 127 bus_dmamap_t); 128int iommu_dvmamap_load_raw(bus_dma_tag_t, struct iommu_state *, 129 bus_dmamap_t, bus_dma_segment_t *, int, int, bus_size_t); 130void iommu_dvmamap_sync(bus_dma_tag_t, struct iommu_state *, bus_dmamap_t, 131 bus_addr_t, bus_size_t, int); 132int iommu_dvmamem_alloc(bus_dma_tag_t, struct iommu_state *, 133 bus_size_t, bus_size_t, bus_size_t, bus_dma_segment_t *, 134 int, int *, int); 135void iommu_dvmamem_free(bus_dma_tag_t, struct iommu_state *, 136 bus_dma_segment_t *, int); 137int iommu_dvmamem_map(bus_dma_tag_t, struct iommu_state *, 138 bus_dma_segment_t *, int, size_t, caddr_t *, int); 139void iommu_dvmamem_unmap(bus_dma_tag_t, struct iommu_state *, 140 caddr_t, size_t); 141 142#define IOMMUREG_READ(is, reg) \ 143 bus_space_read_8((is)->is_bustag, \ 144 (is)->is_iommu, \ 145 IOMMUREG(reg)) 146 147#define IOMMUREG_WRITE(is, reg, v) \ 148 bus_space_write_8((is)->is_bustag, \ 149 (is)->is_iommu, \ 150 IOMMUREG(reg), \ 151 (v)) 152 153#endif /* _SPARC64_DEV_IOMMUVAR_H_ */ 154 155