Windows NT 4.0 source code leak
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.

1098 lines
22 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1993 Digital Equipment Corporation
  3. Module Name:
  4. jxprom.c
  5. Abstract:
  6. This module provides support for different kinds of ROMs/PROMs/Flash
  7. ROMs in Alpha AXP machines.
  8. This file, and rom.c, make no attempt at universal ROM-support.
  9. Current support set:
  10. Intel: 28F008SA 1 megabyte Flash Memory
  11. AMD: Am29F010 128KB Sector Erase Flash Memory
  12. Author:
  13. John DeRosa 4-May-1993
  14. Revision History:
  15. Jeff McLeman 13-May-1993
  16. Adapted for HAL use from Firmware module.
  17. --*/
  18. #include "halp.h"
  19. #include "jxenv.h"
  20. #include "jxprom.h"
  21. #include "arccodes.h"
  22. //
  23. // Function prototypes
  24. //
  25. ARC_STATUS
  26. HalpErase28F008SA(
  27. IN PUCHAR EraseAddress
  28. );
  29. ARC_STATUS
  30. HalpByteWrite28F008SA(
  31. IN PUCHAR WriteAddress,
  32. IN UCHAR WriteData
  33. );
  34. ARC_STATUS
  35. HalpEraseAM29F010 (
  36. IN PUCHAR EraseAddress
  37. );
  38. ARC_STATUS
  39. HalpByteWriteAM29F010 (
  40. IN PUCHAR WriteAddress,
  41. IN UCHAR WriteData
  42. );
  43. //
  44. // ROM identification and control valueds.
  45. //
  46. // These are based on:
  47. //
  48. // Am29F010: AMD publication #16736, Rev. C, Amendment/0, September 1992.
  49. // 28F008SA: Intel order number 290429-003, September 1992.
  50. //
  51. // Table notes:
  52. //
  53. // Addresses for the ID command and response sequences are absolute,
  54. // since this code assumes homogeneous ROM arrays. The code will only
  55. // test the chip at the lowest Jensen ROM address.
  56. //
  57. // Offsets for the Reset and Set Read-mode commands are relative to the
  58. // base address of the individual ROM chip.
  59. //
  60. // Addresses passed to the erase-block function are within the block
  61. // to be erased.
  62. //
  63. // Addresses passed to the write-byte function are the address of the byte
  64. // to be written.
  65. //
  66. // The chip block size must be less than or equal to 64KB.
  67. //
  68. // N.B. The function that determines the ROM type will test each entry
  69. // in RomValues, starting at the beginning. This involves issuing write
  70. // commands to the ROM chip. So care must be taken that the ID command
  71. // write sequence for ROM type "n" will not have a deliterious effect on
  72. // other ROM types which may be in the machine, but are not identified until
  73. // RomValues entry "n + x".
  74. //
  75. //
  76. ROM_VALUES RomValues[InvalidROM] = {
  77. { 16, // Standard stall amount
  78. 1, // ID command length
  79. 2, // ID response length
  80. 1, // Reset command length
  81. 1, // Read command length
  82. I28F008SA, // ROM being described
  83. 0x100000, // 1MB per chip
  84. 0x10000, // 64KB per block
  85. { {(PUCHAR)PROM_VIRTUAL_BASE, 0x90} }, // ID command sequence
  86. { {(PUCHAR)PROM_VIRTUAL_BASE, 0x89}, // ID response sequence
  87. {(PUCHAR)PROM_VIRTUAL_BASE+1, 0xa2} },
  88. { {0, 0x50} }, // Reset command sequence
  89. { {0, 0xff} }, // Read command sequence
  90. HalpErase28F008SA, // Sector erase function
  91. HalpByteWrite28F008SA // Byte write function
  92. },
  93. { 14, // Standard stall amount
  94. 3, // ID command length
  95. 2, // ID response length
  96. 3, // Reset command length
  97. 3, // Read command length
  98. Am29F010, // ROM being described
  99. 0x20000, // 128KB per chip
  100. 0x4000, // 16KB per block
  101. { {(PUCHAR)PROM_VIRTUAL_BASE+0x5555, 0xaa},
  102. {(PUCHAR)PROM_VIRTUAL_BASE+0x2aaa, 0x55},
  103. {(PUCHAR)PROM_VIRTUAL_BASE+0x5555, 0x90} }, // ID command sequence
  104. { {(PUCHAR)PROM_VIRTUAL_BASE, 1}, // ID response sequence
  105. {(PUCHAR)PROM_VIRTUAL_BASE+1, 0x20} },
  106. { {0x5555, 0xaa},
  107. {0x2aaa, 0x55},
  108. {0x5555, 0xf0} }, // Reset command sequence
  109. { {0x5555, 0xaa},
  110. {0x2aaa, 0x55},
  111. {0x5555, 0xf0} }, // Read command sequence
  112. HalpEraseAM29F010, // Sector erase function
  113. HalpByteWriteAM29F010 // Byte write function
  114. }
  115. };
  116. //
  117. // Miscellaneous notes.
  118. //
  119. // A call must first be made to HalpROMDetermineMachineROMType. If this
  120. // returns ESUCCESS, then it has loaded the ROM type into the global variable
  121. // MachineROMType.
  122. //
  123. // After MachineROMType has been loaded, these functions may be called
  124. // to manipulate the system ROM:
  125. //
  126. // HalpROMByteWrite
  127. // HalpROMErase64KB
  128. // HalpROMEraseBlock
  129. // HalpROMResetStatus
  130. // HalpROMSetARCDataToReadMode
  131. // HalpROMSetReadMode
  132. //
  133. // HalpROMErase64KB and HalpROMSetARCDataToReadMode work on a "virtual"
  134. // 64KB ROM block, for compatibility with the first version of Jensen
  135. // hardware.
  136. //
  137. //
  138. // The type of ROM in this machine.
  139. //
  140. ROM_TYPE MachineROMType = 0;
  141. ARC_STATUS
  142. Check28F008SAStatusAndClear (
  143. IN ULONG WhichToCheck
  144. )
  145. /*++
  146. Routine Description:
  147. This checks the status of an Intel 28F008SA 1MB Flash ROM. The
  148. base address of the Jensen space, PROM_VIRTUAL_BASE, is used since
  149. we know there is only one of these chips in the machine.
  150. Hack: The hardwired values here should be changed to come out of
  151. the RomValues array.
  152. Arguments:
  153. WhichToCheck = 0 if a block-erase status check is desired.
  154. = 1 if a byte-write status check is desired.
  155. ROM state on exit:
  156. The status register is cleared.
  157. Return Value:
  158. Returns ESUCCESS if the status is OK.
  159. Otherwise, EIO is returned.
  160. --*/
  161. {
  162. UCHAR FooBar;
  163. //
  164. // Check the full status when the PROM's write state machine is ready.
  165. //
  166. while (((FooBar = READ_PORT_UCHAR((PUCHAR)PROM_VIRTUAL_BASE)) &
  167. 0x80) == 0 ) {
  168. KeStallExecutionProcessor(10);
  169. }
  170. KeStallExecutionProcessor(10);
  171. HalpROMResetStatus((PUCHAR)PROM_VIRTUAL_BASE);
  172. switch (WhichToCheck) {
  173. //
  174. // block-erase status check
  175. //
  176. case 0:
  177. if ( ((FooBar & 0x28) != 0) || ((FooBar & 0x30) == 0x30) ) {
  178. // Error in erase
  179. return EIO;
  180. } else {
  181. // Erase was successful
  182. return ESUCCESS;
  183. }
  184. //
  185. // byte-write status check
  186. //
  187. case 1:
  188. if (FooBar & 0x18) {
  189. // Error in write
  190. return EIO;
  191. } else {
  192. // Write was successful
  193. return ESUCCESS;
  194. }
  195. //
  196. // We should never get here.
  197. //
  198. default:
  199. return EIO;
  200. }
  201. }
  202. ARC_STATUS
  203. HalpErase28F008SA(
  204. IN PUCHAR EraseAddress
  205. )
  206. /*++
  207. Routine Description:
  208. This erases a block in an Intel 28F008SA 1MB Flash ROM. The
  209. base address of the Jensen space, PROM_VIRTUAL_BASE, is used since
  210. we know there is only one of these chips in the machine.
  211. Hack: The hardwired values here should be changed to come out of
  212. the RomValues array.
  213. Arguments:
  214. EraseAddress - An address within the block to be erased.
  215. ROM state on exit:
  216. The status register is left in a cleared (reset) state.
  217. The ROM is left in read-array mode.
  218. Return Value:
  219. Returns ESUCCESS if the erase was successful.
  220. Otherwise, EIO is returned.
  221. --*/
  222. {
  223. ULONG FooBar;
  224. KIRQL OldIrql;
  225. for (FooBar = 0; FooBar <= 10; FooBar++) {
  226. HalpROMResetStatus((PUCHAR)PROM_VIRTUAL_BASE);
  227. KeRaiseIrql(DEVICE_LEVEL, &OldIrql);
  228. WRITE_PORT_UCHAR (EraseAddress, 0x20);
  229. HalpMb();
  230. WRITE_PORT_UCHAR (EraseAddress, 0xd0);
  231. HalpMb();
  232. KeLowerIrql(OldIrql);
  233. // Stall 1 seconds
  234. HalpPromDelay(3000);
  235. if (Check28F008SAStatusAndClear(0) == ESUCCESS) {
  236. HalpROMSetReadMode((PUCHAR)PROM_VIRTUAL_BASE);
  237. return ESUCCESS;
  238. }
  239. // In case the device is busy, give it some time to settle.
  240. HalpPromDelay(6000);
  241. }
  242. //
  243. // If we get here, we have tried unsuccessfully 10 times to erase
  244. // this block. Return an error.
  245. //
  246. HalpROMSetReadMode((PUCHAR)PROM_VIRTUAL_BASE);
  247. return EIO;
  248. }
  249. ARC_STATUS
  250. HalpByteWrite28F008SA(
  251. IN PUCHAR WriteAddress,
  252. IN UCHAR WriteData
  253. )
  254. /*++
  255. Routine Description:
  256. This writes a byte in the Alpha/Jensen 1MB PROM. It retries up to
  257. 20 times if the write status register indicates failure, or a read
  258. of the location indicates that the write was partially done
  259. by the device.
  260. Hack: The hardwired values here should be changed to come out of
  261. the RomValues array.
  262. Arguments:
  263. WriteAddress = meta-virtual address of the byte to be written.
  264. WriteData = byte to be written.
  265. ROM state on exit:
  266. The byte is written, and the WSM status register is modified.
  267. Return Value:
  268. ESUCCESS if the write was successful.
  269. Otherwise, EIO.
  270. --*/
  271. {
  272. ULONG Index;
  273. UCHAR WSMStatus;
  274. KIRQL OldIrql;
  275. HalpROMResetStatus((PUCHAR)PROM_VIRTUAL_BASE);
  276. for (Index = 0; Index < 20; Index++) {
  277. KeRaiseIrql(DEVICE_LEVEL, &OldIrql);
  278. WRITE_PORT_UCHAR (WriteAddress, 0x40);
  279. HalpMb();
  280. WRITE_PORT_UCHAR (WriteAddress, WriteData);
  281. HalpMb();
  282. KeLowerIrql(OldIrql);
  283. //
  284. // The device should need only 14 microseconds.
  285. //
  286. KeStallExecutionProcessor(14);
  287. if (Check28F008SAStatusAndClear(1) != ESUCCESS) {
  288. //
  289. // The write failed. Ensure status is clear and see if we
  290. // can retry.
  291. //
  292. HalpROMResetStatus((PUCHAR)PROM_VIRTUAL_BASE);
  293. HalpROMSetReadMode((PUCHAR)PROM_VIRTUAL_BASE);
  294. DbgPrint("? Write failed to address %x. Wrote %x, ",
  295. WriteAddress, WriteData);
  296. DbgPrint("verify returns %x.\r\n",
  297. READ_PORT_UCHAR((PUCHAR)WriteAddress));
  298. if (READ_PORT_UCHAR(WriteAddress) != 0xff) {
  299. DbgPrint("RETRY ABORTED!\r\n");
  300. return EIO;
  301. } else {
  302. DbgPrint("Retrying..\r\n");
  303. }
  304. } else {
  305. //
  306. // The write succeeded.
  307. //
  308. return ESUCCESS;
  309. }
  310. }
  311. //
  312. // We failed to write the byte after 20 tries.
  313. //
  314. return EIO;
  315. }
  316. ARC_STATUS
  317. CheckAM29F010Status (
  318. IN BOOLEAN SectorErase,
  319. IN PUCHAR Address,
  320. IN UCHAR Data
  321. )
  322. /*++
  323. Routine Description:
  324. This checks the status of an AMD 29F010 128KB ROM chip after a
  325. byte write or sector erase command has been issued. Data Polling
  326. is used.
  327. Arguments:
  328. SectorErase - TRUE if a sector erase is under way.
  329. FALSE if a byte write is under way.
  330. Address - The address of the ROM byte that was just
  331. written, or an address within the chip that
  332. was just given an erase command.
  333. Data - If a byte write is under way, this is the byte
  334. that was written.
  335. If a sector erase is under way, this must be
  336. a value in the range 0xf0 -- 0xff.
  337. ROM state on exit:
  338. The ROM is left at the end of its sector erase or byte write algorithm.
  339. Return Value:
  340. Returns ESUCCESS if the status is OK.
  341. Otherwise, EIO is returned.
  342. --*/
  343. {
  344. UCHAR Character;
  345. ULONG Retries;
  346. //
  347. // If we are doing an erase command, check whether the erase command
  348. // was accepted. This is supposed to happen within the first 100 usec.
  349. //
  350. if (SectorErase) {
  351. Retries = 0;
  352. while ((READ_PORT_UCHAR(Address) & 0x08) != 0x08) {
  353. Retries++;
  354. KeStallExecutionProcessor(20);
  355. if (Retries == 10) {
  356. return (EIO);
  357. }
  358. }
  359. }
  360. //
  361. // Do data polling until the device signals success or a timeout.
  362. //
  363. while (TRUE) {
  364. Character = READ_PORT_UCHAR(Address);
  365. //
  366. // Has the device finished?
  367. //
  368. if (((Character ^ Data) & 0x80) == 0) {
  369. //
  370. // DQ7 says yes!
  371. //
  372. return (ESUCCESS);
  373. }
  374. //
  375. // Check for time-out. If a possible time-out condition, DQ7 is
  376. // re-read and re-checked to account for the case of simultaneous
  377. // updates to DQ5 and DQ7.
  378. //
  379. if (Character & 0x20) {
  380. if (((READ_PORT_UCHAR(Address) ^ Data) & 0x80) == 0) {
  381. // DQ7 says success!
  382. return (ESUCCESS);
  383. } else {
  384. // DQ5 and DQ7 say time-out.
  385. return (EIO);
  386. }
  387. }
  388. }
  389. }
  390. ARC_STATUS
  391. HalpEraseAM29F010 (
  392. IN PUCHAR EraseAddress
  393. )
  394. /*++
  395. Routine Description:
  396. This erases a block in an AMD AM29F010 128KB Flash ROM.
  397. Arguments:
  398. EraseAddress - An address within the block to be erased.
  399. ROM state on exit:
  400. The status register is left in a cleared (reset) state.
  401. The ROM is left in read-array mode.
  402. Return Value:
  403. Returns ESUCCESS if the erase was successful.
  404. Otherwise, EIO is returned.
  405. --*/
  406. {
  407. ULONG FooBar;
  408. PUCHAR Address;
  409. KIRQL OldIrql;
  410. //
  411. // Concoct the base address of this ROM chip.
  412. //
  413. Address = (PUCHAR)
  414. ((ULONG)EraseAddress &
  415. ~(RomValues[MachineROMType].BytesPerChip - 1));
  416. for (FooBar = 0; FooBar <= 10; FooBar++) {
  417. HalpROMResetStatus(EraseAddress);
  418. KeRaiseIrql(DEVICE_LEVEL, &OldIrql);
  419. WRITE_PORT_UCHAR (Address+0x5555, 0xaa);
  420. KeStallExecutionProcessor(2);
  421. WRITE_PORT_UCHAR (Address+0x2aaa, 0x55);
  422. KeStallExecutionProcessor(2);
  423. WRITE_PORT_UCHAR (Address+0x5555, 0x80);
  424. KeStallExecutionProcessor(2);
  425. WRITE_PORT_UCHAR (Address+0x5555, 0xaa);
  426. KeStallExecutionProcessor(2);
  427. WRITE_PORT_UCHAR (Address+0x2aaa, 0x55);
  428. KeStallExecutionProcessor(2);
  429. WRITE_PORT_UCHAR (EraseAddress, 0x30);
  430. KeLowerIrql(OldIrql);
  431. if (CheckAM29F010Status(TRUE, EraseAddress, 0xff) == ESUCCESS) {
  432. HalpROMSetReadMode(EraseAddress);
  433. return ESUCCESS;
  434. }
  435. //
  436. // We have to retry the erase. Give the device some time to settle.
  437. //
  438. HalpPromDelay(3000);
  439. }
  440. //
  441. // If we get here, we have tried unsuccessfully 10 times to erase
  442. // this block. Return an error.
  443. //
  444. HalpROMSetReadMode(EraseAddress);
  445. return EIO;
  446. }
  447. ARC_STATUS
  448. HalpByteWriteAM29F010 (
  449. IN PUCHAR WriteAddress,
  450. IN UCHAR WriteData
  451. )
  452. /*++
  453. Routine Description:
  454. This writes a byte in an AMD AM29F010 128KB Flash ROM. It retries up to
  455. 20 times if the write status register indicates failure, or a read
  456. of the location indicates that the write was partially done
  457. by the device.
  458. Arguments:
  459. WriteAddress = meta-virtual address of the byte to be written.
  460. WriteData = byte to be written.
  461. ROM state on exit:
  462. The byte is written, and the WSM status register is modified.
  463. Return Value:
  464. ESUCCESS if the write was successful.
  465. Otherwise, EIO.
  466. --*/
  467. {
  468. ULONG Index;
  469. UCHAR WSMStatus;
  470. PUCHAR Address;
  471. KIRQL OldIrql;
  472. //
  473. // Concoct the base address of this ROM chip.
  474. //
  475. Address = (PUCHAR)
  476. ((ULONG)WriteAddress &
  477. ~(RomValues[MachineROMType].BytesPerChip - 1));
  478. HalpROMResetStatus(WriteAddress);
  479. for (Index = 0; Index < 20; Index++) {
  480. KeRaiseIrql(DEVICE_LEVEL, &OldIrql);
  481. WRITE_PORT_UCHAR (Address+0x5555, 0xaa);
  482. KeStallExecutionProcessor(2);
  483. WRITE_PORT_UCHAR (Address+0x2aaa, 0x55);
  484. KeStallExecutionProcessor(2);
  485. WRITE_PORT_UCHAR (Address+0x5555, 0xa0);
  486. KeStallExecutionProcessor(2);
  487. WRITE_PORT_UCHAR (WriteAddress, WriteData);
  488. KeStallExecutionProcessor(2);
  489. KeLowerIrql(OldIrql);
  490. if (CheckAM29F010Status(FALSE, WriteAddress, WriteData) != ESUCCESS) {
  491. //
  492. // The write failed. Ensure status is clear and see if we
  493. // can retry.
  494. //
  495. HalpROMResetStatus(WriteAddress);
  496. HalpROMSetReadMode(WriteAddress);
  497. DbgPrint("? Write failed to address %x. Wrote %x, ",
  498. WriteAddress, WriteData);
  499. DbgPrint("verify returns %x.\r\n",
  500. READ_PORT_UCHAR((PUCHAR)WriteAddress));
  501. if (READ_PORT_UCHAR(WriteAddress) != 0xff) {
  502. DbgPrint("RETRY ABORTED!\r\n");
  503. return EIO;
  504. } else {
  505. DbgPrint("Retrying..\r\n");
  506. }
  507. } else {
  508. //
  509. // The write succeeded.
  510. //
  511. return ESUCCESS;
  512. }
  513. }
  514. //
  515. // We failed to write the byte after 20 tries.
  516. //
  517. return EIO;
  518. }
  519. ARC_STATUS
  520. HalpROMDetermineMachineROMType (
  521. VOID
  522. )
  523. /*++
  524. Routine Description:
  525. This determines what kind of Flash ROM is in the machine.
  526. The ROMs making up the Flash ROM space are assumed to be
  527. homogeneous. So, we only check one chip.
  528. N.B. The RomValues array must be tested in ascending order,
  529. N.B. This function must not call any of the HalpROM... functions!
  530. Arguments:
  531. ROMType - A pointer to a variable that will receive the type
  532. of ROM in the machine, if the return value is ESUCCESS.
  533. ROM state on exit:
  534. Left in read-array mode.
  535. Return Value:
  536. ESUCCESS if we could successfully identify the ROM.
  537. Otherwise, and error condition.
  538. --*/
  539. {
  540. BOOLEAN Match;
  541. ROM_TYPE Index;
  542. ULONG IDIndex;
  543. //
  544. // Loop through each ROM type, trying the ID Command Sequence for
  545. // each.
  546. //
  547. for (Index = 0; Index < InvalidROM; Index++) {
  548. //
  549. // Send the command.
  550. //
  551. for (IDIndex = 0;
  552. IDIndex < RomValues[Index].IdCommandLength;
  553. IDIndex++) {
  554. WRITE_PORT_UCHAR(RomValues[Index].IdCommand[IDIndex].Address,
  555. RomValues[Index].IdCommand[IDIndex].Value);
  556. KeStallExecutionProcessor(RomValues[MachineROMType].StallAmount);
  557. }
  558. //
  559. // Check the response.
  560. //
  561. Match = TRUE;
  562. for (IDIndex = 0;
  563. IDIndex < RomValues[Index].IdResponseLength;
  564. IDIndex++) {
  565. if (RomValues[Index].IdResponse[IDIndex].Value !=
  566. READ_PORT_UCHAR(RomValues[Index].IdResponse[IDIndex].Address)) {
  567. //
  568. // This portion of the Response sequence did not match.
  569. //
  570. Match = FALSE;
  571. break;
  572. }
  573. }
  574. if (Match == FALSE) {
  575. continue;
  576. }
  577. //
  578. // We have found a match. Set the ROM to read-array mode, and then
  579. // return the current entry as the ROM type.
  580. //
  581. MachineROMType = RomValues[Index].ROMType;
  582. HalpROMResetStatus((PUCHAR)PROM_VIRTUAL_BASE);
  583. HalpROMSetReadMode((PUCHAR)PROM_VIRTUAL_BASE);
  584. return (ESUCCESS);
  585. }
  586. //
  587. // We have not found a match. Return an error.
  588. //
  589. return (EIO);
  590. }
  591. VOID
  592. HalpROMResetStatus(
  593. IN PUCHAR Address
  594. )
  595. /*++
  596. Routine Description:
  597. This clears the status register in a ROM chip.
  598. Arguments:
  599. Address - An address within the chip that is to be reset.
  600. ROM state on exit:
  601. The status register is left in a cleared (reset) state.
  602. Return Value:
  603. None.
  604. --*/
  605. {
  606. ULONG Index;
  607. KIRQL OldIrql;
  608. //
  609. // Concoct the base address of this ROM chip.
  610. //
  611. // Remember, C is call by value!
  612. //
  613. Address = (PUCHAR)
  614. ((ULONG)Address & ~(RomValues[MachineROMType].BytesPerChip - 1));
  615. for (Index = 0;
  616. Index < RomValues[MachineROMType].ResetCommandLength;
  617. Index++) {
  618. KeRaiseIrql(DEVICE_LEVEL, &OldIrql);
  619. WRITE_PORT_UCHAR (Address +
  620. RomValues[MachineROMType].ResetCommand[Index].Offset,
  621. RomValues[MachineROMType].ResetCommand[Index].Value);
  622. HalpMb();
  623. KeLowerIrql(OldIrql);
  624. KeStallExecutionProcessor(RomValues[MachineROMType].StallAmount);
  625. }
  626. }
  627. VOID
  628. HalpROMSetReadMode(
  629. IN PUCHAR Address
  630. )
  631. /*++
  632. Routine Description:
  633. This returns a ROM chip to read-array mode.
  634. Arguments:
  635. Address - An address within the chip that is to be set to
  636. read-array mode.
  637. ROM state on exit:
  638. The chip is left in read-array mode.
  639. Return Value:
  640. None.
  641. --*/
  642. {
  643. ULONG Index;
  644. KIRQL OldIrql;
  645. //
  646. // Concoct the base address of this ROM chip.
  647. //
  648. // Remember, C is call by value!
  649. //
  650. Address = (PUCHAR)
  651. ((ULONG)Address & ~(RomValues[MachineROMType].BytesPerChip - 1));
  652. for (Index = 0;
  653. Index < RomValues[MachineROMType].ReadCommandLength;
  654. Index++) {
  655. KeRaiseIrql(DEVICE_LEVEL, &OldIrql);
  656. WRITE_PORT_UCHAR (Address +
  657. RomValues[MachineROMType].ReadCommand[Index].Offset,
  658. RomValues[MachineROMType].ReadCommand[Index].Value);
  659. HalpMb();
  660. KeLowerIrql(OldIrql);
  661. KeStallExecutionProcessor(RomValues[MachineROMType].StallAmount);
  662. }
  663. }
  664. VOID
  665. HalpROMSetARCDataToReadMode (
  666. VOID
  667. )
  668. /*++
  669. Routine Description:
  670. This routine sets the virtual 64KB ROM block that houses the
  671. CDS tree, environment variables, and EISA configuration data to
  672. read-array mode. For devices with a block size smaller than
  673. 64KB, we issues set read-mode commands to every block within this
  674. virtual 64KB block. This is overkill, but it is easy.
  675. Arguments:
  676. None.
  677. ROM state on exit:
  678. Set to read-array mode.
  679. Return Value:
  680. None
  681. --*/
  682. {
  683. PUCHAR Address;
  684. ULONG Index;
  685. Address = (PUCHAR)NVRAM_CONFIGURATION;
  686. //
  687. // Hackhack: At some point change this to eliminate the division.
  688. //
  689. for (Index = 0;
  690. Index < (SIXTY_FOUR_KB / RomValues[MachineROMType].BytesPerBlock);
  691. Index++) {
  692. HalpROMSetReadMode(Address);
  693. Address += RomValues[MachineROMType].BytesPerBlock;
  694. }
  695. }
  696. ARC_STATUS
  697. HalpROMByteWrite(
  698. IN PUCHAR WriteAddress,
  699. IN UCHAR WriteData
  700. )
  701. /*++
  702. Routine Description:
  703. This writes a byte in the Alpha/Jensen ROM space.
  704. Arguments:
  705. WriteAddress = meta-virtual address of the byte to be written.
  706. WriteData = byte to be written.
  707. ROM state on exit:
  708. The byte is written, and the WSM status register is modified.
  709. Return Value:
  710. Whatever is returned from the ROM-specific write function.
  711. --*/
  712. {
  713. return ((*RomValues[MachineROMType].ByteWrite)(WriteAddress, WriteData));
  714. }
  715. ARC_STATUS
  716. HalpROMEraseBlock(
  717. IN PUCHAR EraseAddress
  718. )
  719. /*++
  720. Routine Description:
  721. This erases a single block in the Alpha/Jensen ROM space. The number
  722. of bytes erased is dependent on the underlying chip being manipulated.
  723. Arguments:
  724. EraseAddress - An address within the block to be erased.
  725. ROM state on exit:
  726. On a successful return, the status register is left in a reset state and
  727. the ROM is in read-array mode.
  728. Return Value:
  729. Whatever is returned from the ROM-specific erase function.
  730. --*/
  731. {
  732. return ((*RomValues[MachineROMType].SectorErase)(EraseAddress));
  733. }
  734. ARC_STATUS
  735. HalpROMErase64KB(
  736. IN PUCHAR EraseAddress
  737. )
  738. /*++
  739. Routine Description:
  740. This erases a 64KB logical block in the Alpha/Jensen ROM space.
  741. To minimize code changes with the previous version of the firmware,
  742. the PROM space is treated as though it has a block size of 64KB, even
  743. if the block size is must less than that.
  744. Arguments:
  745. EraseAddress - An address within the block to be erased.
  746. ROM state on exit:
  747. On a successful return, the status register is left in a reset state and
  748. the ROM is in read-array mode.
  749. Return Value:
  750. Returns ESUCCESS if the erase was successful.
  751. Otherwise, EIO is returned.
  752. --*/
  753. {
  754. ARC_STATUS Status;
  755. ULONG Index;
  756. //
  757. // Create the base address of the 64KB block to be cleared.
  758. //
  759. // Remember, C is call by value!
  760. //
  761. EraseAddress = (PUCHAR)((ULONG)EraseAddress & ~(SIXTY_FOUR_KB - 1));
  762. //
  763. // Now erase as many blocks as is necessary to erase a 64KB virtual block.
  764. //
  765. // Hack: I should eliminate the integer division.
  766. //
  767. for (Index = 0;
  768. Index < (SIXTY_FOUR_KB / RomValues[MachineROMType].BytesPerBlock);
  769. Index++) {
  770. if ((Status = (*RomValues[MachineROMType].SectorErase)(EraseAddress))
  771. != ESUCCESS) {
  772. break;
  773. }
  774. EraseAddress += RomValues[MachineROMType].BytesPerBlock;
  775. }
  776. return (Status);
  777. }