bonito_iobc.c revision 1.1.4.2 1 1.1.4.2 nathanw /* $NetBSD: bonito_iobc.c,v 1.1.4.2 2002/01/11 23:38:38 nathanw Exp $ */
2 1.1.4.2 nathanw
3 1.1.4.2 nathanw /*-
4 1.1.4.2 nathanw * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1.4.2 nathanw * All rights reserved.
6 1.1.4.2 nathanw *
7 1.1.4.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.1.4.2 nathanw * by Jason R. Thorpe.
9 1.1.4.2 nathanw *
10 1.1.4.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.4.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.4.2 nathanw * are met:
13 1.1.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.4.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.4.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.4.2 nathanw * must display the following acknowledgement:
20 1.1.4.2 nathanw * This product includes software developed by the NetBSD
21 1.1.4.2 nathanw * Foundation, Inc. and its contributors.
22 1.1.4.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.4.2 nathanw * contributors may be used to endorse or promote products derived
24 1.1.4.2 nathanw * from this software without specific prior written permission.
25 1.1.4.2 nathanw *
26 1.1.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.4.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.4.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.4.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.4.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.4.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.4.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.4.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.4.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.4.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.4.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.1.4.2 nathanw */
38 1.1.4.2 nathanw
39 1.1.4.2 nathanw /*
40 1.1.4.2 nathanw * Code to manipulate the I/O Buffer Cache on the BONITO.
41 1.1.4.2 nathanw *
42 1.1.4.2 nathanw * The BONITO snoops uncached access to memory (e.g. via KSEG1); we only
43 1.1.4.2 nathanw * need to deal with the IOBC for DMA to cached memory.
44 1.1.4.2 nathanw *
45 1.1.4.2 nathanw * Note: This only applies to the 32-bit BONITO; BONITO64's IOBC
46 1.1.4.2 nathanw * is coherent.
47 1.1.4.2 nathanw */
48 1.1.4.2 nathanw
49 1.1.4.2 nathanw #include <sys/param.h>
50 1.1.4.2 nathanw
51 1.1.4.2 nathanw #include <machine/locore.h>
52 1.1.4.2 nathanw #include <machine/intr.h>
53 1.1.4.2 nathanw
54 1.1.4.2 nathanw #include <mips/bonito/bonitoreg.h>
55 1.1.4.2 nathanw #include <mips/bonito/bonitovar.h>
56 1.1.4.2 nathanw
57 1.1.4.2 nathanw #define CACHECMD_INVAL 0
58 1.1.4.2 nathanw #define CACHECMD_WBINV 1
59 1.1.4.2 nathanw #define CACHECMD_RDTAG 2
60 1.1.4.2 nathanw #define CACHECMD_WQFLUSH 3
61 1.1.4.2 nathanw
62 1.1.4.2 nathanw #define IOBC_LINESIZE 32
63 1.1.4.2 nathanw #define IOBC_LINESHIFT 5
64 1.1.4.2 nathanw #define IOBC_NLINES 4
65 1.1.4.2 nathanw
66 1.1.4.2 nathanw #define TAG_LOCK 0x80000000
67 1.1.4.2 nathanw #define TAG_WBACK 0x40000000
68 1.1.4.2 nathanw #define TAG_PFPEND 0x20000000
69 1.1.4.2 nathanw #define TAG_PEND 0x10000000
70 1.1.4.2 nathanw #define TAG_MOD 0x08000000
71 1.1.4.2 nathanw #define TAG_PFDVAL 0x04000000
72 1.1.4.2 nathanw #define TAG_DVAL 0x02000000
73 1.1.4.2 nathanw #define TAG_AVAL 0x01000000
74 1.1.4.2 nathanw #define TAG_ADDR 0x00ffffff
75 1.1.4.2 nathanw
76 1.1.4.2 nathanw #define IOBC_LOCK(s) (s) = splhigh()
77 1.1.4.2 nathanw #define IOBC_UNLOCK(s) splx((s))
78 1.1.4.2 nathanw
79 1.1.4.2 nathanw static void
80 1.1.4.2 nathanw bonito_iobc_cmd(uint32_t cmd, uint32_t line)
81 1.1.4.2 nathanw {
82 1.1.4.2 nathanw uint32_t ctrl;
83 1.1.4.2 nathanw
84 1.1.4.2 nathanw ctrl = (cmd << BONITO_PCICACHECTRL_CACHECMD_SHIFT) |
85 1.1.4.2 nathanw (line << BONITO_PCICACHECTRL_CACHECMDLINE_SHIFT);
86 1.1.4.2 nathanw
87 1.1.4.2 nathanw REGVAL(BONITO_PCICACHECTRL) = ctrl;
88 1.1.4.2 nathanw wbflush();
89 1.1.4.2 nathanw
90 1.1.4.2 nathanw REGVAL(BONITO_PCICACHECTRL) = ctrl | BONITO_PCICACHECTRL_CMDEXEC;
91 1.1.4.2 nathanw wbflush();
92 1.1.4.2 nathanw
93 1.1.4.2 nathanw while (REGVAL(BONITO_PCICACHECTRL) & BONITO_PCICACHECTRL_CMDEXEC)
94 1.1.4.2 nathanw /* spin */ ;
95 1.1.4.2 nathanw
96 1.1.4.2 nathanw REGVAL(BONITO_PCICACHECTRL) = ctrl;
97 1.1.4.2 nathanw wbflush();
98 1.1.4.2 nathanw }
99 1.1.4.2 nathanw
100 1.1.4.2 nathanw /*
101 1.1.4.2 nathanw * bonito_iobc_wbinv_range:
102 1.1.4.2 nathanw *
103 1.1.4.2 nathanw * Write-back and invalidate the specified range in
104 1.1.4.2 nathanw * the BONITO IOBC.
105 1.1.4.2 nathanw */
106 1.1.4.2 nathanw void
107 1.1.4.2 nathanw bonito_iobc_wbinv_range(paddr_t pa, psize_t size)
108 1.1.4.2 nathanw {
109 1.1.4.2 nathanw uint32_t line, tag;
110 1.1.4.2 nathanw paddr_t tagaddr;
111 1.1.4.2 nathanw int s;
112 1.1.4.2 nathanw
113 1.1.4.2 nathanw IOBC_LOCK(s);
114 1.1.4.2 nathanw
115 1.1.4.2 nathanw for (line = 0; line < IOBC_NLINES; line++) {
116 1.1.4.2 nathanw bonito_iobc_cmd(CACHECMD_RDTAG, line);
117 1.1.4.2 nathanw tag = REGVAL(BONITO_PCICACHETAG);
118 1.1.4.2 nathanw if (tag & TAG_AVAL) {
119 1.1.4.2 nathanw tagaddr = (tag & TAG_ADDR) << IOBC_LINESHIFT;
120 1.1.4.2 nathanw if (tagaddr < (pa + size) &&
121 1.1.4.2 nathanw (tagaddr + IOBC_LINESIZE) > pa)
122 1.1.4.2 nathanw bonito_iobc_cmd(CACHECMD_WBINV, line);
123 1.1.4.2 nathanw }
124 1.1.4.2 nathanw }
125 1.1.4.2 nathanw bonito_iobc_cmd(CACHECMD_WQFLUSH, 0);
126 1.1.4.2 nathanw
127 1.1.4.2 nathanw IOBC_UNLOCK(s);
128 1.1.4.2 nathanw }
129 1.1.4.2 nathanw
130 1.1.4.2 nathanw /*
131 1.1.4.2 nathanw * bonito_iobc_inv_range:
132 1.1.4.2 nathanw *
133 1.1.4.2 nathanw * Invalidate the specified range in the BONITO IOBC.
134 1.1.4.2 nathanw */
135 1.1.4.2 nathanw void
136 1.1.4.2 nathanw bonito_iobc_inv_range(paddr_t pa, psize_t size)
137 1.1.4.2 nathanw {
138 1.1.4.2 nathanw uint32_t line, tag;
139 1.1.4.2 nathanw paddr_t tagaddr;
140 1.1.4.2 nathanw int s;
141 1.1.4.2 nathanw
142 1.1.4.2 nathanw IOBC_LOCK(s);
143 1.1.4.2 nathanw
144 1.1.4.2 nathanw for (line = 0; line < IOBC_NLINES; line++) {
145 1.1.4.2 nathanw bonito_iobc_cmd(CACHECMD_RDTAG, line);
146 1.1.4.2 nathanw tag = REGVAL(BONITO_PCICACHETAG);
147 1.1.4.2 nathanw if (tag & TAG_AVAL) {
148 1.1.4.2 nathanw tagaddr = (tag & TAG_ADDR) << IOBC_LINESHIFT;
149 1.1.4.2 nathanw if (tagaddr < (pa + size) &&
150 1.1.4.2 nathanw (tagaddr + IOBC_LINESIZE) > pa)
151 1.1.4.2 nathanw bonito_iobc_cmd(CACHECMD_INVAL, line);
152 1.1.4.2 nathanw }
153 1.1.4.2 nathanw }
154 1.1.4.2 nathanw bonito_iobc_cmd(CACHECMD_WQFLUSH, 0);
155 1.1.4.2 nathanw
156 1.1.4.2 nathanw IOBC_UNLOCK(s);
157 1.1.4.2 nathanw }
158