:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / ntoskrnl / io / resource.c
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
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; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /* $Id$
20  *
21  * PROJECT:         ReactOS kernel
22  * FILE:            ntoskrnl/io/resource.c
23  * PURPOSE:         Hardware resource managment
24  * PROGRAMMER:      David Welch (welch@mcmail.com)
25  * UPDATE HISTORY:
26  *                  Created 22/05/98
27  */
28
29 /* INCLUDES *****************************************************************/
30
31 #include <ddk/ntddk.h>
32
33
34 #include <internal/debug.h>
35
36 /* GLOBALS *******************************************************************/
37
38 static CONFIGURATION_INFORMATION
39 SystemConfigurationInformation = {0, 0, 0, 0, 0, 0, 0, FALSE, FALSE};
40
41 /* FUNCTIONS *****************************************************************/
42
43 PCONFIGURATION_INFORMATION STDCALL
44 IoGetConfigurationInformation(VOID)
45 {
46   return(&SystemConfigurationInformation);
47 }
48
49 NTSTATUS STDCALL
50 IoReportResourceUsage(PUNICODE_STRING DriverClassName,
51                       PDRIVER_OBJECT DriverObject,
52                       PCM_RESOURCE_LIST DriverList,
53                       ULONG DriverListSize,
54                       PDEVICE_OBJECT DeviceObject,
55                       PCM_RESOURCE_LIST DeviceList,
56                       ULONG DeviceListSize,
57                       BOOLEAN OverrideConflict,
58                       PBOOLEAN ConflictDetected)
59      /*
60       * FUNCTION: Reports hardware resources in the 
61       * \Registry\Machine\Hardware\ResourceMap tree, so that a subsequently
62       * loaded driver cannot attempt to use the same resources.
63       * ARGUMENTS:
64       *       DriverClassName - The class of driver under which the resource
65       *       information should be stored.
66       *       DriverObject - The driver object that was input to the 
67       *       DriverEntry.
68       *       DriverList - Resources that claimed for the driver rather than
69       *       per-device.
70       *       DriverListSize - Size in bytes of the DriverList.
71       *       DeviceObject - The device object for which resources should be
72       *       claimed.
73       *       DeviceList - List of resources which should be claimed for the
74       *       device.
75       *       DeviceListSize - Size of the per-device resource list in bytes.
76       *       OverrideConflict - True if the resources should be cliamed
77       *       even if a conflict is found.
78       *       ConflictDetected - Points to a variable that receives TRUE if
79       *       a conflict is detected with another driver.
80       */
81 {
82   UNIMPLEMENTED;
83 }
84
85 NTSTATUS STDCALL
86 IoAssignResources(PUNICODE_STRING RegistryPath,
87                   PUNICODE_STRING DriverClassName,
88                   PDRIVER_OBJECT DriverObject,
89                   PDEVICE_OBJECT DeviceObject,
90                   PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources,
91                   PCM_RESOURCE_LIST* AllocatedResources)
92 {
93    UNIMPLEMENTED;
94 }
95
96 NTSTATUS STDCALL
97 IoQueryDeviceDescription(PINTERFACE_TYPE BusType,
98                          PULONG BusNumber,
99                          PCONFIGURATION_TYPE ControllerType,
100                          PULONG ControllerNumber,
101                          PCONFIGURATION_TYPE PeripheralType,
102                          PULONG PeripheralNumber,
103                          PIO_QUERY_DEVICE_ROUTINE CalloutRoutine,
104                          PVOID Context)
105 {
106 #if 0
107   OBJECT_ATTRIBUTES ObjectAttributes;
108   NTSTATUS Status;
109   PWCH BaseKeyName[] = 
110     L"\\Registry\\Machine\\Hardware\\MultifunctionAdapter\\0";
111   HANDLE BaseKeyHandle;
112   ULONG i;
113   struct
114   {
115     KEY_BASIC_INFORMATION BasicInfo;
116     WCH Name[255];
117   } BasicInfo;
118
119   BaseKeyName = L"\\Registry\\Machine\\Hardware\\MultifunctionAdapter";
120   InitializeObjectAttributes(&ObjectAttributes,
121                              BaseKeyName,
122                              0,
123                              NULL,
124                              NULL);
125   Status = ZwOpenKey(&BaseKeyHandle,
126                      KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEY,
127                      &ObjectAttributes);
128   if (!NT_SUCCESS(Status))
129     {
130       return(Status);
131     }
132
133   i = 0;
134   for (;;)
135     {
136       Status = ZwEnumerateKey(BaseKeyHandle,
137                               i,
138                               KeyBasicInformation,
139                               &BasicInfo,
140                               sizeof(BasicInfo),
141                               &ResultLength);
142       if (!NT_SUCCESS(Status))
143         {
144           break;
145         }
146
147       
148     }
149 #endif                    
150   return(STATUS_NOT_IMPLEMENTED);
151 }
152
153 NTSTATUS STDCALL
154 IoReportHalResourceUsage(PUNICODE_STRING HalDescription,
155                          PCM_RESOURCE_LIST RawList,
156                          PCM_RESOURCE_LIST TranslatedList,
157                          ULONG ListSize)
158 /*
159  * FUNCTION:
160  *      Reports hardware resources of the HAL in the
161  *      \Registry\Machine\Hardware\ResourceMap tree.
162  * ARGUMENTS:
163  *      HalDescription: Descriptive name of the HAL.
164  *      RawList: List of raw (bus specific) resources which should be
165  *               claimed for the HAL.
166  *      TranslatedList: List of translated (system wide) resources which
167  *                      should be claimed for the HAL.
168  *      ListSize: Size in bytes of the raw and translated resource lists.
169  *                Both lists have the same size.
170  * RETURNS:
171  *      Status.
172  */
173 {
174   OBJECT_ATTRIBUTES ObjectAttributes;
175   UNICODE_STRING Name;
176   ULONG Disposition;
177   NTSTATUS Status;
178   HANDLE ResourcemapKey;
179   HANDLE HalKey;
180   HANDLE DescriptionKey;
181
182   /* Open/Create 'RESOURCEMAP' key. */
183   RtlInitUnicodeStringFromLiteral(&Name,
184                        L"\\Registry\\Machine\\HARDWARE\\RESOURCEMAP");
185   InitializeObjectAttributes(&ObjectAttributes,
186                              &Name,
187                              OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
188                              0,
189                              NULL);
190   Status = NtCreateKey(&ResourcemapKey,
191                        KEY_ALL_ACCESS,
192                        &ObjectAttributes,
193                        0,
194                        NULL,
195                        REG_OPTION_VOLATILE,
196                        &Disposition);
197   if (!NT_SUCCESS(Status))
198     return(Status);
199
200   /* Open/Create 'Hardware Abstraction Layer' key */
201   RtlInitUnicodeStringFromLiteral(&Name,
202                        L"Hardware Abstraction Layer");
203   InitializeObjectAttributes(&ObjectAttributes,
204                              &Name,
205                              OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
206                              ResourcemapKey,
207                              NULL);
208   Status = NtCreateKey(&HalKey,
209                        KEY_ALL_ACCESS,
210                        &ObjectAttributes,
211                        0,
212                        NULL,
213                        REG_OPTION_VOLATILE,
214                        &Disposition);
215   NtClose(ResourcemapKey);
216   if (!NT_SUCCESS(Status))
217       return(Status);
218
219   /* Create 'HalDescription' key */
220   InitializeObjectAttributes(&ObjectAttributes,
221                              HalDescription,
222                              OBJ_CASE_INSENSITIVE,
223                              HalKey,
224                              NULL);
225   Status = NtCreateKey(&DescriptionKey,
226                        KEY_ALL_ACCESS,
227                        &ObjectAttributes,
228                        0,
229                        NULL,
230                        REG_OPTION_VOLATILE,
231                        &Disposition);
232   NtClose(HalKey);
233   if (!NT_SUCCESS(Status))
234     return(Status);
235
236   /* Add '.Raw' value. */
237   RtlInitUnicodeStringFromLiteral(&Name,
238                        L".Raw");
239   Status = NtSetValueKey(DescriptionKey,
240                          &Name,
241                          0,
242                          REG_RESOURCE_LIST,
243                          RawList,
244                          ListSize);
245   if (!NT_SUCCESS(Status))
246     {
247       NtClose(DescriptionKey);
248       return(Status);
249     }
250
251   /* Add '.Translated' value. */
252   RtlInitUnicodeStringFromLiteral(&Name,
253                        L".Translated");
254   Status = NtSetValueKey(DescriptionKey,
255                          &Name,
256                          0,
257                          REG_RESOURCE_LIST,
258                          TranslatedList,
259                          ListSize);
260   NtClose(DescriptionKey);
261
262   return(Status);
263 }
264
265 /* EOF */