Subject: Re: MI console detection
To: Matthias Drochner <M.Drochner@fz-juelich.de>
From: Martin Husemann <martin@duskware.de>
List: tech-kern
Date: 10/31/2002 21:55:24
On Thu, Oct 31, 2002 at 04:08:53PM +0100, Martin Husemann wrote:

> All this is not realy needed if we accept a few (!) #ifdef's in MI drivers
> from time to time, and to me it is not clear if it's worth the effort.

Sorry, let me rephrase this. Lacking a MI api to test a given device
for being part of console (like the "mach64_is_console()" function does
currently, and a lot other drivers do in MD code), we need a few #ifdefs
now. That's not good.

My request to discuss such an API was put down with a reference to do the
early attach thing the Alpha does now. I see that for some ports this is
an easy solution. I don't see why this aproach is considered cleaner than
the API I originaly proposed. Maybe we could have both, and let ports choose
what is easier for them to implement and define something like
__CONSOLE_VIA_CNATTACH on a port by port basis, implementing the "this is
part of console" test macro/function on other ports.

To see why the Alpha aproach needs IMHO significant levels of hacks, just look
at it's implementation:

arch/alpha/alpha/api_up1000.c:105:      platform.cons_init = api_up1000_cons_init;
arch/alpha/alpha/avalon_a12.c:112:      platform.cons_init = avalon_a12_cons_init;
arch/alpha/alpha/dec_1000a.c:162:       platform.cons_init = dec_1000a_cons_init;
arch/alpha/alpha/dec_2000_300.c:124:    platform.cons_init = dec_2000_300_cons_init;
arch/alpha/alpha/dec_2100_a50.c:126:    platform.cons_init = dec_2100_a50_cons_init;
arch/alpha/alpha/dec_2100_a500.c:150:   platform.cons_init = dec_2100_a500_cons_init;
arch/alpha/alpha/dec_3000_300.c:88:     platform.cons_init = dec_3000_300_cons_init;
arch/alpha/alpha/dec_3000_500.c:108:    platform.cons_init = dec_3000_500_cons_init;
arch/alpha/alpha/dec_550.c:110: platform.cons_init = dec_550_cons_init;
arch/alpha/alpha/dec_6600.c:102:        platform.cons_init = dec_6600_cons_init;
arch/alpha/alpha/dec_alphabook1.c:108:  platform.cons_init = dec_alphabook1_cons_init;
arch/alpha/alpha/dec_axppci_33.c:137:   platform.cons_init = dec_axppci_33_cons_init;
arch/alpha/alpha/dec_eb164.c:106:       platform.cons_init = dec_eb164_cons_init;
arch/alpha/alpha/dec_eb64plus.c:110:    platform.cons_init = dec_eb64plus_cons_init;
arch/alpha/alpha/dec_eb66.c:110:        platform.cons_init = dec_eb66_cons_init;
arch/alpha/alpha/dec_kn20aa.c:116:      platform.cons_init = dec_kn20aa_cons_init;
arch/alpha/alpha/dec_kn300.c:121:       platform.cons_init = dec_kn300_cons_init;
arch/alpha/alpha/dec_kn8ae.c:96:        platform.cons_init = dec_kn8ae_cons_init;

It's well structured, so every single cons_init function is simple. There are
18 of them, and all I looked at have two /* XXX */ comments when deciding 
wether serial console or kbd/display is to be used as console.

Compare that to the "I am part of console" implementation for sparc64
used in machfb.c:

        node = PCITAG_NODE(pa->pa_tag);
        if (node == -1)
                return 0;
                
        return (node == OF_instance_to_package(OF_stdout()));

Ok, it would need a bit more work to be completely generic, but it wouldn't
get far worse.

An implementation of the Alpha method on sparc would probably be a table
of (parts of) OF device names and a function pointer, each entry guarded by
the proper #if Nxxx > 0. Then some matching function would compare the OF
path against the partial strings in the table and call the function pointed
to by that entry, which in turn would call the MI xxx_cnattach() function.

Not too bad, but this still requires a piece of code to know all possible
console drivers, which IMHO is a bad design, if you don't have some fixed set
of possible consoles due to hardware restrictions. Not impossible to
implement, not nearly rocket science. Just not the right thing (TM).

Martin