Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. pcipath.c
  5. Abstract:
  6. This module contains functions for handling our Pci device path strings
  7. Author:
  8. Brandon Allsop (BrandonA)
  9. Revision History:
  10. --*/
  11. #include "pch.h"
  12. #define WCharToLower(ch) \
  13. if (ch >= 'A' && ch <= 'Z') { \
  14. ch += 'a' - 'A'; \
  15. }
  16. USHORT
  17. SoftPCIStringToUSHORT(
  18. IN PWCHAR String
  19. );
  20. PWCHAR
  21. SoftPCIGetNextSlotFromPath(
  22. IN PWCHAR PciPath,
  23. OUT PSOFTPCI_SLOT Slot
  24. )
  25. /*++
  26. Routine Description:
  27. This function takes a PCIPATH and parses out each individual SOFTPCI_SLOT
  28. Arguments:
  29. PciPath - Path to device. Syntax is FFXX\DEVFUNC\DEVFUNC\....
  30. Slot - Slot value that is filled in
  31. Return Value:
  32. Pointer to the beginning of the next Slot in the Path
  33. --*/
  34. {
  35. WCHAR slotString[10];
  36. PWCHAR pciSlot, pciPath;
  37. ASSERT(PciPath != NULL);
  38. RtlZeroMemory(slotString, sizeof(slotString));
  39. SoftPCIDbgPrint(
  40. SOFTPCI_FIND_DEVICE,
  41. "SOFTPCI: GetNextSlotFromPath - \"%ws\"\n",
  42. PciPath
  43. );
  44. pciSlot = slotString;
  45. pciPath = PciPath;
  46. while (*pciPath != '\\'){
  47. if (*pciPath == 0) {
  48. break;
  49. }
  50. *pciSlot = *pciPath;
  51. pciSlot++;
  52. pciPath++;
  53. }
  54. Slot->AsUSHORT = SoftPCIStringToUSHORT(slotString);
  55. if (*pciPath == 0) {
  56. //
  57. // We are at the end of our path
  58. //
  59. pciPath = NULL;
  60. }else{
  61. pciPath++;
  62. }
  63. return pciPath;
  64. }
  65. USHORT
  66. SoftPCIGetTargetSlotFromPath(
  67. IN PWCHAR PciPath
  68. )
  69. /*++
  70. Routine Description:
  71. This function takes a PCIPATH and converts a given Slot from string to number
  72. Arguments:
  73. PciPath - Path to device. Syntax is FFXX\DEVFUNC\DEVFUNC\....
  74. Return Value:
  75. USHORT or (SOFTPCI_SLOT) that was converted from the string
  76. --*/
  77. {
  78. ULONG slotLength;
  79. PWCHAR slotString;
  80. slotLength = (ULONG) wcslen(PciPath);
  81. slotString = PciPath + slotLength;
  82. while (*slotString != '\\') {
  83. slotString--;
  84. }
  85. return SoftPCIStringToUSHORT(slotString+1);
  86. }
  87. USHORT
  88. SoftPCIStringToUSHORT(
  89. IN PWCHAR String
  90. )
  91. /*++
  92. Routine Description:
  93. This function takes a string and manually converts it to a USHORT number. This
  94. was needed because there doesnt appear to be a kernel mode runtime that will do
  95. this at any IRQL.
  96. Arguments:
  97. String - String to convert
  98. Return Value:
  99. USHORT number converted
  100. --*/
  101. {
  102. WCHAR numbers[] = L"0123456789abcdef";
  103. PWCHAR p1, p2;
  104. USHORT convertedValue = 0;
  105. BOOLEAN converted = FALSE;
  106. SoftPCIDbgPrint(
  107. SOFTPCI_FIND_DEVICE,
  108. "SOFTPCI: StringToUSHORT - \"%ws\"\n",
  109. String
  110. );
  111. p1 = numbers;
  112. p2 = String;
  113. while (*p2) {
  114. //
  115. // Ensure our hex letters are lowercase
  116. //
  117. WCharToLower(*p2);
  118. while (*p1 && (converted == FALSE)) {
  119. if (*p1 == *p2) {
  120. //
  121. // Shift anything we already have aside to make room
  122. // for the next digit
  123. //
  124. convertedValue <<= 4;
  125. convertedValue |= (((UCHAR)(p1 - numbers)) & 0x0f);
  126. converted = TRUE;
  127. }
  128. p1++;
  129. }
  130. if (converted == FALSE) {
  131. //
  132. // Encountered something we couldnt convert. Return what we have
  133. //
  134. return convertedValue;
  135. }
  136. p2++;
  137. //
  138. // reset everything
  139. //
  140. p1 = numbers;
  141. converted = FALSE;
  142. }
  143. return convertedValue;
  144. }