xref: /openbmc/qemu/hw/display/dpcd.c (revision eeb1168032a1f6dfc7eb5897c3bf4e53fdc28b98)
1e27ed1bdSKONRAD Frederic /*
291e7fd3aSPhilippe Mathieu-Daudé  * Xilinx Display Port Control Data
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"
33d6454270SMarkus Armbruster #include "migration/vmstate.h"
34e27ed1bdSKONRAD Frederic #include "hw/display/dpcd.h"
35*eeb11680SPhilippe Mathieu-Daudé #include "trace.h"
36e27ed1bdSKONRAD Frederic 
37e27ed1bdSKONRAD Frederic #define DPCD_READABLE_AREA                      0x600
38e27ed1bdSKONRAD Frederic 
39e27ed1bdSKONRAD Frederic struct DPCDState {
40e27ed1bdSKONRAD Frederic     /*< private >*/
41e27ed1bdSKONRAD Frederic     AUXSlave parent_obj;
42e27ed1bdSKONRAD Frederic 
43e27ed1bdSKONRAD Frederic     /*< public >*/
44e27ed1bdSKONRAD Frederic     /*
45e27ed1bdSKONRAD Frederic      * The DCPD is 0x7FFFF length but read as 0 after offset 0x5FF.
46e27ed1bdSKONRAD Frederic      */
47e27ed1bdSKONRAD Frederic     uint8_t dpcd_info[DPCD_READABLE_AREA];
48e27ed1bdSKONRAD Frederic 
49e27ed1bdSKONRAD Frederic     MemoryRegion iomem;
50e27ed1bdSKONRAD Frederic };
51e27ed1bdSKONRAD Frederic 
52e27ed1bdSKONRAD Frederic static uint64_t dpcd_read(void *opaque, hwaddr offset, unsigned size)
53e27ed1bdSKONRAD Frederic {
54e27ed1bdSKONRAD Frederic     uint8_t ret;
55e27ed1bdSKONRAD Frederic     DPCDState *e = DPCD(opaque);
56e27ed1bdSKONRAD Frederic 
57e27ed1bdSKONRAD Frederic     if (offset < DPCD_READABLE_AREA) {
58e27ed1bdSKONRAD Frederic         ret = e->dpcd_info[offset];
59e27ed1bdSKONRAD Frederic     } else {
60e27ed1bdSKONRAD Frederic         qemu_log_mask(LOG_GUEST_ERROR, "dpcd: Bad offset 0x%" HWADDR_PRIX "\n",
61e27ed1bdSKONRAD Frederic                                        offset);
62e27ed1bdSKONRAD Frederic         ret = 0;
63e27ed1bdSKONRAD Frederic     }
64*eeb11680SPhilippe Mathieu-Daudé     trace_dpcd_read(offset, ret);
65e27ed1bdSKONRAD Frederic 
66e27ed1bdSKONRAD Frederic     return ret;
67e27ed1bdSKONRAD Frederic }
68e27ed1bdSKONRAD Frederic 
69e27ed1bdSKONRAD Frederic static void dpcd_write(void *opaque, hwaddr offset, uint64_t value,
70e27ed1bdSKONRAD Frederic                        unsigned size)
71e27ed1bdSKONRAD Frederic {
72e27ed1bdSKONRAD Frederic     DPCDState *e = DPCD(opaque);
73e27ed1bdSKONRAD Frederic 
74*eeb11680SPhilippe Mathieu-Daudé     trace_dpcd_write(offset, value);
75e27ed1bdSKONRAD Frederic     if (offset < DPCD_READABLE_AREA) {
76e27ed1bdSKONRAD Frederic         e->dpcd_info[offset] = value;
77e27ed1bdSKONRAD Frederic     } else {
78e27ed1bdSKONRAD Frederic         qemu_log_mask(LOG_GUEST_ERROR, "dpcd: Bad offset 0x%" HWADDR_PRIX "\n",
79e27ed1bdSKONRAD Frederic                                        offset);
80e27ed1bdSKONRAD Frederic     }
81e27ed1bdSKONRAD Frederic }
82e27ed1bdSKONRAD Frederic 
83e27ed1bdSKONRAD Frederic static const MemoryRegionOps aux_ops = {
84e27ed1bdSKONRAD Frederic     .read = dpcd_read,
85e27ed1bdSKONRAD Frederic     .write = dpcd_write,
86e27ed1bdSKONRAD Frederic     .valid = {
87e27ed1bdSKONRAD Frederic         .min_access_size = 1,
88e27ed1bdSKONRAD Frederic         .max_access_size = 1,
89e27ed1bdSKONRAD Frederic     },
90e27ed1bdSKONRAD Frederic     .impl = {
91e27ed1bdSKONRAD Frederic         .min_access_size = 1,
92e27ed1bdSKONRAD Frederic         .max_access_size = 1,
93e27ed1bdSKONRAD Frederic     },
94e27ed1bdSKONRAD Frederic };
95e27ed1bdSKONRAD Frederic 
96e27ed1bdSKONRAD Frederic static void dpcd_reset(DeviceState *dev)
97e27ed1bdSKONRAD Frederic {
98e27ed1bdSKONRAD Frederic     DPCDState *s = DPCD(dev);
99e27ed1bdSKONRAD Frederic 
100e27ed1bdSKONRAD Frederic     memset(&(s->dpcd_info), 0, sizeof(s->dpcd_info));
101e27ed1bdSKONRAD Frederic 
102e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_REVISION] = DPCD_REV_1_0;
103e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_MAX_LINK_RATE] = DPCD_5_4GBPS;
104e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_MAX_LANE_COUNT] = DPCD_FOUR_LANES;
105e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_RECEIVE_PORT0_CAP_0] = DPCD_EDID_PRESENT;
106e27ed1bdSKONRAD Frederic     /* buffer size */
107e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_RECEIVE_PORT0_CAP_1] = 0xFF;
108e27ed1bdSKONRAD Frederic 
109e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_LANE0_1_STATUS] = DPCD_LANE0_CR_DONE
110e27ed1bdSKONRAD Frederic                                       | DPCD_LANE0_CHANNEL_EQ_DONE
111e27ed1bdSKONRAD Frederic                                       | DPCD_LANE0_SYMBOL_LOCKED
112e27ed1bdSKONRAD Frederic                                       | DPCD_LANE1_CR_DONE
113e27ed1bdSKONRAD Frederic                                       | DPCD_LANE1_CHANNEL_EQ_DONE
114e27ed1bdSKONRAD Frederic                                       | DPCD_LANE1_SYMBOL_LOCKED;
115e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_LANE2_3_STATUS] = DPCD_LANE2_CR_DONE
116e27ed1bdSKONRAD Frederic                                       | DPCD_LANE2_CHANNEL_EQ_DONE
117e27ed1bdSKONRAD Frederic                                       | DPCD_LANE2_SYMBOL_LOCKED
118e27ed1bdSKONRAD Frederic                                       | DPCD_LANE3_CR_DONE
119e27ed1bdSKONRAD Frederic                                       | DPCD_LANE3_CHANNEL_EQ_DONE
120e27ed1bdSKONRAD Frederic                                       | DPCD_LANE3_SYMBOL_LOCKED;
121e27ed1bdSKONRAD Frederic 
122e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_LANE_ALIGN_STATUS_UPDATED] = DPCD_INTERLANE_ALIGN_DONE;
123e27ed1bdSKONRAD Frederic     s->dpcd_info[DPCD_SINK_STATUS] = DPCD_RECEIVE_PORT_0_STATUS;
124e27ed1bdSKONRAD Frederic }
125e27ed1bdSKONRAD Frederic 
126e27ed1bdSKONRAD Frederic static void dpcd_init(Object *obj)
127e27ed1bdSKONRAD Frederic {
128e27ed1bdSKONRAD Frederic     DPCDState *s = DPCD(obj);
129e27ed1bdSKONRAD Frederic 
13091e7fd3aSPhilippe Mathieu-Daudé     memory_region_init_io(&s->iomem, obj, &aux_ops, s, TYPE_DPCD, 0x80000);
131e27ed1bdSKONRAD Frederic     aux_init_mmio(AUX_SLAVE(obj), &s->iomem);
132e27ed1bdSKONRAD Frederic }
133e27ed1bdSKONRAD Frederic 
134e27ed1bdSKONRAD Frederic static const VMStateDescription vmstate_dpcd = {
135e27ed1bdSKONRAD Frederic     .name = TYPE_DPCD,
136e27ed1bdSKONRAD Frederic     .version_id = 0,
137e27ed1bdSKONRAD Frederic     .minimum_version_id = 0,
138e27ed1bdSKONRAD Frederic     .fields = (VMStateField[]) {
139e27ed1bdSKONRAD Frederic         VMSTATE_UINT8_ARRAY_V(dpcd_info, DPCDState, DPCD_READABLE_AREA, 0),
140e27ed1bdSKONRAD Frederic         VMSTATE_END_OF_LIST()
141e27ed1bdSKONRAD Frederic     }
142e27ed1bdSKONRAD Frederic };
143e27ed1bdSKONRAD Frederic 
144e27ed1bdSKONRAD Frederic static void dpcd_class_init(ObjectClass *oc, void *data)
145e27ed1bdSKONRAD Frederic {
146e27ed1bdSKONRAD Frederic     DeviceClass *dc = DEVICE_CLASS(oc);
147e27ed1bdSKONRAD Frederic 
148e27ed1bdSKONRAD Frederic     dc->reset = dpcd_reset;
149e27ed1bdSKONRAD Frederic     dc->vmsd = &vmstate_dpcd;
150e27ed1bdSKONRAD Frederic }
151e27ed1bdSKONRAD Frederic 
152e27ed1bdSKONRAD Frederic static const TypeInfo dpcd_info = {
153e27ed1bdSKONRAD Frederic     .name          = TYPE_DPCD,
154e27ed1bdSKONRAD Frederic     .parent        = TYPE_AUX_SLAVE,
155e27ed1bdSKONRAD Frederic     .instance_size = sizeof(DPCDState),
156e27ed1bdSKONRAD Frederic     .class_init    = dpcd_class_init,
157e27ed1bdSKONRAD Frederic     .instance_init = dpcd_init,
158e27ed1bdSKONRAD Frederic };
159e27ed1bdSKONRAD Frederic 
160e27ed1bdSKONRAD Frederic static void dpcd_register_types(void)
161e27ed1bdSKONRAD Frederic {
162e27ed1bdSKONRAD Frederic     type_register_static(&dpcd_info);
163e27ed1bdSKONRAD Frederic }
164e27ed1bdSKONRAD Frederic 
165e27ed1bdSKONRAD Frederic type_init(dpcd_register_types)
166