Re: [PATCH] powerpc/powernv: Cache OPAL check_token() results
From: Shivang Upadhyay
Date: Mon Jun 22 2026 - 01:40:35 EST
Hi Sourabh,
Thanks for reviewing.
On Wed, 2026-06-03 at 09:22 +0530, Sourabh Jain wrote:
> Yes, it is a good idea to avoid making repetitive calls to check
> whether
> an OPAL call is supported by the firmware.
>
> But it feels like it would have been better if skiboot itself
> advertised
> support for OPAL calls via the FDT, similar to how RTAS does.
>
That's a good suggestion. I can take that up as future scope of
improvements.
> The current approach to finding supported OPAL calls is:
>
> - Discover all supported OPAL calls during the first
> opal_check_token()
> call.
> - From the second call onward, check whether discovery has already
> been
> done, and then test the token in opal_token_cache.
>
> The approach looks reasonable, but how about doing it this way
> instead:
>
> Maintain a tri-state value for each OPAL call:
> 0 - Status needs to be check
> 1 - Supported
> -1 - Not supported
>
this tri-state implementation, maybe would get little hard to
implement, along with how currently i've designed the test_token call.
So currently on the first call it caches all the results. and then just
returns the output. But as per your suggestion, first one would have to
set all to -1, then set the result in the token that is being checked.
IMO, the current implementation is slightly more clean.
as per your concern with opal_token_cache_initialized, I think we can
instead look at jump_labels to solve this. First lookup is same, but
then we asm_patch the next lookup with nops. I think that would be best
of both worlds.
>
>
> >
> > +/**
> > + * opal_token_cache_init - Initialize the OPAL token cache
> > + *
> > + * Called during opal_init() to populate the token cache by
> > querying
> > + * OPAL firmware for all tokens in the supported range.
>
> Seems like the above comment is not correct. I don't see below
> function
> invoked from opal_init().
>
yeah, I missed this. this was my first implementation. But turns out
alot of opal_calls actually happend before opal_init(). So i moved to
opal_token_cache_initialized method.
Regards
~Shivang.