既にお持ちの Linux-2.2 用のデバイスドライバを、 お客様がご自分で Linux-2.4 用に移植するための要点をメモしておきます。
インクルードファイルとして、下記を追加します。
#include <linux/init.h> #include <linux/devfs_fs_kernel.h>
ファイル操作構造体を下記のように書き換えます。
static struct file_operations xx_fops = {
NULL, /* lseek */
xx_read, /* read */
xx_write, /* write */
NULL, /* readdir */
NULL, /* select */
xx_ioctl, /* ioctl */
NULL, /* mmap */
xx_open, /* open */
NULL, /* flush */
xx_close, /* close */
NULL, /* fsync */
NULL, /* faync */
NULL, /* check_media_change */
NULL /* revalidate */
};
から
static struct file_operations gb_fops = {
owner: THIS_MODULE,
read: xx_read,
write: xx_write,
ioctl: xx_ioctl,
open: xx_open,
release: xx_close,
};
Linux の流儀に合わせるため、close を release に書き換えるほうが良いかも
しれません。
struct wait_queue *sc_wait_q; .. interruptible_sleep_on(&sc->sc_wait_q); .. wake_up_interruptible(&sc->sc_wait_q);といったメカニズムで使われる wait_queue を下記のように変更します。
wait_queue_head_t sc_wait; .. interruptible_sleep_on(&sc->sc_wait); .. wake_up_interruptible(&sc->sc_wait);
デバイスドライバの初期化ルーチン xx_init() で、下記のようにウェイトキューを 初期化します。
init_waitqueue_head(&sc->sc_wait);
とりあえずは、これで動作しますが、キャラクタ・デバイスの登録の仕方が変わりつつ ありますので、ついでに下記のように変更するほうが良いでしょう。
xx_init() で行っていたキャラクタ・デバイスの登録
if (register_chrdev(XX_MAJOR, "xx", &xx_fops)) {
..
}
を削除して、新たに追加する関数 init_xx() で次のように登録します。
int __init init_xx(void)
{
if (devfs_register_chrdev(XX_MAJOR, "xx", &xx_fops)) {
printk("xx: unable to get major %d\n", XX_MAJOR);
return -EIO;
}
}
/usr/src/linux/init/main.c で下記のようにデバイスドライバを初期化します。
#ifdef CONFIG_XX
extern void init_xx(void);
#endif
..
#ifdef CONFIG_XX
init_xx();
#endif
2.4 kernel から PCMCIA の kernel driver のサポートが始まりましたが、 まだ完全なサポートには長い道のりが必要で、その状況は
http://pcmcia-cs.sourceforge.net/の「A discussion of PCMCIA in the 2.4 kernel series」を見てください。
現状では、kernel の「CONFIG_PCMCIA」を y(es) にしないようにして、 PCMCIA のサポートのすべてを今までどおり pcmcia-cs package に任せ、 ドライバを上記のように書き換えて使うのが良いと思います。