summaryrefslogtreecommitdiffstats
path: root/private/ntos/fw/mips/jxvideo.c
blob: a4db0974aa186ea9f54d745d17037f7ac14b8a7e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#if defined(JAZZ)

/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    jxvideo.c

Abstract:

    This module implements the interface with the video prom initialization
    code.

Author:

    David M. Robinson (davidro) 24-Jul-1991

Environment:

    Kernel mode.


Revision History:

--*/

#include "fwp.h"
#include "jxvideo.h"
#include "ioaccess.h"
#include "selfmap.h"

//
// Static data
//

UCHAR PromStride, PromSize, PromId;
UCHAR PromWidth;
UCHAR AdrShift;
PUCHAR IdentifierString;
UCHAR PromString[32];

VOID
ReadVideoPromData(
    IN ULONG SrcOfst,
    IN ULONG DstAdr,
    IN ULONG Size
    );

BOOLEAN
ValidVideoProm(
    )
/*++

Routine Description:

    This routine checks for valid header info in the video prom.
    At the same time it initializes the variables needed to
    read data from the video prom.


Arguments:

    None.

Return Value:

    TRUE If the video rom is valid.
    FALSE otherwise.

--*/

{

    PromId = READ_REGISTER_UCHAR(VIDEO_CONTROL_VIRTUAL_BASE);

    PromStride = READ_REGISTER_UCHAR(VIDEO_CONTROL_VIRTUAL_BASE+0x08);

    switch (PromStride) {
        case    1: AdrShift = 0;
                   break;

        case    2: AdrShift = 1;
                   break;

        case    4: AdrShift = 2;
                   break;

        case    8: AdrShift = 3;
                   break;
        default:
                   return FALSE;
    }

    PromWidth  = READ_REGISTER_UCHAR(VIDEO_CONTROL_VIRTUAL_BASE+0x10);
    if ((PromWidth != 1) && (PromWidth != 2) && (PromWidth != 4) &&
       (PromWidth != 8)) {
        return FALSE;
    }
    PromSize = READ_REGISTER_UCHAR(VIDEO_CONTROL_VIRTUAL_BASE+0x18);
    if ((READ_REGISTER_UCHAR(VIDEO_CONTROL_VIRTUAL_BASE+0x20) != 'J') ||
        (READ_REGISTER_UCHAR(VIDEO_CONTROL_VIRTUAL_BASE+0x28) != 'a') ||
        (READ_REGISTER_UCHAR(VIDEO_CONTROL_VIRTUAL_BASE+0x30) != 'z') ||
        (READ_REGISTER_UCHAR(VIDEO_CONTROL_VIRTUAL_BASE+0x38) != 'z')) {
        return FALSE;
    }

    return TRUE;
}

ARC_STATUS
InitializeVideoFromProm(
    IN PMONITOR_CONFIGURATION_DATA Monitor
    )
/*++

Routine Description:

    This routine loads the code from the video prom into the specified address.

Arguments:

    DstAdr -  Address where the video rom code is to be copied.

Return Value:

    If the video rom is not valid, returns EINVAL otherwise
    return ESUCCESS

--*/

{

    VIDEO_VIRTUAL_SPACE VideoAdr;
    ARC_STATUS Status;
    ULONG GlobalConfig;
    ULONG VideoSize;
    ULONG ConfigSize;
    VIDEO_PROM_CONFIGURATION PromConfig;

    if (ValidVideoProm() == FALSE) {
        return EINVAL;
    }

    //
    // Read VIDEO_PROM_CONFIGURATION structure
    //

    ReadVideoPromData(8,(ULONG)&PromConfig,sizeof(PromConfig));

    //sprintf(String,"VideoMemorySize = %lx\r\n",PromConfig.VideoMemorySize);
    //VenPrint(String);
    //sprintf(String,"VideoControlSize = %lx\r\n",PromConfig.VideoControlSize);
    //VenPrint(String);
    //sprintf(String,"CodeOffset = %lx\r\n",PromConfig.CodeOffset);
    //VenPrint(String);
    //sprintf(String,"CodeSize = %lx\r\n",PromConfig.CodeSize);
    //VenPrint(String);

    //
    // Set the video size in the global config
    //

    VideoSize = (PromConfig.VideoMemorySize > PromConfig.VideoControlSize ?  PromConfig.VideoMemorySize : PromConfig.VideoControlSize);

    //
    // Initialize size of Video space
    //
    // 0 ->  512K
    // 1 ->  2MB
    // 2 ->  8MB
    // 3 -> 32MB
    //

    ConfigSize = 0;

    if (VideoSize > 0x80000) {
        ConfigSize = 1;
    }
    if (VideoSize > 0x200000) {
        ConfigSize = 2;
    }

    if (VideoSize > 0x800000) {
        ConfigSize = 3;
    }

    GlobalConfig = READ_REGISTER_ULONG(&DMA_CONTROL->Configuration.Long);

    VideoAdr.MemoryVirtualBase =  VIDEO_MEMORY_VIRTUAL_BASE;
    VideoAdr.ControlVirtualBase = VIDEO_CONTROL_VIRTUAL_BASE;

#ifdef DUO
    GlobalConfig = (GlobalConfig & 0x3C) | ConfigSize;
#else

    //sprintf(String,"Global Config = %lx\r\n",GlobalConfig);
    //VenPrint(String);
    //
    // Look for the MCT_ADR REV2 Map Prom bit in the configuration register,
    // if there this is a REV2, otherwise REV1.
    //
    if (GlobalConfig & 0x400) {
        GlobalConfig = (GlobalConfig & 0xFCFF) | (ConfigSize << 8);
    } else {
        GlobalConfig = (GlobalConfig & 0xFF3F) | (ConfigSize << 6);
    }
#endif

    WRITE_REGISTER_ULONG(&DMA_CONTROL->Configuration.Long,GlobalConfig);
    //sprintf(String,"Setting Global Config = %lx\r\n",GlobalConfig);
    //VenPrint(String);

    //
    //  Read the identifier string
    //

    ReadVideoPromData(8+sizeof(PromConfig),(ULONG)PromString,32);
    IdentifierString = &PromString[0];

    // VenPrint(IdentifierString);

    //
    // Copy the code from the video prom to system memory.
    // The prom is copied uncached, no need to flush Dcache.
    // This memory has just been tested. There has no been any
    // code before -> no need to flush Icache.
    //

    ReadVideoPromData(PromConfig.CodeOffset,VIDEO_PROM_CODE_UNCACHED_BASE,PromConfig.CodeSize);

    //VenPrint("Code loaded\r\n");
    //DbgBreakPoint();
    //
    // Flush caches!!!!
    //

    // FwFlushAllCaches();

    //VenPrint("Code loaded and caches flushed\r\n");
    //DbgBreakPoint();

    //VenPrint("\r\nJumping to the moon\r\n");

    Status = InitializeVideo(&VideoAdr,Monitor);

    //sprintf(String,"Return status %lx \r\n",Status);
    //VenPrint (String);

    return Status;

}

VOID
ReadVideoPromData(
    IN ULONG SrcOfst,
    IN ULONG DstAdr,
    IN ULONG Size
    )

/*++

Routine Description:

    This routine copies Size bytes of data from the Video PROM starting
    at SrcOfst into DstAdr.
    This routine takes into account PromStride and PromWidth;

Arguments:

        SrcOfst -  Offset from the beginning of the video prom in bytes
                   without taking into account PromStride.
        DstAdr  -  Address where the video rom data is to be copied.
        Size    -  Size in bytes to copy

Return Value:

    If the video rom is not valid, returns EINVAL otherwise
    return ESUCCESS

--*/

{

ULONG  SrcAdr;
ULONG  LastAdr;

    SrcAdr  = SrcOfst;
    LastAdr = DstAdr+Size;

    switch (PromWidth) {

        //
        // Read 1 byte at a time.
        //
       case  1:
            while ( DstAdr < LastAdr)  {
                *(PUCHAR)DstAdr = READ_REGISTER_UCHAR(VIDEO_CONTROL_VIRTUAL_BASE + (SrcAdr << AdrShift));
                SrcAdr+=1;
                DstAdr+=1;
            }
            break;


        //
        // Read 2 bytes at a time.
        //

        case  2:
            while ( DstAdr < LastAdr)  {
                *(PUSHORT)DstAdr = READ_REGISTER_USHORT(VIDEO_CONTROL_VIRTUAL_BASE + (SrcAdr << AdrShift));
                SrcAdr+=1;
                DstAdr+=2;
            }
            break;


        //
        // Read 4 bytes at a time.
        //

        case  4:
        case  8:

            while ( DstAdr < LastAdr)  {
                *(PULONG)DstAdr = READ_REGISTER_ULONG(VIDEO_CONTROL_VIRTUAL_BASE + (SrcAdr << AdrShift));
                SrcAdr+=1;
                DstAdr+=4;
            }
            break;

    }

}

#endif