1 // Low level ATA disk access
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
8 #include "types.h" // u8
9 #include "ioport.h" // inb
10 #include "util.h" // dprintf
11 #include "cmos.h" // inb_cmos
12 #include "pic.h" // enable_hwirq
13 #include "biosvar.h" // GET_EBDA
14 #include "pci.h" // pci_find_class
15 #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER
16 #include "pci_regs.h" // PCI_INTERRUPT_LINE
17 #include "boot.h" // add_bcv_hd
18 #include "disk.h" // struct ata_s
19 #include "atabits.h" // ATA_CB_STAT
25 #define NOT_BSY_NOT_DRQ 4
28 #define IDE_SECTOR_SIZE 512
29 #define CDROM_SECTOR_SIZE 2048
31 #define IDE_TIMEOUT 32000 //32 seconds max for IDE ops
33 struct ata_s ATA VAR16_32;
36 /****************************************************************
38 ****************************************************************/
40 // Wait for the specified ide state
42 await_ide(u8 mask, u8 flags, u16 base, u16 timeout)
44 u64 end = calc_future_tsc(timeout);
46 u8 status = inb(base+ATA_CB_STAT);
47 if ((status & mask) == flags)
49 if (rdtscll() > end) {
50 dprintf(1, "IDE time out\n");
56 // Wait for the device to be not-busy.
58 await_not_bsy(u16 base)
60 return await_ide(ATA_CB_STAT_BSY, 0, base, IDE_TIMEOUT);
63 // Wait for the device to be ready.
67 return await_ide(ATA_CB_STAT_RDY, ATA_CB_STAT_RDY, base, IDE_TIMEOUT);
70 // Wait for ide state - pauses for one ata cycle first.
72 pause_await_not_bsy(u16 iobase1, u16 iobase2)
74 // Wait one PIO transfer cycle.
75 inb(iobase2 + ATA_CB_ASTAT);
77 return await_not_bsy(iobase1);
80 // Wait for ide state - pause for 400ns first.
82 ndelay_await_not_bsy(u16 iobase1)
85 return await_not_bsy(iobase1);
90 ata_reset(int driveid)
92 u8 channel = driveid / 2;
93 u8 slave = driveid % 2;
94 u16 iobase1 = GET_GLOBAL(ATA.channels[channel].iobase1);
95 u16 iobase2 = GET_GLOBAL(ATA.channels[channel].iobase2);
97 dprintf(6, "ata_reset driveid=%d\n", driveid);
99 outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN | ATA_CB_DC_SRST, iobase2+ATA_CB_DC);
101 outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN, iobase2+ATA_CB_DC);
104 // wait for device to become not busy.
105 int status = await_not_bsy(iobase1);
110 u64 end = calc_future_tsc(IDE_TIMEOUT);
112 outb(ATA_CB_DH_DEV1, iobase1 + ATA_CB_DH);
113 status = ndelay_await_not_bsy(iobase1);
116 if (inb(iobase1 + ATA_CB_DH) == ATA_CB_DH_DEV1)
118 // Change drive request failed to take effect - retry.
119 if (rdtscll() > end) {
120 dprintf(1, "ata_reset slave time out\n");
126 // On a user-reset request, wait for RDY if it is an ATA device.
127 u8 type=GET_GLOBAL(ATA.devices[driveid].type);
128 if (type == ATA_TYPE_ATA)
129 status = await_rdy(iobase1);
133 outb(ATA_CB_DC_HD15, iobase2+ATA_CB_DC);
135 dprintf(6, "ata_reset exit status=%x\n", status);
139 /****************************************************************
141 ****************************************************************/
143 struct ata_pio_command {
158 // Send an ata command to the drive.
160 send_cmd(int driveid, struct ata_pio_command *cmd)
162 u8 channel = driveid / 2;
163 u8 slave = driveid % 2;
164 u16 iobase1 = GET_GLOBAL(ATA.channels[channel].iobase1);
165 u16 iobase2 = GET_GLOBAL(ATA.channels[channel].iobase2);
167 // Disable interrupts
168 outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN, iobase2 + ATA_CB_DC);
171 int status = await_not_bsy(iobase1);
174 u8 newdh = ((cmd->device & ~ATA_CB_DH_DEV1)
175 | (slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0));
176 u8 olddh = inb(iobase1 + ATA_CB_DH);
177 outb(newdh, iobase1 + ATA_CB_DH);
178 if ((olddh ^ newdh) & (1<<4)) {
179 // Was a device change - wait for device to become not busy.
180 status = ndelay_await_not_bsy(iobase1);
185 if (cmd->command & 0x04) {
186 outb(0x00, iobase1 + ATA_CB_FR);
187 outb(cmd->sector_count2, iobase1 + ATA_CB_SC);
188 outb(cmd->lba_low2, iobase1 + ATA_CB_SN);
189 outb(cmd->lba_mid2, iobase1 + ATA_CB_CL);
190 outb(cmd->lba_high2, iobase1 + ATA_CB_CH);
192 outb(cmd->feature, iobase1 + ATA_CB_FR);
193 outb(cmd->sector_count, iobase1 + ATA_CB_SC);
194 outb(cmd->lba_low, iobase1 + ATA_CB_SN);
195 outb(cmd->lba_mid, iobase1 + ATA_CB_CL);
196 outb(cmd->lba_high, iobase1 + ATA_CB_CH);
197 outb(cmd->command, iobase1 + ATA_CB_CMD);
199 status = ndelay_await_not_bsy(iobase1);
203 if (status & ATA_CB_STAT_ERR) {
204 dprintf(6, "send_cmd : read error (status=%02x err=%02x)\n"
205 , status, inb(iobase1 + ATA_CB_ERR));
208 if (!(status & ATA_CB_STAT_DRQ)) {
209 dprintf(6, "send_cmd : DRQ not set (status %02x)\n", status);
217 /****************************************************************
219 ****************************************************************/
221 // Transfer 'op->count' blocks (of 'blocksize' bytes) to/from drive
224 ata_transfer(struct disk_op_s *op, int iswrite, int blocksize)
226 dprintf(16, "ata_transfer id=%d write=%d count=%d bs=%d buf=%p\n"
227 , op->driveid, iswrite, op->count, blocksize, op->buf_fl);
229 u8 channel = op->driveid / 2;
230 u16 iobase1 = GET_GLOBAL(ATA.channels[channel].iobase1);
231 u16 iobase2 = GET_GLOBAL(ATA.channels[channel].iobase2);
232 int count = op->count;
233 void *buf_fl = op->buf_fl;
237 // Write data to controller
238 dprintf(16, "Write sector id=%d dest=%p\n", op->driveid, buf_fl);
239 if (CONFIG_ATA_PIO32)
240 outsl_fl(iobase1, buf_fl, blocksize / 4);
242 outsw_fl(iobase1, buf_fl, blocksize / 2);
244 // Read data from controller
245 dprintf(16, "Read sector id=%d dest=%p\n", op->driveid, buf_fl);
246 if (CONFIG_ATA_PIO32)
247 insl_fl(iobase1, buf_fl, blocksize / 4);
249 insw_fl(iobase1, buf_fl, blocksize / 2);
253 status = pause_await_not_bsy(iobase1, iobase2);
263 status &= (ATA_CB_STAT_BSY | ATA_CB_STAT_DRQ | ATA_CB_STAT_ERR);
264 if (status != ATA_CB_STAT_DRQ) {
265 dprintf(6, "ata_transfer : more sectors left (status %02x)\n"
272 status &= (ATA_CB_STAT_BSY | ATA_CB_STAT_DF | ATA_CB_STAT_DRQ
275 status &= ~ATA_CB_STAT_DF;
277 dprintf(6, "ata_transfer : no sectors left (status %02x)\n", status);
282 outb(ATA_CB_DC_HD15, iobase2+ATA_CB_DC);
287 /****************************************************************
288 * ATA hard drive functions
289 ****************************************************************/
291 // Read/write count blocks from a harddrive.
293 ata_cmd_data(struct disk_op_s *op)
297 struct ata_pio_command cmd;
298 memset(&cmd, 0, sizeof(cmd));
300 cmd.command = op->command;
301 if (op->count >= (1<<8) || lba + op->count >= (1<<28)) {
302 cmd.sector_count2 = op->count >> 8;
303 cmd.lba_low2 = lba >> 24;
304 cmd.lba_mid2 = lba >> 32;
305 cmd.lba_high2 = lba >> 40;
312 cmd.sector_count = op->count;
314 cmd.lba_mid = lba >> 8;
315 cmd.lba_high = lba >> 16;
316 cmd.device = ((lba >> 24) & 0xf) | ATA_CB_DH_LBA;
318 int ret = send_cmd(op->driveid, &cmd);
321 return ata_transfer(op, op->command == ATA_CMD_WRITE_SECTORS
326 /****************************************************************
328 ****************************************************************/
330 // Low-level atapi command transmit function.
332 send_atapi_cmd(int driveid, u8 *cmdbuf, u8 cmdlen, u16 blocksize)
334 u8 channel = driveid / 2;
335 u16 iobase1 = GET_GLOBAL(ATA.channels[channel].iobase1);
336 u16 iobase2 = GET_GLOBAL(ATA.channels[channel].iobase2);
338 struct ata_pio_command cmd;
339 cmd.sector_count = 0;
342 cmd.lba_mid = blocksize;
343 cmd.lba_high = blocksize >> 8;
345 cmd.command = ATA_CMD_PACKET;
347 int ret = send_cmd(driveid, &cmd);
351 // Send command to device
352 outsw_fl(iobase1, MAKE_FLATPTR(GET_SEG(SS), cmdbuf), cmdlen / 2);
354 int status = pause_await_not_bsy(iobase1, iobase2);
358 if (status & ATA_CB_STAT_ERR) {
359 u8 err = inb(iobase1 + ATA_CB_ERR);
362 dprintf(6, "send_atapi_cmd : read error (status=%02x err=%02x)\n"
366 if (!(status & ATA_CB_STAT_DRQ)) {
367 dprintf(6, "send_atapi_cmd : DRQ not set (status %02x)\n", status);
374 // Read sectors from the cdrom.
376 cdrom_read(struct disk_op_s *op)
379 memset(atacmd, 0, sizeof(atacmd));
380 atacmd[0]=0x28; // READ command
381 atacmd[7]=(op->count & 0xff00) >> 8; // Sectors
382 atacmd[8]=(op->count & 0x00ff);
383 atacmd[2]=(op->lba & 0xff000000) >> 24; // LBA
384 atacmd[3]=(op->lba & 0x00ff0000) >> 16;
385 atacmd[4]=(op->lba & 0x0000ff00) >> 8;
386 atacmd[5]=(op->lba & 0x000000ff);
388 int ret = send_atapi_cmd(op->driveid, atacmd, sizeof(atacmd)
389 , CDROM_SECTOR_SIZE);
393 return ata_transfer(op, 0, CDROM_SECTOR_SIZE);
396 // Send a simple atapi command to a drive.
398 ata_cmd_packet(int driveid, u8 *cmdbuf, u8 cmdlen
399 , u32 length, void *buf_fl)
401 int ret = send_atapi_cmd(driveid, cmdbuf, cmdlen, length);
405 struct disk_op_s dop;
406 memset(&dop, 0, sizeof(dop));
407 dop.driveid = driveid;
411 return ata_transfer(&dop, 0, length);
415 /****************************************************************
416 * Disk geometry translation
417 ****************************************************************/
420 get_translation(int driveid)
422 if (! CONFIG_COREBOOT) {
423 // Emulators pass in the translation info via nvram.
424 u8 channel = driveid / 2;
425 u8 translation = inb_cmos(CMOS_BIOS_DISKTRANSFLAG + channel/2);
426 translation >>= 2 * (driveid % 4);
431 // On COREBOOT, use a heuristic to determine translation type.
432 u16 heads = GET_GLOBAL(ATA.devices[driveid].pchs.heads);
433 u16 cylinders = GET_GLOBAL(ATA.devices[driveid].pchs.cylinders);
434 u16 spt = GET_GLOBAL(ATA.devices[driveid].pchs.spt);
436 if (cylinders <= 1024 && heads <= 16 && spt <= 63)
437 return ATA_TRANSLATION_NONE;
438 if (cylinders * heads <= 131072)
439 return ATA_TRANSLATION_LARGE;
440 return ATA_TRANSLATION_LBA;
444 setup_translation(int driveid)
446 u8 translation = get_translation(driveid);
447 SET_GLOBAL(ATA.devices[driveid].translation, translation);
449 u8 channel = driveid / 2;
450 u8 slave = driveid % 2;
451 u16 heads = GET_GLOBAL(ATA.devices[driveid].pchs.heads);
452 u16 cylinders = GET_GLOBAL(ATA.devices[driveid].pchs.cylinders);
453 u16 spt = GET_GLOBAL(ATA.devices[driveid].pchs.spt);
454 u64 sectors = GET_GLOBAL(ATA.devices[driveid].sectors);
456 dprintf(1, "ata%d-%d: PCHS=%u/%d/%d translation="
457 , channel, slave, cylinders, heads, spt);
458 switch (translation) {
459 case ATA_TRANSLATION_NONE:
462 case ATA_TRANSLATION_LBA:
465 if (sectors > 63*255*1024) {
470 u32 sect = (u32)sectors / 63;
482 cylinders = sect / heads;
484 case ATA_TRANSLATION_RECHS:
485 dprintf(1, "r-echs");
486 // Take care not to overflow
491 cylinders = (u16)((u32)(cylinders)*16/15);
493 // then go through the large bitshift process
494 case ATA_TRANSLATION_LARGE:
495 if (translation == ATA_TRANSLATION_LARGE)
497 while (cylinders > 1024) {
501 // If we max out the head count
507 // clip to 1024 cylinders in lchs
508 if (cylinders > 1024)
510 dprintf(1, " LCHS=%d/%d/%d\n", cylinders, heads, spt);
512 SET_GLOBAL(ATA.devices[driveid].lchs.heads, heads);
513 SET_GLOBAL(ATA.devices[driveid].lchs.cylinders, cylinders);
514 SET_GLOBAL(ATA.devices[driveid].lchs.spt, spt);
518 /****************************************************************
519 * ATA detect and init
520 ****************************************************************/
522 // Extract common information from IDENTIFY commands.
524 extract_identify(int driveid, u16 *buffer)
526 dprintf(3, "Identify w0=%x w2=%x\n", buffer[0], buffer[2]);
529 char *model = ATA.devices[driveid].model;
530 int maxsize = ARRAY_SIZE(ATA.devices[driveid].model);
532 for (i=0; i<maxsize/2; i++) {
533 u16 v = buffer[27+i];
535 model[i*2+1] = v & 0xff;
537 model[maxsize-1] = 0x00;
539 // Trim trailing spaces from model name.
540 for (i=maxsize-2; i>0 && model[i] == 0x20; i--)
543 // Extract ATA/ATAPI version.
544 u16 ataversion = buffer[80];
546 for (version=15; version>0; version--)
547 if (ataversion & (1<<version))
549 ATA.devices[driveid].version = version;
552 SET_GLOBAL(ATA.devices[driveid].removable, (buffer[0] & 0x80) ? 1 : 0);
556 init_drive_atapi(int driveid, u16 *buffer)
558 // Send an IDENTIFY_DEVICE_PACKET command to device
559 memset(buffer, 0, IDE_SECTOR_SIZE);
560 struct disk_op_s dop;
561 dop.driveid = driveid;
562 dop.command = ATA_CMD_IDENTIFY_DEVICE_PACKET;
565 dop.buf_fl = MAKE_FLATPTR(GET_SEG(SS), buffer);
566 int ret = ata_cmd_data(&dop);
570 // Success - setup as ATAPI.
571 extract_identify(driveid, buffer);
572 SET_GLOBAL(ATA.devices[driveid].type, ATA_TYPE_ATAPI);
573 SET_GLOBAL(ATA.devices[driveid].device, (buffer[0] >> 8) & 0x1f);
574 SET_GLOBAL(ATA.devices[driveid].blksize, CDROM_SECTOR_SIZE);
577 u8 cdcount = GET_GLOBAL(ATA.cdcount);
578 SET_GLOBAL(ATA.idmap[1][cdcount], driveid);
579 SET_GLOBAL(ATA.cdcount, cdcount+1);
581 // Report drive info to user.
582 u8 channel = driveid / 2;
583 u8 slave = driveid % 2;
584 printf("ata%d-%d: %s ATAPI-%d %s\n", channel, slave
585 , ATA.devices[driveid].model, ATA.devices[driveid].version
586 , (ATA.devices[driveid].device == ATA_DEVICE_CDROM
587 ? "CD-Rom/DVD-Rom" : "Device"));
593 init_drive_ata(int driveid, u16 *buffer)
595 // Send an IDENTIFY_DEVICE command to device
596 memset(buffer, 0, IDE_SECTOR_SIZE);
597 struct disk_op_s dop;
598 dop.driveid = driveid;
599 dop.command = ATA_CMD_IDENTIFY_DEVICE;
602 dop.buf_fl = MAKE_FLATPTR(GET_SEG(SS), buffer);
603 int ret = ata_cmd_data(&dop);
607 // Success - setup as ATA.
608 extract_identify(driveid, buffer);
609 SET_GLOBAL(ATA.devices[driveid].type, ATA_TYPE_ATA);
610 SET_GLOBAL(ATA.devices[driveid].device, ATA_DEVICE_HD);
611 SET_GLOBAL(ATA.devices[driveid].blksize, IDE_SECTOR_SIZE);
613 SET_GLOBAL(ATA.devices[driveid].pchs.cylinders, buffer[1]);
614 SET_GLOBAL(ATA.devices[driveid].pchs.heads, buffer[3]);
615 SET_GLOBAL(ATA.devices[driveid].pchs.spt, buffer[6]);
618 if (buffer[83] & (1 << 10)) // word 83 - lba48 support
619 sectors = *(u64*)&buffer[100]; // word 100-103
621 sectors = *(u32*)&buffer[60]; // word 60 and word 61
622 SET_GLOBAL(ATA.devices[driveid].sectors, sectors);
624 // Setup disk geometry translation.
625 setup_translation(driveid);
627 // Report drive info to user.
628 u8 channel = driveid / 2;
629 u8 slave = driveid % 2;
630 char *model = ATA.devices[driveid].model;
631 printf("ata%d-%d: %s ATA-%d Hard-Disk ", channel, slave, model
632 , ATA.devices[driveid].version);
633 u64 sizeinmb = sectors >> 11;
634 if (sizeinmb < (1 << 16))
635 printf("(%u MiBytes)\n", (u32)sizeinmb);
637 printf("(%u GiBytes)\n", (u32)(sizeinmb >> 10));
639 // Register with bcv system.
640 add_bcv_hd(driveid, model);
646 powerup_await_non_bsy(u16 base, u64 end)
651 status = inb(base+ATA_CB_STAT);
652 if (!(status & ATA_CB_STAT_BSY))
655 if (orstatus == 0xff) {
656 dprintf(1, "powerup IDE floating\n");
659 if (rdtscll() > end) {
660 dprintf(1, "powerup IDE time out\n");
664 dprintf(6, "powerup iobase=%x st=%x\n", base, status);
672 u64 end = calc_future_tsc(IDE_TIMEOUT);
673 int driveid, last_reset_driveid=-1;
674 for(driveid=0; driveid<CONFIG_MAX_ATA_DEVICES; driveid++) {
675 u8 channel = driveid / 2;
676 u8 slave = driveid % 2;
678 u16 iobase1 = GET_GLOBAL(ATA.channels[channel].iobase1);
683 int status = powerup_await_non_bsy(iobase1, end);
686 u8 newdh = slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0;
687 outb(newdh, iobase1+ATA_CB_DH);
689 status = powerup_await_non_bsy(iobase1, end);
693 // Check if ioport registers look valid.
694 outb(newdh, iobase1+ATA_CB_DH);
695 u8 dh = inb(iobase1+ATA_CB_DH);
696 outb(0x55, iobase1+ATA_CB_SC);
697 outb(0xaa, iobase1+ATA_CB_SN);
698 u8 sc = inb(iobase1+ATA_CB_SC);
699 u8 sn = inb(iobase1+ATA_CB_SN);
700 dprintf(6, "ata_detect drive=%d sc=%x sn=%x dh=%x\n"
701 , driveid, sc, sn, dh);
702 if (sc != 0x55 || sn != 0xaa || dh != newdh)
706 if (slave && driveid == last_reset_driveid + 1) {
707 // The drive was just reset - no need to reset it again.
710 last_reset_driveid = driveid;
715 int ret = init_drive_atapi(driveid, buffer);
717 // Found an ATAPI drive.
719 u8 st = inb(iobase1+ATA_CB_STAT);
721 // Status not set - can't be a valid drive.
725 ret = await_rdy(iobase1);
730 ret = init_drive_ata(driveid, buffer);
732 // No ATA drive found
736 u16 resetresult = buffer[93];
737 dprintf(6, "ata_detect resetresult=%04x\n", resetresult);
738 if (!slave && (resetresult & 0xdf61) == 0x4041)
739 // resetresult looks valid and device 0 is responding to
740 // device 1 requests - device 1 must not be present - skip
751 memset(&ATA, 0, sizeof(ATA));
753 // hdidmap and cdidmap init.
755 for (device=0; device < CONFIG_MAX_ATA_DEVICES; device++) {
756 SET_GLOBAL(ATA.idmap[0][device], CONFIG_MAX_ATA_DEVICES);
757 SET_GLOBAL(ATA.idmap[1][device], CONFIG_MAX_ATA_DEVICES);
760 // Scan PCI bus for ATA adapters
763 foreachpci(bdf, max) {
764 if (pci_config_readw(bdf, PCI_CLASS_DEVICE) != PCI_CLASS_STORAGE_IDE)
766 if (count >= ARRAY_SIZE(ATA.channels))
769 u8 irq = pci_config_readb(bdf, PCI_INTERRUPT_LINE);
770 SET_GLOBAL(ATA.channels[count].irq, irq);
771 SET_GLOBAL(ATA.channels[count].pci_bdf, bdf);
773 u8 prog_if = pci_config_readb(bdf, PCI_CLASS_PROG);
777 port1 = pci_config_readl(bdf, PCI_BASE_ADDRESS_0) & ~3;
778 port2 = pci_config_readl(bdf, PCI_BASE_ADDRESS_1) & ~3;
783 SET_GLOBAL(ATA.channels[count].iobase1, port1);
784 SET_GLOBAL(ATA.channels[count].iobase2, port2);
785 dprintf(1, "ATA controller %d at %x/%x (dev %x prog_if %x)\n"
786 , count, port1, port2, bdf, prog_if);
790 port1 = pci_config_readl(bdf, PCI_BASE_ADDRESS_2) & ~3;
791 port2 = pci_config_readl(bdf, PCI_BASE_ADDRESS_3) & ~3;
796 dprintf(1, "ATA controller %d at %x/%x (dev %x prog_if %x)\n"
797 , count, port1, port2, bdf, prog_if);
798 SET_GLOBAL(ATA.channels[count].iobase1, port1);
799 SET_GLOBAL(ATA.channels[count].iobase2, port2);
810 dprintf(3, "init hard drives\n");
814 SET_BDA(disk_control_byte, 0xc0);
816 enable_hwirq(14, entry_76);
820 /****************************************************************
822 ****************************************************************/
824 // Fill in Fixed Disk Parameter Table (located in ebda).
826 fill_fdpt(int driveid)
831 u16 nlc = GET_GLOBAL(ATA.devices[driveid].lchs.cylinders);
832 u16 nlh = GET_GLOBAL(ATA.devices[driveid].lchs.heads);
833 u16 nlspt = GET_GLOBAL(ATA.devices[driveid].lchs.spt);
835 u16 npc = GET_GLOBAL(ATA.devices[driveid].pchs.cylinders);
836 u16 nph = GET_GLOBAL(ATA.devices[driveid].pchs.heads);
837 u16 npspt = GET_GLOBAL(ATA.devices[driveid].pchs.spt);
839 struct fdpt_s *fdpt = &get_ebda_ptr()->fdpt[driveid];
840 fdpt->precompensation = 0xffff;
841 fdpt->drive_control_byte = 0xc0 | ((nph > 8) << 3);
842 fdpt->landing_zone = npc;
843 fdpt->cylinders = nlc;
845 fdpt->sectors = nlspt;
847 if (nlc == npc && nlh == nph && nlspt == npspt)
848 // no logical CHS mapping used, just physical CHS
849 // use Standard Fixed Disk Parameter Table (FDPT)
852 // complies with Phoenix style Translated Fixed Disk Parameter
854 fdpt->phys_cylinders = npc;
855 fdpt->phys_heads = nph;
856 fdpt->phys_sectors = npspt;
857 fdpt->a0h_signature = 0xa0;
859 // Checksum structure.
860 fdpt->checksum -= checksum(fdpt, sizeof(*fdpt));
863 SET_IVT(0x41, get_ebda_seg()
864 , offsetof(struct extended_bios_data_area_s, fdpt[0]));
866 SET_IVT(0x46, get_ebda_seg()
867 , offsetof(struct extended_bios_data_area_s, fdpt[1]));
870 // Map a drive (that was registered via add_bcv_hd)
872 map_drive(int driveid)
875 u8 hdcount = GET_BDA(hdcount);
876 dprintf(3, "Mapping driveid %d to %d\n", driveid, hdcount);
877 SET_GLOBAL(ATA.idmap[0][hdcount], driveid);
878 SET_BDA(hdcount, hdcount + 1);
880 // Fill "fdpt" structure.