ReactOS 0.4.17-dev-966-gf06eace
cmconfig.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/config/cmconfig.c
5 * PURPOSE: Configuration Manager - System Configuration Routines
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include "ntoskrnl.h"
12#define NDEBUG
13#include "debug.h"
14
15/* FUNCTIONS *****************************************************************/
16
17CODE_SEG("INIT")
22 OUT PHANDLE NewHandle,
25 IN PUSHORT DeviceIndexTable)
26{
30 HANDLE KeyHandle, ParentHandle;
31 ANSI_STRING TempString;
32 CHAR TempBuffer[12];
33 WCHAR Buffer[12];
36
37 /* Get the component */
38 Component = &CurrentEntry->ComponentEntry;
39
40 /*
41 * Normalize the system class component to ARC system type.
42 * The NT OS loader already sets the component type to
43 * ArcSystem for ARC-compatible systems, but sets it to
44 * MaximumType for non-ARC-compatible ones.
45 */
46 if (Component->Class == SystemClass)
47 Component->Type = ArcSystem;
48
49 /* Create a key for the component */
51 &CmTypeName[Component->Type],
54 NULL);
58 0,
59 NULL,
60 0,
62 if (!NT_SUCCESS(Status))
63 return Status;
64
65 /* Check if this is anything but a system class component */
66 if (Component->Class != SystemClass)
67 {
68 /* Build the sub-component string */
69 RtlIntegerToChar(DeviceIndexTable[Component->Type]++,
70 10,
71 _countof(TempBuffer),
72 TempBuffer);
73 RtlInitAnsiString(&TempString, TempBuffer);
74
75 /* Convert it to Unicode */
76 RtlInitEmptyUnicodeString(&KeyName, Buffer, sizeof(Buffer));
78 if (!NT_SUCCESS(Status))
79 {
81 return Status;
82 }
83
84 /* Create the key */
85 ParentHandle = KeyHandle;
87 &KeyName,
89 ParentHandle,
90 NULL);
94 0,
95 NULL,
96 0,
98 NtClose(ParentHandle);
99
100 /* Fail if the key couldn't be created, and make sure it's a new key */
101 if (!NT_SUCCESS(Status)) return Status;
103 }
104
105 /* Setup the component information key */
106 RtlInitUnicodeString(&ValueName, L"Component Information");
108 &ValueName,
109 0,
111 &Component->Flags,
113 ConfigurationDataLength) -
115 if (!NT_SUCCESS(Status))
116 {
117 /* Fail */
119 return Status;
120 }
121
122 /* Check if we have an identifier */
123 if (Component->IdentifierLength)
124 {
125 /* Build the string and convert it to Unicode */
126 RtlInitUnicodeString(&ValueName, L"Identifier");
127 RtlInitAnsiString(&TempString, Component->Identifier);
129 &TempString,
130 TRUE);
131 if (NT_SUCCESS(Status))
132 {
133 /* Save the identifier in the registry */
135 &ValueName,
136 0,
137 REG_SZ,
138 ValueData.Buffer,
139 ValueData.Length + sizeof(UNICODE_NULL));
141 }
142
143 /* Check for failure during conversion or registry write */
144 if (!NT_SUCCESS(Status))
145 {
146 /* Fail */
148 return Status;
149 }
150 }
151
152 /* Setup the configuration data string */
153 RtlInitUnicodeString(&ValueName, L"Configuration Data");
154
155 /* Check if we got configuration data */
156 if (CurrentEntry->ConfigurationData)
157 {
158 /* Calculate the total length and check if it fits into our buffer */
159 Length = Component->ConfigurationDataLength +
160 FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList);
162 {
163 ASSERTMSG("Component too large -- need reallocation!\n", FALSE);
164 }
165 else
166 {
167 /* Copy the data */
169 CurrentEntry->ConfigurationData,
170 Component->ConfigurationDataLength);
171 }
172 }
173 else
174 {
175 /* No configuration data, setup defaults */
179 Length = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
180 FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList);
181 }
182
183 /* Set the interface type and bus number */
186
187 /* Save the actual data */
189 &ValueName,
190 0,
193 Length);
194 if (!NT_SUCCESS(Status))
195 {
196 /* Fail */
198 }
199 else
200 {
201 /* Return the new handle */
202 *NewHandle = KeyHandle;
203 }
204
205 /* Return status */
206 return Status;
207}
208
209CODE_SEG("INIT")
211NTAPI
213 IN HANDLE ParentHandle,
216{
218 USHORT DeviceIndexTable[MaximumType + 1] = {0};
220 ULONG Bus = BusNumber, i;
222 HANDLE NewHandle;
223
224 /* Loop each entry */
225 while (CurrentEntry)
226 {
227 /* Check if this is an adapter */
228 Component = &CurrentEntry->ComponentEntry;
229 if ((Component->Class == AdapterClass) &&
230 (CurrentEntry->Parent->ComponentEntry.Class == SystemClass))
231 {
232 /* Check what kind of adapter it is */
233 switch (Component->Type)
234 {
235 /* EISA */
236 case EisaAdapter:
237 {
238 /* Adjust information */
239 Interface = Eisa;
240 Bus = CmpTypeCount[EisaAdapter]++;
241 break;
242 }
243
244 /* Turbo-channel */
245 case TcAdapter:
246 {
247 /* Adjust information */
249 Bus = CmpTypeCount[TurboChannel]++;
250 break;
251 }
252
253 /* ISA, PCI, etc. buses */
255 {
256 /* Check if we have an identifier */
257 if (Component->Identifier)
258 {
259 /* Loop each multi-function adapter type */
260 for (i = 0; CmpMultifunctionTypes[i].Identifier; i++)
261 {
262 /* Check for a name match */
264 Component->Identifier))
265 {
266 /* Match found */
267 break;
268 }
269 }
270
271 /* Adjust information */
274 }
275 break;
276 }
277
278 /* SCSI Bus */
279 case ScsiAdapter:
280 {
281 /* Adjust information */
283 Bus = CmpTypeCount[ScsiAdapter]++;
284 break;
285 }
286
287 /* Unknown */
288 default:
289 {
291 Bus = CmpUnknownBusCount++;
292 break;
293 }
294 }
295 }
296
297 /* Dump information on the component */
298
299 /* Setup the hardware node */
300 Status = CmpInitializeRegistryNode(CurrentEntry,
301 ParentHandle,
302 &NewHandle,
303 Interface,
304 Bus,
305 DeviceIndexTable);
306 if (!NT_SUCCESS(Status))
307 return Status;
308
309 /* Check for children */
310 if (CurrentEntry->Child)
311 {
312 /* Recurse child */
313 Status = CmpSetupConfigurationTree(CurrentEntry->Child,
314 NewHandle,
315 Interface,
316 Bus);
317 if (!NT_SUCCESS(Status))
318 {
319 /* Fail */
320 NtClose(NewHandle);
321 return Status;
322 }
323 }
324
325 /* Get to the next entry */
326 NtClose(NewHandle);
327 CurrentEntry = CurrentEntry->Sibling;
328 }
329
330 /* We're done */
331 return STATUS_SUCCESS;
332}
333
334CODE_SEG("INIT")
336NTAPI
338{
344
345 /* Setup the key name */
347 L"\\Registry\\Machine\\Hardware\\DeviceMap");
349 &KeyName,
351 NULL,
352 NULL);
353
354 /* Create the device map key */
358 0,
359 NULL,
360 0,
361 &Disposition);
362 if (!NT_SUCCESS(Status))
363 return Status;
365
366 /* Nobody should have created this key yet! */
368
369 /* Setup the key name */
371 L"\\Registry\\Machine\\Hardware\\Description");
373 &KeyName,
375 NULL,
376 NULL);
377
378 /* Create the description key */
382 0,
383 NULL,
384 0,
385 &Disposition);
386 if (!NT_SUCCESS(Status))
387 return Status;
388
389 /* Nobody should have created this key yet! */
391
392 /* Allocate the configuration data buffer */
395 TAG_CM);
397 {
400 }
401
402 /* Check if we got anything from NTLDR */
403 if (LoaderBlock->ConfigurationRoot)
404 {
405#ifdef _M_IX86
407
408 ConfigData = KeFindConfigurationEntry(LoaderBlock->ConfigurationRoot,
411 NULL);
412 if (ConfigData)
413 {
414 /* Check if the system identifier starts with a known string.
415 * Set kernel flags and initialize variables accordingly. */
416 if (!strncmp(ConfigData->ComponentEntry.Identifier,
417 "NEC PC-98",
418 sizeof("NEC PC-98") - 1))
419 {
420 /* Running on a NEC PC-9800 or compatible */
421 KeI386MachineType |= 0x100; /* Should probably be one of MACHINE_TYPE_* consts */
422 SharedUserData->AlternativeArchitecture = NEC98x86;
423 }
424 }
425#endif
426
427 /* Setup the configuration tree */
428 Status = CmpSetupConfigurationTree(LoaderBlock->ConfigurationRoot,
429 KeyHandle,
431 -1);
432 }
433 else
434 {
435 /* Nothing else to do */
437 }
438
439 /* Free the buffer, close our handle and return status */
442 return Status;
443}
#define CODE_SEG(...)
#define REG_SZ
Definition: layer.c:22
@ Identifier
Definition: asmpp.cpp:95
LONG NTSTATUS
Definition: precomp.h:26
@ ScsiAdapter
Definition: arcname.c:40
@ EisaAdapter
Definition: arcname.c:39
#define _stricmp
Definition: cat.c:22
Definition: bufpool.h:45
CMP_MF_TYPE CmpMultifunctionTypes[]
UNICODE_STRING CmTypeName[]
NTSTATUS NTAPI CmpInitializeRegistryNode(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, IN HANDLE NodeHandle, OUT PHANDLE NewHandle, IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PUSHORT DeviceIndexTable)
Definition: cmconfig.c:20
NTSTATUS NTAPI CmpInitializeHardwareConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: cmconfig.c:337
NTSTATUS NTAPI CmpSetupConfigurationTree(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, IN HANDLE ParentHandle, IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber)
Definition: cmconfig.c:212
USHORT CmpUnknownBusCount
Definition: cmdata.c:68
PCM_FULL_RESOURCE_DESCRIPTOR CmpConfigurationData
Definition: cmdata.c:37
ULONG CmpTypeCount[MaximumType+1]
Definition: cmdata.c:69
ULONG CmpConfigurationAreaSize
Definition: cmdata.c:36
#define TAG_CM
Definition: cmlib.h:219
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
_ACRTIMP int __cdecl strncmp(const char *, const char *, size_t)
Definition: string.c:3335
#define L(x)
Definition: resources.c:13
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:24
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
_In_ PKSNODE_CREATE _In_ ACCESS_MASK _Out_ PHANDLE NodeHandle
Definition: ks.h:4548
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
NTSYSAPI NTSTATUS NTAPI RtlIntegerToChar(_In_ ULONG Value, _In_ ULONG Base, _In_ ULONG Length, _Out_ PCHAR String)
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Definition: ntapi.c:859
#define REG_BINARY
Definition: nt_native.h:1499
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define KEY_READ
Definition: nt_native.h:1026
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1087
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3429
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define KEY_WRITE
Definition: nt_native.h:1034
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define REG_FULL_RESOURCE_DESCRIPTOR
Definition: nt_native.h:1506
NTSTATUS NTAPI NtCreateKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG TitleIndex, IN PUNICODE_STRING Class OPTIONAL, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
Definition: ntapi.c:240
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
ULONG KeI386MachineType
Definition: cpu.c:27
PCONFIGURATION_COMPONENT_DATA NTAPI KeFindConfigurationEntry(_In_ PCONFIGURATION_COMPONENT_DATA Child, _In_ CONFIGURATION_CLASS Class, _In_ CONFIGURATION_TYPE Type, _In_opt_ PULONG ComponentKey)
Definition: config.c:108
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
_In_ ULONG BusNumber
Definition: pciidex.h:65
short WCHAR
Definition: pedump.c:58
unsigned short USHORT
Definition: pedump.c:61
char CHAR
Definition: pedump.c:57
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
@ Eisa
Definition: restypes.h:124
@ InterfaceTypeUndefined
Definition: restypes.h:121
@ TurboChannel
Definition: restypes.h:126
@ Internal
Definition: restypes.h:122
enum _INTERFACE_TYPE INTERFACE_TYPE
@ SystemClass
Definition: arc.h:99
@ AdapterClass
Definition: arc.h:102
@ MultiFunctionAdapter
Definition: arc.h:125
@ ArcSystem
Definition: arc.h:113
@ TcAdapter
Definition: arc.h:122
@ MaximumType
Definition: arc.h:154
#define SharedUserData
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _countof(array)
Definition: sndvol32.h:70
USHORT Count
Definition: cm.h:455
PCHAR Identifier
Definition: cm.h:453
USHORT InterfaceType
Definition: cm.h:454
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: restypes.h:145
INTERFACE_TYPE InterfaceType
Definition: restypes.h:143
CONFIGURATION_COMPONENT ComponentEntry
Definition: arc.h:287
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
uint16_t * PUSHORT
Definition: typedefs.h:56
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID InterfaceType
Definition: wdffdo.h:463
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
@ NEC98x86
Definition: wdm.h:15
_In_ ULONG Component
Definition: potypes.h:499