[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PATCH 49/77] ppc/pnv: Create a default PCI layout
From: |
Benjamin Herrenschmidt |
Subject: |
[Qemu-ppc] [PATCH 49/77] ppc/pnv: Create a default PCI layout |
Date: |
Wed, 11 Nov 2015 11:28:02 +1100 |
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 <address@hidden>
---
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;
--
2.5.0
- Re: [Qemu-ppc] [PATCH for-2.5 44/77] pci-bridge: Set a supported devfn_min for bridge, (continued)
- [Qemu-ppc] [PATCH 41/77] ppc/pnv: Add LPC controller and hook it up with a UART and RTC, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 47/77] pci: Don't call pci_irq_handler() for a negative intx, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 46/77] pci: Use the new pci_can_add_device() to enforce devfn_min/max, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 43/77] ppc/pnv: Add OCC model stub with interrupt support, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 42/77] ppc/pnv: Add cut down PSI bridge model and hookup external interrupt, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 50/77] ppc: Update LPCR definitions, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 49/77] ppc/pnv: Create a default PCI layout,
Benjamin Herrenschmidt <=
- [Qemu-ppc] [PATCH 51/77] ppc: Use a helper to filter writes to LPCR, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 53/77] ppc: Add proper real mode translation support, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 52/77] ppc: Cosmetic, align some comments, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 63/77] ppc: Initialize AMOR in PAPR mode, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 57/77] ppc: Enforce setting MSR:EE, IR and DR when MSR:PR is set, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 61/77] ppc: SPURR & PURR are HV writeable and privileged, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 55/77] ppc/pnv+spapr: Add "ibm, pa-features" property to the device-tree, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 56/77] ppc: Fix conditions for delivering external interrupts to a guest, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 54/77] ppc: Fix 64K pages support in full emulation, Benjamin Herrenschmidt, 2015/11/10
- [Qemu-ppc] [PATCH 58/77] ppc: Initial HDEC support, Benjamin Herrenschmidt, 2015/11/10