Adding new driver in Linux 2.6 - read fails with -1
Ramkumar J
ramkumarj2000 at gmail.com
Fri Jan 18 21:54:09 EST 2008
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ozlabs.org/pipermail/linuxppc-embedded/attachments/20080118/71ac4970/attachment.htm
More information about the Linuxppc-embedded
mailing list