2015-07-21 13:31:20

by Graeme Gregory

[permalink] [raw]
Subject: [RFC PATCH] Exporting extra tables for machines without /dev/mem

Hi,

I thought I would send this patch as an RFC. It is something I did when
another linaro engineer was modifying acpica-tools to not require /dev/mem.

It exports the 3 tables that are not currenly exported in sysfs.

Currently I do not think there is any user of this because acpica-tools can
can recover the information in the other tables without these three being
exported, fwts also works fine without the patch so the only use case I have
is the vague "might be useful for debug"

So I ask the list for its opinions.

Graeme


2015-07-21 13:31:23

by Graeme Gregory

[permalink] [raw]
Subject: [RFC PATCH] ACPI: sysfs expose root tables RSDP/RSDT/XSDT

On some architectures /dev/mem is being removed. For debug/analysis
tools like FWTS/acpidump we therefore need to expose the ACPI root
tables in sysfs like the other tables.

Signed-off-by: Graeme Gregory <[email protected]>
---
drivers/acpi/sysfs.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 123 insertions(+)

diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index 0876d77b..c998ea1 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -348,6 +348,127 @@ acpi_sysfs_table_handler(u32 event, void *table, void *context)
return AE_OK;
}

+/*
+ * On some architectures /dev/mem interface is not available so for debug
+ * tools like FWTS, acpidump etc we will also need to export the three
+ * root tables RSDP, RSDT, XSDT where they exist.
+ */
+
+struct acpi_root_table_attr {
+ struct bin_attribute attr;
+ acpi_physical_address table_addr;
+};
+
+static ssize_t acpi_table_show_root(struct file *filp, struct kobject *kobj,
+ struct bin_attribute *bin_attr, char *buf,
+ loff_t offset, size_t count)
+{
+ struct acpi_root_table_attr *table_attr =
+ container_of(bin_attr,
+ struct acpi_root_table_attr, attr);
+ void *table;
+ int ret;
+
+ table = acpi_os_map_memory(table_attr->table_addr, bin_attr->size);
+
+ if (!table)
+ return -EIO;
+
+ ret = memory_read_from_buffer(buf, count, &offset, table,
+ bin_attr->size);
+ acpi_os_unmap_memory(table, bin_attr->size);
+
+ return ret;
+}
+
+static int acpi_root_tables_sysfs_init(struct kobject *tables_kobj)
+{
+ struct acpi_root_table_attr *root_tables_attr;
+ struct acpi_table_rsdp *rsdp;
+ struct acpi_table_header *table_header = NULL;
+ acpi_physical_address rsdp_ptr, rsdt_ptr, xsdt_ptr;
+ int ret;
+
+ rsdp_ptr = acpi_os_get_root_pointer();
+
+ if (!rsdp_ptr)
+ return -EIO;
+
+ rsdp = acpi_os_map_memory(rsdp_ptr, sizeof(*rsdp));
+ if (!rsdp) {
+ ret = -EIO;
+ goto err;
+ }
+
+ root_tables_attr = kzalloc(sizeof(*root_tables_attr) * 3, GFP_KERNEL);
+ if (!root_tables_attr) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ root_tables_attr[0].table_addr = rsdp_ptr;
+ root_tables_attr[0].attr.size = sizeof(*rsdp);
+ root_tables_attr[0].attr.read = acpi_table_show_root;
+ root_tables_attr[0].attr.attr.name = "RSDP";
+ root_tables_attr[0].attr.attr.mode = 0400;
+
+ ret = sysfs_create_bin_file(tables_kobj, &root_tables_attr[0].attr);
+ if (ret)
+ goto err;
+
+ rsdt_ptr = rsdp->rsdt_physical_address;
+ if (rsdt_ptr) {
+ table_header = acpi_os_map_memory(rsdt_ptr,
+ sizeof(*table_header));
+ if (!table_header) {
+ ret = -EIO;
+ goto err;
+ }
+
+ root_tables_attr[1].table_addr = rsdt_ptr;
+ root_tables_attr[1].attr.size = table_header->length;
+ root_tables_attr[1].attr.read = acpi_table_show_root;
+ root_tables_attr[1].attr.attr.name = "RSDT";
+ root_tables_attr[1].attr.attr.mode = 0400;
+
+ ret = sysfs_create_bin_file(tables_kobj,
+ &root_tables_attr[1].attr);
+ if (ret)
+ goto err;
+ acpi_os_unmap_memory(table_header, sizeof(*table_header));
+ }
+
+ xsdt_ptr = rsdp->xsdt_physical_address;
+ if (xsdt_ptr) {
+ table_header = acpi_os_map_memory(xsdt_ptr,
+ sizeof(*table_header));
+ if (!table_header) {
+ ret = -EIO;
+ goto err;
+ }
+
+ root_tables_attr[2].table_addr = xsdt_ptr;
+ root_tables_attr[2].attr.size = table_header->length;
+ root_tables_attr[2].attr.read = acpi_table_show_root;
+ root_tables_attr[2].attr.attr.name = "XSDT";
+ root_tables_attr[2].attr.attr.mode = 0400;
+
+ ret = sysfs_create_bin_file(tables_kobj,
+ &root_tables_attr[2].attr);
+ if (ret)
+ goto err;
+ acpi_os_unmap_memory(table_header, sizeof(*table_header));
+ }
+ return ret;
+
+err:
+ if (rsdp)
+ acpi_os_map_memory(rsdp_ptr, sizeof(*rsdp));
+ if (table_header)
+ acpi_os_unmap_memory(table_header, sizeof(*table_header));
+ return ret;
+}
+
static int acpi_tables_sysfs_init(void)
{
struct acpi_table_attr *table_attr;
@@ -387,6 +508,8 @@ static int acpi_tables_sysfs_init(void)
list_add_tail(&table_attr->node, &acpi_table_attr_list);
}

+ acpi_root_tables_sysfs_init(tables_kobj);
+
kobject_uevent(tables_kobj, KOBJ_ADD);
kobject_uevent(dynamic_tables_kobj, KOBJ_ADD);
status = acpi_install_table_handler(acpi_sysfs_table_handler, NULL);
--
2.1.4

2015-08-05 20:25:12

by Al Stone

[permalink] [raw]
Subject: Re: [RFC PATCH] Exporting extra tables for machines without /dev/mem

On 07/21/2015 07:31 AM, Graeme Gregory wrote:
> Hi,
>
> I thought I would send this patch as an RFC. It is something I did when
> another linaro engineer was modifying acpica-tools to not require /dev/mem.
>
> It exports the 3 tables that are not currenly exported in sysfs.
>
> Currently I do not think there is any user of this because acpica-tools can
> can recover the information in the other tables without these three being
> exported, fwts also works fine without the patch so the only use case I have
> is the vague "might be useful for debug"

Right -- and I personally would like to have that debug use case. AFAICT,
the RSDP and RSDT/XSDT are recreated by acpidump; i.e., based on knowledge
of the mapped tables, acpidump builds what it believes these tables should
look like. But, the /dev/mem mappings would give me what ACPI is actually
using (what was directly passed to the kernel). Should there be a bug in
table mapping or ACPI startup, this info might help.

--
ciao,
al
-----------------------------------
Al Stone
Software Engineer
Red Hat, Inc.
[email protected]
-----------------------------------

2015-08-05 23:11:13

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [RFC PATCH] Exporting extra tables for machines without /dev/mem

On Wednesday, August 05, 2015 02:25:06 PM Al Stone wrote:
> On 07/21/2015 07:31 AM, Graeme Gregory wrote:
> > Hi,
> >
> > I thought I would send this patch as an RFC. It is something I did when
> > another linaro engineer was modifying acpica-tools to not require /dev/mem.
> >
> > It exports the 3 tables that are not currenly exported in sysfs.
> >
> > Currently I do not think there is any user of this because acpica-tools can
> > can recover the information in the other tables without these three being
> > exported, fwts also works fine without the patch so the only use case I have
> > is the vague "might be useful for debug"
>
> Right -- and I personally would like to have that debug use case. AFAICT,
> the RSDP and RSDT/XSDT are recreated by acpidump; i.e., based on knowledge
> of the mapped tables, acpidump builds what it believes these tables should
> look like. But, the /dev/mem mappings would give me what ACPI is actually
> using (what was directly passed to the kernel). Should there be a bug in
> table mapping or ACPI startup, this info might help.

If my memory serves me right, Lv has been doing something in that area. Lv?