1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License").  You may not use this file except in compliance with the
9 * License.  Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Boot video dumb frambuffer shim
24 */
25
26#include "IOBootFramebuffer.h"
27
28enum { kTheDisplayMode  = 10 };
29
30/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
31
32#undef super
33#define super IOFramebuffer
34
35OSDefineMetaClassAndStructors(IOBootFramebuffer, IOFramebuffer)
36
37/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
38
39IOService * IOBootFramebuffer::probe(   IOService *     provider,
40                                      SInt32 *  score )
41{
42    PE_Video            bootDisplay;
43    IOService *         ret = 0;
44    IOReturn            err;
45
46    do
47    {
48        if (!provider->getProperty("AAPL,boot-display"))
49            continue;
50
51        err = getPlatform()->getConsoleInfo( &bootDisplay );
52        if (err || (bootDisplay.v_baseAddr == 0))
53            continue;
54
55        if (false == super::probe(provider, score))
56            continue;
57
58        *score          = 0;
59        ret = this;                     // Success
60    }
61    while (false);
62
63    return (ret);
64}
65
66
67const char * IOBootFramebuffer::getPixelFormats( void )
68{
69    const char *        ret;
70    PE_Video            bootDisplay;
71
72    getPlatform()->getConsoleInfo( &bootDisplay);
73
74    switch (bootDisplay.v_depth)
75    {
76        case 8:
77        default:
78            ret = IO8BitIndexedPixels;
79            break;
80        case 15:
81        case 16:
82            ret = IO16BitDirectPixels;
83            break;
84        case 24:
85        case 32:
86            ret = IO32BitDirectPixels;
87            break;
88    }
89
90    return (ret);
91}
92
93IOItemCount IOBootFramebuffer::getDisplayModeCount( void )
94{
95    return (1);
96}
97
98IOReturn IOBootFramebuffer::getDisplayModes(
99    IODisplayModeID * allDisplayModes )
100{
101    *allDisplayModes = kTheDisplayMode;
102    return (kIOReturnSuccess);
103}
104
105IOReturn IOBootFramebuffer::getInformationForDisplayMode(
106    IODisplayModeID /* displayMode */,
107    IODisplayModeInformation * info )
108{
109    PE_Video    bootDisplay;
110
111    getPlatform()->getConsoleInfo( &bootDisplay);
112
113    bzero( info, sizeof( *info));
114
115    info->maxDepthIndex = 0;
116    info->nominalWidth  = bootDisplay.v_width;
117    info->nominalHeight = bootDisplay.v_height;
118    info->refreshRate   = 75 << 16;
119
120    return (kIOReturnSuccess);
121}
122
123UInt64 IOBootFramebuffer::getPixelFormatsForDisplayMode(
124    IODisplayModeID /* displayMode */, IOIndex /* depth */ )
125{
126    return (1);
127}
128
129IOReturn IOBootFramebuffer::getPixelInformation(
130    IODisplayModeID displayMode, IOIndex depth,
131    IOPixelAperture aperture, IOPixelInformation * info )
132{
133    PE_Video    bootDisplay;
134
135    if (aperture || depth || (displayMode != kTheDisplayMode))
136        return (kIOReturnUnsupportedMode);
137
138    getPlatform()->getConsoleInfo( &bootDisplay);
139
140    bzero( info, sizeof( *info));
141
142    info->activeWidth           = bootDisplay.v_width;
143    info->activeHeight          = bootDisplay.v_height;
144    info->bytesPerRow           = bootDisplay.v_rowBytes & 0x7fff;
145    info->bytesPerPlane         = 0;
146
147    switch (bootDisplay.v_depth)
148    {
149        case 8:
150        default:
151            strlcpy(info->pixelFormat, IO8BitIndexedPixels, sizeof(info->pixelFormat));
152            info->pixelType             = kIOCLUTPixels;
153            info->componentMasks[0]     = 0xff;
154            info->bitsPerPixel          = 8;
155            info->componentCount        = 1;
156            info->bitsPerComponent      = 8;
157            break;
158        case 15:
159        case 16:
160            strlcpy(info->pixelFormat, IO16BitDirectPixels, sizeof(info->pixelFormat));
161            info->pixelType     = kIORGBDirectPixels;
162            info->componentMasks[0] = 0x7c00;
163            info->componentMasks[1] = 0x03e0;
164            info->componentMasks[2] = 0x001f;
165            info->bitsPerPixel  = 16;
166            info->componentCount        = 3;
167            info->bitsPerComponent      = 5;
168            break;
169        case 24:
170        case 32:
171            strlcpy(info->pixelFormat, IO32BitDirectPixels, sizeof(info->pixelFormat));
172            info->pixelType     = kIORGBDirectPixels;
173            info->componentMasks[0] = 0x00ff0000;
174            info->componentMasks[1] = 0x0000ff00;
175            info->componentMasks[2] = 0x000000ff;
176            info->bitsPerPixel  = 32;
177            info->componentCount        = 3;
178            info->bitsPerComponent      = 8;
179            break;
180    }
181
182    return (kIOReturnSuccess);
183}
184
185IOReturn IOBootFramebuffer::getCurrentDisplayMode(
186    IODisplayModeID * displayMode, IOIndex * depth )
187{
188    if (displayMode)
189        *displayMode = kTheDisplayMode;
190    if (depth)
191        *depth = 0;
192
193    return (kIOReturnSuccess);
194}
195
196IODeviceMemory * IOBootFramebuffer::getApertureRange( IOPixelAperture aper )
197{
198    IOReturn                    err;
199    IOPixelInformation          info;
200    IOByteCount                 bytes;
201    PE_Video                    bootDisplay;
202
203    getPlatform()->getConsoleInfo( &bootDisplay);
204
205    err = getPixelInformation( kTheDisplayMode, 0, aper,
206                               &info );
207    if (err)
208        return (0);
209
210    bytes = (info.bytesPerRow * info.activeHeight) + 128;
211
212    return (IODeviceMemory::withRange(bootDisplay.v_baseAddr, bytes));
213}
214
215bool IOBootFramebuffer::isConsoleDevice( void )
216{
217    return ((0 != getProvider()->getProperty("AAPL,boot-display")));
218}
219
220IOReturn IOBootFramebuffer::setGammaTable( UInt32 channelCount,
221        UInt32 dataCount, UInt32 dataWidth, void * data )
222{
223    return (kIOReturnSuccess);
224}
225
226IOReturn IOBootFramebuffer::setCLUTWithEntries(
227    IOColorEntry * colors, UInt32 index, UInt32 numEntries,
228    IOOptionBits options )
229{
230    return (kIOReturnSuccess);
231}
232