mttb in sys/powerpc/include/cpufunc.h still does not handle/protect-against interrupts

Mark Millard marklmi at yahoo.com
Tue Apr 20 20:56:58 UTC 2021



On 2021-Apr-20, at 12:18, Nathan Whitehorn <nwhitehorn at freebsd.org> wrote:

> We don't call mttb() in any circumstance in which interrupts are enabled (only in early-boot and suspend/resume contexts, and even then only on some hardware), so there is no need to disable them.
> -Nathan

Are you sure about that given the status needed for using
vs. not of ofw_quiesce? From my reading I expected that
openfirmware might well have been left operationally
enabled enough to be a potential worry as a source of
interrupts that it set up for itself. powermac_attach
reports:

        /*
         * Quiesce Open Firmware on PowerMac11,2 and 12,1. It is
         * necessary there to shut down a background thread doing fan
         * management, and is harmful on other machines (it will make OF
         * shut off power to various system components it had turned on).
         *
         * Note: we don't need to worry about which OF module we are
         * using since this is called only from very early boot, within
         * OF's boot context.
         */

        rootnode = OF_finddevice("/");
        if (OF_getprop(rootnode, "model", model, sizeof(model)) > 0) {
                if (strcmp(model, "PowerMac11,2") == 0 ||
                    strcmp(model, "PowerMac12,1") == 0) {
                        ofw_quiesce();
                }
        }

I never gained enough knowledge to be able to infer
a global lack of interrupts for the context(s) in
which mttb ends up potentially being executed in.

Presuming that you are correct, the code for mttb could
probably use commentary about its required type of
context for use: no interrupts allowed.


> On 4/20/21 3:07 PM, Mark Millard via freebsd-ppc wrote:
>> Looking at sys/powerpc/include/cpufunc.h in main (and so older too):
>> 
>> static __inline void
>> mttb(u_quad_t time)
>> {
>> 
>> 	mtspr(TBR_TBWL, 0);
>> 	mtspr(TBR_TBWU, (uint32_t)(time >> 32));
>> 	mtspr(TBR_TBWL, (uint32_t)(time & 0xffffffff));
>> }
>> 
>> This code still does not protect against interrupts
>> (only suggestive):
>> 
>> 	mtspr(TBR_TBWL, 0);
>> HERE?
>> 	mtspr(TBR_TBWU, (uint32_t)(time >> 32));
>> HERE?
>> 	mtspr(TBR_TBWL, (uint32_t)(time & 0xffffffff));
>> 
>> 
>> My code disabled interrupts around the update:
>> 
>> static __inline void
>> mttb(u_quad_t time)
>> {
>> 	const uint32_t   high= time>>32;
>> 	const uint32_t   low=  time&0xffffffffu;
>> 
>> 	const register_t predisable_msr= intr_disable();
>> 	mtspr(TBR_TBWL, 0);
>> 	mtspr(TBR_TBWU, high);
>> 	mtspr(TBR_TBWL, low);
>> 	intr_restore(predisable_msr);
>> }
>> 
>> As I remember, I found powerpc documentation that indicated
>> such was important to reliable settings.
>> 
> 

===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)



More information about the freebsd-ppc mailing list