spapr-pci: Make MMIO spacing a machine property and increase it
PATCH 1/1 spapr-pci: Make MMIO spacing a machine property and increase it
The pseries machine supports multiple PHBs. Each PHB's MMIO/IO space is mapped to the CPU address space starting at SPAPR_PCI_WINDOW_BASE plus some offset which is calculated from PHB's index and SPAPR_PCI_WINDOW_SPACING which is defined now as 64GB.
Since the default 32bit DMA window is using first 2GB of MMIO space, the amount of MMIO which the PCI devices can actually use is reduced to 62GB. This is a problem if the user wants to use devices with huge BARs.
For example, 2 PCI functions of a NVIDIA K80 adapter being passed through will exceed this limit as they have 16M + 16G + 32M BARs which (when aligned) will need 64GB.
This converts SPAPR_PCI_WINDOW_BASE and SPAPR_PCI_WINDOW_SPACING to sPAPRMachineState properties. This uses old values for pseries machine before 2.6 and increases the spacing to 128GB so MMIO space becomes 126GB.
This changes the default value of sPAPRPHBState::mem_win_size to -1 for pseries-2.6 and adds setup to spapr_phb_realize.
--- hw/ppc/spapr.c | 43 ++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_pci.c | 14 ++++++++++---- include/hw/pci-host/spapr.h | 4 +--- include/hw/ppc/spapr.h | 1 + 4 files changed, 54 insertions(+), 8 deletions(-)
hw/ppc/spapr.c +42 -1
@@ -40,6 +40,7 @@#include "migration/migration.h" #include "mmu-hash64.h" #include "qom/cpu.h" +#include "qapi/visitor.h" #include "hw/boards.h" #include "hw/ppc/ppc.h"
@@ -2100,6 +2101,29 @@ static void spapr_set_kvm_type(Object *obj, const char *value, Error **errp) spapr->kvm_type =g_strdup (value); } +static void spapr_prop_get_uint64 (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value = *(uint64_t *)opaque; +visit_type_uint64 (v, name, &value, errp); +} + +static void spapr_prop_set_uint64 (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value =-1 ; +visit_type_uint64 (v, name, &value, errp); + *(uint64_t *)opaque = value; +} + +static void spapr_prop_add_uint64 (Object *obj,const char *name, +uint64_t *pval,const char *desc) +{ +object_property_add (obj, name,"uint64" , spapr_prop_get_uint64, + spapr_prop_set_uint64,NULL , pval,NULL ); +object_property_set_description (obj, name, desc,NULL ); +} +static void spapr_machine_initfn (Object *obj) {sPAPRMachineState *spapr =SPAPR_MACHINE (obj);
@@ -2110,6 +2134,10 @@ static void spapr_machine_initfn(Object *obj)object_property_set_description (obj,"kvm-type" ,"Specifies the KVM virtualization mode (HV, PR)" ,NULL ); +spapr_prop_add_uint64 (obj,"phb-mmio-base" , &spapr->phb_mmio_base, +"Base address for PCI host bridge MMIO" ); +spapr_prop_add_uint64 (obj,"phb-mmio-spacing" , &spapr->phb_mmio_spacing, +"Amount of MMIO space per PCI host bridge" ); }static void spapr_machine_finalizefn (Object *obj)
@@ -2357,6 +2385,10 @@ static const TypeInfo spapr_machine_info = {*/ static void spapr_machine_2_6_instance_options (MachineState *machine) { +sPAPRMachineState *spapr =SPAPR_MACHINE (machine); + + spapr->phb_mmio_base =SPAPR_PCI_WINDOW_BASE ; + spapr->phb_mmio_spacing =SPAPR_PCI_WINDOW_SPACING ; }static void spapr_machine_2_6_class_options (MachineClass *mc)
@@ -2370,10 +2402,19 @@ DEFINE_SPAPR_MACHINE(2_6, "2.6", true);* pseries-2.5 */ #define SPAPR_COMPAT_2_5 \ - HW_COMPAT_2_5 + HW_COMPAT_2_5 \ + {\ + .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,\ + .property = "mem_win_size",\ + .value = "0x1000000000",\ + },static void spapr_machine_2_5_instance_options (MachineState *machine) { +sPAPRMachineState *spapr =SPAPR_MACHINE (machine); + + spapr->phb_mmio_base =0x10000000000ULL ; + spapr->phb_mmio_spacing =0x1000000000ULL ; }static void spapr_machine_2_5_class_options (MachineClass *mc)
hw/ppc/spapr_pci.c +10 -4
@@ -1260,9 +1260,11 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) sphb->buid =SPAPR_PCI_BASE_BUID + sphb->index; sphb->dma_liobn =SPAPR_PCI_LIOBN (sphb->index,0 ); - windows_base =SPAPR_PCI_WINDOW_BASE - + sphb->index *SPAPR_PCI_WINDOW_SPACING ; + windows_base = spapr->phb_mmio_base + + sphb->index * spapr->phb_mmio_spacing; sphb->mem_win_addr = windows_base +SPAPR_PCI_MMIO_WIN_OFF ; + sphb->mem_win_size = spapr->phb_mmio_spacing - +SPAPR_PCI_MEM_WIN_BUS_OFFSET ; sphb->io_win_addr = windows_base +SPAPR_PCI_IO_WIN_OFF ; }
@@ -1281,6 +1283,11 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)return ; } +if (sphb->mem_win_size == (hwaddr)-1 ) { +error_setg (errp,"Memory window size not specified for PHB" ); +return ; + } +if (sphb->io_win_addr == (hwaddr)-1 ) {error_setg (errp,"IO window address not specified for PHB" );return ;
@@ -1441,8 +1448,7 @@ static Property spapr_phb_properties[] = {DEFINE_PROP_UINT64 ("buid" , sPAPRPHBState, buid,-1 ),DEFINE_PROP_UINT32 ("liobn" , sPAPRPHBState, dma_liobn,-1 ),DEFINE_PROP_UINT64 ("mem_win_addr" , sPAPRPHBState, mem_win_addr,-1 ), -DEFINE_PROP_UINT64 ("mem_win_size" , sPAPRPHBState, mem_win_size, -SPAPR_PCI_MMIO_WIN_SIZE ), +DEFINE_PROP_UINT64 ("mem_win_size" , sPAPRPHBState, mem_win_size,-1 ),DEFINE_PROP_UINT64 ("io_win_addr" , sPAPRPHBState, io_win_addr,-1 ),DEFINE_PROP_UINT64 ("io_win_size" , sPAPRPHBState, io_win_size, SPAPR_PCI_IO_WIN_SIZE),
include/hw/pci-host/spapr.h +1 -3
@@ -107,10 +107,8 @@ struct sPAPRPHBVFIOState {#define SPAPR_PCI_MEM_WIN_BUS_OFFSET 0x80000000ULL#define SPAPR_PCI_WINDOW_BASE 0x10000000000ULL -#define SPAPR_PCI_WINDOW_SPACING 0x1000000000ULL +#define SPAPR_PCI_WINDOW_SPACING 0x2000000000ULL#define SPAPR_PCI_MMIO_WIN_OFF 0xA0000000 -#define SPAPR_PCI_MMIO_WIN_SIZE (SPAPR_PCI_WINDOW_SPACING - \ - SPAPR_PCI_MEM_WIN_BUS_OFFSET)#define SPAPR_PCI_IO_WIN_OFF 0x80000000#define SPAPR_PCI_IO_WIN_SIZE 0x10000
include/hw/ppc/spapr.h +1 -0
@@ -48,6 +48,7 @@ struct sPAPRMachineState {struct VIOsPAPRBus *vio_bus; QLIST_HEAD(, sPAPRPHBState) phbs; +uint64_t phb_mmio_base, phb_mmio_spacing;struct sPAPRNVRAM *nvram;XICSState *icp;DeviceState *rtc;
Signature · 1 line
2.5.0.rc3
Quoted 14 lines · Alexey Kardashevskiy
The pseries machine supports multiple PHBs. Each PHB's MMIO/IO space is mapped to the CPU address space starting at
SPAPR_PCI_WINDOW_BASEplus some offset which is calculated from PHB's index andSPAPR_PCI_WINDOW_SPACINGwhich is defined now as 64GB.Since the default 32bit DMA window is using first 2GB of MMIO space, the amount of MMIO which the PCI devices can actually use is reduced to 62GB. This is a problem if the user wants to use devices with huge BARs.
For example, 2 PCI functions of a NVIDIA K80 adapter being passed through will exceed this limit as they have 16M + 16G + 32M BARs which (when aligned) will need 64GB.
Quoted 8 lines
This converts
SPAPR_PCI_WINDOW_BASEandSPAPR_PCI_WINDOW_SPACINGto sPAPRMachineState properties. This uses old values for pseries machine before 2.6 and increases the spacing to 128GB so MMIO space becomes 126GB.This changes the default value of
sPAPRPHBState::mem_win_sizeto -1 for pseries-2.6 and adds setup tospapr_phb_realize.Signed-off-by Alexey Kardashevskiy <[email protected]>
So, in theory I dislike the spapr_pci device reaching into the machine type to get the spacing configuration. But.. I don't know of a better way to achieve the desired outcome.
A couple of other details concern me a little more.
Quoted 27 lines
--- hw/ppc/spapr.c | 43 ++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_pci.c | 14 ++++++++++---- include/hw/pci-host/spapr.h | 4 +--- include/hw/ppc/spapr.h | 1 + 4 files changed, 54 insertions(+), 8 deletions(-)hw/ppc/spapr.c +5
-0@@ -40,6 +40,7 @@#include "migration/migration.h" #include "mmu-hash64.h" #include "qom/cpu.h" +#include "qapi/visitor.h" #include "hw/boards.h" #include "hw/ppc/ppc.h" @@ -2100,6 +2101,29 @@ static void spapr_set_kvm_type(Object *obj, const char *value, Error **errp) spapr->kvm_type =g_strdup (value); } +static void spapr_prop_get_uint64 (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value = *(uint64_t *)opaque;
hw/ppc/spapr.c static void spapr_set_kvm_type(Object *obj, const char *value, Error **errp) · line 2117
Quoted 10 lines
hw/ppc/spapr.c +10
-0+visit_type_uint64 (v, name, &value, errp); +} + +static void spapr_prop_set_uint64 (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value =-1 ; +visit_type_uint64 (v, name, &value, errp); + *(uint64_t *)opaque = value; +}
Pity there aren't standard helpers for this.
Quoted 12 lines
hw/ppc/spapr.c +8
-0+static void spapr_prop_add_uint64 (Object *obj,const char *name, +uint64_t *pval,const char *desc) +{ +object_property_add (obj, name,"uint64" , spapr_prop_get_uint64, + spapr_prop_set_uint64,NULL , pval,NULL ); +object_property_set_description (obj, name, desc,NULL ); +} +static void spapr_machine_initfn (Object *obj) {sPAPRMachineState *spapr =SPAPR_MACHINE (obj);
hw/ppc/spapr.c static void spapr_machine_initfn(Object *obj) · line 2140
Quoted 7 lines
hw/ppc/spapr.c +4
-0@@ -2110,6 +2134,10 @@ static void spapr_machine_initfn(Object *obj)object_property_set_description (obj,"kvm-type" ,"Specifies the KVM virtualization mode (HV, PR)" ,NULL ); +spapr_prop_add_uint64 (obj,"phb-mmio-base" , &spapr->phb_mmio_base, +"Base address for PCI host bridge MMIO" ); +spapr_prop_add_uint64 (obj,"phb-mmio-spacing" , &spapr->phb_mmio_spacing, +"Amount of MMIO space per PCI host bridge" );
Hmm.. what happens if someone tries to change these propertis at runtime with qom-set? That sounds bad.
Quoted 103 lines
hw/ppc/spapr.c +14
-1}static void spapr_machine_finalizefn (Object *obj)@@ -2357,6 +2385,10 @@ static const TypeInfo spapr_machine_info = {*/ static void spapr_machine_2_6_instance_options (MachineState *machine) { +sPAPRMachineState *spapr =SPAPR_MACHINE (machine); + + spapr->phb_mmio_base =SPAPR_PCI_WINDOW_BASE ; + spapr->phb_mmio_spacing =SPAPR_PCI_WINDOW_SPACING ; }static void spapr_machine_2_6_class_options (MachineClass *mc)@@ -2370,10 +2402,19 @@ DEFINE_SPAPR_MACHINE(2_6, "2.6", true);* pseries-2.5 */ #define SPAPR_COMPAT_2_5 \ - HW_COMPAT_2_5 + HW_COMPAT_2_5 \ + {\ + .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,\ + .property = "mem_win_size",\ + .value = "0x1000000000",\ + },static void spapr_machine_2_5_instance_options (MachineState *machine) { +sPAPRMachineState *spapr =SPAPR_MACHINE (machine); + + spapr->phb_mmio_base =0x10000000000ULL ; + spapr->phb_mmio_spacing =0x1000000000ULL ; }static void spapr_machine_2_5_class_options (MachineClass *mc)hw/ppc/spapr_pci.c +10
-4@@ -1260,9 +1260,11 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) sphb->buid =SPAPR_PCI_BASE_BUID + sphb->index; sphb->dma_liobn =SPAPR_PCI_LIOBN (sphb->index,0 ); - windows_base =SPAPR_PCI_WINDOW_BASE - + sphb->index *SPAPR_PCI_WINDOW_SPACING ; + windows_base = spapr->phb_mmio_base + + sphb->index * spapr->phb_mmio_spacing; sphb->mem_win_addr = windows_base +SPAPR_PCI_MMIO_WIN_OFF ; + sphb->mem_win_size = spapr->phb_mmio_spacing - +SPAPR_PCI_MEM_WIN_BUS_OFFSET ; sphb->io_win_addr = windows_base +SPAPR_PCI_IO_WIN_OFF ; }@@ -1281,6 +1283,11 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)return ; } +if (sphb->mem_win_size == (hwaddr)-1 ) { +error_setg (errp,"Memory window size not specified for PHB" ); +return ; + } +if (sphb->io_win_addr == (hwaddr)-1 ) {error_setg (errp,"IO window address not specified for PHB" );return ;@@ -1441,8 +1448,7 @@ static Property spapr_phb_properties[] = {DEFINE_PROP_UINT64 ("buid" , sPAPRPHBState, buid,-1 ),DEFINE_PROP_UINT32 ("liobn" , sPAPRPHBState, dma_liobn,-1 ),DEFINE_PROP_UINT64 ("mem_win_addr" , sPAPRPHBState, mem_win_addr,-1 ), -DEFINE_PROP_UINT64 ("mem_win_size" , sPAPRPHBState, mem_win_size, -SPAPR_PCI_MMIO_WIN_SIZE ), +DEFINE_PROP_UINT64 ("mem_win_size" , sPAPRPHBState, mem_win_size,-1 ),DEFINE_PROP_UINT64 ("io_win_addr" , sPAPRPHBState, io_win_addr,-1 ),DEFINE_PROP_UINT64 ("io_win_size" , sPAPRPHBState, io_win_size, SPAPR_PCI_IO_WIN_SIZE),include/hw/pci-host/spapr.h +1
-3@@ -107,10 +107,8 @@ struct sPAPRPHBVFIOState {#define SPAPR_PCI_MEM_WIN_BUS_OFFSET 0x80000000ULL#define SPAPR_PCI_WINDOW_BASE 0x10000000000ULL -#define SPAPR_PCI_WINDOW_SPACING 0x1000000000ULL +#define SPAPR_PCI_WINDOW_SPACING 0x2000000000ULL#define SPAPR_PCI_MMIO_WIN_OFF 0xA0000000 -#define SPAPR_PCI_MMIO_WIN_SIZE (SPAPR_PCI_WINDOW_SPACING - \ - SPAPR_PCI_MEM_WIN_BUS_OFFSET)#define SPAPR_PCI_IO_WIN_OFF 0x80000000#define SPAPR_PCI_IO_WIN_SIZE 0x10000include/hw/ppc/spapr.h +1
-0@@ -48,6 +48,7 @@ struct sPAPRMachineState {struct VIOsPAPRBus *vio_bus; QLIST_HEAD(, sPAPRPHBState) phbs; +uint64_t phb_mmio_base, phb_mmio_spacing;struct sPAPRNVRAM *nvram;XICSState *icp;DeviceState *rtc;
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 19 lines · David Gibson
Quoted 18 lines · Alexey Kardashevskiy
The pseries machine supports multiple PHBs. Each PHB's MMIO/IO space is mapped to the CPU address space starting at
SPAPR_PCI_WINDOW_BASEplus some offset which is calculated from PHB's index andSPAPR_PCI_WINDOW_SPACINGwhich is defined now as 64GB.Since the default 32bit DMA window is using first 2GB of MMIO space, the amount of MMIO which the PCI devices can actually use is reduced to 62GB. This is a problem if the user wants to use devices with huge BARs.
For example, 2 PCI functions of a NVIDIA K80 adapter being passed through will exceed this limit as they have 16M + 16G + 32M BARs which (when aligned) will need 64GB.
This converts
SPAPR_PCI_WINDOW_BASEandSPAPR_PCI_WINDOW_SPACINGto sPAPRMachineState properties. This uses old values for pseries machine before 2.6 and increases the spacing to 128GB so MMIO space becomes 126GB.
Quoted 8 lines
Quoted 4 lines
This changes the default value of
sPAPRPHBState::mem_win_sizeto -1 for pseries-2.6 and adds setup tospapr_phb_realize.Signed-off-by Alexey Kardashevskiy <[email protected]>So, in theory I dislike the
spapr_pcidevice reaching into the machine type to get the spacing configuration. But.. I don't know of a better way to achieve the desired outcome.
We could drop @index and spacing; and request the user to specify the MMIO window start (at least) for every additional PHB.
Quoted 57 lines
A couple of other details concern me a little more.
Quoted 27 lines
--- hw/ppc/spapr.c | 43 ++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_pci.c | 14 ++++++++++---- include/hw/pci-host/spapr.h | 4 +--- include/hw/ppc/spapr.h | 1 + 4 files changed, 54 insertions(+), 8 deletions(-)hw/ppc/spapr.c +5
-0@@ -40,6 +40,7 @@#include "migration/migration.h" #include "mmu-hash64.h" #include "qom/cpu.h" +#include "qapi/visitor.h" #include "hw/boards.h" #include "hw/ppc/ppc.h" @@ -2100,6 +2101,29 @@ static void spapr_set_kvm_type(Object *obj, const char *value, Error **errp) spapr->kvm_type =g_strdup (value); } +static void spapr_prop_get_uint64 (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value = *(uint64_t *)opaque;hw/ppc/spapr.c static void spapr_set_kvm_type(Object *obj, const char *value, Error **errp) · line 2117
Quoted 10 lines
hw/ppc/spapr.c +10
-0+visit_type_uint64 (v, name, &value, errp); +} + +static void spapr_prop_set_uint64 (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value =-1 ; +visit_type_uint64 (v, name, &value, errp); + *(uint64_t *)opaque = value; +}Pity there aren't standard helpers for this.
Quoted 14 lines
hw/ppc/spapr.c +8
-0+static void spapr_prop_add_uint64 (Object *obj,const char *name, +uint64_t *pval,const char *desc) +{ +object_property_add (obj, name,"uint64" , spapr_prop_get_uint64, + spapr_prop_set_uint64,NULL , pval,NULL ); +object_property_set_description (obj, name, desc,NULL ); +} +static void spapr_machine_initfn (Object *obj) {sPAPRMachineState *spapr =SPAPR_MACHINE (obj);@@ -2110,6 +2134,10 @@ static void spapr_machine_initfn(Object *obj) object_property_set_description(obj, "kvm-type", "Specifies the KVM virtualization mode (HV, PR)",
Quoted 8 lines
hw/ppc/spapr.c static void spapr_machine_initfn(Object *obj) · line 2140
Quoted 5 lines
hw/ppc/spapr.c +4
-0NULL); +spapr_prop_add_uint64 (obj,"phb-mmio-base" , &spapr->phb_mmio_base, +"Base address for PCI host bridge MMIO" ); +spapr_prop_add_uint64 (obj,"phb-mmio-spacing" , &spapr->phb_mmio_spacing, +"Amount of MMIO space per PCI host bridge" );Hmm.. what happens if someone tries to change these propertis at runtime with qom-set? That sounds bad.
What is the problem here exactly? These are the properties for new PHBs, if/when we add an ability to hotplug PHBs, changes to these properties will reflect in new PHB properties.
Likewise writing to "kvm-type" does not switch from HV to PR and vice versa.
Quoted 105 lines
Quoted 104 lines
hw/ppc/spapr.c +14
-1}static void spapr_machine_finalizefn (Object *obj)@@ -2357,6 +2385,10 @@ static const TypeInfo spapr_machine_info = {*/ static void spapr_machine_2_6_instance_options (MachineState *machine) { +sPAPRMachineState *spapr =SPAPR_MACHINE (machine); + + spapr->phb_mmio_base =SPAPR_PCI_WINDOW_BASE ; + spapr->phb_mmio_spacing =SPAPR_PCI_WINDOW_SPACING ; }static void spapr_machine_2_6_class_options (MachineClass *mc)@@ -2370,10 +2402,19 @@ DEFINE_SPAPR_MACHINE(2_6, "2.6", true);* pseries-2.5 */ #define SPAPR_COMPAT_2_5 \ - HW_COMPAT_2_5 + HW_COMPAT_2_5 \ + {\ + .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,\ + .property = "mem_win_size",\ + .value = "0x1000000000",\ + },static void spapr_machine_2_5_instance_options (MachineState *machine) { +sPAPRMachineState *spapr =SPAPR_MACHINE (machine); + + spapr->phb_mmio_base =0x10000000000ULL ; + spapr->phb_mmio_spacing =0x1000000000ULL ; }static void spapr_machine_2_5_class_options (MachineClass *mc)hw/ppc/spapr_pci.c +10
-4@@ -1260,9 +1260,11 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) sphb->buid =SPAPR_PCI_BASE_BUID + sphb->index; sphb->dma_liobn =SPAPR_PCI_LIOBN (sphb->index,0 ); - windows_base =SPAPR_PCI_WINDOW_BASE - + sphb->index *SPAPR_PCI_WINDOW_SPACING ; + windows_base = spapr->phb_mmio_base + + sphb->index * spapr->phb_mmio_spacing; sphb->mem_win_addr = windows_base +SPAPR_PCI_MMIO_WIN_OFF ; + sphb->mem_win_size = spapr->phb_mmio_spacing - +SPAPR_PCI_MEM_WIN_BUS_OFFSET ; sphb->io_win_addr = windows_base +SPAPR_PCI_IO_WIN_OFF ; }@@ -1281,6 +1283,11 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)return ; } +if (sphb->mem_win_size == (hwaddr)-1 ) { +error_setg (errp,"Memory window size not specified for PHB" ); +return ; + } +if (sphb->io_win_addr == (hwaddr)-1 ) {error_setg (errp,"IO window address not specified for PHB" );return ;@@ -1441,8 +1448,7 @@ static Property spapr_phb_properties[] = {DEFINE_PROP_UINT64 ("buid" , sPAPRPHBState, buid,-1 ),DEFINE_PROP_UINT32 ("liobn" , sPAPRPHBState, dma_liobn,-1 ),DEFINE_PROP_UINT64 ("mem_win_addr" , sPAPRPHBState, mem_win_addr,-1 ), -DEFINE_PROP_UINT64 ("mem_win_size" , sPAPRPHBState, mem_win_size, -SPAPR_PCI_MMIO_WIN_SIZE ), +DEFINE_PROP_UINT64 ("mem_win_size" , sPAPRPHBState, mem_win_size,-1 ),DEFINE_PROP_UINT64 ("io_win_addr" , sPAPRPHBState, io_win_addr,-1 ),DEFINE_PROP_UINT64 ("io_win_size" , sPAPRPHBState, io_win_size, SPAPR_PCI_IO_WIN_SIZE),include/hw/pci-host/spapr.h +1
-3@@ -107,10 +107,8 @@ struct sPAPRPHBVFIOState {#define SPAPR_PCI_MEM_WIN_BUS_OFFSET 0x80000000ULL#define SPAPR_PCI_WINDOW_BASE 0x10000000000ULL -#define SPAPR_PCI_WINDOW_SPACING 0x1000000000ULL +#define SPAPR_PCI_WINDOW_SPACING 0x2000000000ULL#define SPAPR_PCI_MMIO_WIN_OFF 0xA0000000 -#define SPAPR_PCI_MMIO_WIN_SIZE (SPAPR_PCI_WINDOW_SPACING - \ - SPAPR_PCI_MEM_WIN_BUS_OFFSET)#define SPAPR_PCI_IO_WIN_OFF 0x80000000#define SPAPR_PCI_IO_WIN_SIZE 0x10000include/hw/ppc/spapr.h +1
-0@@ -48,6 +48,7 @@ struct sPAPRMachineState {struct VIOsPAPRBus *vio_bus; QLIST_HEAD(, sPAPRPHBState) phbs; +uint64_t phb_mmio_base, phb_mmio_spacing;struct sPAPRNVRAM *nvram;XICSState *icp;DeviceState *rtc;
Signature · 1 line
Alexey
Quoted 25 lines · Alexey Kardashevskiy
Quoted 24 lines · David Gibson
Quoted 22 lines · Alexey Kardashevskiy
The pseries machine supports multiple PHBs. Each PHB's MMIO/IO space is mapped to the CPU address space starting at
SPAPR_PCI_WINDOW_BASEplus some offset which is calculated from PHB's index andSPAPR_PCI_WINDOW_SPACINGwhich is defined now as 64GB.Since the default 32bit DMA window is using first 2GB of MMIO space, the amount of MMIO which the PCI devices can actually use is reduced to 62GB. This is a problem if the user wants to use devices with huge BARs.
For example, 2 PCI functions of a NVIDIA K80 adapter being passed through will exceed this limit as they have 16M + 16G + 32M BARs which (when aligned) will need 64GB.
This converts
SPAPR_PCI_WINDOW_BASEandSPAPR_PCI_WINDOW_SPACINGto sPAPRMachineState properties. This uses old values for pseries machine before 2.6 and increases the spacing to 128GB so MMIO space becomes 126GB.This changes the default value of
sPAPRPHBState::mem_win_sizeto -1 for pseries-2.6 and adds setup tospapr_phb_realize.Signed-off-by Alexey Kardashevskiy <[email protected]>
Quoted 7 lines
Quoted 3 lines
So, in theory I dislike the
spapr_pcidevice reaching into the machine type to get the spacing configuration. But.. I don't know of a better way to achieve the desired outcome.We could drop @index and spacing; and request the user to specify the MMIO window start (at least) for every additional PHB.
So what is the decision? :)
Quoted 191 lines
Quoted 65 lines
A couple of other details concern me a little more.
Quoted 31 lines
--- hw/ppc/spapr.c | 43 ++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_pci.c | 14 ++++++++++---- include/hw/pci-host/spapr.h | 4 +--- include/hw/ppc/spapr.h | 1 + 4 files changed, 54 insertions(+), 8 deletions(-)hw/ppc/spapr.c +6
-0@@ -40,6 +40,7 @@#include "migration/migration.h" #include "mmu-hash64.h" #include "qom/cpu.h" +#include "qapi/visitor.h" #include "hw/boards.h" #include "hw/ppc/ppc.h" @@ -2100,6 +2101,29 @@ static void spapr_set_kvm_type(Object *obj, const char *value, Error **errp) spapr->kvm_type = g_strdup(value); } +static void spapr_prop_get_uint64 (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value = *(uint64_t *)opaque; +visit_type_uint64 (v, name, &value, errp);hw/ppc/spapr.c static void spapr_set_kvm_type(Object *obj, const · line 2120
Quoted 10 lines
hw/ppc/spapr.c +9
-0+} + +static void spapr_prop_set_uint64 (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value =-1 ; +visit_type_uint64 (v, name, &value, errp); + *(uint64_t *)opaque = value; +}Pity there aren't standard helpers for this.
Quoted 16 lines
hw/ppc/spapr.c +8
-0+static void spapr_prop_add_uint64 (Object *obj,const char *name, +uint64_t *pval,const char *desc) +{ +object_property_add (obj, name,"uint64" , spapr_prop_get_uint64, + spapr_prop_set_uint64,NULL , pval,NULL ); +object_property_set_description (obj, name, desc,NULL ); +} +static void spapr_machine_initfn (Object *obj) {sPAPRMachineState *spapr =SPAPR_MACHINE (obj);@@ -2110,6 +2134,10 @@ static void spapr_machine_initfn(Object *obj)object_property_set_description (obj,"kvm-type" , "Specifies the KVM virtualization mode (HV, PR)",NULL );Quoted 8 lines
hw/ppc/spapr.c static void spapr_machine_initfn(Object *obj) · line 2140
Quoted 5 lines
hw/ppc/spapr.c +4
-0+spapr_prop_add_uint64 (obj,"phb-mmio-base" , &spapr->phb_mmio_base, +"Base address for PCI host bridge MMIO" ); +spapr_prop_add_uint64 (obj,"phb-mmio-spacing" , &spapr->phb_mmio_spacing, +"Amount of MMIO space per PCI host bridge" );Hmm.. what happens if someone tries to change these propertis at runtime with qom-set? That sounds bad.
What is the problem here exactly? These are the properties for new PHBs, if/when we add an ability to hotplug PHBs, changes to these properties will reflect in new PHB properties.
Likewise writing to "kvm-type" does not switch from HV to PR and vice versa.
Quoted 107 lines
Quoted 106 lines
hw/ppc/spapr.c +0
-0}static void
spapr_machine_finalizefn(Object *obj)hw/ppc/spapr.c +14
-1@@ -2357,6 +2385,10 @@ static const TypeInfo spapr_machine_info = {*/ static void spapr_machine_2_6_instance_options (MachineState *machine) { +sPAPRMachineState *spapr =SPAPR_MACHINE (machine); + + spapr->phb_mmio_base =SPAPR_PCI_WINDOW_BASE ; + spapr->phb_mmio_spacing =SPAPR_PCI_WINDOW_SPACING ; }static void spapr_machine_2_6_class_options (MachineClass *mc)@@ -2370,10 +2402,19 @@ DEFINE_SPAPR_MACHINE(2_6, "2.6", true);* pseries-2.5 */ #define SPAPR_COMPAT_2_5 \ - HW_COMPAT_2_5 + HW_COMPAT_2_5 \ + {\ + .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,\ + .property = "mem_win_size",\ + .value = "0x1000000000",\ + },static void spapr_machine_2_5_instance_options (MachineState *machine) { +sPAPRMachineState *spapr =SPAPR_MACHINE (machine); + + spapr->phb_mmio_base =0x10000000000ULL ; + spapr->phb_mmio_spacing =0x1000000000ULL ; }static void spapr_machine_2_5_class_options (MachineClass *mc)hw/ppc/spapr_pci.c +9
-2@@ -1260,9 +1260,11 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) sphb->buid = SPAPR_PCI_BASE_BUID + sphb->index; sphb->dma_liobn =SPAPR_PCI_LIOBN (sphb->index,0 ); - windows_base =SPAPR_PCI_WINDOW_BASE - + sphb->index *SPAPR_PCI_WINDOW_SPACING ; + windows_base = spapr->phb_mmio_base + + sphb->index * spapr->phb_mmio_spacing; sphb->mem_win_addr = windows_base +SPAPR_PCI_MMIO_WIN_OFF ; + sphb->mem_win_size = spapr->phb_mmio_spacing - +SPAPR_PCI_MEM_WIN_BUS_OFFSET ; sphb->io_win_addr = windows_base +SPAPR_PCI_IO_WIN_OFF ; }@@ -1281,6 +1283,11 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) return; } +if (sphb->mem_win_size == (hwaddr)-1 ) { +error_setg (errp,"Memory window size not specified for PHB" ); +return ; + } +if (sphb->io_win_addr == (hwaddr)-1 ) {error_setg (errp,"IO window address not specified for PHB" );return;hw/ppc/spapr_pci.c +1
-2@@ -1441,8 +1448,7 @@ static Property spapr_phb_properties[] = {DEFINE_PROP_UINT64 ("buid" , sPAPRPHBState, buid,-1 ),DEFINE_PROP_UINT32 ("liobn" , sPAPRPHBState, dma_liobn,-1 ),DEFINE_PROP_UINT64 ("mem_win_addr" , sPAPRPHBState, mem_win_addr,-1 ), -DEFINE_PROP_UINT64 ("mem_win_size" , sPAPRPHBState, mem_win_size, -SPAPR_PCI_MMIO_WIN_SIZE ), +DEFINE_PROP_UINT64 ("mem_win_size" , sPAPRPHBState, mem_win_size,-1 ),DEFINE_PROP_UINT64 ("io_win_addr" , sPAPRPHBState, io_win_addr,-1 ),DEFINE_PROP_UINT64 ("io_win_size" , sPAPRPHBState, io_win_size, SPAPR_PCI_IO_WIN_SIZE),include/hw/pci-host/spapr.h +1
-3@@ -107,10 +107,8 @@ struct sPAPRPHBVFIOState {#define SPAPR_PCI_MEM_WIN_BUS_OFFSET 0x80000000ULL#define SPAPR_PCI_WINDOW_BASE 0x10000000000ULL -#define SPAPR_PCI_WINDOW_SPACING 0x1000000000ULL +#define SPAPR_PCI_WINDOW_SPACING 0x2000000000ULL#define SPAPR_PCI_MMIO_WIN_OFF 0xA0000000 -#define SPAPR_PCI_MMIO_WIN_SIZE (SPAPR_PCI_WINDOW_SPACING - \ - SPAPR_PCI_MEM_WIN_BUS_OFFSET)#define SPAPR_PCI_IO_WIN_OFF 0x80000000#define SPAPR_PCI_IO_WIN_SIZE 0x10000include/hw/ppc/spapr.h +1
-0@@ -48,6 +48,7 @@ struct sPAPRMachineState {struct VIOsPAPRBus *vio_bus; QLIST_HEAD(, sPAPRPHBState) phbs; +uint64_t phb_mmio_base, phb_mmio_spacing;struct sPAPRNVRAM *nvram;XICSState *icp;DeviceState *rtc;
Signature · 1 line
Alexey
Quoted 31 lines · Alexey Kardashevskiy
Quoted 30 lines · Alexey Kardashevskiy
Quoted 27 lines · David Gibson
Quoted 14 lines · Alexey Kardashevskiy
The pseries machine supports multiple PHBs. Each PHB's MMIO/IO space is mapped to the CPU address space starting at
SPAPR_PCI_WINDOW_BASEplus some offset which is calculated from PHB's index andSPAPR_PCI_WINDOW_SPACINGwhich is defined now as 64GB.Since the default 32bit DMA window is using first 2GB of MMIO space, the amount of MMIO which the PCI devices can actually use is reduced to 62GB. This is a problem if the user wants to use devices with huge BARs.
For example, 2 PCI functions of a NVIDIA K80 adapter being passed through will exceed this limit as they have 16M + 16G + 32M BARs which (when aligned) will need 64GB.
Quoted 8 lines
This converts
SPAPR_PCI_WINDOW_BASEandSPAPR_PCI_WINDOW_SPACINGto sPAPRMachineState properties. This uses old values for pseries machine before 2.6 and increases the spacing to 128GB so MMIO space becomes 126GB.This changes the default value of
sPAPRPHBState::mem_win_sizeto -1 for pseries-2.6 and adds setup tospapr_phb_realize.Signed-off-by Alexey Kardashevskiy <[email protected]>So, in theory I dislike the
spapr_pcidevice reaching into the machine type to get the spacing configuration. But.. I don't know of a better way to achieve the desired outcome.
Quoted 4 lines
Quoted 2 lines
We could drop @index and spacing; and request the user to specify the MMIO window start (at least) for every additional PHB.
So what is the decision? :)
There isn't one. I really don't know how to handle this, trying to talk to some people for ideas.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 32 lines · David Gibson
Quoted 31 lines · Alexey Kardashevskiy
Quoted 30 lines · Alexey Kardashevskiy
Quoted 27 lines · David Gibson
Quoted 14 lines · Alexey Kardashevskiy
The pseries machine supports multiple PHBs. Each PHB's MMIO/IO space is mapped to the CPU address space starting at
SPAPR_PCI_WINDOW_BASEplus some offset which is calculated from PHB's index andSPAPR_PCI_WINDOW_SPACINGwhich is defined now as 64GB.Since the default 32bit DMA window is using first 2GB of MMIO space, the amount of MMIO which the PCI devices can actually use is reduced to 62GB. This is a problem if the user wants to use devices with huge BARs.
For example, 2 PCI functions of a NVIDIA K80 adapter being passed through will exceed this limit as they have 16M + 16G + 32M BARs which (when aligned) will need 64GB.
Quoted 8 lines
This converts
SPAPR_PCI_WINDOW_BASEandSPAPR_PCI_WINDOW_SPACINGto sPAPRMachineState properties. This uses old values for pseries machine before 2.6 and increases the spacing to 128GB so MMIO space becomes 126GB.This changes the default value of
sPAPRPHBState::mem_win_sizeto -1 for pseries-2.6 and adds setup tospapr_phb_realize.Signed-off-by Alexey Kardashevskiy <[email protected]>So, in theory I dislike the
spapr_pcidevice reaching into the machine type to get the spacing configuration. But.. I don't know of a better way to achieve the desired outcome.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
We could drop @index and spacing; and request the user to specify the MMIO window start (at least) for every additional PHB.
So what is the decision? :)
There isn't one. I really don't know how to handle this, trying to talk to some people for ideas.
Got any new idea?
Signature · 1 line
Alexey