The Pedigree Project  0.1
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ScsiDisk Class Reference
+ Inheritance diagram for ScsiDisk:
+ Collaboration diagram for ScsiDisk:

Classes

struct  Capacity
 
struct  Inquiry
 
struct  Sense
 

Public Member Functions

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 void getName (String &str)
 
virtual uint64_t doRead (uint64_t location)
 
virtual uint64_t doWrite (uint64_t location)
 
virtual uint64_t doSync (uint64_t location)
 
virtual size_t getSize () const
 Gets the size of the disk. More...
 
virtual size_t getBlockCount () const
 
virtual size_t getBlockSize () const
 Gets the block size of the disk. More...
 
virtual size_t getNativeBlockSize () const
 
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)
 

Public Attributes

struct ScsiDisk::Sense PACKED
 
struct ScsiDisk::Inquiry PACKED
 
struct ScsiDisk::Capacity PACKED
 

Protected Member Functions

CachegetCache ()
 
InquirygetInquiry () const
 
- Protected Member Functions inherited from Device
 NOT_COPYABLE_OR_ASSIGNABLE (Device)
 

Private Types

enum  ScsiPeripheralType {
  BlockDevice = 0x00, SequentialDevice = 0x01, PrinterDevice = 0x02, ProcessorDevice = 0x03,
  WriteOnceDevice = 0x04, CdDvdDevice = 0x05, OpticalMemoryDevice = 0x07, MediumChangerDevice = 0x08,
  ArrayDevice = 0x0C, EnclosureDevice = 0x0D, NoDevice = 0x1F
}
 

Private Member Functions

bool unitReady ()
 
bool readSense (Sense *s)
 
bool sendCommand (ScsiCommand *pCommand, uintptr_t pRespBuffer, uint16_t nRespBytes, bool bWrite=false)
 
bool getCapacityInternal (size_t *blockNumber, size_t *blockSize)
 
virtual size_t defaultBlockSize ()
 

Static Private Member Functions

static void cacheCallback (CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page, void *meta)
 

Private Attributes

class ScsiControllerm_pController
 
size_t m_nUnit
 
Cache m_Cache
 
Inquirym_Inquiry
 
uint64_t m_AlignPoints [8]
 
size_t m_nAlignPoints
 
size_t m_NumBlocks
 
size_t m_BlockSize
 
size_t m_NativeBlockSize
 
ScsiPeripheralType m_DeviceType
 

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)
 
- 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

Definition at line 32 of file ScsiDisk.h.

Member Function Documentation

void ScsiDisk::align ( uint64_t  location)
virtual

Sets the page boundary alignment after a specific location on the disk.

For example, if one has a partition starting on byte 512, one will probably want 4096-byte reads to be aligned with this (so reading 4096 bytes from byte 0 on the partition will create one page of cache and not span two). Without an align point a read of the first sector of a partition starting at byte 512 will have to have a location of 512 rather than 0.

Use this function to allow reads to fit into the 4096 byte buffers manipulated in read() or write() even when location isn't aligned on a 4096 byte boundary.

Reimplemented from Disk.

Definition at line 442 of file ScsiDisk.cc.

References assert.

virtual size_t ScsiDisk::defaultBlockSize ( )
inlineprivatevirtual

Default block size for a device

Reimplemented in AtaDisk.

Definition at line 179 of file ScsiDisk.h.

uint64_t ScsiDisk::doRead ( uint64_t  location)
virtual
Todo:
Cache this somewhere.
Todo:
endianness issue?

Reimplemented in AtaDisk.

Definition at line 448 of file ScsiDisk.cc.

References ERROR, FATAL, and WARNING.

Referenced by AtaDisk::doRead(), and ScsiController::executeRequest().

+ Here is the caller graph for this function:

void ScsiDisk::flush ( uint64_t  location)
virtual

Flush a cached page to disk.

Essentially a no-op if the given location is not actually in cache. Called either by filesystem drivers (on removable disks) or from a central cache manager which handles flushing caches back to the disk on a regular basis.

Will not remove the page from cache, that must be done by the caller.

Reimplemented from Disk.

Definition at line 392 of file ScsiDisk.cc.

References RequestQueue::addRequest(), ERROR, and Device::m_pParent.

virtual size_t ScsiDisk::getBlockSize ( ) const
inlinevirtual

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 Disk.

Reimplemented in AtaDisk.

Definition at line 120 of file ScsiDisk.h.

Referenced by AtaDisk::getBlockSize().

+ Here is the caller graph for this function:

virtual void ScsiDisk::getName ( String str)
inlinevirtual

Stores the device's name in str.

Reimplemented from Disk.

Reimplemented in AtaDisk.

Definition at line 99 of file ScsiDisk.h.

virtual size_t ScsiDisk::getNativeBlockSize ( ) const
inlinevirtual

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

Reimplemented in AtaDisk.

Definition at line 129 of file ScsiDisk.h.

Referenced by AtaDisk::getNativeBlockSize().

+ Here is the caller graph for this function:

virtual size_t ScsiDisk::getSize ( ) const
inlinevirtual

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 Disk.

Reimplemented in AtaDisk.

Definition at line 110 of file ScsiDisk.h.

Referenced by AtaDisk::getSize().

+ Here is the caller graph for this function:

bool ScsiDisk::initialise ( class ScsiController pController,
size_t  nUnit 
)
Todo:
Use this data to change how read() and write() work

Definition at line 78 of file ScsiDisk.cc.

References Dec, ServiceManager::enumerateOperations(), ERROR, ServiceManager::getService(), Hex, Device::m_pParent, NOTICE, ServiceFeatures::provides(), Service::serve(), and ServiceFeatures::touch.

Referenced by AtaDisk::initialise().

+ Here is the caller graph for this function:

void ScsiDisk::pin ( uint64_t  location)
virtual

Pins a cache page.

This allows an upstream user of Disk pages to 'pin' cache pages, causing them to only be freed once all consumers have done an 'unpin'. The pin and unpin semantics allow for memory mappings to be made in a reasonably safe manner, as it can be assumed that the physical page for a particular cache block will not be freed.

Reimplemented from Disk.

Definition at line 697 of file ScsiDisk.cc.

uintptr_t ScsiDisk::read ( uint64_t  location)
virtual

Read from location on disk and return a pointer to it. location must be 512 byte aligned. The pointer returned is within a page of cache that maps to 4096 bytes of disk area.

Note
If the Disk is backed by a Cache, the buffer returned should have its refcount incremented by one by a successful run of read(). Use unpin() to indicate you no longer care about the buffer.
Parameters
locationThe offset from the start of the device, in bytes, to start the read, must be multiple of 512.
Returns
Pointer to writable area of memory containing the data. If the data is written, the page is marked as dirty and may be written back to disk at any time (or forced with write() or flush() ).

Reimplemented from Disk.

Definition at line 277 of file ScsiDisk.cc.

References RequestQueue::addAsyncRequest(), RequestQueue::addRequest(), ERROR, Device::m_pParent, and WARNING.

bool ScsiDisk::readSense ( Sense s)
private
Todo:
get the amount of data received from the SCSI device

Definition at line 198 of file ScsiDisk.cc.

References WARNING.

bool ScsiDisk::unitReady ( )
private
Todo:
this can fail with UNIT_ATTN or NOT_READY if the device is removable.

Definition at line 223 of file ScsiDisk.cc.

References WARNING.

void ScsiDisk::unpin ( uint64_t  location)
virtual

Unpins a cache page (see pin() for more information and rationale).

Reimplemented from Disk.

Definition at line 702 of file ScsiDisk.cc.

void ScsiDisk::write ( uint64_t  location)
virtual

This function schedules a cache writeback of the given location. The data to be written back is fetched from the cache (pointer returned by read() ).

Parameters
locationThe offset from the start of the device, in bytes, to start the write. Must be 512byte aligned.

Reimplemented from Disk.

Definition at line 342 of file ScsiDisk.cc.

References RequestQueue::addAsyncRequest(), ERROR, and Device::m_pParent.


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