Linux 2.6 removable media block device driver question

From: beck0778
Date: Wed Jul 25 2007 - 10:21:41 EST


I'm trying to write a block driver for accessing an SD card through a memory-mapped SPI module implemented in a Xilinx FPGA. I'm working with MontaVista's PPC 2.6.10 kernel. I have finished the lower-level card access routines, and can successfully read and write blocks, and even fdisk and mount the card. Through a hardware register, I can tell if a card is inserted, so that is not the problem.

Currently, things only work if I have the sd card inserted when I load the driver module. My next step is to figure out how to handle card insertion and removal after the driver has been loaded, and how to notify the kernel that there is now a disk present.

If there is not a card present at module init, how much can you tell the kernel about your device? Should I allocate a gendisk if I don't know the capacity? Should I set up a timer to periodically check for the presence of a card, and if so, how do I notify the kernel that a new disk has been discovered.

I have a copy of Corbet, Rubini, and Kroah-Hartman's book 'Linux Device Drivers', which has been a big help. Their sample block driver, unfortunately, does not appear to show how to handle a disk that may change during execution, and may not even be present some times.

Is there a guide to the proper way to handle a changing block device?

Thanks in advance for any help,
Matthew
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/