PCI clean-up
cover PCI clean-up
Hi,
this series extracts the struct struct PHPSlots portion of my previous series "[rfc 00/18] ioemu: use devfn instead of slots as the unit for passthrough".
Signature · 3 lines
Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
PATCH 1/4 ioemu: piix4acpi.c: Simplfy PHPSlots structure
The anonymouys structure inside PHPSlots only has one element, so things can be simplified by moving the element into PHPSlots and removing the anonymous structure.
hw/piix4acpi.c +7 -9
@@ -77,9 +77,7 @@ typedef struct GPEState {GPEState gpe_state;typedef struct PHPSlots { -struct { -uint8_t status;/* Apaptor stats */ - } slot[ACPI_PHP_SLOT_NUM ]; +uint8_t status[ACPI_PHP_SLOT_NUM ];/* Apaptor stats */ uint8_t plug_evt;/* slot|event slot:0-no event;1-1st. event:0-remove;1-add */ }PHPSlots ;
@@ -240,7 +238,7 @@ static uint32_t acpi_php_readb(void *opabreak ;default : num = addr -ACPI_PHP_IO_ADDR -1 ; - val = hotplug_slots->slot[num].status; + val = hotplug_slots->status[num]; } fprintf(logfile, "ACPI PCI hotplug: read addr=0x%x, val=0x%x.\n",
@@ -265,7 +263,7 @@ static void acpi_php_writeb(void *opaque php_slot = addr -ACPI_PHP_IO_ADDR -1 ;if ( val ==0x1 ) {/* Eject command */ /* make _STA of the slot 0 */ - hotplug_slots->slot[php_slot].status =0 ; + hotplug_slots->status[php_slot] =0 ;/* clear the hotplug event */ hotplug_slots->plug_evt =0 ;
@@ -284,7 +282,7 @@ static void pcislots_save(QEMUFile* f, vPHPSlots *s = (PHPSlots *)opaque;int i;for ( i =0 ; i <ACPI_PHP_SLOT_NUM ; i++ ) { -qemu_put_8s ( f, &s->slot[i].status); +qemu_put_8s ( f, &s->status[i]); }qemu_put_8s (f, &s->plug_evt); }
@@ -296,7 +294,7 @@ static int pcislots_load(QEMUFile* f, voif (version_id !=1 )return -EINVAL ;for ( i =0 ; i <ACPI_PHP_SLOT_NUM ; i++ ) { -qemu_get_8s ( f, &s->slot[i].status); +qemu_get_8s ( f, &s->status[i]); }qemu_get_8s (f, &s->plug_evt);return 0 ;
@@ -311,7 +309,7 @@ static void php_slots_init(void)/* update the pci slot status */ for ( i =0 ; i <PHP_SLOT_LEN ; i++ ) {if (test_pci_slot (PHP_TO_PCI_SLOT (i) ) ==1 ) - slots->slot[i].status =0xf ; + slots->status[i] =0xf ; }
@@ -495,7 +493,7 @@ void acpi_php_add(int pci_slot) hotplug_slots->plug_evt = (((php_slot+1 ) <<4 ) |PHP_EVT_ADD );/* update the slot status as present */ - hotplug_slots->slot[php_slot].status =0xf ; + hotplug_slots->status[php_slot]=0xf ;/* power on the slot */ power_on_php_slot (php_slot);
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
PATCH 2/4 ioemu: piix4acpi.c: Consistently dont cast opaque to PHPSlots
In reply to Simon HormanSome instances were cast and others were not.
This patch makes all instances not cast opaque into PHPSlots.
Also consistently use hotplug_slots as the variable to which opaque is assigned.
hw/piix4acpi.c +6 -6
@@ -279,24 +279,24 @@ static void acpi_php_writeb(void *opaquestatic void pcislots_save (QEMUFile * f,void * opaque) { -PHPSlots *s = (PHPSlots *)opaque; +PHPSlots *hotplug_slots = opaque;int i;for ( i =0 ; i <ACPI_PHP_SLOT_NUM ; i++ ) { -qemu_put_8s ( f, &s->status[i]); +qemu_put_8s ( f, &hotplug_slots->status[i]); } -qemu_put_8s (f, &s->plug_evt); +qemu_put_8s (f, &hotplug_slots->plug_evt); }static int pcislots_load (QEMUFile * f,void * opaque,int version_id) { -PHPSlots *s = (PHPSlots *)opaque; +PHPSlots *hotplug_slots = opaque;int i;if (version_id !=1 )return -EINVAL ;for ( i =0 ; i <ACPI_PHP_SLOT_NUM ; i++ ) { -qemu_get_8s ( f, &s->status[i]); +qemu_get_8s ( f, &hotplug_slots->status[i]); } -qemu_get_8s (f, &s->plug_evt); +qemu_get_8s (f, &hotplug_slots->plug_evt);return 0 ; }
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
PATCH 3/4 ioemu: piix4acpi.c: remove unnecessary assignment of pci_slots to local variables
In reply to Simon Hormanhw/piix4acpi.c +11 -11
@@ -302,21 +302,23 @@ static int pcislots_load(QEMUFile* f, vostatic void php_slots_init (void ) { -PHPSlots *slots = &php_slots;int i; -memset (slots,0 ,sizeof (PHPSlots)); +memset (&php_slots,0 ,sizeof (PHPSlots));/* update the pci slot status */ for ( i =0 ; i <PHP_SLOT_LEN ; i++ ) {if (test_pci_slot (PHP_TO_PCI_SLOT (i) ) ==1 ) - slots->status[i] =0xf ; + php_slots.status[i] =0xf ; }/* ACPI PCI hotplug controller */ -register_ioport_read (ACPI_PHP_IO_ADDR ,ACPI_PHP_SLOT_NUM +1 ,1 , acpi_php_readb, slots); -register_ioport_write (ACPI_PHP_IO_ADDR ,ACPI_PHP_SLOT_NUM +1 ,1 , acpi_php_writeb, slots); -register_savevm ("pcislots" ,0 ,1 , pcislots_save, pcislots_load, slots); +register_ioport_read (ACPI_PHP_IO_ADDR ,ACPI_PHP_SLOT_NUM +1 ,1 , + acpi_php_readb, &php_slots); +register_ioport_write (ACPI_PHP_IO_ADDR ,ACPI_PHP_SLOT_NUM +1 ,1 , + acpi_php_writeb, &php_slots); +register_savevm ("pcislots" ,0 ,1 , pcislots_save, pcislots_load, + &php_slots); }/* GPEx_STS occupy 1st half of the block, while GPEx_EN 2nd half */
@@ -452,7 +454,6 @@ static void acpi_sci_intr(GPEState *s)void acpi_php_del (int pci_slot) {GPEState *s = &gpe_state; -PHPSlots *hotplug_slots = &php_slots;int php_slot =PCI_TO_PHP_SLOT (pci_slot);if ( pci_slot <PHP_SLOT_START || pci_slot >=PHP_SLOT_END ) {
@@ -462,7 +463,7 @@ void acpi_php_del(int pci_slot) }/* update the php controller status */ - hotplug_slots->plug_evt = (((php_slot+1 ) <<4 ) |PHP_EVT_REMOVE ); + php_slots.plug_evt = (((php_slot+1 ) <<4 ) |PHP_EVT_REMOVE );/* generate a SCI interrupt */ acpi_sci_intr (s);
@@ -471,7 +472,6 @@ void acpi_php_del(int pci_slot)void acpi_php_add (int pci_slot) {GPEState *s = &gpe_state; -PHPSlots *hotplug_slots = &php_slots;int php_slot =PCI_TO_PHP_SLOT (pci_slot);char ret_str[30 ];
@@ -490,10 +490,10 @@ void acpi_php_add(int pci_slot) }/* update the php controller status */ - hotplug_slots->plug_evt = (((php_slot+1 ) <<4 ) |PHP_EVT_ADD ); + php_slots.plug_evt = (((php_slot+1 ) <<4 ) |PHP_EVT_ADD );/* update the slot status as present */ - hotplug_slots->status[php_slot]=0xf ; + php_slots.status[php_slot]=0xf ;/* power on the slot */ power_on_php_slot (php_slot);
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
PATCH 4/4 ioemu: piix4acpi.c: remove ACPI_PHP_SLOT_NUM
In reply to Simon HormanACPI_PHP_SLOT_NUM is equivalent to PHP_SLOT_LEN and both are used inside piix4acpi.c. So for the sake of consistency remove ACPI_PHP_SLOT_NUM.
hw/piix4acpi.c +5 -7
@@ -54,8 +54,6 @@/* The bit in GPE0_STS/EN to notify the pci hotplug event */ #define ACPI_PHP_GPE_BIT 3 -#define ACPI_PHP_SLOT_NUM PHP_SLOT_LEN -typedef struct AcpiDeviceState AcpiDeviceState ;AcpiDeviceState *acpi_device_table;
@@ -77,7 +75,7 @@ typedef struct GPEState {GPEState gpe_state;typedef struct PHPSlots { -uint8_t status[ACPI_PHP_SLOT_NUM ];/* Apaptor stats */ +uint8_t status[PHP_SLOT_LEN ];/* Apaptor stats */ uint8_t plug_evt;/* slot|event slot:0-no event;1-1st. event:0-remove;1-add */ }PHPSlots ;
@@ -281,7 +279,7 @@ static void pcislots_save(QEMUFile* f, v {PHPSlots *hotplug_slots = opaque;int i; -for ( i =0 ; i <ACPI_PHP_SLOT_NUM ; i++ ) { +for ( i =0 ; i <PHP_SLOT_LEN ; i++ ) {qemu_put_8s ( f, &hotplug_slots->status[i]); }qemu_put_8s (f, &hotplug_slots->plug_evt);
@@ -293,7 +291,7 @@ static int pcislots_load(QEMUFile* f, voint i;if (version_id !=1 )return -EINVAL ; -for ( i =0 ; i <ACPI_PHP_SLOT_NUM ; i++ ) { +for ( i =0 ; i <PHP_SLOT_LEN ; i++ ) {qemu_get_8s ( f, &hotplug_slots->status[i]); }qemu_get_8s (f, &hotplug_slots->plug_evt);
@@ -313,9 +311,9 @@ static void php_slots_init(void)/* ACPI PCI hotplug controller */ -register_ioport_read (ACPI_PHP_IO_ADDR ,ACPI_PHP_SLOT_NUM +1 ,1 , +register_ioport_read (ACPI_PHP_IO_ADDR ,PHP_SLOT_LEN +1 ,1 , acpi_php_readb, &php_slots); -register_ioport_write (ACPI_PHP_IO_ADDR ,ACPI_PHP_SLOT_NUM +1 ,1 , +register_ioport_write (ACPI_PHP_IO_ADDR ,PHP_SLOT_LEN +1 ,1 , acpi_php_writeb, &php_slots);register_savevm ("pcislots" ,0 ,1 , pcislots_save, pcislots_load, &php_slots);
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
PATCH 1/5 ioemu: Remove lsi_scsi_init()s devfn parameter as it is always passed as -1
In reply to Simon Hormanhw/lsi53c895a.c +2 -2
@@ -1974,13 +1974,13 @@ static int lsi_scsi_uninit(PCIDevice *d)return 0 ; } -void *lsi_scsi_init (PCIBus *bus,int devfn) +void *lsi_scsi_init (PCIBus *bus) {LSIState *s;uint8_t *pci_conf; s = (LSIState *)pci_register_device (bus,"LSI53C895A SCSI HBA" , -sizeof (*s), devfn,NULL ,NULL ); +sizeof (*s),-1 ,NULL ,NULL );if (s ==NULL ) {fprintf (stderr,"lsi-scsi: Failed to register PCI device\n" );return NULL ;
hw/pc.c +1 -1
@@ -1078,7 +1078,7 @@ vga_bios_error: max_bus =drive_get_max_bus (IF_SCSI );for (bus =0 ; bus <= max_bus; bus++) { - scsi =lsi_scsi_init (pci_bus,-1 ); + scsi =lsi_scsi_init (pci_bus);for (unit =0 ; unit <LSI_MAX_DEVS ; unit++) { index =drive_get_index (IF_SCSI , bus, unit);if (index ==-1 )
hw/pci.h +1 -1
@@ -263,7 +263,7 @@ pci_config_set_class(uint8_t *pci_config/* lsi53c895a.c */ #define LSI_MAX_DEVS 7void lsi_scsi_attach (void *opaque,BlockDriverState *bd,int id); -void *lsi_scsi_init (PCIBus *bus,int devfn); +void *lsi_scsi_init (PCIBus *bus);/* vmware_vga.c */ void pci_vmsvga_init(PCIBus *bus, uint8_t *vga_ram_base,
hw/realview.c +1 -1
@@ -112,7 +112,7 @@ static void realview_init(ram_addr_t ramfprintf (stderr,"qemu: too many SCSI bus\n" );exit (1 ); } - scsi_hba =lsi_scsi_init (pci_bus,-1 ); + scsi_hba =lsi_scsi_init (pci_bus);for (n =0 ; n <LSI_MAX_DEVS ; n++) { index =drive_get_index (IF_SCSI ,0 , n);if (index ==-1 )
hw/versatilepb.c +1 -1
@@ -207,7 +207,7 @@ static void versatile_init(ram_addr_t rafprintf (stderr,"qemu: too many SCSI bus\n" );exit (1 ); } - scsi_hba =lsi_scsi_init (pci_bus,-1 ); + scsi_hba =lsi_scsi_init (pci_bus);for (n =0 ; n <LSI_MAX_DEVS ; n++) { index =drive_get_index (IF_SCSI ,0 , n);if (index ==-1 )
hw/pci-hotplug.c +1 -1
@@ -112,7 +112,7 @@ static PCIDevice *qemu_pci_hot_add_storaswitch (type) {case IF_SCSI : - opaque =lsi_scsi_init (pci_bus,-1 ); + opaque =lsi_scsi_init (pci_bus);if (opaque && drive_idx >=0 )lsi_scsi_attach (opaque, drives_table[drive_idx].bdrv, drives_table[drive_idx].unit);
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
PATCH 2/5 ioemu: Remove lsi_scsi_init()s devfn parameter as it is always passed as -1
In reply to Simon Hormanhw/pc.c +1 -1
@@ -933,7 +933,7 @@ vga_bios_error:if (pci_enabled) { pci_bus =i440fx_init (&i440fx_state, i8259); - piix3_devfn =piix3_init (pci_bus,-1 ); + piix3_devfn =piix3_init (pci_bus); }else { pci_bus =NULL ; }
hw/pc.h +1 -1
@@ -113,7 +113,7 @@ int pcspk_audio_init(AudioState *, qemu_/* piix_pci.c */ PCIBus *i440fx_init (PCIDevice **pi440fx_state,qemu_irq *pic);void i440fx_set_smm (PCIDevice *d,int val); -int piix3_init (PCIBus *bus,int devfn); +int piix3_init (PCIBus *bus);void i440fx_init_memory_mappings (PCIDevice *d);extern PCIDevice *piix4_dev;
hw/piix_pci.c +2 -2
@@ -322,13 +322,13 @@ static int piix_load(QEMUFile* f, void *return pci_device_load (d, f); } -int piix3_init (PCIBus *bus,int devfn) +int piix3_init (PCIBus *bus) {PCIDevice *d;uint8_t *pci_conf; d =pci_register_device (bus,"PIIX3" ,sizeof (PCIDevice), - devfn,NULL ,NULL ); +-1 ,NULL ,NULL );register_savevm ("PIIX3" ,0 ,2 , piix_save, piix_load, d); piix3_dev = d;
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
PATCH 3/5 ioemu: Remove usb_ohci_init*()s devfn parameter as they are always passed as -1
In reply to Simon Hormanhw/pci.h +1 -1
@@ -274,7 +274,7 @@ void usb_uhci_piix3_init(PCIBus *bus, invoid usb_uhci_piix4_init (PCIBus *bus,int devfn);/* usb-ohci.c */ -void usb_ohci_init_pci (struct PCIBus *bus,int num_ports,int devfn); +void usb_ohci_init_pci (struct PCIBus *bus,int num_ports);/* eepro100.c */
hw/ppc_oldworld.c +1 -1
@@ -358,7 +358,7 @@ static void ppc_heathrow_init (ram_addr_ escc_mem_index);if (usb_enabled) { -usb_ohci_init_pci (pci_bus,3 ,-1 ); +usb_ohci_init_pci (pci_bus,3 ); }if (graphic_depth !=15 && graphic_depth !=32 && graphic_depth !=8 )
hw/ppc_prep.c +1 -1
@@ -734,7 +734,7 @@ static void ppc_prep_init (ram_addr_t ra#endif if (usb_enabled) { -usb_ohci_init_pci (pci_bus,3 ,-1 ); +usb_ohci_init_pci (pci_bus,3 ); } m48t59 =m48t59_init (i8259[8 ],0 ,0x0074 ,NVRAM_SIZE ,59 );
hw/realview.c +1 -1
@@ -106,7 +106,7 @@ static void realview_init(ram_addr_t ram pci_bus =pci_vpb_init (pic,48 ,1 );if (usb_enabled) { -usb_ohci_init_pci (pci_bus,3 ,-1 ); +usb_ohci_init_pci (pci_bus,3 ); }if (drive_get_max_bus (IF_SCSI ) >0 ) {fprintf (stderr,"qemu: too many SCSI bus\n" );
hw/versatilepb.c +1 -1
@@ -201,7 +201,7 @@ static void versatile_init(ram_addr_t ra } }if (usb_enabled) { -usb_ohci_init_pci (pci_bus,3 ,-1 ); +usb_ohci_init_pci (pci_bus,3 ); }if (drive_get_max_bus (IF_SCSI ) >0 ) {fprintf (stderr,"qemu: too many SCSI bus\n" );
hw/usb-ohci.c +6 -8
@@ -1619,7 +1619,7 @@ static CPUWriteMemoryFunc *ohci_writefn[ ohci_mem_write }; -static void usb_ohci_init (OHCIState *ohci,int num_ports,int devfn, +static void usb_ohci_init (OHCIState *ohci,int num_ports,qemu_irq irq,enum ohci_type type,const char *name) {int i;
@@ -1668,12 +1668,12 @@ static void ohci_mapfunc(PCIDevice *pci_cpu_register_physical_memory (addr, size, ohci->state.mem); } -void usb_ohci_init_pci (struct PCIBus *bus,int num_ports,int devfn) +void usb_ohci_init_pci (struct PCIBus *bus,int num_ports) {OHCIPCIState *ohci; ohci = (OHCIPCIState *)pci_register_device (bus,"OHCI USB" ,sizeof (*ohci), - devfn,NULL ,NULL ); +-1 ,NULL ,NULL );if (ohci ==NULL ) {fprintf (stderr,"usb-ohci: Failed to register PCI device\n" );return ;
@@ -1685,20 +1685,18 @@ void usb_ohci_init_pci(struct PCIBus *bupci_config_set_class (ohci->pci_dev.config,PCI_CLASS_SERIAL_USB ); ohci->pci_dev.config[0x3d ] =0x01 ;/* interrupt pin 1 */ -usb_ohci_init (&ohci->state, num_ports, devfn, ohci->pci_dev.irq[0 ], +usb_ohci_init (&ohci->state, num_ports, ohci->pci_dev.irq[0 ],OHCI_TYPE_PCI , ohci->pci_dev.name);pci_register_io_region ((struct PCIDevice *)ohci,0 ,256 ,PCI_ADDRESS_SPACE_MEM , ohci_mapfunc); } -void usb_ohci_init_pxa (target_phys_addr_t base,int num_ports,int devfn, -qemu_irq irq) +void usb_ohci_init_pxa (target_phys_addr_t base,int num_ports,qemu_irq irq) {OHCIState *ohci = (OHCIState *)qemu_mallocz (sizeof (OHCIState)); -usb_ohci_init (ohci, num_ports, devfn, irq, -OHCI_TYPE_PXA ,"OHCI USB" ); +usb_ohci_init (ohci, num_ports, irq,OHCI_TYPE_PXA ,"OHCI USB" );cpu_register_physical_memory (base,0x1000 , ohci->mem); }
hw/pxa.h +1 -2
@@ -219,7 +219,6 @@ struct pxa2xx_state_s *pxa270_init(unsigstruct pxa2xx_state_s *pxa255_init (unsigned int sdram_size);/* usb-ohci.c */ -void usb_ohci_init_pxa (target_phys_addr_t base,int num_ports,int devfn, -qemu_irq irq); +void usb_ohci_init_pxa (target_phys_addr_t base,int num_ports,qemu_irq irq);#endif /* PXA_H */
hw/pxa2xx.c +2 -2
@@ -2112,7 +2112,7 @@ struct pxa2xx_state_s *pxa270_init(unsig }if (usb_enabled) { -usb_ohci_init_pxa (0x4c000000 ,3 ,-1 , s->pic[PXA2XX_PIC_USBH1 ]); +usb_ohci_init_pxa (0x4c000000 ,3 , s->pic[PXA2XX_PIC_USBH1 ]); } s->pcmcia[0 ] =pxa2xx_pcmcia_init (0x20000000 );
@@ -2234,7 +2234,7 @@ struct pxa2xx_state_s *pxa255_init(unsig }if (usb_enabled) { -usb_ohci_init_pxa (0x4c000000 ,3 ,-1 , s->pic[PXA2XX_PIC_USBH1 ]); +usb_ohci_init_pxa (0x4c000000 ,3 , s->pic[PXA2XX_PIC_USBH1 ]); } s->pcmcia[0 ] =pxa2xx_pcmcia_init (0x20000000 );
hw/ppc_newworld.c +1 -1
@@ -304,7 +304,7 @@ static void ppc_core99_init (ram_addr_t escc_mem_index);if (usb_enabled) { -usb_ohci_init_pci (pci_bus,3 ,-1 ); +usb_ohci_init_pci (pci_bus,3 ); }if (graphic_depth !=15 && graphic_depth !=32 && graphic_depth !=8 )
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
PATCH 4/5 iommu: Define PCI_DEVFN_AUTO and use it
In reply to Simon Hormanhw/pci.c +1 -2
@@ -235,7 +235,6 @@ int pci_assign_devaddr(const char *addr,return pci_parse_devaddr (devaddr, domp, busp, slotp); } -/* -1 for devfn means auto assign */ PCIDevice *pci_register_device(PCIBus *bus, const char *name, int instance_size, int devfn, PCIConfigReadFunc *config_read,
@@ -246,7 +245,7 @@ PCIDevice *pci_register_device(PCIBus *bif (pci_irq_index >=PCI_DEVICES_MAX )return NULL ; -if (devfn <0 ) { +if (devfn ==PCI_DEVFN_AUTO ) {for (devfn = bus->devfn_min ; devfn <256 ; devfn +=8 ) {if (!bus->devices[devfn]) goto found;
hw/ac97.c +1 -1
@@ -1326,7 +1326,7 @@ int ac97_init (PCIBus *bus, AudioState * d = (PCIAC97LinkState *)pci_register_device (bus,"AC97" ,sizeof (PCIAC97LinkState), --1 ,NULL ,NULL ); +PCI_DEVFN_AUTO ,NULL ,NULL );if (!d) {AUD_log ("ac97" ,"Failed to register PCI device\n" );
hw/cirrus_vga.c +2 -1
@@ -3373,7 +3373,8 @@ void pci_cirrus_vga_init(PCIBus *bus, ui/* setup PCI configuration registers */ d = (PCICirrusVGAState *)pci_register_device (bus,"Cirrus VGA" ,sizeof (PCICirrusVGAState), --1 ,NULL , pci_cirrus_write_config); +PCI_DEVFN_AUTO ,NULL , + pci_cirrus_write_config); pci_conf = d->dev.config;pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_CIRRUS );pci_config_set_device_id (pci_conf, device_id);
hw/eepro100.c +2 -2
@@ -1744,8 +1744,8 @@ static PCIDevice *nic_init(PCIBus * bus,logout ("\n" ); d = (PCIEEPRO100State *)pci_register_device (bus, name, -sizeof (PCIEEPRO100State),-1 , -NULL ,NULL ); +sizeof (PCIEEPRO100State), +PCI_DEVFN_AUTO ,NULL ,NULL ); s = &d->eepro100; s->device = device;
hw/es1370.c +1 -1
@@ -1023,7 +1023,7 @@ int es1370_init (PCIBus *bus, AudioState d = (PCIES1370State *)pci_register_device (bus,"ES1370" ,sizeof (PCIES1370State), --1 ,NULL ,NULL ); +PCI_DEVFN_AUTO ,NULL ,NULL );if (!d) {AUD_log (NULL ,"Failed to register PCI device for ES1370\n" );
hw/ide.c +1 -1
@@ -3286,7 +3286,7 @@ void pci_cmd646_ide_init(PCIBus *bus, Bl d = (PCIIDEState *)pci_register_device (bus,"CMD646 IDE" ,sizeof (PCIIDEState), --1 , +PCI_DEVFN_AUTO ,NULL ,NULL ); d->type =IDE_TYPE_CMD646 ; pci_conf = d->dev.config;
hw/macio.c +1 -1
@@ -89,7 +89,7 @@ void macio_init (PCIBus *bus, int device d =pci_register_device (bus,"macio" ,sizeof (PCIDevice) +sizeof (macio_state_t), --1 ,NULL ,NULL ); +PCI_DEVFN_AUTO ,NULL ,NULL ); macio_state = (macio_state_t *)(d +1 ); macio_state->is_oldworld = is_oldworld; macio_state->pic_mem_index = pic_mem_index;
hw/openpic.c +1 -1
@@ -1143,7 +1143,7 @@ qemu_irq *openpic_init (PCIBus *bus, intreturn NULL ;if (bus) { opp = (openpic_t *)pci_register_device (bus,"OpenPIC" ,sizeof (openpic_t), --1 ,NULL ,NULL ); +PCI_DEVFN_AUTO ,NULL ,NULL );if (opp ==NULL )return NULL ; pci_conf = opp->pci_dev.config;
hw/pci.h +2 -0
@@ -144,6 +144,8 @@ typedef struct PCIIORegion {#define PCI_ROM_SLOT 6#define PCI_NUM_REGIONS 7 +#define PCI_DEVFN_AUTO -1 +#define PCI_DEVICES_MAX 64#define PCI_VENDOR_ID 0x00/* 16 bits */
hw/versatile_pci.c +2 -1
@@ -117,7 +117,8 @@ PCIBus *pci_vpb_init(qemu_irq *pic, int/* Normal config area. */ cpu_register_physical_memory (base +0x02000000 ,0x1000000 , mem_config); - d =pci_register_device (s, name,sizeof (PCIDevice),-1 ,NULL ,NULL ); + d =pci_register_device (s, name,sizeof (PCIDevice),PCI_DEVFN_AUTO , +NULL ,NULL );if (realview) {/* IO memory area. */
hw/vga.c +1 -1
@@ -2492,7 +2492,7 @@ int pci_vga_init(PCIBus *bus, uint8_t *v d = (PCIVGAState *)pci_register_device (bus,"VGA" ,sizeof (PCIVGAState), --1 ,NULL ,NULL ); +PCI_DEVFN_AUTO ,NULL ,NULL );if (!d)return -1 ; s = &d->vga_state;
hw/vmware_vga.c +1 -1
@@ -1214,7 +1214,7 @@ void pci_vmsvga_init(PCIBus *bus, uint8_/* Setup PCI configuration */ s = (struct pci_vmsvga_state_s *)pci_register_device (bus,"QEMUware SVGA" , -sizeof (struct pci_vmsvga_state_s ),-1 ,0 ,0 ); +sizeof (struct pci_vmsvga_state_s ),PCI_DEVFN_AUTO ,0 ,0 );pci_config_set_vendor_id (s->card.config,PCI_VENDOR_ID_VMWARE );pci_config_set_device_id (s->card.config,SVGA_PCI_DEVICE_ID ); s->card.config[PCI_COMMAND ] =0x07 ;/* I/O + Memory */
hw/lsi53c895a.c +1 -1
@@ -1980,7 +1980,7 @@ void *lsi_scsi_init(PCIBus *bus)uint8_t *pci_conf; s = (LSIState *)pci_register_device (bus,"LSI53C895A SCSI HBA" , -sizeof (*s),-1 ,NULL ,NULL ); +sizeof (*s),PCI_DEVFN_AUTO ,NULL ,NULL );if (s ==NULL ) {fprintf (stderr,"lsi-scsi: Failed to register PCI device\n" );return NULL ;
hw/mips_malta.c +1 -1
@@ -489,7 +489,7 @@ static void network_init (PCIBus *pci_bufor (i =0 ; i < nb_nics; i++) {NICInfo *nd = &nd_table[i]; -int devfn =-1 ; +int devfn =PCI_DEVFN_AUTO ;if (i ==0 && (!nd->model ||strcmp (nd->model,"pcnet" ) ==0 ))/* The malta board has a PCNet card using PCI SLOT 11 */
hw/pc.c +1 -1
@@ -1007,7 +1007,7 @@ vga_bios_error:if (!pci_enabled || (nd->model &&strcmp (nd->model,"ne2k_isa" ) ==0 ))pc_init_ne2k_isa (nd, i8259);else -pci_nic_init (pci_bus, nd,-1 ,"ne2k_pci" ); +pci_nic_init (pci_bus, nd,PCI_DEVFN_AUTO ,"ne2k_pci" ); }qemu_system_hot_add_init ();
hw/ppc_oldworld.c +1 -1
@@ -306,7 +306,7 @@ static void ppc_heathrow_init (ram_addr_ serial_hds[1], ESCC_CLOCK, 4);for (i =0 ; i < nb_nics; i++) -pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" ); +pci_nic_init (pci_bus, &nd_table[i],PCI_DEVFN_AUTO ,"ne2k_pci" );/* First IDE channel is a CMD646 on the PCI bus */
hw/ppc_prep.c +1 -1
@@ -674,7 +674,7 @@ static void ppc_prep_init (ram_addr_t raif (strcmp (nd_table[i].model,"ne2k_isa" ) ==0 ) {isa_ne2000_init (ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]); }else { -pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" ); +pci_nic_init (pci_bus, &nd_table[i],PCI_DEVFN_AUTO ,"ne2k_pci" ); } }
hw/realview.c +1 -1
@@ -126,7 +126,7 @@ static void realview_init(ram_addr_t ramsmc91c111_init (nd,0x4e000000 , pic[28 ]); done_smc =1 ; }else { -pci_nic_init (pci_bus, nd,-1 ,"rtl8139" ); +pci_nic_init (pci_bus, nd,PCI_DEVFN_AUTO ,"rtl8139" ); } }
hw/piix_pci.c +1 -1
@@ -328,7 +328,7 @@ int piix3_init(PCIBus *bus)uint8_t *pci_conf; d =pci_register_device (bus,"PIIX3" ,sizeof (PCIDevice), --1 ,NULL ,NULL ); +PCI_DEVFN_AUTO ,NULL ,NULL );register_savevm ("PIIX3" ,0 ,2 , piix_save, piix_load, d); piix3_dev = d;
hw/usb-ohci.c +1 -1
@@ -1673,7 +1673,7 @@ void usb_ohci_init_pci(struct PCIBus *buOHCIPCIState *ohci; ohci = (OHCIPCIState *)pci_register_device (bus,"OHCI USB" ,sizeof (*ohci), --1 ,NULL ,NULL ); +PCI_DEVFN_AUTO ,NULL ,NULL );if (ohci ==NULL ) {fprintf (stderr,"usb-ohci: Failed to register PCI device\n" );return ;
hw/pci-hotplug.c +1 -1
@@ -40,7 +40,7 @@ static PCIDevice *qemu_pci_hot_add_nic(P ret =net_client_init ("nic" , opts);if (ret <0 || !nd_table[ret].model)return NULL ; -return pci_nic_init (pci_bus, &nd_table[ret],-1 ,"rtl8139" ); +return pci_nic_init (pci_bus, &nd_table[ret],PCI_DEVFN_AUTO ,"rtl8139" ); }void drive_hot_add (const char *pci_addr,const char *opts)
hw/ppc440_bamboo.c +1 -1
@@ -124,7 +124,7 @@ static void bamboo_init(ram_addr_t ram_sfor (i =0 ; i < nb_nics; i++) {/* There are no PCI NICs on the Bamboo board, but there are * PCI slots, so we can pick whatever default model we want. */ -pci_nic_init (pcibus, &nd_table[i],-1 ,"e1000" ); +pci_nic_init (pcibus, &nd_table[i],PCI_DEVFN_AUTO ,"e1000" ); } }
hw/ppc_newworld.c +1 -1
@@ -276,7 +276,7 @@ static void ppc_core99_init (ram_addr_t serial_hds[0], serial_hds[1], ESCC_CLOCK, 4);for (i =0 ; i < nb_nics; i++) -pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" ); +pci_nic_init (pci_bus, &nd_table[i],PCI_DEVFN_AUTO ,"ne2k_pci" );if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {fprintf (stderr,"qemu: too many IDE bus\n" );
hw/r2d.c +1 -1
@@ -230,7 +230,7 @@ static void r2d_init(ram_addr_t ram_size/* NIC: rtl8139 on-board, and 2 slots. */ pci_nic_init (pci, &nd_table[0 ],2 <<3 ,"rtl8139" );for (i =1 ; i < nb_nics; i++) -pci_nic_init (pci, &nd_table[i],-1 ,"ne2k_pci" ); +pci_nic_init (pci, &nd_table[i],PCI_DEVFN_AUTO ,"ne2k_pci" );/* Todo: register on board registers */ {
hw/sun4u.c +2 -2
@@ -510,7 +510,7 @@ static void sun4uv_init(ram_addr_t RAM_s 0, 0);// XXX Should be pci_bus3 -pci_ebus_init (pci_bus,-1 ); +pci_ebus_init (pci_bus,PCI_DEVFN_AUTO ); i =0 ;if (hwdef->console_serial_base) {
@@ -533,7 +533,7 @@ static void sun4uv_init(ram_addr_t RAM_s }for (i =0 ; i < nb_nics; i++) -pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" ); +pci_nic_init (pci_bus, &nd_table[i],PCI_DEVFN_AUTO ,"ne2k_pci" ); irq =qemu_allocate_irqs (cpu_set_irq, env,MAX_PILS );if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {
hw/versatilepb.c +1 -1
@@ -197,7 +197,7 @@ static void versatile_init(ram_addr_t rasmc91c111_init (nd,0x10010000 , sic[25 ]); done_smc =1 ; }else { -pci_nic_init (pci_bus, nd,-1 ,"rtl8139" ); +pci_nic_init (pci_bus, nd,PCI_DEVFN_AUTO ,"rtl8139" ); } }if (usb_enabled) {
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
PATCH 5/5 iommu: Use PCI_DEVFN, PCI_SLOT and PCI_FUNC
In reply to Simon Hormanhw/apb_pci.c +2 -2
@@ -265,10 +265,10 @@ PCIBus *pci_apb_init(target_phys_addr_t d->config[0x0E ] =0x00 ;// header_type /* APB secondary busses */ - *bus2 =pci_bridge_init (s->bus,8 ,PCI_VENDOR_ID_SUN , + *bus2 =pci_bridge_init (s->bus,PCI_DEVFN ((1 ,0 ),PCI_VENDOR_ID_SUN ,PCI_DEVICE_ID_SUN_SIMBA , pci_apb_map_irq, "Advanced PCI Bus secondary bridge 1"); - *bus3 =pci_bridge_init (s->bus,9 ,PCI_VENDOR_ID_SUN , + *bus3 =pci_bridge_init (s->bus,PCI_DEVFN (1 ,1 ),PCI_VENDOR_ID_SUN ,PCI_DEVICE_ID_SUN_SIMBA , pci_apb_map_irq,"Advanced PCI Bus secondary bridge 2" );return s->bus;
hw/mips_malta.c +2 -2
@@ -493,7 +493,7 @@ static void network_init (PCIBus *pci_buif (i ==0 && (!nd->model ||strcmp (nd->model,"pcnet" ) ==0 ))/* The malta board has a PCNet card using PCI SLOT 11 */ - devfn =88 ; + devfn =PCI_DEVFN (11 ,0 );pci_nic_init (pci_bus, nd, devfn,"pcnet" ); }
@@ -904,7 +904,7 @@ void mips_malta_init (ram_addr_t ram_siz hd[i] =NULL ; } - piix4_devfn =piix4_init (pci_bus,80 ); + piix4_devfn =piix4_init (pci_bus,PCI_DEVFN (10 ,0 ));pci_piix4_ide_init (pci_bus, hd, piix4_devfn +1 , i8259);usb_uhci_piix4_init (pci_bus, piix4_devfn +2 ); smbus =piix4_pm_init (pci_bus, piix4_devfn +3 ,0x1100 , i8259[9 ]);
hw/unin_pci.c +2 -2
@@ -147,7 +147,7 @@ static CPUReadMemoryFunc *pci_unin_read[/* Don't know if this matches real hardware, but it agrees with OHW. */ static int pci_unin_map_irq (PCIDevice *pci_dev,int irq_num) { -return (irq_num + (pci_dev->devfn >>3 )) &3 ; +return (irq_num +PCI_SLOT (pci_dev->devfn)) &3 ; }static void pci_unin_set_irq (qemu_irq *pic,int irq_num,int level)
@@ -186,7 +186,7 @@ PCIBus *pci_pmac_init(qemu_irq *pic)/* Uninorth main bus */ s =qemu_mallocz (sizeof (UNINState)); s->bus =pci_register_bus (pci_unin_set_irq, pci_unin_map_irq, - pic,11 <<3 ,4 ); + pic,PCI_DEVFN (11 ,0 ),4 ); pci_mem_config =cpu_register_io_memory (0 , pci_unin_main_config_read, pci_unin_main_config_write, s);
hw/piix_pci.c +1 -1
@@ -51,7 +51,7 @@ static void piix3_set_irq(qemu_irq *pic,static int pci_slot_get_pirq (PCIDevice *pci_dev,int irq_num) {int slot_addend; - slot_addend = (pci_dev->devfn >>3 ) -1 ; + slot_addend =PCI_SLOT (pci_dev->devfn) -1 ;return (irq_num + slot_addend) &3 ; }
hw/grackle_pci.c +1 -1
@@ -96,7 +96,7 @@ static CPUReadMemoryFunc *pci_grackle_re/* Don't know if this matches real hardware, but it agrees with OHW. */ static int pci_grackle_map_irq (PCIDevice *pci_dev,int irq_num) { -return (irq_num + (pci_dev->devfn >>3 )) &3 ; +return (irq_num +PCI_SLOT (pci_dev->devfn)) &3 ; }static void pci_grackle_set_irq (qemu_irq *pic,int irq_num,int level)
hw/gt64xxx.c +1 -1
@@ -870,7 +870,7 @@ static int pci_gt64120_map_irq(PCIDevice {int slot; - slot = (pci_dev->devfn >>3 ); + slot =PCI_SLOT (pci_dev->devfn);switch (slot) {/* PIIX4 USB */
hw/pci.c +1 -1
@@ -709,7 +709,7 @@ static void pci_info_device(PCIDevice *dconst pci_class_desc *desc;term_printf (" Bus %2d, device %3d, function %d:\n" , - d->bus->bus_num, d->devfn >>3 , d->devfn &7 ); + d->bus->bus_num,PCI_SLOT (d->devfn),PCI_FUNC (d->devfn)); class =le16_to_cpu (*((uint16_t *)(d->config +PCI_CLASS_DEVICE )));term_printf (" " ); desc = pci_class_descriptions;
hw/ppc4xx_pci.c +1 -1
@@ -297,7 +297,7 @@ static void ppc4xx_pci_reset(void *opaqu* may need further refactoring for other boards. */ static int ppc4xx_pci_map_irq (PCIDevice *pci_dev,int irq_num) { -int slot = pci_dev->devfn >>3 ; +int slot =PCI_SLOT (pci_dev->devfn);DPRINTF ("%s: devfn %x irq %d -> %d\n" , __func__, pci_dev->devfn, irq_num, slot);
hw/prep_pci.c +1 -1
@@ -121,7 +121,7 @@ static CPUReadMemoryFunc *PPC_PCIIO_readstatic int prep_map_irq (PCIDevice *pci_dev,int irq_num) { -return (irq_num + (pci_dev->devfn >>3 )) &1 ; +return (irq_num +PCI_SLOT (pci_dev->devfn)) &1 ; }static void prep_set_irq (qemu_irq *pic,int irq_num,int level)
hw/r2d.c +1 -1
@@ -187,7 +187,7 @@ static void r2d_pci_set_irq(qemu_irq *p,static int r2d_pci_map_irq (PCIDevice *d,int irq_num) {const int intx[] = {PCI_INTA ,PCI_INTB ,PCI_INTC ,PCI_INTD }; -return intx[d->devfn >>3 ]; +return intx[PCI_SLOT (d->devfn)]; } static void r2d_init(ram_addr_t ram_size, int vga_ram_size,
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en