reactos操作系统实现(108)
AtapiHwInitialize函數初始化不是ATAPT設備,設置它支持多塊傳送。接著判斷那些設備是CD-ROM設備,還清除忙狀態。具體實現代碼如下:
#001? BOOLEAN
#002? NTAPI
#003? AtapiHwInitialize(
#004????? IN PVOID HwDeviceExtension
#005????? )
#006?
#007? /*++
#008?
#009? Routine Description:
#010?
#011? Arguments:
#012?
#013????? HwDeviceExtension - HBA miniport driver's adapter data storage
#014?
#015? Return Value:
#016?
#017????? TRUE - if initialization successful.
#018????? FALSE - if initialization unsuccessful.
#019?
#020? --*/
#021?
#022? {
#023????? PHW_DEVICE_EXTENSION deviceExtension = HwDeviceExtension;
#024????? PIDE_REGISTERS_1???? baseIoAddress;
#025????? ULONG i;
#026????? UCHAR statusByte, errorByte;
#027?
#028?
?
對于兩個通道4個IDE控制器進行初始化。
#029????? for (i = 0; i < 4; i++) {
?
如果IDE的設備存在,就進行處理。
#030????????? if (deviceExtension->DeviceFlags[i] & DFLAGS_DEVICE_PRESENT) {
#031?
?
如果這個設備不是ATAPI設備,就進入下面初始化。
#032????????????? if (!(deviceExtension->DeviceFlags[i] & DFLAGS_ATAPI_DEVICE)) {
#033?
#034????????????????? //
#035????????????????? // Enable media status notification
#036????????????????? //
#037?
?
獲取基地址。
#038????????????????? baseIoAddress = deviceExtension->BaseIoAddress1[i >> 1];
#039?
?
設置媒體感知。
#040????????????????? IdeMediaStatus(TRUE,HwDeviceExtension,i);
#041?
?
如果支持多塊傳送,就設置多塊傳送參數。
#042????????????????? //
#043????????????????? // If supported, setup Multi-block transfers.
#044????????????????? //
#045????????????????? if (deviceExtension->MaximumBlockXfer[i]) {
#046?
#047????????????????????? //
#048????????????????????? // Select the device.
#049????????????????????? //
#050?
#051?????????????? ???????ScsiPortWritePortUchar(&baseIoAddress->DriveSelect,
#052???????????????????????????????????????????? (UCHAR)(((i & 0x1) << 4) | 0xA0));
#053?
#054????????????????????? //
#055????????????????????? // Setup sector count to reflect the # of blocks.
#056????????????????????? //
#057?
#058????????????????????? ScsiPortWritePortUchar(&baseIoAddress->BlockCount,
#059???????????????????????????????????????????? deviceExtension->MaximumBlockXfer[i]);
#060?
#061????????????????????? //
#062??????????????? ??????// Issue the command.
#063????????????????????? //
#064?
?
設置多塊傳送。
#065????????????????????? ScsiPortWritePortUchar(&baseIoAddress->Command,
#066???????????????????????????????????????????? IDE_COMMAND_SET_MULTIPLE);
#067?
#068????????????????????? //
#069????????????????????? // Wait for busy to drop.
#070????????????????????? //
#071?
#072????????????????????? WaitOnBaseBusy(baseIoAddress,statusByte);
#073?
#074????????????????????? //
#075????????????????????? // Check for errors. Reset the value to 0 (disable MultiBlock) if the
#076????????????????????? // command was aborted.
#077????????????????????? //
#078?
?
如果設置多塊傳送命令失敗,就設置為不支持多塊傳送。
#079????????????????????? if (statusByte & IDE_STATUS_ERROR) {
#080?
#081????????????????????????? //
#082 ?????????????????????????// Read the error register.
#083????????????????????????? //
#084?
#085????????????????????????? errorByte = ScsiPortReadPortUchar((PUCHAR)baseIoAddress + 1);
#086?
#087????????????????????????? DebugPrint((1,
#088?????????????? ???????????????????????"AtapiHwInitialize: Error setting multiple mode. Status %x, error byte %x/n",
#089????????????????????????????????????? statusByte,
#090????????????????????????????????????? errorByte));
#091????????????????????????? //
#092???????? ?????????????????// Adjust the devExt. value, if necessary.
#093????????????????????????? //
#094?
#095????????????????????????? deviceExtension->MaximumBlockXfer[i] = 0;
#096?
#097????????????????????? } else {
#098????????????????????????? DebugPrint((2,
#099????????????????????????????????????? "AtapiHwInitialize: Using Multiblock on Device %d. Blocks / int - %d/n",
#100????????????????????????????????????? i,
#101????????????????????????????????????? deviceExtension->MaximumBlockXfer[i]));
#102?????? ???????????????}
#103????????????????? }
#104????????????? } else if (!(deviceExtension->DeviceFlags[i] & DFLAGS_CHANGER_INITED)){
?
如果這個設備還沒有初始化,就進行初始化設置。
#105?
#106????????????????? ULONG j;
#107????????????????? BOOLEAN isSanyo = FALSE;
#108??????????? ??????UCHAR vendorId[26];
#109?
#110????????????????? //
#111????????????????? // Attempt to identify any special-case devices - psuedo-atapi changers, atapi changers, etc.
#112????????????????? //
#113?
?
判斷這個IDE設備是否為CR-ROM設備。
#114????????????????? for (j = 0; j < 13; j += 2) {
#115?
#116????????????????????? //
#117????????????????????? // Build a buffer based on the identify data.
#118????????????????????? //
#119?
#120????????????????????? vendorId[j] = ((PUCHAR)deviceExtension->IdentifyData[i].ModelNumber)[j + 1];
#121????????????????????? vendorId[j+1] = ((PUCHAR)deviceExtension->IdentifyData[i].ModelNumber)[j];
#122????????????????? }
#123?
?
比較IDE設備標識是否為CD-ROM。
#124????????????????? if (!AtapiStringCmp ((PCHAR)vendorId, "CD-ROM? CDR", 11)) {
#125 ?
#126????????????????????? //
#127????????????????????? // Inquiry string for older model had a '-', newer is '_'
#128????????????????????? //
#129?
#130????????????????????? if (vendorId[12] == 'C') {
#131?
#132????????????????????????? //
#133??????? ??????????????????// Torisan changer. Set the bit. This will be used in several places
#134????????????????????????? // acting like 1) a multi-lun device and 2) building the 'special' TUR's.
#135????????????????????????? //
#136?
?
設置設備已經初始化。
#137???????? ?????????????????deviceExtension->DeviceFlags[i] |= (DFLAGS_CHANGER_INITED | DFLAGS_SANYO_ATAPI_CHANGER);
#138????????????????????????? deviceExtension->DiscsPresent[i] = 3;
#139????????????????????????? isSanyo = TRUE;
#140????????????????????? }
#141??? ??????????????}
#142????????????? }
#143?
#144????????????? //
#145????????????? // We need to get our device ready for action before
#146????????????? // returning from this function
#147????????????? //
#148????????????? // According to the atapi spec 2.5 or 2.6, an atapi device
#149????????????? // clears its status BSY bit when it is ready for atapi commands.
#150????????????? // However, some devices (Panasonic SQ-TC500N) are still
#151????????????? // not ready even when the status BSY is clear.? They don't react
#152????????????? // to atapi commands.
#153????????????? //
#154????????????? // Since there is really no other indication that tells us
#155????????????? // the drive is really ready for action.? We are going to check BSY
#156????????????? // is clear and then just wait for an arbitrary amount of time!
#157????????????? //
?
下面開始清除忙狀態。
#158????????????? if (deviceExtension->DeviceFlags[i] & DFLAGS_ATAPI_DEVICE) {
#159????????????????? //PIDE_REGISTERS_1???? baseIoAddress1 = deviceExtension->BaseIoAddress1[i >> 1];
#160????????????????? PIDE_REGISTERS_2???? baseIoAddress2 = deviceExtension->BaseIoAddress2[i >> 1];
#161????????????????? ULONG waitCount;
#162?
#163????????????????? // have to get out of the loop sometime!
#164????????????????? // 10000 * 100us = 1000,000us = 1000ms = 1s
#165????????????????? waitCount = 10000;
#166????????????????? GetStatus(baseIoAddress2, statusByte);
#167????????????????? while ((statusByte & IDE_STATUS_BUSY) && waitCount) {
#168????????????????????? //
#169? ????????????????????// Wait for Busy to drop.
#170????????????????????? //
#171????????????????????? ScsiPortStallExecution(100);
#172????????????????????? GetStatus(baseIoAddress2, statusByte);
#173????????????????????? waitCount--;
#174????????????????? }
#175?
#176????????????????? // 5000 * 100us = 500,000us = 500ms = 0.5s
#177????????????????? waitCount = 5000;
#178????????????????? do {
#179????????????????????? ScsiPortStallExecution(100);
#180????????????????? } while (waitCount--);
#181?????????? ???}
#182????????? }
#183????? }
#184?
#185????? return TRUE;
#186?
#187? } // end AtapiHwInitialize()
轉載于:https://www.cnblogs.com/ajuanabc/archive/2009/10/18/2463678.html
總結
以上是生活随笔為你收集整理的reactos操作系统实现(108)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 格拉布斯法—异常值判断(异常值)
- 下一篇: Matlab和Fluent联合仿真实现涡