iommu.h revision 1.9 1 1.9 tsutsui /* $NetBSD: iommu.h,v 1.9 2013/09/06 17:43:19 tsutsui Exp $ */
2 1.1 gwr
3 1.1 gwr /*-
4 1.1 gwr * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 gwr * All rights reserved.
6 1.1 gwr *
7 1.1 gwr * This code is derived from software contributed to The NetBSD Foundation
8 1.1 gwr * by Jeremy Cooper.
9 1.1 gwr *
10 1.1 gwr * Redistribution and use in source and binary forms, with or without
11 1.1 gwr * modification, are permitted provided that the following conditions
12 1.1 gwr * are met:
13 1.1 gwr * 1. Redistributions of source code must retain the above copyright
14 1.1 gwr * notice, this list of conditions and the following disclaimer.
15 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 gwr * notice, this list of conditions and the following disclaimer in the
17 1.1 gwr * documentation and/or other materials provided with the distribution.
18 1.1 gwr *
19 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 gwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 gwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 gwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 gwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 gwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 gwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 gwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 gwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 gwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 gwr * POSSIBILITY OF SUCH DAMAGE.
30 1.1 gwr */
31 1.1 gwr
32 1.1 gwr /*
33 1.1 gwr * Structure and definition of descriptors used in the I/O Mapper.
34 1.1 gwr */
35 1.1 gwr #ifndef _SUN3X_IOMMU_H
36 1.1 gwr #define _SUN3X_IOMMU_H
37 1.1 gwr
38 1.1 gwr /* The I/O Mapper is a special type of MMU in the sun3x architecture
39 1.4 jeremy * (and supposedly in the sun4m as well) that translates an address used by a
40 1.4 jeremy * device during a DMA transfer into an address on the internal system bus.
41 1.4 jeremy * In other words, it is an MMU that stands between devices wishing to do DMA
42 1.4 jeremy * transfers and main memory. In this description, the address issued by a
43 1.4 jeremy * DMA device is called a ``DVMA address'', while the address as it is
44 1.4 jeremy * translated and output from the I/O mapper is called a ``system bus address''
45 1.4 jeremy * (sometimes known as a ``physical address'').
46 1.1 gwr *
47 1.4 jeremy * The DVMA address space in the sun3x architecture is 24 bits wide, in
48 1.4 jeremy * contrast with the system bus address space, which is 32. The mapping of a
49 1.4 jeremy * DVMA address to a system bus address is accomplished by dividing the DVMA
50 1.4 jeremy * address space into 2048 8K pages. Each DVMA page is then mapped to a
51 1.4 jeremy * system bus address using a mapping described by a page descriptor entry
52 1.4 jeremy * within the I/O Mapper. This 2048 entry, page descriptor table is located
53 1.4 jeremy * at physical address 0x60000000 in the sun3x architecture and can be
54 1.4 jeremy * manipulated by the CPU with normal read and write cycles.
55 1.9 tsutsui *
56 1.4 jeremy * In addition to describing an address mapping, a page descriptor entry also
57 1.4 jeremy * indicates whether the DVMA page is read-only, should be inhibited from
58 1.4 jeremy * caching by system caches, and whether or not DMA write transfers to it will
59 1.4 jeremy * be completed in 16 byte aligned blocks. (This last item is used for cache
60 1.4 jeremy * optimization in sun3x systems with special DMA caches.)
61 1.9 tsutsui *
62 1.4 jeremy * Since not every DMA device is capable of addressing all 24 bits of the
63 1.4 jeremy * DVMA address space, each is wired so that the end of its address space is
64 1.4 jeremy * always flush against the end of the DVMA address space. That is, a device
65 1.4 jeremy * with a 16 bit address space (and hence an address space size of 64k) is
66 1.4 jeremy * wired such that it accesses the top 64k of DVMA space.
67 1.1 gwr */
68 1.1 gwr
69 1.4 jeremy /** I/O MAPPER Page Descriptor Entry
70 1.1 gwr * 31 16
71 1.1 gwr * +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
72 1.1 gwr * | PAGE PHYSICAL ADDRESS BITS (31..13) |
73 1.1 gwr * +---.---.---+---.---.---.---.---.---+---+---+---+---+---+---.---+
74 1.1 gwr * | | UNUSED | CI| BX| M | U | WP| DT |
75 1.1 gwr * +---.---.---+---.---.---.---.---.---+---+---+---+---+---+---.---+
76 1.1 gwr * 15 0
77 1.1 gwr *
78 1.1 gwr * <CI> CACHE INHIBIT - When set, prevents instructions and data from the
79 1.1 gwr * page from being cached in any system cache.
80 1.4 jeremy * <BX> FULL BLOCK XFER - When set, acts as an indicator to the caching system
81 1.4 jeremy * that all DMA transfers to this DVMA page will fill
82 1.4 jeremy * complete I/O cache blocks, eliminating the need for
83 1.4 jeremy * the cache block to be filled from main memory first
84 1.4 jeremy * before the DMA write can proceed to it.
85 1.1 gwr * <M> MODIFIED - Set when the cpu has modified (written to) the
86 1.1 gwr * physical page.
87 1.1 gwr * <U> USED - Set when the cpu has accessed the physical page.
88 1.2 jeremy * <WP> WRITE PROTECT - When set, prevents all DMA devices from writing to
89 1.2 jeremy * the page.
90 1.1 gwr * <DT> DESCRIPTOR TYPE - One of the following values:
91 1.1 gwr * 00 = Invalid page
92 1.1 gwr * 01 = Valid page
93 1.1 gwr * 1x = Invalid code for a page descriptor.
94 1.1 gwr */
95 1.1 gwr struct iommu_pde_struct {
96 1.1 gwr union {
97 1.1 gwr struct {
98 1.1 gwr u_int pa:19; /* Physical Address */
99 1.1 gwr u_int unused:6; /* Unused bits */
100 1.1 gwr u_int ci:1; /* Cache Inhibit */
101 1.1 gwr u_int bx:1; /* Full Block Xfer */
102 1.1 gwr u_int m:1; /* Modified bit */
103 1.1 gwr u_int u:1; /* Used bit */
104 1.1 gwr u_int wp:1; /* Write Protect bit */
105 1.1 gwr u_int dt:2; /* Descriptor type */
106 1.1 gwr /* Masks for the above fields. */
107 1.1 gwr #define IOMMU_PDE_PA 0xFFFFE000
108 1.1 gwr #define IOMMU_PDE_UNUSED 0x00001F80
109 1.1 gwr #define IOMMU_PDE_CI 0x00000040
110 1.1 gwr #define IOMMU_PDE_BX 0x00000020
111 1.1 gwr #define IOMMU_PDE_M 0x00000010
112 1.1 gwr #define IOMMU_PDE_USED 0x00000008
113 1.1 gwr #define IOMMU_PDE_WP 0x00000004
114 1.1 gwr #define IOMMU_PDE_DT 0x00000003
115 1.1 gwr /* The descriptor types */
116 1.1 gwr #define IOMMU_PDE_DT_INVALID 0x00000000 /* Invalid page */
117 1.1 gwr #define IOMMU_PDE_DT_VALID 0x00000001 /* Valid page */
118 1.1 gwr } stc;
119 1.6 chs uint32_t raw; /* For unstructured access to the above */
120 1.1 gwr } addr;
121 1.1 gwr };
122 1.1 gwr typedef struct iommu_pde_struct iommu_pde_t;
123 1.1 gwr
124 1.1 gwr /* Constants */
125 1.3 jeremy #define IOMMU_PAGE_SIZE (8 * 1024)
126 1.1 gwr #define IOMMU_PAGE_SHIFT 13
127 1.1 gwr
128 1.1 gwr /* Useful macros */
129 1.1 gwr #define IOMMU_PA_PDE(pde) ((pde).addr.raw & IOMMU_PDE_PA)
130 1.1 gwr #define IOMMU_VALID_DT(pde) ((pde).addr.raw & IOMMU_PDE_DT) /* X1 */
131 1.1 gwr #define IOMMU_BTOP(pa) (((u_int) pa) >> IOMMU_PAGE_SHIFT)
132 1.1 gwr
133 1.2 jeremy /* X1: This macro will incorrectly report the validity for entries which
134 1.2 jeremy * contain codes that are invalid. (Do not confuse this with the code for
135 1.2 jeremy * 'invalid entry', which means that the descriptor is properly formed, but
136 1.2 jeremy * just not used.)
137 1.1 gwr */
138 1.1 gwr
139 1.1 gwr /* Constants for the I/O mapper as used in the sun3x */
140 1.5 gwr #define IOMMU_NENT 2048 /* Number of PTEs in the map */
141 1.5 gwr /* Similarly, the virtual address mask. */
142 1.5 gwr #define IOMMU_VA_MASK 0xFFffff /* 16MB */
143 1.1 gwr
144 1.2 jeremy #ifdef _KERNEL
145 1.1 gwr /* Interfaces for manipulating the I/O mapper */
146 1.6 chs void iommu_enter(uint32_t, uint32_t);
147 1.6 chs void iommu_remove(uint32_t, uint32_t);
148 1.2 jeremy #endif /* _KERNEL */
149 1.1 gwr
150 1.1 gwr #endif /* _SUN3X_IOMMU_H */
151