The Pedigree Project  0.1
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
AtaDisk Class Reference

#include <AtaDisk.h>

+ Inheritance diagram for AtaDisk:
+ Collaboration diagram for AtaDisk:

Classes

struct  Buffer
 

Public Member Functions

 AtaDisk (class AtaController *pDev, bool isMaster, IoBase *commandRegs, IoBase *controlRegs, BusMasterIde *busMaster=0)
 
virtual void getName (String &str)
 
bool initialise (size_t nUnit=~0)
 
virtual uint64_t doRead (uint64_t location)
 
virtual uint64_t doWrite (uint64_t location)
 
virtual void irqReceived ()
 
virtual BusMasterIdegetBusMaster () const
 
virtual size_t getSize () const
 Gets the size of the disk. More...
 
virtual size_t getBlockSize () const
 Gets the block size of the disk. More...
 
virtual size_t getNativeBlockSize () const
 
virtual size_t getBlockCount () const
 
virtual bool sendCommand (size_t nUnit, uintptr_t pCommand, uint8_t nCommandSize, uintptr_t pRespBuffer, uint16_t nRespBytes, bool bWrite)
 
- Public Member Functions inherited from ScsiDisk
bool initialise (class ScsiController *pController, size_t nUnit)
 
virtual uintptr_t read (uint64_t location)
 
virtual void write (uint64_t location)
 
virtual void flush (uint64_t location)
 Flush a cached page to disk. More...
 
virtual void align (uint64_t location)
 Sets the page boundary alignment after a specific location on the disk. More...
 
virtual uint64_t doSync (uint64_t location)
 
virtual void pin (uint64_t location)
 Pins a cache page. More...
 
virtual void unpin (uint64_t location)
 
- Public Member Functions inherited from Disk
 Disk (Device *p)
 
virtual Type getType ()
 
virtual SubType getSubType ()
 
virtual void dump (String &str)
 
virtual bool cacheIsCritical ()
 Whether or not the cache is critical and cannot be flushed or deleted. More...
 
- Public Member Functions inherited from Device
 Device (Device *p)
 
DevicegetParent () const
 
void setParent (Device *p)
 
virtual String getSpecificType ()
 
virtual void setSpecificType (String str)
 
void setPciPosition (uint32_t bus, uint32_t device, uint32_t func)
 
void setPciIdentifiers (uint8_t classCode, uint8_t subclassCode, uint16_t vendorId, uint16_t deviceId, uint8_t progIf)
 
void setPciConfigHeader (const PciBus::ConfigSpace &space)
 
PciBus::ConfigSpace getPciConfigHeader () const
 
uint8_t getPciClassCode ()
 
uint8_t getPciSubclassCode ()
 
uint16_t getPciVendorId ()
 
uint16_t getPciDeviceId ()
 
uint8_t getPciProgInterface ()
 
uint32_t getPciBusPosition ()
 
uint32_t getPciDevicePosition ()
 
uint32_t getPciFunctionNumber ()
 
virtual Vector< Address * > & addresses ()
 
virtual uintptr_t getInterruptNumber ()
 
virtual void setInterruptNumber (uintptr_t n)
 
void addChild (Device *pDevice)
 
DevicegetChild (size_t n)
 
size_t getNumChildren ()
 
void removeChild (size_t n)
 
void removeChild (Device *d)
 
void replaceChild (Device *src, Device *dest)
 

Private Types

enum  AtaDiskType {
  Block = 0x00, Sequential = 0x01, Printer = 0x02, Processor = 0x03,
  WriteOnce = 0x04, CdDvd = 0x05, OpticalMemory = 0x07, MediumChanger = 0x08,
  Raid = 0x0C, Enclosure = 0x0D, None = 0x1F, NotPacket = 0xFF
}
 

Private Member Functions

void setupLBA28 (uint64_t n, uint32_t nSectors)
 
void setupLBA48 (uint64_t n, uint32_t nSectors)
 
virtual size_t defaultBlockSize ()
 
void setFeatures (uint8_t command, uint8_t countreg, uint8_t lowreg, uint8_t midreg, uint8_t hireg)
 

Private Attributes

bool m_IsMaster
 
IdentifyData m_pIdent
 
char m_pName [64]
 
char m_pSerialNumber [64]
 
char m_pFirmwareRevision [64]
 
bool m_SupportsLBA28
 
bool m_SupportsLBA48
 
size_t m_BlockSize
 
Mutexm_IrqReceived
 
Mutex m_IrqLock
 
ConditionVariable m_IrqCondition
 
AtaDiskType m_AtaDiskType
 
uint8_t m_PacketSize
 
bool m_Removable
 
IoBasem_CommandRegs
 
IoBasem_ControlRegs
 
BusMasterIdem_BusMaster
 
Mutex m_PrdTableLock
 
PhysicalRegionDescriptor * m_PrdTable
 
size_t m_LastPrdTableOffset
 
physical_uintptr_t m_PrdTablePhys
 
MemoryRegion m_PrdTableMemRegion
 
bool m_bDma
 
Atomic< size_t > m_IrqCount
 

Additional Inherited Members

- Public Types inherited from Disk
enum  SubType { ATA = 0, ATAPI }
 
- Public Types inherited from Device
enum  Type {
  Generic, Root, Disk, Bus,
  Display, Network, Sound, Console,
  Mouse, Controller, UsbController, UsbGeneric,
  UsbContainer
}
 
typedef Device *(* Callback) (Device *)
 
- Static Public Member Functions inherited from Device
static void foreach (Callback callback, Device *root=0)
 
template<class F , class... Args>
static void foreach (pedigree_std::Callable< F > &callback, Device *root, Args...args)
 
static void addToRoot (Device *device)
 
static void searchByVendorId (uint16_t vendorId, void(*callback)(Device *), Device *root=0)
 
static void searchByVendorIdAndDeviceId (uint16_t vendorId, uint16_t deviceId, void(*callback)(Device *), Device *root=0)
 
static void searchByClass (uint16_t classCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassAndSubclass (uint16_t classCode, uint16_t subclassCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassSubclassAndProgInterface (uint16_t classCode, uint16_t subclassCode, uint8_t progInterface, void(*callback)(Device *), Device *root=0)
 
- Public Attributes inherited from ScsiDisk
struct ScsiDisk::Sense PACKED
 
struct ScsiDisk::Inquiry PACKED
 
struct ScsiDisk::Capacity PACKED
 
- Protected Member Functions inherited from ScsiDisk
CachegetCache ()
 
InquirygetInquiry () const
 
- Protected Member Functions inherited from Device
 NOT_COPYABLE_OR_ASSIGNABLE (Device)
 
- Static Protected Member Functions inherited from Device
static Deviceroot ()
 
- Protected Attributes inherited from Device
Vector< Address * > m_Addresses
 
Vector< Device * > m_Children
 
Devicem_pParent
 
uintptr_t m_InterruptNumber
 
String m_SpecificType
 
PciBus::ConfigSpace m_ConfigHeader
 
uint8_t m_ClassCode
 
uint8_t m_SubclassCode
 
uint16_t m_VendorId
 
uint16_t m_DeviceId
 
uint8_t m_ProgInterface
 
uint32_t m_PciBusPos
 
uint32_t m_PciDevicePos
 
uint32_t m_PciFunctionNum
 
- Static Protected Attributes inherited from Device
static Device m_Root
 
static Mutex m_TreeLock
 

Detailed Description

An ATA device.

This could be anything from an ATAPI device (eg, CDROM) to a pure and simple IDE disk. We inherit ScsiDisk as it is needed for ATAPI. Non-ATAPI disks simply don't use the ScsiDisk interface.

Definition at line 42 of file AtaDisk.h.

Member Function Documentation

virtual size_t AtaDisk::defaultBlockSize ( )
inlineprivatevirtual

Default block size for this device.

Reimplemented from ScsiDisk.

Definition at line 110 of file AtaDisk.h.

References m_AtaDiskType.

uint64_t AtaDisk::doRead ( uint64_t  location)
virtual
Todo:
getPageSize() here
Todo:
logical sector size here
Todo:
What's the best way to handle this?
Todo:
What's the best way to handle this?

Reimplemented from ScsiDisk.

Definition at line 681 of file AtaDisk.cc.

References ALIGN, assert, AtaDisk::Buffer::buffer, ScsiDisk::doRead(), ERROR, FATAL, Device::getInterruptNumber(), Processor::getInterrupts(), AtaDisk::Buffer::offset, IoBase::read16(), IoBase::read8(), AtaStatus::reg, Processor::setInterrupts(), WARNING, and IoBase::write8().

Referenced by IsaAtaController::executeRequest(), PciAtaController::executeRequest(), and getName().

+ Here is the caller graph for this function:

uint64_t AtaDisk::doWrite ( uint64_t  location)
virtual
Todo:
might still want to allow writes - assuming CDROM here...
Todo:
logical sector size here
Todo:
What's the best way to handle this?
Todo:
What's the best way to handle this?

Reimplemented from ScsiDisk.

Definition at line 943 of file AtaDisk.cc.

References FATAL, Device::getInterruptNumber(), Processor::getInterrupts(), NOTICE, panic(), IoBase::read8(), AtaStatus::reg, Processor::setInterrupts(), WARNING, IoBase::write16(), and IoBase::write8().

Referenced by IsaAtaController::executeRequest(), PciAtaController::executeRequest(), and getName().

+ Here is the caller graph for this function:

size_t AtaDisk::getBlockSize ( ) const
virtual

Gets the block size of the disk.

This is the native block size with which all reads and writes are performed, regardless of how much data is available to be read/written.

Reimplemented from ScsiDisk.

Definition at line 1261 of file AtaDisk.cc.

References ScsiDisk::getBlockSize().

Referenced by AtaController::compareRequests(), and getBusMaster().

+ Here is the caller graph for this function:

virtual BusMasterIde* AtaDisk::getBusMaster ( ) const
inlinevirtual

Retrieve the BusMaster IDE interface for this disk.

Definition at line 88 of file AtaDisk.h.

References getBlockSize(), getNativeBlockSize(), getSize(), sendCommand(), setupLBA28(), and setupLBA48().

Referenced by PciAtaController::irq().

+ Here is the caller graph for this function:

virtual void AtaDisk::getName ( String str)
inlinevirtual

Stores the device's name in str.

Reimplemented from ScsiDisk.

Definition at line 67 of file AtaDisk.h.

References doRead(), doWrite(), initialise(), irqReceived(), and m_pName.

size_t AtaDisk::getNativeBlockSize ( ) const
virtual

Retrieves the native block size - that is, the logical block size. This differs from the main block size, which is for caching.

Reimplemented from ScsiDisk.

Definition at line 1270 of file AtaDisk.cc.

References ScsiDisk::getNativeBlockSize().

Referenced by getBusMaster().

+ Here is the caller graph for this function:

size_t AtaDisk::getSize ( ) const
virtual

Gets the size of the disk.

This is the size in bytes of the disk. Reads or writes beyond this size will fail.

Reimplemented from ScsiDisk.

Definition at line 1228 of file AtaDisk.cc.

References ScsiDisk::getSize().

Referenced by getBusMaster().

+ Here is the caller graph for this function:

bool AtaDisk::initialise ( size_t  nUnit = ~0)

Initialises the device and detects its features, if it is present.

Returns
True if the device is present and was successfully initialised.
Todo:
should check that this doesn't break on ATAPI
Todo:
Testing needs to be done on more than just CD/DVD and block devices...

Definition at line 60 of file AtaDisk.cc.

References AtaStatus::__reg_contents, Dec, ERROR, Device::getInterruptNumber(), Hex, ScsiDisk::initialise(), Device::m_pParent, NOTICE, IoBase::read16(), IoBase::read8(), AtaStatus::reg, WARNING, and IoBase::write8().

Referenced by getName(), and PciAtaController::PciAtaController().

+ Here is the caller graph for this function:

void AtaDisk::irqReceived ( )
virtual

Called when an IRQ is received by the controller.

Definition at line 1156 of file AtaDisk.cc.

Referenced by getName(), IsaAtaController::irq(), and PciAtaController::irq().

+ Here is the caller graph for this function:

bool AtaDisk::sendCommand ( size_t  nUnit,
uintptr_t  pCommand,
uint8_t  nCommandSize,
uintptr_t  pRespBuffer,
uint16_t  nRespBytes,
bool  bWrite 
)
virtual
Todo:
What's the best way to handle this?

Definition at line 470 of file AtaDisk.cc.

References AtaStatus::__reg_contents, ERROR, NOTICE, IoBase::read16(), IoBase::read8(), AtaStatus::reg, WARNING, IoBase::write16(), and IoBase::write8().

Referenced by getBusMaster(), and PciAtaController::PciAtaController().

+ Here is the caller graph for this function:

void AtaDisk::setFeatures ( uint8_t  command,
uint8_t  countreg,
uint8_t  lowreg,
uint8_t  midreg,
uint8_t  hireg 
)
private

Performs the SET FEATURES command.

Definition at line 1210 of file AtaDisk.cc.

References IoBase::write8().

void AtaDisk::setupLBA28 ( uint64_t  n,
uint32_t  nSectors 
)
private

Sets the drive up for reading from address 'n' in LBA28 mode.

Definition at line 1162 of file AtaDisk.cc.

References IoBase::write8().

Referenced by getBusMaster().

+ Here is the caller graph for this function:

void AtaDisk::setupLBA48 ( uint64_t  n,
uint32_t  nSectors 
)
private

Sets the drive up for reading from address 'n' in LBA48 mode.

Definition at line 1186 of file AtaDisk.cc.

References IoBase::write8().

Referenced by getBusMaster().

+ Here is the caller graph for this function:

Member Data Documentation

AtaDiskType AtaDisk::m_AtaDiskType
private

What type of disk are we?

Definition at line 160 of file AtaDisk.h.

Referenced by defaultBlockSize().

bool AtaDisk::m_bDma
private

Can we do DMA?

Definition at line 195 of file AtaDisk.h.

size_t AtaDisk::m_BlockSize
private

Block size in bytes for all read/write operations.

Definition at line 148 of file AtaDisk.h.

IoBase* AtaDisk::m_CommandRegs
private

Command & control registers, and DMA access for this disk

Definition at line 174 of file AtaDisk.h.

Atomic<size_t> AtaDisk::m_IrqCount
private

IRQ count.

Definition at line 198 of file AtaDisk.h.

Mutex* AtaDisk::m_IrqReceived
private

When we wait for an IRQ, we create a Mutex and assign it here. When an IRQ fires, the mutex is released and the locked thread can continue.

Todo:
A condvar would really be better here.

Definition at line 155 of file AtaDisk.h.

bool AtaDisk::m_IsMaster
private

Is this the master device on the bus?

Definition at line 133 of file AtaDisk.h.

size_t AtaDisk::m_LastPrdTableOffset
private

Last used offset into the PRD table (so we can run multiple ops at once)

Definition at line 186 of file AtaDisk.h.

uint8_t AtaDisk::m_PacketSize
private

Command packet size

Definition at line 163 of file AtaDisk.h.

char AtaDisk::m_pFirmwareRevision[64]
private

The firmware revision

Definition at line 142 of file AtaDisk.h.

IdentifyData AtaDisk::m_pIdent
private

The result of the IDENTIFY command.

Definition at line 136 of file AtaDisk.h.

char AtaDisk::m_pName[64]
private

The model name of the device.

Definition at line 138 of file AtaDisk.h.

Referenced by getName().

PhysicalRegionDescriptor* AtaDisk::m_PrdTable
private

PRD table (virtual)

Definition at line 182 of file AtaDisk.h.

Mutex AtaDisk::m_PrdTableLock
private

PRD table lock (only used when grabbing the offset)

Definition at line 179 of file AtaDisk.h.

MemoryRegion AtaDisk::m_PrdTableMemRegion
private

MemoryRegion for the PRD table

Definition at line 192 of file AtaDisk.h.

physical_uintptr_t AtaDisk::m_PrdTablePhys
private

PRD table (physical)

Definition at line 189 of file AtaDisk.h.

char AtaDisk::m_pSerialNumber[64]
private

The serial number of the device.

Definition at line 140 of file AtaDisk.h.

bool AtaDisk::m_Removable
private

Device flags

Definition at line 166 of file AtaDisk.h.

bool AtaDisk::m_SupportsLBA28
private

Does the device support LBA28?

Definition at line 144 of file AtaDisk.h.

bool AtaDisk::m_SupportsLBA48
private

Does the device support LBA48?

Definition at line 146 of file AtaDisk.h.


The documentation for this class was generated from the following files: