user space device driver can't write to isa device

user space device driver can't write to isa device

Post by M?ns Rullg? » Tue, 27 Aug 2002 22:48:18




>     int memFile;

Don't use mixed case variable names.  The compiler might be confused
thinking it's java or some other devilry.

--
M?ns Rullg?rd

 
 
 

user space device driver can't write to isa device

Post by Fabian Her » Wed, 28 Aug 2002 05:49:52


I've been using mixed case variable names, function names and whatever for
years, and I never ever heard of a compiler that would wrongly assume code
to be java or something just because of mixed case variable names, even
under really weird circumstances (whatever that may be :-).


> >     int memFile;

> Don't use mixed case variable names.  The compiler might be confused
> thinking it's java or some other devilry.

> --
> M?ns Rullg?rd



 
 
 

user space device driver can't write to isa device

Post by Grant Edwar » Wed, 28 Aug 2002 06:18:47




>>     int memFile;

> Don't use mixed case variable names.  The compiler might be confused
> thinking it's java or some other devilry.

You've _got_ to be trolling, because that's utter nonsense.  

I've been using mixed case for 15 years and no C compiler has
ever had any problems with it.

--
Grant Edwards                   grante             Yow!  I wish I was a
                                  at               sex-starved manicurist
                               visi.com            found dead in the Bronx!!

 
 
 

user space device driver can't write to isa device

Post by Ed Skinne » Wed, 28 Aug 2002 22:47:56


    I'm guessing the ioperm()s might be the most suspect. There's a
comment in the Linux version about some error checking but it doesn't
say what was checked. The ioperm() will return a -1 on an error.
    Does the error checking include the result of the open()?
    Anything in /var/log/messages as a result of running the program?
    Obvious thing: running as root?

> I'm writing an user space device driver for an ISA device (for i386)
> that is visible at the physical address 0xd8000000 after writing to the
> proper I/O port, and writing a 1 to this address. Then I should see some
> values in the following memory. But I can't read nor write anything to
> it. So I have written two testing programs.

> First for DOS:

> void main(void)
> {
>     unsigned char far* mem = (unsigned char far*)0xd8000000UL;
>     int i;
>     outp(0x300, 0xc1); // reset board
>     outp(0x300, 0xc2); // stop reset, visible in memory
>     mem[0] = 1;
>     for(i = 0; i < 512; i++)
>         printf("%02x ", mem[i]);
> }

> which works quite well (also the complete driver works).

> Then for Linux:

> int main(void)
> {
>     int memFile;
>     volatile unsigned char* mem;

>     ioperm(0x300,1,1);
>     ioperm(0x80,1,1); // For the outb_p() command

>     outb_p(0xc1, 0x300);
>     outb_p(0xc2, 0x300);
>     memFile = open("/dev/mem", O_RDWR);
>     mem = (unsigned char*)mmap(NULL, 1024, PROT_READ|PROT_WRITE,
> MAP_SHARED, memFile, 0xd8000000);
>     // some error checking is here
>     mem[0] = 1;
>     for(i = 0; i < 512; i++)
>         printf("%02x ", mem[i]);
>     close(memFile);
> }

> This one only returns lots of FFs, meaning there is nothing. I'm pretty
> sure that the I/O-port  operations succeed, since LEDs on the device
> display that it should be visible in memory. I think he mmapping also
> works, I successfully mmapped parts of the BIOS, or the memory of a
> PCI-SCSI-controller, and something from 0 to 3MB (the kernel?). This was
> with kernel 2.2.20 on a Pentium 90. There I also tried kernel 2.0.35 or
> something.
> More things that I tried:

> the mmap()-sequence from vga.c in the svgalib source. It consists of
> mmapping /proc/self/mem and two other mmaps. The only difference was:
> instead of getting all zeros when reading from existent memory, I
> received an error when trying to mmap() /proc/self/mem.

> opening  /dev/mem and lseek to the right address to write() the one. But
> nothing changed in memory.

> One thing finally worked: I ran the DOS program, rebooted the system
> with Linux, and ran the Linux program without the reset sequnce. Then I
> could see some patterns. So reading seems to work.

> If nobody can help me, I will have to try to write a kernel module, that
> doesn't need interrupts and serves only one application. I've never
> written a driver module before, so this is going to make even more
> trouble (I guess).

> Thanks in advance
>     Fabian Herb

 
 
 

user space device driver can't write to isa device

Post by Fabian Her » Wed, 28 Aug 2002 23:27:42


I check the results of the open call, as well as the ioperm() call. At least
ioperm() returns an error if I'm not running the program as root.
Also, LEDs on the device indicate that the I/O operation worked and should
have made the device visible in memory.
/var/log/messages says nothing (just MARKs for the last few hours now).

>     I'm guessing the ioperm()s might be the most suspect. There's a
> comment in the Linux version about some error checking but it doesn't
> say what was checked. The ioperm() will return a -1 on an error.
>     Does the error checking include the result of the open()?
>     Anything in /var/log/messages as a result of running the program?
>     Obvious thing: running as root?

> > int main(void)
> > {
> >     int memFile;
> >     volatile unsigned char* mem;

> >     ioperm(0x300,1,1);
> >     ioperm(0x80,1,1); // For the outb_p() command

> >     outb_p(0xc1, 0x300);
> >     outb_p(0xc2, 0x300);
> >     memFile = open("/dev/mem", O_RDWR);
> >     mem = (unsigned char*)mmap(NULL, 1024, PROT_READ|PROT_WRITE,
> > MAP_SHARED, memFile, 0xd8000000);
> >     // some error checking is here
> >     mem[0] = 1;
> >     for(i = 0; i < 512; i++)
> >         printf("%02x ", mem[i]);
> >     close(memFile);
> > }

 
 
 

user space device driver can't write to isa device

Post by M?ns Rullg? » Wed, 28 Aug 2002 23:26:56



> > >     int memFile;

> > Don't use mixed case variable names.  The compiler might be confused
> > thinking it's java or some other devilry.

> I've been using mixed case variable names, function names and whatever for
> years, and I never ever heard of a compiler that would wrongly assume code
> to be java or something just because of mixed case variable names, even
> under really weird circumstances (whatever that may be :-).

It was meant to be a joke.  But mixed case names are ugly and should
be avoided.

--
M?ns Rullg?rd

 
 
 

user space device driver can't write to isa device

Post by Ed Skinne » Thu, 29 Aug 2002 23:00:14


Hello Fabian,

     Hmmm... Interesting... ... ...
     Back in your original posting you said,

 > One thing finally worked: I ran the DOS program, rebooted the system
 > with Linux, and ran the Linux program without the reset sequnce. Then
 > I could see some patterns. So reading seems to work.

     What is the "reset sequence" you refer to above? Apparently that
made things fail/work. I'm assuming you mean some sort of hardware
reset, like a reset button. If that's the case, it sounds like Windows
has initialized some chip (to make this work) whereas Linux is leaving
that aspect alone and trusting the "reset sequence" to leave things in
some [probably] safer but, unfortunately, inappropriate state for you.
     I think your user-level device driver code is correct but it's
possible there's something else needed at its very beginning to permit
the reads from the ISA space to start working. Have you looked for any
other examples of user-space drivers for ISA devices and compared them
with yours? (I have not.)
     I just noticed my Email address was incorrect in previous postings.

me directly if you wish.

 
 
 

1. How to write a device driver for data acquisition via ISA card

Hey everybody, I want to respond to a hardware interrupt from a data
acquisition card via ISA card. I manage to communicate with the card
throught simply I/O program. And now I would like to write a user program
with an interrupt handler.

My questions are:
1) My first step is to install the interrupt handler to the kernel. The
following is my source code. Is my structure of source code to install
interrupt handler correct? What am I missing? And what functions and header
files I need to install and service an interrupt routine?

#include <linux/sched.h>

main()
{
  unsigned int CAN_irq = 9;

 if (CAN_irq >= 0)
   {

     int result = request_irq(CAN_irq, CAN_ISR, SA_INTERRUPT, "CAN", NULL);

     if (result)
       {
      printk(KERN_INFO "CAN card can't get assigned irq %i/n", CAN_irq);
      CAN_ISR = -1;
       }

    return 0;

note: I also wrote CAN_ISR interrupt service routine.

2) Is there any example of device driver codes like this?

3) How to compile it? Is "gcc -O -D__KERNEL__ -o test test.c" correct?

4) Is it possible (reasonable, etc) to write a user program that uses a
hardware interrupt without writing a device driver?

For your information, I'm using RH 6.1 with gcc-2.91.66. I'm referring Linux
Device Driver by Alessandro Rubini and Linux Kernel Internal by M Beck, U
Kunitz and etc. Any other good references?

Thank you.

Regards,
Chun Seong

2. kernel 2.0.x SCSI tape problems

3. How to write a device driver for data acquisition via ISA card?

4. UNIX Visual File manager?

5. Unsupported ISA device doesn't appear in /devices on Solaris x86

6. SCSI/Zip Drive Problem

7. Writing control codes to device through a device driver

8. crash without core-file??

9. How to write a 'user space' mouse driver??

10. I/O mapping from Device Driver to User space

11. Notification user-space program from driver about new device.

12. User space device driver?

13. Block device driver in user space