From owner-svn-src-stable@freebsd.org  Tue Jun 13 18:59:35 2017
Return-Path: <owner-svn-src-stable@freebsd.org>
Delivered-To: svn-src-stable@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id E4325BFC46B;
 Tue, 13 Jun 2017 18:59:35 +0000 (UTC)
 (envelope-from emaste@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id B21393A53;
 Tue, 13 Jun 2017 18:59:35 +0000 (UTC)
 (envelope-from emaste@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v5DIxY26035254;
 Tue, 13 Jun 2017 18:59:34 GMT (envelope-from emaste@FreeBSD.org)
Received: (from emaste@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id v5DIxY1V035253;
 Tue, 13 Jun 2017 18:59:34 GMT (envelope-from emaste@FreeBSD.org)
Message-Id: <201706131859.v5DIxY1V035253@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: emaste set sender to
 emaste@FreeBSD.org using -f
From: Ed Maste <emaste@FreeBSD.org>
Date: Tue, 13 Jun 2017 18:59:34 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject: svn commit: r319915 - stable/11/sys/arm/arm
X-SVN-Group: stable-11
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable@freebsd.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: SVN commit messages for all the -stable branches of the src tree
 <svn-src-stable.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-stable>, 
 <mailto:svn-src-stable-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-stable/>
List-Post: <mailto:svn-src-stable@freebsd.org>
List-Help: <mailto:svn-src-stable-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-stable>,
 <mailto:svn-src-stable-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 13 Jun 2017 18:59:36 -0000

Author: emaste
Date: Tue Jun 13 18:59:34 2017
New Revision: 319915
URL: https://svnweb.freebsd.org/changeset/base/319915

Log:
  MFC r317428 (cognet): fix arm64 MSI
  
  In arm_gicv2m_alloc_msi(), if we found a suitable irq range, leave the loop
  before we increase irq again, or we'd end up choosing an irq, and then
  really using the next one, even if it's not available.
  Also in the inner loop, correct the end check so that we check every irq,
  even the last one.
  This makes the msk(4) adapter able to use MSI on Softiron Overdrive 1000.
  
  PR:		219956
  Approved by:	re (gjb)

Modified:
  stable/11/sys/arm/arm/gic.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/arm/arm/gic.c
==============================================================================
--- stable/11/sys/arm/arm/gic.c	Tue Jun 13 18:55:21 2017	(r319914)
+++ stable/11/sys/arm/arm/gic.c	Tue Jun 13 18:59:34 2017	(r319915)
@@ -1640,7 +1640,7 @@ arm_gicv2m_alloc_msi(device_t dev, device_t child, int
 	mtx_lock(&sc->sc_mutex);
 
 	found = false;
-	for (irq = sc->sc_spi_start; irq < sc->sc_spi_end && !found; irq++) {
+	for (irq = sc->sc_spi_start; irq < sc->sc_spi_end; irq++) {
 		/* Start on an aligned interrupt */
 		if ((irq & (maxcount - 1)) != 0)
 			continue;
@@ -1649,7 +1649,7 @@ arm_gicv2m_alloc_msi(device_t dev, device_t child, int
 		found = true;
 
 		/* Check this range is valid */
-		for (end_irq = irq; end_irq != irq + count - 1; end_irq++) {
+		for (end_irq = irq; end_irq != irq + count; end_irq++) {
 			/* No free interrupts */
 			if (end_irq == sc->sc_spi_end) {
 				found = false;
@@ -1666,6 +1666,8 @@ arm_gicv2m_alloc_msi(device_t dev, device_t child, int
 				break;
 			}
 		}
+		if (found)
+			break;
 	}
 
 	/* Not enough interrupts were found */