LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Jake Oshins <jakeo@microsoft.com>
To: gregkh@linuxfoundation.org, kys@microsoft.com,
	linux-kernel@vger.kernel.org, devel@linuxdriverproject.org,
	olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com,
	rjw@rjwysocki.net, arjan@linux.intel.com
Cc: Jake Oshins <jakeo@microsoft.com>
Subject: [PATCH v2 1/3] drivers:pnp Add support for descendants claiming memory address space
Date: Tue,  3 Mar 2015 14:14:27 -0800	[thread overview]
Message-ID: <1425420869-12750-2-git-send-email-jakeo@microsoft.com> (raw)
In-Reply-To: <1425420869-12750-1-git-send-email-jakeo@microsoft.com>

This patch adds the concept of "descendant" device to the pnp layer, one which
can claim memory mapped I/O space from the same regions of address space that
its "aunts" and "uncles" are claiming from.  This is more or less analogous to
a device on an ISA bus that needs address space, but needs to avoid claiming
any regions that are in use by PCI devices which are peers of the PCI to ISA
bridge.

This is done in support of changes in the Hyper-V-related drivers, but nothing
in this patch is specific to Hyper-V, except in that it doesn't seem to be
needed for anything else.


Signed-off-by: Jake Oshins <jakeo@microsoft.com>
---
 drivers/pnp/Makefile     |   2 +-
 drivers/pnp/base.h       |   2 +
 drivers/pnp/core.c       |   1 +
 drivers/pnp/descendant.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pnp.h      |  23 ++++++++++
 5 files changed, 144 insertions(+), 1 deletion(-)
 create mode 100644 drivers/pnp/descendant.c

diff --git a/drivers/pnp/Makefile b/drivers/pnp/Makefile
index bfba893..de315f9 100644
--- a/drivers/pnp/Makefile
+++ b/drivers/pnp/Makefile
@@ -4,7 +4,7 @@
 
 obj-y		:= pnp.o
 
-pnp-y		:= core.o card.o driver.o resource.o manager.o support.o interface.o quirks.o
+pnp-y		:= core.o card.o driver.o resource.o manager.o support.o interface.o quirks.o descendant.o
 
 obj-$(CONFIG_PNPACPI)		+= pnpacpi/
 obj-$(CONFIG_PNPBIOS)		+= pnpbios/
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h
index c8873b0..0b86437 100644
--- a/drivers/pnp/base.h
+++ b/drivers/pnp/base.h
@@ -175,6 +175,8 @@ struct pnp_resource *pnp_add_bus_resource(struct pnp_dev *dev,
 					  resource_size_t start,
 					  resource_size_t end);
 
+int __init pnpdescendant_init(void);
+
 extern int pnp_debug;
 
 #if defined(CONFIG_PNP_DEBUG_MESSAGES)
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
index cb6ce42..fc32912 100644
--- a/drivers/pnp/core.c
+++ b/drivers/pnp/core.c
@@ -212,6 +212,7 @@ void __pnp_remove_device(struct pnp_dev *dev)
 
 static int __init pnp_init(void)
 {
+	pnpdescendant_init();
 	return bus_register(&pnp_bus_type);
 }
 
diff --git a/drivers/pnp/descendant.c b/drivers/pnp/descendant.c
new file mode 100644
index 0000000..c25e40b
--- /dev/null
+++ b/drivers/pnp/descendant.c
@@ -0,0 +1,117 @@
+/*
+ * descendant.c - Resource management for devices which are descendants
+ * (children or grandchildren of) devices which directly allocate resources,
+ * i.e. devices enumerated by ACPI, PCI, PCMCIA, ISAPNP or PNPBIOS
+ *
+ * Copyright (C) 2015 Microsoft
+ *      Jake Oshins <jakeo@microsoft.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/pnp.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include "base.h"
+
+int descendant_get_resources(struct pnp_dev *dev)
+{
+	return 0;
+}
+
+int descendant_set_resources(struct pnp_dev *dev)
+{
+	return 0;
+}
+
+int descendant_disable_resources(struct pnp_dev *dev)
+{
+	return 0;
+}
+
+struct pnp_protocol descendant_protocol = {
+	.name	 = "Plug and Play descendants",
+	.get	 = descendant_get_resources,
+	.set	 = descendant_set_resources,
+	.disable = descendant_disable_resources,
+};
+
+/*
+ * This adds an option to the descendant device for memory address space.
+*/
+int pnp_descendant_memory_option(struct pnp_dev *dev, resource_size_t min,
+				 resource_size_t max, resource_size_t alignment,
+				 resource_size_t size, unsigned char flags)
+{
+	return pnp_register_mem_resource(dev, 0, min, max, alignment, size,
+					 flags);
+}
+EXPORT_SYMBOL(pnp_descendant_memory_option);
+
+/*
+ * This creates an entry in the plug-and-play layer for this device, which
+ * is a descendant of a device already in the plug-and-play layer.
+*/
+int pnp_add_descendant(struct pnp_dev *dev)
+{
+	int error;
+
+	error = pnp_add_device(dev);
+	if (error) {
+		put_device(&dev->dev);
+		return error;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(pnp_add_descendant);
+
+void pnp_remove_descendant(struct pnp_dev *dev)
+{
+	__pnp_remove_device(dev);
+}
+EXPORT_SYMBOL(pnp_remove_descendant);
+
+int __init pnpdescendant_init(void)
+{
+	return pnp_register_protocol(&descendant_protocol);
+}
+
+struct pnp_dev *alloc_pnp_descendant(const char *pnpid)
+{
+	struct pnp_dev *dev;
+
+	dev = pnp_alloc_dev(&descendant_protocol, 0, pnpid);
+
+	if (!dev)
+		return NULL;
+
+	pnp_init_resources(dev);
+	dev->capabilities |= PNP_CONFIGURABLE;
+	dev->capabilities |= PNP_READ;
+	dev->capabilities |= PNP_WRITE;
+	dev->capabilities |= PNP_DISABLE;
+	dev->capabilities |= PNP_REMOVABLE;
+
+	return dev;
+}
+EXPORT_SYMBOL(alloc_pnp_descendant);
+
+void free_pnp_descendant(struct pnp_dev *dev)
+{
+	kfree(dev);
+}
+EXPORT_SYMBOL(free_pnp_descendant);
+
diff --git a/include/linux/pnp.h b/include/linux/pnp.h
index 6512e9c..269a7af 100644
--- a/include/linux/pnp.h
+++ b/include/linux/pnp.h
@@ -477,6 +477,15 @@ int compare_pnp_id(struct pnp_id *pos, const char *id);
 int pnp_register_driver(struct pnp_driver *drv);
 void pnp_unregister_driver(struct pnp_driver *drv);
 
+/* descendant support */
+struct pnp_dev *alloc_pnp_descendant(const char *pnpid);
+void free_pnp_descendant(struct pnp_dev *dev);
+int pnp_add_descendant(struct pnp_dev *dev);
+void pnp_remove_descendant(struct pnp_dev *dev);
+int pnp_descendant_memory_option(struct pnp_dev *dev, resource_size_t min,
+				 resource_size_t max, resource_size_t alignment,
+				 resource_size_t size, unsigned char flags);
+
 #else
 
 /* device management */
@@ -508,6 +517,20 @@ static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -E
 static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; }
 static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
 
+/* descendant support */
+static inline struct pnp_dev *alloc_pnp_descendant(const char *pnpid)
+{ return NULL; }
+static inline void free_pnp_descendant(struct pnp_dev *dev) { }
+static inline int pnp_add_descendant(struct pnp_dev *dev) { return -ENODEV; }
+static inline void pnp_remove_descendant(struct pnp_dev *dev) { }
+static inline int pnp_descendant_memory_option(struct pnp_dev *dev,
+					       resource_size_t min,
+					       resource_size_t max,
+					       resource_size_t alignment,
+					       resource_size_t size,
+					       unsigned char flags)
+{ return -ENODEV; }
+
 #endif /* CONFIG_PNP */
 
 #endif /* _LINUX_PNP_H */
-- 
1.9.1


  reply	other threads:[~2015-03-03 20:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-03 22:14 [PATCH v2 0/3] Convert Hyper-V code to use the pnp layer Jake Oshins
2015-03-03 22:14 ` Jake Oshins [this message]
2015-03-03 22:14 ` [PATCH v2 2/3] drivers:hv Convert VMBus and its descendants to PnP Jake Oshins
2015-03-03 22:14 ` [PATCH v2 3/3] drivers:hv Remove old MMIO management code Jake Oshins

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=1425420869-12750-2-git-send-email-jakeo@microsoft.com \
    --to=jakeo@microsoft.com \
    --cc=apw@canonical.com \
    --cc=arjan@linux.intel.com \
    --cc=devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olaf@aepfle.de \
    --cc=rjw@rjwysocki.net \
    --cc=vkuznets@redhat.com \
    --subject='Re: [PATCH v2 1/3] drivers:pnp Add support for descendants claiming memory address space' \
    /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

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).