summaryrefslogtreecommitdiff
path: root/src/xg47_misc.c
blob: dcce5d0682ba8df8750633ceb1c115c33490c7cf (plain)
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
/***************************************************************************
 * Copyright (C) 2003-2006 by XGI Technology, Taiwan.			   *
 *									   *
 * All Rights Reserved.							   *
 *									   *
 * Permission is hereby granted, free of charge, to any person obtaining   *
 * a copy of this software and associated documentation files (the	   *
 * "Software"), to deal in the Software without restriction, including	   *
 * without limitation on the rights to use, copy, modify, merge,	   *
 * publish, distribute, sublicense, and/or sell copies of the Software,	   *
 * and to permit persons to whom the Software is furnished to do so,	   *
 * subject to the following conditions:					   *
 *									   *
 * The above copyright notice and this permission notice (including the	   *
 * next paragraph) shall be included in all copies or substantial	   *
 * portions of the Software.						   *
 *									   *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,	   *
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF	   *
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND		   *
 * NON-INFRINGEMENT.  IN NO EVENT SHALL XGI AND/OR			   *
 * ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,	   *
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,	   *
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER	   *
 * DEALINGS IN THE SOFTWARE.						   *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "xgi.h"
#include "xgi_version.h"
#include "xgi_regs.h"

void XG47EnableMMIO(ScrnInfoPtr pScrn)
{
    XGIPtr      pXGI = XGIPTR(pScrn);
    CARD8       protect = 0, temp = 0, temp1 = 0;

    /* Unprotect registers */
    outb(0x3C4, 0x11);
    protect = inb(0x3C5);
    outb(0x3C5, 0x92);

    /* Go to new mode */
    outb(0x3C4, 0xB);
    temp1 = inb(0x3C5);

    /*
     * in order to enable write configuration port (3C5.0CH, 3C5.0FH, 3X5.28H,
     * 3X5.29H, 3X5.2AH and bit [6:4] of 3C5.0EH), bit7 of control Register
     * (3C5.0EH) must be set 1 in the New Mode firstly. Bit1 of (3C5.0EH)
     * should be inverted when performing write.
     */
    outb(0x3C4, 0xE);
    temp = inb(0x3C5);
    if (temp & 0x2) {
        outb(0x3C5, ((temp | 0x80) & 0xFC));
    } else {
        outb(0x3C5, ((temp | 0x80) | 0x2));
    }

    /*
     * 3D4/3D5	3A
     * <5>: BOTH_IO
     *      1: Enable both pure-IO and MMIO
     *      0: No MMIO
     */
    outb(0x3D4, 0x3A);
    outb(0x3D5, inb(0x3D5) | 0x20);

    /* Enable MMIO */
    outb(0x3D4, 0x39);
    outb(0x3D5, inb(0x3D5) | 0x01);

    /* Go to old mode */
    OUTB(0x3C4, 0xB);
    OUTB(0x3C5, temp1);

    /* Protect registers */
    OUTB(0x3C4, 0x11);
    OUTB(0x3C5, protect);
}


void XG47DisableMMIO(ScrnInfoPtr pScrn)
{
    uint8_t protect = 0;
    XGIPtr  pXGI = XGIPTR(pScrn);

    if (pXGI->IOBase == 0) {
	return;
    }

    /* Protect registers */
    OUTB(0x3C4, 0x11);
    protect = INB(0x3C5);
    OUTB(0x3C5, 0x92);

    /* Disable MMIO access */
    OUTB(0x3D4, 0x39);
    OUTB(0x3D5, INB(0x3D5) & 0xFE);

    /* Protect registers */
    outb(pXGI->PIOBase + 0x3C4, 0x11);
    outb(pXGI->PIOBase + 0x3C5, protect);
}


void XG47AdjustFrame(ADJUST_FRAME_ARGS_DECL)
{
    SCRN_INFO_PTR(arg);
    XGIPtr          pXGI = XGIPTR(pScrn);
    unsigned long   base = y * pScrn->displayWidth + x;

#if DBG_FLOW
    ErrorF("(II) XGI (0) ++ Enter %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
#endif

    switch (pScrn->bitsPerPixel) {
    case 8:
        base &= 0xFFFFFFF8;
        base >>= (pScrn->progClock) ? 2 : 3;
        break;
    case 16:
        base >>= 1;
        break;
    case 24:
        base = (((base + 1) & ~0x03) * 3) >> 2;
        break;
    case 32:
        break;
    }

    OUT3X5B(0x0d, (base & 0x000000FF) >> 0x00);
    OUT3X5B(0x0c, (base & 0x0000FF00) >> 0x08);
    OUT3X5B(0x8c, (base & 0x00FF0000) >> 0x10);
    OUT3X5B(0x8d, (base & 0xFF000000) >> 0x18);

#if DBG_FLOW
    ErrorF("(II) XGI (0) -- Leave %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
#endif
}


/**
 * Examine hardware to determine the size of installed memory.
 */
void XG47GetFramebufferSize(XGIPtr pXGI)
{
    /* See documentation on page 9-17 of "Volari XP10 non-3D SPG v1.0.pdf"
     */
    const uint8_t biascntl = IN3X5B(0x60);
    static const unsigned s[8] = {
        256, 128, 64, 32, 16, 0, 0, 0
    };


    pXGI->biosFbSize = s[biascntl & 0x07] * 0x100000;
    pXGI->freeFbSize = pXGI->biosFbSize;
}