iommu.c revision 1.2 1 /* $NetBSD: iommu.c,v 1.2 1997/02/13 07:38:21 jeremy Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jeremy Cooper.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Set-up functions for the Sun3x DVMA I/O Mapper.
41 */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 #include <sys/conf.h>
47 #include <sys/buf.h>
48 #include <sys/malloc.h>
49 #include <sys/proc.h>
50
51 #include <machine/autoconf.h>
52 #include <machine/obio.h>
53 #include "iommu.h"
54
55 #define OBIO_IOMMU_SIZE (IOMMU_NENT * sizeof(iommu_pde_t))
56
57 static int iommu_match __P((struct device *, struct cfdata *, void *));
58 static void iommu_attach __P((struct device *, struct device *, void *));
59
60 struct cfattach iommu_ca = {
61 sizeof(struct device), iommu_match, iommu_attach
62 };
63
64 struct cfdriver iommu_cd = {
65 NULL, "iommu", DV_DULL
66 };
67
68 static iommu_pde_t *iommu_va;
69
70 static int
71 iommu_match(parent, cf, args)
72 struct device *parent;
73 struct cfdata *cf;
74 void *args;
75 {
76 struct confargs *ca = args;
77
78 /* This driver only supports one unit. */
79 if (cf->cf_unit != 0)
80 return (0);
81
82 /* Validate the given address. */
83 if (ca->ca_paddr != OBIO_IOMMU)
84 return (0);
85
86 return (1);
87 }
88
89 static void
90 iommu_attach(parent, self, args)
91 struct device *parent;
92 struct device *self;
93 void *args;
94 {
95 struct confargs *ca = args;
96
97 iommu_va = (iommu_pde_t *)
98 obio_alloc(ca->ca_paddr, OBIO_IOMMU_SIZE);
99
100 printf("\n");
101 }
102
103 void
104 iommu_enter(sa, pa)
105 u_int32_t sa; /* slave address */
106 u_int32_t pa; /* phys. address */
107 {
108 int pn;
109
110 #ifdef DIAGNOSTIC
111 if (sa > (1<<24))
112 panic("iommu_enter: bad sa");
113 #endif
114
115 /* Convert the slave address into a page index. */
116 pn = IOMMU_BTOP(sa);
117
118 /* Mask the physical address to insure it is page aligned */
119 pa &= IOMMU_PDE_PA;
120 pa |= IOMMU_PDE_DT_VALID;
121
122 iommu_va[pn].addr.raw = pa;
123 }
124
125 void
126 iommu_remove(sa, len)
127 u_int32_t sa; /* slave address */
128 u_int32_t len;
129 {
130 int pn;
131
132 #ifdef DIAGNOSTIC
133 if (sa > (1<<24))
134 panic("iommu_enter: bad sa");
135 #endif
136
137 pn = IOMMU_BTOP(sa);
138 while (len > 0) {
139 iommu_va[pn++].addr.raw = IOMMU_PDE_DT_INVALID;
140 len -= NBPG;
141 }
142 }
143