Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qemu: add devicetree support for arm64 #10125

Merged
merged 1 commit into from Aug 10, 2023
Merged

Conversation

leo11261
Copy link
Contributor

@leo11261 leo11261 commented Aug 9, 2023

Summary

add devicetree support for qemu arm64. according to https://www.qemu.org/docs/master/system/arm/virt.html#hardware-configuration-information-for-bare-metal-programming

Impact

The FDT provided by QEMU is now available to the kernel and userspace through procfs for arm64.

Testing

internel testing of qemu arm64 . Use fdtdump provided by apache/nuttx-apps#1916 and #10121 to show fdt like below:

fdtdump /proc/fdt

**** fdtdump is a low-level debugging tool, not meant for general use.
**** If you want to decompile a dtb, you probably want
****     dtc -I dtb -O dts <filename>

/dts-v1/;
// magic:               0xd00dfeed
// totalsize:           0x100000 (1048576)
// off_dt_struct:       0x40
// off_dt_strings:      0x1bbc
// off_mem_rsvmap:      0x30
// version:             17
// last_comp_version:   16
// boot_cpuid_phys:     0x0
// size_dt_strings:     0x1e8
// size_dt_struct:      0x1b7c

/ {
    interrupt-parent = <0x00008002>;
    model = "linux,dummy-virt";
    #size-cells = <0x00000002>;
    #address-cells = <0x00000002>;
    compatible = "linux,dummy-virt";
    psci {
        migrate = <0xc4000005>;
        cpu_on = <0xc4000003>;
        cpu_off = <0x84000002>;
        cpu_suspend = <0xc4000001>;
        method = "smc";
        compatible = "arm,psci-1.0", "arm,psci-0.2", "arm,psci";
    };
    memory@40000000 {
        reg = <0x00000000 0x40000000 0x00000000 0x08000000>;
        device_type = "memory";
    };
    platform-bus@c000000 {
        interrupt-parent = <0x00008002>;
        ranges = <0x00000000 0x00000000 0x0c000000 0x02000000>;
        #address-cells = <0x00000001>;
        #size-cells = <0x00000001>;
        compatible = "qemu,platform", "simple-bus";
    };
    fw-cfg@9020000 {
        dma-coherent;
        reg = <0x00000000 0x09020000 0x00000000 0x00000018>;
        compatible = "qemu,fw-cfg-mmio";
    };
    virtio_mmio@a000000 {
        dma-coherent;
        interrupts = <0x00000000 0x00000010 0x00000001>;
        reg = <0x00000000 0x0a000000 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a000200 {
        dma-coherent;
        interrupts = <0x00000000 0x00000011 0x00000001>;
        reg = <0x00000000 0x0a000200 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a000400 {
        dma-coherent;
        interrupts = <0x00000000 0x00000012 0x00000001>;
        reg = <0x00000000 0x0a000400 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a000600 {
        dma-coherent;
        interrupts = <0x00000000 0x00000013 0x00000001>;
        reg = <0x00000000 0x0a000600 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a000800 {
        dma-coherent;
        interrupts = <0x00000000 0x00000014 0x00000001>;
        reg = <0x00000000 0x0a000800 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a000a00 {
        dma-coherent;
        interrupts = <0x00000000 0x00000015 0x00000001>;
        reg = <0x00000000 0x0a000a00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a000c00 {
        dma-coherent;
        interrupts = <0x00000000 0x00000016 0x00000001>;
        reg = <0x00000000 0x0a000c00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a000e00 {
        dma-coherent;
        interrupts = <0x00000000 0x00000017 0x00000001>;
        reg = <0x00000000 0x0a000e00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a001000 {
        dma-coherent;
        interrupts = <0x00000000 0x00000018 0x00000001>;
        reg = <0x00000000 0x0a001000 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a001200 {
        dma-coherent;
        interrupts = <0x00000000 0x00000019 0x00000001>;
        reg = <0x00000000 0x0a001200 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a001400 {
        dma-coherent;
        interrupts = <0x00000000 0x0000001a 0x00000001>;
        reg = <0x00000000 0x0a001400 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a001600 {
        dma-coherent;
        interrupts = <0x00000000 0x0000001b 0x00000001>;
        reg = <0x00000000 0x0a001600 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a001800 {
        dma-coherent;
        interrupts = <0x00000000 0x0000001c 0x00000001>;
        reg = <0x00000000 0x0a001800 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a001a00 {
        dma-coherent;
        interrupts = <0x00000000 0x0000001d 0x00000001>;
        reg = <0x00000000 0x0a001a00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a001c00 {
        dma-coherent;
        interrupts = <0x00000000 0x0000001e 0x00000001>;
        reg = <0x00000000 0x0a001c00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a001e00 {
        dma-coherent;
        interrupts = <0x00000000 0x0000001f 0x00000001>;
        reg = <0x00000000 0x0a001e00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a002000 {
        dma-coherent;
        interrupts = <0x00000000 0x00000020 0x00000001>;
        reg = <0x00000000 0x0a002000 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a002200 {
        dma-coherent;
        interrupts = <0x00000000 0x00000021 0x00000001>;
        reg = <0x00000000 0x0a002200 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a002400 {
        dma-coherent;
        interrupts = <0x00000000 0x00000022 0x00000001>;
        reg = <0x00000000 0x0a002400 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a002600 {
        dma-coherent;
        interrupts = <0x00000000 0x00000023 0x00000001>;
        reg = <0x00000000 0x0a002600 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a002800 {
        dma-coherent;
        interrupts = <0x00000000 0x00000024 0x00000001>;
        reg = <0x00000000 0x0a002800 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a002a00 {
        dma-coherent;
        interrupts = <0x00000000 0x00000025 0x00000001>;
        reg = <0x00000000 0x0a002a00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a002c00 {
        dma-coherent;
        interrupts = <0x00000000 0x00000026 0x00000001>;
        reg = <0x00000000 0x0a002c00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a002e00 {
        dma-coherent;
        interrupts = <0x00000000 0x00000027 0x00000001>;
        reg = <0x00000000 0x0a002e00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a003000 {
        dma-coherent;
        interrupts = <0x00000000 0x00000028 0x00000001>;
        reg = <0x00000000 0x0a003000 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a003200 {
        dma-coherent;
        interrupts = <0x00000000 0x00000029 0x00000001>;
        reg = <0x00000000 0x0a003200 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a003400 {
        dma-coherent;
        interrupts = <0x00000000 0x0000002a 0x00000001>;
        reg = <0x00000000 0x0a003400 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a003600 {
        dma-coherent;
        interrupts = <0x00000000 0x0000002b 0x00000001>;
        reg = <0x00000000 0x0a003600 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a003800 {
        dma-coherent;
        interrupts = <0x00000000 0x0000002c 0x00000001>;
        reg = <0x00000000 0x0a003800 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a003a00 {
        dma-coherent;
        interrupts = <0x00000000 0x0000002d 0x00000001>;
        reg = <0x00000000 0x0a003a00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a003c00 {
        dma-coherent;
        interrupts = <0x00000000 0x0000002e 0x00000001>;
        reg = <0x00000000 0x0a003c00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    virtio_mmio@a003e00 {
        dma-coherent;
        interrupts = <0x00000000 0x0000002f 0x00000001>;
        reg = <0x00000000 0x0a003e00 0x00000000 0x00000200>;
        compatible = "virtio,mmio";
    };
    gpio-keys {
        compatible = "gpio-keys";
        poweroff {
            gpios = <0x00008004 0x00000003 0x00000000>;
            linux,code = <0x00000074>;
            label = "GPIO Key Poweroff";
        };
    };
    pl061@9030000 {
        phandle = <0x00008004>;
        clock-names = "apb_pclk";
        clocks = <0x00008000>;
        interrupts = <0x00000000 0x00000007 0x00000004>;
        gpio-controller;
        #gpio-cells = <0x00000002>;
        compatible = "arm,pl061", "arm,primecell";
        reg = <0x00000000 0x09030000 0x00000000 0x00001000>;
    };
    pcie@10000000 {
        interrupt-map-mask = <0x00001800 0x00000000 0x00000000 0x00000007>;
        interrupt-map = <0x00000000 0x00000000 0x00000000 0x00000001 0x00008002 0x00000000 0x00000000 0x00000000 0x00000003 0x00000004 0x00000000 0x00000000 0x00000000 0x00000002 0x00008002 0x00000000 0x00000000 0x00000000 0x00000004 0x00000004 0x00000000 0x00000000 0x00000000 0x00000003 0x00008002 0x00000000 0x00000000 0x00000000 0x00000005 0x00000004 0x00000000 0x00000000 0x00000000 0x00000004 0x00008002 0x00000000 0x00000000 0x00000000 0x00000006 0x00000004 0x00000800 0x00000000 0x00000000 0x00000001 0x00008002 0x00000000 0x00000000 0x00000000 0x00000004 0x00000004 0x00000800 0x00000000 0x00000000 0x00000002 0x00008002 0x00000000 0x00000000 0x00000000 0x00000005 0x00000004 0x00000800 0x00000000 0x00000000 0x00000003 0x00008002 0x00000000 0x00000000 0x00000000 0x00000006 0x00000004 0x00000800 0x00000000 0x00000000 0x00000004 0x00008002 0x00000000 0x00000000 0x00000000 0x00000003 0x00000004 0x00001000 0x00000000 0x00000000 0x00000001 0x00008002 0x00000000 0x00000000 0x00000000 0x00000005 0x00000004 0x00001000 0x00000000 0x00000000 0x00000002 0x00008002 0x00000000 0x00000000 0x00000000 0x00000006 0x00000004 0x00001000 0x00000000 0x00000000 0x00000003 0x00008002 0x00000000 0x00000000 0x00000000 0x00000003 0x00000004 0x00001000 0x00000000 0x00000000 0x00000004 0x00008002 0x00000000 0x00000000 0x00000000 0x00000004 0x00000004 0x00001800 0x00000000 0x00000000 0x00000001 0x00008002 0x00000000 0x00000000 0x00000000 0x00000006 0x00000004 0x00001800 0x00000000 0x00000000 0x00000002 0x00008002 0x00000000 0x00000000 0x00000000 0x00000003 0x00000004 0x00001800 0x00000000 0x00000000 0x00000003 0x00008002 0x00000000 0x00000000 0x00000000 0x00000004 0x00000004 0x00001800 0x00000000 0x00000000 0x00000004 0x00008002 0x00000000 0x00000000 0x00000000 0x00000005 0x00000004>;
        #interrupt-cells = <0x00000001>;
        ranges = <0x01000000 0x00000000 0x00000000 0x00000000 0x3eff0000 0x00000000 0x00010000 0x02000000 0x00000000 0x10000000 0x00000000 0x10000000 0x00000000 0x2eff0000 0x03000000 0x00000080 0x00000000 0x00000080 0x00000000 0x00000080 0x00000000>;
        reg = <0x00000040 0x10000000 0x00000000 0x10000000>;
        msi-map = <0x00000000 0x00008003 0x00000000 0x00010000>;
        dma-coherent;
        bus-range = <0x00000000 0x000000ff>;
        linux,pci-domain = <0x00000000>;
        #size-cells = <0x00000002>;
        #address-cells = <0x00000003>;
        device_type = "pci";
        compatible = "pci-host-ecam-generic";
    };
    pl031@9010000 {
        clock-names = "apb_pclk";
        clocks = <0x00008000>;
        interrupts = <0x00000000 0x00000002 0x00000004>;
        reg = <0x00000000 0x09010000 0x00000000 0x00001000>;
        compatible = "arm,pl031", "arm,primecell";
    };
    pl011@9000000 {
        clock-names = "uartclk", "apb_pclk";
        clocks = <0x00008000 0x00008000>;
        interrupts = <0x00000000 0x00000001 0x00000004>;
        reg = <0x00000000 0x09000000 0x00000000 0x00001000>;
        compatible = "arm,pl011", "arm,primecell";
    };
    pmu {
        interrupts = <0x00000001 0x00000007 0x00000004>;
        compatible = "arm,armv8-pmuv3";
    };
    intc@8000000 {
        phandle = <0x00008002>;
        interrupts = <0x00000001 0x00000009 0x00000004>;
        reg = <0x00000000 0x08000000 0x00000000 0x00010000 0x00000000 0x080a0000 0x00000000 0x00f60000>;
        #redistributor-regions = <0x00000001>;
        compatible = "arm,gic-v3";
        ranges;
        #size-cells = <0x00000002>;
        #address-cells = <0x00000002>;
        interrupt-controller;
        #interrupt-cells = <0x00000003>;
        its@8080000 {
            phandle = <0x00008003>;
            reg = <0x00000000 0x08080000 0x00000000 0x00020000>;
            #msi-cells = <0x00000001>;
            msi-controller;
            compatible = "arm,gic-v3-its";
        };
    };
    flash@0 {
        bank-width = <0x00000004>;
        reg = <0x00000000 0x00000000 0x00000000 0x04000000 0x00000000 0x04000000 0x00000000 0x04000000>;
        compatible = "cfi-flash";
    };
    cpus {
        #size-cells = <0x00000000>;
        #address-cells = <0x00000001>;
        cpu-map {
            socket0 {
                cluster0 {
                    core0 {
                        cpu = <0x00008001>;
                    };
                };
            };
        };
        cpu@0 {
            phandle = <0x00008001>;
            reg = <0x00000000>;
            compatible = "arm,cortex-a53";
            device_type = "cpu";
        };
    };
    timer {
        interrupts = <0x00000001 0x0000000d 0x00000004 0x00000001 0x0000000e 0x00000004 0x00000001 0x0000000b 0x00000004 0x00000001 0x0000000a 0x00000004>;
        always-on;
        compatible = "arm,armv8-timer", "arm,armv7-timer";
    };
    apb-pclk {
        phandle = <0x00008000>;
        clock-output-names = "clk24mhz";
        clock-frequency = <0x016e3600>;
        #clock-cells = <0x00000000>;
        compatible = "fixed-clock";
    };
    chosen {
        stdout-path = "/pl011@9000000";
        rng-seed = <0xfdef8195 0xfd33993d 0x64c1e1c8 0x9c00046e 0xfefd950e 0xffc5ac4e 0x8504f74c 0xa564df80>;
        kaslr-seed = <0x594b48b8 0xe7837d92>;
    };
};

@xiaoxiang781216
Copy link
Contributor

let's enable CONFIG_DEVICETREE in one of qemu boards config.

@acassis
Copy link
Contributor

acassis commented Aug 9, 2023

@leo11261 please include this Testing as a Documentation/ for users to use as reference

Signed-off-by: liaoao <liaoao@xiaomi.com>
@xiaoxiang781216 xiaoxiang781216 merged commit dffab1e into apache:master Aug 10, 2023
26 checks passed
@xiaoxiang781216
Copy link
Contributor

@leo11261 please create a new pr to add the description to documentation.

@@ -167,6 +171,10 @@ void arm64_chip_boot(void)

arm64_mmu_init(true);

#ifdef CONFIG_DEVICE_TREE
fdt_register((FAR const char *)0x40000000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiaoxiang781216 @leo11261 this should not be hard coded and instead extracted from the register as I did for rv.

See my comments here for arm and arm64

#9204 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but from https://www.qemu.org/docs/master/system/arm/virt.html?highlight=device%20tree%20blob, only -kernel with non-ELF file could get the fdt location from r2 or x0.

@leo11261 leo11261 deleted the dtb branch August 22, 2023 12:49
@jerpelea jerpelea added this to To-Add in Release Notes - 12.3.0 Sep 26, 2023
@jerpelea jerpelea moved this from To-Add to done in Release Notes - 12.3.0 Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants