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
24 void sysbus_connect_irq(SysBusDevice
*dev
, int n
, qemu_irq irq
)
26 assert(n
>= 0 && n
< dev
->num_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. */
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
,
46 dev
->mmio
[n
].addr
= addr
;
47 if (dev
->mmio
[n
].cb
) {
48 dev
->mmio
[n
].cb(dev
, addr
);
50 cpu_register_physical_memory(addr
, dev
->mmio
[n
].size
,
56 /* Request an IRQ source. The actual IRQ object may be populated later. */
57 void sysbus_init_irq(SysBusDevice
*dev
, qemu_irq
*p
)
61 assert(dev
->num_irq
< QDEV_MAX_IRQ
);
66 /* Pass IRQs from a target device. */
67 void sysbus_pass_irq(SysBusDevice
*dev
, SysBusDevice
*target
)
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
)
81 assert(dev
->num_mmio
< QDEV_MAX_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
,
93 assert(dev
->num_mmio
< QDEV_MAX_MMIO
);
95 dev
->mmio
[n
].addr
= -1;
96 dev
->mmio
[n
].size
= size
;
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
, ...)
122 dev
= qdev_create(NULL
, name
);
123 s
= sysbus_from_qdev(dev
);
125 if (addr
!= (target_phys_addr_t
)-1) {
126 sysbus_mmio_map(s
, 0, addr
);
131 irq
= va_arg(va
, qemu_irq
);
135 sysbus_connect_irq(s
, n
, irq
);