Simon Wood writes:
>
> Hello all and sundry,
>
> I'm still plugging away at the Psion port (this weekend didn't see much work
> as it took all of Saturday to put 2 IKEA shelves together, but I did get the
> kernel relocating itself to somewhere sensible).
>
> Next is the 'disk drives'.... and this is where I'm a little lost. Current
> system uses the block drivers for disk access (presumably because the
> hardware is slow mechanical stuff) and registers interrupts for when data is
> ready (is this right?).
The block device driver interface is the type of device driver that must be
implemented for any driver which will be used to access a filesystem.
>
> The Psion SSD (memory cards) are accessed through a fast SIBO serial
> interface. The data is addressed mapped, to get at it you need to set the
> address and then read/write the byte of data.
>
> What is the best way to approach implementing a driver?
IMPORTANT NOTE: Do not use any code in 0.0.77 as a reference for writing
this driver. Please see 0.0.76 instead. I accidentally released some
experimental code which will not be in the next release, and does not make
sense. The code is not buggy, just unnecessary and wrong. If you write a
driver like this it won't work with future kernels. END
The ramdisk driver is probably the best driver to use as a template. It is
very simple, does not use interrupts or waiting, and copies memory in the
simplest way. The block_read and block_write functions are generic function
which allow character orientated reads/writes to occur on a block device.
These are only used by things like mkfs and fsck.
The important function for your driver to implement are the open and
release functions, and the request function. You then create a
file_operations structure just like the one in rd.c, but with entries pointing
to your open, and release function (you won't need an ioctl yet). The open
and release functions may or may not need to do anything, but they should
verify that the device being accessed is valid, and return an error if not.
Most of the functionality will be in the request function (see
do_rd_request()) which actually reads and writes blocks.
You will then need an init function for the driver which calls register_blkdev
and stores a pointer to the request function in the blk_dev array of
structures in the correct place.
Then all you have to do is put a call to this function in blk_dev_init() in
ll_rw_blk.c, and you have your driver.
Al