Page MenuHomeFreeBSD

Remap UART physical address through simple-bus ranges
AbandonedPublic

Authored by bsz_semihalf.com on Nov 19 2015, 12:30 PM.
Tags
Referenced Files
Unknown Object (File)
Fri, Dec 20, 4:45 PM
Unknown Object (File)
Wed, Dec 11, 1:49 AM
Unknown Object (File)
Thu, Dec 5, 4:13 PM
Unknown Object (File)
Sep 26 2024, 2:47 PM
Unknown Object (File)
Sep 20 2024, 4:15 AM
Unknown Object (File)
Sep 18 2024, 3:42 PM
Unknown Object (File)
Sep 18 2024, 1:30 PM
Unknown Object (File)
Sep 18 2024, 12:49 AM

Details

Summary

Kernel console init routine mapped the physical address of UART using only
the 'ranges' property of its immediate parent. However, further parents
may also have address space mappings and they need to be taken into account
to calculate the final physical base address of UART registers.

This commit adds a translation routine similar to
simplebus_alloc_resource() which remaps the address through all simple-bus
parents of the UART node.

NOTE: buffers for ranges data are placed on the stack as malloc cannot be used so early in the kernel.

Obtained from: Semihalf
Sponsored by: Stormshield
Submitted by: Michal Stanek <mst@semihalf.com>

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

bsz_semihalf.com retitled this revision from to Remap UART physical address through simple-bus ranges.
bsz_semihalf.com updated this object.
bsz_semihalf.com edited the test plan for this revision. (Show Details)
bsz_semihalf.com added reviewers: ian, imp.
bsz_semihalf.com set the repository for this revision to rS FreeBSD src repository - subversion.
bsz_semihalf.com added a project: ARM.
bsz_semihalf.com added a subscriber: zbb.
imp requested changes to this revision.Nov 19 2015, 2:51 PM
imp edited edge metadata.

I'd think we'd want this mapping in simplebus itself, or at the very least this function.

sys/dev/uart/uart_cpu_fdt.c
250

Why is this in uart? Isn't this a more generic problem with cascaded simple-bus
typologies?

This revision now requires changes to proceed.Nov 19 2015, 2:51 PM
bsz_semihalf.com edited edge metadata.

Function moved to simplebus' code.

sys/dev/uart/uart_cpu_fdt.c
243–347

imp, please let me know if updated diff looks fine to you, so we can commit the patch series.

Why doesn't fdt_get_ranges work? It should already walk up the tree.

In D4217#94426, @andrew wrote:

Why doesn't fdt_get_ranges work?

This should say: Why doesn't fdt_get_range work?
i.e. the no trailing s.

In D4217#95770, @andrew wrote:
In D4217#94426, @andrew wrote:

Why doesn't fdt_get_ranges work?

This should say: Why doesn't fdt_get_range work?
i.e. the no trailing s.

After spending some time digging through the various code we have that tries to process ranges properties (existing implementations fdt_reg_to_rl(), fdt_get_range(), fdt_get_range_by_busaddr(), and their callers) it looks like this new simplebus_get_base_addr() is the only implementation that actually does it correctly. The only problem I'm seeing with it is that the operation is not really specific to simplebus -- according to ePAPR any node that has children can have a ranges property.

I think it's probably not fair to ask semihalf to drain this whole swamp (now that it has become clear that we are standing in the middle of a swamp) before committing this fix.

We could let this be committed as-is, and then come along later and refactor it to be less simplebus-specific and clean up all the callers of the old routines at that time. It might make sense to do that after D4544 expands the size of rman-managed data using a new typedef, then we can redefine this fdt stuff that works with address resources in terms of that datatype.

imp edited edge metadata.

While I'd prefer that we fix the underlying issue, I'm happy to go along with Ian's suggestion.

This revision is now accepted and ready to land.Dec 17 2015, 7:52 PM
nwhitehorn added a reviewer: nwhitehorn.
nwhitehorn added a subscriber: nwhitehorn.

This is not a simplebus-specific thing. What should happen is something like OF_decode_addr() in /sys/powerpc/ofw/ofw_machdep.c (or exactly that function). In simplebus, the resource decoding using newbus allocation cascading to achieve this. Early boot (for UARTs) has different requirements and needs addresses cascaded all the way to CPU space. OF_decode_addr() is mostly not MD and I think would work as-is on ARM. You can see how it is used in uart_cpu_powerpc.c.

This revision now requires changes to proceed.Dec 18 2015, 4:19 PM

After talking with Nathan about this on irc, I extracted the MI parts of the powerpc OF_decode_addr() to a new common subroutine, then used that to implement OF_decode_addr() on arm. That should now be the correct way to do the translation of the reg to a bus_space tag and handle.

That change is in D4664.

Now that OF_decode_addr() works on all fdt/ofw platforms (after r292579), it's the right way to set up early console access. Unfortunately, even though phabricator is supposed to be a collaboration tool, I can't update the diff attached to this revision, so I created a new revision D4675 to replace this one.

Abandoned because D4675 replaces it.