[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <47A8414D.7080200@gmail.com>
Date: Tue, 05 Feb 2008 11:58:21 +0100
From: Jiri Slaby <jirislaby@...il.com>
To: ohyama_sec@...el-networks.com
CC: linux-kernel@...r.kernel.org,
Jan Engelhardt <jengelh@...putergmbh.de>
Subject: Re: [QUESTION] I have a question about making device driver
On 02/05/2008 10:39 AM, ohyama_sec@...el-networks.com wrote:
>>> --- check program ---
>>> #include <linux/types.h>
>>> #include <asm/io.h>
>>> #include <stdio.h>
>> A userspace program? I thought this was about kernel device drivers.
>
>
> Yes, It is a userspace program to see what I can write parallel port device controller or not.
>
> And, I'm sorry , I should not have explained my device driver in text, but should have written source code.
> So that, the following is source code of the device driver. It works only to obtain I/O resource (I/O address and IRQ).
>
>
>>> int main(void){
>>> int base = 0x378;
>>> char read, write;
>>>
>>> ioperm(base, 1, 1);
if (ioperm(...)) {
perror("ioperm");
return 1;
}
and retest.
>>>
>>> write = 0xa;
>>> outb(write, base);
>>> read = inb(base);
>>> if((read & 0xf) == write){
[...]
>
> --- kernel module (device driver) ---
>
[...]
>
> #define SHORT_NR_PORTS 8
>
> static int major = 0;
>
> unsigned long short_base = 0x378;
>
> volatile int short_irq = 7;
> static struct cdev *obj_cdev;
>
> MODULE_AUTHOR ("hiroyasu ohyama");
> MODULE_LICENSE("GPL2");
>
> struct file_operations my_fops = {
> .owner = THIS_MODULE,
> };
>
> irqreturn_t short_sh_interrupt(int irq, void *dev_id, struct pt_regs *regs)
> {
> printk(KERN_INFO "interrupt\n");
>
> return 0;
> }
>
> int short_init(void)
> {
> int result;
> int err;
> int dev_num;
> dev_t dev;
>
> if (! request_region(short_base, SHORT_NR_PORTS, "hiro_test")) {
> printk(KERN_INFO "can't get I/O port address 0x%lx\n",
> short_base);
> return -ENODEV;
> }
>
> alloc_chrdev_region(&dev, 0, 1, "hiro_test");
why do you register chrdev?
> major = MAJOR(dev);
>
> dev_num = MKDEV(major, 0);
>
> obj_cdev = cdev_alloc();
> cdev_init(obj_cdev, &my_fops);
> obj_cdev->owner = THIS_MODULE;
> obj_cdev->ops = &my_fops;
> err = cdev_add(obj_cdev, dev_num, 1);
> if(err){
> printk(KERN_INFO "err_num : %d", err);
> }
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists