I want to print real physical address that is stored in a variable of type phys_addr_t. Now I'm doing something like this:
phys_addr_t paddr;
...
paddr = virt_to_phys(some_virt_addr);
pr_info("%pa", &paddr);
...
As for documentation:
Physical addresses types ``phys_addr_t``
========================================
::
%pa[p] 0x01234567 or 0x0123456789abcdef
For printing a ``phys_addr_t`` type (and its derivatives, such as
``resource_size_t``) which can vary based on build options, regardless of
the width of the CPU data path. Passed by reference.
but I'm a bit confused about Passed by reference, because it is already something like reference. So my actual questions are:
- How to correctly print
phys_addr_tusingprintk? - What does
Passed by referencemean here? - What does the
[p]postfix of%pa[p]mean?
If my example is not correct or inefficient, please show me how it should be.
You are doing it correctly:
"Pass by reference" means to pass a pointer to the physical address you want to print (
&paddr) instead of directly passing its value (paddr).The
[p]suffix in the documentation means that the lastpis optional. You can use%paor%pap. The finalpis not necessary and also doesn't change the output format (as you can see from the source here).