Create a branch for network fixes.
[reactos.git] / drivers / video / videoprt / int10.c
1 /*
2 * VideoPort driver
3 *
4 * Copyright (C) 2002, 2003, 2004 ReactOS Team
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; see the file COPYING.LIB.
18 * If not, write to the Free Software Foundation,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 */
22
23 #include "videoprt.h"
24 #include "internal/i386/v86m.h"
25
26 /* PRIVATE FUNCTIONS **********************************************************/
27
28 VP_STATUS NTAPI
29 IntInt10AllocateBuffer(
30 IN PVOID Context,
31 OUT PUSHORT Seg,
32 OUT PUSHORT Off,
33 IN OUT PULONG Length)
34 {
35 PVOID MemoryAddress;
36 NTSTATUS Status;
37 PKPROCESS CallingProcess;
38 KAPC_STATE ApcState;
39
40 TRACE_(VIDEOPRT, "IntInt10AllocateBuffer\n");
41
42 IntAttachToCSRSS(&CallingProcess, &ApcState);
43
44 MemoryAddress = (PVOID)0x20000;
45 Status = ZwAllocateVirtualMemory(NtCurrentProcess(), &MemoryAddress, 0,
46 Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
47
48 if (!NT_SUCCESS(Status))
49 {
50 WARN_(VIDEOPRT, "- ZwAllocateVirtualMemory failed\n");
51 IntDetachFromCSRSS(&CallingProcess, &ApcState);
52 return ERROR_NOT_ENOUGH_MEMORY;
53 }
54
55 if (MemoryAddress > (PVOID)(0x100000 - *Length))
56 {
57 ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, Length,
58 MEM_RELEASE);
59 WARN_(VIDEOPRT, "- Unacceptable memory allocated\n");
60 IntDetachFromCSRSS(&CallingProcess, &ApcState);
61 return ERROR_NOT_ENOUGH_MEMORY;
62 }
63
64 *Seg = (ULONG)MemoryAddress >> 4;
65 *Off = (ULONG)MemoryAddress & 0xF;
66
67 INFO_(VIDEOPRT, "- Segment: %x\n", (ULONG)MemoryAddress >> 4);
68 INFO_(VIDEOPRT, "- Offset: %x\n", (ULONG)MemoryAddress & 0xF);
69 INFO_(VIDEOPRT, "- Length: %x\n", *Length);
70
71 IntDetachFromCSRSS(&CallingProcess, &ApcState);
72
73 return NO_ERROR;
74 }
75
76 VP_STATUS NTAPI
77 IntInt10FreeBuffer(
78 IN PVOID Context,
79 IN USHORT Seg,
80 IN USHORT Off)
81 {
82 PVOID MemoryAddress = (PVOID)((Seg << 4) | Off);
83 NTSTATUS Status;
84 PKPROCESS CallingProcess;
85 KAPC_STATE ApcState;
86
87 TRACE_(VIDEOPRT, "IntInt10FreeBuffer\n");
88 INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
89 INFO_(VIDEOPRT, "- Offset: %x\n", Off);
90
91 IntAttachToCSRSS(&CallingProcess, &ApcState);
92 Status = ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, 0,
93 MEM_RELEASE);
94 IntDetachFromCSRSS(&CallingProcess, &ApcState);
95
96 return Status;
97 }
98
99 VP_STATUS NTAPI
100 IntInt10ReadMemory(
101 IN PVOID Context,
102 IN USHORT Seg,
103 IN USHORT Off,
104 OUT PVOID Buffer,
105 IN ULONG Length)
106 {
107 PKPROCESS CallingProcess;
108 KAPC_STATE ApcState;
109
110 TRACE_(VIDEOPRT, "IntInt10ReadMemory\n");
111 INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
112 INFO_(VIDEOPRT, "- Offset: %x\n", Off);
113 INFO_(VIDEOPRT, "- Buffer: %x\n", Buffer);
114 INFO_(VIDEOPRT, "- Length: %x\n", Length);
115
116 IntAttachToCSRSS(&CallingProcess, &ApcState);
117 RtlCopyMemory(Buffer, (PVOID)((Seg << 4) | Off), Length);
118 IntDetachFromCSRSS(&CallingProcess, &ApcState);
119
120 return NO_ERROR;
121 }
122
123 VP_STATUS NTAPI
124 IntInt10WriteMemory(
125 IN PVOID Context,
126 IN USHORT Seg,
127 IN USHORT Off,
128 IN PVOID Buffer,
129 IN ULONG Length)
130 {
131 PKPROCESS CallingProcess;
132 KAPC_STATE ApcState;
133
134 TRACE_(VIDEOPRT, "IntInt10WriteMemory\n");
135 INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
136 INFO_(VIDEOPRT, "- Offset: %x\n", Off);
137 INFO_(VIDEOPRT, "- Buffer: %x\n", Buffer);
138 INFO_(VIDEOPRT, "- Length: %x\n", Length);
139
140 IntAttachToCSRSS(&CallingProcess, &ApcState);
141 RtlCopyMemory((PVOID)((Seg << 4) | Off), Buffer, Length);
142 IntDetachFromCSRSS(&CallingProcess, &ApcState);
143
144 return NO_ERROR;
145 }
146
147 VP_STATUS
148 NTAPI
149 IntInt10CallBios(
150 IN PVOID Context,
151 IN OUT PINT10_BIOS_ARGUMENTS BiosArguments)
152 {
153 CONTEXT BiosContext;
154 NTSTATUS Status;
155 PKPROCESS CallingProcess;
156 KAPC_STATE ApcState;
157
158 /* Attach to CSRSS */
159 IntAttachToCSRSS(&CallingProcess, &ApcState);
160
161 /* Clear the context */
162 RtlZeroMemory(&BiosContext, sizeof(CONTEXT));
163
164 /* Fill out the bios arguments */
165 BiosContext.Eax = BiosArguments->Eax;
166 BiosContext.Ebx = BiosArguments->Ebx;
167 BiosContext.Ecx = BiosArguments->Ecx;
168 BiosContext.Edx = BiosArguments->Edx;
169 BiosContext.Esi = BiosArguments->Esi;
170 BiosContext.Edi = BiosArguments->Edi;
171 BiosContext.Ebp = BiosArguments->Ebp;
172 BiosContext.SegDs = BiosArguments->SegDs;
173 BiosContext.SegEs = BiosArguments->SegEs;
174
175 /* Do the ROM BIOS call */
176 Status = Ke386CallBios(0x10, &BiosContext);
177
178 /* Return the arguments */
179 BiosArguments->Eax = BiosContext.Eax;
180 BiosArguments->Ebx = BiosContext.Ebx;
181 BiosArguments->Ecx = BiosContext.Ecx;
182 BiosArguments->Edx = BiosContext.Edx;
183 BiosArguments->Esi = BiosContext.Esi;
184 BiosArguments->Edi = BiosContext.Edi;
185 BiosArguments->Ebp = BiosContext.Ebp;
186 BiosArguments->SegDs = BiosContext.SegDs;
187 BiosArguments->SegEs = BiosContext.SegEs;
188
189 /* Detach and return status */
190 IntDetachFromCSRSS(&CallingProcess, &ApcState);
191 return Status;
192 }
193
194 /* PUBLIC FUNCTIONS ***********************************************************/
195
196 /*
197 * @implemented
198 */
199
200 VP_STATUS NTAPI
201 VideoPortInt10(
202 IN PVOID HwDeviceExtension,
203 IN PVIDEO_X86_BIOS_ARGUMENTS BiosArguments)
204 {
205 KV86M_REGISTERS Regs;
206 NTSTATUS Status;
207 PKPROCESS CallingProcess;
208 KAPC_STATE ApcState;
209
210 TRACE_(VIDEOPRT, "VideoPortInt10\n");
211
212 if (!CsrssInitialized)
213 {
214 return ERROR_INVALID_PARAMETER;
215 }
216
217 IntAttachToCSRSS(&CallingProcess, &ApcState);
218
219 memset(&Regs, 0, sizeof(Regs));
220 INFO_(VIDEOPRT, "- Input register Eax: %x\n", BiosArguments->Eax);
221 Regs.Eax = BiosArguments->Eax;
222 INFO_(VIDEOPRT, "- Input register Ebx: %x\n", BiosArguments->Ebx);
223 Regs.Ebx = BiosArguments->Ebx;
224 INFO_(VIDEOPRT, "- Input register Ecx: %x\n", BiosArguments->Ecx);
225 Regs.Ecx = BiosArguments->Ecx;
226 INFO_(VIDEOPRT, "- Input register Edx: %x\n", BiosArguments->Edx);
227 Regs.Edx = BiosArguments->Edx;
228 INFO_(VIDEOPRT, "- Input register Esi: %x\n", BiosArguments->Esi);
229 Regs.Esi = BiosArguments->Esi;
230 INFO_(VIDEOPRT, "- Input register Edi: %x\n", BiosArguments->Edi);
231 Regs.Edi = BiosArguments->Edi;
232 INFO_(VIDEOPRT, "- Input register Ebp: %x\n", BiosArguments->Ebp);
233 Regs.Ebp = BiosArguments->Ebp;
234 Status = Ke386CallBios(0x10, (PCONTEXT)&Regs);
235 BiosArguments->Eax = Regs.Eax;
236 BiosArguments->Ebx = Regs.Ebx;
237 BiosArguments->Ecx = Regs.Ecx;
238 BiosArguments->Edx = Regs.Edx;
239 BiosArguments->Esi = Regs.Esi;
240 BiosArguments->Edi = Regs.Edi;
241 BiosArguments->Ebp = Regs.Ebp;
242
243 IntDetachFromCSRSS(&CallingProcess, &ApcState);
244
245 return Status;
246 }