ACPICA: Introduce acpi_load_table_with_index()
diff mbox series

Message ID 20190923094701.24950-1-nikolaus.voss@loewensteinmedical.de
State Queued, archived
Headers show
Series
  • ACPICA: Introduce acpi_load_table_with_index()
Related show

Commit Message

Nikolaus Voss Sept. 23, 2019, 9:47 a.m. UTC
For unloading an ACPI table, it is necessary to provide the
index of the table. The method intended for dynamically
loading or hotplug addition of tables, acpi_load_table(),
does not provide this information, so a new function
acpi_load_table_with_index() with the same functionality,
but an optional pointer to the loaded table index is introduced.

The new function is used in the acpi_configfs driver to save the
index of the newly loaded table in order to unload it later.

Reported-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Fixes: d06c47e3dd07f ("ACPI: configfs: Resolve objects on host-directed table loads")
Signed-off-by: Nikolaus Voss <nikolaus.voss@loewensteinmedical.de>
---
 drivers/acpi/acpi_configfs.c   |  2 +-
 drivers/acpi/acpica/tbxfload.c | 43 ++++++++++++++++++++++++++++++++++
 include/acpi/acpixf.h          |  6 +++++
 3 files changed, 50 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko Sept. 24, 2019, 12:07 p.m. UTC | #1
On Mon, Sep 23, 2019 at 11:47:01AM +0200, Nikolaus Voss wrote:
> For unloading an ACPI table, it is necessary to provide the
> index of the table. The method intended for dynamically
> loading or hotplug addition of tables, acpi_load_table(),
> does not provide this information, so a new function
> acpi_load_table_with_index() with the same functionality,
> but an optional pointer to the loaded table index is introduced.
> 
> The new function is used in the acpi_configfs driver to save the
> index of the newly loaded table in order to unload it later.

I'll test it later, though couple of remarks:
- would it make sense to provide a counter part helper for unloading? Now it
  looks a bit inconsistent in configfs when we use acpi_load_*() vs.
  acpi_tb_*() in remove.
- please, include Ferry into Cc (as done in this mail)
Andy Shevchenko Sept. 24, 2019, 12:08 p.m. UTC | #2
On Tue, Sep 24, 2019 at 03:07:34PM +0300, Shevchenko, Andriy wrote:
> On Mon, Sep 23, 2019 at 11:47:01AM +0200, Nikolaus Voss wrote:
> > For unloading an ACPI table, it is necessary to provide the
> > index of the table. The method intended for dynamically
> > loading or hotplug addition of tables, acpi_load_table(),
> > does not provide this information, so a new function
> > acpi_load_table_with_index() with the same functionality,
> > but an optional pointer to the loaded table index is introduced.
> > 
> > The new function is used in the acpi_configfs driver to save the
> > index of the newly loaded table in order to unload it later.
> 
> I'll test it later, though couple of remarks:
> - would it make sense to provide a counter part helper for unloading? Now it
>   looks a bit inconsistent in configfs when we use acpi_load_*() vs.
>   acpi_tb_*() in remove.

...and I think we may unexport acpi_tb_* in this case as Bob suggested for it
to be internal API.

> - please, include Ferry into Cc (as done in this mail)
Andy Shevchenko Sept. 24, 2019, 3:11 p.m. UTC | #3
On Mon, Sep 23, 2019 at 11:47:01AM +0200, Nikolaus Voss wrote:
> For unloading an ACPI table, it is necessary to provide the
> index of the table. The method intended for dynamically
> loading or hotplug addition of tables, acpi_load_table(),
> does not provide this information, so a new function
> acpi_load_table_with_index() with the same functionality,
> but an optional pointer to the loaded table index is introduced.
> 
> The new function is used in the acpi_configfs driver to save the
> index of the newly loaded table in order to unload it later.
> 

Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

But consider addressing my comments in one of previous mails.

> Reported-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Fixes: d06c47e3dd07f ("ACPI: configfs: Resolve objects on host-directed table loads")
> Signed-off-by: Nikolaus Voss <nikolaus.voss@loewensteinmedical.de>
> ---
>  drivers/acpi/acpi_configfs.c   |  2 +-
>  drivers/acpi/acpica/tbxfload.c | 43 ++++++++++++++++++++++++++++++++++
>  include/acpi/acpixf.h          |  6 +++++
>  3 files changed, 50 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/acpi/acpi_configfs.c b/drivers/acpi/acpi_configfs.c
> index 57d9d574d4dd..9e77d5a266c0 100644
> --- a/drivers/acpi/acpi_configfs.c
> +++ b/drivers/acpi/acpi_configfs.c
> @@ -53,7 +53,7 @@ static ssize_t acpi_table_aml_write(struct config_item *cfg,
>  	if (!table->header)
>  		return -ENOMEM;
>  
> -	ret = acpi_load_table(table->header);
> +	ret = acpi_load_table_with_index(table->header, &table->index);
>  	if (ret) {
>  		kfree(table->header);
>  		table->header = NULL;
> diff --git a/drivers/acpi/acpica/tbxfload.c b/drivers/acpi/acpica/tbxfload.c
> index 86f1693f6d29..7ea4fc879cb6 100644
> --- a/drivers/acpi/acpica/tbxfload.c
> +++ b/drivers/acpi/acpica/tbxfload.c
> @@ -309,6 +309,49 @@ acpi_status acpi_load_table(struct acpi_table_header *table)
>  
>  ACPI_EXPORT_SYMBOL(acpi_load_table)
>  
> +/*******************************************************************************
> + *
> + * FUNCTION:    acpi_load_table_with_index
> + *
> + * PARAMETERS:  table               - Pointer to a buffer containing the ACPI
> + *                                    table to be loaded.
> + *              table_idx           - Pointer to a u32 for storing the table
> + *                                    index, might be NULL
> + * RETURN:      Status
> + *
> + * DESCRIPTION: see acpi_load_table() above. Additionally returns the index
> + *              of the newly created table in table_idx.
> + *
> + ******************************************************************************/
> +acpi_status acpi_load_table_with_index(struct acpi_table_header *table,
> +				       u32 *table_idx)
> +{
> +	acpi_status status;
> +	u32 table_index;
> +
> +	ACPI_FUNCTION_TRACE(acpi_load_table_with_index);
> +
> +	/* Parameter validation */
> +	if (!table)
> +		return_ACPI_STATUS(AE_BAD_PARAMETER);
> +
> +	/* Install the table and load it into the namespace */
> +	ACPI_INFO(("Host-directed Dynamic ACPI Table Load:"));
> +	status = acpi_tb_install_and_load_table(
> +		ACPI_PTR_TO_PHYSADDR(table), ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
> +		FALSE, &table_index);
> +	if (table_idx)
> +		*table_idx = table_index;
> +
> +	if (ACPI_SUCCESS(status)) {
> +		/* Complete the initialization/resolution of new objects */
> +		acpi_ns_initialize_objects();
> +	}
> +
> +	return_ACPI_STATUS(status);
> +}
> +ACPI_EXPORT_SYMBOL(acpi_load_table_with_index)
> +
>  /*******************************************************************************
>   *
>   * FUNCTION:    acpi_unload_parent_table
> diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h
> index e5e041413581..af375ab318de 100644
> --- a/include/acpi/acpixf.h
> +++ b/include/acpi/acpixf.h
> @@ -460,6 +460,12 @@ ACPI_EXTERNAL_RETURN_STATUS(acpi_status ACPI_INIT_FUNCTION
>  ACPI_EXTERNAL_RETURN_STATUS(acpi_status
>  			    acpi_load_table(struct acpi_table_header *table))
>  
> +
> +ACPI_EXTERNAL_RETURN_STATUS(acpi_status
> +			    acpi_load_table_with_index(
> +				    struct acpi_table_header *table,
> +				    u32 *table_idx))
> +
>  ACPI_EXTERNAL_RETURN_STATUS(acpi_status
>  			    acpi_unload_parent_table(acpi_handle object))
>  
> -- 
> 2.17.1
>
Nikolaus Voss Sept. 25, 2019, 10:20 a.m. UTC | #4
On Tue, 24 Sep 2019, Shevchenko, Andriy wrote:
> On Tue, Sep 24, 2019 at 03:07:34PM +0300, Shevchenko, Andriy wrote:
>> On Mon, Sep 23, 2019 at 11:47:01AM +0200, Nikolaus Voss wrote:
>>> For unloading an ACPI table, it is necessary to provide the
>>> index of the table. The method intended for dynamically
>>> loading or hotplug addition of tables, acpi_load_table(),
>>> does not provide this information, so a new function
>>> acpi_load_table_with_index() with the same functionality,
>>> but an optional pointer to the loaded table index is introduced.
>>>
>>> The new function is used in the acpi_configfs driver to save the
>>> index of the newly loaded table in order to unload it later.
>>
>> I'll test it later, though couple of remarks:
>> - would it make sense to provide a counter part helper for unloading? Now it
>>   looks a bit inconsistent in configfs when we use acpi_load_*() vs.
>>   acpi_tb_*() in remove.

Yes, IMO it would make sense, but it is an ACPICA API change. Bob, what's 
your opinion?

>
> ...and I think we may unexport acpi_tb_* in this case as Bob suggested for it
> to be internal API.

see above.

>
>> - please, include Ferry into Cc (as done in this mail)
>
Nikolaus Voss Sept. 25, 2019, 10:22 a.m. UTC | #5
On Tue, 24 Sep 2019, Andy Shevchenko wrote:
> On Mon, Sep 23, 2019 at 11:47:01AM +0200, Nikolaus Voss wrote:
>> For unloading an ACPI table, it is necessary to provide the
>> index of the table. The method intended for dynamically
>> loading or hotplug addition of tables, acpi_load_table(),
>> does not provide this information, so a new function
>> acpi_load_table_with_index() with the same functionality,
>> but an optional pointer to the loaded table index is introduced.
>>
>> The new function is used in the acpi_configfs driver to save the
>> index of the newly loaded table in order to unload it later.
>>
>
> Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks!

>
> But consider addressing my comments in one of previous mails.
>
>> Reported-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> Fixes: d06c47e3dd07f ("ACPI: configfs: Resolve objects on host-directed table loads")
>> Signed-off-by: Nikolaus Voss <nikolaus.voss@loewensteinmedical.de>
>> ---
>>  drivers/acpi/acpi_configfs.c   |  2 +-
>>  drivers/acpi/acpica/tbxfload.c | 43 ++++++++++++++++++++++++++++++++++
>>  include/acpi/acpixf.h          |  6 +++++
>>  3 files changed, 50 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/acpi/acpi_configfs.c b/drivers/acpi/acpi_configfs.c
>> index 57d9d574d4dd..9e77d5a266c0 100644
>> --- a/drivers/acpi/acpi_configfs.c
>> +++ b/drivers/acpi/acpi_configfs.c
>> @@ -53,7 +53,7 @@ static ssize_t acpi_table_aml_write(struct config_item *cfg,
>>  	if (!table->header)
>>  		return -ENOMEM;
>>
>> -	ret = acpi_load_table(table->header);
>> +	ret = acpi_load_table_with_index(table->header, &table->index);
>>  	if (ret) {
>>  		kfree(table->header);
>>  		table->header = NULL;
>> diff --git a/drivers/acpi/acpica/tbxfload.c b/drivers/acpi/acpica/tbxfload.c
>> index 86f1693f6d29..7ea4fc879cb6 100644
>> --- a/drivers/acpi/acpica/tbxfload.c
>> +++ b/drivers/acpi/acpica/tbxfload.c
>> @@ -309,6 +309,49 @@ acpi_status acpi_load_table(struct acpi_table_header *table)
>>
>>  ACPI_EXPORT_SYMBOL(acpi_load_table)
>>
>> +/*******************************************************************************
>> + *
>> + * FUNCTION:    acpi_load_table_with_index
>> + *
>> + * PARAMETERS:  table               - Pointer to a buffer containing the ACPI
>> + *                                    table to be loaded.
>> + *              table_idx           - Pointer to a u32 for storing the table
>> + *                                    index, might be NULL
>> + * RETURN:      Status
>> + *
>> + * DESCRIPTION: see acpi_load_table() above. Additionally returns the index
>> + *              of the newly created table in table_idx.
>> + *
>> + ******************************************************************************/
>> +acpi_status acpi_load_table_with_index(struct acpi_table_header *table,
>> +				       u32 *table_idx)
>> +{
>> +	acpi_status status;
>> +	u32 table_index;
>> +
>> +	ACPI_FUNCTION_TRACE(acpi_load_table_with_index);
>> +
>> +	/* Parameter validation */
>> +	if (!table)
>> +		return_ACPI_STATUS(AE_BAD_PARAMETER);
>> +
>> +	/* Install the table and load it into the namespace */
>> +	ACPI_INFO(("Host-directed Dynamic ACPI Table Load:"));
>> +	status = acpi_tb_install_and_load_table(
>> +		ACPI_PTR_TO_PHYSADDR(table), ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
>> +		FALSE, &table_index);
>> +	if (table_idx)
>> +		*table_idx = table_index;
>> +
>> +	if (ACPI_SUCCESS(status)) {
>> +		/* Complete the initialization/resolution of new objects */
>> +		acpi_ns_initialize_objects();
>> +	}
>> +
>> +	return_ACPI_STATUS(status);
>> +}
>> +ACPI_EXPORT_SYMBOL(acpi_load_table_with_index)
>> +
>>  /*******************************************************************************
>>   *
>>   * FUNCTION:    acpi_unload_parent_table
>> diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h
>> index e5e041413581..af375ab318de 100644
>> --- a/include/acpi/acpixf.h
>> +++ b/include/acpi/acpixf.h
>> @@ -460,6 +460,12 @@ ACPI_EXTERNAL_RETURN_STATUS(acpi_status ACPI_INIT_FUNCTION
>>  ACPI_EXTERNAL_RETURN_STATUS(acpi_status
>>  			    acpi_load_table(struct acpi_table_header *table))
>>
>> +
>> +ACPI_EXTERNAL_RETURN_STATUS(acpi_status
>> +			    acpi_load_table_with_index(
>> +				    struct acpi_table_header *table,
>> +				    u32 *table_idx))
>> +
>>  ACPI_EXTERNAL_RETURN_STATUS(acpi_status
>>  			    acpi_unload_parent_table(acpi_handle object))
>>
>> --
>> 2.17.1
>>
>

Patch
diff mbox series

diff --git a/drivers/acpi/acpi_configfs.c b/drivers/acpi/acpi_configfs.c
index 57d9d574d4dd..9e77d5a266c0 100644
--- a/drivers/acpi/acpi_configfs.c
+++ b/drivers/acpi/acpi_configfs.c
@@ -53,7 +53,7 @@  static ssize_t acpi_table_aml_write(struct config_item *cfg,
 	if (!table->header)
 		return -ENOMEM;
 
-	ret = acpi_load_table(table->header);
+	ret = acpi_load_table_with_index(table->header, &table->index);
 	if (ret) {
 		kfree(table->header);
 		table->header = NULL;
diff --git a/drivers/acpi/acpica/tbxfload.c b/drivers/acpi/acpica/tbxfload.c
index 86f1693f6d29..7ea4fc879cb6 100644
--- a/drivers/acpi/acpica/tbxfload.c
+++ b/drivers/acpi/acpica/tbxfload.c
@@ -309,6 +309,49 @@  acpi_status acpi_load_table(struct acpi_table_header *table)
 
 ACPI_EXPORT_SYMBOL(acpi_load_table)
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_load_table_with_index
+ *
+ * PARAMETERS:  table               - Pointer to a buffer containing the ACPI
+ *                                    table to be loaded.
+ *              table_idx           - Pointer to a u32 for storing the table
+ *                                    index, might be NULL
+ * RETURN:      Status
+ *
+ * DESCRIPTION: see acpi_load_table() above. Additionally returns the index
+ *              of the newly created table in table_idx.
+ *
+ ******************************************************************************/
+acpi_status acpi_load_table_with_index(struct acpi_table_header *table,
+				       u32 *table_idx)
+{
+	acpi_status status;
+	u32 table_index;
+
+	ACPI_FUNCTION_TRACE(acpi_load_table_with_index);
+
+	/* Parameter validation */
+	if (!table)
+		return_ACPI_STATUS(AE_BAD_PARAMETER);
+
+	/* Install the table and load it into the namespace */
+	ACPI_INFO(("Host-directed Dynamic ACPI Table Load:"));
+	status = acpi_tb_install_and_load_table(
+		ACPI_PTR_TO_PHYSADDR(table), ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
+		FALSE, &table_index);
+	if (table_idx)
+		*table_idx = table_index;
+
+	if (ACPI_SUCCESS(status)) {
+		/* Complete the initialization/resolution of new objects */
+		acpi_ns_initialize_objects();
+	}
+
+	return_ACPI_STATUS(status);
+}
+ACPI_EXPORT_SYMBOL(acpi_load_table_with_index)
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_unload_parent_table
diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h
index e5e041413581..af375ab318de 100644
--- a/include/acpi/acpixf.h
+++ b/include/acpi/acpixf.h
@@ -460,6 +460,12 @@  ACPI_EXTERNAL_RETURN_STATUS(acpi_status ACPI_INIT_FUNCTION
 ACPI_EXTERNAL_RETURN_STATUS(acpi_status
 			    acpi_load_table(struct acpi_table_header *table))
 
+
+ACPI_EXTERNAL_RETURN_STATUS(acpi_status
+			    acpi_load_table_with_index(
+				    struct acpi_table_header *table,
+				    u32 *table_idx))
+
 ACPI_EXTERNAL_RETURN_STATUS(acpi_status
 			    acpi_unload_parent_table(acpi_handle object))