[PATCH v2 5/9] gpiolib: Get rid of ARCH_NR_GPIOS

Christophe Leroy christophe.leroy at csgroup.eu
Fri Sep 2 08:22:20 PDT 2022



Le 02/09/2022 à 16:58, Andy Shevchenko a écrit :
> On Fri, Sep 2, 2022 at 4:57 PM Christophe Leroy
> <christophe.leroy at csgroup.eu> wrote:
>>
>> Since commit 14e85c0e69d5 ("gpio: remove gpio_descs global array")
>> there is no limitation on the number of GPIOs that can be allocated
>> in the system since the allocation is fully dynamic.
>>
>> ARCH_NR_GPIOS is today only used in order to provide downwards
>> gpiobase allocation from that value, while static allocation is
>> performed upwards from 0. However that has the disadvantage of
>> limiting the number of GPIOs that can be registered in the system.
>>
>> To overcome this limitation without requiring each and every
>> platform to provide its 'best-guess' maximum number, rework the
>> allocation to allocate upwards, allowing approx 2 millions of
>> GPIOs.
>>
>> In order to still allow static allocation for legacy drivers, define
>> GPIO_DYNAMIC_BASE with the value 512 as the start for dynamic
>> allocation. The 512 value is chosen because it is the end of
>> the current default range so all current static allocations are
>> expected to be below that value. Of course that's just a rough
>> estimate based on the default value, but assuming static
>> allocations come first, even if there are more static allocations
>> it should fit under the 512 value.
>>
>> In the future, it is expected that all static allocations go away
>> and then dynamic allocation will be patched to start at 0.
> 
> Eventually we have to get rid of gpio_is_valid() completely...
> But this is another story.
> Reviewed-by: Andy Shevchenko <andy.shevchenko at gmail.com>

Yes that could be done as a follow-up.

There are about 300 call sites.

Should simply replace gpio_is_valid(gpio) by gpio >= 0. And then verify 
that the check is really required. But needs to check signness of gpio 
at every place.

First look seems already promissing:


int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
{
	struct gpio_desc *desc;
	int err;

	desc = gpio_to_desc(gpio);

	/* Compatibility: assume unavailable "valid" GPIOs will appear later */
	if (!desc && gpio_is_valid(gpio))
		return -EPROBE_DEFER;



More information about the linux-arm-kernel mailing list