2008-03-29 01:32:27 +03:00
|
|
|
/*
|
|
|
|
* QEMU G364 framebuffer Emulator.
|
|
|
|
*
|
2011-08-26 23:20:12 +04:00
|
|
|
* Copyright (c) 2007-2011 Herve Poussineau
|
2008-03-29 01:32:27 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2009-01-05 01:05:52 +03:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2009-07-17 00:47:01 +04:00
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
2008-03-29 01:32:27 +03:00
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:13 +03:00
|
|
|
#include "qemu/osdep.h"
|
2018-06-25 15:42:06 +03:00
|
|
|
#include "qemu/units.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/hw.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2015-03-17 20:29:20 +03:00
|
|
|
#include "qemu/error-report.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2012-11-28 15:06:30 +04:00
|
|
|
#include "ui/console.h"
|
|
|
|
#include "ui/pixel_ops.h"
|
2011-08-26 23:20:11 +04:00
|
|
|
#include "trace.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2009-01-17 00:13:58 +03:00
|
|
|
|
2008-03-29 01:32:27 +03:00
|
|
|
typedef struct G364State {
|
2009-01-17 00:13:58 +03:00
|
|
|
/* hardware */
|
|
|
|
uint8_t *vram;
|
2011-08-26 23:20:12 +04:00
|
|
|
uint32_t vram_size;
|
2009-01-17 00:13:58 +03:00
|
|
|
qemu_irq irq;
|
2011-08-26 23:20:12 +04:00
|
|
|
MemoryRegion mem_vram;
|
|
|
|
MemoryRegion mem_ctrl;
|
2009-01-17 00:13:58 +03:00
|
|
|
/* registers */
|
|
|
|
uint8_t color_palette[256][3];
|
|
|
|
uint8_t cursor_palette[3][3];
|
|
|
|
uint16_t cursor[512];
|
|
|
|
uint32_t cursor_position;
|
2008-03-29 01:32:27 +03:00
|
|
|
uint32_t ctla;
|
2009-01-17 00:13:58 +03:00
|
|
|
uint32_t top_of_screen;
|
|
|
|
uint32_t width, height; /* in pixels */
|
2008-03-29 01:32:27 +03:00
|
|
|
/* display refresh support */
|
2013-03-05 18:24:14 +04:00
|
|
|
QemuConsole *con;
|
2009-01-17 00:13:58 +03:00
|
|
|
int depth;
|
|
|
|
int blanked;
|
2008-03-29 01:32:27 +03:00
|
|
|
} G364State;
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
#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
|
2009-01-17 00:13:58 +03:00
|
|
|
|
|
|
|
#define CTLA_FORCE_BLANK 0x00000400
|
|
|
|
#define CTLA_NO_CURSOR 0x00800000
|
|
|
|
|
2011-09-05 00:51:28 +04:00
|
|
|
#define G364_PAGE_SIZE 4096
|
|
|
|
|
2018-02-06 20:28:10 +03:00
|
|
|
static inline int check_dirty(G364State *s, DirtyBitmapSnapshot *snap, ram_addr_t page)
|
2009-01-17 00:13:58 +03:00
|
|
|
{
|
2018-02-06 20:28:10 +03:00
|
|
|
return memory_region_snapshot_get_dirty(&s->mem_vram, snap, page, G364_PAGE_SIZE);
|
2009-01-17 00:13:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void g364fb_draw_graphic8(G364State *s)
|
2008-03-29 01:32:27 +03:00
|
|
|
{
|
2013-03-05 18:24:14 +04:00
|
|
|
DisplaySurface *surface = qemu_console_surface(s->con);
|
2018-02-06 20:28:10 +03:00
|
|
|
DirtyBitmapSnapshot *snap;
|
2009-01-17 00:13:58 +03:00
|
|
|
int i, w;
|
|
|
|
uint8_t *vram;
|
|
|
|
uint8_t *data_display, *dd;
|
2017-04-21 12:16:30 +03:00
|
|
|
ram_addr_t page;
|
2009-01-17 00:13:58 +03:00
|
|
|
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);
|
|
|
|
|
2013-03-05 18:24:14 +04:00
|
|
|
switch (surface_bits_per_pixel(surface)) {
|
2008-03-29 01:32:27 +03:00
|
|
|
case 8:
|
2009-01-17 00:13:58 +03:00
|
|
|
rgb_to_pixel = rgb_to_pixel8;
|
|
|
|
w = 1;
|
2008-03-29 01:32:27 +03:00
|
|
|
break;
|
|
|
|
case 15:
|
2009-01-17 00:13:58 +03:00
|
|
|
rgb_to_pixel = rgb_to_pixel15;
|
|
|
|
w = 2;
|
2008-03-29 01:32:27 +03:00
|
|
|
break;
|
|
|
|
case 16:
|
2009-01-17 00:13:58 +03:00
|
|
|
rgb_to_pixel = rgb_to_pixel16;
|
|
|
|
w = 2;
|
2008-03-29 01:32:27 +03:00
|
|
|
break;
|
|
|
|
case 32:
|
2009-01-17 00:13:58 +03:00
|
|
|
rgb_to_pixel = rgb_to_pixel32;
|
|
|
|
w = 4;
|
2008-03-29 01:32:27 +03:00
|
|
|
break;
|
|
|
|
default:
|
2011-08-26 23:20:11 +04:00
|
|
|
hw_error("g364: unknown host depth %d",
|
2013-03-05 18:24:14 +04:00
|
|
|
surface_bits_per_pixel(surface));
|
2008-03-29 01:32:27 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
page = 0;
|
2009-01-17 00:13:58 +03:00
|
|
|
|
|
|
|
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? */
|
2013-03-05 18:24:14 +04:00
|
|
|
data_display = dd = surface_data(surface);
|
2018-02-06 20:28:10 +03:00
|
|
|
snap = memory_region_snapshot_and_clear_dirty(&s->mem_vram, 0, s->vram_size,
|
|
|
|
DIRTY_MEMORY_VGA);
|
2009-01-17 00:13:58 +03:00
|
|
|
while (y < s->height) {
|
2018-02-06 20:28:10 +03:00
|
|
|
if (check_dirty(s, snap, page)) {
|
2009-01-17 00:13:58 +03:00
|
|
|
if (y < ymin)
|
|
|
|
ymin = ymax = y;
|
|
|
|
if (x < xmin)
|
|
|
|
xmin = x;
|
2011-09-05 00:51:28 +04:00
|
|
|
for (i = 0; i < G364_PAGE_SIZE; i++) {
|
2009-01-17 00:13:58 +03:00
|
|
|
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;
|
|
|
|
}
|
2013-03-05 18:24:14 +04:00
|
|
|
data_display = dd = data_display + surface_stride(surface);
|
2009-01-17 00:13:58 +03:00
|
|
|
xmin = 0;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (x > xmax)
|
|
|
|
xmax = x;
|
|
|
|
if (y > ymax)
|
|
|
|
ymax = y;
|
|
|
|
} else {
|
|
|
|
int dy;
|
2017-04-21 12:16:30 +03:00
|
|
|
if (xmax || ymax) {
|
2013-03-05 18:24:14 +04:00
|
|
|
dpy_gfx_update(s->con, xmin, ymin,
|
2012-09-28 17:02:08 +04:00
|
|
|
xmax - xmin + 1, ymax - ymin + 1);
|
2009-01-17 00:13:58 +03:00
|
|
|
xmin = s->width;
|
|
|
|
xmax = 0;
|
|
|
|
ymin = s->height;
|
|
|
|
ymax = 0;
|
|
|
|
}
|
2011-09-05 00:51:28 +04:00
|
|
|
x += G364_PAGE_SIZE;
|
2009-01-17 00:13:58 +03:00
|
|
|
dy = x / s->width;
|
|
|
|
x = x % s->width;
|
|
|
|
y += dy;
|
2011-09-05 00:51:28 +04:00
|
|
|
vram += G364_PAGE_SIZE;
|
2013-03-05 18:24:14 +04:00
|
|
|
data_display += dy * surface_stride(surface);
|
2009-01-17 00:13:58 +03:00
|
|
|
dd = data_display + x * w;
|
|
|
|
}
|
2011-09-05 00:51:28 +04:00
|
|
|
page += G364_PAGE_SIZE;
|
2009-01-17 00:13:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2017-04-21 12:16:30 +03:00
|
|
|
if (xmax || ymax) {
|
2013-03-05 18:24:14 +04:00
|
|
|
dpy_gfx_update(s->con, xmin, ymin, xmax - xmin + 1, ymax - ymin + 1);
|
2009-01-17 00:13:58 +03:00
|
|
|
}
|
2018-02-14 19:36:33 +03:00
|
|
|
g_free(snap);
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
|
|
|
|
2009-01-17 00:13:58 +03:00
|
|
|
static void g364fb_draw_blank(G364State *s)
|
2008-03-29 01:32:27 +03:00
|
|
|
{
|
2013-03-05 18:24:14 +04:00
|
|
|
DisplaySurface *surface = qemu_console_surface(s->con);
|
2008-03-29 01:32:27 +03:00
|
|
|
int i, w;
|
|
|
|
uint8_t *d;
|
|
|
|
|
2009-01-17 00:13:58 +03:00
|
|
|
if (s->blanked) {
|
|
|
|
/* Screen is already blank. No need to redraw it */
|
2008-03-29 01:32:27 +03:00
|
|
|
return;
|
2009-01-17 00:13:58 +03:00
|
|
|
}
|
2008-03-29 01:32:27 +03:00
|
|
|
|
2013-03-05 18:24:14 +04:00
|
|
|
w = s->width * surface_bytes_per_pixel(surface);
|
|
|
|
d = surface_data(surface);
|
2009-01-17 00:13:58 +03:00
|
|
|
for (i = 0; i < s->height; i++) {
|
2008-03-29 01:32:27 +03:00
|
|
|
memset(d, 0, w);
|
2013-03-05 18:24:14 +04:00
|
|
|
d += surface_stride(surface);
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
2008-08-17 05:44:53 +04:00
|
|
|
|
2018-08-10 16:28:56 +03:00
|
|
|
dpy_gfx_update_full(s->con);
|
2009-01-17 00:13:58 +03:00
|
|
|
s->blanked = 1;
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void g364fb_update_display(void *opaque)
|
|
|
|
{
|
|
|
|
G364State *s = opaque;
|
2013-03-05 18:24:14 +04:00
|
|
|
DisplaySurface *surface = qemu_console_surface(s->con);
|
2008-03-29 01:32:27 +03:00
|
|
|
|
2011-09-30 14:31:14 +04:00
|
|
|
qemu_flush_coalesced_mmio_buffer();
|
|
|
|
|
2009-01-17 00:13:58 +03:00
|
|
|
if (s->width == 0 || s->height == 0)
|
2008-08-17 05:44:53 +04:00
|
|
|
return;
|
|
|
|
|
2013-03-05 18:24:14 +04:00
|
|
|
if (s->width != surface_width(surface) ||
|
|
|
|
s->height != surface_height(surface)) {
|
|
|
|
qemu_console_resize(s->con, s->width, s->height);
|
2008-08-17 05:44:53 +04:00
|
|
|
}
|
2009-01-17 00:13:58 +03:00
|
|
|
|
|
|
|
if (s->ctla & CTLA_FORCE_BLANK) {
|
|
|
|
g364fb_draw_blank(s);
|
|
|
|
} else if (s->depth == 8) {
|
|
|
|
g364fb_draw_graphic8(s);
|
|
|
|
} else {
|
2011-08-26 23:20:11 +04:00
|
|
|
error_report("g364: unknown guest depth %d", s->depth);
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
2009-01-17 00:13:58 +03:00
|
|
|
|
|
|
|
qemu_irq_raise(s->irq);
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
|
|
|
|
2009-09-23 03:19:00 +04:00
|
|
|
static inline void g364fb_invalidate_display(void *opaque)
|
2008-03-29 01:32:27 +03:00
|
|
|
{
|
|
|
|
G364State *s = opaque;
|
2009-01-17 00:13:58 +03:00
|
|
|
|
|
|
|
s->blanked = 0;
|
2011-10-16 20:04:59 +04:00
|
|
|
memory_region_set_dirty(&s->mem_vram, 0, s->vram_size);
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
static void g364fb_reset(G364State *s)
|
2008-03-29 01:32:27 +03:00
|
|
|
{
|
2009-01-17 00:13:58 +03:00
|
|
|
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);
|
2011-08-26 23:20:12 +04:00
|
|
|
g364fb_invalidate_display(s);
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called for accesses to io ports */
|
2011-08-26 23:20:12 +04:00
|
|
|
static uint64_t g364fb_ctrl_read(void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr,
|
2011-08-26 23:20:12 +04:00
|
|
|
unsigned int size)
|
2008-03-29 01:32:27 +03:00
|
|
|
{
|
2009-01-17 00:13:58 +03:00
|
|
|
G364State *s = opaque;
|
2008-03-29 01:32:27 +03:00
|
|
|
uint32_t val;
|
|
|
|
|
2009-01-17 00:13:58 +03:00
|
|
|
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:
|
|
|
|
{
|
2011-08-26 23:20:11 +04:00
|
|
|
error_report("g364: invalid read at [" TARGET_FMT_plx "]",
|
|
|
|
addr);
|
2009-01-17 00:13:58 +03:00
|
|
|
val = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
|
|
|
|
2011-08-26 23:20:11 +04:00
|
|
|
trace_g364fb_read(addr, val);
|
2008-03-29 01:32:27 +03:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2009-01-17 00:13:58 +03:00
|
|
|
static void g364fb_update_depth(G364State *s)
|
2008-03-29 01:32:27 +03:00
|
|
|
{
|
2009-09-23 03:19:02 +04:00
|
|
|
static const int depths[8] = { 1, 2, 4, 8, 15, 16, 0 };
|
2009-01-17 00:13:58 +03:00
|
|
|
s->depth = depths[(s->ctla & 0x00700000) >> 20];
|
|
|
|
}
|
2008-03-29 01:32:27 +03:00
|
|
|
|
2009-01-17 00:13:58 +03:00
|
|
|
static void g364_invalidate_cursor_position(G364State *s)
|
|
|
|
{
|
2013-03-05 18:24:14 +04:00
|
|
|
DisplaySurface *surface = qemu_console_surface(s->con);
|
2011-10-16 20:04:59 +04:00
|
|
|
int ymin, ymax, start, end;
|
2008-03-29 01:32:27 +03:00
|
|
|
|
2009-01-17 00:13:58 +03:00
|
|
|
/* invalidate only near the cursor */
|
|
|
|
ymin = s->cursor_position & 0xfff;
|
|
|
|
ymax = MIN(s->height, ymin + 64);
|
2013-03-05 18:24:14 +04:00
|
|
|
start = ymin * surface_stride(surface);
|
|
|
|
end = (ymax + 1) * surface_stride(surface);
|
2008-03-29 01:32:27 +03:00
|
|
|
|
2011-10-16 20:04:59 +04:00
|
|
|
memory_region_set_dirty(&s->mem_vram, start, end - start);
|
2009-01-17 00:13:58 +03:00
|
|
|
}
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
static void g364fb_ctrl_write(void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr,
|
2011-08-26 23:20:12 +04:00
|
|
|
uint64_t val,
|
|
|
|
unsigned int size)
|
2009-01-17 00:13:58 +03:00
|
|
|
{
|
|
|
|
G364State *s = opaque;
|
|
|
|
|
2011-08-26 23:20:11 +04:00
|
|
|
trace_g364fb_write(addr, val);
|
2009-01-17 00:13:58 +03:00
|
|
|
|
|
|
|
if (addr >= REG_CLR_PAL && addr < REG_CLR_PAL + 0x800) {
|
2008-03-29 01:32:27 +03:00
|
|
|
/* color palette */
|
2009-01-17 00:13:58 +03:00
|
|
|
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);
|
2008-03-29 01:32:27 +03:00
|
|
|
} else {
|
|
|
|
switch (addr) {
|
2011-08-26 23:20:12 +04:00
|
|
|
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;
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
|
|
|
}
|
2009-01-17 00:13:58 +03:00
|
|
|
qemu_irq_lower(s->irq);
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
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,
|
2008-03-29 01:32:27 +03:00
|
|
|
};
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
static int g364fb_post_load(void *opaque, int version_id)
|
2008-03-29 01:32:27 +03:00
|
|
|
{
|
|
|
|
G364State *s = opaque;
|
2009-01-17 00:13:58 +03:00
|
|
|
|
|
|
|
/* force refresh */
|
|
|
|
g364fb_update_depth(s);
|
|
|
|
g364fb_invalidate_display(s);
|
2008-03-29 01:32:27 +03:00
|
|
|
|
2009-01-17 00:13:58 +03:00
|
|
|
return 0;
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
static const VMStateDescription vmstate_g364fb = {
|
|
|
|
.name = "g364fb",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.post_load = g364fb_post_load,
|
|
|
|
.fields = (VMStateField[]) {
|
2017-02-03 20:52:17 +03:00
|
|
|
VMSTATE_VBUFFER_UINT32(vram, G364State, 1, NULL, vram_size),
|
2011-08-26 23:20:12 +04:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
};
|
2008-03-29 01:32:27 +03:00
|
|
|
|
2013-03-13 17:04:18 +04:00
|
|
|
static const GraphicHwOps g364fb_ops = {
|
|
|
|
.invalidate = g364fb_invalidate_display,
|
|
|
|
.gfx_update = g364fb_update_display,
|
|
|
|
};
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
static void g364fb_init(DeviceState *dev, G364State *s)
|
2008-03-29 01:32:27 +03:00
|
|
|
{
|
2011-08-26 23:20:12 +04:00
|
|
|
s->vram = g_malloc0(s->vram_size);
|
2008-03-29 01:32:27 +03:00
|
|
|
|
2014-01-24 18:35:21 +04:00
|
|
|
s->con = graphic_console_init(dev, 0, &g364fb_ops, s);
|
2008-03-29 01:32:27 +03:00
|
|
|
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_io(&s->mem_ctrl, NULL, &g364fb_ctrl_ops, s, "ctrl", 0x180000);
|
|
|
|
memory_region_init_ram_ptr(&s->mem_vram, NULL, "vram",
|
2011-08-26 23:20:12 +04:00
|
|
|
s->vram_size, s->vram);
|
2011-12-20 17:59:12 +04:00
|
|
|
vmstate_register_ram(&s->mem_vram, dev);
|
2015-03-23 12:47:45 +03:00
|
|
|
memory_region_set_log(&s->mem_vram, true, DIRTY_MEMORY_VGA);
|
2011-08-26 23:20:12 +04:00
|
|
|
}
|
|
|
|
|
2013-07-25 02:30:30 +04:00
|
|
|
#define TYPE_G364 "sysbus-g364"
|
|
|
|
#define G364(obj) OBJECT_CHECK(G364SysBusState, (obj), TYPE_G364)
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
typedef struct {
|
2013-07-25 02:30:30 +04:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
G364State g364;
|
|
|
|
} G364SysBusState;
|
2008-03-29 01:32:27 +03:00
|
|
|
|
2018-12-13 16:47:57 +03:00
|
|
|
static void g364fb_sysbus_realize(DeviceState *dev, Error **errp)
|
2011-08-26 23:20:12 +04:00
|
|
|
{
|
2013-07-25 02:30:30 +04:00
|
|
|
G364SysBusState *sbs = G364(dev);
|
|
|
|
G364State *s = &sbs->g364;
|
2018-12-13 16:47:57 +03:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
2011-08-26 23:20:12 +04:00
|
|
|
|
2013-07-25 02:30:30 +04:00
|
|
|
g364fb_init(dev, s);
|
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
|
|
|
sysbus_init_mmio(sbd, &s->mem_ctrl);
|
|
|
|
sysbus_init_mmio(sbd, &s->mem_vram);
|
2008-03-29 01:32:27 +03:00
|
|
|
}
|
2011-08-26 23:20:12 +04:00
|
|
|
|
|
|
|
static void g364fb_sysbus_reset(DeviceState *d)
|
|
|
|
{
|
2013-07-25 02:30:30 +04:00
|
|
|
G364SysBusState *s = G364(d);
|
|
|
|
|
2011-08-26 23:20:12 +04:00
|
|
|
g364fb_reset(&s->g364);
|
|
|
|
}
|
|
|
|
|
2012-01-24 23:12:29 +04:00
|
|
|
static Property g364fb_sysbus_properties[] = {
|
2018-06-25 15:42:06 +03:00
|
|
|
DEFINE_PROP_UINT32("vram_size", G364SysBusState, g364.vram_size, 8 * MiB),
|
2012-01-24 23:12:29 +04:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void g364fb_sysbus_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 23:12:29 +04:00
|
|
|
|
2018-12-13 16:47:57 +03:00
|
|
|
dc->realize = g364fb_sysbus_realize;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->desc = "G364 framebuffer";
|
|
|
|
dc->reset = g364fb_sysbus_reset;
|
|
|
|
dc->vmsd = &vmstate_g364fb;
|
|
|
|
dc->props = g364fb_sysbus_properties;
|
2012-01-24 23:12:29 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo g364fb_sysbus_info = {
|
2013-07-25 02:30:30 +04:00
|
|
|
.name = TYPE_G364,
|
2011-12-08 07:34:16 +04:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(G364SysBusState),
|
|
|
|
.class_init = g364fb_sysbus_class_init,
|
2011-08-26 23:20:12 +04:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void g364fb_register_types(void)
|
2011-08-26 23:20:12 +04:00
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
type_register_static(&g364fb_sysbus_info);
|
2011-08-26 23:20:12 +04:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(g364fb_register_types)
|