From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.230]) by ozlabs.org (Postfix) with ESMTP id 76487DDED3 for ; Fri, 18 Jan 2008 21:54:12 +1100 (EST) Received: by nz-out-0506.google.com with SMTP id i1so799611nzh.39 for ; Fri, 18 Jan 2008 02:54:10 -0800 (PST) Message-ID: <4f8c3030801180254l1fed257bpdb6839afcfdf2196@mail.gmail.com> Date: Fri, 18 Jan 2008 18:54:09 +0800 From: "Ramkumar J" To: linuxppc-embedded@ozlabs.org Subject: Adding new driver in Linux 2.6 - read fails with -1 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2876_14226228.1200653649616" List-Id: Linux on Embedded PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , ------=_Part_2876_14226228.1200653649616 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi All, I m using the Linux 2.6(2.6.23-rc2) from Grants for ML-403 and I tried to add a new driver for a hardware based stream. When I created the device node and executed the application, I could see that the printk's in the driver are getting executed for open, release and ioctl. For read, the function doesnt seem calling the drivers read routine and exits with -1. However the same is called when I do a cat < /dev/devnode. Am I missing something ? -------------------------------------------------------------------------------------------------------------- static struct file_operations co_stream_fops = { .owner = THIS_MODULE, .open = co_stream_open, .read = co_stream_read, .write = co_stream_write, // .ioctl = co_stream_ioctl, .release = co_stream_release }; static int __init co_stream_init(void) { unsigned int *tmp; int i=0; dbprintk("Welcome !!!\n"); if (!request_mem_region(STREAM_PHY_ADDR, STREAM_PHY_SIZE, DRIVER_NAME) ) { printk("Failed to lock the memory...\n"); goto out; } if (!(remapped_address = ioremap(STREAM_PHY_ADDR, STREAM_PHY_SIZE)) ) { printk("Failed to remap...\n"); goto out; } printk("Address remapped to 0x%08X.\n", remapped_address); Major = register_chrdev( 0, DEVICE_NAME, &co_stream_fops); <========= Registered fops if (Major < 0) { printk("Registration of the device failed.\n\n"); goto out; } } static ssize_t co_stream_read(struct file *filp, char __user *buf, size_t size, loff_t *l) { printk("\n co_stream_read() is called.\n"); int data,status; /* Wait while empty. */ while (((status=readl( ((volatile unsigned char*) remapped_address) + 8)&3))==0) ... -------------------------------------------------------------------------------------------------------------- printf("CPU listening for hello...\n\r"); for ( i = 0; i < 10; i++ ) { cstream_read(hello_in, &hi, sizeof(int)); printf("FPGA hardware says: %d\n\r", hi); } int cstream_read(cstream stream, void *buffer, int size) { int nbytes; /* TO ADD : Error handing calls here */ printf("Value of stream = 0x%08X, stream->fd = %d. \n", stream, stream->fd); printf("Value of buffer = 0x%08X, size = %d. \n", buffer, size ); if (stream) { nbytes = read(stream->fd, buffer, size); printf("read bytes from hardware = %d.\n", nbytes); } else printf("stream is NULL here.\n"); return(0); } -------------------------------------------------------------------------------------------------------------- c00de4d0 t sysrq_handle_reboot c00de4fc T handle_sysrq c00de524 t co_stream_write c00de550 t co_stream_release c00de598 t co_stream_open c00de624 t co_stream_read c00de760 t __uart_start ---------------------------------------- [ 0.383898] Welcome !!! [ 0.384445] Address remapped to 0xC5000000. [ 0.384628] [ 0.384653] [ 0.384675] Impulse Costream assigned with Major = 254. [ 0.384743] Memory dump of fops structure. [ 0.384803] Address : 0xC01CA350, 0x00000000. [ 0.384867] Address : 0xC01CA354, 0x00000000. [ 0.384932] Address : 0xC01CA358, 0xC00DE624. [ 0.384996] Address : 0xC01CA35C, 0xC00DE524. [ 0.385060] Address : 0xC01CA360, 0x00000000. [ 0.385122] Address : 0xC01CA364, 0x00000000. [ 0.385185] Address : 0xC01CA368, 0x00000000. [ 0.385248] Address : 0xC01CA36C, 0x00000000. [ 0.385311] Address : 0xC01CA370, 0x00000000. [ 0.385374] Address : 0xC01CA374, 0x00000000. [ 0.385437] Address : 0xC01CA378, 0x00000000. [ 0.385499] Address : 0xC01CA37C, 0x00000000. [ 0.385565] Address : 0xC01CA380, 0xC00DE598. [ 0.385627] Address : 0xC01CA384, 0x00000000. [ 0.385693] Address : 0xC01CA388, 0xC00DE550. [ 0.385756] Address : 0xC01CA38C, 0x00000000. [ 0.385818] Address : 0xC01CA390, 0x00000000. [ 0.385881] Address : 0xC01CA394, 0x00000000. [ 0.385944] Address : 0xC01CA398, 0x00000000. [ 0.386007] Address : 0xC01CA39C, 0x00000000. [ 0.386070] Address : 0xC01CA3A0, 0x00000000. [ 0.386133] Address : 0xC01CA3A4, 0x00000000. [ 0.386196] Address : 0xC01CA3A8, 0x00000000. [ 0.386259] Address : 0xC01CA3AC, 0x00000000. Any help or pointers would be helpful. Thanks and Regards, Ramkumar. ------=_Part_2876_14226228.1200653649616 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline


Hi All,

I m using the Linux 2.6(2.6.23-rc2) from Grants for ML-403 and I tried to add a new driver for a hardware based stream. When I created the device node and executed the application, I could see that the printk's in the driver are getting executed for open, release and ioctl. For read, the function doesnt seem calling the drivers read routine and exits with -1. However the same is called when I do a cat < /dev/devnode. Am I missing something ?

--------------------------------------------------------------------------------------------------------------
<Code Snip - Driver>

static struct file_operations co_stream_fops = {
        .owner = THIS_MODULE,
        .open = co_stream_open,
        .read = co_stream_read,
        .write = co_stream_write,
//      .ioctl = co_stream_ioctl,
        .release = co_stream_release
};

static int __init co_stream_init(void)
{
    unsigned int *tmp;
    int i=0;
    dbprintk("Welcome !!!\n");

    if (!request_mem_region(STREAM_PHY_ADDR, STREAM_PHY_SIZE, DRIVER_NAME) )
    {
        printk("Failed to lock the memory...\n");
        goto out;
    }

    if (!(remapped_address = ioremap(STREAM_PHY_ADDR, STREAM_PHY_SIZE)) )
    {
        printk("Failed to remap...\n");
        goto out;
    }

    printk("Address remapped to 0x%08X.\n", remapped_address);

    Major = register_chrdev( 0, DEVICE_NAME, &co_stream_fops);    <========= Registered fops

    if (Major < 0)
    {
        printk("Registration of the device failed.\n\n");
        goto out;
    }

}


static ssize_t co_stream_read(struct file *filp, char __user *buf, size_t size, loff_t *l)
{
        printk("\n co_stream_read() is called.\n");
        int data,status;

        /* Wait while empty. */
        while (((status=readl( ((volatile unsigned char*) remapped_address) + 8)&3))==0)
...
--------------------------------------------------------------------------------------------------------------
<Code Snip - Application>


    printf("CPU listening for hello...\n\r");
    for ( i = 0; i < 10; i++ ) {
        cstream_read(hello_in, &hi, sizeof(int));
        printf("FPGA hardware says: %d\n\r", hi);
    }

int cstream_read(cstream stream, void *buffer, int size)

{
  int nbytes;
  /* TO ADD : Error handing calls here */

  printf("Value of stream = 0x%08X, stream->fd = %d. \n",
                                        stream, stream->fd);

  printf("Value of buffer = 0x%08X, size = %d. \n", buffer, size );

  if (stream) {
      nbytes = read(stream->fd, buffer, size);
      printf("read bytes from hardware = %d.\n", nbytes);
  }
  else
      printf("stream is NULL here.\n");

  return(0);
}

--------------------------------------------------------------------------------------------------------------
<From System.map>

c00de4d0 t sysrq_handle_reboot
c00de4fc T handle_sysrq
c00de524 t co_stream_write
c00de550 t co_stream_release
c00de598 t co_stream_open
c00de624 t co_stream_read
c00de760 t __uart_start

----------------------------------------
<From console output fops dump>

[    0.383898] Welcome !!!
[    0.384445] Address remapped to 0xC5000000.
[    0.384628]
[    0.384653]
[    0.384675]  Impulse Costream assigned with Major = 254.
[    0.384743] Memory dump of fops structure.
[    0.384803] Address : 0xC01CA350, 0x00000000.
[    0.384867] Address : 0xC01CA354, 0x00000000.
[    0.384932] Address : 0xC01CA358, 0xC00DE624.
[    0.384996] Address : 0xC01CA35C, 0xC00DE524.
[    0.385060 ] Address : 0xC01CA360, 0x00000000.
[    0.385122] Address : 0xC01CA364, 0x00000000.
[    0.385185] Address : 0xC01CA368, 0x00000000.
[    0.385248] Address : 0xC01CA36C, 0x00000000.
[    0.385311] Address : 0xC01CA370, 0x00000000.
[    0.385374] Address : 0xC01CA374, 0x00000000.
[    0.385437] Address : 0xC01CA378, 0x00000000.
[    0.385499] Address : 0xC01CA37C, 0x00000000.
[    0.385565] Address : 0xC01CA380, 0xC00DE598.
[    0.385627 ] Address : 0xC01CA384, 0x00000000.
[    0.385693] Address : 0xC01CA388, 0xC00DE550.
[    0.385756] Address : 0xC01CA38C, 0x00000000.
[    0.385818] Address : 0xC01CA390, 0x00000000.
[    0.385881] Address : 0xC01CA394, 0x00000000.
[    0.385944] Address : 0xC01CA398, 0x00000000.
[    0.386007] Address : 0xC01CA39C, 0x00000000.
[    0.386070] Address : 0xC01CA3A0, 0x00000000.
[    0.386133] Address : 0xC01CA3A4, 0x00000000.
[    0.386196 ] Address : 0xC01CA3A8, 0x00000000.
[    0.386259] Address : 0xC01CA3AC, 0x00000000.

Any help or pointers would be helpful.

Thanks and Regards,
Ramkumar.


 

------=_Part_2876_14226228.1200653649616--