0

I have a Input output card which I am connecting to My PC through PCIe Interface.

I have written a driver for linux to access the device this is IOCTL routine.

static int _ioctl(struct inode *inode, struct file *file,
                              unsigned int cmd, unsigned long arg)
{
  U32 temp;
  U32 Add = 0;
  U32 Data = 0;
  U32 nCmd = 0;

       // __get_user(nCmd,(int *)cmd)); 
    switch ( cmd )
    {
        case NOOFCARDS:
            __put_user(NumberOfCards,(U32 *)arg);
            break;

        case IOMEMORY:
            temp = pci1553[0].Mem1;
            __put_user(temp,(U32 *)arg);
                     printk("IOMEMORY :%x\n",temp);
            break;

        case IOPORTS:
            temp = pci1553[CardCount].Mem4;
//          temp = PCI_BASE_ADDRESS[3];
            __put_user(temp,(U32 *)arg);
            break;

        case DEVICEID:
            printk("DEVICE_ID :%x\n",DEVICE_ID);

            temp = DEVICE_ID;
            __put_user(temp,(U32 *)arg);
            break;

        case VENDORID:
            printk("VENDOR_ID :%x\n",VENDOR_ID);
            temp = VENDOR_ID;
            __put_user(temp,(U32 *)arg);
            break;

        case BUSNO:
            temp = pci1553[CardCount].BusNum;
            __put_user(temp,(U32 *)arg);
            break;
        case READ16IO:
             __get_user(Add,(U32 *)arg);
                 temp =  inw(pci1553[CardCount].Mem4 + Add);
             __put_user(temp,(U32 *)arg);
                break;
        case READ8IO:
              __get_user(Add,(U32 *)arg);
              temp =  inb(pci1553[CardCount].Mem4 + Add);
              __put_user(temp,(U8 *)arg);
              break;

        case WRITE16IO:
             __get_user(Add,(U32 *)(arg + 0));
                 __get_user(Data,(U32 *)(arg + 4));
                 outw(Data,pci1553[CardCount].Mem4 + Add);
//          printk("W16IO Add:%x\n",Add);
//          printk("W16IO MemAdd:%x\n",pci1553[CardCount].Mem4 + Add);
//          printk("W16IO Data:%x\n",Data);
//              temp =  inw(pci1553[CardCount].Mem4 + Add);
//          printk("R16IO Data:%x\n",temp);
                 break;

            case WRITE8IO:
                   printk("WRITE8IO\n");
             __get_user(Add,(U32 *)(arg + 0));
                 __get_user(Data,(U32 *)(arg + 4));
                 outb(Data,pci1553[0].Mem1 + Add);
                 break;
}

I am trying use this function through ioctl call from my application program

This one of my ioctl call ioctl(fd,WRITEIO16,Data1); Here fd is the File Descriptor I get on opening the Device file WRITIO16 this is the cmd, Data1 is arg

But whatever arguments I am passing I am not getting that in driver. Driver enters the ioctl routine but it's not getting arguments passed from application program. Driver is working when I give my arguments directly in the driver IOCTL routine.

This is first time I am writing Linux Driver so any help would be good.

Mathieu
  • 8,840
  • 7
  • 32
  • 45
Karthik KP
  • 13
  • 4

0 Answers0