net: set a default value for sndbuf=
[qemu/aliguori-queue.git] / hw / sysbus.c
blob08f15e42fad47191d14872a277ec0ee067e03b78
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"
23 #include "monitor.h"
25 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
27 struct BusInfo system_bus_info = {
28 .name = "System",
29 .size = sizeof(BusState),
30 .print_dev = sysbus_dev_print,
33 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq)
35 assert(n >= 0 && n < dev->num_irq);
36 dev->irqs[n] = 0;
37 if (dev->irqp[n]) {
38 *dev->irqp[n] = irq;
42 void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr)
44 assert(n >= 0 && n < dev->num_mmio);
46 if (dev->mmio[n].addr == addr) {
47 /* ??? region already mapped here. */
48 return;
50 if (dev->mmio[n].addr != (target_phys_addr_t)-1) {
51 /* Unregister previous mapping. */
52 cpu_register_physical_memory(dev->mmio[n].addr, dev->mmio[n].size,
53 IO_MEM_UNASSIGNED);
55 dev->mmio[n].addr = addr;
56 if (dev->mmio[n].cb) {
57 dev->mmio[n].cb(dev, addr);
58 } else {
59 cpu_register_physical_memory(addr, dev->mmio[n].size,
60 dev->mmio[n].iofunc);
65 /* Request an IRQ source. The actual IRQ object may be populated later. */
66 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p)
68 int n;
70 assert(dev->num_irq < QDEV_MAX_IRQ);
71 n = dev->num_irq++;
72 dev->irqp[n] = p;
75 /* Pass IRQs from a target device. */
76 void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target)
78 int i;
79 assert(dev->num_irq == 0);
80 dev->num_irq = target->num_irq;
81 for (i = 0; i < dev->num_irq; i++) {
82 dev->irqp[i] = target->irqp[i];
86 void sysbus_init_mmio(SysBusDevice *dev, target_phys_addr_t size, int iofunc)
88 int n;
90 assert(dev->num_mmio < QDEV_MAX_MMIO);
91 n = dev->num_mmio++;
92 dev->mmio[n].addr = -1;
93 dev->mmio[n].size = size;
94 dev->mmio[n].iofunc = iofunc;
97 void sysbus_init_mmio_cb(SysBusDevice *dev, target_phys_addr_t size,
98 mmio_mapfunc cb)
100 int n;
102 assert(dev->num_mmio < QDEV_MAX_MMIO);
103 n = dev->num_mmio++;
104 dev->mmio[n].addr = -1;
105 dev->mmio[n].size = size;
106 dev->mmio[n].cb = cb;
109 static void sysbus_device_init(DeviceState *dev, DeviceInfo *base)
111 SysBusDeviceInfo *info = container_of(base, SysBusDeviceInfo, qdev);
113 info->init(sysbus_from_qdev(dev));
116 void sysbus_register_withprop(SysBusDeviceInfo *info)
118 info->qdev.init = sysbus_device_init;
119 info->qdev.bus_info = &system_bus_info;
121 assert(info->qdev.size >= sizeof(SysBusDevice));
122 qdev_register(&info->qdev);
125 void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init)
127 SysBusDeviceInfo *info;
129 info = qemu_mallocz(sizeof(*info));
130 info->qdev.name = qemu_strdup(name);
131 info->qdev.size = size;
132 info->init = init;
133 sysbus_register_withprop(info);
136 DeviceState *sysbus_create_varargs(const char *name,
137 target_phys_addr_t addr, ...)
139 DeviceState *dev;
140 SysBusDevice *s;
141 va_list va;
142 qemu_irq irq;
143 int n;
145 dev = qdev_create(NULL, name);
146 s = sysbus_from_qdev(dev);
147 qdev_init(dev);
148 if (addr != (target_phys_addr_t)-1) {
149 sysbus_mmio_map(s, 0, addr);
151 va_start(va, addr);
152 n = 0;
153 while (1) {
154 irq = va_arg(va, qemu_irq);
155 if (!irq) {
156 break;
158 sysbus_connect_irq(s, n, irq);
159 n++;
161 return dev;
164 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
166 SysBusDevice *s = sysbus_from_qdev(dev);
167 int i;
169 for (i = 0; i < s->num_mmio; i++) {
170 monitor_printf(mon, "%*smmio " TARGET_FMT_plx "/" TARGET_FMT_plx "\n",
171 indent, "", s->mmio[i].addr, s->mmio[i].size);