g364fb.c 18.1 KB
Newer Older
A
aurel32 已提交
1 2 3
/*
 * QEMU G364 framebuffer Emulator.
 *
H
Hervé Poussineau 已提交
4
 * Copyright (c) 2007-2011 Herve Poussineau
A
aurel32 已提交
5 6 7 8 9 10 11 12 13 14 15
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
16
 * You should have received a copy of the GNU General Public License along
17
 * with this program; if not, see <http://www.gnu.org/licenses/>.
A
aurel32 已提交
18 19
 */

20
#include "hw/hw.h"
21 22
#include "ui/console.h"
#include "ui/pixel_ops.h"
H
Hervé Poussineau 已提交
23
#include "trace.h"
24
#include "hw/sysbus.h"
A
aurel32 已提交
25

A
aurel32 已提交
26
typedef struct G364State {
A
aurel32 已提交
27 28
    /* hardware */
    uint8_t *vram;
H
Hervé Poussineau 已提交
29
    uint32_t vram_size;
A
aurel32 已提交
30
    qemu_irq irq;
H
Hervé Poussineau 已提交
31 32
    MemoryRegion mem_vram;
    MemoryRegion mem_ctrl;
A
aurel32 已提交
33 34 35 36 37
    /* registers */
    uint8_t color_palette[256][3];
    uint8_t cursor_palette[3][3];
    uint16_t cursor[512];
    uint32_t cursor_position;
A
aurel32 已提交
38
    uint32_t ctla;
A
aurel32 已提交
39 40
    uint32_t top_of_screen;
    uint32_t width, height; /* in pixels */
A
aurel32 已提交
41
    /* display refresh support */
42
    QemuConsole *con;
A
aurel32 已提交
43 44
    int depth;
    int blanked;
A
aurel32 已提交
45 46
} G364State;

H
Hervé Poussineau 已提交
47 48 49 50 51 52 53 54 55 56
#define REG_BOOT     0x000000
#define REG_DISPLAY  0x000118
#define REG_VDISPLAY 0x000150
#define REG_CTLA     0x000300
#define REG_TOP      0x000400
#define REG_CURS_PAL 0x000508
#define REG_CURS_POS 0x000638
#define REG_CLR_PAL  0x000800
#define REG_CURS_PAT 0x001000
#define REG_RESET    0x100000
A
aurel32 已提交
57 58 59 60

#define CTLA_FORCE_BLANK 0x00000400
#define CTLA_NO_CURSOR   0x00800000

B
Blue Swirl 已提交
61 62
#define G364_PAGE_SIZE 4096

H
Hervé Poussineau 已提交
63
static inline int check_dirty(G364State *s, ram_addr_t page)
A
aurel32 已提交
64
{
65 66
    return memory_region_get_dirty(&s->mem_vram, page, G364_PAGE_SIZE,
                                   DIRTY_MEMORY_VGA);
A
aurel32 已提交
67 68 69
}

static inline void reset_dirty(G364State *s,
A
Anthony Liguori 已提交
70
                               ram_addr_t page_min, ram_addr_t page_max)
A
aurel32 已提交
71
{
H
Hervé Poussineau 已提交
72 73
    memory_region_reset_dirty(&s->mem_vram,
                              page_min,
B
Blue Swirl 已提交
74
                              page_max + G364_PAGE_SIZE - page_min - 1,
H
Hervé Poussineau 已提交
75
                              DIRTY_MEMORY_VGA);
A
aurel32 已提交
76 77 78
}

static void g364fb_draw_graphic8(G364State *s)
A
aurel32 已提交
79
{
80
    DisplaySurface *surface = qemu_console_surface(s->con);
A
aurel32 已提交
81 82 83
    int i, w;
    uint8_t *vram;
    uint8_t *data_display, *dd;
A
Anthony Liguori 已提交
84
    ram_addr_t page, page_min, page_max;
A
aurel32 已提交
85 86 87 88 89 90
    int x, y;
    int xmin, xmax;
    int ymin, ymax;
    int xcursor, ycursor;
    unsigned int (*rgb_to_pixel)(unsigned int r, unsigned int g, unsigned int b);

91
    switch (surface_bits_per_pixel(surface)) {
A
aurel32 已提交
92
        case 8:
A
aurel32 已提交
93 94
            rgb_to_pixel = rgb_to_pixel8;
            w = 1;
A
aurel32 已提交
95 96
            break;
        case 15:
A
aurel32 已提交
97 98
            rgb_to_pixel = rgb_to_pixel15;
            w = 2;
A
aurel32 已提交
99 100
            break;
        case 16:
A
aurel32 已提交
101 102
            rgb_to_pixel = rgb_to_pixel16;
            w = 2;
A
aurel32 已提交
103 104
            break;
        case 32:
A
aurel32 已提交
105 106
            rgb_to_pixel = rgb_to_pixel32;
            w = 4;
A
aurel32 已提交
107 108
            break;
        default:
H
Hervé Poussineau 已提交
109
            hw_error("g364: unknown host depth %d",
110
                     surface_bits_per_pixel(surface));
A
aurel32 已提交
111 112 113
            return;
    }

H
Hervé Poussineau 已提交
114
    page = 0;
A
Anthony Liguori 已提交
115
    page_min = (ram_addr_t)-1;
A
aurel32 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    page_max = 0;

    x = y = 0;
    xmin = s->width;
    xmax = 0;
    ymin = s->height;
    ymax = 0;

    if (!(s->ctla & CTLA_NO_CURSOR)) {
        xcursor = s->cursor_position >> 12;
        ycursor = s->cursor_position & 0xfff;
    } else {
        xcursor = ycursor = -65;
    }

    vram = s->vram + s->top_of_screen;
    /* XXX: out of range in vram? */
133
    data_display = dd = surface_data(surface);
A
aurel32 已提交
134
    while (y < s->height) {
H
Hervé Poussineau 已提交
135
        if (check_dirty(s, page)) {
A
aurel32 已提交
136 137
            if (y < ymin)
                ymin = ymax = y;
A
Anthony Liguori 已提交
138
            if (page_min == (ram_addr_t)-1)
A
aurel32 已提交
139 140 141 142
                page_min = page;
            page_max = page;
            if (x < xmin)
                xmin = x;
B
Blue Swirl 已提交
143
            for (i = 0; i < G364_PAGE_SIZE; i++) {
A
aurel32 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
                uint8_t index;
                unsigned int color;
                if (unlikely((y >= ycursor && y < ycursor + 64) &&
                    (x >= xcursor && x < xcursor + 64))) {
                    /* pointer area */
                    int xdiff = x - xcursor;
                    uint16_t curs = s->cursor[(y - ycursor) * 8 + xdiff / 8];
                    int op = (curs >> ((xdiff & 7) * 2)) & 3;
                    if (likely(op == 0)) {
                        /* transparent */
                        index = *vram;
                        color = (*rgb_to_pixel)(
                            s->color_palette[index][0],
                            s->color_palette[index][1],
                            s->color_palette[index][2]);
                    } else {
                        /* get cursor color */
                        index = op - 1;
                        color = (*rgb_to_pixel)(
                            s->cursor_palette[index][0],
                            s->cursor_palette[index][1],
                            s->cursor_palette[index][2]);
                    }
                } else {
                    /* normal area */
                    index = *vram;
                    color = (*rgb_to_pixel)(
                        s->color_palette[index][0],
                        s->color_palette[index][1],
                        s->color_palette[index][2]);
                }
                memcpy(dd, &color, w);
                dd += w;
                x++;
                vram++;
                if (x == s->width) {
                    xmax = s->width - 1;
                    y++;
                    if (y == s->height) {
                        ymax = s->height - 1;
                        goto done;
                    }
186
                    data_display = dd = data_display + surface_stride(surface);
A
aurel32 已提交
187 188 189 190 191 192 193 194 195 196
                    xmin = 0;
                    x = 0;
                }
            }
            if (x > xmax)
                xmax = x;
            if (y > ymax)
                ymax = y;
        } else {
            int dy;
A
Anthony Liguori 已提交
197
            if (page_min != (ram_addr_t)-1) {
A
aurel32 已提交
198
                reset_dirty(s, page_min, page_max);
A
Anthony Liguori 已提交
199
                page_min = (ram_addr_t)-1;
A
aurel32 已提交
200
                page_max = 0;
201
                dpy_gfx_update(s->con, xmin, ymin,
202
                               xmax - xmin + 1, ymax - ymin + 1);
A
aurel32 已提交
203 204 205 206 207
                xmin = s->width;
                xmax = 0;
                ymin = s->height;
                ymax = 0;
            }
B
Blue Swirl 已提交
208
            x += G364_PAGE_SIZE;
A
aurel32 已提交
209 210 211
            dy = x / s->width;
            x = x % s->width;
            y += dy;
B
Blue Swirl 已提交
212
            vram += G364_PAGE_SIZE;
213
            data_display += dy * surface_stride(surface);
A
aurel32 已提交
214 215
            dd = data_display + x * w;
        }
B
Blue Swirl 已提交
216
        page += G364_PAGE_SIZE;
A
aurel32 已提交
217 218 219
    }

done:
A
Anthony Liguori 已提交
220
    if (page_min != (ram_addr_t)-1) {
221
        dpy_gfx_update(s->con, xmin, ymin, xmax - xmin + 1, ymax - ymin + 1);
A
aurel32 已提交
222 223
        reset_dirty(s, page_min, page_max);
    }
A
aurel32 已提交
224 225
}

A
aurel32 已提交
226
static void g364fb_draw_blank(G364State *s)
A
aurel32 已提交
227
{
228
    DisplaySurface *surface = qemu_console_surface(s->con);
A
aurel32 已提交
229 230 231
    int i, w;
    uint8_t *d;

A
aurel32 已提交
232 233
    if (s->blanked) {
        /* Screen is already blank. No need to redraw it */
A
aurel32 已提交
234
        return;
A
aurel32 已提交
235
    }
A
aurel32 已提交
236

237 238
    w = s->width * surface_bytes_per_pixel(surface);
    d = surface_data(surface);
A
aurel32 已提交
239
    for (i = 0; i < s->height; i++) {
A
aurel32 已提交
240
        memset(d, 0, w);
241
        d += surface_stride(surface);
A
aurel32 已提交
242
    }
A
aurel32 已提交
243

244
    dpy_gfx_update(s->con, 0, 0, s->width, s->height);
A
aurel32 已提交
245
    s->blanked = 1;
A
aurel32 已提交
246 247 248 249 250
}

static void g364fb_update_display(void *opaque)
{
    G364State *s = opaque;
251
    DisplaySurface *surface = qemu_console_surface(s->con);
A
aurel32 已提交
252

253 254
    qemu_flush_coalesced_mmio_buffer();

A
aurel32 已提交
255
    if (s->width == 0 || s->height == 0)
A
aurel32 已提交
256 257
        return;

258 259 260
    if (s->width != surface_width(surface) ||
        s->height != surface_height(surface)) {
        qemu_console_resize(s->con, s->width, s->height);
A
aurel32 已提交
261
    }
A
aurel32 已提交
262 263 264 265 266 267

    if (s->ctla & CTLA_FORCE_BLANK) {
        g364fb_draw_blank(s);
    } else if (s->depth == 8) {
        g364fb_draw_graphic8(s);
    } else {
H
Hervé Poussineau 已提交
268
        error_report("g364: unknown guest depth %d", s->depth);
A
aurel32 已提交
269
    }
A
aurel32 已提交
270 271

    qemu_irq_raise(s->irq);
A
aurel32 已提交
272 273
}

274
static inline void g364fb_invalidate_display(void *opaque)
A
aurel32 已提交
275 276
{
    G364State *s = opaque;
A
aurel32 已提交
277 278

    s->blanked = 0;
279
    memory_region_set_dirty(&s->mem_vram, 0, s->vram_size);
A
aurel32 已提交
280 281
}

H
Hervé Poussineau 已提交
282
static void g364fb_reset(G364State *s)
A
aurel32 已提交
283
{
A
aurel32 已提交
284 285 286 287 288 289 290 291 292 293
    qemu_irq_lower(s->irq);

    memset(s->color_palette, 0, sizeof(s->color_palette));
    memset(s->cursor_palette, 0, sizeof(s->cursor_palette));
    memset(s->cursor, 0, sizeof(s->cursor));
    s->cursor_position = 0;
    s->ctla = 0;
    s->top_of_screen = 0;
    s->width = s->height = 0;
    memset(s->vram, 0, s->vram_size);
H
Hervé Poussineau 已提交
294
    g364fb_invalidate_display(s);
A
aurel32 已提交
295 296
}

297 298
static void g364fb_screen_dump(void *opaque, const char *filename, bool cswitch,
                               Error **errp)
A
aurel32 已提交
299 300
{
    G364State *s = opaque;
301
    int ret, y, x;
A
aurel32 已提交
302 303 304 305
    uint8_t index;
    uint8_t *data_buffer;
    FILE *f;

306 307
    qemu_flush_coalesced_mmio_buffer();

A
aurel32 已提交
308
    if (s->depth != 8) {
309
        error_setg(errp, "g364: unknown guest depth %d", s->depth);
A
aurel32 已提交
310 311 312
        return;
    }

A
aurel32 已提交
313
    f = fopen(filename, "wb");
314 315 316
    if (!f) {
        error_setg(errp, "failed to open file '%s': %s", filename,
                   strerror(errno));
A
aurel32 已提交
317
        return;
318
    }
A
aurel32 已提交
319

A
aurel32 已提交
320 321
    if (s->ctla & CTLA_FORCE_BLANK) {
        /* blank screen */
322 323 324 325
        ret = fprintf(f, "P4\n%d %d\n", s->width, s->height);
        if (ret < 0) {
            goto write_err;
        }
A
aurel32 已提交
326
        for (y = 0; y < s->height; y++)
327 328 329 330 331 332
            for (x = 0; x < s->width; x++) {
                ret = fputc(0, f);
                if (ret == EOF) {
                    goto write_err;
                }
            }
A
aurel32 已提交
333 334
    } else {
        data_buffer = s->vram + s->top_of_screen;
335 336 337 338
        ret = fprintf(f, "P6\n%d %d\n%d\n", s->width, s->height, 255);
        if (ret < 0) {
            goto write_err;
        }
A
aurel32 已提交
339 340 341
        for (y = 0; y < s->height; y++)
            for (x = 0; x < s->width; x++, data_buffer++) {
                index = *data_buffer;
342 343 344 345 346 347 348 349 350 351 352 353
                ret = fputc(s->color_palette[index][0], f);
                if (ret == EOF) {
                    goto write_err;
                }
                ret = fputc(s->color_palette[index][1], f);
                if (ret == EOF) {
                    goto write_err;
                }
                ret = fputc(s->color_palette[index][2], f);
                if (ret == EOF) {
                    goto write_err;
                }
A
aurel32 已提交
354
        }
A
aurel32 已提交
355 356
    }

357
out:
A
aurel32 已提交
358
    fclose(f);
359 360 361 362 363 364 365
    return;

write_err:
    error_setg(errp, "failed to write to file '%s': %s", filename,
               strerror(errno));
    unlink(filename);
    goto out;
A
aurel32 已提交
366 367 368
}

/* called for accesses to io ports */
H
Hervé Poussineau 已提交
369
static uint64_t g364fb_ctrl_read(void *opaque,
A
Avi Kivity 已提交
370
                                 hwaddr addr,
H
Hervé Poussineau 已提交
371
                                 unsigned int size)
A
aurel32 已提交
372
{
A
aurel32 已提交
373
    G364State *s = opaque;
A
aurel32 已提交
374 375
    uint32_t val;

A
aurel32 已提交
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
    if (addr >= REG_CURS_PAT && addr < REG_CURS_PAT + 0x1000) {
        /* cursor pattern */
        int idx = (addr - REG_CURS_PAT) >> 3;
        val = s->cursor[idx];
    } else if (addr >= REG_CURS_PAL && addr < REG_CURS_PAL + 0x18) {
        /* cursor palette */
        int idx = (addr - REG_CURS_PAL) >> 3;
        val = ((uint32_t)s->cursor_palette[idx][0] << 16);
        val |= ((uint32_t)s->cursor_palette[idx][1] << 8);
        val |= ((uint32_t)s->cursor_palette[idx][2] << 0);
    } else {
        switch (addr) {
            case REG_DISPLAY:
                val = s->width / 4;
                break;
            case REG_VDISPLAY:
                val = s->height * 2;
                break;
            case REG_CTLA:
                val = s->ctla;
                break;
            default:
            {
H
Hervé Poussineau 已提交
399 400
                error_report("g364: invalid read at [" TARGET_FMT_plx "]",
                             addr);
A
aurel32 已提交
401 402 403 404
                val = 0;
                break;
            }
        }
A
aurel32 已提交
405 406
    }

H
Hervé Poussineau 已提交
407
    trace_g364fb_read(addr, val);
A
aurel32 已提交
408 409 410 411

    return val;
}

A
aurel32 已提交
412
static void g364fb_update_depth(G364State *s)
A
aurel32 已提交
413
{
414
    static const int depths[8] = { 1, 2, 4, 8, 15, 16, 0 };
A
aurel32 已提交
415 416
    s->depth = depths[(s->ctla & 0x00700000) >> 20];
}
A
aurel32 已提交
417

A
aurel32 已提交
418 419
static void g364_invalidate_cursor_position(G364State *s)
{
420
    DisplaySurface *surface = qemu_console_surface(s->con);
421
    int ymin, ymax, start, end;
A
aurel32 已提交
422

A
aurel32 已提交
423 424 425
    /* invalidate only near the cursor */
    ymin = s->cursor_position & 0xfff;
    ymax = MIN(s->height, ymin + 64);
426 427
    start = ymin * surface_stride(surface);
    end = (ymax + 1) * surface_stride(surface);
A
aurel32 已提交
428

429
    memory_region_set_dirty(&s->mem_vram, start, end - start);
A
aurel32 已提交
430 431
}

H
Hervé Poussineau 已提交
432
static void g364fb_ctrl_write(void *opaque,
A
Avi Kivity 已提交
433
                              hwaddr addr,
H
Hervé Poussineau 已提交
434 435
                              uint64_t val,
                              unsigned int size)
A
aurel32 已提交
436 437 438
{
    G364State *s = opaque;

H
Hervé Poussineau 已提交
439
    trace_g364fb_write(addr, val);
A
aurel32 已提交
440 441

    if (addr >= REG_CLR_PAL && addr < REG_CLR_PAL + 0x800) {
A
aurel32 已提交
442
        /* color palette */
A
aurel32 已提交
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
        int idx = (addr - REG_CLR_PAL) >> 3;
        s->color_palette[idx][0] = (val >> 16) & 0xff;
        s->color_palette[idx][1] = (val >> 8) & 0xff;
        s->color_palette[idx][2] = val & 0xff;
        g364fb_invalidate_display(s);
    } else if (addr >= REG_CURS_PAT && addr < REG_CURS_PAT + 0x1000) {
        /* cursor pattern */
        int idx = (addr - REG_CURS_PAT) >> 3;
        s->cursor[idx] = val;
        g364fb_invalidate_display(s);
    } else if (addr >= REG_CURS_PAL && addr < REG_CURS_PAL + 0x18) {
        /* cursor palette */
        int idx = (addr - REG_CURS_PAL) >> 3;
        s->cursor_palette[idx][0] = (val >> 16) & 0xff;
        s->cursor_palette[idx][1] = (val >> 8) & 0xff;
        s->cursor_palette[idx][2] = val & 0xff;
        g364fb_invalidate_display(s);
A
aurel32 已提交
460 461
    } else {
        switch (addr) {
H
Hervé Poussineau 已提交
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
        case REG_BOOT: /* Boot timing */
        case 0x00108: /* Line timing: half sync */
        case 0x00110: /* Line timing: back porch */
        case 0x00120: /* Line timing: short display */
        case 0x00128: /* Frame timing: broad pulse */
        case 0x00130: /* Frame timing: v sync */
        case 0x00138: /* Frame timing: v preequalise */
        case 0x00140: /* Frame timing: v postequalise */
        case 0x00148: /* Frame timing: v blank */
        case 0x00158: /* Line timing: line time */
        case 0x00160: /* Frame store: line start */
        case 0x00168: /* vram cycle: mem init */
        case 0x00170: /* vram cycle: transfer delay */
        case 0x00200: /* vram cycle: mask register */
            /* ignore */
            break;
        case REG_TOP:
            s->top_of_screen = val;
            g364fb_invalidate_display(s);
            break;
        case REG_DISPLAY:
            s->width = val * 4;
            break;
        case REG_VDISPLAY:
            s->height = val / 2;
            break;
        case REG_CTLA:
            s->ctla = val;
            g364fb_update_depth(s);
            g364fb_invalidate_display(s);
            break;
        case REG_CURS_POS:
            g364_invalidate_cursor_position(s);
            s->cursor_position = val;
            g364_invalidate_cursor_position(s);
            break;
        case REG_RESET:
            g364fb_reset(s);
            break;
        default:
            error_report("g364: invalid write of 0x%" PRIx64
                         " at [" TARGET_FMT_plx "]", val, addr);
            break;
A
aurel32 已提交
505 506
        }
    }
A
aurel32 已提交
507
    qemu_irq_lower(s->irq);
A
aurel32 已提交
508 509
}

H
Hervé Poussineau 已提交
510 511 512 513 514 515
static const MemoryRegionOps g364fb_ctrl_ops = {
    .read = g364fb_ctrl_read,
    .write = g364fb_ctrl_write,
    .endianness = DEVICE_LITTLE_ENDIAN,
    .impl.min_access_size = 4,
    .impl.max_access_size = 4,
A
aurel32 已提交
516 517
};

H
Hervé Poussineau 已提交
518
static int g364fb_post_load(void *opaque, int version_id)
A
aurel32 已提交
519 520
{
    G364State *s = opaque;
A
aurel32 已提交
521 522 523 524

    /* force refresh */
    g364fb_update_depth(s);
    g364fb_invalidate_display(s);
A
aurel32 已提交
525

A
aurel32 已提交
526
    return 0;
A
aurel32 已提交
527 528
}

H
Hervé Poussineau 已提交
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
static const VMStateDescription vmstate_g364fb = {
    .name = "g364fb",
    .version_id = 1,
    .minimum_version_id = 1,
    .minimum_version_id_old = 1,
    .post_load = g364fb_post_load,
    .fields = (VMStateField[]) {
        VMSTATE_VBUFFER_UINT32(vram, G364State, 1, NULL, 0, vram_size),
        VMSTATE_BUFFER_UNSAFE(color_palette, G364State, 0, 256 * 3),
        VMSTATE_BUFFER_UNSAFE(cursor_palette, G364State, 0, 9),
        VMSTATE_UINT16_ARRAY(cursor, G364State, 512),
        VMSTATE_UINT32(cursor_position, G364State),
        VMSTATE_UINT32(ctla, G364State),
        VMSTATE_UINT32(top_of_screen, G364State),
        VMSTATE_UINT32(width, G364State),
        VMSTATE_UINT32(height, G364State),
        VMSTATE_END_OF_LIST()
    }
};
A
aurel32 已提交
548

H
Hervé Poussineau 已提交
549
static void g364fb_init(DeviceState *dev, G364State *s)
A
aurel32 已提交
550
{
H
Hervé Poussineau 已提交
551
    s->vram = g_malloc0(s->vram_size);
A
aurel32 已提交
552

553 554 555
    s->con = graphic_console_init(g364fb_update_display,
                                  g364fb_invalidate_display,
                                  g364fb_screen_dump, NULL, s);
A
aurel32 已提交
556

H
Hervé Poussineau 已提交
557
    memory_region_init_io(&s->mem_ctrl, &g364fb_ctrl_ops, s, "ctrl", 0x180000);
558
    memory_region_init_ram_ptr(&s->mem_vram, "vram",
H
Hervé Poussineau 已提交
559
                               s->vram_size, s->vram);
560
    vmstate_register_ram(&s->mem_vram, dev);
H
Hervé Poussineau 已提交
561 562 563 564 565 566 567
    memory_region_set_coalescing(&s->mem_vram);
}

typedef struct {
    SysBusDevice busdev;
    G364State g364;
} G364SysBusState;
A
aurel32 已提交
568

H
Hervé Poussineau 已提交
569 570 571 572 573 574
static int g364fb_sysbus_init(SysBusDevice *dev)
{
    G364State *s = &FROM_SYSBUS(G364SysBusState, dev)->g364;

    g364fb_init(&dev->qdev, s);
    sysbus_init_irq(dev, &s->irq);
575 576
    sysbus_init_mmio(dev, &s->mem_ctrl);
    sysbus_init_mmio(dev, &s->mem_vram);
A
aurel32 已提交
577 578 579

    return 0;
}
H
Hervé Poussineau 已提交
580 581 582 583 584 585 586

static void g364fb_sysbus_reset(DeviceState *d)
{
    G364SysBusState *s = DO_UPCAST(G364SysBusState, busdev.qdev, d);
    g364fb_reset(&s->g364);
}

587 588 589 590 591 592 593 594
static Property g364fb_sysbus_properties[] = {
    DEFINE_PROP_HEX32("vram_size", G364SysBusState, g364.vram_size,
    8 * 1024 * 1024),
    DEFINE_PROP_END_OF_LIST(),
};

static void g364fb_sysbus_class_init(ObjectClass *klass, void *data)
{
595
    DeviceClass *dc = DEVICE_CLASS(klass);
596 597 598
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);

    k->init = g364fb_sysbus_init;
599 600 601 602
    dc->desc = "G364 framebuffer";
    dc->reset = g364fb_sysbus_reset;
    dc->vmsd = &vmstate_g364fb;
    dc->props = g364fb_sysbus_properties;
603 604
}

605
static const TypeInfo g364fb_sysbus_info = {
606 607 608 609
    .name          = "sysbus-g364",
    .parent        = TYPE_SYS_BUS_DEVICE,
    .instance_size = sizeof(G364SysBusState),
    .class_init    = g364fb_sysbus_class_init,
H
Hervé Poussineau 已提交
610 611
};

A
Andreas Färber 已提交
612
static void g364fb_register_types(void)
H
Hervé Poussineau 已提交
613
{
614
    type_register_static(&g364fb_sysbus_info);
H
Hervé Poussineau 已提交
615 616
}

A
Andreas Färber 已提交
617
type_init(g364fb_register_types)