Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1873226imm; Thu, 14 Jun 2018 05:22:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKMT0KKedKzWTBsNLlwzkTMl9yx8L8n5yIU2moPhGLweNzuZFQsKPT0DxDBya7IlKOAUKWi X-Received: by 2002:a63:8a4a:: with SMTP id y71-v6mr2063606pgd.291.1528978949875; Thu, 14 Jun 2018 05:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528978949; cv=none; d=google.com; s=arc-20160816; b=v/ZeNEgY+dFjBbGKrk7vRhqYbp3SmwDlwwTlUEKm5A3Csy8iZW4WPvAIzUH33FELnn 7K6/9T9C5r4mv0EdWp4q8jBMUK8Xf/Lg9ILADBsAy10R4fNn6SC3qvLztVGEzx+5pilp AVc/XbqHvM/eZjq7e2fOyZAoTsuOAvETVHE6+yfbDxKvNRjbGQQp+zH/4Zl3hCt2IJQR 5UUNEpuEKSi24ZaOrRZ/Iocdik4X8kmjSgJ35wpG7pg7qgLcwiL+XM4BGo/d+qilY8MK mnHcl6YbcPTmmlPxiO7YUSdSFru0XXaV8qwV6lae7RT0OVZ/I7IfZCpEHJvEVI4LwRcI RzsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature :arc-authentication-results; bh=qRmZFiOJSZDB20f7uqPd9NZeP2i4FhIRYyVWnfN098o=; b=m6WGuJdLx685XfGcoM8SsmAb/1jp5IRg5pUKZubPFzJ5acTJWZuLjpKFYgryKXDd9w +5VDmWowEqa9dS6Fbq8E4m0vDSxdbIQWfXwWWDxXC4NG/Tw1Ad72YDQ7K1iQvR+PGXNZ z1nRpgTGuY1DFxu67VBP+HhkEJJTtkfDWnDE8cJ0SSjT1wHkxI++mkEBgR/Mp2HmBfNM bRl6XnPNNI5aR5L6E8Yv46Hl3T+GuDkuJ4iTvepUYzEWcZuYS6m2EbU/foJs0RNJlfV4 znMooJucJZzH57DcQFqus0psN2YTvctz8QZN5JJJszNpZl8E//w4cjlooH7FGGOrihwQ deOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Dd8F34+n; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v12-v6si4248548pgs.538.2018.06.14.05.22.15; Thu, 14 Jun 2018 05:22:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Dd8F34+n; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754986AbeFNMVv (ORCPT + 99 others); Thu, 14 Jun 2018 08:21:51 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:39358 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752929AbeFNMVt (ORCPT ); Thu, 14 Jun 2018 08:21:49 -0400 Received: by mail-wr0-f194.google.com with SMTP id w7-v6so6208814wrn.6; Thu, 14 Jun 2018 05:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=qRmZFiOJSZDB20f7uqPd9NZeP2i4FhIRYyVWnfN098o=; b=Dd8F34+nIfRDyaHKIcvWCt2iLLS+N4FVWQUTf48qM+7OIv/UrVJ6AgSf/a42IVBWH4 1dRHLgJx2ad4iO0KlJGtCYs+g8PuRxWMFXTuZihEVNq0oGErioFbt0xi0SQK6LNxs4dT RGI8yv9AlpQhB8vXFIdgQ/D411izKtO9jPni6syudVSiDYQubrjpPCXFPSqYIS1xNswZ gkBXfwKG+ok6sqnyK/GqCzVzuWREpAhemdkqpHXhc8R9WATtozIGc2anm36QTM/UX1cO 0lfG7Ost8K60KZFMCxIk+VfRnrGCqh3JbnubtZ37whaeD5PbnwrgHLjMpKYCfunNH2b3 ykvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=qRmZFiOJSZDB20f7uqPd9NZeP2i4FhIRYyVWnfN098o=; b=BT93oSOZz37xdmJh7TSjtM0E20ClY4zr3X35YbMJql+yQfMh2F+pHSSAB2EIIL+5i2 MhvYJ3b0ZHOoGqq3b15buPmNBElJn6T0THrVF+fT25ESJKhWuMoJqfKdpZ8MqBYl51Ey uiLZBTRMUSQbRiGKN5T4vSA5MQq/yiOlzF3GFO6hGaos2D0GBZDkGQg44yx1xUFb1ycI 7IgGQL4jRY4vFUGMk12q/xiCaVgHDxdkEWaGLbR4y/4Igp5U0qxELZBQpjQbWW10t41W kve6knoNP1vj62fP8mQN+V5o3Km8L6y2E6wDm0F9E4mYPxOLsCPOC6pwm4s+3PRPyU3t M14g== X-Gm-Message-State: APt69E1H6RuRjn1ptlpZuE7m4ygENJdirIyrJExXZLl1uydjHK4v08mJ KtLrc5XpZMNiz3IIz+/iztM= X-Received: by 2002:adf:8da1:: with SMTP id o30-v6mr2020472wrb.81.1528978908512; Thu, 14 Jun 2018 05:21:48 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:a58a:cd2:d067:8318]) by smtp.gmail.com with ESMTPSA id v13-v6sm5086191wrq.43.2018.06.14.05.21.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jun 2018 05:21:47 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] PCI: fix restoring resized BAR state on resume Date: Thu, 14 Jun 2018 14:21:45 +0200 Message-Id: <20180614122146.62118-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Resize BARs after resume to the expected size again. Signed-off-by: Christian König BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=199959 CC: stable@vger.kernel.org # v4.15+ --- drivers/pci/pci.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index bd6f156dc3cf..d4685090378b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1159,6 +1159,33 @@ static void pci_restore_config_space(struct pci_dev *pdev) } } +static void pci_restore_rebar_state(struct pci_dev *pdev) +{ + unsigned int pos, nbars, i; + u32 ctrl; + + pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR); + if (!pos) + return; + + pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl); + nbars = (ctrl & PCI_REBAR_CTRL_NBAR_MASK) >> + PCI_REBAR_CTRL_NBAR_SHIFT; + + for (i = 0; i < nbars; i++, pos += 8) { + struct resource *res; + int bar_idx, size; + + pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl); + bar_idx = ctrl & PCI_REBAR_CTRL_BAR_IDX; + res = pdev->resource + bar_idx; + size = order_base_2((resource_size(res) >> 20) | 1) - 1; + ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE; + ctrl |= size << 8; + pci_write_config_dword(pdev, pos + PCI_REBAR_CTRL, ctrl); + } +} + /** * pci_restore_state - Restore the saved state of a PCI device * @dev: - PCI device that we're dealing with @@ -1174,6 +1201,7 @@ void pci_restore_state(struct pci_dev *dev) pci_restore_pri_state(dev); pci_restore_ats_state(dev); pci_restore_vc_state(dev); + pci_restore_rebar_state(dev); pci_cleanup_aer_error_status_regs(dev); -- 2.14.1