From patchwork Wed Nov 11 00:28:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 542722 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 14EC51402A2 for ; Wed, 11 Nov 2015 11:58:29 +1100 (AEDT) Received: from localhost ([::1]:36718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwJjh-000368-Sx for incoming@patchwork.ozlabs.org; Tue, 10 Nov 2015 19:58:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwJJk-0003lg-BZ for qemu-devel@nongnu.org; Tue, 10 Nov 2015 19:31:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwJJj-0004pk-7e for qemu-devel@nongnu.org; Tue, 10 Nov 2015 19:31:16 -0500 Received: from gate.crashing.org ([63.228.1.57]:48700) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwJJi-0004pU-U1; Tue, 10 Nov 2015 19:31:15 -0500 Received: from pasglop.ozlabs.ibm.com. (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id tAB0Sb33024031; Tue, 10 Nov 2015 18:30:43 -0600 From: Benjamin Herrenschmidt To: qemu-ppc@nongnu.org Date: Wed, 11 Nov 2015 11:28:02 +1100 Message-Id: <1447201710-10229-50-git-send-email-benh@kernel.crashing.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1447201710-10229-1-git-send-email-benh@kernel.crashing.org> References: <1447201710-10229-1-git-send-email-benh@kernel.crashing.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 63.228.1.57 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 49/77] ppc/pnv: Create a default PCI layout X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This creates a legacy PCIe->PCI bridge under the PHB by default to which a bunch of standard devices are attached. Currently: - VGA (as specified by -vga) - USB (with keyboard and mouse if graphcis is enabled) - AHCI - e1000 This gives us something close to a standard OpenPower platform. Signed-off-by: Benjamin Herrenschmidt --- hw/ppc/pnv.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index d808802..179f93b 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -52,6 +52,9 @@ #include "hw/char/serial.h" #include "hw/timer/mc146818rtc.h" #include "hw/pci-host/pnv_phb3.h" +#include "hw/usb.h" +#include "hw/ide/pci.h" +#include "hw/ide/ahci.h" #include "exec/address-spaces.h" #include "qemu/config-file.h" @@ -85,6 +88,9 @@ typedef struct sPowerNVMachineState sPowerNVMachineState; /** * sPowerNVMachineState: */ + +#define MAX_SATA_PORTS 6 + struct sPowerNVMachineState { /*< private >*/ MachineState parent_obj; @@ -492,6 +498,71 @@ static const VMStateDescription vmstate_powernv = { .minimum_version_id = 1, }; +/* Returns whether we want to use VGA or not */ +static int pnv_vga_init(PCIBus *pci_bus) +{ + switch (vga_interface_type) { + case VGA_NONE: + return false; + case VGA_DEVICE: + return true; + case VGA_STD: + case VGA_VIRTIO: + return pci_vga_init(pci_bus) != NULL; + default: + fprintf(stderr, "This vga model is not supported," + "currently it only supports -vga std\n"); + exit(0); + } +} + +static void pnv_nic_init(PCIBus *pci_bus) +{ + int i; + + for (i = 0; i < nb_nics; i++) { + NICInfo *nd = &nd_table[i]; + DeviceState *dev; + PCIDevice *pdev; + Error *err = NULL; + + pdev = pci_create(pci_bus, -1, "e1000"); + dev = &pdev->qdev; + qdev_set_nic_properties(dev, nd); + object_property_set_bool(OBJECT(dev), true, "realized", &err); + if (err) { + error_report_err(err); + object_unparent(OBJECT(dev)); + exit(1); + } + } +} + +static void pnv_storage_init(PCIBus *pci_bus) +{ + DriveInfo *hd[MAX_SATA_PORTS]; + PCIDevice *ahci; + + /* Add an AHCI device. We use an ICH9 since that's all we have + * at hand for PCI AHCI but it shouldn't really matter + */ + ahci = pci_create_simple(pci_bus, -1, "ich9-ahci"); + g_assert(MAX_SATA_PORTS == ICH_AHCI(ahci)->ahci.ports); + ide_drive_get(hd, ICH_AHCI(ahci)->ahci.ports); + ahci_ide_create_devs(ahci, hd); +} + +static PCIBus *pnv_create_pci_legacy_bridge(PCIBus *parent, uint8_t chassis_nr) +{ + PCIDevice *dev; + + dev = pci_create_multifunction(parent, 0, false, "pci-bridge"); + qdev_prop_set_uint8(&dev->qdev, "chassis_nr", chassis_nr); + dev->qdev.id = "pci"; + qdev_init_nofail(&dev->qdev); + return pci_bridge_get_sec_bus(PCI_BRIDGE(dev)); +} + static void pnv_lpc_irq_handler_cpld(void *opaque, int n, int level) { #define MAX_ISA_IRQ 16 @@ -575,7 +646,9 @@ static void ppc_powernv_init(MachineState *machine) sPowerNVMachineState *pnv_machine = POWERNV_MACHINE(machine); PnvSystem *sys = &pnv_machine->sys; XICSState *xics; + PCIBus *pbus; ISABus *isa_bus; + bool has_gfx = false; long fw_size; char *filename; void *fdt; @@ -636,6 +709,30 @@ static void ppc_powernv_init(MachineState *machine) /* Create an RTC ISA device too */ rtc_init(isa_bus, 2000, NULL); + /* Add a PCI switch */ + pbus = pnv_create_pci_legacy_bridge(sys->chips[0].phb[0], 128); + + /* Graphics */ + if (pnv_vga_init(pbus)) { + has_gfx = true; + machine->usb |= defaults_enabled() && !machine->usb_disabled; + } + if (machine->usb) { + pci_create_simple(pbus, -1, "nec-usb-xhci"); + if (has_gfx) { + USBBus *usb_bus = usb_bus_find(-1); + + usb_create_simple(usb_bus, "usb-kbd"); + usb_create_simple(usb_bus, "usb-mouse"); + } + } + + /* Add NIC */ + pnv_nic_init(pbus); + + /* Add storage */ + pnv_storage_init(pbus); + if (bios_name == NULL) { bios_name = FW_FILE_NAME; } @@ -709,7 +806,7 @@ static void powernv_machine_class_init(ObjectClass *oc, void *data) NMIClass *nc = NMI_CLASS(oc); mc->init = ppc_powernv_init; - mc->block_default_type = IF_SCSI; + mc->block_default_type = IF_IDE; mc->max_cpus = MAX_CPUS; mc->no_parallel = 1; mc->default_boot_order = NULL;