update for HEAD-2003091401
[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 /*
44  * @implemented
45  */
46 PCONFIGURATION_INFORMATION STDCALL
47 IoGetConfigurationInformation(VOID)
48 {
49   return(&SystemConfigurationInformation);
50 }
51
52 /*
53  * @unimplemented
54  */
55 NTSTATUS STDCALL
56 IoReportResourceUsage(PUNICODE_STRING DriverClassName,
57                       PDRIVER_OBJECT DriverObject,
58                       PCM_RESOURCE_LIST DriverList,
59                       ULONG DriverListSize,
60                       PDEVICE_OBJECT DeviceObject,
61                       PCM_RESOURCE_LIST DeviceList,
62                       ULONG DeviceListSize,
63                       BOOLEAN OverrideConflict,
64                       PBOOLEAN ConflictDetected)
65      /*
66       * FUNCTION: Reports hardware resources in the 
67       * \Registry\Machine\Hardware\ResourceMap tree, so that a subsequently
68       * loaded driver cannot attempt to use the same resources.
69       * ARGUMENTS:
70       *       DriverClassName - The class of driver under which the resource
71       *       information should be stored.
72       *       DriverObject - The driver object that was input to the 
73       *       DriverEntry.
74       *       DriverList - Resources that claimed for the driver rather than
75       *       per-device.
76       *       DriverListSize - Size in bytes of the DriverList.
77       *       DeviceObject - The device object for which resources should be
78       *       claimed.
79       *       DeviceList - List of resources which should be claimed for the
80       *       device.
81       *       DeviceListSize - Size of the per-device resource list in bytes.
82       *       OverrideConflict - True if the resources should be cliamed
83       *       even if a conflict is found.
84       *       ConflictDetected - Points to a variable that receives TRUE if
85       *       a conflict is detected with another driver.
86       */
87 {
88   UNIMPLEMENTED;
89 }
90
91 /*
92  * @unimplemented
93  */
94 NTSTATUS STDCALL
95 IoAssignResources(PUNICODE_STRING RegistryPath,
96                   PUNICODE_STRING DriverClassName,
97                   PDRIVER_OBJECT DriverObject,
98                   PDEVICE_OBJECT DeviceObject,
99                   PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources,
100                   PCM_RESOURCE_LIST* AllocatedResources)
101 {
102    UNIMPLEMENTED;
103 }
104
105 /*
106  * @unimplemented
107  */
108 NTSTATUS STDCALL
109 IoQueryDeviceDescription(PINTERFACE_TYPE BusType,
110                          PULONG BusNumber,
111                          PCONFIGURATION_TYPE ControllerType,
112                          PULONG ControllerNumber,
113                          PCONFIGURATION_TYPE PeripheralType,
114                          PULONG PeripheralNumber,
115                          PIO_QUERY_DEVICE_ROUTINE CalloutRoutine,
116                          PVOID Context)
117 {
118 #if 0
119   OBJECT_ATTRIBUTES ObjectAttributes;
120   NTSTATUS Status;
121   PWCH BaseKeyName[] = 
122     L"\\Registry\\Machine\\Hardware\\MultifunctionAdapter\\0";
123   HANDLE BaseKeyHandle;
124   ULONG i;
125   struct
126   {
127     KEY_BASIC_INFORMATION BasicInfo;
128     WCH Name[255];
129   } BasicInfo;
130
131   BaseKeyName = L"\\Registry\\Machine\\Hardware\\MultifunctionAdapter";
132   InitializeObjectAttributes(&ObjectAttributes,
133                              BaseKeyName,
134                              0,
135                              NULL,
136                              NULL);
137   Status = ZwOpenKey(&BaseKeyHandle,
138                      KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEY,
139                      &ObjectAttributes);
140   if (!NT_SUCCESS(Status))
141     {
142       return(Status);
143     }
144
145   i = 0;
146   for (;;)
147     {
148       Status = ZwEnumerateKey(BaseKeyHandle,
149                               i,
150                               KeyBasicInformation,
151                               &BasicInfo,
152                               sizeof(BasicInfo),
153                               &ResultLength);
154       if (!NT_SUCCESS(Status))
155         {
156           break;
157         }
158
159       
160     }
161 #endif                    
162   return(STATUS_NOT_IMPLEMENTED);
163 }
164
165 /*
166  * @implemented
167  */
168 NTSTATUS STDCALL
169 IoReportHalResourceUsage(PUNICODE_STRING HalDescription,
170                          PCM_RESOURCE_LIST RawList,
171                          PCM_RESOURCE_LIST TranslatedList,
172                          ULONG ListSize)
173 /*
174  * FUNCTION:
175  *      Reports hardware resources of the HAL in the
176  *      \Registry\Machine\Hardware\ResourceMap tree.
177  * ARGUMENTS:
178  *      HalDescription: Descriptive name of the HAL.
179  *      RawList: List of raw (bus specific) resources which should be
180  *               claimed for the HAL.
181  *      TranslatedList: List of translated (system wide) resources which
182  *                      should be claimed for the HAL.
183  *      ListSize: Size in bytes of the raw and translated resource lists.
184  *                Both lists have the same size.
185  * RETURNS:
186  *      Status.
187  */
188 {
189   OBJECT_ATTRIBUTES ObjectAttributes;
190   UNICODE_STRING Name;
191   ULONG Disposition;
192   NTSTATUS Status;
193   HANDLE ResourcemapKey;
194   HANDLE HalKey;
195   HANDLE DescriptionKey;
196
197   /* Open/Create 'RESOURCEMAP' key. */
198   RtlInitUnicodeStringFromLiteral(&Name,
199                        L"\\Registry\\Machine\\HARDWARE\\RESOURCEMAP");
200   InitializeObjectAttributes(&ObjectAttributes,
201                              &Name,
202                              OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
203                              0,
204                              NULL);
205   Status = NtCreateKey(&ResourcemapKey,
206                        KEY_ALL_ACCESS,
207                        &ObjectAttributes,
208                        0,
209                        NULL,
210                        REG_OPTION_VOLATILE,
211                        &Disposition);
212   if (!NT_SUCCESS(Status))
213     return(Status);
214
215   /* Open/Create 'Hardware Abstraction Layer' key */
216   RtlInitUnicodeStringFromLiteral(&Name,
217                        L"Hardware Abstraction Layer");
218   InitializeObjectAttributes(&ObjectAttributes,
219                              &Name,
220                              OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
221                              ResourcemapKey,
222                              NULL);
223   Status = NtCreateKey(&HalKey,
224                        KEY_ALL_ACCESS,
225                        &ObjectAttributes,
226                        0,
227                        NULL,
228                        REG_OPTION_VOLATILE,
229                        &Disposition);
230   NtClose(ResourcemapKey);
231   if (!NT_SUCCESS(Status))
232       return(Status);
233
234   /* Create 'HalDescription' key */
235   InitializeObjectAttributes(&ObjectAttributes,
236                              HalDescription,
237                              OBJ_CASE_INSENSITIVE,
238                              HalKey,
239                              NULL);
240   Status = NtCreateKey(&DescriptionKey,
241                        KEY_ALL_ACCESS,
242                        &ObjectAttributes,
243                        0,
244                        NULL,
245                        REG_OPTION_VOLATILE,
246                        &Disposition);
247   NtClose(HalKey);
248   if (!NT_SUCCESS(Status))
249     return(Status);
250
251   /* Add '.Raw' value. */
252   RtlInitUnicodeStringFromLiteral(&Name,
253                        L".Raw");
254   Status = NtSetValueKey(DescriptionKey,
255                          &Name,
256                          0,
257                          REG_RESOURCE_LIST,
258                          RawList,
259                          ListSize);
260   if (!NT_SUCCESS(Status))
261     {
262       NtClose(DescriptionKey);
263       return(Status);
264     }
265
266   /* Add '.Translated' value. */
267   RtlInitUnicodeStringFromLiteral(&Name,
268                        L".Translated");
269   Status = NtSetValueKey(DescriptionKey,
270                          &Name,
271                          0,
272                          REG_RESOURCE_LIST,
273                          TranslatedList,
274                          ListSize);
275   NtClose(DescriptionKey);
276
277   return(Status);
278 }
279
280 /* EOF */