From: "Ramkumar J" <ramkumarj2000@gmail.com>
To: linuxppc-embedded@ozlabs.org
Subject: Adding new driver in Linux 2.6 - read fails with -1
Date: Fri, 18 Jan 2008 18:54:09 +0800 [thread overview]
Message-ID: <4f8c3030801180254l1fed257bpdb6839afcfdf2196@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 4487 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 6784 bytes --]
next reply other threads:[~2008-01-18 10:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-18 10:54 Ramkumar J [this message]
2008-01-18 11:22 ` Adding new driver in Linux 2.6 - read fails with -1 Jenkins, Clive
2008-01-18 12:28 ` Ramkumar J
2008-01-18 20:15 ` Jenkins, Clive
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4f8c3030801180254l1fed257bpdb6839afcfdf2196@mail.gmail.com \
--to=ramkumarj2000@gmail.com \
--cc=linuxppc-embedded@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).