cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
zouyu930503
Adventurer
Adventurer
605 Views
Registered: ‎07-28-2018

64-bit device tree platform_get_resource()

Jump to solution

I have gone through all materials that I could find, but no one answered my question.

In ZynqMP, peripherals are defined as 64-bit because of 64-bit ARM.

In my case, I have a custom peripheral, which is defined in the device tree as:

#address-cells = <2>;

#size-cells=<2>;

....................

reg=<0x00000004 0x20000000 0x0 0x1000>;

 

How could I get this address using platform_get_resource()?

platform_get_resource(pdev, IORESOURCE_MEM, 0) only returned lower 32 bits.

 

Thx

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ksloatdesignlinx
Explorer
Explorer
445 Views
Registered: ‎02-24-2020

So I tried your original example (with IORESOURCE_MEM) on a ZynqMP with a simple kernel module and I can see all 64 bits of the address.

For your test, how are you checking how many bits that platform_get_resource() returns? Are you using printk? If you are using printk you will need to specify a long hex type otherwise it will chop your variable to 32 bits:

i.e. 

 

printk("Device memory starts at 0x%lx\n", r_mem->start);

 

[   25.753498] Device memory starts at 0x420000000

 

Note that looking at the kernel, resource address types are defined based on the config of the kernel, so because this system supports 64 bit physical addresses then the types are set accordingly at kernel compile time.

// from linux/types.h
#ifdef CONFIG_PHYS_ADDR_T_64BIT typedef u64 phys_addr_t; #else typedef u32 phys_addr_t; #endif typedef phys_addr_t resource_size_t;
Ken Sloat - Embedded Software Engineer
https://www.designlinxhs.com

View solution in original post

3 Replies
ksloatdesignlinx
Explorer
Explorer
575 Views
Registered: ‎02-24-2020

What happens if you use IORESOURCE_MEM_64?

Ken Sloat - Embedded Software Engineer
https://www.designlinxhs.com
0 Kudos
zouyu930503
Adventurer
Adventurer
527 Views
Registered: ‎07-28-2018

If using IORESOURCE_MEM_64, platform_get_resource() failed. And a kernel panic "Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000" was reported.

0 Kudos
ksloatdesignlinx
Explorer
Explorer
446 Views
Registered: ‎02-24-2020

So I tried your original example (with IORESOURCE_MEM) on a ZynqMP with a simple kernel module and I can see all 64 bits of the address.

For your test, how are you checking how many bits that platform_get_resource() returns? Are you using printk? If you are using printk you will need to specify a long hex type otherwise it will chop your variable to 32 bits:

i.e. 

 

printk("Device memory starts at 0x%lx\n", r_mem->start);

 

[   25.753498] Device memory starts at 0x420000000

 

Note that looking at the kernel, resource address types are defined based on the config of the kernel, so because this system supports 64 bit physical addresses then the types are set accordingly at kernel compile time.

// from linux/types.h
#ifdef CONFIG_PHYS_ADDR_T_64BIT typedef u64 phys_addr_t; #else typedef u32 phys_addr_t; #endif typedef phys_addr_t resource_size_t;
Ken Sloat - Embedded Software Engineer
https://www.designlinxhs.com

View solution in original post