serial: Factor out common serial_hds_isa_init()

It's the same old loop copied five times, plus another instance where
it's clipped to two iterations and unrolled.

No external users of serial_isa_init() are left, so give it internal
linkage.

Maintainers of affected machines cc'ed.

Cc: Richard Henderson <rth@twiddle.net>
Cc: Anthony Liguori <aliguori@amazon.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Leon Alrae <leon.alrae@imgtec.com>
Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
Markus Armbruster 2015-02-04 18:33:05 +01:00 committed by Andreas Färber
parent aef0d55a4b
commit b6607a1a20
8 changed files with 22 additions and 30 deletions

View File

@ -83,11 +83,7 @@ static void clipper_init(MachineState *machine)
pci_vga_init(pci_bus);
/* Serial code setup. */
for (i = 0; i < MAX_SERIAL_PORTS; ++i) {
if (serial_hds[i]) {
serial_isa_init(isa_bus, i, serial_hds[i]);
}
}
serial_hds_isa_init(isa_bus, MAX_SERIAL_PORTS);
/* Network setup. e1000 is good enough, failing Tulip support. */
for (i = 0; i < nb_nics; i++) {

View File

@ -119,7 +119,7 @@ static void serial_register_types(void)
type_init(serial_register_types)
bool serial_isa_init(ISABus *bus, int index, CharDriverState *chr)
static bool serial_isa_init(ISABus *bus, int index, CharDriverState *chr)
{
DeviceState *dev;
ISADevice *isadev;
@ -136,3 +136,16 @@ bool serial_isa_init(ISABus *bus, int index, CharDriverState *chr)
}
return true;
}
void serial_hds_isa_init(ISABus *bus, int n)
{
int i;
assert(n <= MAX_SERIAL_PORTS);
for (i = 0; i < n; ++i) {
if (serial_hds[i]) {
serial_isa_init(bus, i, serial_hds[i]);
}
}
}

View File

@ -1419,11 +1419,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
pcspk_init(isa_bus, pit);
}
for(i = 0; i < MAX_SERIAL_PORTS; i++) {
if (serial_hds[i]) {
serial_isa_init(isa_bus, i, serial_hds[i]);
}
}
serial_hds_isa_init(isa_bus, MAX_SERIAL_PORTS);
for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
if (parallel_hds[i]) {

View File

@ -277,7 +277,6 @@ static void mips_fulong2e_init(MachineState *machine)
PCIBus *pci_bus;
ISABus *isa_bus;
I2CBus *smbus;
int i;
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
MIPSCPU *cpu;
CPUMIPSState *env;
@ -384,11 +383,7 @@ static void mips_fulong2e_init(MachineState *machine)
rtc_init(isa_bus, 2000, NULL);
for(i = 0; i < MAX_SERIAL_PORTS; i++) {
if (serial_hds[i]) {
serial_isa_init(isa_bus, i, serial_hds[i]);
}
}
serial_hds_isa_init(isa_bus, MAX_SERIAL_PORTS);
if (parallel_hds[0]) {
parallel_init(isa_bus, 0, parallel_hds[0]);

View File

@ -1172,8 +1172,7 @@ void mips_malta_init(MachineState *machine)
isa_create_simple(isa_bus, "i8042");
rtc_init(isa_bus, 2000, NULL);
serial_isa_init(isa_bus, 0, serial_hds[0]);
serial_isa_init(isa_bus, 1, serial_hds[1]);
serial_hds_isa_init(isa_bus, 2);
if (parallel_hds[0])
parallel_init(isa_bus, 0, parallel_hds[0]);
for(i = 0; i < MAX_FD; i++) {

View File

@ -283,11 +283,7 @@ void mips_r4k_init(MachineState *machine)
pit = pit_init(isa_bus, 0x40, 0, NULL);
for(i = 0; i < MAX_SERIAL_PORTS; i++) {
if (serial_hds[i]) {
serial_isa_init(isa_bus, i, serial_hds[i]);
}
}
serial_hds_isa_init(isa_bus, MAX_SERIAL_PORTS);
isa_vga_init(isa_bus);

View File

@ -849,11 +849,8 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
NULL, 115200, serial_hds[i], DEVICE_BIG_ENDIAN);
i++;
}
for(; i < MAX_SERIAL_PORTS; i++) {
if (serial_hds[i]) {
serial_isa_init(isa_bus, i, serial_hds[i]);
}
}
serial_hds_isa_init(isa_bus, MAX_SERIAL_PORTS);
for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
if (parallel_hds[i]) {

View File

@ -92,6 +92,6 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
/* serial-isa.c */
#define TYPE_ISA_SERIAL "isa-serial"
bool serial_isa_init(ISABus *bus, int index, CharDriverState *chr);
void serial_hds_isa_init(ISABus *bus, int n);
#endif