mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthew Garrett <mjg@redhat.com>
To: abelay@mit.edu
Cc: bhelgaas@google.com, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org, Matthew Garrett <mjg@redhat.com>
Subject: [PATCH 1/2] PNP: Add a release method to system resource driver
Date: Tue, 25 Sep 2012 09:25:43 -0400	[thread overview]
Message-ID: <1348579544-1573-1-git-send-email-mjg@redhat.com> (raw)

This could conceivably be hotpluggable, and we may want to displace it
from devices under certain circustances, so add a release method to hand
back the resources.

Signed-off-by: Matthew Garrett <mjg@redhat.com>
---
 drivers/pnp/system.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/drivers/pnp/system.c b/drivers/pnp/system.c
index 49c1720..b0a50f2 100644
--- a/drivers/pnp/system.c
+++ b/drivers/pnp/system.c
@@ -52,7 +52,17 @@ static void reserve_range(struct pnp_dev *dev, struct resource *r, int port)
 		 res ? "has been" : "could not be");
 }
 
-static void reserve_resources_of_dev(struct pnp_dev *dev)
+static void free_range(struct pnp_dev *dev, struct resource *r, int port)
+{
+	resource_size_t start = r->start, end = r->end;
+
+	if (port)
+		release_region(start, end - start + 1);
+	else
+		release_mem_region(start, end - start + 1);
+}
+
+static void handle_resources_of_dev(struct pnp_dev *dev, bool free)
 {
 	struct resource *res;
 	int i;
@@ -75,29 +85,41 @@ static void reserve_resources_of_dev(struct pnp_dev *dev)
 		if (res->end < res->start)
 			continue;	/* invalid */
 
-		reserve_range(dev, res, 1);
+		if (free)
+			free_range(dev, res, 1);
+		else
+			reserve_range(dev, res, 1);
 	}
 
 	for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
 		if (res->flags & IORESOURCE_DISABLED)
 			continue;
 
-		reserve_range(dev, res, 0);
+		if (free)
+			free_range(dev, res, 0);
+		else
+			reserve_range(dev, res, 0);
 	}
 }
 
 static int system_pnp_probe(struct pnp_dev *dev,
 			    const struct pnp_device_id *dev_id)
 {
-	reserve_resources_of_dev(dev);
+	handle_resources_of_dev(dev, false);
 	return 0;
 }
 
+static void system_pnp_remove(struct pnp_dev *dev)
+{
+	handle_resources_of_dev(dev, true);
+}
+
 static struct pnp_driver system_pnp_driver = {
 	.name     = "system",
 	.id_table = pnp_dev_table,
 	.flags    = PNP_DRIVER_RES_DO_NOT_CHANGE,
 	.probe    = system_pnp_probe,
+	.remove   = system_pnp_remove,
 };
 
 static int __init pnp_system_init(void)
-- 
1.7.11.4


             reply	other threads:[~2012-09-25 13:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-25 13:25 Matthew Garrett [this message]
2012-09-25 13:25 ` [PATCH 2/2] PNP: Unbind drivers if the new driver matches _HID rather than _CID Matthew Garrett
2012-09-25 19:04   ` Bjorn Helgaas
2012-09-25 19:22     ` Matthew Garrett
2012-09-25 16:27 ` [PATCH 1/2] PNP: Add a release method to system resource driver Bjorn Helgaas

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=1348579544-1573-1-git-send-email-mjg@redhat.com \
    --to=mjg@redhat.com \
    --cc=abelay@mit.edu \
    --cc=bhelgaas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@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®