platform/x86: Add BIOS Dynamic SAR driver for Intel M.2 Modem
v4 cover platform/x86: Add BIOS Dynamic SAR driver for Intel M.2 Modem
SAR (Specific Absorption Rate) driver is a host driver implemented for Linux or chrome platform to limit the exposure of human body to RF frequency by informing the Intel M.2 modem to regulate the RF power based on SAR data obtained from the sensors captured in the BIOS. ACPI interface exposes this data from the BIOS to SAR driver. The front end application in userspace ( eg: Modem Manager) will interact with SAR driver to obtain information like the device mode (Example: tablets, laptops, etx), Antenna index, baseband index, SAR table index and use available communication like MBIM interface to enable data communication to modem for RF power regulation.
The BIOS gets notified about device mode changes through Sensor Driver. This information is given to a (newly created) WWAN ACPI function driver when there is a device mode change. The driver then uses a _DSM method to retrieve the required information from BIOS.
This information is then forwarded to the User-space using the sysfs_notify interface.
A lookup table is maintained inside the BIOS which suggests the SAR Table index and Antenna Tuner Table Index values for individual device modes.
The SAR parameters to be used on the Modem differs for each Regulatory Mode like FCC, CE and ISED.
Hence, the SAR parameters are stored separately in the SMBIOS table in the OEM BIOS, for each of the Regulatory mode. Regulatory modes will be different based on the region and network available in that region.
Hence the entire SAR functionality handling is divided into 2 parts:
• A ACPI function driver implemented that uses a dedicated ACPI node for WWAN device.
Sends notifications whenever there is change in Device Mode. (each OEM has different mechanism of updating this DEVICE Mode info). This is notified to User-space applications using the sysfs_notify interface.
• WWAN Device Service listens for sysfs_notify messages and reads the sysfs data and routes them
to Modem using MBIM.
Shravan S (1):
platform/x86: Add BIOS Dynamic SAR driver for Intel M.2 Modem
.../ABI/testing/sysfs-driver-intc_sar | 56 ++++ MAINTAINERS | 7 + drivers/platform/x86/Kconfig | 15 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel-sar.c | 317 ++++++++++++++++++ include/linux/platform_data/x86/intel-sar.h | 88 +++++ 6 files changed, 484 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-intc_sar create mode 100644 drivers/platform/x86/intel-sar.c create mode 100644 include/linux/platform_data/x86/intel-sar.h
base-commit: 902e7f373fff2476b53824264c12e4e76c7ec02a
Signature · 1 line
2.17.1
PATCH v4 1/1 platform/x86: Add BIOS Dynamic SAR driver for Intel M.2 Modem
BIOS SAR driver for RF power regulation on Intel M.2 Modem. Uses ACPI to communicate to BIOS to retrieve SAR information data. Uses Sysfs to communicate this data to userspace via read and notify. Userspace will use MBIM interface to enable data communication to modem.
---
V4 :
* Code changes based on review comments.
* Logging related changes
* Added Documentation and Maintainer file updates
--- .../ABI/testing/sysfs-driver-intc_sar | 56 ++++ MAINTAINERS | 7 + drivers/platform/x86/Kconfig | 15 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel-sar.c | 317 ++++++++++++++++++ include/linux/platform_data/x86/intel-sar.h | 88 +++++ 6 files changed, 484 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-intc_sar create mode 100644 drivers/platform/x86/intel-sar.c create mode 100644 include/linux/platform_data/x86/intel-sar.h
Documentation/ABI/testing/sysfs-driver-intc_sar new file +56 -0
@@ -0,0 +1,56 @@ +What: /sys/bus/platform/devices/INTC1092:00/intc_reg +Date: August 2021 +KernelVersion: 5.13.8 +Contact: Shravan S <[email protected]>, + An Sudhakar <[email protected]> +Description: + Specific Absorption Rate (SAR) regulatory mode is typically + derived based on information like mcc/mnc that is available for + the currently attached LTE network. A userspace application is + required to set the current SAR regulatory mode on the Dynamic SAR + driver using this sysfs node. Such an application can also read + back using this sysfs node, the currently configured regulatory mode + value from the Dynamic SAR driver. + + Acceptable regulatory modes are: + == ==== + 0 FCC + 1 CE + 2 ISED + == ==== + + - The regulatory mode value has one of the above values. + - The default regulatory mode used in the driver is 0. + +What: /sys/bus/platform/devices/INTC1092:00/intc_data +Date: August 2021 +KernelVersion: 5.13.8 +Contact: Shravan S <[email protected]>, + An Sudhakar <[email protected]> +Description: + This sysfs entry is used to retrieve Dynamic SAR information + emitted/maintained by a BIOS that supports Dynamic SAR. + + The retrieved information is in the order given below: + - device_mode + - bandtable_index + - antennatable_index + - sartable_index + + The above information is sent as integer values separated + by a single space. This information can then be pushed to a + WWAN modem that uses this to control the transmit signal + level using the Band/Antenna/SAR table index information. + These parameters are derived/decided by aggregating + device-mode like laptop/tablet/clamshell etc. and the + proximity-sensor data available to the embedded controller on + given host. The regulatory mode configured on Dynamic SAR + driver also influences these values. + + The above information is communicated to a userspace + application using EPOLLPRI event on file-descriptor (fd) + obtained by opening this sysfs entry. This event is received + using the epoll() system call with EPOLLET flag to get only + edge triggered events. On getting such an event, application + can then read this information from the sysfs node and + consume the given information.
MAINTAINERS +7 -0
@@ -9221,6 +9221,13 @@ L: [email protected] S: Maintained F: drivers/platform/x86/intel_atomisp2_led.c +INTEL BIOS SAR DRIVER +M: Shravan S <[email protected]> +M: Intel Corporation <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/intel-sar.c + INTEL BROXTON PMC DRIVER M: Mika Westerberg <[email protected]> M: Zha Qipeng <[email protected]>
drivers/platform/x86/Kconfig +15 -0
@@ -1247,6 +1247,21 @@ config INTEL_PUNIT_IPC This driver provides support for Intel P-Unit Mailbox IPC mechanism, which is used to bridge the communications between kernel and P-Unit. +config INTEL_SAR + tristate "Intel Specific Absorption Rate Driver" + depends on ACPI + help + This driver helps to limit the exposure of human body to RF frequency by + providing information to userspace application that will inform the Intel + M.2 modem to regulate the RF power based on SAR data obtained from the + sensors captured in the BIOS. ACPI interface exposes this data from the BIOS + to SAR driver. The front end application in userspace will interact with SAR + driver to obtain information like the device mode, Antenna index, baseband index, + SAR table index and use available communication like MBIM interface to enable + data communication to modem for RF power regulation. Enable this config when + given platform needs to support "Dynamic SAR" configuration for a modem available + on the platform. + config INTEL_SCU_IPC bool
drivers/platform/x86/Makefile +1 -0
@@ -123,6 +123,7 @@ obj-$(CONFIG_INTEL_SMARTCONNECT) += intel-smartconnect.o obj-$(CONFIG_INTEL_SPEED_SELECT_INTERFACE) += intel_speed_select_if/ obj-$(CONFIG_INTEL_TURBO_MAX_3) += intel_turbo_max_3.o obj-$(CONFIG_INTEL_UNCORE_FREQ_CONTROL) += intel-uncore-frequency.o +obj-$(CONFIG_INTEL_SAR) += intel-sar.o # Intel PMIC / PMC / P-Unit devices obj-$(CONFIG_INTEL_BXTWC_PMIC_TMU) += intel_bxtwc_tmu.o
drivers/platform/x86/intel-sar.c new file +317 -0
317 lines not on this page · raw message
include/linux/platform_data/x86/intel-sar.h new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.17.1
(Side note, most of the comments you may have avoided if you had read an internal Wiki page about popular style mistakes) Another note, comments given even against one occurrence of similar code should be considered for the others.
Quoted 5 lines · Shravan S
BIOS SAR driver for RF power regulation on Intel M.2 Modem. Uses ACPI to communicate to BIOS to retrieve SAR information data. Uses Sysfs to communicate this data to userspace via read and notify. Userspace will use MBIM interface to enable data communication to modem.
This is going to be a commit message. The one above is poorly written to the reader. E.g. what should I get from it "Uses ACPI"? Perhaps something more elaborative like "It uses ACPI specific methods FOO and BAR to retrieve this and that information". "The driver provides a custom sysfs interface, documented in Documentation/...."
...
Quoted 3 lines
drivers/platform/x86/Kconfig | 15 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel-sar.c | 317 ++++++++++++++++++
Use intel/ subfolder, please.
...
Quoted 1 line
+ derived based on information like mcc/mnc that is available for
What are the mcc/mnc TLAs?
...
MAINTAINERS L: [email protected] · line 9229
Quoted 6 lines
MAINTAINERS +6
-0+INTEL BIOS SAR DRIVER +M: Shravan S <[email protected]> +M: Intel Corporation <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/intel-sar.c
And nicely misses the file brought in this patch...
...
Quoted 1 line
+#include <
asm/errno.h>
Why asm?
Why at the beginning of the inclusion list?
Quoted 6 lines
drivers/platform/x86/intel-sar.c new file +5
-0+#include <linux/acpi.h> +#include <linux/kobject.h> +#include <linux/platform_data/x86/intel-sar.h> +#include <linux/platform_device.h> +#include <linux/sysfs.h>
...
Quoted 4 lines
+/**
+ *get_int_value- Retrieve Integer values from ACPI Object+ * Value of the integer from the object of ACPI is obtained.
Put this after field descriptions. Same for all kernel doc descriptions.
Quoted 4 lines
+ * @obj:
acpi_objectpointer which has the integer value
+ * @out: output pointer will get integer value+ * returns 0 on success
and that's it?
Besides that, your style doesn't follow the grammar and punctuation rules.
drivers/platform/x86/intel-sar.c line 26
Quoted 8 lines
+ */
drivers/platform/x86/intel-sar.c new file +6
-0+static int get_int_value (union acpi_object *obj,int *out) +{ +if (obj && obj->type ==ACPI_TYPE_INTEGER ) { + *out = (int )obj->integer.value; +return 0 ; + }else {
Redundant.
Review
Quoted 2 lines
(quoted diff) +2
-0+ return -EIO; + }
Besides above, use standard pattern
if (foo != expected)
return error;
Quoted 1 line
+}
...
drivers/platform/x86/intel-sar.c line 62
Quoted 5 lines
drivers/platform/x86/intel-sar.c new file +4
-0+static acpi_status parse_package (struct wwan_sar_context *context,union acpi_object *item) +{ +struct wwan_device_mode_configuration *data; +int value =0 , itr =0 , reg =0 , count =0 ;
Why redundant assignments? They actually may hide the real errors.
drivers/platform/x86/intel-sar.c line 66
Quoted 5 lines
drivers/platform/x86/intel-sar.c new file +4
-0+union acpi_object *num; + + num = &item->package.elements[0 ]; +if ((get_int_value (num, &value) !=0 ) || (value <0 || value >=MAX_REGULATORY ))
Too many parentheses. " != 0" is redundant (this applies to many places in the proposed patch).
Quoted 31 lines
drivers/platform/x86/intel-sar.c new file +31
-0+return AE_ERROR ; + + reg = value; + + data = &context->config_data[reg]; +if (data->total_dev_mode >MAX_DEV_MODES || data->total_dev_mode ==0 ) +return AE_ERROR ; + count = (data->total_dev_mode < item->package.count) ? + data->total_dev_mode : item->package.count; + data->device_mode_info =kmalloc_array (data->total_dev_mode, +sizeof (struct wwan_device_mode_info ),GFP_KERNEL ); +if (!data->device_mode_info) +return AE_ERROR ; +for (itr =0 ; itr < count; itr++) { +struct wwan_device_mode_info temp = {0 }; + + num = &item->package.elements[itr +1 ]; +if (num->type !=ACPI_TYPE_PACKAGE || num->package.count <TOTAL_DATA ) +continue ; +if (get_int_value (&num->package.elements[0 ], &temp.device_mode) !=0 ) +continue ; +if (get_int_value (&num->package.elements[1 ], &temp.bandtable_index) !=0 ) +continue ; +if (get_int_value (&num->package.elements[2 ], &temp.antennatable_index) !=0 ) +continue ; +if (get_int_value (&num->package.elements[3 ], &temp.sartable_index) !=0 ) +continue ; + data->device_mode_info[itr] = temp; + } +return AE_OK ; +}
...
drivers/platform/x86/intel-sar.c line 116
Quoted 13 lines
drivers/platform/x86/intel-sar.c new file +12
-0+static acpi_status sar_get_device_mode (struct platform_device *device) +{ +struct wwan_sar_context *context =dev_get_drvdata (&device->dev); +acpi_status status =AE_OK ; +union acpi_object *out; +int value =0 ; +u32 rev =0 ; + + out =acpi_evaluate_dsm (context->handle, &context->guid, rev, +COMMAND_ID_DEV_MODE ,NULL ); +if (get_int_value (out, &value) !=0 ) { +pr_err ("%s: Cmd:%d Failed\n" , __func__,COMMAND_ID_DEV_MODE );
Use dev_err() and similar when you have a struct device. The message itself looks like debugging, to be an error you have to provide a human readable one and without __func__.
Quoted 5 lines
drivers/platform/x86/intel-sar.c new file +5
-0+ status =AE_ERROR ; + goto dev_mode_error; + } + context->sar_data.device_mode = value; +sysfs_notify (&device->dev.kobj,NULL ,SYSFS_DATANAME );
drivers/platform/x86/intel-sar.c line 130
Quoted 10 lines
drivers/platform/x86/intel-sar.c new file +9
-0+ +dev_mode_error: +ACPI_FREE (out); +return status; +} + +static const struct acpi_device_id sar_device_ids[] = { + {"INTC1092" ,0 }, + {"" ,0 },
No comma for terminator, moreover the { } is enough.
drivers/platform/x86/intel-sar.c line 132
Quoted 3 lines
drivers/platform/x86/intel-sar.c new file +2
-0+}; +
Redundant blank line.
Quoted 1 line
+MODULE_DEVICE_TABLE(acpi,
sar_device_ids);
...
drivers/platform/x86/intel-sar.c line 137
Quoted 3 lines
drivers/platform/x86/intel-sar.c new file +3
-0+static const struct platform_device_id sar_device_table[] = { + {"intc1092" ,0 }, + {},
No comma.
Quoted 1 line
+};
...
drivers/platform/x86/intel-sar.c line 167
Quoted 11 lines
drivers/platform/x86/intel-sar.c new file +10
-0+static ssize_t intc_reg_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct wwan_sar_context *context =dev_get_drvdata (dev); +unsigned long value =0 ; +int read =0 ; +if (!count) { +pr_err ("%s count = %d" , __func__, (int )count); +return -EFAULT ; + }
Is it ever possible?
drivers/platform/x86/intel-sar.c line 171
Quoted 4 lines
drivers/platform/x86/intel-sar.c new file +4
-0+ read =kstrtoul (buf,0 , &value); +if (read <=0 ) { +pr_err ("%s Not a integer" , __func__); +return -EINVAL ;
Don't shadow an error code.
drivers/platform/x86/intel-sar.c line 174
Quoted 5 lines
drivers/platform/x86/intel-sar.c new file +3
-0+ } +if (value >=MAX_REGULATORY ) +return -EINVAL ;
ERANGE?
EOVERFLOW?
Quoted 1 line
+
context->reg_value= (int)value;
Why to use unsigned long in then cast to int? Maybe use int in the first place?
drivers/platform/x86/intel-sar.c line 177
Quoted 3 lines
drivers/platform/x86/intel-sar.c new file +2
-0+update_sar_data (context); +dev_set_drvdata (dev, context);
This seems a misuse of the field.
drivers/platform/x86/intel-sar.c line 181
Quoted 5 lines
drivers/platform/x86/intel-sar.c new file +4
-0+sysfs_notify (&dev->kobj,NULL ,SYSFS_DATANAME ); +return count; +} +
Redundant.
drivers/platform/x86/intel-sar.c line 183
Quoted 2 lines
drivers/platform/x86/intel-sar.c new file +2
-0+static DEVICE_ATTR_RO (intc_data); +static DEVICE_ATTR_RW (intc_reg);
Attach each of them to the respective functions.
...
drivers/platform/x86/intel-sar.c line 211
Quoted 7 lines
drivers/platform/x86/intel-sar.c new file +7
-0+static int sar_probe (struct platform_device *device) +{ +union acpi_object *out, *item, req; +struct wwan_sar_context *context; +acpi_status status =AE_OK ; +u32 rev =0 , reg =0 ; +int result =0 ;
Why assignments?
drivers/platform/x86/intel-sar.c line 216
Quoted 4 lines
drivers/platform/x86/intel-sar.c new file +4
-0+ context =kmalloc (sizeof (*context),GFP_KERNEL ); +if (!context) +return -ENOMEM ; +memset (context,0 ,sizeof (struct wwan_sar_context ));
NIH kzalloc().
drivers/platform/x86/intel-sar.c line 219
Quoted 4 lines
drivers/platform/x86/intel-sar.c new file +3
-0+ context->sar_device = device; +dev_set_drvdata (&device->dev, context); +if (guid_parse (SAR_DSM_UUID , &context->guid)) {
Shadowed error code
Quoted 30 lines
drivers/platform/x86/intel-sar.c new file +29
-0+pr_err ("%s: UUID error\n" , __func__); + goto r_free; + } + context->handle =ACPI_HANDLE (&device->dev); +for (reg =0 ; reg <MAX_REGULATORY ; reg++) { + req.type =ACPI_TYPE_INTEGER ; + req.integer.value = reg; + out =acpi_evaluate_dsm (context->handle, &context->guid, rev, +COMMAND_ID_CONFIG_TABLE , &req); +if (!out) { +pr_err ("%s: Cmd:%d Failed\n" , __func__,COMMAND_ID_CONFIG_TABLE ); +continue ; + } +if (out->type ==ACPI_TYPE_PACKAGE && out->package.count >=3 && + out->package.elements[0 ].type ==ACPI_TYPE_INTEGER && + out->package.elements[1 ].type ==ACPI_TYPE_INTEGER && + out->package.elements[2 ].type ==ACPI_TYPE_PACKAGE ) { + context->config_data[reg].version = out->package.elements[0 ].integer.value; + context->config_data[reg].total_dev_mode = + out->package.elements[1 ].integer.value; +if (context->config_data[reg].total_dev_mode <=0 || + context->config_data[reg].total_dev_mode >MAX_DEV_MODES ) { +pr_err ("total_dev_mode is not within range : %d\n" , + context->config_data[reg].total_dev_mode); +ACPI_FREE (out); +continue ; + } + item = &out->package.elements[2 ]; +if (item->package.count >0 )
drivers/platform/x86/intel-sar.c line 258
Quoted 10 lines
drivers/platform/x86/intel-sar.c new file +10
-0+ status =parse_package (context, item); + else + status =AE_ERROR ; +if (status !=AE_OK ) { +ACPI_FREE (out); +continue ; + } + } +ACPI_FREE (out); + }
Try to refactor this for-loop. Perhaps even move it out to a function or so.
Quoted 13 lines
drivers/platform/x86/intel-sar.c new file +13
-0+update_sar_data (context); + result =sysfs_create_group (&device->dev.kobj, &intcsar_group); +if (result) { +pr_err ("sysfs creation failed\n" ); + goto r_free; + } +if (sar_get_device_mode (device) !=AE_OK ) { +pr_err ("Failed sar_get_device_mode\n" ); + goto r_sys; + } +if (acpi_install_notify_handler (ACPI_HANDLE (&device->dev),ACPI_DEVICE_NOTIFY , + sar_notify, (void *)device) !=AE_OK ) { +pr_err ("Failed acpi_install_notify_handler\n" );
drivers/platform/x86/intel-sar.c line 280
Quoted 10 lines
drivers/platform/x86/intel-sar.c new file +9
-0+ goto r_sys; + } +return 0 ; + +r_sys: +sysfs_remove_group (&device->dev.kobj, &intcsar_group); +r_free: +kfree (context); +return -1 ;
What is this?
Quoted 17 lines
drivers/platform/x86/intel-sar.c new file +17
-0+} + +static int sar_remove (struct platform_device *device) +{ +struct wwan_sar_context *context =dev_get_drvdata (&device->dev); +int reg =0 ; + +acpi_remove_notify_handler (ACPI_HANDLE (&device->dev), +ACPI_DEVICE_NOTIFY , sar_notify); +sysfs_remove_group (&device->dev.kobj, &intcsar_group); +for (reg =0 ; reg <MAX_REGULATORY ; reg++) { +kfree (context->config_data[reg].device_mode_info); + context->config_data[reg].device_mode_info =NULL ; + } +kfree (context); +return 0 ; +}
...
Quoted 1 line
+MODULE_DEVICE_TABLE(platform,
sar_device_table);
Besides the misplaced line in the code, why do you need this?
...
Quoted 1 line
+ /* FOR ACPI HANDLING */
Useless.
...
Quoted 1 line
+ .id_table =
sar_device_table,
Why?
drivers/platform/x86/intel-sar.c line 132
Quoted 3 lines
drivers/platform/x86/intel-sar.c new file +2
-0+}; +
Redundant blank line.
...
Quoted 2 lines
+/*
+ * Intel Corporation Header File for Specific Absorption Rate
What is this supposed to mean?
Quoted 2 lines
+ * Copyright (c) 2021, Intel Corporation.
+ */
It seems like your header lacks the inclusion of the needed headers and/or type forward declarations.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 10 lines · Shravan S
SAR (Specific Absorption Rate) driver is a host driver implemented for Linux or chrome platform to limit the exposure of human body to RF frequency by informing the Intel M.2 modem to regulate the RF power based on SAR data obtained from the sensors captured in the BIOS. ACPI interface exposes this data from the BIOS to SAR driver. The front end application in userspace ( eg: Modem Manager) will interact with SAR driver to obtain information like the device mode (Example: tablets, laptops, etx), Antenna index, baseband index, SAR table index and use available communication like MBIM interface to enable data communication to modem for RF power regulation.
The BIOS gets notified about device mode changes through Sensor Driver. This information is given to a (newly created) WWAN ACPI function driver when there is a device mode change. The driver then uses a
_DSMmethod to retrieve the required information from BIOS.
This information is then forwarded to the User-space using thesysfs_notifyinterface.
A lookup table is maintained inside the BIOS which suggests the SAR Table index and Antenna Tuner Table Index values for individual device modes.The SAR parameters to be used on the Modem differs for each Regulatory Mode like FCC, CE and ISED.
Hence, the SAR parameters are stored separately in the SMBIOS table in the OEM BIOS, for each of the Regulatory mode. Regulatory modes will be different based on the region and network available in that region.
Quoted 8 lines
Hence the entire SAR functionality handling is divided into 2 parts:
• A ACPI function driver implemented that uses a dedicated ACPI node for WWAN device.
Sends notifications whenever there is change in Device Mode. (each OEM has different mechanism of updating this DEVICE Mode info). This is notified to User-space applications using thesysfs_notifyinterface.
• WWAN Device Service listens forsysfs_notifymessages and reads the sysfs data and routes them
to Modem using MBIM.
Thank you for the new version.
I expect that you will send a new version addressing Andy's remarks, so I'm going to drop this version from my queue.
Regards,
Hans