Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / common / agp.c
1 /****************************************************************************
2 *
3 *                   SciTech OS Portability Manager Library
4 *
5 *  ========================================================================
6 *
7 *    The contents of this file are subject to the SciTech MGL Public
8 *    License Version 1.0 (the "License"); you may not use this file
9 *    except in compliance with the License. You may obtain a copy of
10 *    the License at http://www.scitechsoft.com/mgl-license.txt
11 *
12 *    Software distributed under the License is distributed on an
13 *    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 *    implied. See the License for the specific language governing
15 *    rights and limitations under the License.
16 *
17 *    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18 *
19 *    The Initial Developer of the Original Code is SciTech Software, Inc.
20 *    All Rights Reserved.
21 *
22 *  ========================================================================
23 *
24 * Language:     ANSI C
25 * Environment:  32-bit Ring 0 device driver
26 *
27 * Description:  Generic module to implement AGP support functions using the
28 *               SciTech Nucleus AGP support drivers. If the OS provides
29 *               native AGP support, this module should *NOT* be used. Instead
30 *               wrappers should be placed around the OS support functions
31 *               to implement this functionality.
32 *
33 ****************************************************************************/
34
35 #include "pmapi.h"
36 #ifndef REALMODE
37 #include "nucleus/agp.h"
38
39 /*--------------------------- Global variables ----------------------------*/
40
41 static AGP_devCtx       *agp;
42 static AGP_driverFuncs  driver;
43
44 /*----------------------------- Implementation ----------------------------*/
45
46 /****************************************************************************
47 RETURNS:
48 Size of AGP aperture in MB on success, 0 on failure.
49
50 REMARKS:
51 This function initialises the AGP driver in the system and returns the
52 size of the available AGP aperture in megabytes.
53 ****************************************************************************/
54 ulong PMAPI PM_agpInit(void)
55 {
56     if ((agp = AGP_loadDriver(0)) == NULL)
57         return 0;
58     driver.dwSize = sizeof(driver);
59     if (!agp->QueryFunctions(AGP_GET_DRIVERFUNCS,&driver))
60         return 0;
61     switch (driver.GetApertureSize()) {
62         case agpSize4MB:    return 4;
63         case agpSize8MB:    return 8;
64         case agpSize16MB:   return 16;
65         case agpSize32MB:   return 32;
66         case agpSize64MB:   return 64;
67         case agpSize128MB:  return 128;
68         case agpSize256MB:  return 256;
69         case agpSize512MB:  return 512;
70         case agpSize1GB:    return 1024;
71         case agpSize2GB:    return 2048;
72         }
73     return 0;
74 }
75
76 /****************************************************************************
77 REMARKS:
78 This function closes down the loaded AGP driver.
79 ****************************************************************************/
80 void PMAPI PM_agpExit(void)
81 {
82     AGP_unloadDriver(agp);
83 }
84
85 /****************************************************************************
86 PARAMETERS:
87 numPages    - Number of memory pages that should be reserved
88 type        - Type of memory to allocate
89 physContext - Returns the physical context handle for the mapping
90 physAddr    - Returns the physical address for the mapping
91
92 RETURNS:
93 True on success, false on failure.
94
95 REMARKS:
96 This function reserves a range of physical memory addresses on the system
97 bus which the AGP controller will respond to. If this function succeeds,
98 the AGP controller can respond to the reserved physical address range on
99 the bus. However you must first call AGP_commitPhysical to cause this memory
100 to actually be committed for use before it can be accessed.
101 ****************************************************************************/
102 ibool PMAPI PM_agpReservePhysical(
103     ulong numPages,
104     int type,
105     void **physContext,
106     PM_physAddr *physAddr)
107 {
108     switch (type) {
109         case PM_agpUncached:
110             type = agpUncached;
111             break;
112         case PM_agpWriteCombine:
113             type = agpWriteCombine;
114             break;
115         case PM_agpIntelDCACHE:
116             type = agpIntelDCACHE;
117             break;
118         default:
119             return false;
120         }
121     return driver.ReservePhysical(numPages,type,physContext,physAddr) == nOK;
122 }
123
124 /****************************************************************************
125 PARAMETERS:
126 physContext - Physical AGP context to release
127
128 RETURNS:
129 True on success, false on failure.
130
131 REMARKS:
132 This function releases a range of physical memory addresses on the system
133 bus which the AGP controller will respond to. All committed memory for
134 the physical address range covered by the context will be released.
135 ****************************************************************************/
136 ibool PMAPI PM_agpReleasePhysical(
137     void *physContext)
138 {
139     return driver.ReleasePhysical(physContext) == nOK;
140 }
141
142 /****************************************************************************
143 PARAMETERS:
144 physContext - Physical AGP context to commit memory for
145 numPages    - Number of pages to be committed
146 startOffset - Offset in pages into the reserved physical context
147 physAddr    - Returns the physical address of the committed memory
148
149 RETURNS:
150 True on success, false on failure.
151
152 REMARKS:
153 This function commits into the specified physical context that was previously
154 reserved by a call to ReservePhysical. You can use the startOffset and
155 numPages parameters to only commit portions of the reserved memory range at
156 a time.
157 ****************************************************************************/
158 ibool PMAPI PM_agpCommitPhysical(
159     void *physContext,
160     ulong numPages,
161     ulong startOffset,
162     PM_physAddr *physAddr)
163 {
164     return driver.CommitPhysical(physContext,numPages,startOffset,physAddr) == nOK;
165 }
166
167 /****************************************************************************
168 PARAMETERS:
169 physContext - Physical AGP context to free memory for
170 numPages    - Number of pages to be freed
171 startOffset - Offset in pages into the reserved physical context
172
173 RETURNS:
174 True on success, false on failure.
175
176 REMARKS:
177 This function frees memory previously committed by the CommitPhysical
178 function. Note that you can free a portion of a memory range that was
179 previously committed if you wish.
180 ****************************************************************************/
181 ibool PMAPI PM_agpFreePhysical(
182     void *physContext,
183     ulong numPages,
184     ulong startOffset)
185 {
186     return driver.FreePhysical(physContext,numPages,startOffset) == nOK;
187 }
188
189 #endif  /* !REALMODE */