ata.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /* ATA PIO driver: IDENTIFY + LBA28/LBA48 read/write, polled (no IRQ).
  2. * The ATA IRQs (14/15) stay masked at boot, so we poll BSY/DRQ/ERR.
  3. *
  4. * Channel port bases default to the legacy primary/secondary ports and are
  5. * replaced by the PCI IDE interface's BARs when it runs in native mode
  6. * (nVidia MCP79 "compatibility mode" and friends). */
  7. #include "ata.h"
  8. #include "pci.h"
  9. #include "serial.h"
  10. #include "timer.h"
  11. static unsigned short ata_base[2] = { 0x1F0, 0x170 };
  12. /* Kept for the bring-up log only; transfers poll the command-block status
  13. * because some controllers' alt-status BAR does not answer correctly. */
  14. static unsigned short ata_ctrl[2] = { 0x3F6, 0x376 };
  15. /* Set when a multi-sector PIO command left DRQ pending on this channel.
  16. * From then on use one ATA command per sector; slower, but it works on
  17. * bridges that mishandle multi-sector PIO. */
  18. static int ata_single[2];
  19. static int ata_lba48[2];
  20. static int ata_tf_logged;
  21. /* Register offsets from the I/O base. */
  22. #define REG_DATA 0
  23. #define REG_ERROR 1
  24. #define REG_COUNT 2
  25. #define REG_LBA_LO 3
  26. #define REG_LBA_MID 4
  27. #define REG_LBA_HI 5
  28. #define REG_DRIVE 6
  29. #define REG_CMD 7
  30. /* Status bits (status = base+7, alt-status = ctrl+0). */
  31. #define SR_BSY 0x80
  32. #define SR_DRDY 0x40
  33. #define SR_DRQ 0x08
  34. #define SR_ERR 0x01
  35. /* Commands. */
  36. #define CMD_IDENTIFY 0xEC
  37. #define CMD_READ 0x20 /* LBA28 */
  38. #define CMD_WRITE 0x30 /* LBA28 */
  39. #define CMD_READ_EXT 0x24 /* LBA48 */
  40. #define CMD_WRITE_EXT 0x34 /* LBA48 */
  41. /* A spun-down disk can take several seconds to accept its first command;
  42. * keep a generous poll budget. */
  43. #define ATA_TIMEOUT_MS 15000
  44. /* Once the data is transferred, the drive should finish the sector quickly.
  45. * A longer wait here would only delay the single-sector fallback. */
  46. #define ATA_COMPLETE_TIMEOUT_MS 2000
  47. static void ata_reset_channel(unsigned short base, unsigned short ctrl);
  48. /* Point the primary/secondary channels at the PCI IDE interface's native
  49. * per-channel I/O BARs when it uses native mode, keeping the legacy ports
  50. * otherwise. Runs once; without a PCI IDE function the defaults stay. */
  51. void ata_init_ports(void)
  52. {
  53. static int inited;
  54. unsigned int bus, dev, func;
  55. if (inited)
  56. return;
  57. inited = 1;
  58. for (bus = 0; bus < 256; bus++) {
  59. for (dev = 0; dev < 32; dev++) {
  60. unsigned int id = pci_cfg_read32(bus, dev, 0, 0x00);
  61. unsigned int htype, nfunc;
  62. if (id == 0xFFFFFFFFu || id == 0)
  63. continue;
  64. htype = (pci_cfg_read32(bus, dev, 0, 0x0C) >> 16) & 0xFFu;
  65. nfunc = (htype & 0x80u) ? 8u : 1u;
  66. for (func = 0; func < nfunc; func++) {
  67. unsigned int idf = pci_cfg_read32(bus, dev, func, 0x00);
  68. unsigned int crev, cls, sub, prog;
  69. unsigned int bar0, bar1, bar2, bar3, cmd;
  70. unsigned short b0, c0, b1, c1;
  71. if (idf == 0xFFFFFFFFu || idf == 0)
  72. continue;
  73. crev = pci_cfg_read32(bus, dev, func, 0x08);
  74. cls = (crev >> 24) & 0xFFu;
  75. sub = (crev >> 16) & 0xFFu;
  76. prog = (crev >> 8) & 0xFFu;
  77. if (cls != 0x01 || sub != 0x01)
  78. continue;
  79. cmd = pci_cfg_read32(bus, dev, func, 0x04);
  80. pci_cfg_write32(bus, dev, func, 0x04, cmd | 0x0005u);
  81. bar0 = pci_cfg_read32(bus, dev, func, 0x10);
  82. bar1 = pci_cfg_read32(bus, dev, func, 0x14);
  83. bar2 = pci_cfg_read32(bus, dev, func, 0x18);
  84. bar3 = pci_cfg_read32(bus, dev, func, 0x1C);
  85. /* prog-if bit 0/2: primary/secondary native mode. */
  86. if ((prog & 0x01u) && (bar0 & 0x1u)) {
  87. b0 = (unsigned short)(bar0 & 0xFFFCu);
  88. /* A native-mode BAR1 of 0 is malformed;
  89. * the legacy control port is a safer
  90. * fallback than b0+8. */
  91. c0 = (bar1 & 0x1u)
  92. ? (unsigned short)(bar1 & 0xFFFCu)
  93. : (unsigned short)0x3F6;
  94. } else {
  95. b0 = 0x1F0; c0 = 0x3F6;
  96. }
  97. if ((prog & 0x04u) && (bar2 & 0x1u)) {
  98. b1 = (unsigned short)(bar2 & 0xFFFCu);
  99. c1 = (bar3 & 0x1u)
  100. ? (unsigned short)(bar3 & 0xFFFCu)
  101. : (unsigned short)0x376;
  102. } else {
  103. b1 = 0x170; c1 = 0x376;
  104. }
  105. ata_base[0] = b0; ata_ctrl[0] = c0;
  106. ata_base[1] = b1; ata_ctrl[1] = c1;
  107. ata_reset_channel(ata_base[0], ata_ctrl[0]);
  108. ata_reset_channel(ata_base[1], ata_ctrl[1]);
  109. serial_puts(SERIAL_COM1, "ata: ctl ");
  110. serial_puthex(SERIAL_COM1, port_inb(c0));
  111. serial_putc(SERIAL_COM1, '/');
  112. serial_puthex(SERIAL_COM1, port_inb(c0 + 2));
  113. serial_putc(SERIAL_COM1, ' ');
  114. serial_puthex(SERIAL_COM1, port_inb(c1));
  115. serial_putc(SERIAL_COM1, '/');
  116. serial_puthex(SERIAL_COM1, port_inb(c1 + 2));
  117. serial_putc(SERIAL_COM1, '\n');
  118. serial_puts(SERIAL_COM1, "ata: pci ide ");
  119. serial_putdec(SERIAL_COM1, bus);
  120. serial_putc(SERIAL_COM1, ':');
  121. serial_putdec(SERIAL_COM1, dev);
  122. serial_putc(SERIAL_COM1, '.');
  123. serial_putdec(SERIAL_COM1, func);
  124. serial_puts(SERIAL_COM1, " prog ");
  125. serial_puthex(SERIAL_COM1, prog);
  126. serial_puts(SERIAL_COM1, " ch0 ");
  127. serial_puthex(SERIAL_COM1, b0);
  128. serial_putc(SERIAL_COM1, '-');
  129. serial_puthex(SERIAL_COM1, c0);
  130. serial_puts(SERIAL_COM1, " ch1 ");
  131. serial_puthex(SERIAL_COM1, b1);
  132. serial_putc(SERIAL_COM1, '-');
  133. serial_puthex(SERIAL_COM1, c1);
  134. serial_putc(SERIAL_COM1, '\n');
  135. return;
  136. }
  137. }
  138. }
  139. serial_puts(SERIAL_COM1, "ata: no PCI IDE function, legacy ports\n");
  140. }
  141. /* Delay 400 ns by reading the command-block status register a few times.
  142. * The alt-status port is not used for polling: some IDE functions expose a
  143. * BAR that does not answer correctly, and a bogus BSY bit there made every
  144. * transfer time out even though the command block reported ready. */
  145. static void ata_400ns(unsigned short base)
  146. {
  147. (void)port_inb(base + REG_CMD);
  148. (void)port_inb(base + REG_CMD);
  149. (void)port_inb(base + REG_CMD);
  150. (void)port_inb(base + REG_CMD);
  151. }
  152. /* A channel with no device floats to 0xFF. Treat that as "absent" before
  153. * any reset/wait: otherwise an AHCI-only machine spends a full second in
  154. * ata_reset_channel() for each of the four legacy targets. (0x00 is left
  155. * alone: a drive that has not finished spinning up can report it, and the
  156. * IDENTIFY path already fails fast when it stays 0x00.) */
  157. static int ata_bus_floating(unsigned short base)
  158. {
  159. return port_inb(base + REG_CMD) == 0xFF;
  160. }
  161. static int ata_wait_not_busy(unsigned short base, unsigned int timeout_ms)
  162. {
  163. unsigned int t0 = get_ticks_ms();
  164. while (get_ticks_ms() - t0 < timeout_ms) {
  165. if (!(port_inb(base + REG_CMD) & SR_BSY))
  166. return 0;
  167. }
  168. return -1;
  169. }
  170. /* Assert SRST for ~10 ms. This aborts a command a crashed/reloaded kernel
  171. * left half-transferred (the drive would otherwise stay in DRQ forever and
  172. * ignore the next IDENTIFY). Best effort: a malformed control BAR simply
  173. * makes the reset a no-op. */
  174. static void ata_reset_channel(unsigned short base, unsigned short ctrl)
  175. {
  176. unsigned int t0;
  177. port_outb(ctrl, 0x04); /* SRST */
  178. t0 = get_ticks_ms();
  179. while (get_ticks_ms() - t0 < 10)
  180. ;
  181. /* nIEN=1: the driver polls, so keep the drive's IRQ line quiet
  182. * instead of leaving a masked level-triggered interrupt asserted. */
  183. port_outb(ctrl, 0x02);
  184. t0 = get_ticks_ms();
  185. while (get_ticks_ms() - t0 < 1000) {
  186. unsigned char st = port_inb(base + REG_CMD);
  187. if (!(st & SR_BSY) || st == 0x00 || st == 0xFF)
  188. break;
  189. }
  190. ata_400ns(base);
  191. }
  192. static int ata_wait_drq(unsigned short base, unsigned int timeout_ms)
  193. {
  194. unsigned int t0 = get_ticks_ms();
  195. while (get_ticks_ms() - t0 < timeout_ms) {
  196. unsigned char st = port_inb(base + REG_CMD);
  197. if (st & SR_ERR)
  198. return -1;
  199. if (st & SR_DRQ)
  200. return 0;
  201. }
  202. return -1;
  203. }
  204. /* A command is done only when both BSY and DRQ are clear. Waiting for BSY
  205. * alone can return while the last sector is still pending; the next command
  206. * is then ignored and the drive stays in DRQ, which looks like a zeroed /
  207. * unmountable filesystem. */
  208. static int ata_wait_idle(unsigned short base, unsigned int timeout_ms)
  209. {
  210. unsigned int t0 = get_ticks_ms();
  211. while (get_ticks_ms() - t0 < timeout_ms) {
  212. unsigned char st = port_inb(base + REG_CMD);
  213. if (st & SR_ERR)
  214. return -1;
  215. if (!(st & (SR_BSY | SR_DRQ)))
  216. return 0;
  217. }
  218. return -1;
  219. }
  220. static int ata_identify(int bus, int unit, unsigned short *id)
  221. {
  222. unsigned short base = ata_base[bus];
  223. unsigned char st;
  224. unsigned int t0;
  225. unsigned int i;
  226. if (ata_bus_floating(base))
  227. return -1; /* floating bus: no device on this channel */
  228. /* A previous failed transfer can leave the drive waiting for PIO
  229. * data, in which case it ignores IDENTIFY and returns zeros. */
  230. if (ata_wait_idle(base, 1000) != 0)
  231. ata_reset_channel(base, ata_ctrl[bus]);
  232. port_outb(base + REG_DRIVE, (unsigned char)(0xA0 | (unit << 4)));
  233. port_outb(base + REG_COUNT, 0);
  234. port_outb(base + REG_LBA_LO, 0);
  235. port_outb(base + REG_LBA_MID, 0);
  236. port_outb(base + REG_LBA_HI, 0);
  237. port_outb(base + REG_CMD, CMD_IDENTIFY);
  238. ata_400ns(base);
  239. t0 = get_ticks_ms();
  240. for (;;) {
  241. st = port_inb(base + REG_CMD);
  242. if (st == 0 || st == 0xFF) /* floating bus: no device */
  243. return -1;
  244. if (!(st & SR_BSY))
  245. break;
  246. if (get_ticks_ms() - t0 > ATA_TIMEOUT_MS)
  247. return -1;
  248. }
  249. if (!(st & SR_DRQ))
  250. return -1;
  251. for (i = 0; i < 256; i++)
  252. id[i] = port_inw(base + REG_DATA);
  253. return 0;
  254. }
  255. int ata_identify_parse(const unsigned short *id, unsigned int *total_sectors, char model[41])
  256. {
  257. unsigned int sectors, lo, hi, i;
  258. if (id[0] & 0x8000) /* ATAPI (cdrom/zip): not a data disk */
  259. return -1;
  260. /* Model string: words 27..46, byte-swapped. */
  261. for (i = 0; i < 20; i++) {
  262. unsigned short w = id[27 + i];
  263. model[i * 2] = (char)(w >> 8);
  264. model[i * 2 + 1] = (char)(w & 0xFF);
  265. }
  266. model[40] = '\0';
  267. for (i = 40; i > 0; i--) {
  268. if (model[i - 1] == ' ')
  269. model[i - 1] = '\0';
  270. else
  271. break;
  272. }
  273. sectors = (unsigned int)id[60] | ((unsigned int)id[61] << 16);
  274. if (id[83] & 0x0400) { /* LBA48 supported */
  275. lo = (unsigned int)id[100] | ((unsigned int)id[101] << 16);
  276. hi = (unsigned int)id[102] | ((unsigned int)id[103] << 16);
  277. if (lo || hi)
  278. sectors = lo;
  279. if (hi)
  280. sectors = 0xFFFFFFFFu; /* > 2 TB: clamp to 32-bit LBA */
  281. }
  282. *total_sectors = sectors;
  283. return 0;
  284. }
  285. int ata_probe(int bus, int unit, unsigned int *total_sectors, char model[41])
  286. {
  287. static unsigned short id[256];
  288. int r;
  289. if (ata_identify(bus, unit, id) != 0)
  290. return -1;
  291. r = ata_identify_parse(id, total_sectors, model);
  292. if (r == 0)
  293. ata_lba48[bus] = (id[83] & 0x0400) != 0;
  294. return r;
  295. }
  296. static void ata_log_failure(int write, unsigned int lba, unsigned int count,
  297. const char *what, unsigned short base)
  298. {
  299. unsigned char st = port_inb(base + REG_CMD);
  300. unsigned char err = port_inb(base + REG_ERROR);
  301. serial_puts(SERIAL_COM1, "ata: ");
  302. serial_puts(SERIAL_COM1, write ? "write" : "read");
  303. serial_puts(SERIAL_COM1, " failed (");
  304. serial_puts(SERIAL_COM1, what);
  305. serial_puts(SERIAL_COM1, ") lba ");
  306. serial_putdec(SERIAL_COM1, lba);
  307. serial_puts(SERIAL_COM1, " count ");
  308. serial_putdec(SERIAL_COM1, count);
  309. serial_puts(SERIAL_COM1, " status ");
  310. serial_puthex(SERIAL_COM1, st);
  311. serial_puts(SERIAL_COM1, " error ");
  312. serial_puthex(SERIAL_COM1, err);
  313. serial_puts(SERIAL_COM1, " cnt ");
  314. serial_puthex(SERIAL_COM1, port_inb(base + REG_COUNT));
  315. serial_puts(SERIAL_COM1, " lba ");
  316. serial_puthex(SERIAL_COM1,
  317. port_inb(base + REG_LBA_LO) |
  318. (port_inb(base + REG_LBA_MID) << 8) |
  319. (port_inb(base + REG_LBA_HI) << 16));
  320. serial_putc(SERIAL_COM1, '\n');
  321. }
  322. /* Use explicit 16-bit port reads/writes instead of `rep ins/outs`. The
  323. * string form writes through ES:EDI; the C loop uses the normal data
  324. * segment and is the same path IDENTIFY already uses successfully on the
  325. * real MCP79 board. A sector is only 256 words, so the speed difference
  326. * is small compared with the drive's PIO timing. */
  327. static void ata_insw(unsigned short port, void *dst, unsigned int count)
  328. {
  329. unsigned short *p = (unsigned short *)dst;
  330. while (count--)
  331. *p++ = port_inw(port);
  332. }
  333. static void ata_outsw(unsigned short port, const void *src, unsigned int count)
  334. {
  335. const unsigned short *p = (const unsigned short *)src;
  336. while (count--)
  337. port_outw(port, *p++);
  338. }
  339. static int ata_xfer(int bus, int unit, unsigned int lba, void *buf,
  340. unsigned int count, int write)
  341. {
  342. unsigned short base = ata_base[bus];
  343. unsigned char *p = buf;
  344. unsigned int done = 0, i;
  345. if (ata_wait_idle(base, 1000) != 0)
  346. ata_reset_channel(base, ata_ctrl[bus]);
  347. while (done < count) {
  348. unsigned int chunk = count - done;
  349. int lba48;
  350. unsigned int cur = lba + done;
  351. if (ata_single[bus])
  352. chunk = 1;
  353. else if (chunk > 255)
  354. chunk = 255;
  355. lba48 = ata_lba48[bus] ||
  356. ((cur + chunk - 1) >= 0x10000000u);
  357. {
  358. unsigned char cmd;
  359. if (lba48) {
  360. port_outb(base + REG_DRIVE, (unsigned char)(0x40 | (unit << 4)));
  361. port_outb(base + REG_COUNT, (unsigned char)(chunk >> 8));
  362. port_outb(base + REG_LBA_LO, (unsigned char)(cur >> 24));
  363. port_outb(base + REG_LBA_MID, 0);
  364. port_outb(base + REG_LBA_HI, 0);
  365. port_outb(base + REG_COUNT, (unsigned char)(chunk & 0xFF));
  366. port_outb(base + REG_LBA_LO, (unsigned char)(cur & 0xFF));
  367. port_outb(base + REG_LBA_MID, (unsigned char)((cur >> 8) & 0xFF));
  368. port_outb(base + REG_LBA_HI, (unsigned char)((cur >> 16) & 0xFF));
  369. cmd = (unsigned char)(write ? CMD_WRITE_EXT : CMD_READ_EXT);
  370. } else {
  371. port_outb(base + REG_DRIVE,
  372. (unsigned char)(0xE0 | (unit << 4) | ((cur >> 24) & 0x0F)));
  373. port_outb(base + REG_COUNT, (unsigned char)(chunk & 0xFF));
  374. port_outb(base + REG_LBA_LO, (unsigned char)(cur & 0xFF));
  375. port_outb(base + REG_LBA_MID, (unsigned char)((cur >> 8) & 0xFF));
  376. port_outb(base + REG_LBA_HI, (unsigned char)((cur >> 16) & 0xFF));
  377. cmd = (unsigned char)(write ? CMD_WRITE : CMD_READ);
  378. }
  379. if (!ata_tf_logged) {
  380. ata_tf_logged = 1;
  381. serial_puts(SERIAL_COM1, "ata: tf cnt ");
  382. serial_puthex(SERIAL_COM1, port_inb(base + REG_COUNT));
  383. serial_puts(SERIAL_COM1, " lba ");
  384. serial_puthex(SERIAL_COM1,
  385. port_inb(base + REG_LBA_LO) |
  386. (port_inb(base + REG_LBA_MID) << 8) |
  387. (port_inb(base + REG_LBA_HI) << 16));
  388. serial_puts(SERIAL_COM1, " drv ");
  389. serial_puthex(SERIAL_COM1, port_inb(base + REG_DRIVE));
  390. serial_puts(SERIAL_COM1, " cmd ");
  391. serial_puthex(SERIAL_COM1, cmd);
  392. serial_putc(SERIAL_COM1, '\n');
  393. }
  394. port_outb(base + REG_CMD, cmd);
  395. }
  396. ata_400ns(base);
  397. /* PIO transfers must wait for DRQ before *each* sector: the
  398. * drive drops DRQ between sectors while it commits the previous
  399. * one, and writing into the data register while DRQ is low is
  400. * silently lost. A single rep outsw over a large chunk looked
  401. * fine for one sector but left the drive waiting for more data
  402. * (DRQ set, count/LBA registers advanced), so the next command
  403. * read stale data and a large format eventually failed. */
  404. for (i = 0; i < chunk; i++) {
  405. if (ata_wait_not_busy(base, ATA_TIMEOUT_MS) != 0) {
  406. ata_log_failure(write, cur + i, 1,
  407. "busy timeout", base);
  408. goto xfer_fail;
  409. }
  410. if (ata_wait_drq(base, ATA_TIMEOUT_MS) != 0) {
  411. ata_log_failure(write, cur + i, 1,
  412. "drq timeout", base);
  413. goto xfer_fail;
  414. }
  415. if (write)
  416. ata_outsw(base + REG_DATA, p + i * 512, 256);
  417. else
  418. ata_insw(base + REG_DATA, p + i * 512, 256);
  419. }
  420. /* Let the last sector finish before the next command. */
  421. if (ata_wait_idle(base, ATA_COMPLETE_TIMEOUT_MS) != 0) {
  422. ata_log_failure(write, cur, chunk, "completion timeout", base);
  423. goto xfer_fail;
  424. }
  425. if (port_inb(base + REG_CMD) & SR_ERR) {
  426. ata_log_failure(write, cur, chunk, "transfer error", base);
  427. goto xfer_fail;
  428. }
  429. p += chunk * 512;
  430. done += chunk;
  431. continue;
  432. xfer_fail:
  433. ata_reset_channel(base, ata_ctrl[bus]);
  434. if (ata_single[bus])
  435. return -1;
  436. /* A multi-sector command upset this bridge; retry from the same
  437. * sector with one ATA command per sector. */
  438. ata_single[bus] = 1;
  439. serial_puts(SERIAL_COM1, "ata: switching to single-sector PIO\n");
  440. }
  441. return 0;
  442. }
  443. int ata_read_sectors(int bus, int unit, unsigned int lba, void *buf, unsigned int count)
  444. {
  445. return ata_xfer(bus, unit, lba, buf, count, 0);
  446. }
  447. int ata_write_sectors(int bus, int unit, unsigned int lba, const void *buf, unsigned int count)
  448. {
  449. return ata_xfer(bus, unit, lba, (void *)buf, count, 1);
  450. }
  451. int ata_flush(int bus, int unit)
  452. {
  453. unsigned short base;
  454. if (bus < 0 || bus > 1)
  455. return -1;
  456. base = ata_base[bus];
  457. if (ata_wait_idle(base, 1000) != 0)
  458. ata_reset_channel(base, ata_ctrl[bus]);
  459. port_outb(base + REG_DRIVE, (unsigned char)(0xA0 | (unit << 4)));
  460. port_outb(base + REG_CMD, 0xE7); /* FLUSH CACHE */
  461. ata_400ns(base);
  462. if (ata_wait_idle(base, ATA_TIMEOUT_MS) != 0) {
  463. ata_log_failure(1, 0, 0, "cache flush timeout", base);
  464. ata_reset_channel(base, ata_ctrl[bus]);
  465. return -1;
  466. }
  467. if (port_inb(base + REG_CMD) & SR_ERR) {
  468. ata_log_failure(1, 0, 0, "cache flush error", base);
  469. ata_reset_channel(base, ata_ctrl[bus]);
  470. return -1;
  471. }
  472. return 0;
  473. }