Hi, My current software is for an embedded system, running VxWorks OS, on PPC860. I need to convert it to Linux. The HW is memory mapped, and in VxWorks I just write or read from specific addresses to access the HW device. How should I implement it in Linux? I am thinking about writting a char device. Is it the right choice? If so, is there a sample code for such a char device?
That driver assumes the device is on the PCI bus and uses PCI calls to obtain the address range for the memory-mapped HW. IIRC, that was back around 2.0/2.2, so don't expect it to compile...
--
Grant Edwards grante Yow! My DIGITAL WATCH
at has an automatic SNOOZE
visi.com FEATURE!!
Well, you *can* do it the same way. All you need to do in addition to what you did on vxWorks is to map the device's registers using mmap() (*). What you can *not* do from user space is handle interrupts. Also, note that your program needs to run as root and that this is a huge security hole (as it is in vxWorks).
Definitely. However, porting vxWorks code that was designed with a "we-can-access-any-hardware-directly-as-we-please" mindset can be tedious. In most cases, you'll need to design a whole new interface between what remains in the application and what goes into the driver. The art is to get this interface small, efficient and yet comprehensive.
So many that it is hard to pick a suitable example. Best start probably is to read "Linux Device Drivers" by Corbet & Rubini. AFAIK, this book is also available as PDF for free download (try google).
HTH
Rob
(*) A long time ago I wrote two small programs (called "peek" and "poke", ever programmed in BASIC ;-)) that allow you to inspect/modify arbitrary memory locations including HW registers. Drop me a mail if you're interested and I'll send you the source code.
--
Robert Kaiser email: rkaiser AT sysgo DOT com
SYSGO AG http://www.elinos.com
Klein-Winternheim / Germany http://www.sysgo.com
I don't recall any restriction on mmap() only being usable from programs run as root. It's been a couple years since I did a lot with mmap, but I'm pretty sure I ran my apps as a normal user. The mmap(2) man page doesn't mention any requirement to be root either.
--
Grant Edwards grante Yow! .. someone in DAYTON,
at Ohio is selling USED
visi.com CARPETS to a SERBO-CROATIAN
... and I should add that, unless things have changed, the /dev/kmem driver imposes this security requirement not via the normal permissions you might see on the device node. Instead, it is implemented in the driver itself so "chmod" and "chown" won't bypass the root check.
This probably refers to the vxWorks to Linux migration library which has been integrated into our embedded Linux suite "ElinOS". It provides an API that maps VxWorks functions to Linux ones. It simplifies porting efforts a lot, but unfortunately it does not cover the OP's problem of accessing HW registers from application programs directly.
Then, there is also the possibility of creating a vxWorks server to run alongside Linux on our soon-to-be-released microkernel-based multi-OS platform "PikeOS" (see
formatting link
That would allow a vxWorks system to coexist with Linux in the same machine. However, I'm afraid such a server is not likely to be available in the near future.
Rob
--
Robert Kaiser email: rkaiser AT sysgo DOT com
SYSGO AG http://www.elinos.com
Klein-Winternheim / Germany http://www.sysgo.com
Right. I wasn't thinking about /dev/kmem. When I've done things with memory mapped I/O devcies, I wrote a driver that implimented mmap() to allow user-space process to map the device into memory. That allows you to set the ownership and protection of the device appropriately. Using kmem is a bit dangerous.
--
Grant Edwards grante Yow! I want to dress you
at up as TALLULAH BANKHEAD and
visi.com cover you with VASELINE and
WHEAT THINS...
I have only 4 address of HW mapped in my system. Is using ioctl(), instead of mmap(), a better choice in my case? Will it solve the above root problem?
How would we know? We have no idea what sort of device it is and what sort of operations you do upon it. Perhaps ioctl() is the best solution, perhaps mmap() is.
In order to use ioctl() you'll have to write a driver. If you write a driver, you can just as easily impliment mmap(). If you write a driver you'll have the exact same permissions for mmap() that you will for ioctl().
--
Grant Edwards grante Yow! .. I think I'd
at better go back to my DESK
visi.com and toy with a few common
MISAPPREHENSIONS...
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.