Source code of Windows XP (NT5)
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.

406 lines
9.9 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. arcdtect.c
  5. Abstract:
  6. Provides HAL and SCSI detection for ARC-compliant machines.
  7. Author:
  8. John Vert (jvert) 21-Oct-1993
  9. Revision History:
  10. --*/
  11. #include "setupldr.h"
  12. #include <stdlib.h>
  13. #if defined(_IA64_)
  14. //
  15. // Stuff used for detecting video
  16. //
  17. #define MAX_VIDEO_ADAPTERS 5
  18. ULONG VideoAdapterCount;
  19. PCONFIGURATION_COMPONENT_DATA VideoAdapter[MAX_VIDEO_ADAPTERS];
  20. VOID
  21. DecideVideoAdapter(
  22. VOID
  23. );
  24. BOOLEAN FoundUnknownScsi;
  25. //
  26. // private function prototypes
  27. //
  28. BOOLEAN
  29. EnumerateSCSIAdapters(
  30. IN PCONFIGURATION_COMPONENT_DATA ConfigData
  31. );
  32. BOOLEAN
  33. EnumerateVideoAdapters(
  34. IN PCONFIGURATION_COMPONENT_DATA ConfigData
  35. );
  36. VOID
  37. SlDetectScsi(
  38. IN PSETUP_LOADER_BLOCK SetupBlock
  39. )
  40. /*++
  41. Routine Description:
  42. Detects SCSI adapters on an ARC machine by walking the ARC firmware tree.
  43. Fills in the appropriate entries in the setuploaderblock
  44. Arguments:
  45. SetupBlock - Supplies a pointer to the setup loader block.
  46. Return Value:
  47. None.
  48. --*/
  49. {
  50. FoundUnknownScsi = FALSE;
  51. BlSearchConfigTree(BlLoaderBlock->ConfigurationRoot,
  52. AdapterClass,
  53. ScsiAdapter,
  54. (ULONG)-1,
  55. EnumerateSCSIAdapters);
  56. if (FoundUnknownScsi) {
  57. //
  58. // We found at least one scsi device we didn't recognize,
  59. // so force the OEM selection menu.
  60. //
  61. PromptOemScsi=TRUE;
  62. }
  63. SetupBlock->ScalarValues.LoadedScsi = 1;
  64. }
  65. BOOLEAN
  66. EnumerateSCSIAdapters(
  67. IN PCONFIGURATION_COMPONENT_DATA ConfigData
  68. )
  69. /*++
  70. Routine Description:
  71. Callback function for enumerating SCSI adapters in the ARC tree.
  72. Adds the SCSI adapter that was found to the list of detected SCSI devices.
  73. Arguments:
  74. ConfigData - Supplies a pointer to the ARC node of the SCSI adapter.
  75. Return Value:
  76. TRUE - continue searching
  77. FALSE - some error, abort the search
  78. --*/
  79. {
  80. PDETECTED_DEVICE ScsiDevice;
  81. PCHAR AdapterName;
  82. ULONG Ordinal;
  83. PCHAR ScsiFileName;
  84. PTCHAR ScsiDescription;
  85. SCSI_INSERT_STATUS sis;
  86. AdapterName = SlSearchSection("Map.SCSI",ConfigData->ComponentEntry.Identifier);
  87. if (AdapterName==NULL) {
  88. //
  89. // We found an adapter in the ARC tree, but it is not one of the ones
  90. // specified in our INF file, so trigger the prompt for an OEM driver
  91. // disk.
  92. //
  93. FoundUnknownScsi = TRUE;
  94. return(TRUE);
  95. }
  96. //
  97. // Find this adapter's ordinal within the Scsi.Load section of txtsetup.sif
  98. //
  99. Ordinal = SlGetSectionKeyOrdinal(InfFile, "Scsi.Load", AdapterName);
  100. if(Ordinal == (ULONG)-1) {
  101. FoundUnknownScsi = TRUE;
  102. return(TRUE);
  103. }
  104. //
  105. // Find the driver filename
  106. //
  107. ScsiFileName = SlGetSectionKeyIndex(InfFile,
  108. "Scsi.Load",
  109. AdapterName,
  110. SIF_FILENAME_INDEX);
  111. if(!ScsiFileName) {
  112. FoundUnknownScsi = TRUE;
  113. return(TRUE);
  114. }
  115. //
  116. // Create a new detected device entry.
  117. //
  118. if((sis = SlInsertScsiDevice(Ordinal, &ScsiDevice)) == ScsiInsertError) {
  119. SlFriendlyError(ENOMEM, "SCSI detection", 0, NULL);
  120. return(FALSE);
  121. }
  122. if(sis == ScsiInsertExisting) {
  123. #if DBG
  124. //
  125. // Sanity check to make sure we're talking about the same driver
  126. //
  127. if(_stricmp(ScsiDevice->BaseDllName, ScsiFileName)) {
  128. SlError(400);
  129. return FALSE;
  130. }
  131. #endif
  132. } else {
  133. //
  134. // Find the driver description
  135. //
  136. #ifdef UNICODE
  137. ScsiDescription = SlGetIniValueW(
  138. #else
  139. ScsiDescription = SlGetIniValue(
  140. #endif
  141. InfFile,
  142. "SCSI",
  143. AdapterName,
  144. AdapterName);
  145. ScsiDevice->IdString = AdapterName;
  146. ScsiDevice->Description = ScsiDescription;
  147. ScsiDevice->ThirdPartyOptionSelected = FALSE;
  148. ScsiDevice->FileTypeBits = 0;
  149. ScsiDevice->Files = NULL;
  150. ScsiDevice->BaseDllName = ScsiFileName;
  151. }
  152. return(TRUE);
  153. }
  154. VOID
  155. SlDetectVideo(
  156. IN PSETUP_LOADER_BLOCK SetupBlock
  157. )
  158. /*++
  159. Routine Description:
  160. Detects video adapters on an ARC machine by walking the ARC firmware tree.
  161. Fills in the appropriate entries in the setuploaderblock
  162. Arguments:
  163. SetupBlock - Supplies a pointer to the setup loader block.
  164. Return Value:
  165. None.
  166. --*/
  167. {
  168. //
  169. // On arc machines, there is no default video type.
  170. //
  171. SetupBlock->VideoDevice.Next = NULL;
  172. SetupBlock->VideoDevice.IdString = NULL;
  173. SetupBlock->VideoDevice.ThirdPartyOptionSelected = FALSE;
  174. SetupBlock->VideoDevice.FileTypeBits = 0;
  175. SetupBlock->VideoDevice.Files = NULL;
  176. SetupBlock->VideoDevice.BaseDllName = NULL;
  177. SetupBlock->Monitor = NULL;
  178. SetupBlock->MonitorId = NULL;
  179. BlSearchConfigTree(BlLoaderBlock->ConfigurationRoot,
  180. ControllerClass,
  181. DisplayController,
  182. (ULONG)-1,
  183. EnumerateVideoAdapters);
  184. DecideVideoAdapter();
  185. }
  186. BOOLEAN
  187. EnumerateVideoAdapters(
  188. IN PCONFIGURATION_COMPONENT_DATA ConfigData
  189. )
  190. /*++
  191. Routine Description:
  192. Callback function for enumerating video adapters in the ARC tree.
  193. Adds the video adapter that was found to the setup block.
  194. Arguments:
  195. ConfigData - Supplies a pointer to the ARC node of the display adapter.
  196. Return Value:
  197. TRUE - continue searching
  198. FALSE - some error, abort the search
  199. --*/
  200. {
  201. //
  202. // Just remember this guy for later.
  203. //
  204. if(VideoAdapterCount < MAX_VIDEO_ADAPTERS) {
  205. VideoAdapter[VideoAdapterCount++] = ConfigData;
  206. }
  207. return(TRUE);
  208. }
  209. VOID
  210. DecideVideoAdapter(
  211. VOID
  212. )
  213. {
  214. IN PCONFIGURATION_COMPONENT_DATA ConfigData;
  215. PCHAR AdapterName,MonitorId;
  216. PCONFIGURATION_COMPONENT_DATA MonitorData;
  217. PMONITOR_CONFIGURATION_DATA Monitor;
  218. CHAR ArcPath[256];
  219. CHAR ConsoleOut[256];
  220. PCHAR p,q;
  221. ULONG u;
  222. if(VideoAdapterCount) {
  223. //
  224. // The first thing we want to do is to see whether any of the
  225. // adapters we found match the value of the CONSOLEOUT nvram var.
  226. // If so then use that node for detection. Before comparing we have to
  227. // change all instances of () to (0) in the value of CONSOLEOUT.
  228. //
  229. ConfigData = NULL;
  230. if(p = ArcGetEnvironmentVariable("CONSOLEOUT")) {
  231. strncpy(ArcPath,p,sizeof(ArcPath)-1);
  232. ArcPath[sizeof(ArcPath)-1] = 0;
  233. ConsoleOut[0] = 0;
  234. for(p=ArcPath; q=strstr(p,"()"); p=q+2) {
  235. *q = 0;
  236. strcat(ConsoleOut,p);
  237. strcat(ConsoleOut,"(0)");
  238. }
  239. strcat(ConsoleOut,p);
  240. //
  241. // Finally, we need to truncate the consoleout variable after
  242. // the video adapter, if any.
  243. //
  244. _strlwr(ConsoleOut);
  245. if(p = strstr(ConsoleOut,")video(")) {
  246. *(p+sizeof(")video(")+1) = 0;
  247. }
  248. for(u=0; u<VideoAdapterCount; u++) {
  249. ArcPath[0] = 0;
  250. BlGetPathnameFromComponent(VideoAdapter[u],ArcPath);
  251. if(!_stricmp(ConsoleOut,ArcPath)) {
  252. ConfigData = VideoAdapter[u];
  253. break;
  254. }
  255. }
  256. }
  257. //
  258. // If we didn't find a match for CONSOLEOUT then use the last node
  259. // we found in the tree scan.
  260. //
  261. if(!ConfigData) {
  262. ConfigData = VideoAdapter[VideoAdapterCount-1];
  263. }
  264. AdapterName = SlSearchSection("Map.Display",ConfigData->ComponentEntry.Identifier);
  265. if (AdapterName==NULL) {
  266. //
  267. // We found a display adapter in the ARC tree, but it is not one of the ones
  268. // specified in our INF file, so trigger the prompt for an OEM driver
  269. // disk.
  270. //
  271. PromptOemVideo = TRUE;
  272. return;
  273. }
  274. BlLoaderBlock->SetupLoaderBlock->VideoDevice.IdString = AdapterName;
  275. BlLoaderBlock->SetupLoaderBlock->VideoDevice.Description = NULL;
  276. BlLoaderBlock->SetupLoaderBlock->VideoDevice.ThirdPartyOptionSelected = FALSE;
  277. BlLoaderBlock->SetupLoaderBlock->VideoDevice.FileTypeBits = 0;
  278. BlLoaderBlock->SetupLoaderBlock->VideoDevice.Files = NULL;
  279. BlLoaderBlock->SetupLoaderBlock->VideoDevice.BaseDllName = NULL;
  280. //
  281. // If there is a monitor peripheral associated with this device,
  282. // capture its configuration data. Otherwise, let Setup assume an
  283. // appropriate default.
  284. //
  285. MonitorData = ConfigData->Child;
  286. if (MonitorData==NULL) {
  287. BlLoaderBlock->SetupLoaderBlock->Monitor = NULL;
  288. BlLoaderBlock->SetupLoaderBlock->MonitorId = NULL;
  289. } else {
  290. Monitor = BlAllocateHeap(MonitorData->ComponentEntry.ConfigurationDataLength);
  291. if (Monitor==NULL) {
  292. SlFriendlyError(ENOMEM, "video detection", 0, NULL);
  293. return;
  294. }
  295. MonitorId = BlAllocateHeap(MonitorData->ComponentEntry.IdentifierLength+1);
  296. if (MonitorId==NULL) {
  297. SlFriendlyError(ENOMEM, "video detection", 0, NULL);
  298. return;
  299. }
  300. strncpy(MonitorId,
  301. MonitorData->ComponentEntry.Identifier,
  302. MonitorData->ComponentEntry.IdentifierLength);
  303. MonitorId[MonitorData->ComponentEntry.IdentifierLength] = 0;
  304. RtlCopyMemory((PVOID)Monitor,
  305. MonitorData->ConfigurationData,
  306. MonitorData->ComponentEntry.ConfigurationDataLength);
  307. BlLoaderBlock->SetupLoaderBlock->Monitor = Monitor;
  308. BlLoaderBlock->SetupLoaderBlock->MonitorId = MonitorId;
  309. }
  310. }
  311. }
  312. #endif