user3815726
user3815726

Reputation: 518

Linux device driver - memory mapped I/O example discussion

I have gone through the following topic and I still have some questions.

ioread32 followed by iowrite32 not giving same value

  1. In the link, where can I get my base which is defined as 0xfed00000 in the post ?
  2. what should I put for the second parameter in

    void request_mem_region(unsigned long start, unsigned long len,char *name);

  3. what should I put for the second parameter in

    void *ioremap_nocache(unsigned long phys_addr, unsigned long size);

  4. By having the Makefile and generating the kernel module, I should use the insmod and then dmesg to check if the code works as I expect, is this correct ?

  5. In the case, should I add iounmap(virtual_base); before return 0; in the source ?

Thanks

Upvotes: 0

Views: 1365

Answers (1)

sawdust
sawdust

Reputation: 17077

  1. In the link, where can I get my base which is defined as 0xfed00000 in the post ?

It's the base (physical) address of the peripheral's registers.
If the peripheral is a discrete chip on the board, then consult the board documentation.
If the peripheral is embedded in a SoC, then consult the memory map in the SoC datasheet.

  1. what should I put for the second parameter in
void request_mem_region(unsigned long start, unsigned long len,char *name);
  1. what should I put for the second parameter in
void *ioremap_nocache(unsigned long phys_addr, unsigned long size);

These two routines should be called with the same first and second parameters.
The length/size is the number of bytes the peripheral's register set occupies.
Sometimes the entire memory region to the next peripheral is specified.

  1. By having the Makefile and generating the kernel module, I should use the insmod and then dmesg to check if the code works as I expect, is this correct ?

A judicious sprinkling of printk() statements is the tried & true method of testing a Linux kernel driver/module.
Unix has kdb.

  1. In the case, should I add iounmap(virtual_base); before return 0; in the source ?

Do not copy that poorly written example of init code.
If ioremap() is performed in a driver's probe() (or other initialization) routine, then the iounmap() should be in the probe's error exit sequence and in the driver's remove() (or the complementary to init) routine.
There are numerous examples to study in the Linux kernel source. Use an online Linux cross reference such as http://lxr.free-electrons.com/source/
Note that almost all Linux drivers use iounmap() two or more times.

Upvotes: 1

Related Questions