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
25 void sysbus_connect_irq(SysBusDevice
*dev
, int n
, qemu_irq irq
)
27 assert(n
>= 0 && n
< dev
->num_irq
);
34 void sysbus_mmio_map(SysBusDevice
*dev
, int n
, target_phys_addr_t addr
)
36 assert(n
>= 0 && n
< dev
->num_mmio
);
38 if (dev
->mmio
[n
].addr
== addr
) {
39 /* ??? region already mapped here. */
42 if (dev
->mmio
[n
].addr
!= (target_phys_addr_t
)-1) {
43 /* Unregister previous mapping. */
44 cpu_register_physical_memory(dev
->mmio
[n
].addr
, dev
->mmio
[n
].size
,
47 dev
->mmio
[n
].addr
= addr
;
48 if (dev
->mmio
[n
].cb
) {
49 dev
->mmio
[n
].cb(dev
, addr
);
51 cpu_register_physical_memory(addr
, dev
->mmio
[n
].size
,
57 /* Request an IRQ source. The actual IRQ object may be populated later. */
58 void sysbus_init_irq(SysBusDevice
*dev
, qemu_irq
*p
)
62 assert(dev
->num_irq
< QDEV_MAX_IRQ
);
67 /* Pass IRQs from a target device. */
68 void sysbus_pass_irq(SysBusDevice
*dev
, SysBusDevice
*target
)
71 assert(dev
->num_irq
== 0);
72 dev
->num_irq
= target
->num_irq
;
73 for (i
= 0; i
< dev
->num_irq
; i
++) {
74 dev
->irqp
[i
] = target
->irqp
[i
];
78 void sysbus_init_mmio(SysBusDevice
*dev
, target_phys_addr_t size
, int iofunc
)
82 assert(dev
->num_mmio
< QDEV_MAX_MMIO
);
84 dev
->mmio
[n
].addr
= -1;
85 dev
->mmio
[n
].size
= size
;
86 dev
->mmio
[n
].iofunc
= iofunc
;
89 void sysbus_init_mmio_cb(SysBusDevice
*dev
, target_phys_addr_t size
,
94 assert(dev
->num_mmio
< QDEV_MAX_MMIO
);
96 dev
->mmio
[n
].addr
= -1;
97 dev
->mmio
[n
].size
= size
;
101 static void sysbus_device_init(DeviceState
*dev
, DeviceInfo
*base
)
103 SysBusDeviceInfo
*info
= container_of(base
, SysBusDeviceInfo
, qdev
);
105 info
->init(sysbus_from_qdev(dev
));
108 void sysbus_register_withprop(SysBusDeviceInfo
*info
)
110 info
->qdev
.init
= sysbus_device_init
;
111 info
->qdev
.bus_type
= BUS_TYPE_SYSTEM
;
113 assert(info
->qdev
.size
>= sizeof(SysBusDevice
));
114 qdev_register(&info
->qdev
);
117 void sysbus_register_dev(const char *name
, size_t size
, sysbus_initfn init
)
119 SysBusDeviceInfo
*info
;
121 info
= qemu_mallocz(sizeof(*info
));
122 info
->qdev
.name
= qemu_strdup(name
);
123 info
->qdev
.size
= size
;
125 sysbus_register_withprop(info
);
128 DeviceState
*sysbus_create_varargs(const char *name
,
129 target_phys_addr_t addr
, ...)
137 dev
= qdev_create(NULL
, name
);
138 s
= sysbus_from_qdev(dev
);
140 if (addr
!= (target_phys_addr_t
)-1) {
141 sysbus_mmio_map(s
, 0, addr
);
146 irq
= va_arg(va
, qemu_irq
);
150 sysbus_connect_irq(s
, n
, irq
);
156 void sysbus_dev_print(Monitor
*mon
, DeviceState
*dev
, int indent
)
158 SysBusDevice
*s
= sysbus_from_qdev(dev
);
161 for (i
= 0; i
< s
->num_mmio
; i
++) {
162 monitor_printf(mon
, "%*smmio " TARGET_FMT_plx
"/" TARGET_FMT_plx
"\n",
163 indent
, "", s
->mmio
[i
].addr
, s
->mmio
[i
].size
);