2 * PROJECT: ReactOS PCI Bus Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/bus/pci/pci/id.c
5 * PURPOSE: PCI Device Identification
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
15 /* GLOBALS ********************************************************************/
17 /* FUNCTIONS ******************************************************************/
21 PciGetDescriptionMessage(IN ULONG Identifier
,
24 PMESSAGE_RESOURCE_ENTRY Entry
;
26 PWCHAR Description
, Buffer
;
27 ANSI_STRING MessageString
;
28 UNICODE_STRING UnicodeString
;
31 /* Find the message identifier in the message table */
32 MessageString
.Buffer
= NULL
;
33 Status
= RtlFindMessage(PciDriverObject
->DriverStart
,
34 11, // RT_MESSAGETABLE
38 if (!NT_SUCCESS(Status
)) return NULL
;
40 /* Check if the resource data is Unicode or ANSI */
41 if (Entry
->Flags
& MESSAGE_RESOURCE_UNICODE
)
43 /* Subtract one space for the end-of-message terminator */
44 TextLength
= Entry
->Length
-
45 FIELD_OFFSET(MESSAGE_RESOURCE_ENTRY
, Text
) -
49 Description
= (PWCHAR
)Entry
->Text
;
51 /* Validate valid message length, ending with a newline character */
52 ASSERT(TextLength
> 1);
53 ASSERT(Description
[TextLength
/ sizeof(WCHAR
) == L
'\n']);
55 /* Allocate the buffer to hold the message string */
56 Buffer
= ExAllocatePoolWithTag(PagedPool
, TextLength
, 'BicP');
57 if (!Buffer
) return NULL
;
59 /* Copy the message, minus the newline character, and terminate it */
60 RtlCopyMemory(Buffer
, Entry
->Text
, TextLength
- 1);
61 Buffer
[TextLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
63 /* Return the length to the caller */
64 if (Length
) *Length
= UnicodeString
.Length
;
68 /* Initialize the entry as a string */
69 RtlInitAnsiString(&MessageString
, (PCHAR
)Entry
->Text
);
71 /* Remove the newline character */
72 MessageString
.Length
-= sizeof(CHAR
);
74 /* Convert it to Unicode */
75 RtlAnsiStringToUnicodeString(&UnicodeString
, &MessageString
, TRUE
);
76 Buffer
= UnicodeString
.Buffer
;
78 /* Return the length to the caller */
79 if (Length
) *Length
= UnicodeString
.Length
;
82 /* Return the message buffer to the caller */
88 PciGetDeviceDescriptionMessage(IN UCHAR BaseClass
,
94 /* The message identifier in the table is encoded based on the PCI class */
95 Identifier
= (BaseClass
<< 8) | SubClass
;
97 /* Go grab the description message for this device */
98 Message
= PciGetDescriptionMessage(Identifier
, NULL
);
101 /* It wasn't found, allocate a buffer for a generic description */
102 Message
= ExAllocatePoolWithTag(PagedPool
, sizeof(L
"PCI Device"), 'bicP');
103 if (Message
) RtlCopyMemory(Message
, L
"PCI Device", sizeof(L
"PCI Device"));
106 /* Return the description message */