linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Octavian Purdila <octavian.purdila@intel.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <lenb@kernel.org>,
	Matt Fleming <matt@codeblueprint.co.uk>,
	Mark Brown <broonie@kernel.org>, Wolfram Sang <wsa@the-dreams.de>
Cc: Joel Becker <jlbec@evilplan.org>,
	linux-acpi@vger.kernel.org, linux-efi@vger.kernel.org,
	linux-i2c@vger.kernel.org, linux-spi@vger.kernel.org,
	linux-kernel@vger.kernel.org, irina.tirdea@intel.com,
	Octavian Purdila <octavian.purdila@intel.com>
Subject: [RFC PATCH v2 09/10] acpi: add support for loading SSDTs via configfs
Date: Wed, 20 Apr 2016 01:39:07 +0300	[thread overview]
Message-ID: <1461105548-20618-10-git-send-email-octavian.purdila@intel.com> (raw)
In-Reply-To: <1461105548-20618-1-git-send-email-octavian.purdila@intel.com>

Add support for acpi_user_table configfs items that allows the user to
load new tables. The data attributes contains the table data and once it
is filled from userspace the table is loaded and ACPI devices are
enumerated.

Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
---
 Documentation/ABI/testing/configfs-acpi |  16 +++++
 Documentation/acpi/ssdt-overlays.txt    |  14 +++++
 drivers/acpi/configfs.c                 | 103 +++++++++++++++++++++++++++++++-
 3 files changed, 132 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/configfs-acpi b/Documentation/ABI/testing/configfs-acpi
index 0c806aa..34a205e 100644
--- a/Documentation/ABI/testing/configfs-acpi
+++ b/Documentation/ABI/testing/configfs-acpi
@@ -5,3 +5,19 @@ Contact:	linux-acpi@vger.kernel.org
 Description:
 		This represents the ACPI subsystem entry point directory. It
 		contains sub-groups corresponding to ACPI configurable options.
+
+What:		/config/acpi/table
+Date:		April 2016
+KernelVersion:	4.6
+Description:
+
+		This group contains the configuration for user defined ACPI
+		tables. The attributes of a user define table are:
+
+		data - a binary write only attribute that the user can use to
+		       fill in the ACPI aml definitions. Once the aml data is
+		       written to this file and the file is closed the table
+		       will be loaded and ACPI device will be enumerated. To
+		       check if the operation is successful the user must check
+		       the error code for close(). If the operation is
+		       successful, subsequent writes to this attribute will fail.
diff --git a/Documentation/acpi/ssdt-overlays.txt b/Documentation/acpi/ssdt-overlays.txt
index 27f8108..f74202f 100644
--- a/Documentation/acpi/ssdt-overlays.txt
+++ b/Documentation/acpi/ssdt-overlays.txt
@@ -155,3 +155,17 @@ tmp=$(mktemp)
 /bin/echo -ne "\007\000\000\000" | cat - $filename > $tmp
 dd if=$tmp of="$EFIVARFS/$name-$guid" bs=$(stat -c %s $tmp)
 rm $tmp
+
+== Loading ACPI SSDTs from configfs ==
+
+This option allows loading of user defined SSDTs from userspace via the configfs
+interface. The CONFIG_ACPI_CONFIGFS option must be select and configfs must be
+mounted. In the following examples, we assume that configfs has been mounted in
+/config.
+
+New tables can be loading by creating new directories in /config/acpi/table/ and
+writing the SSDT aml code in the data attribute:
+
+cd /config/acpi/table
+mkdir my_ssdt
+cat ~/ssdt.aml > my_ssdt/data
diff --git a/drivers/acpi/configfs.c b/drivers/acpi/configfs.c
index 96aa3d8..5efa8ca 100644
--- a/drivers/acpi/configfs.c
+++ b/drivers/acpi/configfs.c
@@ -13,6 +13,104 @@
 #include <linux/configfs.h>
 #include <linux/acpi.h>
 
+static struct config_group *acpi_table_group;
+
+struct acpi_user_table {
+	struct config_item cfg;
+	struct acpi_table_header *table;
+};
+
+static ssize_t acpi_table_data_write(struct config_item *cfg,
+				     const void *data, size_t size)
+{
+	struct acpi_table_header *header = (struct acpi_table_header *)data;
+	struct acpi_user_table *table;
+	int ret;
+
+	table = container_of(cfg, struct acpi_user_table, cfg);
+
+	if (table->table) {
+		pr_err("ACPI configfs table: table already loaded\n");
+		return -EBUSY;
+	}
+
+	if (header->length != size) {
+		pr_err("ACPI configfs table: invalid table length\n");
+		return -EINVAL;
+	}
+
+	if (memcmp(header->signature, ACPI_SIG_SSDT, 4)) {
+		pr_err("ACPI configfs table: invalid table signature\n");
+		return -EINVAL;
+	}
+
+	table = container_of(cfg, struct acpi_user_table, cfg);
+
+	table->table = kmemdup(header, header->length, GFP_KERNEL);
+	if (!table->table)
+		return -ENOMEM;
+
+	ret = acpi_load_table(table->table);
+	if (ret) {
+		kfree(table->table);
+		table->table = NULL;
+	}
+
+	add_taint(TAINT_OVERLAY_ACPI_TABLE, LOCKDEP_STILL_OK);
+
+	return ret;
+}
+
+#define MAX_ACPI_TABLE_SIZE (128 * 1024)
+
+CONFIGFS_BIN_ATTR_WO(acpi_table_, data, NULL, MAX_ACPI_TABLE_SIZE);
+
+struct configfs_bin_attribute *acpi_table_bin_attrs[] = {
+	&acpi_table_attr_data,
+	NULL,
+};
+
+static struct config_item_type acpi_table_type = {
+	.ct_owner = THIS_MODULE,
+	.ct_bin_attrs = acpi_table_bin_attrs,
+};
+
+static struct config_item *acpi_table_make_item(struct config_group *group,
+						const char *name)
+{
+	struct acpi_user_table *table;
+
+	table = kzalloc(sizeof(*table), GFP_KERNEL);
+	if (!table)
+		return ERR_PTR(-ENOMEM);
+
+	config_item_init_type_name(&table->cfg, name, &acpi_table_type);
+	return &table->cfg;
+}
+
+struct configfs_group_operations acpi_table_group_ops = {
+	.make_item = acpi_table_make_item,
+};
+
+static struct config_item_type acpi_tables_type = {
+	.ct_owner = THIS_MODULE,
+	.ct_group_ops = &acpi_table_group_ops,
+};
+
+static struct config_item_type acpi_root_group_type = {
+	.ct_owner	= THIS_MODULE,
+};
+
+static struct configfs_subsystem acpi_configfs = {
+	.su_group = {
+		.cg_item = {
+			.ci_namebuf = "acpi",
+			.ci_type = &acpi_root_group_type,
+		},
+	},
+	.su_mutex = __MUTEX_INITIALIZER(acpi_configfs.su_mutex),
+};
+
 static int __init acpi_configfs_init(void)
 {
 	int ret;
@@ -24,12 +122,15 @@ static int __init acpi_configfs_init(void)
 	if (ret)
 		return ret;
 
-	return 0;
+	acpi_table_group = configfs_register_default_group(root, "table",
+							   &acpi_tables_type);
+	return PTR_ERR_OR_ZERO(acpi_table_group);
 }
 module_init(acpi_configfs_init);
 
 static void __exit acpi_configfs_exit(void)
 {
+	configfs_unregister_default_group(acpi_table_group);
 	configfs_unregister_subsystem(&acpi_configfs);
 }
 module_exit(acpi_configfs_exit);
-- 
1.9.1

  parent reply	other threads:[~2016-04-19 22:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-19 22:38 [RFC PATCH v2 00/10] ACPI overlays Octavian Purdila
2016-04-19 22:38 ` [RFC PATCH v2 01/10] kernel: add TAINT_OVERLAY_ACPI_TABLE Octavian Purdila
2016-04-19 22:39 ` [RFC PATCH v2 02/10] acpi: decouple initrd table install from CONFIG_ACPI_INITRD_TABLE_OVERRIDE Octavian Purdila
2016-04-19 22:39 ` [RFC PATCH v2 03/10] acpi: fix enumeration (visited) flags for bus rescans Octavian Purdila
2016-04-19 22:39 ` [RFC PATCH v2 04/10] acpi: add support for ACPI reconfiguration notifiers Octavian Purdila
2016-04-19 22:39 ` [RFC PATCH v2 05/10] i2c: add support for ACPI reconfigure notifications Octavian Purdila
     [not found]   ` <1461105548-20618-6-git-send-email-octavian.purdila-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-04-21 21:27     ` Andy Shevchenko
2016-04-21 21:41       ` Octavian Purdila
2016-04-28 14:58   ` Mika Westerberg
2016-04-19 22:39 ` [RFC PATCH v2 06/10] spi: " Octavian Purdila
     [not found]   ` <1461105548-20618-7-git-send-email-octavian.purdila-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-04-28 15:00     ` Mika Westerberg
2016-04-28 17:42     ` Mark Brown
2016-04-28 19:37       ` Octavian Purdila
2016-05-03 12:19         ` Mark Brown
     [not found]           ` <20160503121954.GQ6292-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2016-05-04 15:04             ` Octavian Purdila
2016-04-19 22:39 ` [RFC PATCH v2 07/10] efi: load SSTDs from EFI variables Octavian Purdila
2016-05-09  4:13   ` Jon Masters
     [not found]     ` <da0e65ef-7c04-e274-2f15-a50daa8c4c8c-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-09  9:59       ` Octavian Purdila
2016-04-19 22:39 ` [RFC PATCH v2 08/10] acpi: add support for configfs Octavian Purdila
2016-04-19 22:39 ` Octavian Purdila [this message]
2016-04-19 22:39 ` [RFC PATCH v2 10/10] HACK: acpi: configfs: add unload_hanlde_path attribute for tables Octavian Purdila

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=1461105548-20618-10-git-send-email-octavian.purdila@intel.com \
    --to=octavian.purdila@intel.com \
    --cc=broonie@kernel.org \
    --cc=irina.tirdea@intel.com \
    --cc=jlbec@evilplan.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=rjw@rjwysocki.net \
    --cc=wsa@the-dreams.de \
    /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).