2007-09-17 01:08:06 +04:00
|
|
|
/*
|
2006-02-06 07:11:15 +03:00
|
|
|
* Arm PrimeCell PL110 Color LCD Controller
|
|
|
|
*
|
2009-05-15 01:35:07 +04:00
|
|
|
* Copyright (c) 2005-2009 CodeSourcery.
|
2006-02-06 07:11:15 +03:00
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
2011-06-26 06:21:35 +04:00
|
|
|
* This code is licensed under the GNU LGPL
|
2006-02-06 07:11:15 +03:00
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:05 +03:00
|
|
|
#include "qemu/osdep.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.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"
|
2012-11-28 15:06:30 +04:00
|
|
|
#include "ui/console.h"
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "framebuffer.h"
|
2012-11-28 15:06:30 +04:00
|
|
|
#include "ui/pixel_ops.h"
|
2018-01-25 14:45:30 +03:00
|
|
|
#include "qemu/timer.h"
|
2015-12-15 15:16:16 +03:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2006-02-06 07:11:15 +03:00
|
|
|
|
|
|
|
#define PL110_CR_EN 0x001
|
2007-10-05 03:45:31 +04:00
|
|
|
#define PL110_CR_BGR 0x100
|
2006-02-06 07:11:15 +03:00
|
|
|
#define PL110_CR_BEBO 0x200
|
|
|
|
#define PL110_CR_BEPO 0x400
|
|
|
|
#define PL110_CR_PWR 0x800
|
2018-01-25 14:45:30 +03:00
|
|
|
#define PL110_IE_NB 0x004
|
|
|
|
#define PL110_IE_VC 0x008
|
2006-02-06 07:11:15 +03:00
|
|
|
|
|
|
|
enum pl110_bppmode
|
|
|
|
{
|
|
|
|
BPP_1,
|
|
|
|
BPP_2,
|
|
|
|
BPP_4,
|
|
|
|
BPP_8,
|
|
|
|
BPP_16,
|
2011-07-22 17:19:33 +04:00
|
|
|
BPP_32,
|
|
|
|
BPP_16_565, /* PL111 only */
|
|
|
|
BPP_12 /* PL111 only */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* The Versatile/PB uses a slightly modified PL110 controller. */
|
|
|
|
enum pl110_version
|
|
|
|
{
|
|
|
|
PL110,
|
|
|
|
PL110_VERSATILE,
|
|
|
|
PL111
|
2006-02-06 07:11:15 +03:00
|
|
|
};
|
|
|
|
|
2013-07-25 03:09:03 +04:00
|
|
|
#define TYPE_PL110 "pl110"
|
|
|
|
#define PL110(obj) OBJECT_CHECK(PL110State, (obj), TYPE_PL110)
|
|
|
|
|
2013-07-25 02:57:23 +04:00
|
|
|
typedef struct PL110State {
|
2013-07-25 03:09:03 +04:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-10-10 19:18:44 +04:00
|
|
|
MemoryRegion iomem;
|
2015-07-13 13:00:29 +03:00
|
|
|
MemoryRegionSection fbsection;
|
2013-03-05 18:24:14 +04:00
|
|
|
QemuConsole *con;
|
2018-01-25 14:45:30 +03:00
|
|
|
QEMUTimer *vblank_timer;
|
2008-07-01 20:24:38 +04:00
|
|
|
|
2011-07-22 17:19:33 +04:00
|
|
|
int version;
|
2006-02-06 07:11:15 +03:00
|
|
|
uint32_t timing[4];
|
|
|
|
uint32_t cr;
|
|
|
|
uint32_t upbase;
|
|
|
|
uint32_t lpbase;
|
|
|
|
uint32_t int_status;
|
|
|
|
uint32_t int_mask;
|
|
|
|
int cols;
|
|
|
|
int rows;
|
|
|
|
enum pl110_bppmode bpp;
|
|
|
|
int invalidate;
|
2011-07-22 17:42:39 +04:00
|
|
|
uint32_t mux_ctrl;
|
2012-08-27 15:32:36 +04:00
|
|
|
uint32_t palette[256];
|
|
|
|
uint32_t raw_palette[128];
|
2007-04-07 22:14:41 +04:00
|
|
|
qemu_irq irq;
|
2013-07-25 02:57:23 +04:00
|
|
|
} PL110State;
|
2006-02-06 07:11:15 +03:00
|
|
|
|
2011-12-19 16:01:58 +04:00
|
|
|
static int vmstate_pl110_post_load(void *opaque, int version_id);
|
|
|
|
|
2010-12-23 20:19:56 +03:00
|
|
|
static const VMStateDescription vmstate_pl110 = {
|
|
|
|
.name = "pl110",
|
2011-07-22 17:42:39 +04:00
|
|
|
.version_id = 2,
|
2010-12-23 20:19:56 +03:00
|
|
|
.minimum_version_id = 1,
|
2011-12-19 16:01:58 +04:00
|
|
|
.post_load = vmstate_pl110_post_load,
|
2010-12-23 20:19:56 +03:00
|
|
|
.fields = (VMStateField[]) {
|
2013-07-25 02:57:23 +04:00
|
|
|
VMSTATE_INT32(version, PL110State),
|
|
|
|
VMSTATE_UINT32_ARRAY(timing, PL110State, 4),
|
|
|
|
VMSTATE_UINT32(cr, PL110State),
|
|
|
|
VMSTATE_UINT32(upbase, PL110State),
|
|
|
|
VMSTATE_UINT32(lpbase, PL110State),
|
|
|
|
VMSTATE_UINT32(int_status, PL110State),
|
|
|
|
VMSTATE_UINT32(int_mask, PL110State),
|
|
|
|
VMSTATE_INT32(cols, PL110State),
|
|
|
|
VMSTATE_INT32(rows, PL110State),
|
|
|
|
VMSTATE_UINT32(bpp, PL110State),
|
|
|
|
VMSTATE_INT32(invalidate, PL110State),
|
|
|
|
VMSTATE_UINT32_ARRAY(palette, PL110State, 256),
|
|
|
|
VMSTATE_UINT32_ARRAY(raw_palette, PL110State, 128),
|
|
|
|
VMSTATE_UINT32_V(mux_ctrl, PL110State, 2),
|
2010-12-23 20:19:56 +03:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-02-06 07:11:15 +03:00
|
|
|
static const unsigned char pl110_id[] =
|
|
|
|
{ 0x10, 0x11, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
|
|
|
|
|
2011-07-22 17:19:33 +04:00
|
|
|
static const unsigned char pl111_id[] = {
|
|
|
|
0x11, 0x11, 0x24, 0x00, 0x0d, 0xf0, 0x05, 0xb1
|
|
|
|
};
|
|
|
|
|
2013-09-10 22:09:33 +04:00
|
|
|
|
2011-07-22 17:19:33 +04:00
|
|
|
/* Indexed by pl110_version */
|
|
|
|
static const unsigned char *idregs[] = {
|
|
|
|
pl110_id,
|
2013-09-10 22:09:33 +04:00
|
|
|
/* The ARM documentation (DDI0224C) says the CLCDC on the Versatile board
|
|
|
|
* has a different ID (0x93, 0x10, 0x04, 0x00, ...). However the hardware
|
|
|
|
* itself has the same ID values as a stock PL110, and guests (in
|
|
|
|
* particular Linux) rely on this. We emulate what the hardware does,
|
|
|
|
* rather than what the docs claim it ought to do.
|
|
|
|
*/
|
|
|
|
pl110_id,
|
2011-07-22 17:19:33 +04:00
|
|
|
pl111_id
|
|
|
|
};
|
|
|
|
|
2006-02-06 07:11:15 +03:00
|
|
|
#define BITS 8
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "pl110_template.h"
|
2006-02-06 07:11:15 +03:00
|
|
|
#define BITS 15
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "pl110_template.h"
|
2006-02-06 07:11:15 +03:00
|
|
|
#define BITS 16
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "pl110_template.h"
|
2006-02-06 07:11:15 +03:00
|
|
|
#define BITS 24
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "pl110_template.h"
|
2006-02-06 07:11:15 +03:00
|
|
|
#define BITS 32
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "pl110_template.h"
|
2006-02-06 07:11:15 +03:00
|
|
|
|
2013-07-25 02:57:23 +04:00
|
|
|
static int pl110_enabled(PL110State *s)
|
2006-02-06 07:11:15 +03:00
|
|
|
{
|
|
|
|
return (s->cr & PL110_CR_EN) && (s->cr & PL110_CR_PWR);
|
|
|
|
}
|
|
|
|
|
2006-04-09 05:06:34 +04:00
|
|
|
static void pl110_update_display(void *opaque)
|
2006-02-06 07:11:15 +03:00
|
|
|
{
|
2013-07-25 02:57:23 +04:00
|
|
|
PL110State *s = (PL110State *)opaque;
|
2013-07-25 03:09:03 +04:00
|
|
|
SysBusDevice *sbd;
|
2013-03-05 18:24:14 +04:00
|
|
|
DisplaySurface *surface = qemu_console_surface(s->con);
|
2006-02-06 07:11:15 +03:00
|
|
|
drawfn* fntable;
|
|
|
|
drawfn fn;
|
|
|
|
int dest_width;
|
|
|
|
int src_width;
|
2007-10-05 03:45:31 +04:00
|
|
|
int bpp_offset;
|
2009-04-01 16:27:59 +04:00
|
|
|
int first;
|
|
|
|
int last;
|
2006-02-06 07:11:15 +03:00
|
|
|
|
2013-07-25 03:09:03 +04:00
|
|
|
if (!pl110_enabled(s)) {
|
2006-02-06 07:11:15 +03:00
|
|
|
return;
|
2013-07-25 03:09:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sbd = SYS_BUS_DEVICE(s);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2013-03-05 18:24:14 +04:00
|
|
|
switch (surface_bits_per_pixel(surface)) {
|
2006-02-06 19:05:19 +03:00
|
|
|
case 0:
|
|
|
|
return;
|
2006-02-06 07:11:15 +03:00
|
|
|
case 8:
|
|
|
|
fntable = pl110_draw_fn_8;
|
|
|
|
dest_width = 1;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
fntable = pl110_draw_fn_15;
|
|
|
|
dest_width = 2;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
fntable = pl110_draw_fn_16;
|
|
|
|
dest_width = 2;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
fntable = pl110_draw_fn_24;
|
|
|
|
dest_width = 3;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
fntable = pl110_draw_fn_32;
|
|
|
|
dest_width = 4;
|
|
|
|
break;
|
|
|
|
default:
|
2006-02-06 19:05:19 +03:00
|
|
|
fprintf(stderr, "pl110: Bad color depth\n");
|
2006-02-06 07:11:15 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
2007-10-05 03:45:31 +04:00
|
|
|
if (s->cr & PL110_CR_BGR)
|
|
|
|
bpp_offset = 0;
|
|
|
|
else
|
2011-07-22 17:19:33 +04:00
|
|
|
bpp_offset = 24;
|
|
|
|
|
|
|
|
if ((s->version != PL111) && (s->bpp == BPP_16)) {
|
|
|
|
/* The PL110's native 16 bit mode is 5551; however
|
|
|
|
* most boards with a PL110 implement an external
|
|
|
|
* mux which allows bits to be reshuffled to give
|
|
|
|
* 565 format. The mux is typically controlled by
|
|
|
|
* an external system register.
|
2011-07-22 17:42:39 +04:00
|
|
|
* This is controlled by a GPIO input pin
|
2011-07-22 17:19:33 +04:00
|
|
|
* so boards can wire it up to their register.
|
|
|
|
*
|
|
|
|
* The PL111 straightforwardly implements both
|
|
|
|
* 5551 and 565 under control of the bpp field
|
|
|
|
* in the LCDControl register.
|
|
|
|
*/
|
2011-07-22 17:42:39 +04:00
|
|
|
switch (s->mux_ctrl) {
|
|
|
|
case 3: /* 565 BGR */
|
|
|
|
bpp_offset = (BPP_16_565 - BPP_16);
|
|
|
|
break;
|
|
|
|
case 1: /* 5551 */
|
|
|
|
break;
|
|
|
|
case 0: /* 888; also if we have loaded vmstate from an old version */
|
|
|
|
case 2: /* 565 RGB */
|
|
|
|
default:
|
|
|
|
/* treat as 565 but honour BGR bit */
|
|
|
|
bpp_offset += (BPP_16_565 - BPP_16);
|
|
|
|
break;
|
|
|
|
}
|
2011-07-22 17:19:33 +04:00
|
|
|
}
|
2007-10-05 03:45:31 +04:00
|
|
|
|
2006-02-06 07:11:15 +03:00
|
|
|
if (s->cr & PL110_CR_BEBO)
|
2011-07-22 17:19:33 +04:00
|
|
|
fn = fntable[s->bpp + 8 + bpp_offset];
|
2006-02-06 07:11:15 +03:00
|
|
|
else if (s->cr & PL110_CR_BEPO)
|
2011-07-22 17:19:33 +04:00
|
|
|
fn = fntable[s->bpp + 16 + bpp_offset];
|
2006-02-06 07:11:15 +03:00
|
|
|
else
|
2007-10-05 03:45:31 +04:00
|
|
|
fn = fntable[s->bpp + bpp_offset];
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2006-02-06 07:11:15 +03:00
|
|
|
src_width = s->cols;
|
|
|
|
switch (s->bpp) {
|
|
|
|
case BPP_1:
|
|
|
|
src_width >>= 3;
|
|
|
|
break;
|
|
|
|
case BPP_2:
|
|
|
|
src_width >>= 2;
|
|
|
|
break;
|
|
|
|
case BPP_4:
|
|
|
|
src_width >>= 1;
|
|
|
|
break;
|
|
|
|
case BPP_8:
|
|
|
|
break;
|
|
|
|
case BPP_16:
|
2011-07-22 17:19:33 +04:00
|
|
|
case BPP_16_565:
|
|
|
|
case BPP_12:
|
2006-02-06 07:11:15 +03:00
|
|
|
src_width <<= 1;
|
|
|
|
break;
|
|
|
|
case BPP_32:
|
|
|
|
src_width <<= 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dest_width *= s->cols;
|
2009-04-01 16:27:59 +04:00
|
|
|
first = 0;
|
2015-07-13 13:00:29 +03:00
|
|
|
if (s->invalidate) {
|
|
|
|
framebuffer_update_memory_section(&s->fbsection,
|
|
|
|
sysbus_address_space(sbd),
|
|
|
|
s->upbase,
|
|
|
|
s->rows, src_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
framebuffer_update_display(surface, &s->fbsection,
|
|
|
|
s->cols, s->rows,
|
2009-04-01 16:27:59 +04:00
|
|
|
src_width, dest_width, 0,
|
|
|
|
s->invalidate,
|
2012-08-27 15:32:36 +04:00
|
|
|
fn, s->palette,
|
2009-04-01 16:27:59 +04:00
|
|
|
&first, &last);
|
2015-07-13 13:00:29 +03:00
|
|
|
|
2009-04-01 16:27:59 +04:00
|
|
|
if (first >= 0) {
|
2013-03-05 18:24:14 +04:00
|
|
|
dpy_gfx_update(s->con, 0, first, s->cols, last - first + 1);
|
2006-02-06 07:11:15 +03:00
|
|
|
}
|
|
|
|
s->invalidate = 0;
|
|
|
|
}
|
|
|
|
|
2006-04-09 05:06:34 +04:00
|
|
|
static void pl110_invalidate_display(void * opaque)
|
2006-02-06 07:11:15 +03:00
|
|
|
{
|
2013-07-25 02:57:23 +04:00
|
|
|
PL110State *s = (PL110State *)opaque;
|
2006-02-06 07:11:15 +03:00
|
|
|
s->invalidate = 1;
|
2009-07-31 10:10:02 +04:00
|
|
|
if (pl110_enabled(s)) {
|
2013-03-05 18:24:14 +04:00
|
|
|
qemu_console_resize(s->con, s->cols, s->rows);
|
2009-07-31 10:10:02 +04:00
|
|
|
}
|
2006-02-06 07:11:15 +03:00
|
|
|
}
|
|
|
|
|
2013-07-25 02:57:23 +04:00
|
|
|
static void pl110_update_palette(PL110State *s, int n)
|
2006-02-06 07:11:15 +03:00
|
|
|
{
|
2013-03-05 18:24:14 +04:00
|
|
|
DisplaySurface *surface = qemu_console_surface(s->con);
|
2006-02-06 07:11:15 +03:00
|
|
|
int i;
|
|
|
|
uint32_t raw;
|
|
|
|
unsigned int r, g, b;
|
|
|
|
|
2012-08-27 15:32:36 +04:00
|
|
|
raw = s->raw_palette[n];
|
2006-02-06 07:11:15 +03:00
|
|
|
n <<= 1;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
r = (raw & 0x1f) << 3;
|
|
|
|
raw >>= 5;
|
|
|
|
g = (raw & 0x1f) << 3;
|
|
|
|
raw >>= 5;
|
|
|
|
b = (raw & 0x1f) << 3;
|
|
|
|
/* The I bit is ignored. */
|
|
|
|
raw >>= 6;
|
2013-03-05 18:24:14 +04:00
|
|
|
switch (surface_bits_per_pixel(surface)) {
|
2006-02-06 07:11:15 +03:00
|
|
|
case 8:
|
2012-08-27 15:32:36 +04:00
|
|
|
s->palette[n] = rgb_to_pixel8(r, g, b);
|
2006-02-06 07:11:15 +03:00
|
|
|
break;
|
|
|
|
case 15:
|
2012-08-27 15:32:36 +04:00
|
|
|
s->palette[n] = rgb_to_pixel15(r, g, b);
|
2006-02-06 07:11:15 +03:00
|
|
|
break;
|
|
|
|
case 16:
|
2012-08-27 15:32:36 +04:00
|
|
|
s->palette[n] = rgb_to_pixel16(r, g, b);
|
2006-02-06 07:11:15 +03:00
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
case 32:
|
2012-08-27 15:32:36 +04:00
|
|
|
s->palette[n] = rgb_to_pixel32(r, g, b);
|
2006-02-06 07:11:15 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 02:57:23 +04:00
|
|
|
static void pl110_resize(PL110State *s, int width, int height)
|
2006-02-06 07:11:15 +03:00
|
|
|
{
|
|
|
|
if (width != s->cols || height != s->rows) {
|
|
|
|
if (pl110_enabled(s)) {
|
2013-03-05 18:24:14 +04:00
|
|
|
qemu_console_resize(s->con, width, height);
|
2006-02-06 07:11:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
s->cols = width;
|
|
|
|
s->rows = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update interrupts. */
|
2013-07-25 02:57:23 +04:00
|
|
|
static void pl110_update(PL110State *s)
|
2006-02-06 07:11:15 +03:00
|
|
|
{
|
2018-01-25 14:45:30 +03:00
|
|
|
/* Raise IRQ if enabled and any status bit is 1 */
|
|
|
|
if (s->int_status & s->int_mask) {
|
|
|
|
qemu_irq_raise(s->irq);
|
|
|
|
} else {
|
|
|
|
qemu_irq_lower(s->irq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pl110_vblank_interrupt(void *opaque)
|
|
|
|
{
|
|
|
|
PL110State *s = opaque;
|
|
|
|
|
|
|
|
/* Fire the vertical compare and next base IRQs and re-arm */
|
|
|
|
s->int_status |= (PL110_IE_NB | PL110_IE_VC);
|
|
|
|
timer_mod(s->vblank_timer,
|
|
|
|
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
|
|
|
|
NANOSECONDS_PER_SECOND / 60);
|
|
|
|
pl110_update(s);
|
2006-02-06 07:11:15 +03:00
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t pl110_read(void *opaque, hwaddr offset,
|
2011-10-10 19:18:44 +04:00
|
|
|
unsigned size)
|
2006-02-06 07:11:15 +03:00
|
|
|
{
|
2013-07-25 02:57:23 +04:00
|
|
|
PL110State *s = (PL110State *)opaque;
|
2006-02-06 07:11:15 +03:00
|
|
|
|
|
|
|
if (offset >= 0xfe0 && offset < 0x1000) {
|
2011-07-22 17:19:33 +04:00
|
|
|
return idregs[s->version][(offset - 0xfe0) >> 2];
|
2006-02-06 07:11:15 +03:00
|
|
|
}
|
|
|
|
if (offset >= 0x200 && offset < 0x400) {
|
2012-08-27 15:32:36 +04:00
|
|
|
return s->raw_palette[(offset - 0x200) >> 2];
|
2006-02-06 07:11:15 +03:00
|
|
|
}
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* LCDTiming0 */
|
|
|
|
return s->timing[0];
|
|
|
|
case 1: /* LCDTiming1 */
|
|
|
|
return s->timing[1];
|
|
|
|
case 2: /* LCDTiming2 */
|
|
|
|
return s->timing[2];
|
|
|
|
case 3: /* LCDTiming3 */
|
|
|
|
return s->timing[3];
|
|
|
|
case 4: /* LCDUPBASE */
|
|
|
|
return s->upbase;
|
|
|
|
case 5: /* LCDLPBASE */
|
|
|
|
return s->lpbase;
|
|
|
|
case 6: /* LCDIMSC */
|
2011-07-22 17:19:33 +04:00
|
|
|
if (s->version != PL110) {
|
|
|
|
return s->cr;
|
|
|
|
}
|
2006-02-06 07:11:15 +03:00
|
|
|
return s->int_mask;
|
|
|
|
case 7: /* LCDControl */
|
2011-07-22 17:19:33 +04:00
|
|
|
if (s->version != PL110) {
|
|
|
|
return s->int_mask;
|
|
|
|
}
|
2006-02-06 07:11:15 +03:00
|
|
|
return s->cr;
|
|
|
|
case 8: /* LCDRIS */
|
|
|
|
return s->int_status;
|
|
|
|
case 9: /* LCDMIS */
|
|
|
|
return s->int_status & s->int_mask;
|
|
|
|
case 11: /* LCDUPCURR */
|
|
|
|
/* TODO: Implement vertical refresh. */
|
|
|
|
return s->upbase;
|
|
|
|
case 12: /* LCDLPCURR */
|
|
|
|
return s->lpbase;
|
|
|
|
default:
|
2012-10-30 11:45:09 +04:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"pl110_read: Bad offset %x\n", (int)offset);
|
2006-02-06 07:11:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void pl110_write(void *opaque, hwaddr offset,
|
2011-10-10 19:18:44 +04:00
|
|
|
uint64_t val, unsigned size)
|
2006-02-06 07:11:15 +03:00
|
|
|
{
|
2013-07-25 02:57:23 +04:00
|
|
|
PL110State *s = (PL110State *)opaque;
|
2006-02-06 07:11:15 +03:00
|
|
|
int n;
|
|
|
|
|
|
|
|
/* For simplicity invalidate the display whenever a control register
|
2011-11-29 12:52:39 +04:00
|
|
|
is written to. */
|
2006-02-06 07:11:15 +03:00
|
|
|
s->invalidate = 1;
|
|
|
|
if (offset >= 0x200 && offset < 0x400) {
|
2012-08-27 15:32:36 +04:00
|
|
|
/* Palette. */
|
2006-02-06 07:11:15 +03:00
|
|
|
n = (offset - 0x200) >> 2;
|
2012-08-27 15:32:36 +04:00
|
|
|
s->raw_palette[(offset - 0x200) >> 2] = val;
|
|
|
|
pl110_update_palette(s, n);
|
2006-03-03 02:58:13 +03:00
|
|
|
return;
|
2006-02-06 07:11:15 +03:00
|
|
|
}
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* LCDTiming0 */
|
|
|
|
s->timing[0] = val;
|
|
|
|
n = ((val & 0xfc) + 4) * 4;
|
|
|
|
pl110_resize(s, n, s->rows);
|
|
|
|
break;
|
|
|
|
case 1: /* LCDTiming1 */
|
|
|
|
s->timing[1] = val;
|
|
|
|
n = (val & 0x3ff) + 1;
|
|
|
|
pl110_resize(s, s->cols, n);
|
|
|
|
break;
|
|
|
|
case 2: /* LCDTiming2 */
|
|
|
|
s->timing[2] = val;
|
|
|
|
break;
|
|
|
|
case 3: /* LCDTiming3 */
|
|
|
|
s->timing[3] = val;
|
|
|
|
break;
|
|
|
|
case 4: /* LCDUPBASE */
|
|
|
|
s->upbase = val;
|
|
|
|
break;
|
|
|
|
case 5: /* LCDLPBASE */
|
|
|
|
s->lpbase = val;
|
|
|
|
break;
|
|
|
|
case 6: /* LCDIMSC */
|
2011-07-22 17:19:33 +04:00
|
|
|
if (s->version != PL110) {
|
2006-04-09 05:32:52 +04:00
|
|
|
goto control;
|
2011-07-22 17:19:33 +04:00
|
|
|
}
|
2006-04-09 05:32:52 +04:00
|
|
|
imsc:
|
2006-02-06 07:11:15 +03:00
|
|
|
s->int_mask = val;
|
|
|
|
pl110_update(s);
|
|
|
|
break;
|
|
|
|
case 7: /* LCDControl */
|
2011-07-22 17:19:33 +04:00
|
|
|
if (s->version != PL110) {
|
2006-04-09 05:32:52 +04:00
|
|
|
goto imsc;
|
2011-07-22 17:19:33 +04:00
|
|
|
}
|
2006-04-09 05:32:52 +04:00
|
|
|
control:
|
2006-02-06 07:11:15 +03:00
|
|
|
s->cr = val;
|
|
|
|
s->bpp = (val >> 1) & 7;
|
|
|
|
if (pl110_enabled(s)) {
|
2013-03-05 18:24:14 +04:00
|
|
|
qemu_console_resize(s->con, s->cols, s->rows);
|
2018-01-25 14:45:30 +03:00
|
|
|
timer_mod(s->vblank_timer,
|
|
|
|
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
|
|
|
|
NANOSECONDS_PER_SECOND / 60);
|
|
|
|
} else {
|
|
|
|
timer_del(s->vblank_timer);
|
2006-02-06 07:11:15 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10: /* LCDICR */
|
|
|
|
s->int_status &= ~val;
|
|
|
|
pl110_update(s);
|
|
|
|
break;
|
|
|
|
default:
|
2012-10-30 11:45:09 +04:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"pl110_write: Bad offset %x\n", (int)offset);
|
2006-02-06 07:11:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-10 19:18:44 +04:00
|
|
|
static const MemoryRegionOps pl110_ops = {
|
|
|
|
.read = pl110_read,
|
|
|
|
.write = pl110_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2006-02-06 07:11:15 +03:00
|
|
|
};
|
|
|
|
|
2011-07-22 17:42:39 +04:00
|
|
|
static void pl110_mux_ctrl_set(void *opaque, int line, int level)
|
|
|
|
{
|
2013-07-25 02:57:23 +04:00
|
|
|
PL110State *s = (PL110State *)opaque;
|
2011-07-22 17:42:39 +04:00
|
|
|
s->mux_ctrl = level;
|
|
|
|
}
|
|
|
|
|
2011-12-19 16:01:58 +04:00
|
|
|
static int vmstate_pl110_post_load(void *opaque, int version_id)
|
|
|
|
{
|
2013-07-25 02:57:23 +04:00
|
|
|
PL110State *s = opaque;
|
2011-12-19 16:01:58 +04:00
|
|
|
/* Make sure we redraw, and at the right size */
|
|
|
|
pl110_invalidate_display(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-13 17:04:18 +04:00
|
|
|
static const GraphicHwOps pl110_gfx_ops = {
|
|
|
|
.invalidate = pl110_invalidate_display,
|
|
|
|
.gfx_update = pl110_update_display,
|
|
|
|
};
|
|
|
|
|
2016-10-24 18:26:56 +03:00
|
|
|
static void pl110_realize(DeviceState *dev, Error **errp)
|
2006-02-06 07:11:15 +03:00
|
|
|
{
|
2013-07-25 03:09:03 +04:00
|
|
|
PL110State *s = PL110(dev);
|
2016-10-24 18:26:56 +03:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
2006-02-06 07:11:15 +03:00
|
|
|
|
2013-06-07 05:25:08 +04:00
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &pl110_ops, s, "pl110", 0x1000);
|
2013-07-25 03:09:03 +04:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
2018-01-25 14:45:30 +03:00
|
|
|
s->vblank_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
|
|
|
|
pl110_vblank_interrupt, s);
|
2013-07-25 03:09:03 +04:00
|
|
|
qdev_init_gpio_in(dev, pl110_mux_ctrl_set, 1);
|
2014-01-24 18:35:21 +04:00
|
|
|
s->con = graphic_console_init(dev, 0, &pl110_gfx_ops, s);
|
2006-02-06 07:11:15 +03:00
|
|
|
}
|
2009-05-15 01:35:07 +04:00
|
|
|
|
2013-07-25 03:09:03 +04:00
|
|
|
static void pl110_init(Object *obj)
|
|
|
|
{
|
|
|
|
PL110State *s = PL110(obj);
|
|
|
|
|
|
|
|
s->version = PL110;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pl110_versatile_init(Object *obj)
|
2009-05-15 01:35:07 +04:00
|
|
|
{
|
2013-07-25 03:09:03 +04:00
|
|
|
PL110State *s = PL110(obj);
|
|
|
|
|
2011-07-22 17:19:33 +04:00
|
|
|
s->version = PL110_VERSATILE;
|
|
|
|
}
|
|
|
|
|
2013-07-25 03:09:03 +04:00
|
|
|
static void pl111_init(Object *obj)
|
2011-07-22 17:19:33 +04:00
|
|
|
{
|
2013-07-25 03:09:03 +04:00
|
|
|
PL110State *s = PL110(obj);
|
|
|
|
|
2011-07-22 17:19:33 +04:00
|
|
|
s->version = PL111;
|
2009-05-15 01:35:07 +04:00
|
|
|
}
|
|
|
|
|
2012-01-24 23:12:29 +04:00
|
|
|
static void pl110_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
|
|
|
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->vmsd = &vmstate_pl110;
|
2016-10-24 18:26:56 +03:00
|
|
|
dc->realize = pl110_realize;
|
2012-01-24 23:12:29 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo pl110_info = {
|
2013-07-25 03:09:03 +04:00
|
|
|
.name = TYPE_PL110,
|
2011-12-08 07:34:16 +04:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2013-07-25 02:57:23 +04:00
|
|
|
.instance_size = sizeof(PL110State),
|
2013-07-25 03:09:03 +04:00
|
|
|
.instance_init = pl110_init,
|
2011-12-08 07:34:16 +04:00
|
|
|
.class_init = pl110_class_init,
|
2010-12-23 20:19:56 +03:00
|
|
|
};
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo pl110_versatile_info = {
|
2011-12-08 07:34:16 +04:00
|
|
|
.name = "pl110_versatile",
|
2013-07-25 03:09:03 +04:00
|
|
|
.parent = TYPE_PL110,
|
|
|
|
.instance_init = pl110_versatile_init,
|
2010-12-23 20:19:56 +03:00
|
|
|
};
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo pl111_info = {
|
2011-12-08 07:34:16 +04:00
|
|
|
.name = "pl111",
|
2013-07-25 03:09:03 +04:00
|
|
|
.parent = TYPE_PL110,
|
|
|
|
.instance_init = pl111_init,
|
2011-07-22 17:19:33 +04:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void pl110_register_types(void)
|
2009-05-15 01:35:07 +04:00
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
type_register_static(&pl110_info);
|
|
|
|
type_register_static(&pl110_versatile_info);
|
|
|
|
type_register_static(&pl111_info);
|
2009-05-15 01:35:07 +04:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(pl110_register_types)
|