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.

798 lines
16 KiB

  1. /**
  2. *** Copyright (C) 1996-97 Intel Corporation. All rights reserved.
  3. ***
  4. *** The information and source code contained herein is the exclusive
  5. *** property of Intel Corporation and may not be disclosed, examined
  6. *** or reproduced in whole or in part without explicit written authorization
  7. *** from the company.
  8. **/
  9. /*++
  10. Copyright (c) 1995 Intel Corporation
  11. Module Name:
  12. simkrnl.c
  13. Abstract:
  14. This module implements the kernel support routines for the HAL DLL.
  15. Author:
  16. 14-Apr-1995
  17. Environment:
  18. Kernel mode
  19. Revision History:
  20. --*/
  21. #include "halp.h"
  22. extern VOID HalpCalibrateTB();
  23. static short HalpOwnDisplay = TRUE;
  24. ULONG
  25. HalpNoBusData (
  26. IN PVOID BusHandler,
  27. IN PVOID RootHandler,
  28. IN ULONG SlotNumber,
  29. IN PVOID Buffer,
  30. IN ULONG Offset,
  31. IN ULONG Length
  32. );
  33. BOOLEAN
  34. HalAllProcessorsStarted (
  35. VOID
  36. )
  37. /*++
  38. Routine Description:
  39. This function returns TRUE if all the processors in the system started
  40. successfully.
  41. Arguments:
  42. None.
  43. Return Value:
  44. Returns TRUE.
  45. --*/
  46. {
  47. return TRUE;
  48. }
  49. BOOLEAN
  50. HalStartNextProcessor (
  51. IN PLOADER_PARAMETER_BLOCK pLoaderBlock,
  52. IN PKPROCESSOR_STATE pProcessorState
  53. )
  54. /*++
  55. Routine Description:
  56. This function always returns FALSE on a uni-processor platform
  57. because there is no second processor to be started.
  58. Arguments:
  59. pLoaderBlock - Loader Block.
  60. pProcessorState - A description of the processor state.
  61. Return Value:
  62. Returns TRUE.
  63. --*/
  64. {
  65. //
  66. // no other processors
  67. //
  68. return FALSE;
  69. }
  70. VOID
  71. HalRequestIpi (
  72. IN ULONG Mask
  73. )
  74. /*++
  75. Routine Description:
  76. This function does nothing on a uni-processor platform.
  77. Arguments:
  78. Mask - A mask that specifies the target processor(s) to which an
  79. IPI is to be sent.
  80. Return Value:
  81. None.
  82. --*/
  83. {
  84. //
  85. // no other processors.
  86. //
  87. return;
  88. }
  89. BOOLEAN
  90. HalMakeBeep (
  91. IN ULONG Frequency
  92. )
  93. /*++
  94. Routine Description:
  95. This function calls SSC function SscMakeBeep() to make a beep sound
  96. when the specified frequency has a non-zero value.
  97. Arguments:
  98. Frequency - the frequency of the sound to be made.
  99. Return Value:
  100. None.
  101. --*/
  102. {
  103. if (Frequency > 0) {
  104. SscMakeBeep(Frequency);
  105. }
  106. return TRUE;
  107. }
  108. BOOLEAN
  109. HalQueryRealTimeClock (
  110. OUT PTIME_FIELDS TimeFields
  111. )
  112. /*++
  113. Routine Description:
  114. This function calls the SSC function SscQueryRealTimeClock to
  115. get the real time clock data from the host. This function always
  116. succeeds in the simulation environment and should return TRUE at
  117. all times.
  118. Arguments:
  119. TimeFields - Real Time Clock Data
  120. Return Value:
  121. Returns TRUE if successful; otherwise, FALSE.
  122. --*/
  123. {
  124. PMDL Mdl;
  125. SSC_TIME_FIELDS SscTimeFields;
  126. PHYSICAL_ADDRESS physicalAddress;
  127. /*
  128. Mdl = MmCreateMdl (NULL, TimeFields, sizeof(TIME_FIELDS));
  129. MmProbeAndLockPages (Mdl, KernelMode, IoModifyAccess);
  130. */
  131. physicalAddress = MmGetPhysicalAddress (&SscTimeFields);
  132. SscQueryRealTimeClock((PVOID)physicalAddress.QuadPart);
  133. TimeFields->Year = (USHORT)SscTimeFields.Year;
  134. TimeFields->Month = (USHORT)SscTimeFields.Month;
  135. TimeFields->Day = (USHORT)SscTimeFields.Day;
  136. TimeFields->Hour = (USHORT)SscTimeFields.Hour;
  137. TimeFields->Minute = (USHORT)SscTimeFields.Minute;
  138. TimeFields->Second = (USHORT)SscTimeFields.Second;
  139. TimeFields->Milliseconds = (USHORT)SscTimeFields.Milliseconds;
  140. TimeFields->Weekday = (USHORT)SscTimeFields.WeekDay;
  141. /*
  142. MmUnlockPages (Mdl);
  143. */
  144. return TRUE;
  145. }
  146. BOOLEAN
  147. HalSetRealTimeClock (
  148. IN PTIME_FIELDS TimeFields
  149. )
  150. /*++
  151. Routine Description:
  152. This function calls the SSC function SscQueryRealTimeClock to
  153. get the real time clock data from the host.
  154. Arguments:
  155. TimeFields - Real Time Clock Data
  156. Return Value:
  157. None.
  158. --*/
  159. {
  160. DbgPrint("HalSetRealTimeClock: Warning.\n");
  161. return TRUE;
  162. }
  163. VOID
  164. KeStallExecutionProcessor (
  165. IN ULONG MicroSeconds
  166. )
  167. /*++
  168. Routine Description:
  169. This function does nothing in the simulation environment.
  170. Arguments:
  171. MicroSeconds - Number of microseconds to stall the processor.
  172. Return Value:
  173. None.
  174. --*/
  175. {
  176. return;
  177. }
  178. VOID
  179. HalQueryDisplayParameters (
  180. OUT PULONG WidthInCharacters,
  181. OUT PULONG HeightInLines,
  182. OUT PULONG CursorColumn,
  183. OUT PULONG CursorRow
  184. )
  185. /*++
  186. Routine Description:
  187. This routine returns information about the display area and current
  188. cursor position. In the simulation environment, the function does
  189. nothing. Therefore, the kernel should either ignore the returned
  190. results or not call the function at all.
  191. Arguments:
  192. WidthInCharacter - Supplies a pointer to a varible that receives
  193. the width of the display area in characters.
  194. HeightInLines - Supplies a pointer to a variable that receives the
  195. height of the display area in lines.
  196. CursorColumn - Supplies a pointer to a variable that receives the
  197. current display column position.
  198. CursorRow - Supplies a pointer to a variable that receives the
  199. current display row position.
  200. Return Value:
  201. None.
  202. --*/
  203. {
  204. return;
  205. }
  206. VOID
  207. HalSetDisplayParameters (
  208. IN ULONG CursorColumn,
  209. IN ULONG CursorRow
  210. )
  211. /*++
  212. Routine Description:
  213. This routine does nothing in the simulation environment.
  214. Arguments:
  215. CursorColumn - Supplies the new display column position.
  216. CursorRow - Supplies a the new display row position.
  217. Return Value:
  218. None.
  219. --*/
  220. {
  221. return;
  222. }
  223. VOID
  224. HalDisplayString (
  225. PUCHAR String
  226. )
  227. /*++
  228. Routine Description:
  229. This routine calls the SSC function SscDisplayString to display
  230. the specified character string in a window.
  231. Arguments:
  232. String - Supplies a pointer to the characters that are to be displayed.
  233. Return Value:
  234. None.
  235. N.B. The string must be resident in memory or it must be paged in.
  236. --*/
  237. {
  238. PHYSICAL_ADDRESS StringBufferPtr;
  239. if (String) {
  240. StringBufferPtr = MmGetPhysicalAddress (String);
  241. if (StringBufferPtr.QuadPart != 0ULL) {
  242. SscDisplayString((PVOID)StringBufferPtr.QuadPart);
  243. }
  244. }
  245. }
  246. VOID
  247. HalAcquireDisplayOwnership (
  248. IN PHAL_RESET_DISPLAY_PARAMETERS ResetDisplayParameters
  249. )
  250. /*++
  251. Routine Description:
  252. This routine switches ownership of the display away from the HAL to
  253. the system display driver. It is called when the system has reached
  254. a point during bootstrap where it is self supporting and can output
  255. its own messages. Once ownership has passed to the system display
  256. driver any attempts to output messages using HalDisplayString must
  257. result in ownership of the display reverting to the HAL and the
  258. display hardware reinitialized for use by the HAL.
  259. Arguments:
  260. ResetDisplayParameters - if non-NULL the address of a function
  261. the hal can call to reset the video card.
  262. Return Value:
  263. None.
  264. --*/
  265. {
  266. HalpOwnDisplay = FALSE;
  267. return;
  268. }
  269. VOID
  270. HalInitializeProcessor (
  271. IN ULONG Number,
  272. IN PLOADER_PARAMETER_BLOCK LoaderBlock
  273. )
  274. /*++
  275. Routine Description:
  276. This function is called early in the initialization of the kernel
  277. to perform platform dependent initialization for each processor
  278. before the HAL Is fully functional.
  279. N.B. When this routine is called, the PCR is present but is not
  280. fully initialized.
  281. Arguments:
  282. Number - Supplies the number of the processor to initialize.
  283. Return Value:
  284. None.
  285. --*/
  286. {
  287. PCR->StallScaleFactor = 0;
  288. return;
  289. }
  290. BOOLEAN
  291. HalInitSystem (
  292. IN ULONG Phase,
  293. IN PLOADER_PARAMETER_BLOCK LoaderBlock
  294. )
  295. /*++
  296. Routine Description:
  297. This function initializes the Hardware Architecture Layer (HAL) for
  298. IA64/NT in the simulation environment.
  299. Arguments:
  300. Phase - A number that specifies the initialization phase that the
  301. kernel is in.
  302. LoaderBlock - Loader Block Data.
  303. Return Value:
  304. A value of TRUE is returned is the initialization was successfully
  305. complete. Otherwise a value of FALSE is returend.
  306. --*/
  307. {
  308. PKPRCB Prcb;
  309. Prcb = PCR->Prcb;
  310. if (Phase == 0) {
  311. //
  312. // If processor 0 is being initialized, then initialize various
  313. // variables.
  314. //
  315. if (Prcb->Number == 0) {
  316. //
  317. // Set the interval clock increment value.
  318. //
  319. HalpCalibrateTB();
  320. // *** TBD define these constants
  321. //KeSetTimeIncrement(MAXIMUM_CLOCK_INTERVAL, MINIMUM_CLOCK_INTERVAL);
  322. KeSetTimeIncrement(100000, 10000);
  323. }
  324. //
  325. // Initialize the interrupt structures
  326. //
  327. HalpInitializeInterrupts ();
  328. //
  329. // Fill in handlers for APIs which this hal supports
  330. //
  331. HalQuerySystemInformation = HaliQuerySystemInformation;
  332. HalSetSystemInformation = HaliSetSystemInformation;
  333. } else {
  334. //
  335. // Phase 1 initialization
  336. //
  337. if (Prcb->Number == 0) {
  338. //
  339. // If P0, then setup global vectors
  340. //
  341. HalpRegisterInternalBusHandlers ();
  342. }
  343. }
  344. return TRUE;
  345. }
  346. VOID
  347. HalChangeColorPage (
  348. IN PVOID NewColor,
  349. IN PVOID OldColor,
  350. IN ULONG PageFrame
  351. )
  352. /*++
  353. Routine Description:
  354. This function changes the color of a page if the old and new colors
  355. do not match.
  356. BUGBUG: For now this is a stub. Needs to be filled in.
  357. Arguments:
  358. NewColor - Supplies the page aligned virtual address of the
  359. new color of the page to change.
  360. OldColor - Supplies the page aligned virtual address of the
  361. old color of the page to change.
  362. pageFrame - Supplies the page frame number of the page that
  363. is changed.
  364. Return Value:
  365. None.
  366. --*/
  367. {
  368. return;
  369. }
  370. PBUS_HANDLER
  371. HalpAllocateBusHandler (
  372. IN INTERFACE_TYPE InterfaceType,
  373. IN BUS_DATA_TYPE BusDataType,
  374. IN ULONG BusNumber,
  375. IN INTERFACE_TYPE ParentBusInterfaceType,
  376. IN ULONG ParentBusNumber,
  377. IN ULONG BusSpecificData
  378. )
  379. /*++
  380. Routine Description:
  381. Stub function to map old style code into new HalRegisterBusHandler code.
  382. Note we can add our specific bus handler functions after this bus
  383. handler structure has been added since this is being done during
  384. hal initialization.
  385. --*/
  386. {
  387. PBUS_HANDLER Bus;
  388. //
  389. // Create bus handler - new style
  390. //
  391. HaliRegisterBusHandler (
  392. InterfaceType,
  393. BusDataType,
  394. BusNumber,
  395. ParentBusInterfaceType,
  396. ParentBusNumber,
  397. BusSpecificData,
  398. NULL,
  399. &Bus
  400. );
  401. return Bus;
  402. }
  403. ULONG
  404. HalpGetSystemInterruptVector(
  405. IN PBUS_HANDLER BusHandler,
  406. IN PBUS_HANDLER RootHandler,
  407. IN ULONG BusInterruptLevel,
  408. IN ULONG BusInterruptVector,
  409. OUT PKIRQL Irql,
  410. OUT PKAFFINITY Affinity
  411. )
  412. /*++
  413. Routine Description:
  414. Arguments:
  415. BusInterruptLevel - Supplies the bus specific interrupt level.
  416. BusInterruptVector - Supplies the bus specific interrupt vector.
  417. Irql - Returns the system request priority.
  418. Affinity - Returns the system wide irq affinity.
  419. Return Value:
  420. Returns the system interrupt vector corresponding to the specified device.
  421. --*/
  422. {
  423. //
  424. // Just return the passed parameters.
  425. //
  426. *Irql = (KIRQL) BusInterruptLevel;
  427. *Affinity = 1;
  428. return( BusInterruptLevel << VECTOR_IRQL_SHIFT );
  429. }
  430. BOOLEAN
  431. HalpTranslateSystemBusAddress(
  432. IN PBUS_HANDLER BusHandler,
  433. IN PBUS_HANDLER RootHandler,
  434. IN PHYSICAL_ADDRESS BusAddress,
  435. IN OUT PULONG AddressSpace,
  436. OUT PPHYSICAL_ADDRESS TranslatedAddress
  437. )
  438. /*++
  439. Routine Description:
  440. This function translates a bus-relative address space and address into
  441. a system physical address.
  442. Arguments:
  443. BusAddress - Supplies the bus-relative address
  444. AddressSpace - Supplies the address space number.
  445. Returns the host address space number.
  446. AddressSpace == 0 => memory space
  447. AddressSpace == 1 => I/O space
  448. TranslatedAddress - Supplies a pointer to return the translated address
  449. Return Value:
  450. A return value of TRUE indicates that a system physical address
  451. corresponding to the supplied bus relative address and bus address
  452. number has been returned in TranslatedAddress.
  453. A return value of FALSE occurs if the translation for the address was
  454. not possible
  455. --*/
  456. {
  457. *TranslatedAddress = BusAddress;
  458. return TRUE;
  459. }
  460. BOOLEAN
  461. HalpTranslateIsaBusAddress(
  462. IN PBUS_HANDLER BusHandler,
  463. IN PBUS_HANDLER RootHandler,
  464. IN PHYSICAL_ADDRESS BusAddress,
  465. IN OUT PULONG AddressSpace,
  466. OUT PPHYSICAL_ADDRESS TranslatedAddress
  467. )
  468. /*++
  469. Routine Description:
  470. This function translates a bus-relative address space and address into
  471. a system physical address.
  472. Arguments:
  473. BusAddress - Supplies the bus-relative address
  474. AddressSpace - Supplies the address space number.
  475. Returns the host address space number.
  476. AddressSpace == 0 => memory space
  477. AddressSpace == 1 => I/O space
  478. TranslatedAddress - Supplies a pointer to return the translated address
  479. Return Value:
  480. A return value of TRUE indicates that a system physical address
  481. corresponding to the supplied bus relative address and bus address
  482. number has been returned in TranslatedAddress.
  483. A return value of FALSE occurs if the translation for the address was
  484. not possible
  485. --*/
  486. {
  487. BOOLEAN Status;
  488. //
  489. // Translated normally
  490. //
  491. Status = HalpTranslateSystemBusAddress (
  492. BusHandler,
  493. RootHandler,
  494. BusAddress,
  495. AddressSpace,
  496. TranslatedAddress
  497. );
  498. return Status;
  499. }
  500. VOID
  501. HalpRegisterInternalBusHandlers (
  502. VOID
  503. )
  504. {
  505. PBUS_HANDLER Bus;
  506. if (KeGetCurrentPrcb()->Number) {
  507. // only need to do this once
  508. return ;
  509. }
  510. //
  511. // Initalize BusHandler data before registering any handlers
  512. //
  513. HalpInitBusHandler ();
  514. //
  515. // Build internal-bus 0, or system level bus
  516. //
  517. Bus = HalpAllocateBusHandler (
  518. Internal,
  519. ConfigurationSpaceUndefined,
  520. 0, // Internal BusNumber 0
  521. InterfaceTypeUndefined, // no parent bus
  522. 0,
  523. 0 // no bus specfic data
  524. );
  525. Bus->GetInterruptVector = HalpGetSystemInterruptVector;
  526. Bus->TranslateBusAddress = HalpTranslateSystemBusAddress;
  527. //
  528. // Build Isa/Eisa bus #0
  529. //
  530. #if 0
  531. Bus = HalpAllocateBusHandler (Eisa, EisaConfiguration, 0, Internal, 0, 0);
  532. Bus->GetBusData = HalpGetEisaData;
  533. Bus->GetInterruptVector = HalpGetEisaInterruptVector;
  534. Bus->AdjustResourceList = HalpAdjustEisaResourceList;
  535. Bus->TranslateBusAddress = HalpTranslateEisaBusAddress;
  536. #endif
  537. Bus = HalpAllocateBusHandler (Isa, ConfigurationSpaceUndefined, 0, Internal, 0,
  538. 0);
  539. Bus->GetBusData = HalpNoBusData;
  540. Bus->TranslateBusAddress = HalpTranslateIsaBusAddress;
  541. }