/* $NetBSD: bonito_iobc.c,v 1.5 2011/07/10 23:13:22 matt Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Code to manipulate the I/O Buffer Cache on the BONITO.
*
* The BONITO snoops uncached access to memory (e.g. via KSEG1); we only
* need to deal with the IOBC for DMA to cached memory.
*
* Note: This only applies to the 32-bit BONITO; BONITO64's IOBC
* is coherent.
*/
while (REGVAL(BONITO_PCICACHECTRL) & BONITO_PCICACHECTRL_CMDEXEC)
/* spin */ ;
REGVAL(BONITO_PCICACHECTRL) = ctrl;
wbflush();
}
/*
* bonito_iobc_wbinv_range:
*
* Write-back and invalidate the specified range in
* the BONITO IOBC.
*/
void
bonito_iobc_wbinv_range(paddr_t pa, psize_t size)
{
uint32_t line, tag;
paddr_t tagaddr;
int s;
IOBC_LOCK(s);
for (line = 0; line < IOBC_NLINES; line++) {
bonito_iobc_cmd(CACHECMD_RDTAG, line);
tag = REGVAL(BONITO_PCICACHETAG);
if (tag & TAG_AVAL) {
tagaddr = (tag & TAG_ADDR) << IOBC_LINESHIFT;
if (tagaddr < (pa + size) &&
(tagaddr + IOBC_LINESIZE) > pa)
bonito_iobc_cmd(CACHECMD_WBINV, line);
}
}
bonito_iobc_cmd(CACHECMD_WQFLUSH, 0);
IOBC_UNLOCK(s);
}
/*
* bonito_iobc_inv_range:
*
* Invalidate the specified range in the BONITO IOBC.
*/
void
bonito_iobc_inv_range(paddr_t pa, psize_t size)
{
uint32_t line, tag;
paddr_t tagaddr;
int s;
IOBC_LOCK(s);
for (line = 0; line < IOBC_NLINES; line++) {
bonito_iobc_cmd(CACHECMD_RDTAG, line);
tag = REGVAL(BONITO_PCICACHETAG);
if (tag & TAG_AVAL) {
tagaddr = (tag & TAG_ADDR) << IOBC_LINESHIFT;
if (tagaddr < (pa + size) &&
(tagaddr + IOBC_LINESIZE) > pa)
bonito_iobc_cmd(CACHECMD_INVAL, line);
}
}
bonito_iobc_cmd(CACHECMD_WQFLUSH, 0);