PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
ps2atad.c File Reference
#include <types.h>
#include <defs.h>
#include <irx.h>
#include <loadcore.h>
#include <thbase.h>
#include <thevent.h>
#include <stdio.h>
#include <sysclib.h>
#include <atad.h>
#include <atahw.h>
+ Include dependency graph for ps2atad.c:

Go to the source code of this file.

Data Structures

struct  _ata_cmd_info
 
struct  _ata_cmd_state
 
union  _ata_cmd_state.__unnamed113__
 

Macros

#define MODNAME   "atad"
 
#define M_PRINTF(format, args...)
 
#define BANNER   "ATA device driver %s - Copyright (c) 2003 Marcus R. Brown\n"
 
#define VERSION   "v1.2"
 
#define ATA_XFER_MODE_PIO   0x08
 
#define ATA_XFER_MODE_UDMA   0x40
 
#define ATA_EV_TIMEOUT   1
 
#define ATA_EV_COMPLETE   2
 
#define ATA_CMD_TABLE_SIZE   (sizeof ata_cmd_table / sizeof(ata_cmd_info_t))
 
#define SEC_CTRL_CMD_TABLE_SIZE   (sizeof sec_ctrl_cmd_table / sizeof(ata_cmd_info_t))
 
#define SMART_CMD_TABLE_SIZE   (sizeof smart_cmd_table / sizeof(ata_cmd_info_t))
 
#define ATA_WAIT_BUSY   0x80
 
#define ATA_WAIT_BUSBUSY   0x88
 
#define ata_wait_busy()
 
#define ata_wait_bus_busy()
 

Typedefs

typedef struct _ata_cmd_info ata_cmd_info_t
 
typedef struct _ata_cmd_state ata_cmd_state_t
 

Functions

 IRX_ID (MODNAME, 2, 7)
 
static unsigned int ata_alarm_cb (void *unused)
 
static void ata_shutdown_cb (void)
 
int ata_device_sector_io64 (int device, void *buf, u64 lba, u32 nsectors, int dir)
 
static int ata_create_event_flag (void)
 
int _start (int argc, char *argv[])
 
int _exit (void)
 
int sceAtaGetError (void)
 
static int gen_ata_wait_busy (int bits)
 
static int ata_device_select (int device)
 
int sceAtaExecCmd (void *buf, u32 blkcount, u16 feature, u16 nsector, u16 sector, u16 lcyl, u16 hcyl, u16 select, u16 command)
 
static int ata_pio_transfer (ata_cmd_state_t *cmd_state)
 
int sceAtaWaitResult (void)
 
static int ata_bus_reset (void)
 
int sceAtaSoftReset (void)
 
int sceAtaFlushCache (int device)
 
int sceAtaIdle (int device, int period)
 
static int ata_device_identify (int device, void *info)
 
static int ata_device_pkt_identify (int device, void *info)
 
int sceAtaGetSceId (int device, void *data)
 
static int ata_device_smart_enable (int device)
 
int sceAtaSmartSaveAttr (int device)
 
int sceAtaSmartReturnStatus (int device)
 
static int ata_device_set_transfer_mode (int device, int type, int mode)
 
int sceAtaDmaTransfer (int device, void *buf, u32 lba, u32 nsectors, int dir)
 
static void ata_get_security_status (int device, ata_devinfo_t *devinfo, u16 *param)
 
int sceAtaSecuritySetPassword (int device, void *password)
 
int sceAtaSecurityUnLock (int device, void *password)
 
int sceAtaSecurityEraseUnit (int device)
 
static void ata_device_probe (ata_devinfo_t *devinfo)
 
static int ata_init_devices (ata_devinfo_t *devinfo)
 
ata_devinfo_tsceAtaInit (int device)
 
int sceAtaIdleImmediate (int device)
 
static int ata_device_standby_immediate (int device)
 

Variables

static int ata_devinfo_init = 0
 
static int ata_evflg = -1
 
static u8 ata_dvrp_workaround = 0
 
static ata_devinfo_t atad_devinfo [2]
 
static u16 ata_param [256]
 
static const ata_cmd_info_t ata_cmd_table []
 
static const ata_cmd_info_t sec_ctrl_cmd_table []
 
static const ata_cmd_info_t smart_cmd_table []
 
static ata_cmd_state_t atad_cmd_state
 
struct irx_export_table _exp_atad
 

Detailed Description

ATA device driver. This module provides the low-level ATA support for hard disk drives, based on ATAD v2.7. It is 100% compatible with its proprietary counterpart called atad.irx.

This module also include support for 48-bit feature set (done by Clement). To avoid causing an "emergency park" for some HDDs, shutdown callback 15 of dev9 is used for issuing the STANDBY IMMEDIATE command prior to DEV9 getting shut down.

Definition in file ps2atad.c.


Data Structure Documentation

◆ _ata_cmd_state.__unnamed113__

union _ata_cmd_state.__unnamed113__

Definition at line 179 of file ps2atad.c.

Data Fields
void * buf
u8 * buf8
u16 * buf16

Macro Definition Documentation

◆ MODNAME

#define MODNAME   "atad"

Definition at line 47 of file ps2atad.c.

◆ M_PRINTF

#define M_PRINTF ( format,
args... )
Value:
printf(MODNAME ": " format, ##args)

Definition at line 53 of file ps2atad.c.

◆ BANNER

#define BANNER   "ATA device driver %s - Copyright (c) 2003 Marcus R. Brown\n"

Definition at line 56 of file ps2atad.c.

◆ VERSION

#define VERSION   "v1.2"

Definition at line 57 of file ps2atad.c.

◆ ATA_XFER_MODE_PIO

#define ATA_XFER_MODE_PIO   0x08

Definition at line 59 of file ps2atad.c.

◆ ATA_XFER_MODE_UDMA

#define ATA_XFER_MODE_UDMA   0x40

Definition at line 63 of file ps2atad.c.

◆ ATA_EV_TIMEOUT

#define ATA_EV_TIMEOUT   1

Definition at line 65 of file ps2atad.c.

◆ ATA_EV_COMPLETE

#define ATA_EV_COMPLETE   2

Definition at line 66 of file ps2atad.c.

◆ ATA_CMD_TABLE_SIZE

#define ATA_CMD_TABLE_SIZE   (sizeof ata_cmd_table / sizeof(ata_cmd_info_t))

Definition at line 150 of file ps2atad.c.

◆ SEC_CTRL_CMD_TABLE_SIZE

#define SEC_CTRL_CMD_TABLE_SIZE   (sizeof sec_ctrl_cmd_table / sizeof(ata_cmd_info_t))

Definition at line 161 of file ps2atad.c.

◆ SMART_CMD_TABLE_SIZE

#define SMART_CMD_TABLE_SIZE   (sizeof smart_cmd_table / sizeof(ata_cmd_info_t))

Definition at line 173 of file ps2atad.c.

◆ ATA_WAIT_BUSY

#define ATA_WAIT_BUSY   0x80

Definition at line 433 of file ps2atad.c.

◆ ATA_WAIT_BUSBUSY

#define ATA_WAIT_BUSBUSY   0x88

Definition at line 434 of file ps2atad.c.

◆ ata_wait_busy

#define ata_wait_busy ( )
Value:
gen_ata_wait_busy(ATA_WAIT_BUSY)

Definition at line 436 of file ps2atad.c.

◆ ata_wait_bus_busy

#define ata_wait_bus_busy ( )
Value:
gen_ata_wait_busy(ATA_WAIT_BUSBUSY)

Definition at line 437 of file ps2atad.c.

Function Documentation

◆ ata_alarm_cb()

static unsigned int ata_alarm_cb ( void * unused)
static

Definition at line 413 of file ps2atad.c.

◆ ata_shutdown_cb()

static void ata_shutdown_cb ( void )
static

Definition at line 1488 of file ps2atad.c.

◆ ata_device_sector_io64()

int ata_device_sector_io64 ( int device,
void * buf,
u64 lba,
u32 nsectors,
int dir )

Definition at line 1023 of file ps2atad.c.

◆ ata_create_event_flag()

static int ata_create_event_flag ( void )
static

Definition at line 254 of file ps2atad.c.

◆ _start()

int _start ( int argc,
char * argv[] )

Definition at line 263 of file ps2atad.c.

◆ _exit()

int _exit ( void )

Definition at line 387 of file ps2atad.c.

◆ sceAtaGetError()

int sceAtaGetError ( void )

Definition at line 422 of file ps2atad.c.

◆ gen_ata_wait_busy()

static int gen_ata_wait_busy ( int bits)
static

Definition at line 441 of file ps2atad.c.

◆ ata_device_select()

static int ata_device_select ( int device)
static

Definition at line 484 of file ps2atad.c.

◆ sceAtaExecCmd()

int sceAtaExecCmd ( void * buf,
u32 blkcount,
u16 feature,
u16 nsector,
u16 sector,
u16 lcyl,
u16 hcyl,
u16 select,
u16 command )

Definition at line 519 of file ps2atad.c.

◆ ata_pio_transfer()

static int ata_pio_transfer ( ata_cmd_state_t * cmd_state)
static

Definition at line 653 of file ps2atad.c.

◆ sceAtaWaitResult()

int sceAtaWaitResult ( void )

Definition at line 760 of file ps2atad.c.

◆ ata_bus_reset()

static int ata_bus_reset ( void )
static

Definition at line 845 of file ps2atad.c.

◆ sceAtaSoftReset()

int sceAtaSoftReset ( void )

Definition at line 859 of file ps2atad.c.

◆ sceAtaFlushCache()

int sceAtaFlushCache ( int device)

Definition at line 883 of file ps2atad.c.

◆ sceAtaIdle()

int sceAtaIdle ( int device,
int period )

Definition at line 894 of file ps2atad.c.

◆ ata_device_identify()

static int ata_device_identify ( int device,
void * info )
static

Definition at line 904 of file ps2atad.c.

◆ ata_device_pkt_identify()

static int ata_device_pkt_identify ( int device,
void * info )
static

Definition at line 914 of file ps2atad.c.

◆ sceAtaGetSceId()

int sceAtaGetSceId ( int device,
void * data )

Definition at line 925 of file ps2atad.c.

◆ ata_device_smart_enable()

static int ata_device_smart_enable ( int device)
static

Definition at line 935 of file ps2atad.c.

◆ sceAtaSmartSaveAttr()

int sceAtaSmartSaveAttr ( int device)

Definition at line 946 of file ps2atad.c.

◆ sceAtaSmartReturnStatus()

int sceAtaSmartReturnStatus ( int device)

Definition at line 957 of file ps2atad.c.

◆ ata_device_set_transfer_mode()

static int ata_device_set_transfer_mode ( int device,
int type,
int mode )
static

Definition at line 980 of file ps2atad.c.

◆ sceAtaDmaTransfer()

int sceAtaDmaTransfer ( int device,
void * buf,
u32 lba,
u32 nsectors,
int dir )

Definition at line 1018 of file ps2atad.c.

◆ ata_get_security_status()

static void ata_get_security_status ( int device,
ata_devinfo_t * devinfo,
u16 * param )
static

Definition at line 1094 of file ps2atad.c.

◆ sceAtaSecuritySetPassword()

int sceAtaSecuritySetPassword ( int device,
void * password )

Definition at line 1101 of file ps2atad.c.

◆ sceAtaSecurityUnLock()

int sceAtaSecurityUnLock ( int device,
void * password )

Definition at line 1122 of file ps2atad.c.

◆ sceAtaSecurityEraseUnit()

int sceAtaSecurityEraseUnit ( int device)

Definition at line 1148 of file ps2atad.c.

◆ ata_device_probe()

static void ata_device_probe ( ata_devinfo_t * devinfo)
static

Definition at line 1170 of file ps2atad.c.

◆ ata_init_devices()

static int ata_init_devices ( ata_devinfo_t * devinfo)
static

Definition at line 1212 of file ps2atad.c.

◆ sceAtaInit()

ata_devinfo_t * sceAtaInit ( int device)

Definition at line 1338 of file ps2atad.c.

◆ sceAtaIdleImmediate()

int sceAtaIdleImmediate ( int device)

Definition at line 1468 of file ps2atad.c.

◆ ata_device_standby_immediate()

static int ata_device_standby_immediate ( int device)
static

Definition at line 1478 of file ps2atad.c.

Variable Documentation

◆ ata_devinfo_init

int ata_devinfo_init = 0
static

Definition at line 68 of file ps2atad.c.

◆ ata_evflg

int ata_evflg = -1
static

Definition at line 69 of file ps2atad.c.

◆ ata_dvrp_workaround

u8 ata_dvrp_workaround = 0
static

Definition at line 72 of file ps2atad.c.

◆ atad_devinfo

ata_devinfo_t atad_devinfo[2]
static

Definition at line 80 of file ps2atad.c.

◆ ata_param

u16 ata_param[256]
static

Definition at line 84 of file ps2atad.c.

◆ ata_cmd_table

const ata_cmd_info_t ata_cmd_table[]
static

Definition at line 93 of file ps2atad.c.

◆ sec_ctrl_cmd_table

const ata_cmd_info_t sec_ctrl_cmd_table[]
static
Initial value:
= {
{ATA_SCE_IDENTIFY_DRIVE, 2},
{ATA_SCE_SECURITY_ERASE_PREPARE, 1},
{ATA_SCE_SECURITY_ERASE_UNIT, 1},
{ATA_SCE_SECURITY_FREEZE_LOCK, 1},
{ATA_SCE_SECURITY_SET_PASSWORD, 3},
{ATA_SCE_SECURITY_UNLOCK, 3},
{ATA_SCE_SECURITY_WRITE_ID, 3},
{ATA_SCE_SECURITY_READ_ID, 2}}

Definition at line 152 of file ps2atad.c.

◆ smart_cmd_table

const ata_cmd_info_t smart_cmd_table[]
static
Initial value:
= {
{ATA_S_SMART_READ_DATA, 2},
{ATA_S_SMART_ENABLE_DISABLE_AUTOSAVE, 1},
{ATA_S_SMART_SAVE_ATTRIBUTE_VALUES, 1},
{ATA_S_SMART_EXECUTE_OFF_LINE, 1},
{ATA_S_SMART_READ_LOG, 2},
{ATA_S_SMART_WRITE_LOG, 3},
{ATA_S_SMART_ENABLE_OPERATIONS, 1},
{ATA_S_SMART_DISABLE_OPERATIONS, 1},
{ATA_S_SMART_RETURN_STATUS, 1}}

Definition at line 163 of file ps2atad.c.

◆ atad_cmd_state

ata_cmd_state_t atad_cmd_state
static

Definition at line 189 of file ps2atad.c.