Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Minwoo Im <minwoo.im.dev@gmail.com>
To: linux-pci@vger.kernel.org
Cc: "Bjorn Helgaas" <bhelgaas@google.com>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Minwoo Im" <minwoo.im.dev@gmail.com>
Subject: [PATCH V2] PCI: Use __pci_set_master from do_pci_disable_device
Date: Fri,  5 Mar 2021 21:22:56 +0900	[thread overview]
Message-ID: <20210305122256.133779-1-minwoo.im.dev@gmail.com> (raw)

__pci_set_master is there to enable or disable the Bus Master Enable
bit in the COMMAND register.  This function also has debug log which is
useful to users.

do_pci_disable_device is also disabling the BME bitfield where some of
the codes are duplicated with __pci_set_master.  The only difference
between the two is whether to set flag `dev->is_busmaster` or not.

This patch removed that duplications by adding one more parameter to
__pci_set_master `update_bm` to decide whether to update the flag or
not.  It also will have the debug log from __pci_set_master which is
good for debug from logs.

Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
---
Since V1:
  - Update commit description to indicate why this patch is needed.
    (Krzysztof)
  - Take dev->is_busmaster into account by adding a new argument to
    __pci_set_master.  (Krzysztof)

 drivers/pci/pci.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 16a17215f633..374b555b59c0 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -48,6 +48,8 @@ EXPORT_SYMBOL(pci_pci_problems);
 
 unsigned int pci_pm_d3hot_delay;
 
+static void __pci_set_master(struct pci_dev *dev, bool enable,
+			     bool update_bme);
 static void pci_pme_list_scan(struct work_struct *work);
 
 static LIST_HEAD(pci_pme_list);
@@ -2101,13 +2103,7 @@ void __weak pcibios_penalize_isa_irq(int irq, int active) {}
 
 static void do_pci_disable_device(struct pci_dev *dev)
 {
-	u16 pci_command;
-
-	pci_read_config_word(dev, PCI_COMMAND, &pci_command);
-	if (pci_command & PCI_COMMAND_MASTER) {
-		pci_command &= ~PCI_COMMAND_MASTER;
-		pci_write_config_word(dev, PCI_COMMAND, pci_command);
-	}
+	__pci_set_master(dev, false, false);
 
 	pcibios_disable_device(dev);
 }
@@ -4244,7 +4240,7 @@ void __iomem *devm_pci_remap_cfg_resource(struct device *dev,
 }
 EXPORT_SYMBOL(devm_pci_remap_cfg_resource);
 
-static void __pci_set_master(struct pci_dev *dev, bool enable)
+static void __pci_set_master(struct pci_dev *dev, bool enable, bool update_bme)
 {
 	u16 old_cmd, cmd;
 
@@ -4258,7 +4254,9 @@ static void __pci_set_master(struct pci_dev *dev, bool enable)
 			enable ? "enabling" : "disabling");
 		pci_write_config_word(dev, PCI_COMMAND, cmd);
 	}
-	dev->is_busmaster = enable;
+
+	if (update_bme)
+		dev->is_busmaster = enable;
 }
 
 /**
@@ -4309,7 +4307,7 @@ void __weak pcibios_set_master(struct pci_dev *dev)
  */
 void pci_set_master(struct pci_dev *dev)
 {
-	__pci_set_master(dev, true);
+	__pci_set_master(dev, true, true);
 	pcibios_set_master(dev);
 }
 EXPORT_SYMBOL(pci_set_master);
@@ -4320,7 +4318,7 @@ EXPORT_SYMBOL(pci_set_master);
  */
 void pci_clear_master(struct pci_dev *dev)
 {
-	__pci_set_master(dev, false);
+	__pci_set_master(dev, false, true);
 }
 EXPORT_SYMBOL(pci_clear_master);
 
-- 
2.27.0


                 reply	other threads:[~2021-03-05 12:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210305122256.133779-1-minwoo.im.dev@gmail.com \
    --to=minwoo.im.dev@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=kw@linux.com \
    --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