mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 03:59:52 +00:00
serial-pci-multi: factor out multi_serial_get_port_count()
Common function to be reused in next patch. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
This commit is contained in:
parent
1e419ee68f
commit
4305d4825c
@ -77,33 +77,34 @@ static void multi_serial_irq_mux(void *opaque, int n, int level)
|
|||||||
pci_set_irq(&pci->dev, pending);
|
pci_set_irq(&pci->dev, pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t multi_serial_get_port_count(PCIDeviceClass *pc)
|
||||||
|
{
|
||||||
|
switch (pc->device_id) {
|
||||||
|
case 0x0003:
|
||||||
|
return 2;
|
||||||
|
case 0x0004:
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
|
static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
|
||||||
{
|
{
|
||||||
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
|
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
|
||||||
PCIMultiSerialState *pci = DO_UPCAST(PCIMultiSerialState, dev, dev);
|
PCIMultiSerialState *pci = DO_UPCAST(PCIMultiSerialState, dev, dev);
|
||||||
SerialState *s;
|
SerialState *s;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
int i, nr_ports = 0;
|
size_t i, nports = multi_serial_get_port_count(pc);
|
||||||
|
|
||||||
switch (pc->device_id) {
|
|
||||||
case 0x0003:
|
|
||||||
nr_ports = 2;
|
|
||||||
break;
|
|
||||||
case 0x0004:
|
|
||||||
nr_ports = 4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
assert(nr_ports > 0);
|
|
||||||
assert(nr_ports <= PCI_SERIAL_MAX_PORTS);
|
|
||||||
|
|
||||||
pci->dev.config[PCI_CLASS_PROG] = pci->prog_if;
|
pci->dev.config[PCI_CLASS_PROG] = pci->prog_if;
|
||||||
pci->dev.config[PCI_INTERRUPT_PIN] = 0x01;
|
pci->dev.config[PCI_INTERRUPT_PIN] = 0x01;
|
||||||
memory_region_init(&pci->iobar, OBJECT(pci), "multiserial", 8 * nr_ports);
|
memory_region_init(&pci->iobar, OBJECT(pci), "multiserial", 8 * nports);
|
||||||
pci_register_bar(&pci->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &pci->iobar);
|
pci_register_bar(&pci->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &pci->iobar);
|
||||||
pci->irqs = qemu_allocate_irqs(multi_serial_irq_mux, pci,
|
pci->irqs = qemu_allocate_irqs(multi_serial_irq_mux, pci, nports);
|
||||||
nr_ports);
|
|
||||||
|
|
||||||
for (i = 0; i < nr_ports; i++) {
|
for (i = 0; i < nports; i++) {
|
||||||
s = pci->state + i;
|
s = pci->state + i;
|
||||||
s->baudbase = 115200;
|
s->baudbase = 115200;
|
||||||
serial_realize_core(s, &err);
|
serial_realize_core(s, &err);
|
||||||
@ -113,7 +114,7 @@ static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s->irq = pci->irqs[i];
|
s->irq = pci->irqs[i];
|
||||||
pci->name[i] = g_strdup_printf("uart #%d", i + 1);
|
pci->name[i] = g_strdup_printf("uart #%zu", i + 1);
|
||||||
memory_region_init_io(&s->io, OBJECT(pci), &serial_io_ops, s,
|
memory_region_init_io(&s->io, OBJECT(pci), &serial_io_ops, s,
|
||||||
pci->name[i], 8);
|
pci->name[i], 8);
|
||||||
memory_region_add_subregion(&pci->iobar, 8 * i, &s->io);
|
memory_region_add_subregion(&pci->iobar, 8 * i, &s->io);
|
||||||
|
Loading…
Reference in New Issue
Block a user