From: Rajat Jain <rajatja@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Alan Stern <stern@rowland.harvard.edu>,
Rajat Jain <rajatja@google.com>,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
linux-usb@vger.kernel.org, helgaas@kernel.org
Cc: rajatxjain@gmail.com, jsbarnes@google.com, dtor@google.com
Subject: [PATCH 2/2] pci: Support "removable" attribute for PCI devices
Date: Fri, 23 Apr 2021 17:29:18 -0700 [thread overview]
Message-ID: <20210424002918.1962649-2-rajatja@google.com> (raw)
In-Reply-To: <20210424002918.1962649-1-rajatja@google.com>
Export the already available info, to the userspace via the
device core, so that userspace can implement whatever policies it
wants to, for external removable devices.
Signed-off-by: Rajat Jain <rajatja@google.com>
---
drivers/pci/pci-sysfs.c | 1 +
drivers/pci/probe.c | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index f8afd54ca3e1..9302f0076e73 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1582,4 +1582,5 @@ static const struct attribute_group *pci_dev_attr_groups[] = {
const struct device_type pci_dev_type = {
.groups = pci_dev_attr_groups,
+ .supports_removable = true,
};
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 953f15abc850..d1cceee62e1b 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1575,6 +1575,16 @@ static void set_pcie_untrusted(struct pci_dev *dev)
dev->untrusted = true;
}
+static void set_pci_dev_removable(struct pci_dev *dev)
+{
+ struct pci_dev *parent = pci_upstream_bridge(dev);
+ if (parent &&
+ (parent->external_facing || dev_is_removable(&parent->dev)))
+ dev_set_removable(&dev->dev, DEVICE_REMOVABLE);
+ else
+ dev_set_removable(&dev->dev, DEVICE_FIXED);
+}
+
/**
* pci_ext_cfg_is_aliased - Is ext config space just an alias of std config?
* @dev: PCI device
@@ -1819,6 +1829,8 @@ int pci_setup_device(struct pci_dev *dev)
/* "Unknown power state" */
dev->current_state = PCI_UNKNOWN;
+ set_pci_dev_removable(dev);
+
/* Early fixups, before probing the BARs */
pci_fixup_device(pci_fixup_early, dev);
--
2.31.1.498.g6c1eba8ee3d-goog
prev parent reply other threads:[~2021-04-24 0:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-24 0:29 [PATCH 1/2] driver core: Move the "removable" attribute from USB to core Rajat Jain
2021-04-24 0:29 ` Rajat Jain [this message]
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=20210424002918.1962649-2-rajatja@google.com \
--to=rajatja@google.com \
--cc=bhelgaas@google.com \
--cc=dtor@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=helgaas@kernel.org \
--cc=jsbarnes@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rajatxjain@gmail.com \
--cc=stern@rowland.harvard.edu \
/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;
as well as URLs for NNTP newsgroup(s).