Home | History | Annotate | Line # | Download | only in bonito
bonito_iobc.c revision 1.3
      1  1.3  christos /*	$NetBSD: bonito_iobc.c,v 1.3 2005/12/11 12:18:07 christos 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.2     lukem 
     49  1.2     lukem #include <sys/cdefs.h>
     50  1.3  christos __KERNEL_RCSID(0, "$NetBSD: bonito_iobc.c,v 1.3 2005/12/11 12:18:07 christos Exp $");
     51  1.1   thorpej 
     52  1.1   thorpej #include <sys/param.h>
     53  1.1   thorpej 
     54  1.1   thorpej #include <machine/locore.h>
     55  1.1   thorpej #include <machine/intr.h>
     56  1.1   thorpej 
     57  1.1   thorpej #include <mips/bonito/bonitoreg.h>
     58  1.1   thorpej #include <mips/bonito/bonitovar.h>
     59  1.1   thorpej 
     60  1.1   thorpej #define	CACHECMD_INVAL		0
     61  1.1   thorpej #define	CACHECMD_WBINV		1
     62  1.1   thorpej #define	CACHECMD_RDTAG		2
     63  1.1   thorpej #define	CACHECMD_WQFLUSH	3
     64  1.1   thorpej 
     65  1.1   thorpej #define	IOBC_LINESIZE		32
     66  1.1   thorpej #define	IOBC_LINESHIFT		5
     67  1.1   thorpej #define	IOBC_NLINES		4
     68  1.1   thorpej 
     69  1.1   thorpej #define	TAG_LOCK		0x80000000
     70  1.1   thorpej #define	TAG_WBACK		0x40000000
     71  1.1   thorpej #define	TAG_PFPEND		0x20000000
     72  1.1   thorpej #define	TAG_PEND		0x10000000
     73  1.1   thorpej #define	TAG_MOD			0x08000000
     74  1.1   thorpej #define	TAG_PFDVAL		0x04000000
     75  1.1   thorpej #define	TAG_DVAL		0x02000000
     76  1.1   thorpej #define	TAG_AVAL		0x01000000
     77  1.1   thorpej #define	TAG_ADDR		0x00ffffff
     78  1.1   thorpej 
     79  1.1   thorpej #define	IOBC_LOCK(s)		(s) = splhigh()
     80  1.1   thorpej #define	IOBC_UNLOCK(s)		splx((s))
     81  1.1   thorpej 
     82  1.1   thorpej static void
     83  1.1   thorpej bonito_iobc_cmd(uint32_t cmd, uint32_t line)
     84  1.1   thorpej {
     85  1.1   thorpej 	uint32_t ctrl;
     86  1.1   thorpej 
     87  1.1   thorpej 	ctrl = (cmd << BONITO_PCICACHECTRL_CACHECMD_SHIFT) |
     88  1.1   thorpej 	       (line << BONITO_PCICACHECTRL_CACHECMDLINE_SHIFT);
     89  1.1   thorpej 
     90  1.1   thorpej 	REGVAL(BONITO_PCICACHECTRL) = ctrl;
     91  1.1   thorpej 	wbflush();
     92  1.1   thorpej 
     93  1.1   thorpej 	REGVAL(BONITO_PCICACHECTRL) = ctrl | BONITO_PCICACHECTRL_CMDEXEC;
     94  1.1   thorpej 	wbflush();
     95  1.1   thorpej 
     96  1.1   thorpej 	while (REGVAL(BONITO_PCICACHECTRL) & BONITO_PCICACHECTRL_CMDEXEC)
     97  1.1   thorpej 		/* spin */ ;
     98  1.1   thorpej 
     99  1.1   thorpej 	REGVAL(BONITO_PCICACHECTRL) = ctrl;
    100  1.1   thorpej 	wbflush();
    101  1.1   thorpej }
    102  1.1   thorpej 
    103  1.1   thorpej /*
    104  1.1   thorpej  * bonito_iobc_wbinv_range:
    105  1.1   thorpej  *
    106  1.1   thorpej  *	Write-back and invalidate the specified range in
    107  1.1   thorpej  *	the BONITO IOBC.
    108  1.1   thorpej  */
    109  1.1   thorpej void
    110  1.1   thorpej bonito_iobc_wbinv_range(paddr_t pa, psize_t size)
    111  1.1   thorpej {
    112  1.1   thorpej 	uint32_t line, tag;
    113  1.1   thorpej 	paddr_t tagaddr;
    114  1.1   thorpej 	int s;
    115  1.1   thorpej 
    116  1.1   thorpej 	IOBC_LOCK(s);
    117  1.1   thorpej 
    118  1.1   thorpej 	for (line = 0; line < IOBC_NLINES; line++) {
    119  1.1   thorpej 		bonito_iobc_cmd(CACHECMD_RDTAG, line);
    120  1.1   thorpej 		tag = REGVAL(BONITO_PCICACHETAG);
    121  1.1   thorpej 		if (tag & TAG_AVAL) {
    122  1.1   thorpej 			tagaddr = (tag & TAG_ADDR) << IOBC_LINESHIFT;
    123  1.1   thorpej 			if (tagaddr < (pa + size) &&
    124  1.1   thorpej 			    (tagaddr + IOBC_LINESIZE) > pa)
    125  1.1   thorpej 				bonito_iobc_cmd(CACHECMD_WBINV, line);
    126  1.1   thorpej 		}
    127  1.1   thorpej 	}
    128  1.1   thorpej 	bonito_iobc_cmd(CACHECMD_WQFLUSH, 0);
    129  1.1   thorpej 
    130  1.1   thorpej 	IOBC_UNLOCK(s);
    131  1.1   thorpej }
    132  1.1   thorpej 
    133  1.1   thorpej /*
    134  1.1   thorpej  * bonito_iobc_inv_range:
    135  1.1   thorpej  *
    136  1.1   thorpej  *	Invalidate the specified range in the BONITO IOBC.
    137  1.1   thorpej  */
    138  1.1   thorpej void
    139  1.1   thorpej bonito_iobc_inv_range(paddr_t pa, psize_t size)
    140  1.1   thorpej {
    141  1.1   thorpej 	uint32_t line, tag;
    142  1.1   thorpej 	paddr_t tagaddr;
    143  1.1   thorpej 	int s;
    144  1.1   thorpej 
    145  1.1   thorpej 	IOBC_LOCK(s);
    146  1.1   thorpej 
    147  1.1   thorpej 	for (line = 0; line < IOBC_NLINES; line++) {
    148  1.1   thorpej 		bonito_iobc_cmd(CACHECMD_RDTAG, line);
    149  1.1   thorpej 		tag = REGVAL(BONITO_PCICACHETAG);
    150  1.1   thorpej 		if (tag & TAG_AVAL) {
    151  1.1   thorpej 			tagaddr = (tag & TAG_ADDR) << IOBC_LINESHIFT;
    152  1.1   thorpej 			if (tagaddr < (pa + size) &&
    153  1.1   thorpej 			    (tagaddr + IOBC_LINESIZE) > pa)
    154  1.1   thorpej 				bonito_iobc_cmd(CACHECMD_INVAL, line);
    155  1.1   thorpej 		}
    156  1.1   thorpej 	}
    157  1.1   thorpej 	bonito_iobc_cmd(CACHECMD_WQFLUSH, 0);
    158  1.1   thorpej 
    159  1.1   thorpej 	IOBC_UNLOCK(s);
    160  1.1   thorpej }
    161