Bd


Files

file  ata_bd.c
 ATA disk driver.
file  file_bd.c
 File-backed block device driver.
file  gpt.h
file  guid_part.c
 GUID partition table driver.
file  gxe_bd.c
 GXemul disk driver.
file  mbr_part.c
 PC MBR partition driver.

Data Structures

struct  ata_base_t
 Base addresses for ATA I/O blocks. More...
union  ata_cmd_t
 ATA Command Register Block. More...
union  ata_ctl_t
struct  ata_inquiry_data_t
 Data returned from Inquiry command (mandatory part). More...
struct  ata_pcmd_inquiry_t
 ATAPI Inquiry command. More...
struct  ata_pcmd_read_12_t
 ATAPI Read(12) command. More...
struct  block_coord_t
 Block coordinates. More...
struct  br_block_t
 Structure of a boot-record block. More...
struct  disk_t
 ATA device state structure. More...
struct  gpt_entry_t
 GPT partition entry. More...
struct  gpt_header_t
 GPT header. More...
struct  gxe_bd_t
struct  identify_data_t
 Data returned from identify device and identify packet device command. More...
struct  part
 Partition. More...
struct  part
 Partition. More...
struct  pt_entry_t
 Structure of a partition table entry. More...

Defines

#define DEFAULT_BLOCK_SIZE   512
#define GPT_HDR_BA   1
 Block address of GPT header.
#define INQUIRY_PDEV_TYPE(val)   ((val) & 0x1f)
 Extract value of ata_inquiry_data_t.pdev_type.
#define LEGACY_CTLS   4
 Number of defined legacy controller base addresses.
#define NAME   "mbr_part"
#define NAME   "guid_part"
#define NAME   "gxe_bd"
#define NAME   "file_bd"
#define NAME   "ata_bd"
#define NAMESPACE   "bd"
#define NAMESPACE   "bd"

Typedefs

typedef part part_t
 Partition.
typedef part part_t
 Partition.

Enumerations

enum  
enum  
enum  
enum  
enum  
enum  
enum  { N_PRIMARY = 4, BR_SIGNATURE = 0xAA55 }
enum  ata_command
enum  ata_cs1 { cs1_addr48 = 0x0400 }
 Bits of identify_data_t.cmd_set1. More...
enum  ata_dev_type
enum  ata_pdev_signature { PDEV_SIGNATURE_BC = 0xEB14 }
enum  ata_pdev_type
 Values for ata_inquiry_data_t.pdev_type.
enum  ata_pkt_command
 ATA packet command codes.
enum  ata_pktdev_caps
 Capability bits for packet device.
enum  ata_regdev_caps
 Capability bits for register device.
enum  ata_timeout
 Timeout definitions. More...
enum  devctl_bits { DCR_SRST = 0x04, DCR_nIEN = 0x02 }
enum  drive_head_bits { DHR_LBA = 0x40, DHR_DRV = 0x10 }
enum  error_bits {
  ER_BBK = 0x80, ER_UNC = 0x40, ER_MC = 0x20, ER_IDNF = 0x10,
  ER_MCR = 0x08, ER_ABRT = 0x04, ER_TK0NF = 0x02, ER_AMNF = 0x01
}
enum  ptype { PT_UNUSED = 0x00, PT_EXTENDED = 0x05 }
enum  rd_addr_mode { am_chs, am_lba28, am_lba48 }
 Register device block addressing mode. More...
enum  status_bits {
  SR_BSY = 0x80, SR_DRDY = 0x40, SR_DWF = 0x20, SR_DSC = 0x10,
  SR_DRQ = 0x08, SR_CORR = 0x04, SR_IDX = 0x02, SR_ERR = 0x01
}

Functions

static void ata_bd_connection (ipc_callid_t iid, ipc_call_t *icall)
 Block device connection handler.
static int ata_bd_init (void)
 Register driver and enable device I/O.
static int ata_bd_read_blocks (int disk_id, uint64_t ba, size_t cnt, void *buf)
 Read multiple blocks from the device.
static int ata_bd_write_blocks (int disk_id, uint64_t ba, size_t cnt, const void *buf)
 Write multiple blocks to the device.
static int ata_cmd_packet (int dev_idx, const void *cpkt, size_t cpkt_size, void *obuf, size_t obuf_size)
 Issue packet command (i.
static int ata_pcmd_inquiry (int dev_idx, void *obuf, size_t obuf_size)
 Issue ATAPI Inquiry.
static int ata_pcmd_read_12 (int dev_idx, uint64_t ba, size_t cnt, void *obuf, size_t obuf_size)
 Issue ATAPI read(12) command.
static int ata_rcmd_read (int disk_id, uint64_t ba, size_t blk_cnt, void *buf)
 Read a physical from the device.
static int ata_rcmd_write (int disk_id, uint64_t ba, size_t cnt, const void *buf)
 Write a physical block to the device.
static int coord_calc (disk_t *d, uint64_t ba, block_coord_t *bc)
 Calculate block coordinates.
static void coord_sc_program (const block_coord_t *bc, uint16_t scnt)
 Program block coordinates and sector count into ATA registers.
static int disk_init (disk_t *d, int disk_id)
 Initialize a disk.
static void disk_print_summary (disk_t *d)
 Print one-line device summary.
static int drive_identify (int disk_id, void *buf)
 Issue IDENTIFY command.
static void file_bd_connection (ipc_callid_t iid, ipc_call_t *icall)
static int file_bd_init (const char *fname)
static int file_bd_read_blocks (uint64_t ba, size_t cnt, void *buf)
 Read blocks from the device.
static int file_bd_write_blocks (uint64_t ba, size_t cnt, const void *buf)
 Write blocks to the device.
static int gpt_bd_read (part_t *p, aoff64_t ba, size_t cnt, void *buf)
 Read blocks from partition.
static int gpt_bd_write (part_t *p, aoff64_t ba, size_t cnt, const void *buf)
 Write blocks to partition.
static int gpt_bsa_translate (part_t *p, aoff64_t ba, size_t cnt, aoff64_t *gba)
 Translate block segment address with range checking.
static void gpt_connection (ipc_callid_t iid, ipc_call_t *icall)
static int gpt_init (const char *dev_name)
static part_tgpt_part_new (void)
 Allocate a new part_t structure.
static void gpt_pte_to_part (const gpt_entry_t *pte, part_t *part)
 Parse partition table entry.
static int gpt_read (void)
 Read in partition records.
static void gxe_bd_connection (ipc_callid_t iid, ipc_call_t *icall)
static int gxe_bd_init (void)
static int gxe_bd_read_block (int disk_id, uint64_t ba, void *buf)
 Read a block from the device.
static int gxe_bd_read_blocks (int disk_id, uint64_t ba, unsigned cnt, void *buf)
 Read multiple blocks from the device.
static int gxe_bd_write_block (int disk_id, uint64_t ba, const void *buf)
 Write a block to the device.
static int gxe_bd_write_blocks (int disk_id, uint64_t ba, unsigned cnt, const void *buf)
 Write multiple blocks to the device.
static int identify_pkt_dev (int dev_idx, void *buf)
 Issue Identify Packet Device command.
int main (int argc, char **argv)
static int mbr_bd_read (part_t *p, uint64_t ba, size_t cnt, void *buf)
 Read blocks from partition.
static int mbr_bd_write (part_t *p, uint64_t ba, size_t cnt, const void *buf)
 Write blocks to partition.
static int mbr_bsa_translate (part_t *p, uint64_t ba, size_t cnt, uint64_t *gba)
 Translate block segment address with range checking.
static void mbr_connection (ipc_callid_t iid, ipc_call_t *icall)
static int mbr_init (const char *dev_name)
static part_tmbr_part_new (void)
 Allocate a new part_t structure.
static int mbr_part_read (void)
 Read in partition records.
static void mbr_pte_to_part (uint32_t base, const pt_entry_t *pte, part_t *part)
 Parse partition table entry.
static void print_syntax (void)
static void print_usage (void)
static int wait_status (unsigned set, unsigned n_reset, uint8_t *pstatus, unsigned timeout)
 Wait until some status bits are set and some are reset.

Variables

static size_t block_size
static size_t block_size
static const size_t block_size = 512
static size_t block_size
static ata_cmd_tcmd
static uintptr_t cmd_physical
 I/O base address of the command registers.
static size_t comm_size
static size_t comm_size
 Size of the communication area.
static ata_ctl_tctl
static uintptr_t ctl_physical
 I/O base address of the control registers.
static gxe_bd_tdev
static fibril_mutex_t dev_lock [MAX_DISKS]
static fibril_mutex_t dev_lock
static uintptr_t dev_physical = 0x13000000
static devmap_handle_t devmap_handle [MAX_DISKS]
static devmap_handle_t devmap_handle
static disk_t disk [MAX_DISKS]
 Per-disk state.
const uint8_t efi_signature [8]
static const size_t identify_data_size = 512
 Size of data returned from Identify Device or Identify Packet Device command.
static FILEimg
static devmap_handle_t indev_handle
 Partitioned device (inbound device).
static devmap_handle_t indev_handle
 Partitioned device (inbound device).
static ata_base_t legacy_base [LEGACY_CTLS]
 I/O base addresses for legacy (ISA-compatible) controllers.
static aoff64_t num_blocks
static part_t plist_head
 List of partitions.
static part_t plist_head
 List of partitions.

Enumeration Type Documentation

anonymous enum

Enumerator:
N_PRIMARY  Number of primary partition records.
BR_SIGNATURE  Boot record signature.

Definition at line 78 of file mbr_part.c.

enum ata_cs1

Bits of identify_data_t.cmd_set1.

Enumerator:
cs1_addr48  48-bit address feature set

Definition at line 239 of file ata_hw.h.

enum ata_pdev_signature

Enumerator:
PDEV_SIGNATURE_BC  Signature put by a packet device in byte count register in response to Identify command.

Definition at line 295 of file ata_hw.h.

enum ata_timeout

Timeout definitions.

Unit is 10 ms.

Definition at line 49 of file ata_bd.h.

enum devctl_bits

Enumerator:
DCR_SRST  Software Reset.
DCR_nIEN  Interrupt Enable (negated).

Definition at line 99 of file ata_hw.h.

enum drive_head_bits

Enumerator:
DHR_LBA  Use LBA addressing mode.
DHR_DRV  Select device 1.

Definition at line 115 of file ata_hw.h.

enum error_bits

Enumerator:
ER_BBK  Bad Block Detected.
ER_UNC  Uncorrectable Data Error.
ER_MC  Media Changed.
ER_IDNF  ID Not Found.
ER_MCR  Media Change Request.
ER_ABRT  Aborted Command.
ER_TK0NF  Track 0 Not Found.
ER_AMNF  Address Mark Not Found.

Definition at line 120 of file ata_hw.h.

enum ptype

Enumerator:
PT_UNUSED  Unused partition entry.
PT_EXTENDED  Extended partition.

Definition at line 86 of file mbr_part.c.

enum rd_addr_mode

Register device block addressing mode.

Enumerator:
am_chs  CHS block addressing.
am_lba28  LBA-28 block addressing.
am_lba48  LBA-48 block addressing.

Definition at line 61 of file ata_bd.h.

enum status_bits

Enumerator:
SR_BSY  Busy.
SR_DRDY  Drive Ready.
SR_DWF  Drive Write Fault.
SR_DSC  Drive Seek Complete.
SR_DRQ  Data Request.
SR_CORR  Corrected Data.
SR_IDX  Index.
SR_ERR  Error.

Definition at line 104 of file ata_hw.h.


Function Documentation

static int ata_cmd_packet ( int  dev_idx,
const void *  cpkt,
size_t  cpkt_size,
void *  obuf,
size_t  obuf_size 
) [static]

Issue packet command (i.

e. write a command packet to the device).

Only data-in commands are supported (e.g. inquiry, read).

Parameters:
dev_idx Device index (0 or 1)
obuf Buffer for storing data read from device
obuf_size Size of obuf in bytes
Returns:
EOK on success, EIO on error.

Definition at line 670 of file ata_bd.c.

static int ata_pcmd_inquiry ( int  dev_idx,
void *  obuf,
size_t  obuf_size 
) [static]

Issue ATAPI Inquiry.

Parameters:
dev_idx Device index (0 or 1)
obuf Buffer for storing inquiry data read from device
obuf_size Size of obuf in bytes
Returns:
EOK on success, EIO on error.

Definition at line 759 of file ata_bd.c.

static int ata_pcmd_read_12 ( int  dev_idx,
uint64_t  ba,
size_t  cnt,
void *  obuf,
size_t  obuf_size 
) [static]

Issue ATAPI read(12) command.

Output buffer must be large enough to hold the data, otherwise the function will fail.

Parameters:
dev_idx Device index (0 or 1)
ba Starting block address
cnt Number of blocks to read
obuf Buffer for storing inquiry data read from device
obuf_size Size of obuf in bytes
Returns:
EOK on success, EIO on error.

Definition at line 789 of file ata_bd.c.

static int ata_rcmd_read ( int  disk_id,
uint64_t  ba,
size_t  blk_cnt,
void *  buf 
) [static]

Read a physical from the device.

Parameters:
disk_id Device index (0 or 1)
ba Address the first block.
cnt Number of blocks to transfer.
buf Buffer for holding the data.
Returns:
EOK on success, EIO on error.

Definition at line 820 of file ata_bd.c.

static int ata_rcmd_write ( int  disk_id,
uint64_t  ba,
size_t  cnt,
const void *  buf 
) [static]

Write a physical block to the device.

Parameters:
disk_id Device index (0 or 1)
ba Address of the first block.
cnt Number of blocks to transfer.
buf Buffer holding the data to write.
Returns:
EOK on success, EIO on error.

Definition at line 897 of file ata_bd.c.

static int coord_calc ( disk_t d,
uint64_t  ba,
block_coord_t bc 
) [static]

Calculate block coordinates.

Calculates block coordinates in the best coordinate system supported by the device. These can be later programmed into the device using coord_sc_program().

Returns:
EOK on success or EINVAL if block index is past end of device.

Definition at line 972 of file ata_bd.c.

static void coord_sc_program ( const block_coord_t bc,
uint16_t  scnt 
) [static]

Program block coordinates and sector count into ATA registers.

Note that bc->h must be programmed separately into the device/head register.

Definition at line 1022 of file ata_bd.c.

static int disk_init ( disk_t d,
int  disk_id 
) [static]

Initialize a disk.

Probes for a disk, determines its parameters and initializes the disk structure.

Definition at line 367 of file ata_bd.c.

static int drive_identify ( int  disk_id,
void *  buf 
) [static]

Issue IDENTIFY command.

Reads identify data into the provided buffer. This is used to detect whether an ATA device is present and if so, to determine its parameters.

Parameters:
disk_id Device ID, 0 or 1.
buf Pointer to a 512-byte buffer.
Returns:
ETIMEOUT on timeout (this can mean the device is not present). EIO if device responds with error.

Definition at line 566 of file ata_bd.c.

static int identify_pkt_dev ( int  dev_idx,
void *  buf 
) [static]

Issue Identify Packet Device command.

Reads identify data into the provided buffer. This is used to detect whether an ATAPI device is present and if so, to determine its parameters.

Parameters:
dev_idx Device index, 0 or 1.
buf Pointer to a 512-byte buffer.

Definition at line 622 of file ata_bd.c.

static int wait_status ( unsigned  set,
unsigned  n_reset,
uint8_t *  pstatus,
unsigned  timeout 
) [static]

Wait until some status bits are set and some are reset.

Example: wait_status(SR_DRDY, ~SR_BSY) waits for SR_DRDY to become set and SR_BSY to become reset.

Parameters:
set Combination if bits which must be all set.
n_reset Negated combination of bits which must be all reset.
pstatus Pointer where to store last read status or NULL.
timeout Timeout in 10ms units.
Returns:
EOK on success, EIO on timeout.

Definition at line 1051 of file ata_bd.c.


Variable Documentation

part_t plist_head [static]

List of partitions.

This structure is an empty head.

Definition at line 146 of file mbr_part.c.

part_t plist_head [static]

List of partitions.

This structure is an empty head.

Definition at line 95 of file guid_part.c.


Generated on Thu Jun 2 07:45:58 2011 for HelenOS/USB by  doxygen 1.4.7