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