⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ide.c

📁 MIPS YAMON, a famous monitor inc. source, make file and PDF manuals.
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ * *      ide.c * *      The 'IDE' module implements the IDE driver *      interface to be used via 'IO' device driver services: * *        1) init  device:  configure and initialize IDE driver *        2) open  device:  not used *        3) close device:  not used *        4) read  device:  not used *        5) write device:  not used *        6) ctrl  device:  a) READ  sector *                          b) WRITE sector *			    c) READ info * * ###################################################################### * * mips_start_of_legal_notice *  * Copyright (c) 2004 MIPS Technologies, Inc. All rights reserved. * * * Unpublished rights (if any) reserved under the copyright laws of the * United States of America and other countries. * * This code is proprietary to MIPS Technologies, Inc. ("MIPS * Technologies"). Any copying, reproducing, modifying or use of this code * (in whole or in part) that is not expressly permitted in writing by MIPS * Technologies or an authorized third party is strictly prohibited. At a * minimum, this code is protected under unfair competition and copyright * laws. Violations thereof may result in criminal penalties and fines. * * MIPS Technologies reserves the right to change this code to improve * function, design or otherwise. MIPS Technologies does not assume any * liability arising out of the application or use of this code, or of any * error or omission in such code. Any warranties, whether express, * statutory, implied or otherwise, including but not limited to the implied * warranties of merchantability or fitness for a particular purpose, are * excluded. Except as expressly provided in any written license agreement * from MIPS Technologies or an authorized third party, the furnishing of * this code does not give recipient any license to any intellectual * property rights, including any patent rights, that cover this code. * * This code shall not be exported, reexported, transferred, or released, * directly or indirectly, in violation of the law of any country or * international law, regulation, treaty, Executive Order, statute, * amendments or supplements thereto. Should a conflict arise regarding the * export, reexport, transfer, or release of this code, the laws of the * United States of America shall be the governing law. * * This code constitutes one or more of the following: commercial computer * software, commercial computer software documentation or other commercial * items. If the user of this code, or any related documentation of any * kind, including related technical data or manuals, is an agency, * department, or other entity of the United States government * ("Government"), the use, duplication, reproduction, release, * modification, disclosure, or transfer of this code, or any related * documentation of any kind, is restricted in accordance with Federal * Acquisition Regulation 12.212 for civilian agencies and Defense Federal * Acquisition Regulation Supplement 227.7202 for military agencies. The use * of this code by the Government is further restricted in accordance with * the terms of the license agreement(s) and/or applicable contract terms * and conditions covering this code from MIPS Technologies or an authorized * third party. * * * *  * mips_end_of_legal_notice *  * ************************************************************************//************************************************************************ *      Include files ************************************************************************/#include <sysdefs.h>#include <syserror.h>#include <sysdev.h>#include <syscon_api.h>#include <sys_api.h>#include <io_api.h>#include <ide_api.h>#include <stdio.h>/************************************************************************ *      Definitions ************************************************************************/#define IDE_DATA_OFS		0#define IDE_ERROR_OFS		1#define IDE_SECTOR_COUNT_OFS	2#define IDE_SECTOR_NUMBER_OFS	3#define IDE_CYL_LOW_OFS		4#define IDE_CYL_HI_OFS		5#define IDE_DRIVE_HEAD_OFS	6#define IDE_COMMAND_OFS		7#define IDE_STATUS_OFS		7#define IDE_ERROR_BBK_SHF	7#define IDE_ERROR_BBK_MSK	(MSK(1) << IDE_ERROR_BBK_SHF)#define IDE_ERROR_BBK_BIT	IDE_ERROR_BBK_MSK#define IDE_ERROR_UNC_SHF	6#define IDE_ERROR_UNC_MSK	(MSK(1) << IDE_ERROR_UNC_SHF)#define IDE_ERROR_UNC_BIT	IDE_ERROR_UNC_MSK#define IDE_ERROR_MC_SHF	5#define IDE_ERROR_MC_MSK	(MSK(1) << IDE_ERROR_MC_SHF)#define IDE_ERROR_MC_BIT	IDE_ERROR_MC_MSK#define IDE_ERROR_IDNF_SHF	4#define IDE_ERROR_IDNF_MSK	(MSK(1) << IDE_ERROR_IDNF_SHF)#define IDE_ERROR_IDNF_BIT	IDE_ERROR_IDNF_MSK#define IDE_ERROR_MCR_SHF	3#define IDE_ERROR_MCR_MSK	(MSK(1) << IDE_ERROR_MCR_SHF)#define IDE_ERROR_MCR_BIT	IDE_ERROR_MCR_MSK#define IDE_ERROR_ABRT_SHF	2#define IDE_ERROR_ABRT_MSK	(MSK(1) << IDE_ERROR_ABRT_SHF)#define IDE_ERROR_ABRT_BIT	IDE_ERROR_ABRT_MSK#define IDE_ERROR_TK0NF_SHF	1#define IDE_ERROR_TK0NF_MSK	(MSK(1) << IDE_ERROR_TK0NF_SHF)#define IDE_ERROR_TK0NF_BIT	IDE_ERROR_TK0NF_MSK#define IDE_ERROR_AMNF_SHF	0#define IDE_ERROR_AMNF_MSK	(MSK(1) << IDE_ERROR_AMNF_SHF)#define IDE_ERROR_AMNF_BIT	IDE_ERROR_AMNF_MSK#define IDE_DRIVE_HEAD_DEV_SHF	4#define IDE_DRIVE_HEAD_DEV_MSK  (MSK(1) << IDE_DRIVE_HEAD_DEV_SHF)#define IDE_DRIVE_HEAD_DEV_BIT  IDE_DRIVE_HEAD_DEV_MSK#define IDE_STATUS_ERR_SHF	0#define IDE_STATUS_ERR_MSK	(MSK(1) << IDE_STATUS_ERR_SHF)#define IDE_STATUS_ERR_BIT	IDE_STATUS_ERR_MSK#define IDE_STATUS_DRQ_SHF	3#define IDE_STATUS_DRQ_MSK	(MSK(1) << IDE_STATUS_DRQ_SHF)#define IDE_STATUS_DRQ_BIT	IDE_STATUS_DRQ_MSK#define IDE_STATUS_DSC_SHF	4#define IDE_STATUS_DSC_MSK	(MSK(1) << IDE_STATUS_DSC_SHF)#define IDE_STATUS_DSC_BIT	IDE_STATUS_DSC_MSK#define IDE_STATUS_DF_SHF	5#define IDE_STATUS_DF_MSK	(MSK(1) << IDE_STATUS_DF_SHF)#define IDE_STATUS_DF_BIT	IDE_STATUS_DF_MSK#define IDE_STATUS_DRDY_SHF	6#define IDE_STATUS_DRDY_MSK	(MSK(1) << IDE_STATUS_DRDY_SHF)#define IDE_STATUS_DRDY_BIT	IDE_STATUS_DRDY_MSK#define IDE_STATUS_BSY_SHF	7#define IDE_STATUS_BSY_MSK	(MSK(1) << IDE_STATUS_BSY_SHF)#define IDE_STATUS_BSY_BIT	IDE_STATUS_BSY_MSK/*  Calc addresses to use for 8 and 32 bit accesses to IDE controller. *  Macro SWAP_BYTEADDR_EL swaps the 2 lsb bits of the addr in case  *  CPU is running Big Endian.  *  This is since we assume the IDE controller is a PCI device,  *  and PCI is always Little Endian. */#define IO_ADDR(ofs)		(pci_io_base + ide_io_base + (ofs))#define IO32(ofs)		REG32(KSEG1(IO_ADDR(ofs)))#define IO8(ofs)		REG8(KSEG1(SWAP_BYTEADDR_EL(IO_ADDR(ofs))))#define IDE_PRIMARY_IO_CMD_BASE		0x1f0#define IDE_SECONDARY_IO_CMD_BASE	0x170#define IDE_DEV_MASTER			0#define IDE_DEV_SLAVE			1/************************************************************************ *  Macro Definitions*************************************************************************//************************************************************************ *      Public variables ************************************************************************//************************************************************************ *      Static variables ************************************************************************/static char* ide_error_string[] = {    /* ERROR_IDE_INVALID_COMMAND */      "Internal ERROR: Invalid control command",    /* ERROR_IDE_UNKNOWN_DEVICE */      "Internal ERROR: Illegal minor number",    /* ERROR_IDE_NULL_BUFFER */	    "Internal ERROR: NULL buffer",    /* ERROR_IDE_UNAVAILABLE_DEVICE */    "Device unavailable",    /* ERROR_IDE_BAD_BLOCK */    "Bad block detected",    /* ERROR_IDE_UNCORRECTABLE_DATA */    "Uncorrectable data error",    /* ERROR_IDE_MEDIA_CHANGE */    "Media change",    /* ERROR_IDE_ID_NOT_FOUND */    "ID not found (damaged or non-existent sector)",    /* ERROR_IDE_MEDIA_CHANGE_REQUESTED */    "Media change requested",    /* ERROR_IDE_ABORTED */    "Aborted command (illegal command or disk drive error)",    /* ERROR_IDE_TRACK_0_NOT_FOUND */    "Track 0 not found",    /* ERROR_IDE_ADDRESS_MARK_NOT_FOUND	*/    "Address mark not found",    /* ERROR_IDE_UNKNOWN */    "Unknown IDE error"};static UINT32 pci_io_base;    /* Base access of PCI I/O range		*/static UINT32 ide_io_base;    /* Offset of IDE device within I/O range	*/static UINT32 sector;	      /* Last sector read (or failed)		*/static bool   sector_valid;   /* 'sector' valid for error handling	*/static char   diag_msg[40];   /* Diagnostics error message		*//************************************************************************ *      Static function prototypes ************************************************************************/static UINT32get_error( void );/************************************************************************ *      Implementation : Static functions ************************************************************************//************************************************************************ * *                          ide_init *  Description : *  ------------- * *  This service initializes the IDE driver. * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    not used *  'p_param',   INOUT, not used * * *  Return values : *  --------------- * *  'OK'(=0) * ************************************************************************/static INT32 ide_init(    UINT32 major,          /* IN: major device number             */    UINT32 minor,          /* IN: minor device number             */    void   *p_param )      /* INOUT: device parameter block       */{    /* Read base of PCI I/O range */    return SYSCON_read(        SYSCON_CORE_PCI_IO_OFFSET,	(void *)&pci_io_base,	sizeof(UINT32) );}/************************************************************************ * *                          ide_ctrl *  Description : *  ------------- *  This service comprises following specific IDE services: * *    1) IDE_CMD_READ *    2) IDE_CMD_WRITE *    3) IDE_CMD_IDENTIFY * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    minor device number for multi device drivers *  'p_param',   IN,    variable of type, t_ide_ctrl_descriptor. * *  Return values : *  --------------- * *  OK (0x00):                   IDE service completed successfully *  Other :			 See error codes in ide_api.h * ************************************************************************/static INT32 ide_ctrl(    UINT32                major,     /* IN: major device number		*/    UINT32		  minor,     /* IN: minor device number		*/    t_ide_ctrl_descriptor *p_param ) /* IN: write data			*/{    UINT32          i,t;    UINT32	    sector_count;    UINT8	    dev;    UINT16	    buf_id[IDE_BYTES_PER_SECTOR/2]; /* 16 bit aligned  */    t_ide_identify  *identify_struct;    UINT8	    *buffer;    UINT8	    status;    UINT32	    data32;    /* Sector number is not valid for error handling any more */    sector_valid = FALSE;    switch( minor )    {      case IDE_MINOR_PRIMARY_MASTER :        ide_io_base = IDE_PRIMARY_IO_CMD_BASE;        dev	    = IDE_DEV_MASTER;	break;      case IDE_MINOR_PRIMARY_SLAVE :        ide_io_base = IDE_PRIMARY_IO_CMD_BASE;        dev	    = IDE_DEV_SLAVE;	break;      case IDE_MINOR_SECONDARY_MASTER :        ide_io_base = IDE_SECONDARY_IO_CMD_BASE;        dev	    = IDE_DEV_MASTER;	break;      case IDE_MINOR_SECONDARY_SLAVE :        ide_io_base = IDE_SECONDARY_IO_CMD_BASE;        dev	    = IDE_DEV_SLAVE;	break;      default :        return ERROR_IDE_UNKNOWN_DEVICE;    }    switch( p_param->command )    {      case IDE_CMD_READ  :      case IDE_CMD_WRITE :        sector          = p_param->u.sector.sector;	sector_count    = p_param->u.sector.count;	buffer          = p_param->u.sector.buffer;	if( buffer == NULL ) 	    return ERROR_IDE_NULL_BUFFER;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -