ARM64 Port Status

I pushed current WIP code there: Commits · Milek7/haiku-work · GitHub
I did not reuse much existing code from efi loader or that linked github earlier, but that’s just because I needed some practice with how it all works, we will need to decide later which approach use for upstreaming.

I run it in qemu like that:

qemu-system-aarch64 -bios /usr/share/edk2/aarch64/QEMU_EFI-pflash.raw -M virt -device ramfb -cpu max -no-acpi -drive file=~/haiku/build/haiku-mmc.image,format=raw,id=d0,if=none -device virtio-blk-device,drive=d0

If you want to try it on different device it needs updating kernel debug serial in arch_debug_console.cpp, currently it’s hardcoded there to pl011@0x9000000. (and likely add appropiate device memory mapping in efi loader, in kernel address space)
In qemu it runs all the way up to PANIC: did not find any boot partitions!, but hardware is less forgiving so I would expect some snags there :wink:

12 Likes

KDL console now works.

36 Likes

Out of curiosity: does the console message “module: Search for bus_managers/pci/x86/v1 failed.” mean the code still uses some x86 specific code?

No. Drivers ask PCI MSI interrupts module that is currently declared as “x86-specific”, but actually it isn’t. MSI interrupt handling is a part of PCI Express specification and available on all hardware that support it including RISC-V and ARM.

3 Likes

Nice work! the UART commit is still pending to be merged

I’ll be incorporating other parts for the next commit on properly dealing with an ongoing MMU in EL1 in EFI.

Let me remark that:

Will fail, as that position is not covered by the MMU, I see in your next commit that you opened the whole kernel virtual range, avoiding the commented fail. Can you explain?

1 Like

64 bit Haiku kernels (x86_64, riscv64) use linear mapping of whole RAM for easy and efficient access to physical memory. So physical RAM addresses can be converted to virtual by adding some fixed offset value.

5 Likes

Why? This is stack top, so only memory below this address should be used. - 8 seems wrong, AAPCS64 ABI requires that stack is 16-byte aligned, and it will probably fault on hardware when SCTLR_EL1.SA bit is set. - 16 would be fine but I don’t see reason for subtracting here.

This is linear mapping that is used by PhysicalPageMapper to access memory directly. (instead of mapping it in-and-out which is necessary on 32-bit platforms, when there isn’t enough virtual address space to cover all memory). Note that mapping everything like that works fine only for qemu, for hardware we also want this linear mapping but it needs to be changed to map only areas covering physical RAM (otherwise speculative access might cause unwanted MMIO reads or bus SError).

3 Likes

As far as I remember:

map 0xffff000002000000 --> 0xf9caf000, len=0x10000, flags=0x7

This was the mapping for the kernel Stack, this involves MMU covers from 0xffff000002000000 to 0xFFFF00000200FFFF.

Writting 0xFFFF000002010000(top+size) to the stack registers provoked an exeception, because that address is already in the next page (not covered by MMU). That is the reason of the substraction.

Alright… hybrid kernels. Maybe is not feasible but I would delay that as much as possible in the progress of the port, to catch as soon a possible unintented acceses & bugs.

Understood, Indeed that mappìng won’t work for me (at physical 0x0 is the mappping of the xSPI controller)

Thank you both!

More icons:

I didn’t push the code yet because it’s too hardcoded.
I’m having trouble with PCI controller discovery because it seems pci_controller_init is getting called at the beginning, but I need information from acpi/devicetree which is only parsed later.

x86 code parses acpi MCFG manually, but that’s not enough here because while it contains config space address, I/O ranges information are accessed through PNP0A03 _CRS method, thus it requires fully parsed acpi namespace.

riscv uses devicetree and binds root module in proper place by filtering in pci_root_supports_device, but I’m not sure how it resolves the problem that by the point this device is discovered pci_controller_init was already called earlier.

25 Likes

If I remember correctly PCI module loading fails if FDT node is not found (not yest registered etc.). So PCI module will be functional if accessed after publishing FDT bus nodes. If it is accessed before, it will load, fail and unload, potentially multiple times.

I think that PCI initialization should be reworked to have initially empty bus with no host controllers and then dynamically register PCI host controllers during ACPI/FDT bus enumeration. Hot pluggable PCI devices also exist.

2 Likes

I think it would make sense to rewrite how ACPI is initialised, it is a bigger task though. ACPI spec expects it to be done very early as well, but we do it quite late in boot.

1 Like

I’m working on this for my (x86_64, boring) laptop.

It is not possible to have the PCI module depend on the ACPI module at the kernel level because the ACPI module depends on the PCI one currently. So the kernel complains about a circular dependency.

What I did so far:

  • Change the support_device function so that the PCI root supports the ACPI PNP0A03 device node, instead of the “root” device node. This is similar to what is done for FDT for RISC-V.

What I did not do yet:

  • In the device initialization, load the ACPI module, use it to call the _CRS method, and parse the result.

I will submit my patch to Gerrit in a few hours when I’m back home.

7 Likes

https://antmicro.com/blog/2022/04/open-source-snapdragon-845-baseboard/

Here you go: https://review.haiku-os.org/c/haiku/+/5182

Hope it helps.

6 Likes

But here’s the issue, by the time root binds to proper node, pci_controller_init was already called. I worked it around like that, but that’s rather ugly: pci deferred init · Milek7/haiku-work@dbb65cd · GitHub

2 Likes

Is RPI4 build able to print anything on uart? I have build Haiku ARM for rpi4. Here’s what happens.

Once I use the dd command to burn haiku-rpi4.mmc to the sd card, SD is not being able to mount again after the dd command. I get following error when I try to mount the sd card:

mount: /mnt: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error.
       dmesg(1) may have more information after failed mount system call.

Also, there’s no uart output with the sdcard too. Is there anything wrong that i’m doing??

It seems run Linux kernel, not Haiku.

So haiku is not yet ported to RPI4 :frowning:

I tried the arm64 port on rpi3 so far, there are still a few issues that we’re trying to iron out with @oruizdorantes
I expect the rpi4 would be a bit more difficult as /chosen/std-path seems to be missing from the device tree, so I’m not sure if the bootloader can recognize the mini-UART

but maybe we need to go back one step:

  • how did you prepare the SD card, what is the exact command?
  • how does your config.txt look like?
  • are you trying to boot Haiku with u-boot or TianoCore?

@Milek7 seems use ACPI, not FDT: discover uart from acpi · Milek7/haiku-work@d91cf63 · GitHub.