bonito_iobc.c revision 1.1 1 /* $NetBSD: bonito_iobc.c,v 1.1 2002/01/09 00:43:38 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
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 * Code to manipulate the I/O Buffer Cache on the BONITO.
41 *
42 * The BONITO snoops uncached access to memory (e.g. via KSEG1); we only
43 * need to deal with the IOBC for DMA to cached memory.
44 *
45 * Note: This only applies to the 32-bit BONITO; BONITO64's IOBC
46 * is coherent.
47 */
48
49 #include <sys/param.h>
50
51 #include <machine/locore.h>
52 #include <machine/intr.h>
53
54 #include <mips/bonito/bonitoreg.h>
55 #include <mips/bonito/bonitovar.h>
56
57 #define CACHECMD_INVAL 0
58 #define CACHECMD_WBINV 1
59 #define CACHECMD_RDTAG 2
60 #define CACHECMD_WQFLUSH 3
61
62 #define IOBC_LINESIZE 32
63 #define IOBC_LINESHIFT 5
64 #define IOBC_NLINES 4
65
66 #define TAG_LOCK 0x80000000
67 #define TAG_WBACK 0x40000000
68 #define TAG_PFPEND 0x20000000
69 #define TAG_PEND 0x10000000
70 #define TAG_MOD 0x08000000
71 #define TAG_PFDVAL 0x04000000
72 #define TAG_DVAL 0x02000000
73 #define TAG_AVAL 0x01000000
74 #define TAG_ADDR 0x00ffffff
75
76 #define IOBC_LOCK(s) (s) = splhigh()
77 #define IOBC_UNLOCK(s) splx((s))
78
79 static void
80 bonito_iobc_cmd(uint32_t cmd, uint32_t line)
81 {
82 uint32_t ctrl;
83
84 ctrl = (cmd << BONITO_PCICACHECTRL_CACHECMD_SHIFT) |
85 (line << BONITO_PCICACHECTRL_CACHECMDLINE_SHIFT);
86
87 REGVAL(BONITO_PCICACHECTRL) = ctrl;
88 wbflush();
89
90 REGVAL(BONITO_PCICACHECTRL) = ctrl | BONITO_PCICACHECTRL_CMDEXEC;
91 wbflush();
92
93 while (REGVAL(BONITO_PCICACHECTRL) & BONITO_PCICACHECTRL_CMDEXEC)
94 /* spin */ ;
95
96 REGVAL(BONITO_PCICACHECTRL) = ctrl;
97 wbflush();
98 }
99
100 /*
101 * bonito_iobc_wbinv_range:
102 *
103 * Write-back and invalidate the specified range in
104 * the BONITO IOBC.
105 */
106 void
107 bonito_iobc_wbinv_range(paddr_t pa, psize_t size)
108 {
109 uint32_t line, tag;
110 paddr_t tagaddr;
111 int s;
112
113 IOBC_LOCK(s);
114
115 for (line = 0; line < IOBC_NLINES; line++) {
116 bonito_iobc_cmd(CACHECMD_RDTAG, line);
117 tag = REGVAL(BONITO_PCICACHETAG);
118 if (tag & TAG_AVAL) {
119 tagaddr = (tag & TAG_ADDR) << IOBC_LINESHIFT;
120 if (tagaddr < (pa + size) &&
121 (tagaddr + IOBC_LINESIZE) > pa)
122 bonito_iobc_cmd(CACHECMD_WBINV, line);
123 }
124 }
125 bonito_iobc_cmd(CACHECMD_WQFLUSH, 0);
126
127 IOBC_UNLOCK(s);
128 }
129
130 /*
131 * bonito_iobc_inv_range:
132 *
133 * Invalidate the specified range in the BONITO IOBC.
134 */
135 void
136 bonito_iobc_inv_range(paddr_t pa, psize_t size)
137 {
138 uint32_t line, tag;
139 paddr_t tagaddr;
140 int s;
141
142 IOBC_LOCK(s);
143
144 for (line = 0; line < IOBC_NLINES; line++) {
145 bonito_iobc_cmd(CACHECMD_RDTAG, line);
146 tag = REGVAL(BONITO_PCICACHETAG);
147 if (tag & TAG_AVAL) {
148 tagaddr = (tag & TAG_ADDR) << IOBC_LINESHIFT;
149 if (tagaddr < (pa + size) &&
150 (tagaddr + IOBC_LINESIZE) > pa)
151 bonito_iobc_cmd(CACHECMD_INVAL, line);
152 }
153 }
154 bonito_iobc_cmd(CACHECMD_WQFLUSH, 0);
155
156 IOBC_UNLOCK(s);
157 }
158