2 * ACPI configfs support
4 * Copyright (c) 2016 Intel Corporation
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
11 #define pr_fmt(fmt) "ACPI configfs: " fmt
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/configfs.h>
16 #include <linux/acpi.h>
18 #include "acpica/accommon.h"
19 #include "acpica/actables.h"
21 static struct config_group
*acpi_table_group
;
24 struct config_item cfg
;
25 struct acpi_table_header
*header
;
29 static ssize_t
acpi_table_aml_write(struct config_item
*cfg
,
30 const void *data
, size_t size
)
32 const struct acpi_table_header
*header
= data
;
33 struct acpi_table
*table
;
36 table
= container_of(cfg
, struct acpi_table
, cfg
);
39 pr_err("table already loaded\n");
43 if (header
->length
!= size
) {
44 pr_err("invalid table length\n");
48 if (memcmp(header
->signature
, ACPI_SIG_SSDT
, 4)) {
49 pr_err("invalid table signature\n");
53 table
= container_of(cfg
, struct acpi_table
, cfg
);
55 table
->header
= kmemdup(header
, header
->length
, GFP_KERNEL
);
59 ACPI_INFO(("Host-directed Dynamic ACPI Table Load:"));
60 ret
= acpi_tb_install_and_load_table(
61 ACPI_PTR_TO_PHYSADDR(table
->header
),
62 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
, FALSE
,
72 static inline struct acpi_table_header
*get_header(struct config_item
*cfg
)
74 struct acpi_table
*table
= container_of(cfg
, struct acpi_table
, cfg
);
77 pr_err("table not loaded\n");
82 static ssize_t
acpi_table_aml_read(struct config_item
*cfg
,
83 void *data
, size_t size
)
85 struct acpi_table_header
*h
= get_header(cfg
);
91 memcpy(data
, h
, h
->length
);
96 #define MAX_ACPI_TABLE_SIZE (128 * 1024)
98 CONFIGFS_BIN_ATTR(acpi_table_
, aml
, NULL
, MAX_ACPI_TABLE_SIZE
);
100 struct configfs_bin_attribute
*acpi_table_bin_attrs
[] = {
101 &acpi_table_attr_aml
,
105 ssize_t
acpi_table_signature_show(struct config_item
*cfg
, char *str
)
107 struct acpi_table_header
*h
= get_header(cfg
);
112 return sprintf(str
, "%.*s\n", ACPI_NAME_SIZE
, h
->signature
);
115 ssize_t
acpi_table_length_show(struct config_item
*cfg
, char *str
)
117 struct acpi_table_header
*h
= get_header(cfg
);
122 return sprintf(str
, "%d\n", h
->length
);
125 ssize_t
acpi_table_revision_show(struct config_item
*cfg
, char *str
)
127 struct acpi_table_header
*h
= get_header(cfg
);
132 return sprintf(str
, "%d\n", h
->revision
);
135 ssize_t
acpi_table_oem_id_show(struct config_item
*cfg
, char *str
)
137 struct acpi_table_header
*h
= get_header(cfg
);
142 return sprintf(str
, "%.*s\n", ACPI_OEM_ID_SIZE
, h
->oem_id
);
145 ssize_t
acpi_table_oem_table_id_show(struct config_item
*cfg
, char *str
)
147 struct acpi_table_header
*h
= get_header(cfg
);
152 return sprintf(str
, "%.*s\n", ACPI_OEM_TABLE_ID_SIZE
, h
->oem_table_id
);
155 ssize_t
acpi_table_oem_revision_show(struct config_item
*cfg
, char *str
)
157 struct acpi_table_header
*h
= get_header(cfg
);
162 return sprintf(str
, "%d\n", h
->oem_revision
);
165 ssize_t
acpi_table_asl_compiler_id_show(struct config_item
*cfg
, char *str
)
167 struct acpi_table_header
*h
= get_header(cfg
);
172 return sprintf(str
, "%.*s\n", ACPI_NAME_SIZE
, h
->asl_compiler_id
);
175 ssize_t
acpi_table_asl_compiler_revision_show(struct config_item
*cfg
,
178 struct acpi_table_header
*h
= get_header(cfg
);
183 return sprintf(str
, "%d\n", h
->asl_compiler_revision
);
186 CONFIGFS_ATTR_RO(acpi_table_
, signature
);
187 CONFIGFS_ATTR_RO(acpi_table_
, length
);
188 CONFIGFS_ATTR_RO(acpi_table_
, revision
);
189 CONFIGFS_ATTR_RO(acpi_table_
, oem_id
);
190 CONFIGFS_ATTR_RO(acpi_table_
, oem_table_id
);
191 CONFIGFS_ATTR_RO(acpi_table_
, oem_revision
);
192 CONFIGFS_ATTR_RO(acpi_table_
, asl_compiler_id
);
193 CONFIGFS_ATTR_RO(acpi_table_
, asl_compiler_revision
);
195 struct configfs_attribute
*acpi_table_attrs
[] = {
196 &acpi_table_attr_signature
,
197 &acpi_table_attr_length
,
198 &acpi_table_attr_revision
,
199 &acpi_table_attr_oem_id
,
200 &acpi_table_attr_oem_table_id
,
201 &acpi_table_attr_oem_revision
,
202 &acpi_table_attr_asl_compiler_id
,
203 &acpi_table_attr_asl_compiler_revision
,
207 static const struct config_item_type acpi_table_type
= {
208 .ct_owner
= THIS_MODULE
,
209 .ct_bin_attrs
= acpi_table_bin_attrs
,
210 .ct_attrs
= acpi_table_attrs
,
213 static struct config_item
*acpi_table_make_item(struct config_group
*group
,
216 struct acpi_table
*table
;
218 table
= kzalloc(sizeof(*table
), GFP_KERNEL
);
220 return ERR_PTR(-ENOMEM
);
222 config_item_init_type_name(&table
->cfg
, name
, &acpi_table_type
);
226 static void acpi_table_drop_item(struct config_group
*group
,
227 struct config_item
*cfg
)
229 struct acpi_table
*table
= container_of(cfg
, struct acpi_table
, cfg
);
231 ACPI_INFO(("Host-directed Dynamic ACPI Table Unload"));
232 acpi_tb_unload_table(table
->index
);
235 struct configfs_group_operations acpi_table_group_ops
= {
236 .make_item
= acpi_table_make_item
,
237 .drop_item
= acpi_table_drop_item
,
240 static const struct config_item_type acpi_tables_type
= {
241 .ct_owner
= THIS_MODULE
,
242 .ct_group_ops
= &acpi_table_group_ops
,
245 static const struct config_item_type acpi_root_group_type
= {
246 .ct_owner
= THIS_MODULE
,
249 static struct configfs_subsystem acpi_configfs
= {
252 .ci_namebuf
= "acpi",
253 .ci_type
= &acpi_root_group_type
,
256 .su_mutex
= __MUTEX_INITIALIZER(acpi_configfs
.su_mutex
),
259 static int __init
acpi_configfs_init(void)
262 struct config_group
*root
= &acpi_configfs
.su_group
;
264 config_group_init(root
);
266 ret
= configfs_register_subsystem(&acpi_configfs
);
270 acpi_table_group
= configfs_register_default_group(root
, "table",
272 return PTR_ERR_OR_ZERO(acpi_table_group
);
274 module_init(acpi_configfs_init
);
276 static void __exit
acpi_configfs_exit(void)
278 configfs_unregister_default_group(acpi_table_group
);
279 configfs_unregister_subsystem(&acpi_configfs
);
281 module_exit(acpi_configfs_exit
);
283 MODULE_AUTHOR("Octavian Purdila <octavian.purdila@intel.com>");
284 MODULE_DESCRIPTION("ACPI configfs support");
285 MODULE_LICENSE("GPL v2");