1 | /* $Id: edid.c 35776 2011-01-30 00:14:29Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * Linux Additions X11 graphics driver, EDID construction
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | * --------------------------------------------------------------------
|
---|
18 | *
|
---|
19 | * This code is based on drmmode_display.c from the X.Org xf86-video-intel
|
---|
20 | * driver with the following copyright notice:
|
---|
21 | *
|
---|
22 | * Copyright © 2007 Red Hat, Inc.
|
---|
23 | *
|
---|
24 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
25 | * copy of this software and associated documentation files (the "Software"),
|
---|
26 | * to deal in the Software without restriction, including without limitation
|
---|
27 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
28 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
29 | * Software is furnished to do so, subject to the following conditions:
|
---|
30 | *
|
---|
31 | * The above copyright notice and this permission notice (including the next
|
---|
32 | * paragraph) shall be included in all copies or substantial portions of the
|
---|
33 | * Software.
|
---|
34 | *
|
---|
35 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
36 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
37 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
38 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
39 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
---|
40 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
---|
41 | * SOFTWARE.
|
---|
42 | *
|
---|
43 | * Authors:
|
---|
44 | * Dave Airlie <[email protected]>
|
---|
45 | */
|
---|
46 |
|
---|
47 | #include <xorg-server.h>
|
---|
48 | #include <misc.h>
|
---|
49 | #include <xf86DDC.h>
|
---|
50 | #include <xf86Crtc.h>
|
---|
51 | #include "vboxvideo.h"
|
---|
52 |
|
---|
53 | enum { EDID_SIZE = 128 };
|
---|
54 |
|
---|
55 | const unsigned char g_acszEDIDBase[EDID_SIZE] =
|
---|
56 | {
|
---|
57 | 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, /* header */
|
---|
58 | 0x58, 0x58, /* manufacturer (VBX) */
|
---|
59 | 0x00, 0x00, /* product code */
|
---|
60 | 0x00, 0x00,0x00, 0x00, /* serial number goes here */
|
---|
61 | 0x01, /* week of manufacture */
|
---|
62 | 0x00, /* year of manufacture */
|
---|
63 | 0x01, 0x03, /* EDID version */
|
---|
64 | 0x80, /* capabilities - digital */
|
---|
65 | 0x00, /* horiz. res in cm, zero for projectors */
|
---|
66 | 0x00, /* vert. res in cm */
|
---|
67 | 0x78, /* display gamma (120 == 2.2). Should we ask the host for this? */
|
---|
68 | 0xEE, /* features (standby, suspend, off, RGB, standard colour space,
|
---|
69 | * preferred timing mode) */
|
---|
70 | 0xEE, 0x91, 0xA3, 0x54, 0x4C, 0x99, 0x26, 0x0F, 0x50, 0x54,
|
---|
71 | /* chromaticity for standard colour space - should we ask the host? */
|
---|
72 | 0x00, 0x00, 0x00, /* no default timings */
|
---|
73 | 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
---|
74 | 0x01, 0x01, 0x01, 0x01, /* no standard timings */
|
---|
75 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
---|
76 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* descriptor block 1 goes here */
|
---|
77 | 0x00, 0x00, 0x00, 0xFD, 0x00, /* descriptor block 2, monitor ranges */
|
---|
78 | 0x00, 0xC8, 0x00, 0xC8, 0x64, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
---|
79 | 0x20, /* 0-200Hz vertical, 0-200KHz horizontal, 1000MHz pixel clock */
|
---|
80 | 0x00, 0x00, 0x00, 0xFC, 0x00, /* descriptor block 3, monitor name */
|
---|
81 | 'V', 'B', 'O', 'X', ' ', 'm', 'o', 'n', 'i', 't', 'o', 'r', '\n',
|
---|
82 | 0x00, 0x00, 0x00, 0x10, 0x00, /* descriptor block 4: dummy data */
|
---|
83 | 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
---|
84 | 0x20,
|
---|
85 | 0x00, /* number of extensions */
|
---|
86 | 0x00 /* checksum goes here */
|
---|
87 | };
|
---|
88 |
|
---|
89 | static void fillDescBlockTimings(unsigned char *pchDescBlock,
|
---|
90 | DisplayModePtr mode)
|
---|
91 | {
|
---|
92 | struct detailed_timings timing;
|
---|
93 |
|
---|
94 | timing.clock = mode->Clock * 1000;
|
---|
95 | timing.h_active = mode->HDisplay;
|
---|
96 | timing.h_blanking = mode->HTotal - mode->HDisplay;
|
---|
97 | timing.v_active = mode->VDisplay;
|
---|
98 | timing.v_blanking = mode->VTotal - mode->VDisplay;
|
---|
99 | timing.h_sync_off = mode->HSyncStart - mode->HDisplay;
|
---|
100 | timing.h_sync_width = mode->HSyncEnd - mode->HSyncStart;
|
---|
101 | timing.v_sync_off = mode->VSyncStart - mode->VDisplay;
|
---|
102 | timing.v_sync_width = mode->VSyncEnd - mode->VSyncStart;
|
---|
103 | pchDescBlock[0] = (timing.clock / 10000) & 0xff;
|
---|
104 | pchDescBlock[1] = (timing.clock / 10000) >> 8;
|
---|
105 | pchDescBlock[2] = timing.h_active & 0xff;
|
---|
106 | pchDescBlock[3] = timing.h_blanking & 0xff;
|
---|
107 | pchDescBlock[4] = (timing.h_active >> 4) & 0xf0;
|
---|
108 | pchDescBlock[4] |= (timing.h_blanking >> 8) & 0xf;
|
---|
109 | pchDescBlock[5] = timing.v_active & 0xff;
|
---|
110 | pchDescBlock[6] = timing.v_blanking & 0xff;
|
---|
111 | pchDescBlock[7] = (timing.v_active >> 4) & 0xf0;
|
---|
112 | pchDescBlock[7] |= (timing.v_blanking >> 8) & 0xf;
|
---|
113 | pchDescBlock[8] = timing.h_sync_off & 0xff;
|
---|
114 | pchDescBlock[9] = timing.h_sync_width & 0xff;
|
---|
115 | pchDescBlock[10] = (timing.v_sync_off << 4) & 0xf0;
|
---|
116 | pchDescBlock[10] |= timing.v_sync_width & 0xf;
|
---|
117 | pchDescBlock[11] = (timing.h_sync_off >> 2) & 0xC0;
|
---|
118 | pchDescBlock[11] |= (timing.h_sync_width >> 4) & 0x30;
|
---|
119 | pchDescBlock[11] |= (timing.v_sync_off >> 2) & 0xC;
|
---|
120 | pchDescBlock[11] |= (timing.v_sync_width >> 4) & 0x3;
|
---|
121 | pchDescBlock[12] = pchDescBlock[13] = pchDescBlock[14]
|
---|
122 | = pchDescBlock[15] = pchDescBlock[16]
|
---|
123 | = pchDescBlock[17] = 0;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | static void setEDIDChecksum(unsigned char *pch)
|
---|
128 | {
|
---|
129 | unsigned i, sum = 0;
|
---|
130 | for (i = 0; i < EDID_SIZE - 1; ++i)
|
---|
131 | sum += pch[i];
|
---|
132 | pch[EDID_SIZE - 1] = (0x100 - (sum & 0xFF)) & 0xFF;
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Construct an EDID for an output given a preferred mode. The main reason for
|
---|
138 | * doing this is to confound gnome-settings-deamon which tries to reset the
|
---|
139 | * last mode configuration if the same monitors are plugged in again, which is
|
---|
140 | * a reasonable thing to do but not what we want in a VM. We evily store
|
---|
141 | * the (empty) raw EDID data at the end of the structure so that it gets
|
---|
142 | * freed automatically along with the structure.
|
---|
143 | */
|
---|
144 | Bool VBOXEDIDSet(xf86OutputPtr output, DisplayModePtr pmode)
|
---|
145 | {
|
---|
146 | int i, j;
|
---|
147 | unsigned char *pch, *pchEDID;
|
---|
148 | xf86MonPtr pEDIDMon;
|
---|
149 |
|
---|
150 | pch = calloc(1, sizeof(xf86Monitor) + EDID_SIZE);
|
---|
151 | if (!pch)
|
---|
152 | {
|
---|
153 | xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
|
---|
154 | "Can't allocate memory for EDID structure.\n");
|
---|
155 | return FALSE;
|
---|
156 | }
|
---|
157 | pchEDID = pch + sizeof(xf86Monitor);
|
---|
158 | memcpy(pchEDID, g_acszEDIDBase, EDID_SIZE);
|
---|
159 | pchEDID[12] = pmode->HDisplay & 0xff;
|
---|
160 | pchEDID[13] = pmode->HDisplay >> 8;
|
---|
161 | pchEDID[14] = pmode->VDisplay & 0xff;
|
---|
162 | pchEDID[15] = pmode->VDisplay >> 8;
|
---|
163 | fillDescBlockTimings(pchEDID + 54, pmode);
|
---|
164 | setEDIDChecksum(pchEDID);
|
---|
165 | pEDIDMon = xf86InterpretEDID(output->scrn->scrnIndex, pchEDID);
|
---|
166 | if (!pEDIDMon)
|
---|
167 | {
|
---|
168 | free(pch);
|
---|
169 | return FALSE;
|
---|
170 | }
|
---|
171 | memcpy(pch, pEDIDMon, sizeof(xf86Monitor));
|
---|
172 | free(pEDIDMon);
|
---|
173 | pEDIDMon = (xf86MonPtr)pch;
|
---|
174 | xf86OutputSetEDID(output, pEDIDMon);
|
---|
175 | return TRUE;
|
---|
176 | }
|
---|