ACPI _CRS CSI-2 and MIPI DisCo for Imaging support
Subsystems (5)
Sakari Ailus
reviewerv4 cover ACPI _CRS CSI-2 and MIPI DisCo for Imaging support
Hello all,
Here's an implementation of ACPI 6.4 _CRS CSI-2 resource descriptor and MIPI DisCo for Imaging 1.0 [1]. What the two basically provide is an officially sanctioned way to describe CSI-2 connected cameras to operating system software, something DT based systems have enjoyed for quite some time already.
The implementation digs the information from ACPI tables (_CRS descriptors and data + property extensions) and constructs software nodes that are compatible with Documentation/firmware-guide/acpi/dsd/graph.rst and Documentation/devicetree/bindings/media/video-interface-devices.yaml . No specific driver changes are needed.
These patches are on the testing branch of the linux-acpi tree where they depend on the patch constifying the ACPI pathname argument for acpi_get_handle() (commit 91fdb91ccca2b48572a1ccf1d382fd599e3e1237).
[1] https://www.mipi.org/specifications/mipi-disco-imaging
since v3:
- Add comments to data structures and functions, code inside functions.
- Use ACPI_FAILURE() for testing ACPI framework function return values.
- Unwrap a few lines.
- Rename list heads as "head", some were called just "list".
- Count ACPI handles related to _CRS CSI2 resources during tree walk.
- Reshape testing for CSI-2 port allocation in next_csi2_port_index().
- Move allocation of software nodes into a new function, acpi_crs_csi2_alloc_fill_swnodes().
- Comments: acpi_bus_scan_crs_csi2() is to be called on the namespace root.
- Use size_t for this_count variable in acpi_bus_scan_crs_csi2().
- Revert the NEXT_PROPERTY() macro condition to original (the suggested one was different).
- Remove u union in init_port_csi2_common().
- Fix val array size in init_port_csi2_common(). This issue was masked by the presence of a u32 field in the union.
- Use "-" for copyright year range.
since v2:
- Unwrap a few lines.
- Copy CSI-2 resource source string using strscpy() instead of memcpy() in scan_check_crs_csi2_instance.
- Fix GRAPH_PORT_NAME() sanity check bug introduced in v2.
- Fix snprintf() return value check for port node name in get_mipi_port_handle().
- Fix mipi-img-lane-polarities reading.
- Cast bit value to bool instead of using ... ? 1U : 0U.
- Get primary fwnode using acpi_fwnode_handle().
- Don't use MIPI_IMG_PREFIX in the array of renamed properties.
- Use tabs for indenting drivers/acpi/property.c authors.
- Add a comment on assigning ACPI device's secondary fwnode and assign ACPI device's secondary fwnode straight to NULL when unassigning it.
since v1:
- Update copyright notices.
- Include linux/types.h instead of linux/kernel.h in drivers/acpi/mipi.c.
- Use SWNODE_GRAPH_PORT_NAME_FMT instead of plain "port@%u" in GRAPH_PORT_NAME macro.
- Make the condition in NEXT_PROPERTY() macro easier to read.
- Unwrap lines to make them moderately longer than 80 characters.
- Use * BITS_PER_TYPE(u8) instead of << 3 to convert bytes to bits in init_port_csi2_common().
- Test ACPI framework call success using ACPI_SUCCESS() instead of comparing with AE_OK. Likewise for ACPI_FAILURE and != AE_OK.
- Use newly added SOFTWARE_NODE() macro to construct the root software node.
- Use str_has_prefix() to test for a string prefix instead of memcmp().
- Add pr_fmt() macro to drivers/acpi/property.c.
- Move logical or operators to the end of the line in acpi_properties_prepare().
- Improve bad node type error in acpi_parse_string_ref().
Sakari Ailus (8):
ACPI: property: Parse data node string references in properties
ACPI: property: Parse _CRS CSI-2 descriptor
device property: Add SOFTWARE_NODE() macro for defining software nodes
ACPI: property: Generate camera swnodes for ACPI and DisCo for Imaging
ACPI: property: Dig "rotation" property for devices with CSI2 _CRS
ACPI: property: Rename parsed MIPI DisCo for Imaging properties
ACPI: property: Skip MIPI property table without "mipi-img" prefix
ACPI: property: Document _CRS CSI-2 and DisCo for Imaging support
drivers/acpi/Makefile | 2 +- drivers/acpi/internal.h | 9 + drivers/acpi/mipi.c | 806 +++++++++++++++++++++++++++++++++++++++ drivers/acpi/property.c | 132 +++++-- drivers/acpi/scan.c | 35 +- include/acpi/acpi_bus.h | 82 ++++ include/linux/property.h | 7 + 7 files changed, 1042 insertions(+), 31 deletions(-) create mode 100644 drivers/acpi/mipi.c
Signature · 1 line
2.30.2
Sakari Ailus
reviewerPATCH v4 1/8 ACPI: property: Parse data node string references in properties
Add support for parsing property references using strings, besides reference objects that were previously supported. This allows also referencing data nodes which was not possible with reference objects.
Also add pr_fmt() macro to prefix printouts.
While at it, update copyright.
--- drivers/acpi/property.c | 110 ++++++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 16 deletions(-)
drivers/acpi/property.c +94 -16
@@ -2,14 +2,17 @@/* * ACPI device specific properties support. * -* Copyright (C) 2014, Intel Corporation +* Copyright (C) 2014-2023, Intel Corporation * All rights reserved. * * Authors: Mika Westerberg <[email protected]> -* Darren Hart <[email protected]> -* Rafael J. Wysocki <[email protected]> +* Darren Hart <[email protected]> +* Rafael J. Wysocki <[email protected]> +* Sakari Ailus <[email protected]> */ +#define pr_fmt (fmt) "ACPI: " fmt +#include <linux/acpi.h> #include <linux/device.h> #include <linux/export.h>
@@ -795,7 +798,8 @@ acpi_fwnode_get_named_child_node(const struct fwnode_handle *fwnode,static int acpi_get_ref_args (struct fwnode_reference_args *args,struct fwnode_handle *ref_fwnode,const union acpi_object **element, -const union acpi_object *end,size_t num_args) +const union acpi_object *end,size_t num_args, +bool subnode_string) {u32 nargs =0 , i;
@@ -803,13 +807,16 @@ static int acpi_get_ref_args(struct fwnode_reference_args *args,* Find the referred data extension node under the * referred device node. */ -for (; *element < end && (*element)->type ==ACPI_TYPE_STRING ; - (*element)++) { -const char *child_name = (*element)->string.pointer; - - ref_fwnode =acpi_fwnode_get_named_child_node (ref_fwnode, child_name); -if (!ref_fwnode) -return -EINVAL ; +if (subnode_string) { +for (; *element < end && (*element)->type ==ACPI_TYPE_STRING ; + (*element)++) { +const char *child_name = (*element)->string.pointer; + + ref_fwnode =acpi_fwnode_get_named_child_node (ref_fwnode, + child_name); +if (!ref_fwnode) +return -EINVAL ; + } }/*
@@ -820,7 +827,8 @@ static int acpi_get_ref_args(struct fwnode_reference_args *args,for (i =0 ; (*element) + i < end && i < num_args; i++) {acpi_object_type type = (*element)[i].type; -if (type ==ACPI_TYPE_LOCAL_REFERENCE ) +if (type ==ACPI_TYPE_LOCAL_REFERENCE || + (!subnode_string && type ==ACPI_TYPE_STRING ))break ;if (type ==ACPI_TYPE_INTEGER )
@@ -844,6 +852,43 @@ static int acpi_get_ref_args(struct fwnode_reference_args *args,return 0 ; } +static struct fwnode_handle * +acpi_parse_string_ref (const struct fwnode_handle *fwnode,const char *refstring) +{ +acpi_handle scope, handle; +struct acpi_data_node *dn; +struct acpi_device *device; +acpi_status status; + +if (is_acpi_device_node (fwnode)) { + scope =to_acpi_device_node (fwnode)->handle; + }else if (is_acpi_data_node (fwnode)) { + scope =to_acpi_data_node (fwnode)->handle; + }else { +pr_err ("bad node type for node %pfw\n" , fwnode); +return ERR_PTR (-EINVAL ); + } + + status =acpi_get_handle (scope, refstring, &handle); +if (ACPI_FAILURE (status)) { +acpi_handle_debug (scope,"can't get handle for %s" , refstring); +return ERR_PTR (-EINVAL ); + } + + device =acpi_fetch_acpi_dev (handle); +if (device) +return acpi_fwnode_handle (device); + + status =acpi_get_data_full (handle, acpi_nondev_subnode_tag, + (void **)&dn,NULL ); +if (ACPI_FAILURE (status) || !dn) { +acpi_handle_debug (handle,"can't find subnode" ); +return ERR_PTR (-EINVAL ); + } + +return &dn->fwnode; +} +/** * __acpi_node_get_property_reference - returns handle to the referenced object * @fwnode: Firmware node to get the property from
@@ -886,6 +931,7 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,const union acpi_object *element, *end;const union acpi_object *obj;const struct acpi_device_data *data; +struct fwnode_handle *ref_fwnode;struct acpi_device *device;int ret, idx =0 ;
@@ -909,16 +955,29 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, args->fwnode =acpi_fwnode_handle (device); args->nargs =0 ; +return 0 ; +case ACPI_TYPE_STRING : +if (index) +return -ENOENT ; + + ref_fwnode =acpi_parse_string_ref (fwnode, obj->string.pointer); +if (IS_ERR (ref_fwnode)) +return PTR_ERR (ref_fwnode); + + args->fwnode = ref_fwnode; + args->nargs =0 ; +return 0 ;case ACPI_TYPE_PACKAGE :/* * If it is not a single reference, then it is a package of -* references followed by number of ints as follows: +* references, followed by number of ints as follows: * * Package () { REF, INT, REF, INT, INT } * -* The index argument is then used to determine which reference -* the caller wants (along with the arguments). +* Here, REF may be either a local reference or a string. The +* index argument is then used to determine which reference the +* caller wants (along with the arguments). */ break ;default :
@@ -942,7 +1001,26 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, ret =acpi_get_ref_args (idx == index ? args :NULL ,acpi_fwnode_handle (device), - &element, end, num_args); + &element, end, num_args, true); +if (ret <0 ) +return ret; + +if (idx == index) +return 0 ; + +break ; +case ACPI_TYPE_STRING : + ref_fwnode = +acpi_parse_string_ref (fwnode, + element->string.pointer); +if (IS_ERR (ref_fwnode)) +return PTR_ERR (ref_fwnode); + + element++; + + ret =acpi_get_ref_args (idx == index ? args :NULL , + ref_fwnode, &element, end, + num_args, false);if (ret <0 )return ret;
Signature · 1 line
2.30.2
Sakari Ailus
reviewerPATCH v4 2/8 ACPI: property: Parse _CRS CSI-2 descriptor
In reply to Sakari AilusParse newly added ACPI _CRS CSI-2 descriptor for CSI-2 and camera configuration. For now, only figure out where the descriptor is present in order to allow adding information from it to related devices.
--- drivers/acpi/Makefile | 2 +- drivers/acpi/internal.h | 7 + drivers/acpi/mipi.c | 358 ++++++++++++++++++++++++++++++++++++++++ drivers/acpi/scan.c | 16 +- include/acpi/acpi_bus.h | 11 ++ 5 files changed, 389 insertions(+), 5 deletions(-) create mode 100644 drivers/acpi/mipi.c
drivers/acpi/Makefile +1 -1
@@ -37,7 +37,7 @@ acpi-$(CONFIG_ACPI_SLEEP) += proc.o # ACPI Bus and Device Drivers # acpi-y += bus.o glue.o -acpi-y += scan.o +acpi-y += scan.o mipi.o acpi-y += resource.o acpi-y += acpi_processor.o acpi-y += processor_core.o
drivers/acpi/internal.h +7 -0
@@ -282,4 +282,11 @@ void acpi_init_lpit(void);static inline void acpi_init_lpit (void ) { }#endif +/*-------------------------------------------------------------------------- +ACPI and MIPI DisCo for Imaging conversion +-------------------------------------------------------------------------- */ + +void acpi_crs_csi2_swnodes_del_free (void ); +void acpi_bus_scan_crs_csi2 (acpi_handle handle); +#endif /* _ACPI_INTERNAL_H_ */
drivers/acpi/mipi.c new file +358 -0
358 lines not on this page · raw message
drivers/acpi/scan.c +12 -4
@@ -2423,9 +2423,12 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_next_consumer_dev);int acpi_bus_scan (acpi_handle handle) {struct acpi_device *device =NULL ; +int ret =0 ; acpi_bus_scan_second_pass = false; +acpi_bus_scan_crs_csi2 (handle); +/* Pass 1: Avoid enumerating devices with missing dependencies. */ if (ACPI_SUCCESS (acpi_bus_check_add (handle, true, &device)))
@@ -2433,13 +2436,15 @@ int acpi_bus_scan(acpi_handle handle) acpi_bus_check_add_1,NULL ,NULL , (void **)&device); -if (!device) -return -ENODEV ; +if (!device) { + ret = -ENODEV ; + goto out_release; + }acpi_bus_attach (device, (void *)true);if (!acpi_bus_scan_second_pass) -return 0 ; + goto out_release;/* Pass 2: Enumerate all of the remaining devices. */
@@ -2452,7 +2457,10 @@ int acpi_bus_scan(acpi_handle handle)acpi_bus_attach (device,NULL ); -return 0 ; +out_release: +acpi_crs_csi2_swnodes_del_free (); + +return ret; }EXPORT_SYMBOL (acpi_bus_scan);
include/acpi/acpi_bus.h +11 -0
@@ -360,6 +360,17 @@ struct acpi_device_data {struct acpi_gpio_mapping ; +struct acpi_device_software_node_port { +unsigned int port_nr; +}; + +struct acpi_device_software_nodes { +struct acpi_device_software_node_port *ports; +struct software_node *nodes; +const struct software_node **nodeptrs; +unsigned int num_ports; +}; +/* Device */ struct acpi_device {u32 pld_crc;
Signature · 1 line
2.30.2
Andy Shevchenko
reviewerRe: [PATCH v4 2/8] ACPI: property: Parse _CRS CSI-2 descriptor
Quoted 3 lines · Sakari Ailus
Parse newly added ACPI
_CRSCSI-2 descriptor for CSI-2 and camera configuration. For now, only figure out where the descriptor is present in order to allow adding information from it to related devices.
Nit-picks below that may be ignored. Up to you, guys.
...
Quoted 1 line
+#define
NO_CSI2_PORT(~1U)
A bit unclear why this value. Is it bitfield? Then GENMASK() would be better. Is it a plain value with a type limit? Then (UINT_MAX - 1) probably the best.
...
drivers/acpi/mipi.c line 239
Quoted 2 lines
drivers/acpi/mipi.c new file +2
-0+ ads->nodeptrs = (void *)(ads->nodes + + ports_count *2 +1 );
Now this fits one line.
...
drivers/acpi/mipi.c line 312
Quoted 7 lines
drivers/acpi/mipi.c new file +7
-0+ handle_refs =kcalloc (csi2_all.handle_count +1 ,sizeof (*handle_refs), +GFP_KERNEL ); +if (!handle_refs) { +acpi_handle_debug (handle,"no memory for %zu handle refs\n" , + csi2_all.handle_count +1 ); +return ; + }
In a code above you used "1 + foo" approach if I'm not mistaken. Why here is the difference?
...
In some code comments which I removed before remarking you forgot the grammatical period.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sakari Ailus
reviewerRe: [PATCH v4 2/8] ACPI: property: Parse _CRS CSI-2 descriptor
Hi Andy,
Thanks for the review.
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Sakari Ailus
Parse newly added ACPI
_CRSCSI-2 descriptor for CSI-2 and camera configuration. For now, only figure out where the descriptor is present in order to allow adding information from it to related devices.
Quoted 8 lines
Nit-picks below that may be ignored. Up to you, guys.
...
Quoted 1 line
+#define
NO_CSI2_PORT(~1U)A bit unclear why this value. Is it bitfield? Then
GENMASK()would be better. Is it a plain value with a type limit? Then (UINT_MAX- 1) probably the best.
This value is used to signify that a port node isn't yet allocated for a CSI-2 port. I can change this to UINT_MAX - 1.
Quoted 7 lines
...
drivers/acpi/mipi.c line 239
Quoted 2 lines
drivers/acpi/mipi.c new file +2
-0+ ads->nodeptrs = (void *)(ads->nodes + + ports_count *2 +1 );Now this fits one line.
Yes.
Quoted 13 lines
...
drivers/acpi/mipi.c line 312
Quoted 7 lines
drivers/acpi/mipi.c new file +7
-0+ handle_refs =kcalloc (csi2_all.handle_count +1 ,sizeof (*handle_refs), +GFP_KERNEL ); +if (!handle_refs) { +acpi_handle_debug (handle,"no memory for %zu handle refs\n" , + csi2_all.handle_count +1 ); +return ; + }In a code above you used "1 + foo" approach if I'm not mistaken. Why here is the difference?
The last entry is a guardian (NULL handle). 1 + number of lanes is used where the first lane is the clock lane.
Quoted 5 lines
...
In some code comments which I removed before remarking you forgot the grammatical period.
Some comments aren't proper sentences. I'll see which could be improved by adding a period.
Signature · 3 lines
Regards, Sakari Ailus
kernel test robot
build botRe: [PATCH v4 2/8] ACPI: property: Parse _CRS CSI-2 descriptor
In reply to Sakari AilusI love your patch! Perhaps something to improve:
Hi Sakari,
I love your patch! Perhaps something to improve:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on sailus-media-tree/streams linus/master v6.2-rc7 next-20230208] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sakari-Ailus/ACPI-property-Parse-data-node-string-references-in-properties/20230208-233112 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next patch link: https://lore.kernel.org/r/20230208152807.3064242-3-sakari.ailus%40linux.intel.com patch subject: [PATCH v4 2/8] ACPI: property: Parse _CRS CSI-2 descriptor config: x86_64-rhel-8.3-kselftests (https://download.01.org/0day-ci/archive/20230209/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/d78f47f2d5051c50bdcea131da1779ec0fc8e266
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sakari-Ailus/ACPI-property-Parse-data-node-string-references-in-properties/20230208-233112 git checkout d78f47f2d5051c50bdcea131da1779ec0fc8e266
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/acpi/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]
All warnings (new ones prefixed by >>):
>> drivers/acpi/mipi.c:205:6: warning: no previous prototype for 'acpi_crs_csi2_alloc_fill_swnodes' [-Wmissing-prototypes]
205 | void acpi_crs_csi2_alloc_fill_swnodes(size_t ports_count, acpi_handle handle)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/acpi_crs_csi2_alloc_fill_swnodes +205 drivers/acpi/mipi.c
200
201 /*
202 * Allocate memory and set up software nodes for an ACPI device with given
203 * number of CSI-2 ports.
204 */
> 205 void acpi_crs_csi2_alloc_fill_swnodes(size_t ports_count, acpi_handle handle)
206 {
207 struct acpi_device_software_nodes *ads;
208 struct crs_csi2_swnodes *swnodes;
209 size_t alloc_size;
210 unsigned int i;
211 bool overflow;
212 void *end;
213
214 /*
215 * Allocate memory for ports, node pointers (number of nodes +
216 * 1 (guardian), nodes (root + number of ports * 2 (for for
217 * every port there is an endpoint)).
218 */
219 overflow = check_mul_overflow(sizeof(*ads->ports) +
220 sizeof(*ads->nodes) * 2 +
221 sizeof(*ads->nodeptrs) * 2,
222 ports_count, &alloc_size); 223 overflow = overflow ||
224 check_add_overflow(sizeof(*ads) + sizeof(*ads->nodes) +
225 sizeof(*ads->nodeptrs) * 2,
226 alloc_size, &alloc_size);
227 if (overflow) {
228 acpi_handle_warn(handle,
229 "too many _CRS CSI2 resource handles (%zu)",
230 ports_count);
231 return;
232 }
233
234 swnodes = kzalloc(sizeof(*swnodes), GFP_KERNEL);
235 ads = kzalloc(alloc_size, GFP_KERNEL);
236 ads->ports = (void *)(ads + 1);
237 ads->nodes = (void *)(ads->ports + ports_count);
238 ads->nodeptrs = (void *)(ads->nodes +
239 ports_count * 2 + 1);
240 end = ads->nodeptrs + ports_count * 2 + 2;
241 if (!swnodes || !ads || WARN_ON((void *)ads + alloc_size != end)) {
242 kfree(swnodes);
243 kfree(ads);
244 acpi_handle_debug(handle,
245 "cannot allocate for %zu software nodes\n",
246 ports_count);
247 return;
248 }
249
250 ads->num_ports = ports_count;
251 for (i = 0; i < ports_count * 2 + 1; i++)
252 ads->nodeptrs[i] = &ads->nodes[i];
253 ads->nodeptrs[i] = NULL;
254 for (i = 0; i < ports_count; i++)
255 ads->ports[i].port_nr = NO_CSI2_PORT;
256 swnodes->handle = handle;
257 swnodes->ads = ads;
258 list_add(&swnodes->list, &crs_csi2_swnodes);
259 }
260
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Sakari Ailus
reviewerRe: [PATCH v4 2/8] ACPI: property: Parse _CRS CSI-2 descriptor
Quoted 2 lines · kernel test robot
Quoted 1 line
Quoted 1 line
drivers/acpi/mipi.c:205:6: warning: no previous prototype for 'acpi_crs_csi2_alloc_fill_swnodes' [-Wmissing-prototypes]205 | void
acpi_crs_csi2_alloc_fill_swnodes(size_t ports_count, acpi_handle handle)
I was wondering what wast the actual problem here as having no prototype isn't an issue really. The function should have been static, of course. I'll address this in v6, but waiting for other comments for now.
Signature · 1 line
Sakari Ailus
kernel test robot
build botRe: [PATCH v4 2/8] ACPI: property: Parse _CRS CSI-2 descriptor
In reply to Sakari AilusI love your patch! Perhaps something to improve:
Hi Sakari,
I love your patch! Perhaps something to improve:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on sailus-media-tree/streams linus/master v6.2-rc7 next-20230208] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sakari-Ailus/ACPI-property-Parse-data-node-string-references-in-properties/20230208-233112 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next patch link: https://lore.kernel.org/r/20230208152807.3064242-3-sakari.ailus%40linux.intel.com patch subject: [PATCH v4 2/8] ACPI: property: Parse _CRS CSI-2 descriptor config: x86_64-rhel-8.3-syz (https://download.01.org/0day-ci/archive/20230209/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/d78f47f2d5051c50bdcea131da1779ec0fc8e266
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sakari-Ailus/ACPI-property-Parse-data-node-string-references-in-properties/20230208-233112 git checkout d78f47f2d5051c50bdcea131da1779ec0fc8e266
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/acpi/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]
All warnings (new ones prefixed by >>):
>> drivers/acpi/mipi.c:205:6: warning: no previous prototype for 'acpi_crs_csi2_alloc_fill_swnodes' [-Wmissing-prototypes]
205 | void acpi_crs_csi2_alloc_fill_swnodes(size_t ports_count, acpi_handle handle)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/acpi_crs_csi2_alloc_fill_swnodes +205 drivers/acpi/mipi.c
200
201 /*
202 * Allocate memory and set up software nodes for an ACPI device with given
203 * number of CSI-2 ports.
204 */
> 205 void acpi_crs_csi2_alloc_fill_swnodes(size_t ports_count, acpi_handle handle)
206 {
207 struct acpi_device_software_nodes *ads;
208 struct crs_csi2_swnodes *swnodes;
209 size_t alloc_size;
210 unsigned int i;
211 bool overflow;
212 void *end;
213
214 /*
215 * Allocate memory for ports, node pointers (number of nodes +
216 * 1 (guardian), nodes (root + number of ports * 2 (for for
217 * every port there is an endpoint)).
218 */
219 overflow = check_mul_overflow(sizeof(*ads->ports) +
220 sizeof(*ads->nodes) * 2 +
221 sizeof(*ads->nodeptrs) * 2,
222 ports_count, &alloc_size); 223 overflow = overflow ||
224 check_add_overflow(sizeof(*ads) + sizeof(*ads->nodes) +
225 sizeof(*ads->nodeptrs) * 2,
226 alloc_size, &alloc_size);
227 if (overflow) {
228 acpi_handle_warn(handle,
229 "too many _CRS CSI2 resource handles (%zu)",
230 ports_count);
231 return;
232 }
233
234 swnodes = kzalloc(sizeof(*swnodes), GFP_KERNEL);
235 ads = kzalloc(alloc_size, GFP_KERNEL);
236 ads->ports = (void *)(ads + 1);
237 ads->nodes = (void *)(ads->ports + ports_count);
238 ads->nodeptrs = (void *)(ads->nodes +
239 ports_count * 2 + 1);
240 end = ads->nodeptrs + ports_count * 2 + 2;
241 if (!swnodes || !ads || WARN_ON((void *)ads + alloc_size != end)) {
242 kfree(swnodes);
243 kfree(ads);
244 acpi_handle_debug(handle,
245 "cannot allocate for %zu software nodes\n",
246 ports_count);
247 return;
248 }
249
250 ads->num_ports = ports_count;
251 for (i = 0; i < ports_count * 2 + 1; i++)
252 ads->nodeptrs[i] = &ads->nodes[i];
253 ads->nodeptrs[i] = NULL;
254 for (i = 0; i < ports_count; i++)
255 ads->ports[i].port_nr = NO_CSI2_PORT;
256 swnodes->handle = handle;
257 swnodes->ads = ads;
258 list_add(&swnodes->list, &crs_csi2_swnodes);
259 }
260
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Re: [PATCH v4 2/8] ACPI: property: Parse _CRS CSI-2 descriptor
Quoted 26 lines · kernel test robot
Hi Sakari,
I love your patch! Perhaps something to improve:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on sailus-media-tree/streams linus/master v6.2-rc7 next-20230208] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Sakari-Ailus/ACPI-property-Parse-data-node-string-references-in-properties/20230208-233112 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next patch link: https://lore.kernel.org/r/20230208152807.3064242-3-sakari.ailus%40linux.intel.com patch subject: [PATCH v4 2/8] ACPI: property: Parse _CRS CSI-2 descriptor config: x86_64-rhel-8.3-syz (https://download.01.org/0day-ci/archive/20230209/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/d78f47f2d5051c50bdcea131da1779ec0fc8e266
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sakari-Ailus/ACPI-property-Parse-data-node-string-references-in-properties/20230208-233112 git checkoutd78f47f2d5051c50bdcea131da1779ec0fc8e266
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bashdrivers/acpi/
Quoted 3 lines
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]
Sorry that the link is wrong, it should be
Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 76 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/acpi/mipi.c:205:6: warning: no previous prototype for 'acpi_crs_csi2_alloc_fill_swnodes' [-Wmissing-prototypes]205 | void
acpi_crs_csi2_alloc_fill_swnodes(size_t ports_count, acpi_handle handle)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~vim +/acpi_crs_csi2_alloc_fill_swnodes +205
drivers/acpi/mipi.c200 201 /* 202 * Allocate memory and set up software nodes for an ACPI device with given 203 * number of CSI-2 ports. 204 */Quoted 1 line
205 void
acpi_crs_csi2_alloc_fill_swnodes(size_t ports_count, acpi_handle handle)206 { 207 struct acpi_device_software_nodes *ads; 208 struct crs_csi2_swnodes *swnodes; 209 size_t alloc_size; 210 unsigned int i; 211 bool overflow; 212 void *end; 213 214 /* 215 * Allocate memory for ports, node pointers (number of nodes + 216 * 1 (guardian), nodes (root + number of ports * 2 (for for 217 * every port there is an endpoint)). 218 */ 219 overflow = check_mul_overflow(sizeof(*ads->ports) + 220 sizeof(*ads->nodes) * 2 + 221 sizeof(*ads->nodeptrs) * 2, 222 ports_count, &alloc_size); 223 overflow = overflow || 224 check_add_overflow(sizeof(*ads) + sizeof(*ads->nodes) + 225 sizeof(*ads->nodeptrs) * 2, 226 alloc_size, &alloc_size); 227 if (overflow) { 228 acpi_handle_warn(handle, 229 "too many _CRS CSI2 resource handles (%zu)", 230 ports_count); 231 return; 232 } 233 234 swnodes = kzalloc(sizeof(*swnodes), GFP_KERNEL); 235 ads = kzalloc(alloc_size, GFP_KERNEL); 236 ads->ports = (void *)(ads + 1); 237 ads->nodes = (void *)(ads->ports + ports_count); 238 ads->nodeptrs = (void *)(ads->nodes + 239 ports_count * 2 + 1); 240 end = ads->nodeptrs + ports_count * 2 + 2; 241 if (!swnodes || !ads || WARN_ON((void *)ads + alloc_size != end)) { 242 kfree(swnodes); 243 kfree(ads); 244 acpi_handle_debug(handle, 245 "cannot allocate for %zu software nodes\n", 246 ports_count); 247 return; 248 } 249 250 ads->num_ports = ports_count; 251 for (i = 0; i < ports_count * 2 + 1; i++) 252 ads->nodeptrs[i] = &ads->nodes[i]; 253 ads->nodeptrs[i] = NULL; 254 for (i = 0; i < ports_count; i++) 255 ads->ports[i].port_nr = NO_CSI2_PORT; 256 swnodes->handle = handle; 257 swnodes->ads = ads; 258 list_add(&swnodes->list, &crs_csi2_swnodes); 259 } 260Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Sakari Ailus
reviewerPATCH v4 3/8 device property: Add SOFTWARE_NODE() macro for defining software nodes
In reply to Sakari AilusAdd SOFTWARE_NODE() macro in order to make defining software nodes look nicer. This is analogous to different PROPERTY_ENTRY_*() macros for defining properties.
--- include/linux/property.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/linux/property.h +7 -0
@@ -477,6 +477,13 @@ struct software_node {const struct property_entry *properties; }; +#define SOFTWARE_NODE (_name_, _properties_, _parent_) \ + (struct software_node) { \ + .name = _name_, \ + .properties = _properties_, \ + .parent = _parent_, \ + } +bool is_software_node (const struct fwnode_handle *fwnode);const struct software_node *to_software_node (const struct fwnode_handle *fwnode);
Signature · 1 line
2.30.2
Sakari Ailus
reviewerPATCH v4 4/8 ACPI: property: Generate camera swnodes for ACPI and DisCo for Imaging
In reply to Sakari AilusGenerate software nodes for information parsed from ACPI _CRS for CSI-2 as well as MIPI DisCo for Imaging spec. The software nodes are compliant with existing ACPI or DT definitions and are parsed by relevant drivers without changes.
--- drivers/acpi/internal.h | 1 + drivers/acpi/mipi.c | 353 ++++++++++++++++++++++++++++++++++++++++ drivers/acpi/scan.c | 19 +++ include/acpi/acpi_bus.h | 70 ++++++++ 4 files changed, 443 insertions(+)
drivers/acpi/internal.h +1 -0
@@ -288,5 +288,6 @@ static inline void acpi_init_lpit(void) { }void acpi_crs_csi2_swnodes_del_free (void );void acpi_bus_scan_crs_csi2 (acpi_handle handle); +void acpi_init_swnodes (struct acpi_device *device);#endif /* _ACPI_INTERNAL_H_ */
drivers/acpi/mipi.c +353 -0
390 lines not on this page · raw message
drivers/acpi/scan.c +19 -0
@@ -449,10 +449,28 @@ static void acpi_free_power_resources_lists(struct acpi_device *device) } } +static void acpi_free_swnodes (struct acpi_device *device) +{ +struct acpi_device_software_nodes *ads = device->swnodes; +struct fwnode_handle *primary; + +if (!ads) +return ; + +software_node_unregister_node_group (ads->nodeptrs); + primary =acpi_fwnode_handle (device); + primary->secondary =NULL ; +kfree (ads->nodes[ACPI_DEVICE_SWNODE_ROOT ].name); +kfree (ads); + + device->swnodes =NULL ; +} +static void acpi_device_release (struct device *dev) {struct acpi_device *acpi_dev =to_acpi_device (dev); +acpi_free_swnodes (acpi_dev);acpi_free_properties (acpi_dev);acpi_free_pnp_ids (&acpi_dev->pnp);acpi_free_power_resources_lists (acpi_dev);
@@ -1771,6 +1789,7 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,acpi_device_get_busid (device);acpi_set_pnp_ids (handle, &device->pnp, type);acpi_init_properties (device); +acpi_init_swnodes (device);acpi_bus_get_flags (device); device->flags.match_driver = false; device->flags.initialized = true;
include/acpi/acpi_bus.h +70 -0
91 lines not on this page · raw message
Signature · 1 line
2.30.2
Andy Shevchenko
reviewerRe: [PATCH v4 4/8] ACPI: property: Generate camera swnodes for ACPI and DisCo for Imaging
Quoted 4 lines · Sakari Ailus
Generate software nodes for information parsed from ACPI
_CRSfor CSI-2 as well as MIPI DisCo for Imaging spec. The software nodes are compliant with existing ACPI or DT definitions and are parsed by relevant drivers without changes.
...
Quoted 17 lines
drivers/acpi/mipi.c +17
-0+ ret =fwnode_property_count_u8 (mipi_port_fwnode,"mipi-img-lane-polarities" ); +if (ret >0 ) { + unsigned int bytes = min_t(unsigned int, ret, sizeof(val)); + +fwnode_property_read_u8_array (mipi_port_fwnode, +"mipi-img-lane-polarities" , + val, bytes); + +/* Total number of lanes here is clock lane + data lanes */ +if (bytes *BITS_PER_TYPE (u8) >=1 + num_lanes) { +unsigned int i; + +/* Move polarity bits to the lane polarity u32 array */ +for (i =0 ; i <1 + num_lanes; i++) + port->lane_polarities[i] = + (bool )(val[i >>3 ] & (1 << (i &7 ))); +
drivers/acpi/mipi.c void acpi_bus_scan_crs_csi2(acpi_handle handle) · line 597
Quoted 10 lines
drivers/acpi/mipi.c +10
-0+ port->ep_props[NEXT_PROPERTY (*ep_prop_index,EP_LANE_POLARITIES )] = +PROPERTY_ENTRY_U32_ARRAY_LEN ("lane-polarities" , + port->lane_polarities, +1 + num_lanes); + }else { +acpi_handle_warn (acpi_device_handle (device), +"too few lane polarity bytes (%u)\n" , + bytes); + } + }
I still think this will be better with bitmap APIs in use, but I leave it to maintainers and you to decide.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sakari Ailus
reviewerPATCH v4 5/8 ACPI: property: Dig "rotation" property for devices with CSI2 _CRS
In reply to Sakari AilusDig "rotation" property value for devices with _CRS CSI2 resource descriptor. The value comes from _PLD (physical location of device) object, if it exists for the device.
This way camera sensor drivers that know the "rotation" property do not need to care about _PLD on ACPI.
--- drivers/acpi/mipi.c | 16 ++++++++++++++++ include/acpi/acpi_bus.h | 1 + 2 files changed, 17 insertions(+)
drivers/acpi/mipi.c +16 -0
@@ -667,16 +667,32 @@ static void init_port_csi2_remote(struct acpi_device *device,*/ void acpi_init_swnodes (struct acpi_device *device) { +struct fwnode_handle *fwnode =acpi_fwnode_handle (device);struct acpi_device_software_nodes *ads;struct acpi_buffer buffer = { .length =ACPI_ALLOCATE_BUFFER };struct fwnode_handle *primary; +struct acpi_pld_info *pld; +unsigned int prop_index =0 ;unsigned int i; +u32 val;int ret; device->swnodes = ads =crs_csi2_swnode_get (device->handle);if (!ads)return ; +/* +* Check if "rotation" property exists and if it doesn't but there's a +* _PLD object, then get the rotation value from there. +*/ +if (fwnode_property_read_u32 (fwnode,"rotation" , &val) && +ACPI_SUCCESS (acpi_get_physical_device_location (acpi_device_handle (device), + &pld))) { + ads->dev_props[NEXT_PROPERTY (prop_index,DEV_ROTATION )] = +PROPERTY_ENTRY_U32 ("rotation" , pld->rotation *45U ); +kfree (pld); + } +if (ACPI_FAILURE (acpi_get_name (device->handle,ACPI_FULL_PATHNAME , &buffer))) {acpi_handle_warn (acpi_device_handle (device),"cannot get path name\n" );return ;
include/acpi/acpi_bus.h +1 -0
@@ -361,6 +361,7 @@ struct acpi_device_data {struct acpi_gpio_mapping ;enum acpi_device_swnode_dev_props { +ACPI_DEVICE_SWNODE_DEV_ROTATION ,ACPI_DEVICE_SWNODE_DEV_NUM_OF ,ACPI_DEVICE_SWNODE_DEV_NUM_ENTRIES };
Signature · 1 line
2.30.2
Andy Shevchenko
reviewerRe: [PATCH v4 5/8] ACPI: property: Dig "rotation" property for devices with CSI2 _CRS
Quoted 6 lines · Sakari Ailus
Dig "rotation" property value for devices with
_CRSCSI2 resource descriptor. The value comes from_PLD(physical location of device) object, if it exists for the device.This way camera sensor drivers that know the "rotation" property do not need to care about
_PLDon ACPI.
...
drivers/acpi/mipi.c static void init_port_csi2_remote(struct acpi_device *device,
Quoted 11 lines
drivers/acpi/mipi.c +10
-0+/* +* Check if "rotation" property exists and if it doesn't but there's a +* _PLD object, then get the rotation value from there. +*/ +if (fwnode_property_read_u32 (fwnode,"rotation" , &val) && +ACPI_SUCCESS (acpi_get_physical_device_location (acpi_device_handle (device), + &pld))) { +if (fwnode_property_read_u32 (fwnode,"rotation" , &val) && +ACPI_SUCCESS (acpi_get_physical_device_location (acpi_device_handle (device), + &pld))) {
Wouldn't be a bit better to use temporary variables for this?
ret = fwnode_property_read_u32(fwnode, "rotation", &val);
if (ret) {
acpi_handle handle = acpi_device_handle(device);
acpi_status status;
status = acpi_get_physical_device_location(handle, &pld);
if (ACPI_SUCCESS(status)) {
...
}
}?
Quoted 4 lines
drivers/acpi/mipi.c +4
-0+ ads->dev_props[NEXT_PROPERTY (prop_index,DEV_ROTATION )] = +PROPERTY_ENTRY_U32 ("rotation" , pld->rotation *45U ); +kfree (pld); + }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sakari Ailus
reviewerRe: [PATCH v4 5/8] ACPI: property: Dig "rotation" property for devices with CSI2 _CRS
Hi Andy,
Quoted 35 lines · Andy Shevchenko
Quoted 6 lines · Sakari Ailus
Dig "rotation" property value for devices with
_CRSCSI2 resource descriptor. The value comes from_PLD(physical location of device) object, if it exists for the device.This way camera sensor drivers that know the "rotation" property do not need to care about
_PLDon ACPI....
drivers/acpi/mipi.c static void init_port_csi2_remote(struct acpi_device *device,
Quoted 11 lines
drivers/acpi/mipi.c +10
-0+/* +* Check if "rotation" property exists and if it doesn't but there's a +* _PLD object, then get the rotation value from there. +*/ +if (fwnode_property_read_u32 (fwnode,"rotation" , &val) && +ACPI_SUCCESS (acpi_get_physical_device_location (acpi_device_handle (device), + &pld))) { +if (fwnode_property_read_u32 (fwnode,"rotation" , &val) && +ACPI_SUCCESS (acpi_get_physical_device_location (acpi_device_handle (device), + &pld))) {Wouldn't be a bit better to use temporary variables for this?
ret = fwnode_property_read_u32(fwnode, "rotation", &val); if (ret) { acpi_handle handle = acpi_device_handle(device); acpi_status status; status = acpi_get_physical_device_location(handle, &pld); if (ACPI_SUCCESS(status)) { ... } }
Quoted 1 line
?
It seems that val isn't used. So I'll use fwnode_property_present() which I think is fine to test in if () directly.
Signature · 1 line
Sakari Ailus
Sakari Ailus
reviewerPATCH v4 6/8 ACPI: property: Rename parsed MIPI DisCo for Imaging properties
In reply to Sakari AilusMIPI DisCo for Imaging defines properties for sensor-adjacent devices such as EEPROM, LED flash or lens VCM as either device or sub-node references. This is compliant with existing DT definitions apart from property names.
Rename parsed MIPI-defined properties so drivers will have a unified view of them as defined in DT and already parsed by drivers. This can be done in-place as the MIPI-defined property strings are always longer than the DT one. This also results in loss of constness in parser function arguments.
Individual bindings to devices could define the references differently between MIPI DisCo for Imaging and DT, in terms of device or sub-node references. This will still need to be handled in the drivers themselves.
--- drivers/acpi/internal.h | 1 + drivers/acpi/mipi.c | 37 +++++++++++++++++++++++++++++++++++++ drivers/acpi/property.c | 22 ++++++++++++---------- 3 files changed, 50 insertions(+), 10 deletions(-)
drivers/acpi/internal.h +1 -0
@@ -289,5 +289,6 @@ static inline void acpi_init_lpit(void) { }void acpi_crs_csi2_swnodes_del_free (void );void acpi_bus_scan_crs_csi2 (acpi_handle handle);void acpi_init_swnodes (struct acpi_device *device); +void acpi_properties_prepare_mipi (union acpi_object *elements);#endif /* _ACPI_INTERNAL_H_ */
drivers/acpi/mipi.c +37 -0
@@ -725,3 +725,40 @@ void acpi_init_swnodes(struct acpi_device *device) primary =acpi_fwnode_handle (device); primary->secondary =software_node_fwnode (ads->nodes); } + +static const struct mipi_disco_prop { +const char *mipi_prop; +const char *dt_prop; +} mipi_disco_props[] = { + {"mipi-img-lens-focus" ,"lens-focus" }, + {"mipi-img-flash-leds" ,"flash-leds" }, + {"mipi-img-clock-frequency" ,"clock-frequency" }, + {"mipi-img-led-max-current" ,"led-max-microamp" }, + {"mipi-img-flash-max-current" ,"flash-max-microamp" }, + {"mipi-img-flash-max-timeout" ,"flash-max-timeout-us" }, +}; + +/** +* acpi_properties_prepare_mipi - Rename MIPI properties as commin DT ones +* +* @elements: ACPI object containing _DSD properties for a device node +* +* Renames MIPI-defined properties as common DT ones. The pre-requisite is that +* the names of all such MIPI properties are no longer than the corresponding DT +* ones. +*/ +void acpi_properties_prepare_mipi (union acpi_object *elements) +{ +unsigned int i; + +/* Replace MIPI DisCo for Imaging property names with DT equivalents. */ +for (i =0 ; i <ARRAY_SIZE (mipi_disco_props); i++) { +if (!strcmp (mipi_disco_props[i].mipi_prop, + elements[0 ].string.pointer)) { +WARN_ON (strscpy (elements[0 ].string.pointer, + mipi_disco_props[i].dt_prop, + elements[0 ].string.length) <0 ); +break ; + } + } +}
drivers/acpi/property.c +12 -10
@@ -124,7 +124,7 @@ static bool acpi_nondev_subnode_extract(union acpi_object *desc, }static bool acpi_nondev_subnode_data_ok (acpi_handle handle, -const union acpi_object *link, +union acpi_object *link,struct list_head *list,struct fwnode_handle *parent) {
@@ -145,7 +145,7 @@ static bool acpi_nondev_subnode_data_ok(acpi_handle handle, }static bool acpi_nondev_subnode_ok (acpi_handle scope, -const union acpi_object *link, +union acpi_object *link,struct list_head *list,struct fwnode_handle *parent) {
@@ -276,22 +276,24 @@ static bool acpi_property_value_ok(const union acpi_object *value)return false; } -static bool acpi_properties_format_valid (const union acpi_object *properties) +static bool acpi_properties_prepare (union acpi_object *properties) { -int i; +unsigned int i;for (i =0 ; i < properties->package.count; i++) { -const union acpi_object *property; +union acpi_object *property = &properties->package.elements[i]; +union acpi_object *elements = property->package.elements; - property = &properties->package.elements[i];/* * Only two elements allowed, the first one must be a string and * the second one has to satisfy certain conditions. */ -if (property->package.count !=2 - || property->package.elements[0 ].type !=ACPI_TYPE_STRING - || !acpi_property_value_ok (&property->package.elements[1 ])) +if (property->package.count !=2 || + elements[0 ].type !=ACPI_TYPE_STRING || + !acpi_property_value_ok (&elements[1 ]))return false; + +acpi_properties_prepare_mipi (elements); }return true; }
@@ -523,7 +525,7 @@ static bool acpi_extract_properties(acpi_handle scope, union acpi_object *desc,* We found the matching GUID. Now validate the format of the * package immediately following it. */ -if (!acpi_properties_format_valid (properties)) +if (!acpi_properties_prepare (properties))continue ; acpi_data_add_props(data, (const guid_t *)guid->buffer.pointer,
Signature · 1 line
2.30.2
Andy Shevchenko
reviewerRe: [PATCH v4 6/8] ACPI: property: Rename parsed MIPI DisCo for Imaging properties
Quoted 13 lines · Sakari Ailus
MIPI DisCo for Imaging defines properties for sensor-adjacent devices such as EEPROM, LED flash or lens VCM as either device or sub-node references. This is compliant with existing DT definitions apart from property names.
Rename parsed MIPI-defined properties so drivers will have a unified view of them as defined in DT and already parsed by drivers. This can be done in-place as the MIPI-defined property strings are always longer than the DT one. This also results in loss of constness in parser function arguments.
Individual bindings to devices could define the references differently between MIPI DisCo for Imaging and DT, in terms of device or sub-node references. This will still need to be handled in the drivers themselves.
...
drivers/acpi/mipi.c void acpi_init_swnodes(struct acpi_device *device) · line 757
Quoted 8 lines
drivers/acpi/mipi.c +8
-0+void acpi_properties_prepare_mipi (union acpi_object *elements) +{ +unsigned int i; + +/* Replace MIPI DisCo for Imaging property names with DT equivalents. */ +for (i =0 ; i <ARRAY_SIZE (mipi_disco_props); i++) { +if (!strcmp (mipi_disco_props[i].mipi_prop, + elements[0 ].string.pointer)) {
/* const ? */ char *e0 = elements[0].string.pointer;
...
if (!strcmp(mipi_disco_props[i].mipi_prop, e0)) {drivers/acpi/mipi.c void acpi_init_swnodes(struct acpi_device *device) · line 760
Quoted 3 lines
drivers/acpi/mipi.c +3
-0+WARN_ON (strscpy (elements[0 ].string.pointer, + mipi_disco_props[i].dt_prop, + elements[0 ].string.length) <0 );
WARN_ON(strscpy(e0, mipi_disco_props[i].dt_prop, elements[0].string.pointer) < 0);
?
Quoted 4 lines
drivers/acpi/mipi.c +4
-0+break ; + } + } +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sakari Ailus
reviewerRe: [PATCH v4 6/8] ACPI: property: Rename parsed MIPI DisCo for Imaging properties
Quoted 17 lines · Andy Shevchenko
Quoted 13 lines · Sakari Ailus
MIPI DisCo for Imaging defines properties for sensor-adjacent devices such as EEPROM, LED flash or lens VCM as either device or sub-node references. This is compliant with existing DT definitions apart from property names.
Rename parsed MIPI-defined properties so drivers will have a unified view of them as defined in DT and already parsed by drivers. This can be done in-place as the MIPI-defined property strings are always longer than the DT one. This also results in loss of constness in parser function arguments.
Individual bindings to devices could define the references differently between MIPI DisCo for Imaging and DT, in terms of device or sub-node references. This will still need to be handled in the drivers themselves.
...
Quoted 10 lines
drivers/acpi/mipi.c void acpi_init_swnodes(struct acpi_device *device) · line 757
Quoted 8 lines
drivers/acpi/mipi.c +8
-0+void acpi_properties_prepare_mipi (union acpi_object *elements) +{ +unsigned int i; + +/* Replace MIPI DisCo for Imaging property names with DT equivalents. */ +for (i =0 ; i <ARRAY_SIZE (mipi_disco_props); i++) { +if (!strcmp (mipi_disco_props[i].mipi_prop, + elements[0 ].string.pointer)) {/* const ? */ char *e0 = elements[0].string.pointer;
Yes, and can be placed outside the loop.
Quoted 17 lines
... if (!strcmp(mipi_disco_props[i].mipi_prop, e0)) {drivers/acpi/mipi.c void acpi_init_swnodes(struct acpi_device *device) · line 760
Quoted 3 lines
drivers/acpi/mipi.c +3
-0+WARN_ON (strscpy (elements[0 ].string.pointer, + mipi_disco_props[i].dt_prop, + elements[0 ].string.length) <0 );WARN_ON(strscpy(e0, mipi_disco_props[i].dt_prop, elements[0].string.pointer) < 0);?
Quoted 4 lines
drivers/acpi/mipi.c +4
-0+break ; + } + } +}
Signature · 1 line
Sakari Ailus
Sakari Ailus
reviewerPATCH v4 7/8 ACPI: property: Skip MIPI property table without "mipi-img" prefix
In reply to Sakari AilusFor all _DSD properties, skip going through the MIPI DisCo for Imaging property name substitution table if the property doesn't have "mipi-img-" prefix.
--- drivers/acpi/mipi.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/acpi/mipi.c +5 -0
@@ -726,6 +726,8 @@ void acpi_init_swnodes(struct acpi_device *device) primary->secondary =software_node_fwnode (ads->nodes); } +#define MIPI_IMG_PREFIX "mipi-img-" + static const struct mipi_disco_prop { const char *mipi_prop; const char *dt_prop;
@@ -751,6 +753,9 @@ void acpi_properties_prepare_mipi(union acpi_object *elements) { unsigned int i; + if (!str_has_prefix(elements[0].string.pointer, MIPI_IMG_PREFIX)) + return; + /* Replace MIPI DisCo for Imaging property names with DT equivalents. */ for (i = 0; i < ARRAY_SIZE(mipi_disco_props); i++) { if (!strcmp(mipi_disco_props[i].mipi_prop,
Signature · 1 line
2.30.2
Sakari Ailus
reviewerPATCH v4 8/8 ACPI: property: Document _CRS CSI-2 and DisCo for Imaging support
In reply to Sakari AilusDocument how ACPI _CRS CSI-2 and DisCo for Imaging works. It's non-trivial so such documentation can be useful.
--- drivers/acpi/mipi.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
drivers/acpi/mipi.c +37 -0
@@ -3,6 +3,43 @@* MIPI DisCo for Imaging support. * * Copyright (C) 2023 Intel Corporation +* +* _CRS CSI-2 descriptors, as defined starting from ACPI 6.4 [1], contain +* information on cross-device CSI-2 bus configuration. The descriptors are +* located under transmitter devices, and the receiver devices have no direct +* way to access them even if the information in these descriptors is equally +* important for receivers. This information is amended with MIPI DisCo for +* Imaging [2] specification that defines _DSD data nodes and properties. +* +* The support for these is based on two-fold approach, firstly renaming +* properties where semantics matches and secondly gathering information to +* generate properties using information gathered from various sources. The +* former is trivial (see acpi_properties_prepare_mipi() at the end of the +* file) whereas the latter requires a more elaborate explanation. +* +* acpi_bus_scan_crs_csi2() scans an ACPI bus for devices with _CRS CSI-2 +* descriptors and stores them to a linked list. This is done as traversing just +* this list is much smaller task than the entire DSDT. This list is then used +* to figure out how much memory is needed for swnodes related to a given ACPI +* device (handle). Further on, the same function sets the property values for +* the properties the values of which are obtained from the _CRS CSI-2 +* descriptor. The information is stored into another list where the information +* can be looked up based on device's acpi_handle as the struct acpi_device +* isn't available yet at this point (and could not, as cross-device references +* need to be set up before the devices are available for drivers to probe). +* +* For each struct acpi_device, acpi_init_swnodes() further obtains information +* required to find out the values for the rest of the properties needed by +* drivers. This includes all port and endpoint properties as the node +* structures used by DT graphs and DisCo for Imaging are different. Finally the +* function registers software nodes for the device and sets the secondary +* pointer for the ACPI device's fwnode. +* +* Access to data the structures is serialised using acpi_scan_lock in scan.c. +* +* [1] https://uefi.org/sites/default/files/resources/ACPI_Spec_6_4_Jan22.pdf +* +* [2] https://www.mipi.org/specifications/mipi-disco-imaging */ #include <linux/acpi.h>
Signature · 1 line
2.30.2