xref: /openbmc/qemu/hw/display/dpcd.c (revision d6454270575da1f16a8923c7cb240e46ef243f72)
1e27ed1bdSKONRAD Frederic /*
2e27ed1bdSKONRAD Frederic  * dpcd.c
3e27ed1bdSKONRAD Frederic  *
4e27ed1bdSKONRAD Frederic  *  Copyright (C) 2015 : GreenSocs Ltd
5e27ed1bdSKONRAD Frederic  *      http://www.greensocs.com/ , email: info@greensocs.com
6e27ed1bdSKONRAD Frederic  *
7e27ed1bdSKONRAD Frederic  *  Developed by :
8e27ed1bdSKONRAD Frederic  *  Frederic Konrad   <fred.konrad@greensocs.com>
9e27ed1bdSKONRAD Frederic  *
10e27ed1bdSKONRAD Frederic  * This program is free software; you can redistribute it and/or modify
11e27ed1bdSKONRAD Frederic  * it under the terms of the GNU General Public License as published by
12e27ed1bdSKONRAD Frederic  * the Free Software Foundation, either version 2 of the License, or
13e27ed1bdSKONRAD Frederic  * (at your option)any later version.
14e27ed1bdSKONRAD Frederic  *
15e27ed1bdSKONRAD Frederic  * This program is distributed in the hope that it will be useful,
16e27ed1bdSKONRAD Frederic  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17e27ed1bdSKONRAD Frederic  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18e27ed1bdSKONRAD Frederic  * GNU General Public License for more details.
19e27ed1bdSKONRAD Frederic  *
20e27ed1bdSKONRAD Frederic  * You should have received a copy of the GNU General Public License along
21e27ed1bdSKONRAD Frederic  * with this program; if not, see <http://www.gnu.org/licenses/>.
22e27ed1bdSKONRAD Frederic  *
23e27ed1bdSKONRAD Frederic  */
24e27ed1bdSKONRAD Frederic 
25e27ed1bdSKONRAD Frederic /*
26e27ed1bdSKONRAD Frederic  * This is a simple AUX slave which emulates a connected screen.
27e27ed1bdSKONRAD Frederic  */
28e27ed1bdSKONRAD Frederic 
29e27ed1bdSKONRAD Frederic #include "qemu/osdep.h"
30e27ed1bdSKONRAD Frederic #include "qemu/log.h"
310b8fa32fSMarkus Armbruster #include "qemu/module.h"
32e0dadc1eSPeter Maydell #include "hw/misc/auxbus.h"
33*d6454270SMarkus Armbruster #include "migration/vmstate.h"
34e27ed1bdSKONRAD Frederic #include "hw/display/dpcd.h"
35e27ed1bdSKONRAD Frederic 
36e27ed1bdSKONRAD Frederic #ifndef DEBUG_DPCD
37e27ed1bdSKONRAD Frederic #define DEBUG_DPCD 0
38e27ed1bdSKONRAD Frederic #endif
39e27ed1bdSKONRAD Frederic 
40e27ed1bdSKONRAD Frederic #define DPRINTF(fmt, ...) do {                                                 \
41e27ed1bdSKONRAD Frederic     if (DEBUG_DPCD) {                                                          \
42e27ed1bdSKONRAD Frederic         qemu_log("dpcd: " fmt, ## __VA_ARGS__);                                \
43e27ed1bdSKONRAD Frederic     }                                                                          \
442562755eSEric Blake } while (0)
45e27ed1bdSKONRAD Frederic 
46e27ed1bdSKONRAD Frederic #define DPCD_READABLE_AREA                      0x600
47e27ed1bdSKONRAD Frederic 
48e27ed1bdSKONRAD Frederic struct DPCDState {
49e27ed1bdSKONRAD Frederic     /*< private >*/
50e27ed1bdSKONRAD Frederic     AUXSlave parent_obj;
51e27ed1bdSKONRAD Frederic 
52e27ed1bdSKONRAD Frederic     /*< public >*/
53e27ed1bdSKONRAD Frederic     /*
54e27ed1bdSKONRAD Frederic      * The DCPD is 0x7FFFF length but read as 0 after offset 0x5FF.
55e27ed1bdSKONRAD Frederic      */
56e27ed1bdSKONRAD Frederic     uint8_t dpcd_info[DPCD_READABLE_AREA];
57e27ed1bdSKONRAD Frederic 
58e27ed1bdSKONRAD Frederic     MemoryRegion iomem;
59e27ed1bdSKONRAD Frederic };
60e27ed1bdSKONRAD Frederic 
61e27ed1bdSKONRAD Frederic static uint64_t dpcd_read(void *opaque, hwaddr offset, unsigned size)
62e27ed1bdSKONRAD Frederic {
63e27ed1bdSKONRAD Frederic     uint8_t ret;
64e27ed1bdSKONRAD Frederic     DPCDState *e = DPCD(opaque);
65e27ed1bdSKONRAD Frederic 
66e27ed1bdSKONRAD Frederic     if (offset < DPCD_READABLE_AREA) {
67e27ed1bdSKONRAD Frederic         ret = e->dpcd_info[offset];
68e27ed1bdSKONRAD Frederic     } else {
69e27ed1bdSKONRAD Frederic         qemu_log_mask(LOG_GUEST_ERROR, "dpcd: Bad offset 0x%" HWADDR_PRIX "\n",
70e27ed1bdSKONRAD Frederic                                        offset);
71e27ed1bdSKONRAD Frederic         ret = 0;
72e27ed1bdSKONRAD Frederic     }
73e27ed1bdSKONRAD Frederic 
74e27ed1bdSKONRAD Frederic     DPRINTF("read 0x%" PRIX8 " @0x%" HWADDR_PRIX "\n", ret, offset);
75e27ed1bdSKONRAD Frederic     return ret;
76e27ed1bdSKONRAD Frederic }
77e27ed1bdSKONRAD Frederic 
78e27ed1bdSKONRAD Frederic static void dpcd_write(void *opaque, hwaddr offset, uint64_t value,
79e27ed1bdSKONRAD Frederic                        unsigned size)
80e27ed1bdSKONRAD Frederic {
81e27ed1bdSKONRAD Frederic     DPCDState *e = DPCD(opaque);
82e27ed1bdSKONRAD Frederic 
83e27ed1bdSKONRAD Frederic     DPRINTF("write 0x%" PRIX8 " @0x%" HWADDR_PRIX "\n", (uint8_t)value, offset);
84e27ed1bdSKONRAD Frederic 
85e27ed1bdSKONRAD Frederic     if (offset < DPCD_READABLE_AREA) {
86e27ed1bdSKONRAD Frederic         e->dpcd_info[offset] = value;
87e27ed1bdSKONRAD Frederic     } else {
88e27ed1bdSKONRAD Frederic         qemu_log_mask(LOG_GUEST_ERROR, "dpcd: Bad offset 0x%" HWADDR_PRIX "\n",
89e27ed1bdSKONRAD Frederic                                        offset);
90e27ed1bdSKONRAD Frederic     }
91e27ed1bdSKONRAD Frederic }
92e27ed1bdSKONRAD Frederic 
93e27ed1bdSKONRAD Frederic static const MemoryRegionOps aux_ops = {
94e27ed1bdSKONRAD Frederic     .read = dpcd_read,
95e27ed1bdSKONRAD Frederic     .write = dpcd_write,
96e27ed1bdSKONRAD Frederic     .valid = {
97e27ed1bdSKONRAD Frederic         .min_access_size = 1,
98e27ed1bdSKONRAD Frederic         .max_access_size = 1,
99e27ed1bdSKONRAD Frederic     },
100e27ed1bdSKONRAD Frederic     .impl = {
101e27ed1bdSKONRAD Frederic         .min_access_size = 1,
102e27ed1bdSKONRAD Frederic         .max_access_size = 1,
103e27ed1bdSKONRAD Frederic     },
104e27ed1bdSKONRAD Frederic };
105e27ed1bdSKONRAD Frederic 
106e27ed1bdSKONRAD Frederic static void dpcd_reset(DeviceState *dev)
107e27ed1bdSKONRAD Frederic {
108e27ed1bdSKONRAD Frederic     DPCDState *s = DPCD(dev);
109e27ed1bdSKONRAD Frederic 
110e27ed1bdSKONRAD Frederic     memset(&(s->dpcd_info), 0, sizeof(s->dpcd_info));
111e27ed1bdSKONRAD Frederic 
112e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_REVISION] = DPCD_REV_1_0;
113e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_MAX_LINK_RATE] = DPCD_5_4GBPS;
114e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_MAX_LANE_COUNT] = DPCD_FOUR_LANES;
115e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_RECEIVE_PORT0_CAP_0] = DPCD_EDID_PRESENT;
116e27ed1bdSKONRAD Frederic     /* buffer size */
117e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_RECEIVE_PORT0_CAP_1] = 0xFF;
118e27ed1bdSKONRAD Frederic 
119e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_LANE0_1_STATUS] = DPCD_LANE0_CR_DONE
120e27ed1bdSKONRAD Frederic                                       | DPCD_LANE0_CHANNEL_EQ_DONE
121e27ed1bdSKONRAD Frederic                                       | DPCD_LANE0_SYMBOL_LOCKED
122e27ed1bdSKONRAD Frederic                                       | DPCD_LANE1_CR_DONE
123e27ed1bdSKONRAD Frederic                                       | DPCD_LANE1_CHANNEL_EQ_DONE
124e27ed1bdSKONRAD Frederic                                       | DPCD_LANE1_SYMBOL_LOCKED;
125e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_LANE2_3_STATUS] = DPCD_LANE2_CR_DONE
126e27ed1bdSKONRAD Frederic                                       | DPCD_LANE2_CHANNEL_EQ_DONE
127e27ed1bdSKONRAD Frederic                                       | DPCD_LANE2_SYMBOL_LOCKED
128e27ed1bdSKONRAD Frederic                                       | DPCD_LANE3_CR_DONE
129e27ed1bdSKONRAD Frederic                                       | DPCD_LANE3_CHANNEL_EQ_DONE
130e27ed1bdSKONRAD Frederic                                       | DPCD_LANE3_SYMBOL_LOCKED;
131e27ed1bdSKONRAD Frederic 
132e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_LANE_ALIGN_STATUS_UPDATED] = DPCD_INTERLANE_ALIGN_DONE;
133e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_SINK_STATUS] = DPCD_RECEIVE_PORT_0_STATUS;
134e27ed1bdSKONRAD Frederic }
135e27ed1bdSKONRAD Frederic 
136e27ed1bdSKONRAD Frederic static void dpcd_init(Object *obj)
137e27ed1bdSKONRAD Frederic {
138e27ed1bdSKONRAD Frederic     DPCDState *s = DPCD(obj);
139e27ed1bdSKONRAD Frederic 
140e27ed1bdSKONRAD Frederic     memory_region_init_io(&s->iomem, obj, &aux_ops, s, TYPE_DPCD, 0x7FFFF);
141e27ed1bdSKONRAD Frederic     aux_init_mmio(AUX_SLAVE(obj), &s->iomem);
142e27ed1bdSKONRAD Frederic }
143e27ed1bdSKONRAD Frederic 
144e27ed1bdSKONRAD Frederic static const VMStateDescription vmstate_dpcd = {
145e27ed1bdSKONRAD Frederic     .name = TYPE_DPCD,
146e27ed1bdSKONRAD Frederic     .version_id = 0,
147e27ed1bdSKONRAD Frederic     .minimum_version_id = 0,
148e27ed1bdSKONRAD Frederic     .fields = (VMStateField[]) {
149e27ed1bdSKONRAD Frederic         VMSTATE_UINT8_ARRAY_V(dpcd_info, DPCDState, DPCD_READABLE_AREA, 0),
150e27ed1bdSKONRAD Frederic         VMSTATE_END_OF_LIST()
151e27ed1bdSKONRAD Frederic     }
152e27ed1bdSKONRAD Frederic };
153e27ed1bdSKONRAD Frederic 
154e27ed1bdSKONRAD Frederic static void dpcd_class_init(ObjectClass *oc, void *data)
155e27ed1bdSKONRAD Frederic {
156e27ed1bdSKONRAD Frederic     DeviceClass *dc = DEVICE_CLASS(oc);
157e27ed1bdSKONRAD Frederic 
158e27ed1bdSKONRAD Frederic     dc->reset = dpcd_reset;
159e27ed1bdSKONRAD Frederic     dc->vmsd = &vmstate_dpcd;
160e27ed1bdSKONRAD Frederic }
161e27ed1bdSKONRAD Frederic 
162e27ed1bdSKONRAD Frederic static const TypeInfo dpcd_info = {
163e27ed1bdSKONRAD Frederic     .name          = TYPE_DPCD,
164e27ed1bdSKONRAD Frederic     .parent        = TYPE_AUX_SLAVE,
165e27ed1bdSKONRAD Frederic     .instance_size = sizeof(DPCDState),
166e27ed1bdSKONRAD Frederic     .class_init    = dpcd_class_init,
167e27ed1bdSKONRAD Frederic     .instance_init = dpcd_init,
168e27ed1bdSKONRAD Frederic };
169e27ed1bdSKONRAD Frederic 
170e27ed1bdSKONRAD Frederic static void dpcd_register_types(void)
171e27ed1bdSKONRAD Frederic {
172e27ed1bdSKONRAD Frederic     type_register_static(&dpcd_info);
173e27ed1bdSKONRAD Frederic }
174e27ed1bdSKONRAD Frederic 
175e27ed1bdSKONRAD Frederic type_init(dpcd_register_types)
176