Re: [QUESTION] I have a question about making device driver

2008-02-05 Thread Jiri Slaby

On 02/05/2008 10:39 AM, [EMAIL PROTECTED] wrote:

--- check program ---
#include 
#include 
#include 

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 [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [QUESTION] I have a question about making device driver

2008-02-05 Thread ohyama_sec
by Hiroyasu Ohyama


Thank you for giving some advices.

>
>>I'm writing device driver for parallel port on Linux.
>
>Another one?


I write it for study and fun. And the main reason I chose parallel port is that 
I think it is simpler than any other device.


>
>>In initial function which is argument of module_init() in my device
>>driver, I reserved I/O address region, 0x378-0x37a, with using
>>request_region() and regist my charactor device driver calling
>>register_chrdev().
>>
>>After I compile and link it. I insert this module and I can confirm
>>that I obtaind the range of I/O address at /proc/ioports. But I
>>cannot write data on I/O address line, It means that following check
>>program shows "false".
>
>>--- check program ---
>>#include 
>>#include 
>>#include 
>
>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);
>>
>>write = 0xa;
>>outb(write, base);
>>read = inb(base);
>>if((read & 0xf) == write){
>
>Some parallel port chips always return 0 on inb(base), for example
>the AMD K6 boards that shipped with VIA Apollo chipsets (1998). On
>the other hand, a chipset as old as to carry a i386DX CPU (probably
>was all Intel back then) returns the desired 0xA on inb(base).


The CPU of hardware requirement is Athlon XP that shipped with SIS 964L, I 
think that has i386 compatibility but I'll manage with a execution environment 
having Intel and try it with the other machine.
In current machine, whatever I write date to parallel port controller which is 
in booked I/O address 0x378, I get only 0xff from inb(0x378).

I found that the check program that I worte in previous mail shows true with 
loaded parport_pc.
So that I read source code of parport_pc which is driver/parport/parport_pc.c 
to seek how it enable to write data to I/O line. And I located function to do 
I/O, that is parport_SPP_supported().
I thought that It was supposed to do enable to do I/O before calling this 
function, But I couldn't find especially processing.
After that, I didn't find processing that I seeked.

The mainly difference between my device driver and parport_pc , except for 
beauty and support of several device , is support of DMA.
But I believe this difference is not related.



--- kernel module (device driver) ---

#include 
#include 
#include 
#include 
#include 
#include
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#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");
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);  
}

result = request_irq(short_irq, short_sh_interrupt,
SA_INTERRUPT,"hiro_test",
NULL);
if (result) {
printk(KERN_INFO "can't get assigned irq %i\n", short_irq);
short_irq = -1;
}

printk(KERN_INFO "hiro_test: loaded\n");
return 0; 
}

void short_cleanup(void)
{
free_irq(short_irq, NULL);
cdev_del(obj_cdev);
release_region(short_base,SHORT_NR_PORTS);
unregister_chrdev_region(MKDEV(major, 0), 1);

printk(KERN_INFO "hiro_test: Unloaded\n");
}

module_init(short_init);
module_exit(short_cleanup);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [QUESTION] I have a question about making device driver

2008-02-04 Thread Jan Engelhardt

On Feb 4 2008 18:54, [EMAIL PROTECTED] wrote:
>
>I'm writing device driver for parallel port on Linux.

Another one?

>In initial function which is argument of module_init() in my device
>driver, I reserved I/O address region, 0x378-0x37a, with using
>request_region() and regist my charactor device driver calling
>register_chrdev().
>
>After I compile and link it. I insert this module and I can confirm
>that I obtaind the range of I/O address at /proc/ioports. But I
>cannot write data on I/O address line, It means that following check
>program shows "false".

>--- check program ---
>#include 
>#include 
>#include 

A userspace program? I thought this was about kernel device drivers.

>int main(void){
>int base = 0x378;
>char read, write;
>
>ioperm(base, 1, 1);
>
>write = 0xa;
>outb(write, base);
>read = inb(base);
>if((read & 0xf) == write){

Some parallel port chips always return 0 on inb(base), for example
the AMD K6 boards that shipped with VIA Apollo chipsets (1998). On
the other hand, a chipset as old as to carry a i386DX CPU (probably
was all Intel back then) returns the desired 0xA on inb(base).

>printf("true\n");
>}else{
>printf("false\n");
>}
>return 0;
>}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/