kvm: add error message for when SMP is requested
[qemu-kvm/fedora.git] / hw / sysbus.c
blobe6cb7dd78b0a23c2ccb8ac856121b0970ebaf300
1 /*
2 * System (CPU) Bus device support code
4 * Copyright (c) 2009 CodeSourcery
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, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
21 #include "sysbus.h"
22 #include "sysemu.h"
24 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq)
26 assert(n >= 0 && n < dev->num_irq);
27 dev->irqs[n] = 0;
28 if (dev->irqp[n]) {
29 *dev->irqp[n] = irq;
33 void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr)
35 assert(n >= 0 && n < dev->num_mmio);
37 if (dev->mmio[n].addr == addr) {
38 /* ??? region already mapped here. */
39 return;
41 if (dev->mmio[n].addr != (target_phys_addr_t)-1) {
42 /* Unregister previous mapping. */
43 cpu_register_physical_memory(dev->mmio[n].addr, dev->mmio[n].size,
44 IO_MEM_UNASSIGNED);
46 dev->mmio[n].addr = addr;
47 if (dev->mmio[n].cb) {
48 dev->mmio[n].cb(dev, addr);
49 } else {
50 cpu_register_physical_memory(addr, dev->mmio[n].size,
51 dev->mmio[n].iofunc);
56 /* Request an IRQ source. The actual IRQ object may be populated later. */
57 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p)
59 int n;
61 assert(dev->num_irq < QDEV_MAX_IRQ);
62 n = dev->num_irq++;
63 dev->irqp[n] = p;
66 /* Pass IRQs from a target device. */
67 void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target)
69 int i;
70 assert(dev->num_irq == 0);
71 dev->num_irq = target->num_irq;
72 for (i = 0; i < dev->num_irq; i++) {
73 dev->irqp[i] = target->irqp[i];
77 void sysbus_init_mmio(SysBusDevice *dev, target_phys_addr_t size, int iofunc)
79 int n;
81 assert(dev->num_mmio < QDEV_MAX_MMIO);
82 n = dev->num_mmio++;
83 dev->mmio[n].addr = -1;
84 dev->mmio[n].size = size;
85 dev->mmio[n].iofunc = iofunc;
88 void sysbus_init_mmio_cb(SysBusDevice *dev, target_phys_addr_t size,
89 mmio_mapfunc cb)
91 int n;
93 assert(dev->num_mmio < QDEV_MAX_MMIO);
94 n = dev->num_mmio++;
95 dev->mmio[n].addr = -1;
96 dev->mmio[n].size = size;
97 dev->mmio[n].cb = cb;
100 static void sysbus_device_init(DeviceState *dev, void *opaque)
102 sysbus_initfn init = (sysbus_initfn)opaque;
104 init(sysbus_from_qdev(dev));
107 void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init)
109 assert(size >= sizeof(SysBusDevice));
110 qdev_register(name, size, sysbus_device_init, init);
113 DeviceState *sysbus_create_varargs(const char *name,
114 target_phys_addr_t addr, ...)
116 DeviceState *dev;
117 SysBusDevice *s;
118 va_list va;
119 qemu_irq irq;
120 int n;
122 dev = qdev_create(NULL, name);
123 s = sysbus_from_qdev(dev);
124 qdev_init(dev);
125 if (addr != (target_phys_addr_t)-1) {
126 sysbus_mmio_map(s, 0, addr);
128 va_start(va, addr);
129 n = 0;
130 while (1) {
131 irq = va_arg(va, qemu_irq);
132 if (!irq) {
133 break;
135 sysbus_connect_irq(s, n, irq);
136 n++;
138 return dev;