|
Go back OS Review Device Driver NS Tools Home Papers Daily Link To Main |
Printer I/O Port Á¦¾î (1)
============== prnioport.c ===========================
//
// ÈÀϸí : prnport.c
// ¼³ ¸í : ÇÁ¸°ÅÍ IO Æ÷Æ®¸¦ Á÷Á¢ Á¦¾î ÇÑ´Ù.
// ÀÛ¼ºÀÚ : À¯¿µÃ¢ (ÁÖ)JDT
// ÀúÀÛ±Ç : GNU
// ÁÖ ÀÇ : 1. À̰ÍÀº ÇнÀÀ» À§ÇÏ¿© Ä¿³Î 2.1ÀÌÈÄ¿ëÀ¸·Î¸¸ Á¤ÀÇ ÇÏ¿´´Ù.
// 2. À̰ÍÀº ÇнÀÀ» À§ÇÏ¿© ÀÚü Çì´õÈÀÏ Á¤ÀǸ¦ »ç¿ëÇÏÁö ¾Ê¾Ò´Ù.
//
//*****************************************************
#define MODULE
#include <linux/module.h>
#include <linux/fs.h>
#define PRNIOPORT_MAJOR 88
#define PRNIOPORT_NAME "PRINT IO PORT"
#define PRNIOPORT_MODULE_VERSION "PRINT IO PORT V0.1"
#define PRNIOPORT_ADDRESS 0x0378
#define PRNIOPORT_ADDRESS_RANGE 3
//*****************************************************
//-----------------------------------------------------
// ¼³¸í : insmodÇÔ¼ö¿¡ ÀÇÇØ¼ È£ÃâµÇ´Â ÇÔ¼ö
// ¸Å°è : ¾øÀ½
// ¹Ýȯ : Á¤»óÀ̸é 0À» ¹ÝȯÇÑ´Ù.
// ÁÖÀÇ : ¾øÀ½
//-----------------------------------------------------
int init_module(void)
{
// ÀÌ ±¸Á¶Ã¼´Â fs.h¿¡ Á¤ÀÇ µÇ¾î ÀÖ´Ù.
static struct file_operations lcd_fops =
{
NULL, // loff_t (*llseek) (struct file *, loff_t, int);
NULL, // ssize_t (*read) (struct file *, char *, size_t, loff_t *);
NULL, // ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
NULL, // int (*readdir) (struct file *, void *, filldir_t);
NULL, // unsigned int (*poll) (struct file *, struct poll_table_struct *);
NULL, // int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
NULL, // int (*mmap) (struct file *, struct vm_area_struct *);
NULL, // int (*open) (struct inode *, struct file *);
NULL, // int (*flush) (struct file *);
NULL, // int (*release) (struct inode *, struct file *);
NULL, // int (*fsync) (struct file *, struct dentry *);
NULL, // int (*fasync) (int, struct file *, int);
NULL, // int (*check_media_change) (kdev_t dev);
NULL, // int (*revalidate) (kdev_t dev);
NULL // int (*lock) (struct file *, int, struct file_lock *);
};
if( !register_chrdev( PRNIOPORT_MAJOR, PRNIOPORT_NAME , &lcd_fops ) )
{
printk(" register_chrdev %s Ok \n", PRNIOPORT_MODULE_VERSION );
if (!check_region( PRNIOPORT_ADDRESS, PRNIOPORT_ADDRESS_RANGE ))
{
request_region( PRNIOPORT_ADDRESS, PRNIOPORT_ADDRESS_RANGE, PRNIOPORT_NAME );
printk(" got %d addresses from %x \n",PRNIOPORT_ADDRESS_RANGE, PRNIOPORT_ADDRESS );
printk(" %s DRIVE REGISTER OKn", PRNIOPORT_NAME );
} else {
unregister_chrdev( PRNIOPORT_MAJOR, PRNIOPORT_NAME );
printk(" could not get %d addresses from %x \n", PRNIOPORT_ADDRESS_RANGE, PRNIOPORT_ADDRESS );
}
} else {
printk("unable to get major %d for %s \n", PRNIOPORT_MAJOR, PRNIOPORT_NAME );
}
return 0;
}
//-----------------------------------------------------
// ¼³¸í : rmmodÇÔ¼ö¿¡ ÀÇÇØ¼ È£ÃâµÇ´Â ÇÔ¼ö
// ¸Å°è : ¾øÀ½
// ¹Ýȯ : ¾øÀ½
// ÁÖÀÇ : ¾øÀ½
//-----------------------------------------------------
void cleanup_module(void)
{
release_region( PRNIOPORT_ADDRESS, PRNIOPORT_ADDRESS_RANGE );
if( !unregister_chrdev( PRNIOPORT_MAJOR, PRNIOPORT_NAME ))
{
printk("%s DRIVER CLEANUP OK \n", PRNIOPORT_NAME);
} else {
printk("%s DRIVER CLEANUP FAILED \n", PRNIOPORT_NAME);
}
}
============== prnioport.c ³¡ ========================
============== Makefile ========================
#DEBUG = y
INCLUDEDIR = /usr/src/linux/include
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DJIT_DEBUG -DJIQ_DEBUG -DALL_DEBUG
else
DEBFLAGS = -O2
endif
CFLAGS = -D__KERNEL__ -DMODULE -Wall $(DEBFLAGS)
CFLAGS += -I$(INCLUDEDIR)
OBJS = prnioport.o
all: $(OBJS)
$(CC) $(CFLAGS) -c $^ -o $@
clean:
rm -f *.o
============== Makefile ³¡ ========================
make
/sbin/insmod prnioport.o
cat /proc/ioports
/sbin/rmmod prnioport
|