Fixed gtk-doc comment syntax
[captive.git] / src / libcaptive / mm / mdl.c
1 /* $Id$
2  * reactos MDL emulation of libcaptive
3  * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "reactos/ddk/mmfuncs.h"        /* self */
23 #include <glib/gmessages.h>
24
25
26 /**
27  * MmProbeAndLockPages:
28  * @Mdl: Pointer to the #MDL specification structure to probe and lock.
29  * %NULL value is forbidden.
30  * @AccessMode: Access at which to probe the pages. Ignored by libcaptive.
31  * @Operation: One of %IoReadAccess, %IoWriteAccess or %IoModifyAccess.
32  *
33  * Probles the specified @AccessMode and locks those pages specified by @Mdl to memory
34  * with the desired @AccessMode.
35  * libcaptive does NOP here as it just sets the %MDL_PAGES_LOCKED flag.
36  */
37 VOID MmProbeAndLockPages(PMDL Mdl,KPROCESSOR_MODE AccessMode,LOCK_OPERATION Operation)
38 {
39         g_return_if_fail(Mdl!=NULL);
40
41         Mdl->MdlFlags|=MDL_PAGES_LOCKED;
42 }
43
44
45 /**
46  * MmUnlockPages:
47  * @Mdl: Pointer to the #MDL specification structure to unlock.
48  * %NULL value is forbidden.
49  *
50  * Unlock the pages specified by @Mdl from memory.
51  * libcaptive does NOP here as it just clears the %MDL_PAGES_LOCKED flag.
52  */
53 VOID MmUnlockPages(PMDL Mdl)
54 {
55         g_return_if_fail(Mdl!=NULL);
56
57         Mdl->MdlFlags&=~MDL_PAGES_LOCKED;
58 }
59
60
61 /**
62  * MmMapLockedPages:
63  * @Mdl: Pointer to the #MDL specification structure to map.
64  * %NULL value is forbidden.
65  * @AccessMode: Access at which to lock the pages. Ignored by libcaptive.
66  *
67  * Leaves the pages at their original location as they are never moved anyway
68  * by libcaptive.
69  *
70  * Returns: Address of the mapped pages base.
71  * This offset does not neet to be %PAGE_SIZE aligned.
72  */
73 PVOID MmMapLockedPages(PMDL Mdl,KPROCESSOR_MODE AccessMode)
74 {
75         g_return_val_if_fail(Mdl!=NULL,NULL);
76         g_assert(Mdl->StartVa!=NULL);
77
78         if (Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA) {
79                 /* already mapped */
80                 g_assert(Mdl->MappedSystemVa==Mdl->StartVa+Mdl->ByteOffset);
81                 }
82         else {
83                 /* new mapping */
84                 Mdl->MappedSystemVa=Mdl->StartVa+Mdl->ByteOffset;
85                 Mdl->MdlFlags|=MDL_MAPPED_TO_SYSTEM_VA;
86                 }
87
88         return Mdl->MappedSystemVa;
89 }
90
91
92 /**
93  * MmUnmapLockedPages:
94  * @BaseAddress: Address of the mapped pages base.
95  * This offset does not neet to be %PAGE_SIZE aligned.
96  * @Mdl: Pointer to the #MDL specification structure to unmap.
97  *
98  * Declares the specified @Mdl pages as unmapped. @BaseAddress
99  * is required to be previously returned by MmMapLockedPages().
100  * You must not call this function twice without MmMapLockedPages() between.
101  */
102 VOID MmUnmapLockedPages(PVOID BaseAddress,PMDL Mdl)
103 {
104         g_return_if_fail(BaseAddress!=NULL);
105         g_return_if_fail(Mdl!=NULL);
106         g_return_if_fail(Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA);
107         g_return_if_fail(BaseAddress!=Mdl->MappedSystemVa);
108
109         Mdl->MappedSystemVa=NULL;
110         Mdl->MdlFlags&=~MDL_MAPPED_TO_SYSTEM_VA;
111 }