Received: from mail.onstor.com (66.201.51.107) by exch1.onstor.net
 (10.0.0.225) with Microsoft SMTP Server id 8.1.311.2; Sat, 24 Jan 2009
 11:12:09 -0800
Received: from dalesmta2-1.messageone.com ([129.41.169.249]) by
 mail.onstor.com with Microsoft SMTPSVC(6.0.3790.3959);	 Sat, 24 Jan 2009
 11:12:07 -0800
Received: from ftp.linux-mips.org (ftp.linux-mips.org [213.58.128.207])	by
 dalesmta2-1.messageone.com (8.13.8/8.13.8) with ESMTP id n0OJC7cD023130	for
 <andy.sharp@onstor.com>; Sat, 24 Jan 2009 13:12:07 -0600
Received: from localhost.localdomain ([127.0.0.1]:48616 "EHLO
	ftp.linux-mips.org") by ftp.linux-mips.org with ESMTP	id S21366175AbZAXTLV
 (ORCPT <rfc822;andy.sharp@onstor.com>);	Sat, 24 Jan 2009 19:11:21 +0000
Received: with ECARTIS (v1.0.0; list linux-mips); Sat, 24 Jan 2009 19:11:05
 +0000 (GMT)
Received: from h5.dl5rb.org.uk ([81.2.74.5]:34199 "EHLO h5.dl5rb.org.uk")	by
 ftp.linux-mips.org with ESMTP id S21366177AbZAXTK7 (ORCPT
	<rfc822;linux-mips@linux-mips.org>); Sat, 24 Jan 2009 19:10:59 +0000
Received: from h5.dl5rb.org.uk (localhost.localdomain [127.0.0.1])	by
 h5.dl5rb.org.uk (8.14.3/8.14.3) with ESMTP id n0OJAvhY014533;	Sat, 24 Jan
 2009 19:10:58 GMT
Received: (from ralf@localhost)	by h5.dl5rb.org.uk (8.14.3/8.14.3/Submit) id
 n0OJAtxV014518;	Sat, 24 Jan 2009 19:10:55 GMT
From: Ralf Baechle <ralf@linux-mips.org>
To: Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
CC: linux-mips <linux-mips@linux-mips.org>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Sat, 24 Jan 2009 11:10:55 -0800
Subject: Re: [PATCH][MIPS] fix oops in r4k_dma_cache_inv
Thread-Topic: [PATCH][MIPS] fix oops in r4k_dma_cache_inv
Thread-Index: Acl+V6dvCj/RL2liRR2KSivlQeNQAg==
Message-ID: <20090124191055.GA29966@linux-mips.org>
References: <20090124221542.bcc6c19f.yoichi_yuasa@tripeaks.co.jp>
In-Reply-To: <20090124221542.bcc6c19f.yoichi_yuasa@tripeaks.co.jp>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 0b
X-MS-Exchange-Organization-AuthSource: exch1.onstor.net
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-originalarrivaltime: 24 Jan 2009 19:12:08.0066 (UTC)
 FILETIME=[A6B14620:01C97E57]
user-agent: Mutt/1.5.18 (2008-05-17)
errors-to: linux-mips-bounce@linux-mips.org
x-ems-proccessed: 2K3Xl1OQTInXD6xxuA8z3Q==
x-ems-stamp: 5y06mymmfPR1GotydWhomg==
x-messageone-virus-version: vendor=fsecure
 engine=4.65.7400:2.4.4,1.2.40,4.0.164
 definitions=2009-01-24_05:2009-01-21,2009-01-24,2009-01-23 signatures=0
x-messageone-virus-scanned: Clean
x-messageone-envelope-sender: linux-mips-bounce@linux-mips.org
x-messageone-spam-details: rule=m773emszm_notspam policy=m773emszm score=0
 spamscore=0 ipscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam
 adjust=0 reason=mlx engine=3.1.0-0810130000 definitions=main-0901240120
x-messageone-spam-score: 0
x-messageone-spam-bar:
x-list: linux-mips
x-archive-position: 21809
x-ecartis-version: Ecartis v1.0.0
x-original-sender: ralf@linux-mips.org
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

On Sat, Jan 24, 2009 at 10:15:42PM +0900, Yoichi Yuasa wrote:

Patch looks ok - but I think we also have to assume that the starting
address of the range might be miss-aligned, so how about this patch?

  Ralf

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

diff --git a/arch/mips/mm/c-r4k.c b/arch/mips/mm/c-r4k.c
index 56290a7..c43f4b2 100644
--- a/arch/mips/mm/c-r4k.c
+++ b/arch/mips/mm/c-r4k.c
@@ -619,8 +619,20 @@ static void r4k_dma_cache_inv(unsigned long addr, unsi=
gned long size)
 		if (size >=3D scache_size)
 			r4k_blast_scache();
 		else {
-			cache_op(Hit_Writeback_Inv_SD, addr);
-			cache_op(Hit_Writeback_Inv_SD, addr + size - 1);
+			unsigned long lsize =3D cpu_scache_line_size();
+			unsigned long almask =3D ~(lsize - 1);
+
+			/*
+			 * There is no clearly documented alignment requirement
+			 * for the cache instruction on MIPS processors and
+			 * some processors, among them the RM5200 and RM7000
+			 * QED processors will throw an address error for cache
+			 * hit ops with insufficient alignment.  Solved by
+			 * aligning the address to cache line size.
+			 */
+			cache_op(Hit_Writeback_Inv_SD, addr & almask);
+			cache_op(Hit_Writeback_Inv_SD,
+				 (addr + size - 1) & almask);
 			blast_inv_scache_range(addr, addr + size);
 		}
 		return;
@@ -629,9 +641,12 @@ static void r4k_dma_cache_inv(unsigned long addr, unsi=
gned long size)
 	if (cpu_has_safe_index_cacheops && size >=3D dcache_size) {
 		r4k_blast_dcache();
 	} else {
+		unsigned long lsize =3D cpu_dcache_line_size();
+		unsigned long almask =3D ~(lsize - 1);
+
 		R4600_HIT_CACHEOP_WAR_IMPL;
-		cache_op(Hit_Writeback_Inv_D, addr);
-		cache_op(Hit_Writeback_Inv_D, addr + size - 1);
+		cache_op(Hit_Writeback_Inv_D, addr & almask);
+		cache_op(Hit_Writeback_Inv_D, (addr + size - 1)  & almask);
 		blast_inv_dcache_range(addr, addr + size);
 	}
=20

