Add MMC START STOP interface.

This commit is contained in:
rocky
2005-03-09 10:23:01 +00:00
parent 912ab1082d
commit 8e8c54a457
3 changed files with 401 additions and 349 deletions

View File

@@ -1,5 +1,5 @@
/*
$Id: mmc.h,v 1.17 2005/03/06 02:59:26 rocky Exp $
$Id: mmc.h,v 1.18 2005/03/09 10:23:01 rocky Exp $
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -37,18 +37,18 @@
extern "C" {
#endif /* __cplusplus */
/*! \brief The opcode-portion (generic packet commands) of an MMC command.
/*! \brief The opcode-portion (generic packet commands) of an MMC command.
In general, those opcodes that end in 6 take a 6-byte command
descriptor, those that end in 10 take a 10-byte
descriptor and those that in in 12 take a 12-byte descriptor.
In general, those opcodes that end in 6 take a 6-byte command
descriptor, those that end in 10 take a 10-byte
descriptor and those that in in 12 take a 12-byte descriptor.
(Not that you need to know that, but it seems to be a
big deal in the MMC specification.)
(Not that you need to know that, but it seems to be a
big deal in the MMC specification.)
*/
typedef enum {
*/
typedef enum {
CDIO_MMC_GPCMD_INQUIRY = 0x12, /**< Request drive
information. */
CDIO_MMC_GPCMD_MODE_SELECT_6 = 0x15, /**< Select medium
@@ -339,10 +339,10 @@ typedef struct mmc_cdb_s {
uint8_t field[MAX_CDB_LEN];
} mmc_cdb_t;
/*! \brief Format of header block in data returned from an MMC
/*! \brief Format of header block in data returned from an MMC
GET_CONFIGURATION command.
*/
typedef struct mmc_feature_list_header_s {
typedef struct mmc_feature_list_header_s {
unsigned char length_msb;
unsigned char length_1sb;
unsigned char length_2sb;
@@ -351,18 +351,18 @@ typedef struct mmc_feature_list_header_s {
unsigned char reserved2;
unsigned char profile_msb;
unsigned char profile_lsb;
} mmc_feature_list_header_t;
} mmc_feature_list_header_t;
/*! An enumeration indicating whether an MMC command is sending
/*! An enumeration indicating whether an MMC command is sending
data or getting data.
*/
typedef enum mmc_direction_s {
typedef enum mmc_direction_s {
SCSI_MMC_DATA_READ,
SCSI_MMC_DATA_WRITE
} mmc_direction_t;
} mmc_direction_t;
typedef struct mmc_subchannel_s
{
typedef struct mmc_subchannel_s
{
uint8_t reserved;
uint8_t audio_status;
uint16_t data_length; /* Really 7.2.2 */
@@ -373,7 +373,7 @@ typedef struct mmc_subchannel_s
uint8_t index;
uint8_t abs_addr[4];
uint8_t rel_addr[4];
} mmc_subchannel_t;
} mmc_subchannel_t;
#define CDIO_MMC_SET_COMMAND(cdb, command) \
cdb[0] = command
@@ -425,50 +425,58 @@ typedef struct mmc_subchannel_s
driver_return_code_t
mmc_audio_read_subchannel (CdIo_t *p_cdio, cdio_subchannel_t *p_subchannel);
/*!
/*!
Return a string containing the name of the audio state as returned from
the Q_SUBCHANNEL.
*/
const char *mmc_audio_state2str( uint8_t i_audio_state );
const char *mmc_audio_state2str( uint8_t i_audio_state );
/*!
* Eject using MMC commands.
@return 0 if successful.
/*!
Eject using MMC commands. If CD-ROM is "locked" we'll unlock it.
Command is not "immediate" -- we'll wait for the command to complete.
For a more general (and lower-level) routine, @see mmc_start_stop_media.
*/
int mmc_eject_media( const CdIo_t *p_cdio );
driver_return_code_t mmc_eject_media( const CdIo_t *p_cdio );
/*!
/*!
Return a string containing the name of the given feature
*/
const char *mmc_feature2str( int i_feature );
const char *mmc_feature2str( int i_feature );
/*!
/*!
Return a string containing the name of the given feature
*/
const char *mmc_feature_profile2str( int i_feature_profile );
const char *mmc_feature_profile2str( int i_feature_profile );
/*!
/*!
Return the length in bytes of the Command Descriptor
Buffer (CDB) for a given MMC command. The length will be
either 6, 10, or 12.
*/
uint8_t mmc_get_cmd_len(uint8_t mmc_cmd);
*/
uint8_t mmc_get_cmd_len(uint8_t mmc_cmd);
/*!
/*!
Get the block size used in read requests, via MMC.
@return the blocksize if > 0; error if <= 0
*/
int mmc_get_blocksize ( CdIo_t *p_cdio );
int mmc_get_blocksize ( CdIo_t *p_cdio );
/*!
#if 0
/*! Don't know how to implement yet. */
/*!
* Close tray using a MMC START STOP command.
*/
driver_return_code_t mmc_close_tray( const char *psz_device );
#endif
/*!
Get the lsn of the end of the CD
@return the lsn. On error return CDIO_INVALID_LSN.
*/
lsn_t mmc_get_disc_last_lsn( const CdIo_t *p_cdio );
*/
lsn_t mmc_get_disc_last_lsn( const CdIo_t *p_cdio );
/*!
/*!
Return the discmode as reported by the MMC Read (FULL) TOC
command.
@@ -477,45 +485,45 @@ lsn_t mmc_get_disc_last_lsn( const CdIo_t *p_cdio );
at http://www.t10.org/ftp/t10/drafts/mmc/mmc-r10a.pdf See
especially tables 72, 73 and 75.
*/
discmode_t mmc_get_discmode( const CdIo_t *p_cdio );
discmode_t mmc_get_discmode( const CdIo_t *p_cdio );
/*!
/*!
Get drive capabilities for a device.
@return the drive capabilities.
*/
void mmc_get_drive_cap ( CdIo_t *p_cdio,
void mmc_get_drive_cap ( CdIo_t *p_cdio,
/*out*/ cdio_drive_read_cap_t *p_read_cap,
/*out*/ cdio_drive_write_cap_t *p_write_cap,
/*out*/ cdio_drive_misc_cap_t *p_misc_cap);
/*!
/*!
Get the DVD type associated with cd object.
@return the DVD discmode.
*/
discmode_t mmc_get_dvd_struct_physical ( const CdIo_t *p_cdio,
*/
discmode_t mmc_get_dvd_struct_physical ( const CdIo_t *p_cdio,
cdio_dvd_struct_t *s);
/*!
/*!
Get the CD-ROM hardware info via an MMC INQUIRY command.
@return true if we were able to get hardware info, false if we had
an error.
*/
bool mmc_get_hwinfo ( const CdIo_t *p_cdio,
*/
bool mmc_get_hwinfo ( const CdIo_t *p_cdio,
/* out*/ cdio_hwinfo_t *p_hw_info );
/*!
/*!
Find out if media has changed since the last call.
@param p_cdio the CD object to be acted upon.
@return 1 if media has changed since last call, 0 if not. Error
return codes are the same as driver_return_code_t
*/
int mmc_get_media_changed(const CdIo_t *p_cdio);
int mmc_get_media_changed(const CdIo_t *p_cdio);
/*!
/*!
Get the media catalog number (MCN) from the CD via MMC.
@return the media catalog number r NULL if there is none or we
@@ -524,48 +532,48 @@ int mmc_get_media_changed(const CdIo_t *p_cdio);
Note: string is malloc'd so caller has to free() the returned
string when done with it.
*/
char * mmc_get_mcn ( const CdIo_t *p_cdio );
*/
char * mmc_get_mcn ( const CdIo_t *p_cdio );
/** Get the output port volumes and port selections used on AUDIO PLAY
/** Get the output port volumes and port selections used on AUDIO PLAY
commands via a MMC MODE SENSE command using the CD Audio Control
Page.
*/
driver_return_code_t mmc_audio_get_volume (CdIo_t *p_cdio, /*out*/
driver_return_code_t mmc_audio_get_volume (CdIo_t *p_cdio, /*out*/
mmc_audio_volume_t *p_volume);
/*!
/*!
Report if CD-ROM has a praticular kind of interface (ATAPI, SCSCI, ...)
Is it possible for an interface to have serveral? If not this
routine could probably return the sincle mmc_feature_interface_t.
@return true if we have the interface and false if not.
*/
bool_3way_t mmc_have_interface( CdIo_t *p_cdio,
bool_3way_t mmc_have_interface( CdIo_t *p_cdio,
mmc_feature_interface_t e_interface );
/*! Run a MODE_SENSE command (6- or 10-byte version)
/*! Run a MODE_SENSE command (6- or 10-byte version)
and put the results in p_buf
@return DRIVER_OP_SUCCESS if we ran the command ok.
*/
int mmc_mode_sense( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size,
*/
int mmc_mode_sense( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size,
int page);
/*! Run a MODE_SENSE command (10-byte version)
/*! Run a MODE_SENSE command (10-byte version)
and put the results in p_buf
@return DRIVER_OP_SUCCESS if we ran the command ok.
*/
int mmc_mode_sense_10( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size,
*/
int mmc_mode_sense_10( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size,
int page);
/*! Run a MODE_SENSE command (6-byte version)
/*! Run a MODE_SENSE command (6-byte version)
and put the results in p_buf
@return DRIVER_OP_SUCCESS if we ran the command ok.
*/
int mmc_mode_sense_6( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size,
*/
int mmc_mode_sense_6( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size,
int page);
/*! Issue a MMC READ_CD command.
/*! Issue a MMC READ_CD command.
@param p_cdio object to read from
@@ -662,16 +670,16 @@ int mmc_mode_sense_6( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size,
@param i_blocks number of blocks expected to be returned.
*/
driver_return_code_t
mmc_read_cd ( const CdIo_t *p_cdio, void *p_buf, lsn_t i_lsn,
*/
driver_return_code_t
mmc_read_cd ( const CdIo_t *p_cdio, void *p_buf, lsn_t i_lsn,
int expected_sector_type, bool b_digital_audio_play,
bool b_sync, uint8_t header_codes, bool b_user_data,
bool b_edc_ecc, uint8_t c2_error_information,
uint8_t subchannel_selection, uint16_t i_blocksize,
uint32_t i_blocks );
/*! Read just the user data part of some sort of data sector (via
/*! Read just the user data part of some sort of data sector (via
mmc_read_cd).
@param p_cdio object to read from
@@ -687,26 +695,26 @@ mmc_read_cd ( const CdIo_t *p_cdio, void *p_buf, lsn_t i_lsn,
@param i_lsn sector to read
@param i_blocksize
*/
driver_return_code_t mmc_read_data_sectors ( CdIo_t *p_cdio, void *p_buf,
*/
driver_return_code_t mmc_read_data_sectors ( CdIo_t *p_cdio, void *p_buf,
lsn_t i_lsn,
uint16_t i_blocksize,
uint32_t i_blocks );
/*! issue a MMC read mode2 sectors. - depricated.
*/
driver_return_code_t mmc_read_sectors ( const CdIo_t *p_cdio, void *p_buf,
/*! issue a MMC read mode2 sectors. - depricated.
*/
driver_return_code_t mmc_read_sectors ( const CdIo_t *p_cdio, void *p_buf,
lsn_t i_lsn, int read_sector_type,
uint32_t i_blocks);
/*!
/*!
Run an MMC command.
@param p_cdio CD structure set by cdio_open().
@param i_timeout_ms time in milliseconds we will wait for the command
to complete.
@param p_cdb CDB bytes. All values that are needed should be set on
input. We'll figure out what the right CDB length
@param p_cdb CDB bytes. All values that are needed should be set
on input. We'll figure out what the right CDB length
should be.
@param e_direction direction the transfer is to go.
@param i_buf Size of buffer
@@ -714,20 +722,35 @@ driver_return_code_t mmc_read_sectors ( const CdIo_t *p_cdio, void *p_buf,
@return 0 if command completed successfully.
*/
int mmc_run_cmd( const CdIo_t *p_cdio, unsigned int i_timeout_ms,
int mmc_run_cmd( const CdIo_t *p_cdio, unsigned int i_timeout_ms,
const mmc_cdb_t *p_cdb,
mmc_direction_t e_direction, unsigned int i_buf,
/*in/out*/ void *p_buf );
/*!
/*!
Set the block size for subsequest read requests, via MMC.
*/
driver_return_code_t mmc_set_blocksize ( const CdIo_t *p_cdio,
driver_return_code_t mmc_set_blocksize ( const CdIo_t *p_cdio,
uint16_t i_blocksize);
/*!
/*!
Set the drive speed.
*/
driver_return_code_t mmc_set_speed( const CdIo_t *p_cdio, int i_speed );
*/
driver_return_code_t mmc_set_speed( const CdIo_t *p_cdio, int i_speed );
/*!
Load or Unload media using a MMC START STOP command.
@param p_cdio the CD object to be acted upon.
@param b_eject eject if true and close tray if false
@param b_immediate wait or don't wait for operation to complete
@param power_condition Set CD-ROM to idle/standby/sleep. If nonzero
eject/load is ignored, so set to 0 if you want to eject or load.
@see mmc_eject_media or mmc_close_tray
*/
driver_return_code_t
mmc_start_stop_media(const CdIo_t *p_cdio, bool b_eject, bool b_immediate,
uint8_t power_condition);
#ifdef __cplusplus
}

View File

@@ -185,5 +185,6 @@ mmc_read_sectors
mmc_run_cmd
mmc_set_blocksize
mmc_set_speed
mmc_start_stop
track_format2str
CDIO_SECTOR_SYNC_HEADER

View File

@@ -1,6 +1,6 @@
/* Common Multimedia Command (MMC) routines.
$Id: mmc.c,v 1.21 2005/03/06 02:59:26 rocky Exp $
$Id: mmc.c,v 1.22 2005/03/09 10:23:03 rocky Exp $
Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -521,7 +521,7 @@ mmc_set_blocksize_private ( void *p_env,
************************************************************/
/*!
Return the number of length in bytes of the Command Descriptor
buffer (CDB) for a given SCSI MMC command. The length will be
buffer (CDB) for a given MMC command. The length will be
either 6, 10, or 12.
*/
uint8_t
@@ -623,7 +623,7 @@ mmc_audio_read_subchannel (CdIo_t *p_cdio, cdio_subchannel_t *p_subchannel)
command.
Information was obtained from Section 5.1.13 (Read TOC/PMA/ATIP)
pages 56-62 from the SCSI MMC draft specification, revision 10a
pages 56-62 from the MMC draft specification, revision 10a
at http://www.t10.org/ftp/t10/drafts/mmc/mmc-r10a.pdf See
especially tables 72, 73 and 75.
*/
@@ -744,14 +744,14 @@ mmc_get_dvd_struct_physical ( const CdIo_t *p_cdio, cdio_dvd_struct_t *s)
}
/*!
Get the CD-ROM hardware info via a SCSI MMC INQUIRY command.
Get the CD-ROM hardware info via a MMC INQUIRY command.
False is returned if we had an error getting the information.
*/
bool
mmc_get_hwinfo ( const CdIo_t *p_cdio,
/*out*/ cdio_hwinfo_t *hw_info )
{
int i_status; /* Result of SCSI MMC command */
int i_status; /* Result of MMC command */
char buf[36] = { 0, }; /* Place to hold returned data */
mmc_cdb_t cdb = {{0, }}; /* Command Descriptor Block */
@@ -823,7 +823,7 @@ mmc_get_mcn ( const CdIo_t *p_cdio )
}
/*!
Run a SCSI MMC command.
Run a MMC command.
cdio CD structure set by cdio_open().
i_timeout time in milliseconds we will wait for the command
@@ -892,7 +892,51 @@ mmc_get_blocksize ( CdIo_t *p_cdio)
/*!
* Eject using SCSI MMC commands. Return 0 if successful.
* Load or Unload media using a MMC START STOP command.
*/
driver_return_code_t
mmc_start_stop_media(const CdIo_t *p_cdio, bool b_eject, bool b_immediate,
uint8_t power_condition)
{
mmc_cdb_t cdb = {{0, }};
uint8_t buf[1];
if ( ! p_cdio ) return DRIVER_OP_UNINIT;
if ( ! p_cdio->op.run_mmc_cmd ) return DRIVER_OP_UNSUPPORTED;
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_START_STOP);
if (b_immediate) cdb.field[1] |= 1;
if (power_condition)
cdb.field[4] = power_condition << 4;
else {
if (b_eject)
cdb.field[4] = 2; /* eject */
else
cdb.field[4] = 3; /* close tray for tray-type */
}
return p_cdio->op.run_mmc_cmd (p_cdio->env, DEFAULT_TIMEOUT_MS,
mmc_get_cmd_len(cdb.field[0]), &cdb,
SCSI_MMC_DATA_WRITE, 0, &buf);
}
#if 0
/*!
* Close tray using a MMC START STOP command.
*/
driver_return_code_t
mmc_close_tray( const CdIo_t *p_cdio )
{
return mmc_start_stop_media(p_cdio, false, false, 0);
}
#endif
/*!
Eject using MMC commands. If CD-ROM is "locked" we'll unlock it.
Command is not "immediate" -- we'll wait for the command to complete.
For a more general (and lower-level) routine, @see mmc_start_stop_media.
*/
driver_return_code_t
mmc_eject_media( const CdIo_t *p_cdio )
@@ -900,34 +944,18 @@ mmc_eject_media( const CdIo_t *p_cdio )
int i_status = 0;
mmc_cdb_t cdb = {{0, }};
uint8_t buf[1];
mmc_run_cmd_fn_t run_mmc_cmd;
if ( ! p_cdio ) return DRIVER_OP_UNINIT;
if ( ! p_cdio->op.run_mmc_cmd ) return DRIVER_OP_UNSUPPORTED;
run_mmc_cmd = p_cdio->op.run_mmc_cmd;
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_ALLOW_MEDIUM_REMOVAL);
i_status = run_mmc_cmd (p_cdio->env, DEFAULT_TIMEOUT_MS,
i_status = p_cdio->op.run_mmc_cmd (p_cdio->env, DEFAULT_TIMEOUT_MS,
mmc_get_cmd_len(cdb.field[0]), &cdb,
SCSI_MMC_DATA_WRITE, 0, &buf);
if (0 != i_status) return i_status;
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_START_STOP);
cdb.field[4] = 1;
i_status = run_mmc_cmd (p_cdio->env, DEFAULT_TIMEOUT_MS,
mmc_get_cmd_len(cdb.field[0]), &cdb,
SCSI_MMC_DATA_WRITE, 0, &buf);
if (0 != i_status)
return i_status;
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_START_STOP);
cdb.field[4] = 2; /* eject */
return run_mmc_cmd (p_cdio->env, DEFAULT_TIMEOUT_MS,
mmc_get_cmd_len(cdb.field[0]), &cdb,
SCSI_MMC_DATA_WRITE, 0, &buf);
return mmc_start_stop_media(p_cdio, true, false, 0);
}