Support qcom pinctrl protected pins
Subsystems (6)
v3 cover Support qcom pinctrl protected pins
This patchset proposes a solution to describing the valid pins for a pin controller in a generic way so that qcom platforms can expose the pins that are really available.
Typically, this has been done by having drivers and firmware descriptions only use pins they know they have access to, and that still works now because we no longer read the pin direction at boot. But there are still some userspace drivers and debugfs facilities that don't know what pins are available and attempt to read everything they can. On qcom platforms, this may lead to a system hang, which isn't very nice behavior, even if root is the only user that can trigger it.
The proposal is to describe the valid pins and then not allow things to cause problems by using the invalid pins. Obviously, the firmware may mess this up, so this is mostly a nice to have feature or a safety net so that things don't blow up easily.
Changes from v2:
* Renamed binding to 'gpio-reserved-ranges'
* Reworked gpiolib patch to not use irqdomains
* Update qcom driver patch to use new valid_mask field
Changes from v1:
* Pushed into gpiolib-of core under irq valid line logic
* Fixed up qcom driver patch to free stuff properly and remove custom code
* Dropped export patch as it got picked up
* Renamed binding to 'reserved-gpio-ranges'
Stephen Boyd (3):
dt-bindings: gpio: Add a gpio-reserved-ranges property
gpiolib: Support 'gpio-reserved-ranges' property
pinctrl: qcom: Don't allow protected pins to be requested
.../devicetree/bindings/gpio/gpio.txt | 7 +- drivers/gpio/gpiolib-of.c | 24 +++++++ drivers/gpio/gpiolib.c | 50 ++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.c | 69 +++++++++++++++++-- include/linux/gpio/driver.h | 16 +++++ 5 files changed, 159 insertions(+), 7 deletions(-)
Signature · 1 line
Sent by a computer through tubes
PATCH v3 1/3 dt-bindings: gpio: Add a gpio-reserved-ranges property
From: Stephen Boyd <[email protected]>
Some qcom platforms make some GPIOs or pins unavailable for use by non-secure operating systems, and thus reading or writing the registers for those pins will cause access control issues. Introduce a DT property to describe the set of GPIOs that are available for use so that higher level OSes are able to know what pins to avoid reading/writing.
--- Documentation/devicetree/bindings/gpio/gpio.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/gpio/gpio.txt +4 -3
@@ -151,9 +151,9 @@ in a lot of designs, some using all 32 bits, some using 18 and some using first 18 GPIOs, at local offset 0 .. 17, are in use. If these GPIOs do not happen to be the first N GPIOs at offset 0...N-1, an -additional bitmask is needed to specify which GPIOs are actually in use, -and which are dummies. The bindings for this case has not yet been -specified, but should be specified if/when such hardware appears. +additional set of tuples is needed to specify which GPIOs are unusable, with +the gpio-reserved-ranges binding. This property indicates the start and size +of the GPIOs that can't be used. Optionally, a GPIO controller may have a "gpio-line-names" property. This is an array of strings defining the names of the GPIO lines going out of the
@@ -178,6 +178,7 @@ gpio-controller at 00000000 { gpio-controller; #gpio-cells = <2>; ngpios = <18>; + gpio-reserved-ranges = <0 4>, <12 2>; gpio-line-names = "MMC-CD", "MMC-WP", "VDD eth", "RST eth", "LED R", "LED G", "LED B", "Col A", "Col B", "Col C", "Col D", "Row A", "Row B", "Row C", "Row D", "NMI button",
Signature · 1 line
Sent by a computer through tubes
PATCH v3 2/3 gpiolib: Support 'gpio-reserved-ranges' property
In reply to Stephen BoydFrom: Stephen Boyd <[email protected]>
Some qcom platforms make some GPIOs or pins unavailable for use by non-secure operating systems, and thus reading or writing the registers for those pins will cause access control issues. Add support for a DT property to describe the set of GPIOs that are available for use so that higher level OSes are able to know what pins to avoid reading/writing. Non-DT platforms can add support by directly updating the chip->valid_mask.
--- drivers/gpio/gpiolib-of.c | 24 ++++++++++++++++++ drivers/gpio/gpiolib.c | 50 +++++++++++++++++++++++++++++++++++++ include/linux/gpio/driver.h | 16 ++++++++++++ 3 files changed, 90 insertions(+)
drivers/gpio/gpiolib-of.c +24 -0
@@ -511,6 +511,28 @@ void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc) }EXPORT_SYMBOL (of_mm_gpiochip_remove); +static void of_gpiochip_init_valid_mask (struct gpio_chip *chip) +{ +int len, i; +u32 start, count; +struct device_node *np = chip->of_node; + + len =of_property_count_u32_elems (np,"gpio-reserved-ranges" ); +if (len <0 || len %2 !=0 ) +return ; + +for (i =0 ; i < len; i +=2 ) { +of_property_read_u32_index (np,"gpio-reserved-ranges" , + i, &start); +of_property_read_u32_index (np,"gpio-reserved-ranges" , + i +1 , &count); +if (start >= chip->ngpio || start + count >= chip->ngpio) +continue ; + +bitmap_clear (chip->valid_mask, start, count); + } +}; +#ifdef CONFIG_PINCTRL static int of_gpiochip_add_pin_range (struct gpio_chip *chip) {
@@ -615,6 +637,8 @@ int of_gpiochip_add(struct gpio_chip *chip)if (chip->of_gpio_n_cells >MAX_PHANDLE_ARGS )return -EINVAL ; +of_gpiochip_init_valid_mask (chip); + status =of_gpiochip_add_pin_range (chip);if (status)return status;
drivers/gpio/gpiolib.c +50 -0
80 lines not on this page · raw message
include/linux/gpio/driver.h +16 -0
@@ -288,6 +288,21 @@ struct gpio_chip {struct gpio_irq_chip irq;#endif +/** +* @need_valid_mask: +* +* If set core allocates @valid_mask with all bits set to one. +*/ +bool need_valid_mask; + +/** +* @valid_mask: +* +* If not %NULL holds bitmask of GPIOs which are valid to be used +* from the chip. +*/ +unsigned long *valid_mask; +#if defined(CONFIG_OF_GPIO )/* * If CONFIG_OF is enabled, then all GPIO controllers described in the
@@ -384,6 +399,7 @@ bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset);/* Sleep persistence inquiry for drivers */ bool gpiochip_line_is_persistent (struct gpio_chip *chip,unsigned int offset); +bool gpiochip_line_is_valid (const struct gpio_chip *chip,unsigned int offset);/* get driver data */ void *gpiochip_get_data (struct gpio_chip *chip);
Signature · 1 line
Sent by a computer through tubes
PATCH v3 3/3 pinctrl: qcom: Don't allow protected pins to be requested
In reply to Stephen BoydFrom: Stephen Boyd <[email protected]>
Some qcom platforms make some GPIOs or pins unavailable for use by non-secure operating systems, and thus reading or writing the registers for those pins will cause access control issues and reset the device. With a DT/ACPI property to describe the set of pins that are available for use, parse the available pins and set the irq valid bits for gpiolib to know what to consider 'valid'. This should avoid any issues with gpiolib. Furthermore, implement the pinmux_ops::request function so that pinmux can also make sure to not use pins that are unavailable.
--- drivers/pinctrl/qcom/pinctrl-msm.c | 69 ++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-)
drivers/pinctrl/qcom/pinctrl-msm.c +65 -4
@@ -105,6 +105,17 @@ static const struct pinctrl_ops msm_pinctrl_ops = { .dt_free_map = pinctrl_utils_free_map, }; +static int msm_pinmux_request (struct pinctrl_dev *pctldev,unsigned offset) +{ +struct msm_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); +struct gpio_chip *chip = &pctrl->chip; + +if (gpiochip_line_is_valid (chip, offset)) +return 0 ; + +return -EINVAL ; +} +static int msm_get_functions_count (struct pinctrl_dev *pctldev) {struct msm_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev);
@@ -166,6 +177,7 @@ static int msm_pinmux_set_mux(struct pinctrl_dev *pctldev, }static const struct pinmux_ops msm_pinmux_ops = { + .request = msm_pinmux_request, .get_functions_count = msm_get_functions_count, .get_function_name = msm_get_function_name, .get_function_groups = msm_get_function_groups,
@@ -506,6 +518,9 @@ static void msm_gpio_dbg_show_one(struct seq_file *s, "pull up" }; +if (!gpiochip_line_is_valid (chip, offset)) +return ; + g = &pctrl->soc->groups[offset]; ctl_reg =readl (pctrl->regs + g->ctl_reg);
@@ -516,7 +531,7 @@ static void msm_gpio_dbg_show_one(struct seq_file *s,seq_printf (s," %-8s: %-3s %d" , g->name, is_out ?"out" :"in" , func);seq_printf (s," %dmA" ,msm_regval_to_drive (drive)); -seq_printf (s," %s" , pulls[pull]); +seq_printf (s," %s\n" , pulls[pull]); }static void msm_gpio_dbg_show (struct seq_file *s,struct gpio_chip *chip)
@@ -524,10 +539,8 @@ static void msm_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)unsigned gpio = chip->base;unsigned i; -for (i =0 ; i < chip->ngpio; i++, gpio++) { +for (i =0 ; i < chip->ngpio; i++, gpio++) msm_gpio_dbg_show_one(s, NULL, chip, i, gpio); -seq_puts (s,"\n" ); - } }#else
@@ -808,6 +821,46 @@ static void msm_gpio_irq_handler(struct irq_desc *desc)chained_irq_exit (chip, desc); } +static int msm_gpio_init_valid_mask (struct gpio_chip *chip, +struct msm_pinctrl *pctrl) +{ +int ret; +unsigned int len, i; +unsigned int max_gpios = pctrl->soc->ngpios; + +/* The number of GPIOs in the ACPI tables */ + ret =device_property_read_u16_array (pctrl->dev,"gpios" ,NULL ,0 ); +if (ret >0 && ret < max_gpios) { +u16 *tmp; + + len = ret; + tmp =kmalloc_array (len,sizeof (tmp[0 ]),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + + ret =device_property_read_u16_array (pctrl->dev,"gpios" , tmp, + len); +if (ret <0 ) { +dev_err (pctrl->dev,"could not read list of GPIOs\n" ); +kfree (tmp); +return ret; + } + +bitmap_zero (chip->valid_mask, max_gpios); +for (i =0 ; i < len; i++) +set_bit (tmp[i], chip->valid_mask); + +return 0 ; + } + +return 0 ; +} + +static bool msm_gpio_needs_valid_mask (struct msm_pinctrl *pctrl) +{ +return device_property_read_u16_array (pctrl->dev,"gpios" ,NULL ,0 ) >0 ; +} +static int msm_gpio_init (struct msm_pinctrl *pctrl) {struct gpio_chip *chip;
@@ -824,6 +877,7 @@ static int msm_gpio_init(struct msm_pinctrl *pctrl) chip->parent = pctrl->dev; chip->owner =THIS_MODULE ; chip->of_node = pctrl->dev->of_node; + chip->need_valid_mask =msm_gpio_needs_valid_mask (pctrl); ret =gpiochip_add_data (&pctrl->chip, pctrl);if (ret) {
@@ -831,6 +885,13 @@ static int msm_gpio_init(struct msm_pinctrl *pctrl)return ret; } + ret =msm_gpio_init_valid_mask (chip, pctrl); +if (ret) { +dev_err (pctrl->dev,"Failed to setup irq valid bits\n" ); +gpiochip_remove (&pctrl->chip); +return ret; + } + ret =gpiochip_add_pin_range (&pctrl->chip,dev_name (pctrl->dev),0 ,0 , chip->ngpio);if (ret) {dev_err (pctrl->dev,"Failed to add pin range\n" );
Signature · 1 line
Sent by a computer through tubes
Re: [PATCH v3 2/3] gpiolib: Support 'gpio-reserved-ranges' property
In reply to Stephen BoydQuoted 12 lines · Stephen Boyd
From: Stephen Boyd <[email protected]>
Some qcom platforms make some GPIOs or pins unavailable for use by non-secure operating systems, and thus reading or writing the registers
for those pins will cause access control issues. Add support for a DT property to describe the set of GPIOs that are available for use so that
higher level OSes are able to know what pins to avoid reading/writing. Non-DT platforms can add support by directly updating thechip->valid_mask.
Quoted 2 lines
Signed-off-by Stephen Boyd <[email protected]>Signed-off-by Stephen Boyd <[email protected]>
Hmm...
drivers/gpio/gpiolib.c static int gpiochip_set_desc_names(struct gpio_chip *gc) · line 355
Quoted 3 lines
(quoted diff) +1
-0+ gpiochip->valid_mask = kcalloc(BITS_TO_LONGS(gpiochip-Quoted 1 line
ngpio),
drivers/gpio/gpiolib.c +1
-0+ sizeof(long), GFP_KERNEL);
Just noticed that kcalloc is superfluous here.kmalloc_array() would be enough.
Quoted 5 lines
drivers/gpio/gpiolib.c +5
-0+if (!gpiochip->valid_mask) +return -ENOMEM ; + +/* Assume by default all GPIOs are valid */ +bitmap_fill (gpiochip->valid_mask, gpiochip->ngpio);
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v3 2/3] gpiolib: Support 'gpio-reserved-ranges' property
Quoted 1 line · Andy Shevchenko
On Wed, 2018-03-21 at 09:58 -0700, Stephen Boyd wrote:
After addressing comments,
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
In reply to Stephen BoydQuoted 12 lines · Stephen Boyd
From: Stephen Boyd <[email protected]>
Some qcom platforms make some GPIOs or pins unavailable for use by non-secure operating systems, and thus reading or writing the registers for those pins will cause access control issues and reset the device. With a DT/ACPI property to describe the set of pins that are available for use, parse the available pins and set the irq valid bits for gpiolib to know what to consider 'valid'. This should avoid any issues with gpiolib. Furthermore, implement the
pinmux_ops::requestfunction so that pinmux can also make sure to not use pins that are unavailable.
Quoted 2 lines
Signed-off-by Stephen Boyd <[email protected]>Signed-off-by Stephen Boyd <[email protected]>
Hmm...
drivers/pinctrl/qcom/pinctrl-msm.c static const struct pinctrl_ops msm_pinctrl_ops = { · line 116
Quoted 10 lines
+static int
msm_pinmux_request(struct pinctrl_dev *pctldev, unsigned offset)drivers/pinctrl/qcom/pinctrl-msm.c +8
-0+{ +struct msm_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); +struct gpio_chip *chip = &pctrl->chip; + +if (gpiochip_line_is_valid (chip, offset)) +return 0 ; + +return -EINVAL ;
Perhaps traditional pattern
if (!...)
return -EINVAL;
return 0;
?
drivers/pinctrl/qcom/pinctrl-msm.c static void msm_gpio_dbg_show_one(struct seq_file *s, · line 534
Quoted 5 lines
drivers/pinctrl/qcom/pinctrl-msm.c +2
-1+}seq_printf (s," %dmA" ,msm_regval_to_drive (drive)); -seq_printf (s," %s" , pulls[pull]); +seq_printf (s," %s\n" , pulls[pull]);
I had commented this once, but you ignored by some reason.
I would rather just move
seq_puts(s, "\n");
here.
The rationale behind, besides making diff more neat, is to reduce possible burden in the future if someone would like to squeeze more data in between.
drivers/pinctrl/qcom/pinctrl-msm.c static void msm_gpio_irq_handler(struct irq_desc *desc) · line 837
Quoted 1 line
drivers/pinctrl/qcom/pinctrl-msm.c +1
-0+ tmp =kmalloc_array (len,sizeof (tmp[0 ]),GFP_KERNEL );
sizeof(*tmp) ?
Quoted 2 lines
drivers/pinctrl/qcom/pinctrl-msm.c +2
-0+if (!tmp) +return -ENOMEM ;
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v3 2/3] gpiolib: Support 'gpio-reserved-ranges' property
In reply to Andy ShevchenkoQuoting Andy Shevchenko (2018-03-21 10:59:10)
Quoted 13 lines · Stephen Boyd
Quoted 11 lines
From: Stephen Boyd <[email protected]>
Some qcom platforms make some GPIOs or pins unavailable for use by non-secure operating systems, and thus reading or writing the registers
for those pins will cause access control issues. Add support for a DT property to describe the set of GPIOs that are available for use so that
higher level OSes are able to know what pins to avoid reading/writing. Non-DT platforms can add support by directly updating thechip->valid_mask.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Stephen Boyd <[email protected]>Signed-off-by Stephen Boyd <[email protected]>Hmm...
Don't look closely! :P
Quoted 8 lines
Quoted 4 lines
+
gpiochip->valid_mask= kcalloc(BITS_TO_LONGS(gpiochip-Quoted 1 line
ngpio),
+ sizeof(long),
GFP_KERNEL);Just noticed that kcalloc is superfluous here.
kmalloc_array()would be enough.
Ok. I was copying the irqchip style. Should I fold them together into a helper function and also update to kmalloc_array?
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
In reply to Andy ShevchenkoQuoting Andy Shevchenko (2018-03-21 11:07:09)
Quoted 14 lines · Stephen Boyd
drivers/pinctrl/qcom/pinctrl-msm.c static const struct pinctrl_ops msm_pinctrl_ops = { · line 116
Quoted 10 lines
+static int
msm_pinmux_request(struct pinctrl_dev *pctldev, unsigned offset)drivers/pinctrl/qcom/pinctrl-msm.c +8
-0+{ +struct msm_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); +struct gpio_chip *chip = &pctrl->chip; + +if (gpiochip_line_is_valid (chip, offset)) +return 0 ; + +return -EINVAL ;Perhaps traditional pattern
Quoted 5 lines
if (!...)
return-EINVAL;return 0;
Or ternary?
return gpiochip_line_is_valid(chip, offset) ? 0 : -EINVAL;
Quoted 9 lines
drivers/pinctrl/qcom/pinctrl-msm.c static void msm_gpio_dbg_show_one(struct seq_file *s, · line 534
Quoted 6 lines
drivers/pinctrl/qcom/pinctrl-msm.c +2
-1+}seq_printf (s," %dmA" ,msm_regval_to_drive (drive)); -seq_printf (s," %s" , pulls[pull]); +seq_printf (s," %s\n" , pulls[pull]);I had commented this once, but you ignored by some reason.
Quoted 7 lines
I would rather just move
seq_puts(s, "\n");
here.The rationale behind, besides making diff more neat, is to reduce possible burden in the future if someone would like to squeeze more data in between.
Sure.
Quoted 5 lines
Quoted 2 lines
+ tmp =
kmalloc_array(len, sizeof(tmp[0]), GFP_KERNEL);
sizeof(*tmp)?
Ok.
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
In reply to Stephen BoydQuoting Stephen Boyd (2018-03-21 09:58:48)
Quoted 10 lines
drivers/pinctrl/qcom/pinctrl-msm.c +10
-0+ ret =device_property_read_u16_array (pctrl->dev,"gpios" ,NULL ,0 ); +if (ret >0 && ret < max_gpios) { +u16 *tmp; + + len = ret; + tmp =kmalloc_array (len,sizeof (tmp[0 ]),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + + ret = device_property_read_u16_array(pctrl->dev, "gpios", tmp,
drivers/pinctrl/qcom/pinctrl-msm.c static void msm_gpio_irq_handler(struct irq_desc *desc) · line 851
Quoted 10 lines
drivers/pinctrl/qcom/pinctrl-msm.c +10
-0+ len); +if (ret <0 ) { +dev_err (pctrl->dev,"could not read list of GPIOs\n" ); +kfree (tmp); +return ret; + } + +bitmap_zero (chip->valid_mask, max_gpios); +for (i =0 ; i < len; i++) +set_bit (tmp[i], chip->valid_mask);
This leaks tmp too.. I'll fix that in v4 and resend tomorrow if there aren't more comments.
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
In reply to Stephen BoydQuoted 7 lines · Stephen Boyd
Quoting Andy Shevchenko (2018-03-21 11:07:09)
Quoted 2 lines · Stephen Boyd
Quoted 1 line
Or ternary?
return gpiochip_line_is_valid(chip, offset) ? 0 : -EINVAL;
Fine with me!
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v3 2/3] gpiolib: Support 'gpio-reserved-ranges' property
In reply to Stephen BoydQuoted 10 lines · Stephen Boyd
Quoting Andy Shevchenko (2018-03-21 10:59:10)
Quoted 9 lines · Stephen Boyd
Quoted 7 lines
+
gpiochip->valid_mask= kcalloc(BITS_TO_LONGS(gpiochip-Quoted 1 line
ngpio),
+ sizeof(long),
GFP_KERNEL);
Quoted 7 lines
Quoted 3 lines
Just noticed that kcalloc is superfluous here.
kmalloc_array()would be enough.Ok. I was copying the irqchip style. Should I fold them together into a
helper function and also update tokmalloc_array?
Not sure about first part, but definitely makes sense the second one (as a separate patch perhaps).
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
In reply to Stephen Boyddrivers/pinctrl/qcom/pinctrl-msm.c static void msm_gpio_irq_handler(struct irq_desc *desc) · line 833
Quoted 10 lines · Stephen Boyd
drivers/pinctrl/qcom/pinctrl-msm.c +10
-0+static int msm_gpio_init_valid_mask (struct gpio_chip *chip, +struct msm_pinctrl *pctrl) +{ +int ret; +unsigned int len, i; +unsigned int max_gpios = pctrl->soc->ngpios; + +/* The number of GPIOs in the ACPI tables */ + ret =device_property_read_u16_array (pctrl->dev,"gpios" ,NULL ,0 ); +if (ret >0 && ret < max_gpios) {
This needs to be ret <= max_gpios, otherwise it will fail if every GPIO is available.
And it should print an error message and return an error code if ret > max_gpios.
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
Quoted 6 lines · Timur Tabi
This needs to be ret <=
max_gpios, otherwise it will fail if every GPIO is available.And it should print an error message and return an error code if ret >
max_gpios.
Also, you don't allocate chip->valid_mask anywhere.
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
Quoted 2 lines · Timur Tabi
Also, you don't allocate
chip->valid_maskanywhere.
So I see now where it's allocated, but something is fishy. I have three TLMMs on my chip:
[ 67.107018] gpiochip_init_valid_mask:351 gpiochip->need_valid_mask=1 [ 67.153747] gpiochip_init_valid_mask:356 gpiochip->ngpio=72 [ 67.195324] gpiochip_init_valid_mask:361 gpiochip->valid_mask=0000000070b1a4b6 [ 68.532992] gpiochip_init_valid_mask:356 gpiochip->ngpio=44 [ 68.574496] gpiochip_init_valid_mask:361 gpiochip->valid_mask=000000002f33b8a3 [ 68.709378] msm_gpio_init_valid_mask:837 ret=44 max_gpios=44 chip->valid_mask=000000002f33b8a3 [ 69.726502] gpiochip_init_valid_mask:351 gpiochip->need_valid_mask=1 [ 69.772960] gpiochip_init_valid_mask:356 gpiochip->ngpio=54 [ 69.814084] gpiochip_init_valid_mask:361
gpiochip->valid_mask=000000001a53c932
Are these normal addresses for kcalloc() to return? They're not even word-aligned.
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
Quoted 5 lines · Timur Tabi
Quoted 2 lines · Timur Tabi
Also, you don't allocate
chip->valid_maskanywhere.So I see now where it's allocated, but something is fishy.
No, it seems you missed %p vs. %px discussion.
The pointers printed by %p nowadays are hashed values, not the original ones.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
In reply to Timur TabiQuoted 17 lines · Timur Tabi
drivers/pinctrl/qcom/pinctrl-msm.c static void msm_gpio_irq_handler(struct irq_desc *desc) · line 833
Quoted 11 lines · Stephen Boyd
drivers/pinctrl/qcom/pinctrl-msm.c +9
-0+static int msm_gpio_init_valid_mask (struct gpio_chip *chip, +struct msm_pinctrl *pctrl) +{ +int ret; +unsigned int len, i; +unsigned int max_gpios = pctrl->soc->ngpios; + +/* The number of GPIOs in the ACPI tables */ + ret = device_property_read_u16_array(pctrl->dev, "gpios",NULL, 0);
drivers/pinctrl/qcom/pinctrl-msm.c +1
-0+if (ret >0 && ret < max_gpios) {This needs to be ret <=
max_gpios, otherwise it will fail if every GPIO
is available.
Quoted 3 lines
And it should print an error message and return an error code if ret
Quoted 1 line
max_gpios.
Perhaps makes sense to do the opposite condition
if (ret < 0 || ret > max_gpios) {
... error handling ...
}
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
In reply to Andy ShevchenkoQuoted 4 lines · Andy Shevchenko
No, it seems you missed %p vs. %px discussion.
The pointers printed by %p nowadays are hashed values, not the original ones.
I totally forgot about that, thanks.
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
In reply to Andy ShevchenkoQuoting Andy Shevchenko (2018-03-23 04:36:04)
Quoted 20 lines · Timur Tabi
Quoted 19 lines · Stephen Boyd
Quoted 11 lines
drivers/pinctrl/qcom/pinctrl-msm.c +9
-0+static int msm_gpio_init_valid_mask (struct gpio_chip *chip, +struct msm_pinctrl *pctrl) +{ +int ret; +unsigned int len, i; +unsigned int max_gpios = pctrl->soc->ngpios; + +/* The number of GPIOs in the ACPI tables */ + ret = device_property_read_u16_array(pctrl->dev, "gpios",NULL, 0);
+ if (ret > 0 && ret <max_gpios) {This needs to be ret <=
max_gpios, otherwise it will fail if every GPIO
is available.And it should print an error message and return an error code if ret
Quoted 1 line
Quoted 8 lines
Quoted 1 line
max_gpios.Perhaps makes sense to do the opposite condition
if (ret < 0 || ret >
max_gpios) {
... error handling ...
}
Indeed. I already rewrote it like this two days ago:
static int msm_gpio_init_valid_mask(struct gpio_chip *chip,
struct msm_pinctrl *pctrl)
{
int ret;
unsigned int len, i;
unsigned int max_gpios = pctrl->soc->ngpios;
u16 *tmp;
/* The number of GPIOs in the ACPI tables */
len = ret = device_property_read_u16_array(pctrl->dev, "gpios",
ULL, 0);
if (ret < 0)
return 0;
if (ret > max_gpios)
return -EINVAL;
tmp = kmalloc_array(len, sizeof(*tmp), GFP_KERNEL);
if (!tmp)
return -ENOMEM;
ret = device_property_read_u16_array(pctrl->dev, "gpios", tmp,
en);
if (ret < 0) {
dev_err(pctrl->dev, "could not read list of GPIOs\n");
goto out;
}
bitmap_zero(chip->valid_mask, max_gpios);
for (i = 0; i < len; i++)
set_bit(tmp[i], chip->valid_mask);out:
kfree(tmp);
return ret;
}I'll send the updated patches now.
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
Quoted 1 line · Stephen Boyd
I'll send the updated patches now.
Thanks.
BTW, I just discovered that the static globals in pinctrl-msm are breaking the ability to support more than one TLMM:
static struct pinctrl_desc msm_pinctrl_desc = {
static struct irq_chip msm_gpio_irq_chip = {
static struct msm_pinctrl *poweroff_pctrl;
I'm going to have to fix all of these.
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
In reply to Stephen BoydQuoted 3 lines · Stephen Boyd
bitmap_zero(chip->valid_mask, max_gpios);
for (i = 0; i < len; i++)
set_bit(tmp[i], chip->valid_mask);Looking to this code I just realized it would be nice to have
{of,device}_property_read_bitmask() where bitmask_parse() is called.
Since it related to change a binding, I would really take couple of days to hear other opinions.
In the above case, you need to supply a string, like
"1-5,16,18,25"
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · Stephen Boyd
bitmap_zero(chip->valid_mask, max_gpios); for (i = 0; i < len; i++) set_bit(tmp[i], chip->valid_mask);Looking to this code I just realized it would be nice to have
Quoted 8 lines
{of,device}_property_read_bitmask() where
bitmask_parse()is called.Since it related to change a binding, I would really take couple of days to hear other opinions.
In the above case, you need to supply a string, like
"1-5,16,18,25"
s/bitmask/bitmap/g
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/3] gpiolib: Support 'gpio-reserved-ranges' property
In reply to Stephen BoydQuoted 14 lines · Stephen Boyd
Quoting Andy Shevchenko (2018-03-21 10:59:10)
Quoted 13 lines · Stephen Boyd
Quoted 11 lines
From: Stephen Boyd <[email protected]>
Some qcom platforms make some GPIOs or pins unavailable for use by non-secure operating systems, and thus reading or writing the registers
for those pins will cause access control issues. Add support for a DT property to describe the set of GPIOs that are available for use so that
higher level OSes are able to know what pins to avoid reading/writing. Non-DT platforms can add support by directly updating thechip->valid_mask.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Stephen Boyd <[email protected]>Signed-off-by Stephen Boyd <[email protected]>Hmm...
Don't look closely! :P
Same physical person acting on behalf of two different legal entities right? Seems OK to me.
Yours,
Linus Walleij