hw/pci-host/sh_pcic: Style cleanup
cover hw/pci-host/sh_pcic: Style cleanup
- Use QOM DEFINE_TYPES
- Rename few functions
- Replace magic value by definition
Philippe Mathieu-Daudé (3):
hw/pci-host/sh_pcic: Declare CPU QOM types using DEFINE_TYPES() macro hw/pci-host/sh_pcic: Correct PCI host / devfn#0 function names hw/pci-host/sh_pcic: Replace magic value by proper definition
hw/pci-host/sh_pci.c | 57 ++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 31 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/3 hw/pci-host/sh_pcic: Declare CPU QOM types using DEFINE_TYPES() macro
When multiple QOM types are registered in the same file, it is simpler to use the the DEFINE_TYPES() macro. In particular because type array declared with such macro are easier to review.
--- hw/pci-host/sh_pci.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)
hw/pci-host/sh_pci.c +17 -23
@@ -167,17 +167,6 @@ static void sh_pci_host_class_init(ObjectClass *klass, void *data) dc->user_creatable = false; } -static const TypeInfo sh_pci_host_info = { - .name ="sh_pci_host" , - .parent =TYPE_PCI_DEVICE , - .instance_size =sizeof (PCIDevice), - .class_init = sh_pci_host_class_init, - .interfaces = (InterfaceInfo []) { - {INTERFACE_CONVENTIONAL_PCI_DEVICE }, - { }, - }, -}; -static void sh_pci_device_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -185,17 +174,22 @@ static void sh_pci_device_class_init(ObjectClass *klass, void *data) dc->realize = sh_pci_device_realize; } -static const TypeInfo sh_pci_device_info = { - .name =TYPE_SH_PCI_HOST_BRIDGE , - .parent =TYPE_PCI_HOST_BRIDGE , - .instance_size =sizeof (SHPCIState), - .class_init = sh_pci_device_class_init, +static const TypeInfo sh_pcic_types[] = { + { + .name =TYPE_SH_PCI_HOST_BRIDGE , + .parent =TYPE_PCI_HOST_BRIDGE , + .instance_size =sizeof (SHPCIState), + .class_init = sh_pci_device_class_init, + }, { + .name ="sh_pci_host" , + .parent =TYPE_PCI_DEVICE , + .instance_size =sizeof (PCIDevice), + .class_init = sh_pci_host_class_init, + .interfaces = (InterfaceInfo []) { + {INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, + }, }; -static void sh_pci_register_types (void ) -{ -type_register_static (&sh_pci_device_info); -type_register_static (&sh_pci_host_info); -} - -type_init (sh_pci_register_types) +DEFINE_TYPES (sh_pcic_types)
Signature · 1 line
2.41.0
PATCH 2/3 hw/pci-host/sh_pcic: Correct PCI host / devfn#0 function names
In reply to Philippe Mathieu-DaudéHost bridge device and PCI function #0 are inverted.
--- hw/pci-host/sh_pci.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
hw/pci-host/sh_pci.c +8 -8
@@ -116,7 +116,7 @@ static void sh_pci_set_irq(void *opaque, int irq_num, int level)qemu_set_irq (pic[irq_num], level); } -static void sh_pci_device_realize (DeviceState *dev,Error **errp) +static void sh_pcic_host_realize (DeviceState *dev,Error **errp) {SysBusDevice *sbd =SYS_BUS_DEVICE (dev);SHPCIState *s =SH_PCI_HOST_BRIDGE (dev);
@@ -145,19 +145,19 @@ static void sh_pci_device_realize(DeviceState *dev, Error **errp) s->dev =pci_create_simple (phb->bus,PCI_DEVFN (0 ,0 ),"sh_pci_host" ); } -static void sh_pci_host_realize (PCIDevice *d,Error **errp) +static void sh_pcic_pci_realize (PCIDevice *d,Error **errp) {pci_set_word (d->config +PCI_COMMAND ,PCI_COMMAND_WAIT );pci_set_word (d->config +PCI_STATUS ,PCI_STATUS_CAP_LIST |PCI_STATUS_FAST_BACK |PCI_STATUS_DEVSEL_MEDIUM ); } -static void sh_pci_host_class_init (ObjectClass *klass,void *data) +static void sh_pcic_pci_class_init (ObjectClass *klass,void *data) {PCIDeviceClass *k =PCI_DEVICE_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass); - k->realize = sh_pci_host_realize; + k->realize = sh_pcic_pci_realize; k->vendor_id =PCI_VENDOR_ID_HITACHI ; k->device_id =PCI_DEVICE_ID_HITACHI_SH7751R ;/*
@@ -167,11 +167,11 @@ static void sh_pci_host_class_init(ObjectClass *klass, void *data) dc->user_creatable = false; } -static void sh_pci_device_class_init (ObjectClass *klass,void *data) +static void sh_pcic_host_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->realize = sh_pci_device_realize; + dc->realize = sh_pcic_host_realize; }static const TypeInfo sh_pcic_types[] = {
@@ -179,12 +179,12 @@ static const TypeInfo sh_pcic_types[] = { .name = TYPE_SH_PCI_HOST_BRIDGE, .parent = TYPE_PCI_HOST_BRIDGE, .instance_size = sizeof(SHPCIState), - .class_init = sh_pci_device_class_init, + .class_init = sh_pcic_host_class_init, }, { .name = "sh_pci_host", .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCIDevice), - .class_init = sh_pci_host_class_init, + .class_init = sh_pcic_pci_class_init, .interfaces = (InterfaceInfo []) { {INTERFACE_CONVENTIONAL_PCI_DEVICE }, { },
Signature · 1 line
2.41.0
PATCH 3/3 hw/pci-host/sh_pcic: Replace magic value by proper definition
In reply to Philippe Mathieu-Daudé--- hw/pci-host/sh_pci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/pci-host/sh_pci.c +3 -2
@@ -40,7 +40,7 @@ struct SHPCIState {PCIHostState parent_obj;PCIDevice *dev; -qemu_irq irq[4 ]; +qemu_irq irq[PCI_NUM_PINS ];MemoryRegion memconfig_p4;MemoryRegion memconfig_a7;MemoryRegion isa;
@@ -131,7 +131,8 @@ static void sh_pcic_host_realize(DeviceState *dev, Error **errp) s->irq,get_system_memory (),get_system_io (), - PCI_DEVFN(0, 0), 4, TYPE_PCI_BUS); +PCI_DEVFN (0 ,0 ),PCI_NUM_PINS , + TYPE_PCI_BUS);memory_region_init_io (&s->memconfig_p4,OBJECT (s), &sh_pci_reg_ops, s,"sh_pci" ,0x224 ); memory_region_init_alias(&s->memconfig_a7, OBJECT(s), "sh_pci.2",
Signature · 1 line
2.41.0
Re: [PATCH 2/3] hw/pci-host/sh_pcic: Correct PCI host / devfn#0 function names
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
Host bridge device and PCI function #0 are inverted.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 72 lines
--- hw/pci-host/sh_pci.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)hw/pci-host/sh_pci.c +8
-8@@ -116,7 +116,7 @@ static void sh_pci_set_irq(void *opaque, int irq_num, int level)qemu_set_irq (pic[irq_num], level); } -static void sh_pci_device_realize (DeviceState *dev,Error **errp) +static void sh_pcic_host_realize (DeviceState *dev,Error **errp) {SysBusDevice *sbd =SYS_BUS_DEVICE (dev);SHPCIState *s =SH_PCI_HOST_BRIDGE (dev);@@ -145,19 +145,19 @@ static void sh_pci_device_realize(DeviceState *dev, Error **errp) s->dev =pci_create_simple (phb->bus,PCI_DEVFN (0 ,0 ),"sh_pci_host" ); } -static void sh_pci_host_realize (PCIDevice *d,Error **errp) +static void sh_pcic_pci_realize (PCIDevice *d,Error **errp) {pci_set_word (d->config +PCI_COMMAND ,PCI_COMMAND_WAIT );pci_set_word (d->config +PCI_STATUS ,PCI_STATUS_CAP_LIST |PCI_STATUS_FAST_BACK |PCI_STATUS_DEVSEL_MEDIUM ); } -static void sh_pci_host_class_init (ObjectClass *klass,void *data) +static void sh_pcic_pci_class_init (ObjectClass *klass,void *data) {PCIDeviceClass *k =PCI_DEVICE_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass); - k->realize = sh_pci_host_realize; + k->realize = sh_pcic_pci_realize; k->vendor_id =PCI_VENDOR_ID_HITACHI ; k->device_id =PCI_DEVICE_ID_HITACHI_SH7751R ;/* @@ -167,11 +167,11 @@ static void sh_pci_host_class_init(ObjectClass *klass, void *data) dc->user_creatable = false; } -static void sh_pci_device_class_init (ObjectClass *klass,void *data) +static void sh_pcic_host_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->realize = sh_pci_device_realize; + dc->realize = sh_pcic_host_realize; }static const TypeInfo sh_pcic_types[] = {@@ -179,12 +179,12 @@ static const TypeInfo sh_pcic_types[] = { .name = TYPE_SH_PCI_HOST_BRIDGE, .parent = TYPE_PCI_HOST_BRIDGE, .instance_size = sizeof(SHPCIState), - .class_init = sh_pci_device_class_init, + .class_init = sh_pcic_host_class_init, }, { .name = "sh_pci_host", .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCIDevice), - .class_init = sh_pci_host_class_init, + .class_init = sh_pcic_pci_class_init, .interfaces = (InterfaceInfo []) { {INTERFACE_CONVENTIONAL_PCI_DEVICE }, { },Signature · 1 line
2.41.0
Re: [PATCH 3/3] hw/pci-host/sh_pcic: Replace magic value by proper definition
In reply to Philippe Mathieu-DaudéQuoted 2 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 30 lines
--- hw/pci-host/sh_pci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/pci-host/sh_pci.c +3
-2@@ -40,7 +40,7 @@ struct SHPCIState {PCIHostState parent_obj;PCIDevice *dev; -qemu_irq irq[4 ]; +qemu_irq irq[PCI_NUM_PINS ];MemoryRegion memconfig_p4;MemoryRegion memconfig_a7;MemoryRegion isa;@@ -131,7 +131,8 @@ static void sh_pcic_host_realize(DeviceState *dev, Error **errp) s->irq,get_system_memory (),get_system_io (), - PCI_DEVFN(0, 0), 4, TYPE_PCI_BUS); +PCI_DEVFN (0 ,0 ),PCI_NUM_PINS , + TYPE_PCI_BUS);memory_region_init_io (&s->memconfig_p4,OBJECT (s), &sh_pci_reg_ops, s,"sh_pci" ,0x224 ); memory_region_init_alias(&s->memconfig_a7, OBJECT(s), "sh_pci.2",Signature · 1 line
2.41.0
Re: [PATCH 1/3] hw/pci-host/sh_pcic: Declare CPU QOM types using DEFINE_TYPES() macro
In reply to Philippe Mathieu-DaudéQuoted 7 lines · Philippe Mathieu-Daudé
When multiple QOM types are registered in the same file, it is simpler to use the the
DEFINE_TYPES()macro. In particular because type array declared with such macro are easier to review.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 64 lines
--- hw/pci-host/sh_pci.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)hw/pci-host/sh_pci.c +17
-23@@ -167,17 +167,6 @@ static void sh_pci_host_class_init(ObjectClass *klass, void *data) dc->user_creatable = false; } -static const TypeInfo sh_pci_host_info = { - .name ="sh_pci_host" , - .parent =TYPE_PCI_DEVICE , - .instance_size =sizeof (PCIDevice), - .class_init = sh_pci_host_class_init, - .interfaces = (InterfaceInfo []) { - {INTERFACE_CONVENTIONAL_PCI_DEVICE }, - { }, - }, -}; -static void sh_pci_device_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -185,17 +174,22 @@ static void sh_pci_device_class_init(ObjectClass *klass, void *data) dc->realize = sh_pci_device_realize; } -static const TypeInfo sh_pci_device_info = { - .name =TYPE_SH_PCI_HOST_BRIDGE , - .parent =TYPE_PCI_HOST_BRIDGE , - .instance_size =sizeof (SHPCIState), - .class_init = sh_pci_device_class_init, +static const TypeInfo sh_pcic_types[] = { + { + .name =TYPE_SH_PCI_HOST_BRIDGE , + .parent =TYPE_PCI_HOST_BRIDGE , + .instance_size =sizeof (SHPCIState), + .class_init = sh_pci_device_class_init, + }, { + .name ="sh_pci_host" , + .parent =TYPE_PCI_DEVICE , + .instance_size =sizeof (PCIDevice), + .class_init = sh_pci_host_class_init, + .interfaces = (InterfaceInfo []) { + {INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, + }, }; -static void sh_pci_register_types (void ) -{ -type_register_static (&sh_pci_device_info); -type_register_static (&sh_pci_host_info); -} - -type_init (sh_pci_register_types) +DEFINE_TYPES (sh_pcic_types)Signature · 1 line
2.41.0
Quoted 4 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (3):
hw/pci-host/sh_pcic: Declare CPU QOM types usingDEFINE_TYPES()macro hw/pci-host/sh_pcic: Correct PCI host / devfn#0 function names hw/pci-host/sh_pcic: Replace magic value by proper definition
Series queued, thanks.