Subject: Re: Fwd: Re: Queries about bus_space (MIPS: TX49)
To: Anand Lalgondar <solarflares@fastmail.fm>
From: Jochen Kunz <jkunz@unixag-kl.fh-kl.de>
List: tech-kern
Date: 02/02/2004 18:28:59
On Mon, 02 Feb 2004 20:35:07 +0530
"Anand Lalgondar" <solarflares@fastmail.fm> wrote:

> > bus_space_alignstride_chipdep.c is the file that
> > implements bus_space.
> But these contains only macro definition, how to use this is a
> question?
See the rbtx4927_bus_mem.c you already mentioned. rbtx4927_bus_mem.c
sets up some #defines and includes bus_space_alignstride_chipdep.c at
the end. The bus_space_*_chipdep.c file generates the bus space
functions out of the #defines.

> Now suppose if I want to create a new bus space, can I do it like
> this:----------------------------------------------------------------
> ---------- bus_space_tag_t st;
> bus_space_handle_t sh;
>=20
> bus_space_map(st, address, size, flags, &sh);=20
No. This creates a bus_space_handle that you have to use to actually
access the bus space with bus_space_read / bus_space_write.=20

A bus space tag is the abstraction of an entire (CPU) bus. A bus space
handle is an abstraction of an address (or a range of addresses) on this
bus.=20

> I could not see bus_space_map function call only __BS(map) is there.
__BS(map) is bus_space_map. Walk backwards the macro replacements and
you will see:
mips/include/bus_space.h:
#define bus_space_map(t, a, s, f, hp)                             \
        (*(t)->bs_map)((t)->bs_cookie, (a), (s), (f), (hp), 1)
mips/bus_space_alignstride_chipdep.c:
        t->bs_map =3D             __BS(map);
Now have a look at the definition of the __BS() macro at the start of
bus_space_alignstride_chipdep.c...

> What is the function of __BS(init), does it create a tag OR something
> else?
A bus space tag is a data structure that contains lots of function
pinters. These pinters point to functions that actually implement the
bus space functionality. You have macros in include/bus_space.h that map
a call to a bus_space(9) function to an indirect call of the according
function in the bus space tag. The function pointers in the bus space
tag must be initialized, hence __BS(init). __BS(init) (expands to
rbtx4927_bus_io_init) is caled early in the startup of your kernel,
bevore autoconfig(9) starts. There is only a single, architecture
dependent bus space tag data structure in the kernel. The tag parameter
to bus_space(9) functions is a pointer to this data structure. In case
you have distinct I/O and memory spaces you may have a bus I/O tag data
structure and a bus memory tag data structure. E.g. PCI has a (usually)
32 bit wide I/O space and a distict (usually) 32 bit wide memory space.
There are distinct bus cycles / signales to access ether I/O or memory
space.

Note that this is only one possible implementation of bus space. ;-)
--=20


tsch=FC=DF,
       Jochen

Homepage: http://www.unixag-kl.fh-kl.de/~jkunz/