On Tue, 21 Oct 2003, Erez Doron wrote:

> o.k., here is the story:
> 
> we are developping a uwb (ultra wide band) network chip.
> this should be a wireless 100-500 Mbps with Qos communication chip. ( 
> bluetooth and WiFi, beware  ;-)
> 
> the prototype i am working on has it's registers and rams mapped as 
> memory on a PCI card.
> 
> i tried using /dev/mem to access it, but it didn't work.
> so i  tried looking at examples and builded my own driver.

You did something wrong there, since /dev/mem surely works for PCI MMIO 
regions.

You can look at the kernel module in svgalib for a simple device driver 
that allows mmap to MMIO regions.

> i am succesfull at accessing my card as a file. (/dev/uwb/0)
> i was not successful at accessing it as mmapped (i can mmap it, 
> write/read to/from it, but it does not do the real writing/reading 
> to/from the card, and i get no errors either).
> 
> the only issue, is that when i do a read or write, even that the length 
> of the copy_from_user or copy_to_user is 4 bytes long, it seems to 
> read/write more than that
> so if i access (read) adress  0xa00004, i get the register at 0xa00000 
> also read. (probably being cached)
> 
> arch is x86 (Pentium III)
> 
> any idea ?

Look at the MTRR setup (cat /proc/mtrr). The default is uncached, so if 
your range is not in any of the MTRRs listed, it is accessed uncached by 
the CPU.

> btw, here are the main code:

>         if (num>num_boards) return -EFAULT;
>         if (p>(unsigned int)mem_size) return -EFAULT;
>         size=MIN(count,(unsigned int)mem_size-p);
>         size=MIN(size,4);
>         //printk(KERN_INFO UWB "read addres 0x%lx..0x%lx ... ",p,p+size-1);
>         //printk(KERN_INFO UWB "coping to user space\n");
>         if (copy_to_user (buf, uwb_mem[num]+p,  size))
>                          return -EFAULT;

I would not use copy to user directly from IO regions, since you should 
access ioremapped regions with readb, readw, readl, rather than pointer 
derefernce.  Try first reading the data, and then copying it to 
userspace. A similar remark holds for the writes, of course. Here's a 
working example from svgalib:

        case _IOC_NR(SVGAHELPER_READL):
           copy_from_user(&iov,(char *)arg,sizeof(iov));
           iov.val=readl(iov.port);
           copy_to_user((char *)arg,&iov,sizeof(iov));
           break;


> static int uwb_dev_mmap(struct file * filp, struct vm_area_struct * vma)
> {
>         //if (noncached_address(offset) || (file->f_flags & O_SYNC))
>          //       vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);

Why did you leave out this code? You do want the accesses to be 
uncached.


-- 
Matan Ziv-Av.                         [EMAIL PROTECTED]


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to