From: Stewart Hildebrand <stewart.hildebrand@amd.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: Stewart Hildebrand <stewart.hildebrand@amd.com>,
<linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 2/8] PCI: Don't unnecessarily disable memory decoding
Date: Tue, 16 Jul 2024 15:32:32 -0400 [thread overview]
Message-ID: <20240716193246.1909697-3-stewart.hildebrand@amd.com> (raw)
In-Reply-To: <20240716193246.1909697-1-stewart.hildebrand@amd.com>
If alignment is requested for a device and all the BARs are already
sufficiently aligned, there is no need to disable memory decoding for
the device. Add a check for this scenario to save a PCI config space
access.
Also, there is no need to disable memory decoding if already disabled,
since the bit in question (PCI_COMMAND_MEMORY) is a RW bit. Make the
write conditional to save a PCI config space access.
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
---
v1->v2:
* new subject (was: "PCI: don't clear already cleared bit")
* don't disable memory decoding if alignment is not needed
---
drivers/pci/pci.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 02b1d81b1419..53345dc596b5 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6565,7 +6565,7 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev,
return align;
}
-static void pci_request_resource_alignment(struct pci_dev *dev, int bar,
+static bool pci_request_resource_alignment(struct pci_dev *dev, int bar,
resource_size_t align, bool resize)
{
struct resource *r = &dev->resource[bar];
@@ -6573,17 +6573,17 @@ static void pci_request_resource_alignment(struct pci_dev *dev, int bar,
resource_size_t size;
if (!(r->flags & IORESOURCE_MEM))
- return;
+ return false;
if (r->flags & IORESOURCE_PCI_FIXED) {
pci_info(dev, "%s %pR: ignoring requested alignment %#llx\n",
r_name, r, (unsigned long long)align);
- return;
+ return false;
}
size = resource_size(r);
if (size >= align)
- return;
+ return false;
/*
* Increase the alignment of the resource. There are two ways we
@@ -6626,6 +6626,8 @@ static void pci_request_resource_alignment(struct pci_dev *dev, int bar,
r->end = r->start + size - 1;
}
r->flags |= IORESOURCE_UNSET;
+
+ return true;
}
/*
@@ -6641,7 +6643,7 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
struct resource *r;
resource_size_t align;
u16 command;
- bool resize = false;
+ bool resize = false, align_needed = false;
/*
* VF BARs are read-only zero according to SR-IOV spec r1.1, sec
@@ -6663,12 +6665,21 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
return;
}
- pci_read_config_word(dev, PCI_COMMAND, &command);
- command &= ~PCI_COMMAND_MEMORY;
- pci_write_config_word(dev, PCI_COMMAND, command);
+ for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
+ bool ret;
- for (i = 0; i <= PCI_ROM_RESOURCE; i++)
- pci_request_resource_alignment(dev, i, align, resize);
+ ret = pci_request_resource_alignment(dev, i, align, resize);
+ align_needed = align_needed || ret;
+ }
+
+ if (!align_needed)
+ return;
+
+ pci_read_config_word(dev, PCI_COMMAND, &command);
+ if (command & PCI_COMMAND_MEMORY) {
+ command &= ~PCI_COMMAND_MEMORY;
+ pci_write_config_word(dev, PCI_COMMAND, command);
+ }
/*
* Need to disable bridge's resource window,
--
2.45.2
next prev parent reply other threads:[~2024-07-16 19:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-16 19:32 [PATCH v2 0/8] PCI: Align small (<4k) BARs Stewart Hildebrand
2024-07-16 19:32 ` [PATCH v2 1/8] x86/PCI: Move some logic to new function Stewart Hildebrand
2024-07-17 19:28 ` Philipp Stanner
2024-07-18 14:54 ` Stewart Hildebrand
2024-07-16 19:32 ` Stewart Hildebrand [this message]
2024-07-16 19:32 ` [PATCH v2 3/8] PCI: Restore resource alignment Stewart Hildebrand
2024-07-16 19:32 ` [PATCH v2 4/8] PCI: Restore memory decoding after reallocation Stewart Hildebrand
2024-07-16 19:32 ` [PATCH v2 5/8] x86/PCI: Preserve IORESOURCE_STARTALIGN alignment Stewart Hildebrand
2024-07-16 19:32 ` [PATCH v2 6/8] powerpc/pci: " Stewart Hildebrand
2024-07-16 19:32 ` [PATCH v2 7/8] PCI: Don't reassign resources that are already aligned Stewart Hildebrand
2024-07-16 19:32 ` [PATCH v2 8/8] PCI: Align small (<4k) BARs Stewart Hildebrand
2024-07-17 13:15 ` [PATCH v2 0/8] " David Laight
2024-07-17 13:21 ` David Laight
2024-07-17 18:30 ` Stewart Hildebrand
2024-07-18 10:01 ` David Laight
2024-07-18 13:48 ` Stewart Hildebrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240716193246.1909697-3-stewart.hildebrand@amd.com \
--to=stewart.hildebrand@amd.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®