Statistics
| Branch: | Revision:

root / hw / milkymist-hw.h @ d43ed9ec

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