Statistics
| Branch: | Revision:

root / hw / milkymist-hw.h @ 0200db65

History | View | Annotate | Download (6.2 kB)

1 38d33393 Michael Walle
#ifndef QEMU_HW_MILKYMIST_H
2 38d33393 Michael Walle
#define QEMU_HW_MILKYMIST_H
3 38d33393 Michael Walle
4 57aa265d Michael Walle
#include "qdev.h"
5 57aa265d Michael Walle
#include "qdev-addr.h"
6 57aa265d Michael Walle
7 38d33393 Michael Walle
static inline DeviceState *milkymist_uart_create(target_phys_addr_t base,
8 fcfa3397 Michael Walle
        qemu_irq irq)
9 38d33393 Michael Walle
{
10 38d33393 Michael Walle
    DeviceState *dev;
11 38d33393 Michael Walle
12 38d33393 Michael Walle
    dev = qdev_create(NULL, "milkymist-uart");
13 38d33393 Michael Walle
    qdev_init_nofail(dev);
14 38d33393 Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
15 fcfa3397 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 0, irq);
16 38d33393 Michael Walle
17 38d33393 Michael Walle
    return dev;
18 38d33393 Michael Walle
}
19 38d33393 Michael Walle
20 38d33393 Michael Walle
static inline DeviceState *milkymist_hpdmc_create(target_phys_addr_t base)
21 38d33393 Michael Walle
{
22 38d33393 Michael Walle
    DeviceState *dev;
23 38d33393 Michael Walle
24 38d33393 Michael Walle
    dev = qdev_create(NULL, "milkymist-hpdmc");
25 38d33393 Michael Walle
    qdev_init_nofail(dev);
26 38d33393 Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
27 38d33393 Michael Walle
28 38d33393 Michael Walle
    return dev;
29 38d33393 Michael Walle
}
30 38d33393 Michael Walle
31 38d33393 Michael Walle
static inline DeviceState *milkymist_memcard_create(target_phys_addr_t base)
32 38d33393 Michael Walle
{
33 38d33393 Michael Walle
    DeviceState *dev;
34 38d33393 Michael Walle
35 38d33393 Michael Walle
    dev = qdev_create(NULL, "milkymist-memcard");
36 38d33393 Michael Walle
    qdev_init_nofail(dev);
37 38d33393 Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
38 38d33393 Michael Walle
39 38d33393 Michael Walle
    return dev;
40 38d33393 Michael Walle
}
41 38d33393 Michael Walle
42 38d33393 Michael Walle
static inline DeviceState *milkymist_vgafb_create(target_phys_addr_t base,
43 38d33393 Michael Walle
        uint32_t fb_offset, uint32_t fb_mask)
44 38d33393 Michael Walle
{
45 38d33393 Michael Walle
    DeviceState *dev;
46 38d33393 Michael Walle
47 38d33393 Michael Walle
    dev = qdev_create(NULL, "milkymist-vgafb");
48 38d33393 Michael Walle
    qdev_prop_set_uint32(dev, "fb_offset", fb_offset);
49 38d33393 Michael Walle
    qdev_prop_set_uint32(dev, "fb_mask", fb_mask);
50 38d33393 Michael Walle
    qdev_init_nofail(dev);
51 38d33393 Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
52 38d33393 Michael Walle
53 38d33393 Michael Walle
    return dev;
54 38d33393 Michael Walle
}
55 38d33393 Michael Walle
56 38d33393 Michael Walle
static inline DeviceState *milkymist_sysctl_create(target_phys_addr_t base,
57 38d33393 Michael Walle
        qemu_irq gpio_irq, qemu_irq timer0_irq, qemu_irq timer1_irq,
58 38d33393 Michael Walle
        uint32_t freq_hz, uint32_t system_id, uint32_t capabilities,
59 38d33393 Michael Walle
        uint32_t gpio_strappings)
60 38d33393 Michael Walle
{
61 38d33393 Michael Walle
    DeviceState *dev;
62 38d33393 Michael Walle
63 38d33393 Michael Walle
    dev = qdev_create(NULL, "milkymist-sysctl");
64 38d33393 Michael Walle
    qdev_prop_set_uint32(dev, "frequency", freq_hz);
65 38d33393 Michael Walle
    qdev_prop_set_uint32(dev, "systemid", system_id);
66 38d33393 Michael Walle
    qdev_prop_set_uint32(dev, "capabilities", capabilities);
67 38d33393 Michael Walle
    qdev_prop_set_uint32(dev, "gpio_strappings", gpio_strappings);
68 38d33393 Michael Walle
    qdev_init_nofail(dev);
69 38d33393 Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
70 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 0, gpio_irq);
71 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 1, timer0_irq);
72 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 2, timer1_irq);
73 38d33393 Michael Walle
74 38d33393 Michael Walle
    return dev;
75 38d33393 Michael Walle
}
76 38d33393 Michael Walle
77 38d33393 Michael Walle
static inline DeviceState *milkymist_pfpu_create(target_phys_addr_t base,
78 38d33393 Michael Walle
        qemu_irq irq)
79 38d33393 Michael Walle
{
80 38d33393 Michael Walle
    DeviceState *dev;
81 38d33393 Michael Walle
82 38d33393 Michael Walle
    dev = qdev_create(NULL, "milkymist-pfpu");
83 38d33393 Michael Walle
    qdev_init_nofail(dev);
84 38d33393 Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
85 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 0, irq);
86 38d33393 Michael Walle
    return dev;
87 38d33393 Michael Walle
}
88 38d33393 Michael Walle
89 38d33393 Michael Walle
#ifdef CONFIG_OPENGL
90 38d33393 Michael Walle
#include <X11/Xlib.h>
91 38d33393 Michael Walle
#include <GL/glx.h>
92 38d33393 Michael Walle
static const int glx_fbconfig_attr[] = {
93 38d33393 Michael Walle
    GLX_GREEN_SIZE, 5,
94 38d33393 Michael Walle
    GLX_GREEN_SIZE, 6,
95 38d33393 Michael Walle
    GLX_BLUE_SIZE, 5,
96 38d33393 Michael Walle
    None
97 38d33393 Michael Walle
};
98 38d33393 Michael Walle
#endif
99 38d33393 Michael Walle
100 38d33393 Michael Walle
static inline DeviceState *milkymist_tmu2_create(target_phys_addr_t base,
101 38d33393 Michael Walle
        qemu_irq irq)
102 38d33393 Michael Walle
{
103 38d33393 Michael Walle
#ifdef CONFIG_OPENGL
104 38d33393 Michael Walle
    DeviceState *dev;
105 38d33393 Michael Walle
    Display *d;
106 38d33393 Michael Walle
    GLXFBConfig *configs;
107 38d33393 Michael Walle
    int nelements;
108 38d33393 Michael Walle
    int ver_major, ver_minor;
109 38d33393 Michael Walle
110 38d33393 Michael Walle
    if (display_type == DT_NOGRAPHIC) {
111 38d33393 Michael Walle
        return NULL;
112 38d33393 Michael Walle
    }
113 38d33393 Michael Walle
114 38d33393 Michael Walle
    /* check that GLX will work */
115 38d33393 Michael Walle
    d = XOpenDisplay(NULL);
116 38d33393 Michael Walle
    if (d == NULL) {
117 38d33393 Michael Walle
        return NULL;
118 38d33393 Michael Walle
    }
119 38d33393 Michael Walle
120 38d33393 Michael Walle
    if (!glXQueryVersion(d, &ver_major, &ver_minor)) {
121 38d33393 Michael Walle
        /* Yeah, sometimes getting the GLX version can fail.
122 38d33393 Michael Walle
         * Isn't X beautiful? */
123 38d33393 Michael Walle
        XCloseDisplay(d);
124 38d33393 Michael Walle
        return NULL;
125 38d33393 Michael Walle
    }
126 38d33393 Michael Walle
127 38d33393 Michael Walle
    if ((ver_major < 1) || ((ver_major == 1) && (ver_minor < 3))) {
128 38d33393 Michael Walle
        printf("Your GLX version is %d.%d,"
129 38d33393 Michael Walle
          "but TMU emulation needs at least 1.3. TMU disabled.\n",
130 38d33393 Michael Walle
          ver_major, ver_minor);
131 38d33393 Michael Walle
        XCloseDisplay(d);
132 38d33393 Michael Walle
        return NULL;
133 38d33393 Michael Walle
    }
134 38d33393 Michael Walle
135 38d33393 Michael Walle
    configs = glXChooseFBConfig(d, 0, glx_fbconfig_attr, &nelements);
136 38d33393 Michael Walle
    if (configs == NULL) {
137 38d33393 Michael Walle
        XCloseDisplay(d);
138 38d33393 Michael Walle
        return NULL;
139 38d33393 Michael Walle
    }
140 38d33393 Michael Walle
141 38d33393 Michael Walle
    XFree(configs);
142 38d33393 Michael Walle
    XCloseDisplay(d);
143 38d33393 Michael Walle
144 38d33393 Michael Walle
    dev = qdev_create(NULL, "milkymist-tmu2");
145 38d33393 Michael Walle
    qdev_init_nofail(dev);
146 38d33393 Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
147 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 0, irq);
148 38d33393 Michael Walle
149 38d33393 Michael Walle
    return dev;
150 38d33393 Michael Walle
#else
151 38d33393 Michael Walle
    return NULL;
152 38d33393 Michael Walle
#endif
153 38d33393 Michael Walle
}
154 38d33393 Michael Walle
155 38d33393 Michael Walle
static inline DeviceState *milkymist_ac97_create(target_phys_addr_t base,
156 38d33393 Michael Walle
        qemu_irq crrequest_irq, qemu_irq crreply_irq, qemu_irq dmar_irq,
157 38d33393 Michael Walle
        qemu_irq dmaw_irq)
158 38d33393 Michael Walle
{
159 38d33393 Michael Walle
    DeviceState *dev;
160 38d33393 Michael Walle
161 38d33393 Michael Walle
    dev = qdev_create(NULL, "milkymist-ac97");
162 38d33393 Michael Walle
    qdev_init_nofail(dev);
163 38d33393 Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
164 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 0, crrequest_irq);
165 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 1, crreply_irq);
166 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 2, dmar_irq);
167 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 3, dmaw_irq);
168 38d33393 Michael Walle
169 38d33393 Michael Walle
    return dev;
170 38d33393 Michael Walle
}
171 38d33393 Michael Walle
172 38d33393 Michael Walle
static inline DeviceState *milkymist_minimac_create(target_phys_addr_t base,
173 38d33393 Michael Walle
        qemu_irq rx_irq, qemu_irq tx_irq)
174 38d33393 Michael Walle
{
175 38d33393 Michael Walle
    DeviceState *dev;
176 38d33393 Michael Walle
177 38d33393 Michael Walle
    qemu_check_nic_model(&nd_table[0], "minimac");
178 38d33393 Michael Walle
    dev = qdev_create(NULL, "milkymist-minimac");
179 38d33393 Michael Walle
    qdev_set_nic_properties(dev, &nd_table[0]);
180 38d33393 Michael Walle
    qdev_init_nofail(dev);
181 38d33393 Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
182 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 0, rx_irq);
183 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 1, tx_irq);
184 38d33393 Michael Walle
185 38d33393 Michael Walle
    return dev;
186 38d33393 Michael Walle
}
187 38d33393 Michael Walle
188 57aa265d Michael Walle
static inline DeviceState *milkymist_minimac2_create(target_phys_addr_t base,
189 57aa265d Michael Walle
        target_phys_addr_t buffers_base, qemu_irq rx_irq, qemu_irq tx_irq)
190 57aa265d Michael Walle
{
191 57aa265d Michael Walle
    DeviceState *dev;
192 57aa265d Michael Walle
193 57aa265d Michael Walle
    qemu_check_nic_model(&nd_table[0], "minimac2");
194 57aa265d Michael Walle
    dev = qdev_create(NULL, "milkymist-minimac2");
195 57aa265d Michael Walle
    qdev_prop_set_taddr(dev, "buffers_base", buffers_base);
196 57aa265d Michael Walle
    qdev_set_nic_properties(dev, &nd_table[0]);
197 57aa265d Michael Walle
    qdev_init_nofail(dev);
198 57aa265d Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
199 57aa265d Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 0, rx_irq);
200 57aa265d Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 1, tx_irq);
201 57aa265d Michael Walle
202 57aa265d Michael Walle
    return dev;
203 57aa265d Michael Walle
}
204 57aa265d Michael Walle
205 38d33393 Michael Walle
static inline DeviceState *milkymist_softusb_create(target_phys_addr_t base,
206 38d33393 Michael Walle
        qemu_irq irq, uint32_t pmem_base, uint32_t pmem_size,
207 38d33393 Michael Walle
        uint32_t dmem_base, uint32_t dmem_size)
208 38d33393 Michael Walle
{
209 38d33393 Michael Walle
    DeviceState *dev;
210 38d33393 Michael Walle
211 38d33393 Michael Walle
    dev = qdev_create(NULL, "milkymist-softusb");
212 38d33393 Michael Walle
    qdev_prop_set_uint32(dev, "pmem_base", pmem_base);
213 38d33393 Michael Walle
    qdev_prop_set_uint32(dev, "pmem_size", pmem_size);
214 38d33393 Michael Walle
    qdev_prop_set_uint32(dev, "dmem_base", dmem_base);
215 38d33393 Michael Walle
    qdev_prop_set_uint32(dev, "dmem_size", dmem_size);
216 38d33393 Michael Walle
    qdev_init_nofail(dev);
217 38d33393 Michael Walle
    sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
218 38d33393 Michael Walle
    sysbus_connect_irq(sysbus_from_qdev(dev), 0, irq);
219 38d33393 Michael Walle
220 38d33393 Michael Walle
    return dev;
221 38d33393 Michael Walle
}
222 38d33393 Michael Walle
223 38d33393 Michael Walle
#endif /* QEMU_HW_MILKYMIST_H */