From: Jiri Slaby <jirislaby@gmail.com>
To: ohyama_sec@ariel-networks.com
Cc: linux-kernel@vger.kernel.org, Jan Engelhardt <jengelh@computergmbh.de>
Subject: Re: [QUESTION] I have a question about making device driver
Date: Tue, 05 Feb 2008 11:58:21 +0100 [thread overview]
Message-ID: <47A8414D.7080200@gmail.com> (raw)
In-Reply-To: <20080205093900.D0BF6948006@ns.ariel-networks.com>
On 02/05/2008 10:39 AM, ohyama_sec@ariel-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);
> }
>
next prev parent reply other threads:[~2008-02-05 10:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-05 9:39 [QUESTION] I have a question about making device driver ohyama_sec
2008-02-05 10:58 ` Jiri Slaby [this message]
-- strict thread matches above, loose matches on Subject: below --
2008-02-04 9:54 ohyama_sec
2008-02-04 10:29 ` Jan Engelhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47A8414D.7080200@gmail.com \
--to=jirislaby@gmail.com \
--cc=jengelh@computergmbh.de \
--cc=linux-kernel@vger.kernel.org \
--cc=ohyama_sec@ariel-networks.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox