virtio-9p: Avoid SEGV when log file couldn't be opened
[qemu/mdroth.git] / hw / isa-bus.c
blob4e306de9cfd4d29efbc7a6e036bc866e8618e25d
1 /*
2 * isa bus support for qdev.
4 * Copyright (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "hw.h"
20 #include "sysemu.h"
21 #include "monitor.h"
22 #include "sysbus.h"
23 #include "isa.h"
25 struct ISABus {
26 BusState qbus;
27 qemu_irq *irqs;
28 uint32_t assigned;
30 static ISABus *isabus;
31 target_phys_addr_t isa_mem_base = 0;
33 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent);
35 static struct BusInfo isa_bus_info = {
36 .name = "ISA",
37 .size = sizeof(ISABus),
38 .print_dev = isabus_dev_print,
41 ISABus *isa_bus_new(DeviceState *dev)
43 if (isabus) {
44 fprintf(stderr, "Can't create a second ISA bus\n");
45 return NULL;
47 if (NULL == dev) {
48 dev = qdev_create(NULL, "isabus-bridge");
49 qdev_init_nofail(dev);
52 isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL));
53 return isabus;
56 void isa_bus_irqs(qemu_irq *irqs)
58 isabus->irqs = irqs;
62 * isa_reserve_irq() reserves the ISA irq and returns the corresponding
63 * qemu_irq entry for the i8259.
65 * This function is only for special cases such as the 'ferr', and
66 * temporary use for normal devices until they are converted to qdev.
68 qemu_irq isa_reserve_irq(int isairq)
70 if (isairq < 0 || isairq > 15) {
71 fprintf(stderr, "isa irq %d invalid\n", isairq);
72 exit(1);
74 if (isabus->assigned & (1 << isairq)) {
75 fprintf(stderr, "isa irq %d already assigned\n", isairq);
76 exit(1);
78 isabus->assigned |= (1 << isairq);
79 return isabus->irqs[isairq];
82 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq)
84 assert(dev->nirqs < ARRAY_SIZE(dev->isairq));
85 if (isabus->assigned & (1 << isairq)) {
86 fprintf(stderr, "isa irq %d already assigned\n", isairq);
87 exit(1);
89 isabus->assigned |= (1 << isairq);
90 dev->isairq[dev->nirqs] = isairq;
91 *p = isabus->irqs[isairq];
92 dev->nirqs++;
95 static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
97 ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev);
98 ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base);
100 dev->isairq[0] = -1;
101 dev->isairq[1] = -1;
103 return info->init(dev);
106 void isa_qdev_register(ISADeviceInfo *info)
108 info->qdev.init = isa_qdev_init;
109 info->qdev.bus_info = &isa_bus_info;
110 qdev_register(&info->qdev);
113 ISADevice *isa_create(const char *name)
115 DeviceState *dev;
117 if (!isabus) {
118 hw_error("Tried to create isa device %s with no isa bus present.\n",
119 name);
121 dev = qdev_create(&isabus->qbus, name);
122 return DO_UPCAST(ISADevice, qdev, dev);
125 ISADevice *isa_create_simple(const char *name)
127 ISADevice *dev;
129 dev = isa_create(name);
130 qdev_init_nofail(&dev->qdev);
131 return dev;
134 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
136 ISADevice *d = DO_UPCAST(ISADevice, qdev, dev);
138 if (d->isairq[1] != -1) {
139 monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "",
140 d->isairq[0], d->isairq[1]);
141 } else if (d->isairq[0] != -1) {
142 monitor_printf(mon, "%*sisa irq %d\n", indent, "",
143 d->isairq[0]);
147 static int isabus_bridge_init(SysBusDevice *dev)
149 /* nothing */
150 return 0;
153 static SysBusDeviceInfo isabus_bridge_info = {
154 .init = isabus_bridge_init,
155 .qdev.name = "isabus-bridge",
156 .qdev.size = sizeof(SysBusDevice),
157 .qdev.no_user = 1,
160 static void isabus_register_devices(void)
162 sysbus_register_withprop(&isabus_bridge_info);
165 device_init(isabus_register_devices)