[PATCH V2] PCI: Use __pci_set_master from do_pci_disable_device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



__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@xxxxxxxxx>
---
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




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux