Skip to content

Commit

Permalink
Add some devices to FDT (Flattened Device Tree)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzw29107 committed Sep 13, 2024
1 parent 30b4ba3 commit 348ca19
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,14 @@ jobs:

- name: 'Install software packages'
if: ${{ matrix.arch == 'x64' }}
run: sudo apt-get install libglib2.0-dev libfdt-dev libpixman-1-dev ninja-build libaio-dev libbluetooth-dev libcapstone-dev libbrlapi-dev libbz2-dev libcap-ng-dev libcurl4-gnutls-dev libgtk-3-dev libibverbs-dev libjpeg8-dev libnuma-dev librbd-dev librdmacm-dev libsasl2-dev libsdl2-dev libseccomp-dev libsnappy-dev libssh-dev libvde-dev libvdeplug-dev libvte-2.91-dev libxen-dev liblzo2-dev valgrind xfslibs-dev libnfs-dev libiscsi-dev
run: |
sudo apt update
sudo apt-get install libglib2.0-dev libfdt-dev libpixman-1-dev ninja-build libaio-dev libbluetooth-dev libcapstone-dev libbrlapi-dev libbz2-dev libcap-ng-dev libcurl4-gnutls-dev libgtk-3-dev libibverbs-dev libjpeg8-dev libnuma-dev librbd-dev librdmacm-dev libsasl2-dev libsdl2-dev libseccomp-dev libsnappy-dev libssh-dev libvde-dev libvdeplug-dev libvte-2.91-dev libxen-dev liblzo2-dev valgrind xfslibs-dev libnfs-dev libiscsi-dev
- name: 'Install software packages (for cross build)'
if: ${{ matrix.arch == 'aarch64' }}
run: |
sudo apt update
sudo apt-get install gcc-aarch64-linux-gnu ninja-build
sudo dpkg --add-architecture arm64
sudo sed -i '/Types/{N;N;N;N;N;N;N;N;N;N;N;N;s/\(Types.*\n.*\)archive\(.*\)\/ubuntu\(.*\n.*\n.*\n.*gpg\)\(\n\n.*\n.*\n\)\(Types.*\n.*\)archive\(.*\)\/ubuntu\(.*\n.*\n.*\n.*gpg\)/\1archive\2\/ubuntu\3\nArchitectures: amd64\n\n\1ports\2\/ubuntu-ports\3\nArchitectures: arm64\4\5archive\6\/ubuntu\7\nArchitectures: amd64\n\n\5ports\6\/ubuntu-ports\7\nArchitectures: arm64/}' /etc/apt/sources.list.d/ubuntu.sources
Expand Down
46 changes: 45 additions & 1 deletion hw/arm/virt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,32 +1428,67 @@ static void sdhci_attach_drive(DeviceState *sdhci, DriveInfo *dinfo, bool emmc)

static void create_ehci(const VirtMachineState *vms)
{
MachineState *ms = MACHINE(vms);
hwaddr base = vms->memmap[VIRT_EHCI_XHCI].base;
hwaddr size = vms->memmap[VIRT_EHCI_XHCI].size;
int irq = vms->irqmap[VIRT_EHCI_XHCI];
const char compat[] = "generic-ehci";
const char irq_names[] = "usb";
char *node;

sysbus_create_simple("platform-ehci-usb", base,
qdev_get_gpio_in(vms->gic, irq));

node = g_strdup_printf("/usb@%" PRIx64, base);
qemu_fdt_add_subnode(ms->fdt, node);
qemu_fdt_setprop(ms->fdt, node, "compatible", compat, sizeof(compat));
qemu_fdt_setprop_sized_cells(ms->fdt, node, "reg", 2, base, 2, size);
qemu_fdt_setprop(ms->fdt, node, "dma-coherent", NULL, 0);
qemu_fdt_setprop_cells(ms->fdt, node, "interrupts", irq, 0);
qemu_fdt_setprop(ms->fdt, node, "interrupt-names", irq_names,
sizeof(irq_names));
g_free(node);
}

static void create_xhci(const VirtMachineState *vms)
{
MachineState *ms = MACHINE(vms);
hwaddr base = vms->memmap[VIRT_EHCI_XHCI].base;
hwaddr size = vms->memmap[VIRT_EHCI_XHCI].size;
int irq = vms->irqmap[VIRT_EHCI_XHCI];
const char compat[] = "generic-xhci";
const char irq_names[] = "usb";
char *node;

DeviceState *dev = qdev_new(TYPE_XHCI_SYSBUS);
qdev_prop_set_uint32(dev, "slots", XHCI_MAXSLOTS);

sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, qdev_get_gpio_in(vms->gic, irq));

node = g_strdup_printf("/usb@%" PRIx64, base);
qemu_fdt_add_subnode(ms->fdt, node);
qemu_fdt_setprop(ms->fdt, node, "compatible", compat, sizeof(compat));
qemu_fdt_setprop_sized_cells(ms->fdt, node, "reg", 2, base, 2, size);
qemu_fdt_setprop(ms->fdt, node, "dma-coherent", NULL, 0);
qemu_fdt_setprop_cells(ms->fdt, node, "#stream-id-cells", 1);
qemu_fdt_setprop_cells(ms->fdt, node, "interrupts", irq, 0);
qemu_fdt_setprop(ms->fdt, node, "interrupt-names", irq_names,
sizeof(irq_names));
g_free(node);
}

static void create_sdhci(const VirtMachineState *vms)
{

MachineState *ms = MACHINE(vms);
hwaddr base = vms->memmap[VIRT_SDHCI].base;
hwaddr size = vms->memmap[VIRT_SDHCI].size;
int irq = vms->irqmap[VIRT_SDHCI];
DeviceState *dev;
SysBusDevice *busdev;
const char compat[] = "sdhci";
const char irq_names[] = "sdhci";

dev = qdev_new(TYPE_SYSBUS_SDHCI);
qdev_prop_set_uint64(dev, "capareg", VIRT_SDHCI_CAPABILITIES);
Expand All @@ -1464,6 +1499,15 @@ static void create_sdhci(const VirtMachineState *vms)
sysbus_mmio_map(busdev, 0, base);
sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(vms->gic, irq));

char *node = g_strdup_printf("/sdhci@%" PRIx64, base);
qemu_fdt_add_subnode(ms->fdt, node);
qemu_fdt_setprop_cells(ms->fdt, node, "interrupts", irq, 0);
qemu_fdt_setprop_sized_cells(ms->fdt, node, "reg", 2, base, 2, size);
qemu_fdt_setprop(ms->fdt, node, "compatible", compat, sizeof(compat));
qemu_fdt_setprop(ms->fdt, node, "interrupt-names", irq_names,
sizeof(irq_names));
g_free(node);

sdhci_attach_drive(dev, drive_get(IF_SD, 0, 0), true);
}

Expand Down

0 comments on commit 348ca19

Please sign in to comment.