Subject: Re: Using same com.c driver for two devices that access serial port differently?
To: matthew green <mrg@eterna.com.au>
From: Ian Zagorskih <ianzag@megasignal.com>
List: tech-kern
Date: 06/27/2003 12:51:04
On Thursday 26 June 2003 05:12, matthew green wrote:
>
> perhaps this is the way we should go for a truly "generic" bus
> space that deal with these cases... i'm not sure.  i don't know
> how expensive the memory accesses (probably two of them) and
> the test are...
>

If there were some generic bus space access mechanism that would be great=
=2E For=20
now bus_space calls cover only local busses like port and memory IO acces=
s.

But let's immagine that i have a remote "bus". For example, i have some c=
ustom=20
ISA and PCI DSP plates with ADSP 2185 on board. This DSP has data and pro=
gram=20
memory which can be accessed with some board specific hardware registers,=
=20
usually setting up address register and reading/writing data register. Ps=
eudo=20
code looks like:

--- cut ---
struct dsp_sofrc {
=09struct device sc_dev;

=09/* ISA or PCI bus space */
=09bus_space_tag_t sc_iot;
=09bus_space_handle_t sc_ioh;

=09/* Board registers */
=09int sc_reg_adr;=09=09/* Address register */
=09int sc_reg_dat;=09=09/* Data register */
};

void
dsp_read(sc, adr, data, nwords)
=09struct dsp_softc *sc;
=09u_long adr, *data, nwords;
{
=09bus_space_write_2(sc->sc_iot, sc->sc_ioh, sc->sc_reg_adr, adr);
=09while (nwords-- > 0) {
=09=09*data++ =3D bus_space_read_2(sc->sc_iot, sc->sc_ioh, sc->sc_reg_dat=
);
=09}
}
--- cut ---

Now let we have some upper level device driver which needs to access this=
 DSP=20
board memory to do something. ATM i need to do this like:

--- cut ---
struct dev_softc {
=09struct device sc_dev;
=09struct dsp_softc *sc_dsp;
};
void dev_some_func(sc)
=09struct dev_softc *sc;
{
=09u_long data[10], count;
=09count =3D 10;
=09dsp_read(sc->sc_dsp, 0x123, data, count);
=09/* ... */
=09dsp_write(sc->sc_dsp, 0x123, data, count);
}
--- cut ---

=2E.so this code is underlying dsp_softc dependant. And this is instead o=
f=20
implementing my own "bus space" for DSP and doing the same in generic for=
m=20
like DSP device doing it itself:

--- cut ---
struct dev_softc {
=09struct device sc_dev;

=09/* Note: now this is DSP bus space */
=09bus_space_tag_t sc_iot;
=09bus_space_handle_t sc_ioh;
};
void dev_some_func(sc)
=09struct dev_softc *sc;
{
=09u_long data[10], count;
=09count =3D 10;
=09bus_space_read_region_2(sc->sc_iot, sc->sc_ioh, 0x123, data, count);
=09/* ... */
=09bus_space_write_region_2(sc->sc_dsp, 0x123, data, count);
}
--- cut ---

Obviously the second example is more generic and device independant. But =
i do=20
not see an elegant and system friendly way to do it now :(

--=20
JSC Novosibirsk Geophysical Equipment Development Center.
WEB=09http://www.megasignal.com