PCI IDE Controller: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
No edit summary
Line 68: Line 68:
IRQs are really a problem for IDEs, because the IDE uses IRQs 14 and 15, if it is a Parallel IDE.
IRQs are really a problem for IDEs, because the IDE uses IRQs 14 and 15, if it is a Parallel IDE.
If it is a Serial IDE, it uses another IRQ and only one IRQ, but how does we know the IRQs used by IDE? In Quafios it is quite easy:
If it is a Serial IDE, it uses another IRQ and only one IRQ, but how does we know the IRQs used by IDE? In Quafios it is quite easy:

<source lang="c">
outl((1<<31) | (bus<<16) | (device<<11) | (func<<8) | 8, 0xCF8); // Send the parameters.
if ((class = inl(0xCFC)>>16) != 0xFFFF) { // If there is exactly a device
// Check if this device need an IRQ assignment:
outl((1<<31) | (bus<<16) | (device<<11) | (func<<8) | 0x3C, 0xCF8);
outb(0xFE, 0xCFC); // Change the IRQ field to 0xFE
outl((1<<31) | (bus<<16) | (device<<11) | (func<<8) | 0x3C, 0xCF8); // Read the IRQ Field Again.
if ((inl(0xCFC) & 0xFF)==0xFE) {
// This Device needs IRQ assignment.
} else {
// The Device doesn't use IRQs, check if this is an Parallel IDE:
if (class == 0x01 && subclass == 0x01 && (ProgIF == 0x8A || ProgIF == 0x80)) {
// This is a Parallel IDE Controller which use IRQ 14 and IRQ 15.
}
}
}
</source>

By this way, you can make a structure with PCI Devices, each device has IRQ0 and IRQ1, the both should have an initial value of 0xFF [No IRQ]. if we detect a PCI Device, if the Device needs an IRQ, we can change IRQ0. if the device on PCI doesn't need, but it is a Parallel IDE, we can edit IRQ0 to 14 and IRQ1 to 15.

When an IRQ is invoked, ISR should read the IRQ number from PIC, then it searches for the device which has this IRQ [in IRQ0 or IRQ1], and if the device is found, call the device driver to inform it that an IRQ is invoked.

Revision as of 10:42, 8 November 2009

IDE is a keyword points to the semi-conductors on the mother-board that controls ATA Drives(like ATA Hard-Disks). ATA (AT-Attachment) is the interface of this drives. IDE also can be an IDE card connected to PCI.

ATAPI is an extension to ATA. ATAPI (ATA Packet Interface) adds the support of Drives wich uses SCSI Command-Set (like ODDs (Optical Disk Drives .e.g CD-ROMs, DVD-ROMs), Tape Drives, and ZIP Drives).

Parallel/Serial ATA/ATAPI

IDE can allow even 4 drives to be connected to. Each drive may be:

  • 1. Parallel AT-Attachment [PATA]: Like PATA HDDs.
  • 2. Parallel AT-Attachment Packet-Interface [PATAPI]: Like PATAPI ODDs.
  • 3. Serial ATA [SATA]: Like SATA HDDs.
  • 4. Serial ATAPI [SATAPI]: Like SATAPI ODDs.

We can ignore Tape Drives and ZIP Drives as they are obseleted. The Way of accessing ATA Drives is one, means that the way of accessing PATA HDDs is the same of SATA HDDs. also the way of accessing PATAPI ODDs is the same of SATAPI ODDs. For that, for IDE Device Driver, it is not required to know if a drive is Parallel or Serial, but it is important to know if it is ATA or ATAPI.

IDE Interface

File:Ide-motherboard-connectors.jpg
The white and green ports are the Parallel IDE ports on the motherboard.
File:PATA-Cable.jpg
PATA Cable which is connected to Parallel IDE Ports on motherboard.
File:SATA-motherboard.jpg
4 Serial IDE Ports on the motherboard.
File:SATA-Cable.gif
SATA Cable connected to SATA Ports on the motherboard, or on a Serial IDE Card Connected to PCI.

If you open your case and look at the mother board, we will see a port or two like these in the picture to the right.

The white and green ports are IDE Ports, each port of them is called channel. so there is:

  • Primary IDE Channel.
  • Secondary IDE Channel.

These Ports allows only Parallel Drives to be connected to, means that it supports only PATA/PATAPI Drives.



Each Port can has a PATA cable connected to, it is like this in the photo to the right. One master drive, or two drives [Master and Slave] can be connected to one PATA Cable. So we can have:

  • Primary Master Drive.
  • Primary Slave Drive.
  • Secondary Master Drive.
  • Secondary Slave Drive.

Each Drive May be: PATA or PATAPI.




But What about Serial IDE? Almost many of modern motherboards have a Serial IDE which allows SATA and SATAPI Drives to be connected to. Serial IDE Ports are 4, like these appear in the photo to the right, Each Port is conducted with a Serial ATA (SATA) Cable. So from the pictures we can understand that only one drive can be connected to Serial IDE Port, each two ports make a channel, and also Serial IDE has:

  • Primary Master Drive [Port1, or Port 2], also called [SATA1] in BIOS Setup Utility.
  • Primary Slave Drive [Port 1 or Port 2], also called [SATA2] in BIOS Setup Utility.
  • Secondary Master Drive [Port 3 or Port 4], also called [SATA3] in BIOS Setup Utility.
  • Secondary Slave Drive [Port 3 or Port 4], also called [SATA4] in BIOS Setup Utility.

Detecting an IDE

Please if you wanna support only the Parallel IDE, skip the part of [Detecting an IDE]. Each IDE appears as a device [in PCI World, it is called a function] on PCI Bus. If you don't know about PCI, please refer to PCI. When you find a device on PCI, you should determine whether it is an IDE Device or not, this is determined according to Class Code and Subclass code. If Class code is: 0x01 [Mass Storage Controller] and Subclass Code is: 0x01 [IDE], so this device is an IDE Device. We know all that each PCI Device has 6 BARs, ok, only 5 BARs are used by IDE Device:

  • BAR0: Base Address of Primary Channel I/O Ports, if it is 0x0 or 0x1, this means [0x1F0].
  • BAR1: Base Address of Priamry Channel Control Ports, if it is 0x0 or 0x1, this means [0x3F4].
  • BAR2: Base Address of Secondary Channel I/O Ports, if it is 0x0 or 0x1, this means [0x170].
  • BAR3: Base Address of Secondary Channel Control Ports, if it is 0x0 or 0x1, this means [0x374].
  • BAR4: Bus Master IDE, this I/O Address refers to the base of I/O range consists of 16 ports, each 8 ports controls DMA on a channel.

IRQs are really a problem for IDEs, because the IDE uses IRQs 14 and 15, if it is a Parallel IDE. If it is a Serial IDE, it uses another IRQ and only one IRQ, but how does we know the IRQs used by IDE? In Quafios it is quite easy:

outl((1<<31) | (bus<<16) | (device<<11) | (func<<8) | 8, 0xCF8); // Send the parameters.
if ((class = inl(0xCFC)>>16) != 0xFFFF) { // If there is exactly a device
   // Check if this device need an IRQ assignment:
   outl((1<<31) | (bus<<16) | (device<<11) | (func<<8) | 0x3C, 0xCF8);
   outb(0xFE, 0xCFC); // Change the IRQ field to 0xFE
   outl((1<<31) | (bus<<16) | (device<<11) | (func<<8) | 0x3C, 0xCF8); // Read the IRQ Field Again.
   if ((inl(0xCFC) & 0xFF)==0xFE) {
      // This Device needs IRQ assignment.
   } else {
      // The Device doesn't use IRQs, check if this is an Parallel IDE:
      if (class == 0x01 && subclass == 0x01 && (ProgIF == 0x8A || ProgIF == 0x80)) {
         // This is a Parallel IDE Controller which use IRQ 14 and IRQ 15.
      }
   }
}

By this way, you can make a structure with PCI Devices, each device has IRQ0 and IRQ1, the both should have an initial value of 0xFF [No IRQ]. if we detect a PCI Device, if the Device needs an IRQ, we can change IRQ0. if the device on PCI doesn't need, but it is a Parallel IDE, we can edit IRQ0 to 14 and IRQ1 to 15.

When an IRQ is invoked, ISR should read the IRQ number from PIC, then it searches for the device which has this IRQ [in IRQ0 or IRQ1], and if the device is found, call the device driver to inform it that an IRQ is invoked.