2016-06-14 17:59:15 +03:00
|
|
|
/*
|
|
|
|
* dpcd.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 : GreenSocs Ltd
|
|
|
|
* http://www.greensocs.com/ , email: info@greensocs.com
|
|
|
|
*
|
|
|
|
* Developed by :
|
|
|
|
* Frederic Konrad <fred.konrad@greensocs.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a simple AUX slave which emulates a connected screen.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "qemu/log.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2016-07-07 15:47:01 +03:00
|
|
|
#include "hw/misc/auxbus.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2016-06-14 17:59:15 +03:00
|
|
|
#include "hw/display/dpcd.h"
|
|
|
|
|
|
|
|
#ifndef DEBUG_DPCD
|
|
|
|
#define DEBUG_DPCD 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DPRINTF(fmt, ...) do { \
|
|
|
|
if (DEBUG_DPCD) { \
|
|
|
|
qemu_log("dpcd: " fmt, ## __VA_ARGS__); \
|
|
|
|
} \
|
maint: Fix macros with broken 'do/while(0); ' usage
The point of writing a macro embedded in a 'do { ... } while (0)'
loop (particularly if the macro has multiple statements or would
otherwise end with an 'if' statement) is so that the macro can be
used as a drop-in statement with the caller supplying the
trailing ';'. Although our coding style frowns on brace-less 'if':
if (cond)
statement;
else
something else;
that is the classic case where failure to use do/while(0) wrapping
would cause the 'else' to pair with any embedded 'if' in the macro
rather than the intended outer 'if'. But conversely, if the macro
includes an embedded ';', then the same brace-less coding style
would now have two statements, making the 'else' a syntax error
rather than pairing with the outer 'if'. Thus, even though our
coding style with required braces is not impacted, ending a macro
with ';' makes our code harder to port to projects that use
brace-less styles.
The change should have no semantic impact. I was not able to
fully compile-test all of the changes (as some of them are
examples of the ugly bit-rotting debug print statements that are
completely elided by default, and I didn't want to recompile
with the necessary -D witnesses - cleaning those up is left as a
bite-sized task for another day); I did, however, audit that for
all files touched, all callers of the changed macros DID supply
a trailing ';' at the callsite, and did not appear to be used
as part of a brace-less conditional.
Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20171201232433.25193-7-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-12-02 02:24:32 +03:00
|
|
|
} while (0)
|
2016-06-14 17:59:15 +03:00
|
|
|
|
|
|
|
#define DPCD_READABLE_AREA 0x600
|
|
|
|
|
|
|
|
struct DPCDState {
|
|
|
|
/*< private >*/
|
|
|
|
AUXSlave parent_obj;
|
|
|
|
|
|
|
|
/*< public >*/
|
|
|
|
/*
|
|
|
|
* The DCPD is 0x7FFFF length but read as 0 after offset 0x5FF.
|
|
|
|
*/
|
|
|
|
uint8_t dpcd_info[DPCD_READABLE_AREA];
|
|
|
|
|
|
|
|
MemoryRegion iomem;
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint64_t dpcd_read(void *opaque, hwaddr offset, unsigned size)
|
|
|
|
{
|
|
|
|
uint8_t ret;
|
|
|
|
DPCDState *e = DPCD(opaque);
|
|
|
|
|
|
|
|
if (offset < DPCD_READABLE_AREA) {
|
|
|
|
ret = e->dpcd_info[offset];
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "dpcd: Bad offset 0x%" HWADDR_PRIX "\n",
|
|
|
|
offset);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF("read 0x%" PRIX8 " @0x%" HWADDR_PRIX "\n", ret, offset);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dpcd_write(void *opaque, hwaddr offset, uint64_t value,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
DPCDState *e = DPCD(opaque);
|
|
|
|
|
|
|
|
DPRINTF("write 0x%" PRIX8 " @0x%" HWADDR_PRIX "\n", (uint8_t)value, offset);
|
|
|
|
|
|
|
|
if (offset < DPCD_READABLE_AREA) {
|
|
|
|
e->dpcd_info[offset] = value;
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "dpcd: Bad offset 0x%" HWADDR_PRIX "\n",
|
|
|
|
offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps aux_ops = {
|
|
|
|
.read = dpcd_read,
|
|
|
|
.write = dpcd_write,
|
|
|
|
.valid = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 1,
|
|
|
|
},
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void dpcd_reset(DeviceState *dev)
|
|
|
|
{
|
|
|
|
DPCDState *s = DPCD(dev);
|
|
|
|
|
|
|
|
memset(&(s->dpcd_info), 0, sizeof(s->dpcd_info));
|
|
|
|
|
|
|
|
s->dpcd_info[DPCD_REVISION] = DPCD_REV_1_0;
|
|
|
|
s->dpcd_info[DPCD_MAX_LINK_RATE] = DPCD_5_4GBPS;
|
|
|
|
s->dpcd_info[DPCD_MAX_LANE_COUNT] = DPCD_FOUR_LANES;
|
|
|
|
s->dpcd_info[DPCD_RECEIVE_PORT0_CAP_0] = DPCD_EDID_PRESENT;
|
|
|
|
/* buffer size */
|
|
|
|
s->dpcd_info[DPCD_RECEIVE_PORT0_CAP_1] = 0xFF;
|
|
|
|
|
|
|
|
s->dpcd_info[DPCD_LANE0_1_STATUS] = DPCD_LANE0_CR_DONE
|
|
|
|
| DPCD_LANE0_CHANNEL_EQ_DONE
|
|
|
|
| DPCD_LANE0_SYMBOL_LOCKED
|
|
|
|
| DPCD_LANE1_CR_DONE
|
|
|
|
| DPCD_LANE1_CHANNEL_EQ_DONE
|
|
|
|
| DPCD_LANE1_SYMBOL_LOCKED;
|
|
|
|
s->dpcd_info[DPCD_LANE2_3_STATUS] = DPCD_LANE2_CR_DONE
|
|
|
|
| DPCD_LANE2_CHANNEL_EQ_DONE
|
|
|
|
| DPCD_LANE2_SYMBOL_LOCKED
|
|
|
|
| DPCD_LANE3_CR_DONE
|
|
|
|
| DPCD_LANE3_CHANNEL_EQ_DONE
|
|
|
|
| DPCD_LANE3_SYMBOL_LOCKED;
|
|
|
|
|
|
|
|
s->dpcd_info[DPCD_LANE_ALIGN_STATUS_UPDATED] = DPCD_INTERLANE_ALIGN_DONE;
|
|
|
|
s->dpcd_info[DPCD_SINK_STATUS] = DPCD_RECEIVE_PORT_0_STATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dpcd_init(Object *obj)
|
|
|
|
{
|
|
|
|
DPCDState *s = DPCD(obj);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->iomem, obj, &aux_ops, s, TYPE_DPCD, 0x7FFFF);
|
|
|
|
aux_init_mmio(AUX_SLAVE(obj), &s->iomem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_dpcd = {
|
|
|
|
.name = TYPE_DPCD,
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8_ARRAY_V(dpcd_info, DPCDState, DPCD_READABLE_AREA, 0),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void dpcd_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
|
|
|
dc->reset = dpcd_reset;
|
|
|
|
dc->vmsd = &vmstate_dpcd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo dpcd_info = {
|
|
|
|
.name = TYPE_DPCD,
|
|
|
|
.parent = TYPE_AUX_SLAVE,
|
|
|
|
.instance_size = sizeof(DPCDState),
|
|
|
|
.class_init = dpcd_class_init,
|
|
|
|
.instance_init = dpcd_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void dpcd_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&dpcd_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(dpcd_register_types)
|