1 /* $NetBSD: bonito_iobc.c,v 1.3 2005/12/11 12:18:07 christos Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Code to manipulate the I/O Buffer Cache on the BONITO.
35 * The BONITO snoops uncached access to memory (e.g. via KSEG1); we only
36 * need to deal with the IOBC for DMA to cached memory.
38 * Note: This only applies to the 32-bit BONITO; BONITO64's IOBC
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: bonito_iobc.c,v 1.3 2005/12/11 12:18:07 christos Exp $");
45 #include <sys/param.h>
47 #include <machine/locore.h>
48 #include <machine/intr.h>
50 #include <mips/bonito/bonitoreg.h>
51 #include <mips/bonito/bonitovar.h>
53 #define CACHECMD_INVAL 0
54 #define CACHECMD_WBINV 1
55 #define CACHECMD_RDTAG 2
56 #define CACHECMD_WQFLUSH 3
58 #define IOBC_LINESIZE 32
59 #define IOBC_LINESHIFT 5
62 #define TAG_LOCK 0x80000000
63 #define TAG_WBACK 0x40000000
64 #define TAG_PFPEND 0x20000000
65 #define TAG_PEND 0x10000000
66 #define TAG_MOD 0x08000000
67 #define TAG_PFDVAL 0x04000000
68 #define TAG_DVAL 0x02000000
69 #define TAG_AVAL 0x01000000
70 #define TAG_ADDR 0x00ffffff
72 #define IOBC_LOCK(s) (s) = splhigh()
73 #define IOBC_UNLOCK(s) splx((s))
76 bonito_iobc_cmd(uint32_t cmd
, uint32_t line
)
80 ctrl
= (cmd
<< BONITO_PCICACHECTRL_CACHECMD_SHIFT
) |
81 (line
<< BONITO_PCICACHECTRL_CACHECMDLINE_SHIFT
);
83 REGVAL(BONITO_PCICACHECTRL
) = ctrl
;
86 REGVAL(BONITO_PCICACHECTRL
) = ctrl
| BONITO_PCICACHECTRL_CMDEXEC
;
89 while (REGVAL(BONITO_PCICACHECTRL
) & BONITO_PCICACHECTRL_CMDEXEC
)
92 REGVAL(BONITO_PCICACHECTRL
) = ctrl
;
97 * bonito_iobc_wbinv_range:
99 * Write-back and invalidate the specified range in
103 bonito_iobc_wbinv_range(paddr_t pa
, psize_t size
)
111 for (line
= 0; line
< IOBC_NLINES
; line
++) {
112 bonito_iobc_cmd(CACHECMD_RDTAG
, line
);
113 tag
= REGVAL(BONITO_PCICACHETAG
);
114 if (tag
& TAG_AVAL
) {
115 tagaddr
= (tag
& TAG_ADDR
) << IOBC_LINESHIFT
;
116 if (tagaddr
< (pa
+ size
) &&
117 (tagaddr
+ IOBC_LINESIZE
) > pa
)
118 bonito_iobc_cmd(CACHECMD_WBINV
, line
);
121 bonito_iobc_cmd(CACHECMD_WQFLUSH
, 0);
127 * bonito_iobc_inv_range:
129 * Invalidate the specified range in the BONITO IOBC.
132 bonito_iobc_inv_range(paddr_t pa
, psize_t size
)
140 for (line
= 0; line
< IOBC_NLINES
; line
++) {
141 bonito_iobc_cmd(CACHECMD_RDTAG
, line
);
142 tag
= REGVAL(BONITO_PCICACHETAG
);
143 if (tag
& TAG_AVAL
) {
144 tagaddr
= (tag
& TAG_ADDR
) << IOBC_LINESHIFT
;
145 if (tagaddr
< (pa
+ size
) &&
146 (tagaddr
+ IOBC_LINESIZE
) > pa
)
147 bonito_iobc_cmd(CACHECMD_INVAL
, line
);
150 bonito_iobc_cmd(CACHECMD_WQFLUSH
, 0);