* simple access to mem mapped peripheral
@ 2001-10-02 9:02 Matthias Fuchs
0 siblings, 0 replies; 6+ messages in thread
From: Matthias Fuchs @ 2001-10-02 9:02 UTC (permalink / raw)
To: linuxppc-embedded
Hi,
I need a "very simple" way to access a mem mapped peripheral. The device
is mem mapped at 0xf0200000.
I was trying /dev/mem but this dev only accesses my physical memory
chips.
My target is a ppc405gp running recent kernel 2.4.10.
Any idea ?
Matthias
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: simple access to mem mapped peripheral
@ 2001-10-02 14:53 Subodh Nijsure
2001-10-04 8:02 ` Matthias Fuchs
0 siblings, 1 reply; 6+ messages in thread
From: Subodh Nijsure @ 2001-10-02 14:53 UTC (permalink / raw)
To: 'Matthias Fuchs', linuxppc-embedded
Hello,
May be try this?
chip_registerbase = (unsigned
long)ioremap_nocache(CHIP_PHYSICAL_ADDRESS,
CHIP_MEM_SIZE);
printk("Linux kernel Memory mapped base register %lX \n",
chip_registerbase);
Then you can read and write to your chip via *chip_registerbase
/Subodh
-----Original Message-----
From: Matthias Fuchs [mailto:matthias.fuchs@esd-electronics.com]
Sent: Tuesday, October 02, 2001 10:02 AM
To: linuxppc-embedded
Subject: simple access to mem mapped peripheral
Hi,
I need a "very simple" way to access a mem mapped peripheral. The device
is mem mapped at 0xf0200000.
I was trying /dev/mem but this dev only accesses my physical memory
chips.
My target is a ppc405gp running recent kernel 2.4.10.
Any idea ?
Matthias
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: simple access to mem mapped peripheral
2001-10-02 14:53 simple access to mem mapped peripheral Subodh Nijsure
@ 2001-10-04 8:02 ` Matthias Fuchs
2001-10-04 8:15 ` Pierre AUBERT
0 siblings, 1 reply; 6+ messages in thread
From: Matthias Fuchs @ 2001-10-04 8:02 UTC (permalink / raw)
To: linuxppc-embedded
Subodh Nijsure wrote:
>
> Hello,
>
> May be try this?
>
> chip_registerbase = (unsigned
> long)ioremap_nocache(CHIP_PHYSICAL_ADDRESS,
> CHIP_MEM_SIZE);
> printk("Linux kernel Memory mapped base register %lX \n",
> chip_registerbase);
>
> Then you can read and write to your chip via *chip_registerbase
>
Sorry, but I forgot to say that I need a way to access the peripheral
from userspace without writing a
kernel module. I need it only for a simple test and therefore it does
not make sense to me to write a driver.
Of course, writing a driver is not htat dirty :-)
Matthias
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: simple access to mem mapped peripheral
2001-10-04 8:02 ` Matthias Fuchs
@ 2001-10-04 8:15 ` Pierre AUBERT
2001-10-04 10:07 ` Matthias Fuchs
0 siblings, 1 reply; 6+ messages in thread
From: Pierre AUBERT @ 2001-10-04 8:15 UTC (permalink / raw)
To: Matthias Fuchs, Mailing list Embedded linux on PowerPC
Matthias Fuchs wrote:
> Subodh Nijsure wrote:
> >
> > Hello,
> >
> > May be try this?
> >
> > chip_registerbase = (unsigned
> > long)ioremap_nocache(CHIP_PHYSICAL_ADDRESS,
> > CHIP_MEM_SIZE);
> > printk("Linux kernel Memory mapped base register %lX \n",
> > chip_registerbase);
> >
> > Then you can read and write to your chip via *chip_registerbase
> >
>
> Sorry, but I forgot to say that I need a way to access the peripheral
> from userspace without writing a
> kernel module. I need it only for a simple test and therefore it does
> not make sense to me to write a driver.
>
> Of course, writing a driver is not htat dirty :-)
>
> Matthias
>
I think that you can try the mmap function :
int mmap_fd;
/* Open the memory device and mmap the chip registers */
if ((mmap_fd = open("/dev/mem", O_RDWR)) < 0 ) {
perror("open(/dev/mem)");
exit(1);
}
ptr = (chip_register *)mmap(NULL, CHIP_MEM_SIZE,
(PROT_READ|PROT_WRITE),
MAP_SHARED, mmap_fd, CHIP_PHYSICAL_ADDRESS);
if ( ((int)ptr) < 0 ) {
perror("mmap()");
close(mmap_fd);
exit(1);
}
else {
/* Read and write your chip registers ... */
munmap (ptr, CHIP_MEM_SIZE);
close(mmap_fd);
}
--
------------------------------------------------------------------------------
Pierre Aubert | Phone: +33 4 50 65 62 88
| Fax: +33 4 50 65 62 08
STÄUBLI Faverges |
Place Robert STÄUBLI | Mailto:p.aubert@staubli.com
74210 Faverges FRANCE | http://www.staubli.com
------------------------------------------------------------------------------
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: simple access to mem mapped peripheral
2001-10-04 8:15 ` Pierre AUBERT
@ 2001-10-04 10:07 ` Matthias Fuchs
2001-10-04 15:34 ` Francis Litterio
0 siblings, 1 reply; 6+ messages in thread
From: Matthias Fuchs @ 2001-10-04 10:07 UTC (permalink / raw)
To: Pierre AUBERT; +Cc: linuxppc-embedded
Hi Pierre,
thanks. mmap is working fine for my problem ! I wonder why lseek'ing and
reading does not work.
Matthias
Pierre AUBERT wrote:
> I think that you can try the mmap function :
>
> int mmap_fd;
>
> /* Open the memory device and mmap the chip registers */
> if ((mmap_fd = open("/dev/mem", O_RDWR)) < 0 ) {
> perror("open(/dev/mem)");
> exit(1);
> }
> ptr = (chip_register *)mmap(NULL, CHIP_MEM_SIZE,
> (PROT_READ|PROT_WRITE),
> MAP_SHARED, mmap_fd, CHIP_PHYSICAL_ADDRESS);
> if ( ((int)ptr) < 0 ) {
> perror("mmap()");
> close(mmap_fd);
> exit(1);
> }
> else {
>
> /* Read and write your chip registers ... */
>
> munmap (ptr, CHIP_MEM_SIZE);
> close(mmap_fd);
> }
>
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: simple access to mem mapped peripheral
2001-10-04 10:07 ` Matthias Fuchs
@ 2001-10-04 15:34 ` Francis Litterio
0 siblings, 0 replies; 6+ messages in thread
From: Francis Litterio @ 2001-10-04 15:34 UTC (permalink / raw)
To: 'linuxppc-embedded'; +Cc: matthias.fuchs
Matthias Fuchs wrote:
> thanks. mmap is working fine for my problem ! I wonder why
> lseek'ing and reading does not work.
Because in linux/drivers/char/mem.c the function memory_lseek(), which
implements the lseek() system call for /dev/mem, does not call
remap_page_range(), but function mmap_mem(), which implements the mmap()
system call for /dev/mem, does call remap_page_range().
remap_page_range() is a kernel function that builds virtual memory page
table entries for physical pages. In this case, the physical pages are
your device memory that is mapped into RAM by the PCI bus.
Without the PTEs for those physical pages, attempts to read from those
pages (e.g., via lseek() and read()) will segfault just as if you had
dereferenced a pointer that does not point to a valid page in your user
address space.
--
Francis Litterio
Software Engineer
Pyxsys Corproration
litterio@pyxsys.net
978-371-9115 x131
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2001-10-04 15:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-10-02 14:53 simple access to mem mapped peripheral Subodh Nijsure
2001-10-04 8:02 ` Matthias Fuchs
2001-10-04 8:15 ` Pierre AUBERT
2001-10-04 10:07 ` Matthias Fuchs
2001-10-04 15:34 ` Francis Litterio
-- strict thread matches above, loose matches on Subject: below --
2001-10-02 9:02 Matthias Fuchs
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).