LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-13-2019, 09:14 AM   #1
DeanAnderson
LQ Newbie
 
Registered: Nov 2019
Posts: 19

Rep: Reputation: Disabled
how to understand devm_regmap_init_mmio function in kernel?


Hi
I am newbie in kernel linux programming and I am investigating probe function in one of kernel driver.
In device tree we have node:
Code:
reg = <0xF0001000 0x3C0>;  //start addr + size
reg-names = "some_name";
In kernel module at the beginning of file:

Code:
struct Data {
         ....
	void __iomem *pReg;
	struct regmap *pRegMap;
          ...
}
stuct Data* pData;

static const struct regmap_config regCfg= {
	.reg_bits	= 32,
	.reg_stride	= 4,
	.val_bits	= 32,
	.fast_io	= true,
};
In probe in kernel module:
Code:
pData= devm_kzalloc(...  //allocate memory for pData
struct resource* res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "some_name"); //go through pdev->resource and find "some_name"
pData->pReg = devm_ioremap(dev, res->start, resource_size(res)); //my understanding is that this one maps physical register address into virtual kernel address space, so beginning from now You can access by pData->pReg[3]  so it is similar to mechanism used in user space with mmap
pData->pRegmap = devm_regmap_init_mmio(dev, pData->pReg, &regCfg); //this unfortunately I ma not able to understand
Does anyone know what does function:
"devm_regmap_init_mmio"
do? I am not able to understand even looking at google. I don't see a need of existence such function, as I think after ioremap we can access to pData->pReg directly by indexing or initialize memory with some memset(&pData->pReg,...) or equivalent function in kernel, is it true?



It seems that devm_regmap_init_mmio is not needed at all if you plan to use iowrite32, ioread32 api on __iomem pointer. Above instead the idea was to use regmap_write, regmap_read api. For this API you have to firstly do some kind of initialization and that is why there is devm_regmap_init_mmio. Also it is not recommended practise to iterate through index __iomem pointer like in mmap case.

Last edited by DeanAnderson; 11-14-2019 at 02:04 AM.
 
Old 11-17-2019, 04:19 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
The function sets up memory-mapped I/O. It is documented in the header file https://elixir.bootlin.com/linux/lat.../regmap.h#L943 If you prefer to use io instructions, you are free to do so.
 
Old 11-18-2019, 09:53 AM   #3
DeanAnderson
LQ Newbie
 
Registered: Nov 2019
Posts: 19

Original Poster
Rep: Reputation: Disabled
and what is the advantage of using memory mapped io than iowrite/read32 API? I saw only one that write/reads are secured with spinlock. Apart from there is different API to write and read and I don't see any other advantage.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] I don't understand how this bash function works in mkinitrd_command_generator.sh jheengut Slackware 2 08-05-2018 07:06 AM
Trying to understand this function in Javascript resetreset Programming 7 12-09-2010 03:51 PM
[SOLVED] Threaded function cannot call a function with extern "C" but nonthreaded function can morty346 Programming 16 01-12-2010 05:00 PM
How to understand chdir function? xeon123 Programming 1 10-15-2007 05:53 PM
my firewall script: unable to understand its function Niceman2005 Linux - Security 3 11-16-2005 07:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration