MentOS  0.8.0
The Mentoring Operating System
Classes | Macros | Typedefs | Functions | Variables
ata.c File Reference

Advanced Technology Attachment (ATA) and Advanced Technology Attachment Packet Interface (ATAPI) drivers. More...

Classes

struct  ata_identity_t
 IDENTIFY device data (response to 0xEC). More...
 
struct  prdt_t
 Physical Region Descriptor Table (PRDT) entry. More...
 
struct  ata_device_t
 Stores information about an ATA device. More...
 

Macros

#define __DEBUG_HEADER__   "[ATA ]"
 Change header.
 
#define __DEBUG_LEVEL__   LOGLEVEL_NOTICE
 Set log level.
 
#define ATA_SECTOR_SIZE   512
 The sector size.
 
#define ATA_DMA_SIZE   512
 The size of the DMA area.
 

Typedefs

typedef struct ata_identity_t ata_identity_t
 IDENTIFY device data (response to 0xEC).
 
typedef struct prdt_t prdt_t
 Physical Region Descriptor Table (PRDT) entry. More...
 
typedef struct ata_device_t ata_device_t
 Stores information about an ATA device.
 

Functions

static const char * ata_get_device_error_str (uint8_t error)
 Returns the set of ATA errors as a string. More...
 
static const char * ata_get_device_status_str (uint8_t status)
 Returns the device status as a string. More...
 
static const char * ata_get_device_settings_str (ata_device_t *dev)
 Returns the device configuration as string. More...
 
static const char * ata_get_device_type_str (ata_device_type_t type)
 Returns the device type as string. More...
 
static void ata_dump_device (ata_device_t *dev)
 Dumps on debugging output the device data. More...
 
static void ata_io_wait (ata_device_t *dev)
 Waits for approximately 400 nanoseconds by performing four I/O reads. More...
 
static int ata_status_wait_not (ata_device_t *dev, long mask, long timeout)
 Waits until the status bits selected through the mask are zero. More...
 
static int ata_status_wait_for (ata_device_t *dev, long mask, long timeout)
 Waits until the status bits selected through the mask are set. More...
 
static void ata_print_status_error (ata_device_t *dev)
 Prints the status and error information about the device. More...
 
static uint64_t ata_max_offset (ata_device_t *dev)
 Ge the maximum offset for the given device. More...
 
static void ata_fix_string (char *str, size_t len)
 Fixes all ATA-related strings. More...
 
static void ata_soft_reset (ata_device_t *dev)
 Performs a soft reset of the device. More...
 
static uintptr_t ata_dma_alloc (size_t size, uintptr_t *physical)
 Creates the DMA memory area used to write and read on the device. More...
 
static int ata_dma_free (uintptr_t logical_addr)
 Frees the DMA memory area previously allocated. More...
 
static int ata_dma_enable_bus_mastering (void)
 Enables bus mastering, allowing Direct Memory Access (DMA) transactions. More...
 
static int ata_dma_disable_bus_mastering (void)
 Disables bus mastering, preventing Direct Memory Access (DMA) transactions. More...
 
static int ata_dma_initialize_bus_mastering_address (ata_device_t *dev)
 Initializes the bus mastering register (BMR) fields of the ATA device. More...
 
static ata_device_type_t ata_detect_device_type (ata_device_t *dev)
 Detects the type of device. More...
 
static bool_t ata_device_init (ata_device_t *dev)
 Initialises the given device. More...
 
static void ata_device_read_sector (ata_device_t *dev, uint32_t lba_sector, uint8_t *buffer)
 Reads an ATA sector. More...
 
static void ata_device_write_sector (ata_device_t *dev, uint32_t lba_sector, uint8_t *buffer)
 Writs an ATA sector. More...
 
static vfs_file_tata_open (const char *path, int flags, mode_t mode)
 Implements the open function for an ATA device. More...
 
static int ata_close (vfs_file_t *file)
 Closes an ATA device. More...
 
static ssize_t ata_read (vfs_file_t *file, char *buffer, off_t offset, size_t size)
 Reads from an ATA device. More...
 
static ssize_t ata_write (vfs_file_t *file, const void *buffer, off_t offset, size_t size)
 Writes on an ATA device. More...
 
static int _ata_stat (const ata_device_t *dev, stat_t *stat)
 Stats an ATA device. More...
 
static int ata_fstat (vfs_file_t *file, stat_t *stat)
 Retrieves information concerning the file at the given position. More...
 
static int ata_stat (const char *path, stat_t *stat)
 Retrieves information concerning the file at the given position. More...
 
static vfs_file_tata_mount_callback (const char *path, const char *device)
 The mount call-back, which prepares everything and calls the actual ATA mount function. More...
 
static vfs_file_tata_device_create (ata_device_t *dev)
 Creates a VFS file, starting from an ATA device. More...
 
static ata_device_type_t ata_device_detect (ata_device_t *dev)
 Detects and mount the given ATA device. More...
 
static void ata_irq_handler_master (pt_regs *f)
 
static void ata_irq_handler_slave (pt_regs *f)
 
static void pci_find_ata (uint32_t device, uint16_t vendorid, uint16_t deviceid, void *extra)
 Used while scanning the PCI interface. More...
 
int ata_initialize (void)
 Initializes the ATA drivers. More...
 
int ata_finalize (void)
 De-initializes the ATA drivers. More...
 

Variables

static char ata_drive_char = 'a'
 Keeps track of the incremental letters for the ATA drives.
 
static int cdrom_number = 0
 Keeps track of the incremental number for removable media.
 
static uint32_t ata_pci = 0x00000000
 We store the ATA pci address here.
 
static ata_device_t ata_primary_master
 The ATA primary master control register locations. More...
 
static ata_device_t ata_primary_slave
 The ATA primary slave control register locations. More...
 
static ata_device_t ata_secondary_master
 The ATA secondary master control register locations. More...
 
static ata_device_t ata_secondary_slave
 The ATA secondary slave control register locations. More...
 
static file_system_type ata_file_system_type
 Filesystem information. More...
 
static vfs_sys_operations_t ata_sys_operations
 Filesystem general operations. More...
 
static vfs_file_operations_t ata_fs_operations
 ATA filesystem file operations. More...
 

Detailed Description

Advanced Technology Attachment (ATA) and Advanced Technology Attachment Packet Interface (ATAPI) drivers.