All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v3] drivers: core: Add translation in live tree case
@ 2017-12-18  8:34 Mario Six
  2017-12-18 22:29 ` Stephen Warren
  0 siblings, 1 reply; 5+ messages in thread
From: Mario Six @ 2017-12-18  8:34 UTC (permalink / raw)
  To: u-boot

The function dev_read_addr calls ofnode_get_addr_index in the live tree
case, which does not apply bus translations to the address read from the
device tree. This results in illegal addresses on boards that rely on
bus translations being applied.

Fix this situation by applying bus translations in the live tree case as
well.

Signed-off-by: Mario Six <mario.six@gdsys.cc>

---

v2 -> v3:
* Fixed endianness issue on little-endian platforms

v1 -> v2:
* Added IS_ENABLED(CONFIG_OF_TRANSLATE) case distinction

 drivers/core/ofnode.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 0030ab962e..09f0aeab4f 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -200,13 +200,22 @@ fdt_addr_t ofnode_get_addr_index(ofnode node, int index)
 		uint flags;
 		u64 size;
 		int na;
+		__be32 addr;

 		prop_val = of_get_address(ofnode_to_np(node), index, &size,
 					  &flags);
 		if (!prop_val)
 			return FDT_ADDR_T_NONE;
 		na = of_n_addr_cells(ofnode_to_np(node));
-		return of_read_number(prop_val, na);
+		addr = of_read_number(prop_val, na);
+
+		if (IS_ENABLED(CONFIG_OF_TRANSLATE)) {
+			u64 paddr = of_translate_address(ofnode_to_np(node), &addr);
+
+			return be32_to_cpu((fdt_addr_t)paddr);
+		} else {
+			return addr;
+		}
 	} else {
 		return fdt_get_base_address(gd->fdt_blob,
 					    ofnode_to_offset(node));
--
2.13.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v3] drivers: core: Add translation in live tree case
  2017-12-18  8:34 [U-Boot] [PATCH v3] drivers: core: Add translation in live tree case Mario Six
@ 2017-12-18 22:29 ` Stephen Warren
  2017-12-18 22:33   ` Stephen Warren
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Warren @ 2017-12-18 22:29 UTC (permalink / raw)
  To: u-boot

On 12/18/2017 01:34 AM, Mario Six wrote:
> The function dev_read_addr calls ofnode_get_addr_index in the live tree
> case, which does not apply bus translations to the address read from the
> device tree. This results in illegal addresses on boards that rely on
> bus translations being applied.
> 
> Fix this situation by applying bus translations in the live tree case as
> well.

Tested-by: Stephen Warren <swarren@nvidia.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v3] drivers: core: Add translation in live tree case
  2017-12-18 22:29 ` Stephen Warren
@ 2017-12-18 22:33   ` Stephen Warren
  2017-12-18 23:03     ` Stephen Warren
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Warren @ 2017-12-18 22:33 UTC (permalink / raw)
  To: u-boot

On 12/18/2017 03:29 PM, Stephen Warren wrote:
> On 12/18/2017 01:34 AM, Mario Six wrote:
>> The function dev_read_addr calls ofnode_get_addr_index in the live tree
>> case, which does not apply bus translations to the address read from the
>> device tree. This results in illegal addresses on boards that rely on
>> bus translations being applied.
>>
>> Fix this situation by applying bus translations in the live tree case as
>> well.
> 
> Tested-by: Stephen Warren <swarren@nvidia.com>

Uggh. Sorry, I take that back. This seems to break NVIDIA Jetson TX1 
(p2371-2180 board), even though it did solve this issue that was present 
on other boards in the previous patch version. I'll try and see what's 
up (something to do with I2C accesses early during boot)...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v3] drivers: core: Add translation in live tree case
  2017-12-18 22:33   ` Stephen Warren
@ 2017-12-18 23:03     ` Stephen Warren
  2017-12-20  9:00       ` Mario Six
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Warren @ 2017-12-18 23:03 UTC (permalink / raw)
  To: u-boot

On 12/18/2017 03:33 PM, Stephen Warren wrote:
> On 12/18/2017 03:29 PM, Stephen Warren wrote:
>> On 12/18/2017 01:34 AM, Mario Six wrote:
>>> The function dev_read_addr calls ofnode_get_addr_index in the live tree
>>> case, which does not apply bus translations to the address read from the
>>> device tree. This results in illegal addresses on boards that rely on
>>> bus translations being applied.
>>>
>>> Fix this situation by applying bus translations in the live tree case as
>>> well.
>>
>> Tested-by: Stephen Warren <swarren@nvidia.com>
> 
> Uggh. Sorry, I take that back. This seems to break NVIDIA Jetson TX1 
> (p2371-2180 board), even though it did solve this issue that was present 
> on other boards in the previous patch version. I'll try and see what's 
> up (something to do with I2C accesses early during boot)...

I guess this is something to do with:

> +		if (IS_ENABLED(CONFIG_OF_TRANSLATE)) {
> +			u64 paddr = of_translate_address(ofnode_to_np(node), &addr);
> +
> +			return be32_to_cpu((fdt_addr_t)paddr);

My tests passed on a 32-bit platform but failed on a 64-bit platform. I 
expect you need be64_to_cpu() there on 64-bit platforms? Actually, it 
should really base the bit-width on #address-cells, but we only support 
32- or 64-bit at the moment so switching between the two is probably fine.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v3] drivers: core: Add translation in live tree case
  2017-12-18 23:03     ` Stephen Warren
@ 2017-12-20  9:00       ` Mario Six
  0 siblings, 0 replies; 5+ messages in thread
From: Mario Six @ 2017-12-20  9:00 UTC (permalink / raw)
  To: u-boot

On Tue, Dec 19, 2017 at 12:03 AM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> On 12/18/2017 03:33 PM, Stephen Warren wrote:
>>
>> On 12/18/2017 03:29 PM, Stephen Warren wrote:
>>>
>>> On 12/18/2017 01:34 AM, Mario Six wrote:
>>>>
>>>> The function dev_read_addr calls ofnode_get_addr_index in the live tree
>>>> case, which does not apply bus translations to the address read from the
>>>> device tree. This results in illegal addresses on boards that rely on
>>>> bus translations being applied.
>>>>
>>>> Fix this situation by applying bus translations in the live tree case as
>>>> well.
>>>
>>>
>>> Tested-by: Stephen Warren <swarren@nvidia.com>
>>
>>
>> Uggh. Sorry, I take that back. This seems to break NVIDIA Jetson TX1
>> (p2371-2180 board), even though it did solve this issue that was present on
>> other boards in the previous patch version. I'll try and see what's up
>> (something to do with I2C accesses early during boot)...
>
>
> I guess this is something to do with:
>
>> +               if (IS_ENABLED(CONFIG_OF_TRANSLATE)) {
>> +                       u64 paddr =
>> of_translate_address(ofnode_to_np(node), &addr);
>> +
>> +                       return be32_to_cpu((fdt_addr_t)paddr);
>
>
> My tests passed on a 32-bit platform but failed on a 64-bit platform. I
> expect you need be64_to_cpu() there on 64-bit platforms? Actually, it should
> really base the bit-width on #address-cells, but we only support 32- or
> 64-bit at the moment so switching between the two is probably fine.
>

Just sent a v4, which will hopefully fix this for all platforms. I tested with
32-bit and 64-bit sandbox, and I now get the same result with and without
translation for both.

@Simon: I also sent a RFC patch for a sandbox with 64-bit addresses, since it
might be useful for testing.

Best regards,

Mario

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-12-20  9:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-18  8:34 [U-Boot] [PATCH v3] drivers: core: Add translation in live tree case Mario Six
2017-12-18 22:29 ` Stephen Warren
2017-12-18 22:33   ` Stephen Warren
2017-12-18 23:03     ` Stephen Warren
2017-12-20  9:00       ` Mario Six

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.