OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 1019 to Rev 1020
    Reverse comparison

Rev 1019 → Rev 1020

/trunk/orpmon/services/dos.c
33,7 → 33,7
*/
int dos_open(struct dosparam *params)
{
int error;
int error, start_sector, partition;
unsigned char buf[512];
 
struct inode *inode = &params->inode;
44,15 → 44,35
return error;
 
 
/* device opened, read boot-sector */
/* device opened, read MBR */
request->cmd = READ;
request->sector = 0;
request->nr_sectors = 1;
request->buffer = buf;
 
/* skip bootload (446) bytes */
/* currently only support the first partition (partition 4) */
/* This is OK, because CompactFLASH devices only have 1 partition */
if ( (error = ata_request(inode, filp, request)) )
return error;
 
partition = 0; /* first partition */
partition *= 16; /* 16 bytes per partition table */
partition += 446; /* skip bootloader, go to partition table */
start_sector = buf[partition +11] << 24 |
buf[partition +10] << 16 |
buf[partition +9] << 8 |
buf[partition +8];
 
/* device opened, read boot-sector */
request->cmd = READ;
request->sector = start_sector;
request->nr_sectors = 1;
request->buffer = buf;
 
if ( (error = ata_request(inode, filp, request)) )
return error;
 
/* get the necessary data from the boot-sector */
params->bytes_per_sector = (buf[12]<<8) | buf[11];
params->fats = buf[16];
62,11 → 82,11
 
 
/* set start of current directory to start of root-directory */
params->ssector = params->fats * params->sectors_per_fat +1;
params->ssector = start_sector + params->fats * params->sectors_per_fat +1;
 
/* set current sector to start of root-directory */
params->csector = params->ssector;
 
/* set start-entry number */
params->sentry = 0;
 
/trunk/orpmon/include/hdbug.h
30,7 → 30,7
#define HD_DEBUG
 
 
#define MAX_HDBUG_COMMANDS 25
#define MAX_HDBUG_COMMANDS 10
 
/* ---------------------------- */
/* ----- Prototypes ----- */
/trunk/orpmon/include/atabug.h
32,6 → 32,19
 
#define MAX_ATA_COMMANDS 25
 
struct partition {
char boot;
char start_head;
short start_cylinder;
char start_sector;
char system;
char end_head;
short end_cylinder;
char end_sector;
int start;
int sectors;
};
 
/* ---------------------------- */
/* ----- Prototypes ----- */
/* ---------------------------- */
46,11 → 59,13
int ata_close_cmd(int arc, char **argv);
int ata_dump_device_regs_cmd(int argc, char **argv);
int ata_dump_host_regs_cmd(int argc, char **argv);
int ata_dump_dataport_cmd(int argc, char **argv);
int ata_enable_cmd(int argc, char **argv);
int ata_exec_cmd_cmd(int argc, char **argv);
int ata_identify_device_cmd(int argc, char **argv);
int ata_open_cmd(int argc, char **argv);
int ata_read_sectors_cmd(int argc, char **argv);
int ata_read_mbr_cmd(int argc, char **argv);
int ata_read_dosboot_cmd(int argc, char **argv);
int ata_reset_cmd(int argc, char **argv);
int ata_select_device_cmd(int argc, char **argv);
58,5 → 73,4
 
unsigned char atabug_dump_data(unsigned char *buffer, int cnt);
 
 
#endif
/trunk/orpmon/include/ata.h
276,6 → 276,7
#define ata_astatus(base) (REG32(base + ATA_ASR))
#define ata_status(base) (REG32(base + ATA_SR))
#define ata_error(base) (REG32(base + ATA_ERR))
#define ata_cmd(base) (REG32(base + ATA_CR))
 
#define ata_dev_busy(base) (ata_astatus(base) & ATA_SR_BSY)
#define ata_dev_cmdrdy(base) (ata_astatus(base) & (~ATA_SR_BSY & ATA_SR_DRDY))
311,13 → 312,16
#define MINOR_DEV1 0X80
 
 
#define ATA_IOCTL_IDENTIFY_DEVICE 0
#define ATA_IOCTL_IDENTIFY_HOST 1
#define ATA_IOCTL_SELECT_DEVICE 3
#define ATA_IOCTL_SET_RST 4
#define ATA_IOCTL_SET_PIO 5
#define ATA_IOCTL_SET_FEATURES 6
#define ATA_IOCTL_SET_FTE 7
#define ATA_IOCTL_EXEC_CMD 0
#define ATA_IOCTL_READ 1
#define ATA_IOCTL_ENABLE_HOST 2
#define ATA_IOCTL_IDENTIFY_DEVICE 3
#define ATA_IOCTL_IDENTIFY_HOST 4
#define ATA_IOCTL_SELECT_DEVICE 5
#define ATA_IOCTL_SET_RST 6
#define ATA_IOCTL_SET_PIO 7
#define ATA_IOCTL_SET_FEATURES 8
#define ATA_IOCTL_SET_FTE 9
 
#define ARG_HW_RST 0
#define ARG_SW_RST 1
449,6 → 453,8
int ata_ioctl(struct inode *inode, struct file *filp, unsigned command, unsigned long argument);
unsigned long ata_calc_pio_timing(short t0, short t1, short t2, short t4, short t2i, short t9);
 
int ata_read_dport(unsigned long base);
 
int ata_check_media_change(dev_t dev);
 
int ata_revalidate(dev_t dev);
/trunk/orpmon/include/dos.h
38,7 → 38,7
unsigned long ssector; // startsector of current directory
unsigned long csector; // startsector of current cluster
unsigned long sentry; // startentry of current cluster
unsigned char cbuf[2048]; // cluster buffer. This should be dynamically alocated
unsigned char cbuf[8192]; // cluster buffer. This should be dynamically alocated
 
/* ata driver structures */
struct inode inode;
/trunk/orpmon/cmds/atabug.c
62,15 → 62,16
register_ata_command ("exit", "", "Exit atabug and return to ORPmon", atabug_exit);
register_ata_command ("open", "<device> [<mode>]", "Opens the requested device. Device=<0|1>, Mode=<r>eadonly|read<w>rite.", ata_open_cmd);
register_ata_command ("close", "", "Closes the device.", ata_close_cmd);
register_ata_command ("reset", "<mode>", "Reset ata device(s). Mode: 0=hw_reset, 1=sw_reset, 2=device_reset", ata_reset_cmd);
register_ata_command ("enable", "<mode>", "Clear ata reset bits. Mode: 0=hw_reset, 1=sw_reset", ata_enable_cmd);
register_ata_command ("reset", "<mode>", "Reset ata device(s).", ata_reset_cmd);
register_ata_command ("enable", "", "Enables ATA host controller, clears all resets", ata_enable_cmd);
register_ata_command ("dump_dev_regs", "", "Dump the (readable) ata device registers.", ata_dump_device_regs_cmd);
register_ata_command ("dump_host_regs", "", "Dump the ata host registers.", ata_dump_host_regs_cmd);
register_ata_command ("exec_cmd", "<cmd>", "Execute ata command <cmd> (hex)", ata_exec_cmd_cmd);
register_ata_command ("identify_device", "", "Dumps device's IDENTIFY DEVICE block.", ata_identify_device_cmd);
register_ata_command ("program_timing", "<PIO mode>", "Programs the device to the selected PIO mode.", ata_set_piomode_cmd);
register_ata_command ("read_sectors", "<startsector> [<sectorcount>]", "Reads sector <sectorno>(dec)from the selected device (LBA mode)", ata_read_sectors_cmd);
register_ata_command ("read_dosboot", "", "Reads the device's bootsector (FAT).", ata_read_dosboot_cmd);
register_ata_command ("read_sectors", "<startsector> [<sectorcount>]", "Reads sector", ata_read_sectors_cmd);
register_ata_command ("read_mbr", "<partition>", "Reads the Master Boot Record.", ata_read_mbr_cmd);
register_ata_command ("read_dosboot", "<sector>", "Reads the device's bootsector (FAT).", ata_read_dosboot_cmd);
register_ata_command ("select_device", "<device_no>", "Select ata device. device_no=<0|1>", ata_select_device_cmd);
}
 
225,7 → 226,7
int ata_close_cmd(int argc, char **argv)
{
inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0');
 
return ata_release(inode, filp);
}
 
270,7 → 271,7
printf("Status register STAT : 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_STAT) );
printf("Pio command timing register PCTR : 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_PCTR) );
printf("Pio fast timing register (device0) PFTR0: 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_PFTR0) );
printf("Pio fast timing register (device1) PFTR1: 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_PFTR0) );
printf("Pio fast timing register (device1) PFTR1: 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_PFTR1) );
printf("Dma timing register (device0) DTR0 : 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_DTR0) );
printf("Dma timing register (device1) DTR1 : 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_DTR1) );
 
285,15 → 286,26
*/
int ata_enable_cmd(int argc, char **argv)
{
if (argc != 1)
return -1;
if (argc != 0)
printf("Ignoring invalid parameters\n");
 
inode->i_rdev = (ATA_BASE_ADDR >> 16);
 
if ( ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | (**argv - '0') ) )
// clear hardware reset bit
if ( ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | ARG_HW_RST) )
return -1;
else
return 0;
 
// clear software reset bit
if ( ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | ARG_SW_RST) )
return -1;
 
// enable ATA Hostcontroller core
if ( ata_ioctl(inode, filp, ATA_IOCTL_ENABLE_HOST, 0) )
return -1;
 
printf("ATA host controller enabled\n");
 
return 0;
}
 
 
307,7 → 319,9
if (argc != 1)
return -1;
 
REG32(ATA_BASE_ADDR + ATA_CR) = strtoul(*argv, argv, 16);
inode->i_rdev = (ATA_BASE_ADDR >> 16);
ata_ioctl(inode, filp, ATA_IOCTL_EXEC_CMD, strtoul(*argv, argv, 16) );
return 0;
}
 
331,12 → 345,20
else
{
/* execute identify device */
ata_ioctl(inode, filp, ATA_IOCTL_IDENTIFY_DEVICE, (unsigned long) buf);
ata_ioctl(inode, filp, ATA_IOCTL_EXEC_CMD, IDENTIFY_DEVICE);
 
/* read block from ata-device */
buf[0] = 0;
buf[1] = 1;
ata_ioctl(inode, filp, ATA_IOCTL_READ, (unsigned long) buf);
 
/* dump data to the screen */
checksum = atabug_dump_data(buf, 256);
checksum = atabug_dump_data(buf, 512);
 
printf("Checksum = 0x%02X (%s)\n", checksum, checksum ? "error" : "OK");
if (buf[512] == 0xa5)
printf("Checksum = 0x%02X (%s)\n", checksum, checksum ? "error" : "OK");
else
printf("No checksum supported\n");
}
return 0;
}
397,7 → 419,7
unsigned long sector_cnt, sector;
 
sector = strtoul(argv[0], argv, 10);
 
switch (argc) {
case 2:
sector_cnt = strtoul(argv[1], argv, 10);
410,7 → 432,7
default:
return -1;
}
 
if ( !sector_cnt )
{
printf( "Invalid number of sectors.\n" );
436,7 → 458,7
else
{
/* dump data to the screen */
atabug_dump_data(buf, 256 * sector_cnt);
atabug_dump_data(buf, 512 * sector_cnt);
}
}
return 0;
444,15 → 466,92
 
 
/*
A T A _ R E A D B O O T
A T A _ R E A D _ M B R
 
Reads master boot record from the device and dumps it's contents to the screen
*/
int ata_read_mbr_cmd(int argc, char **argv)
{
struct request request;
unsigned int partition;
 
// get requested partition number
partition = 0;
if (argc)
partition = strtoul(*argv, argv, 10);
 
/* check for busy flag */
if ( ata_dev_busy(ATA_BASE_ADDR) )
printf("Selected ata device busy, ignoring command\n");
else
{
/* fill the request structure */
request.cmd = READ;
request.sector = 0;
request.nr_sectors = 1;
request.buffer = buf;
 
if ( ata_request(inode, filp, &request) )
{
printf("Error while reading master boot sector.\n");
printf("Status register = 0x%02lX, error register = 0x%02lX\n", ata_astatus(ATA_BASE_ADDR), ata_error(ATA_BASE_ADDR) );
}
else
{
printf( "Skipping bootloader (446bytes)\n" );
printf( "Partition %1d:\n", partition);
 
// abuse partitionnumber to get offset in MBR record
partition *= 16;
partition += 446;
 
printf( "Bootindicator: 0x%2X (%s)\n", buf[partition], buf[partition] ? "bootable" : "non-bootable");
printf( "Partition start (head: 0x%02X cyl: 0x%03X sect: 0x%02X)\n",
buf[partition +1], (buf[partition +2] & 0xc0) << 2 | buf[partition +3] ,buf[partition +2] & 0x3f );
printf( "Systemindicator: 0x%02X (", buf[partition +4]);
 
switch (buf[partition +4])
{
case 0: printf ("Non DOS"); break;
case 1: printf ("DOS FAT12"); break;
case 4: printf ("DOS FAT16"); break;
case 5: printf ("DOS extended"); break;
case 6: printf ("DOS >32MByte"); break;
 
default : printf ("unkown");
};
printf (")\n");
printf( "Partition end (head: 0x%02X cyl: 0x%03X sect: 0x%02X)\n",
buf[partition +5], (buf[partition +6] & 0xc0) << 2 | buf[partition +7] ,buf[partition +6] & 0x3f );
printf( "Physical Startsector: 0x%08X\n", buf[partition +11] << 24 |
buf[partition +10] << 16 |
buf[partition +9] << 8 |
buf[partition +8]);
printf( "Sector count: 0x%08X\n", buf[partition +15] << 24 |
buf[partition +14] << 16 |
buf[partition +13] << 8 |
buf[partition +12]);
}
}
return 0;
}
 
 
/*
A T A _ R E A D _ D O S B O O T
 
Reads boot sector from the device and dumps it's contents to the screen
*/
int ata_read_dosboot_cmd(int argc, char **argv)
{
struct request request;
unsigned int sector;
char txt[8];
 
sector = 0;
if (argc)
sector = strtoul(*argv, argv, 0);
 
/* check for busy flag */
if ( ata_dev_busy(ATA_BASE_ADDR) )
printf("Selected ata device busy, ignoring command\n");
460,17 → 559,18
{
/* fill the request structure */
request.cmd = READ;
request.sector = 0;
request.sector = sector;
request.nr_sectors = 1;
request.buffer = buf;
 
if ( ata_request(inode, filp, &request) )
{
printf("Error whilereading boot sector.\n");
printf("Error whilereading boot sector 0x%02X.\n", sector);
printf("Status register = 0x%02lX, error register = 0x%02lX\n", ata_astatus(ATA_BASE_ADDR), ata_error(ATA_BASE_ADDR) );
}
else
{
printf( "Reading boot sector 0x%02X\n", sector );
printf( "ID number: 0x%2X%2X%2X\n", buf[0], buf[1], buf[2] );
 
printf( "OEM-name and number: " );
520,7 → 620,7
return -1;
 
inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0');
 
ata_ioctl(inode, filp, ATA_IOCTL_SELECT_DEVICE, **argv - '0');
 
printf("Ata device %1d selected.\n", REG32(ATA_BASE_ADDR + ATA_DHR) & ATA_DHR_DEV ? 1 : 0);
541,9 → 641,9
 
dumps byte-data in a buffer of type short to the screen
and returns the byte-checksum
 
*buffer = pointer to (short)buffer
cnt = number of words to display
cnt = number of bytes to display
*/
unsigned char atabug_dump_data(unsigned char *buffer, int cnt)
{
556,9 → 656,9
buf_ptr = buffer;
 
/* display data */
for (i=0; i < cnt; i += bytes_per_line /2)
for (i=0; i < cnt; i += bytes_per_line)
{
printf("%2X ", i);
printf("%3X ", i);
 
/* print hexadecimal notation */
for (n=0; n < bytes_per_line; n++)
570,7 → 670,7
for (n=0; n < bytes_per_line; n++)
{
c = *buf_ptr++;
printf(" %c", isprint(c) ? c : '.');
printf("%c", isprint(c) ? c : '.');
checksum += c;
}
printf("\n");
579,3 → 679,4
return checksum;
}
 
 
/trunk/orpmon/cmds/hdbug.c
49,13 → 49,13
{
hdbug_num_commands = 0;
 
register_command ("mount", "<device> [<mode>]", "Opens ata device <device> and mounts the DOS filesystem on it.", hdbug_mount_cmd);
register_hdbug_command ("umount", "", "Unmounts the DOS filesystem and Closes the device.", hdbug_umount_cmd);
register_command ("hdbug", "<device> [<mode>]", "Opens ata device <device> & mounts DOS filesystem", hdbug_mount_cmd);
register_hdbug_command ("umount", "", "Unmounts DOS filesystem & Closes device", hdbug_umount_cmd);
 
register_hdbug_command ("dir", "", "dos 'dir' command.", hdbug_dir_cmd);
register_hdbug_command ("cd", "", "dos 'cd' command.", hdbug_cd_cmd);
register_hdbug_command ("help", "", "Display this help message", hdbug_help);
register_hdbug_command ("exit", "", "Exit hdbug and return to ORPmon (same as umount)", hdbug_umount_cmd);
register_hdbug_command ("exit", "", "Exit hdbug and return to ORPmon", hdbug_umount_cmd);
}
 
 
228,6 → 228,10
}
else
{
printf( "directory startsector: 0x%08lX\n", dos_params->ssector );
printf( "cluster startsector : 0x%08lX\n", dos_params->csector );
printf( "cluster startentry : 0x%08lX\n", dos_params->sentry );
 
/* device is opened, filesystem is mounted, start command prompt */
while ( !hdbug_mon_command() );
}
309,6 → 313,8
unsigned long ltmp;
unsigned short stmp;
 
char txt[9];
 
switch (entry->name[0]) {
case 0x00:
/* empty entry */
319,35 → 325,49
break;
 
default:
/* display date & time */
stmp = entry->date;
swap(&stmp, sizeof(short) );
printf( "%02d-%02d-%4d ",stmp & 0x1f, (stmp >> 5) & 0xf, ((stmp >> 9) & 0xffff) +1980);
/* check if entry is a label */
if (entry->attribute & ATT_LAB)
{
printf( "LABEL: " );
memcpy(txt, entry->name, 8);
txt[8] = '\0';
printf( "%s", txt);
memcpy(txt, entry->ext, 3);
txt[3] = '\0';
printf( "%s\n", txt);
}
else
{
/* display date & time */
stmp = entry->date;
swap(&stmp, sizeof(short) );
printf( "%02d-%02d-%4d ",stmp & 0x1f, (stmp >> 5) & 0xf, ((stmp >> 9) & 0xffff) +1980);
 
stmp = entry->time;
swap(&stmp, sizeof(short) );
printf( "%02d:%02d ", (stmp >> 11) & 0x1f, (stmp >> 5) & 0x3f );
stmp = entry->time;
swap(&stmp, sizeof(short) );
printf( "%02d:%02d ", (stmp >> 11) & 0x1f, (stmp >> 5) & 0x3f );
 
/* display directory bit */
printf( "%s ", entry->attribute & ATT_DIR ? "<DIR>" : " " );
/* display directory bit */
printf( "%s ", entry->attribute & ATT_DIR ? "<DIR>" : " " );
 
/* display filesize */
ltmp = entry->size;
swap(&ltmp, sizeof(unsigned long) );
printf( "%12ld ", ltmp );
/* display filesize */
ltmp = entry->size;
swap(&ltmp, sizeof(unsigned long) );
printf( "%12ld ", ltmp );
 
/* replace the first 'space' in the name by an null char */
*(char*)memchr(entry->name, 0x20, 8) = '\0';
printf( "%s", entry->name);
/* replace the first 'space' in the name by an null char */
*(char*)memchr(entry->name, 0x20, 8) = '\0';
printf( "%s", entry->name);
 
/* add extension */
if (entry->ext[0] != 0x20)
{
printf( ".%3s", entry->ext);
}
/* add extension */
if (entry->ext[0] != 0x20)
{
printf( ".%3s", entry->ext);
}
 
printf("\n");
break;
printf("\n");
break;
}
}
 
return 0;
/trunk/orpmon/drivers/ata.c
67,10 → 67,12
 
char txt[41];
 
printf( "Checking device-id\n" );
/* check device-id (MINOR number) */
if ( (device = DEVICE(inode)) > 1 )
return EOPENIDEV;
 
printf( "Searching for hostcontroller: " );
/* get atahost id */
atahost = ata_ioctl(inode, filp, ATA_IOCTL_IDENTIFY_HOST, 0);
if (atahost)
87,19 → 89,29
/* check if the host has been opened already */
if (!usage[device]++)
{
printf( "Opening device for the first time\n" );
/* no, take device out of reset */
ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | ARG_HW_RST);
ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | ARG_SW_RST);
 
/* program PIO timing registers (set to PIO mode 0) */
ata_ioctl(inode, filp, ATA_IOCTL_SET_PIO, ARG_PIO0);
 
/* enable host controller (for old OCIDEC cores) */
ata_ioctl(inode, filp, ATA_IOCTL_ENABLE_HOST, 0);
}
 
/* select requested device */
ata_ioctl(inode, filp, ATA_IOCTL_SELECT_DEVICE, 0);
 
printf( "Executing IdentifyDevice command\n" );
/* identify requested ata-devices */
ata_ioctl(inode, filp, ATA_IOCTL_IDENTIFY_DEVICE, (unsigned long) buf);
ata_ioctl(inode, filp, ATA_IOCTL_EXEC_CMD, IDENTIFY_DEVICE);
 
/* read block from ata-device */
buf[0] = 256;
ata_ioctl(inode, filp, ATA_IOCTL_READ, (unsigned long) buf);
 
/* check if a valid device was found */
/* bit 15 in identify_device word0 must be '0',
or be equal to 0x848a (CFA feature set) */
110,49 → 122,49
}
 
/* Then check specific configuration word */
switch(buf[2]) {
case 0x37c8:
/* device does require SET_FEATURES
IDENTIFY_DEVICE response is incomplete */
case 0x738c:
/* device does require SET_FEATURES
IDENTIFY_DEVICE response is complete */
ata_ioctl(inode, filp, ATA_IOCTL_SET_FEATURES, 0); //FIXME
break;
case 0x8c73:
/* device does not require SET_FEATURES
IDENTIFY_DEVICE response is incomplete */
case 0xc837:
/* device does not require SET_FEATURES
IDENTIFY_DEVICE response is complete */
break;
if (buf[0] == 0x848a)
printf( "Found CompactFLASH device.\n" );
else
switch(buf[2]) {
case 0x37c8:
/* device does require SET_FEATURES
IDENTIFY_DEVICE response is incomplete */
case 0x738c:
/* device does require SET_FEATURES
IDENTIFY_DEVICE response is complete */
ata_ioctl(inode, filp, ATA_IOCTL_SET_FEATURES, 0); //FIXME
break;
case 0x8c73:
/* device does not require SET_FEATURES
IDENTIFY_DEVICE response is incomplete */
case 0xc837:
/* device does not require SET_FEATURES
IDENTIFY_DEVICE response is complete */
break;
 
default:
ata_release(inode, filp);
return EOPENNODEV;
}
default:
ata_release(inode, filp);
return EOPENNODEV;
}
 
/* checks ok */
 
/* extract data from device */
printf( "Device%1d: ", device);
 
/* display device model, serialnumber, and firmware revision */
memcpy(txt, &buf[27], 40);
txt[40] = '\0';
printf( "%s ", txt );
printf( "Model : %s\n", txt );
 
memcpy(txt, &buf[10], 20);
txt[20] = '\0';
printf( "%s ", txt );
printf( "Serial : %s\n", txt );
 
memcpy( txt, &buf[23], 8);
txt[8] = '\0';
printf( "%s\n", txt );
printf( "Firmware rev: %s\n", txt );
 
/* display size in MBytes */
sectors = (buf[61] << 16) | buf[60];
printf( " %ld MBytes ", sectors >> 11 ); /* assuming 512bytes per sector */
printf( " %ld MBytes ", sectors >> 11 ); /* assuming 512bytes per sector */
 
/* get supported pio modes */
dev_pio = buf[64];
196,7 → 208,20
}
 
 
/*
A T A _ R E A D _ D P O R T
 
closes ata device;
*/
int ata_read_dport(unsigned long base)
{
/* device ready to transfer data ?? */
while ( !ata_dev_datrdy(base) );
 
return REG32(base + ATA_DR);
}
 
 
/*
A T A _ I O C T L
*/
206,20 → 231,36
 
switch (command)
{
case ATA_IOCTL_IDENTIFY_DEVICE:
/* Reads the identify_device block */
case ATA_IOCTL_ENABLE_HOST:
/* enables the ATA host controller (sets IDE_EN bit) */
{
int i;
unsigned short *buf_ptr = (short *)argument;
REG32(base + ATA_CTRL) |= ATA_IDE_EN;
return 0;
}
 
/* send 'identify_device' command */
REG32(base + ATA_CR) = IDENTIFY_DEVICE;
 
/* read data from devices and store it in buffer */
for (i=0; i < 256; i++)
*buf_ptr++ = REG32(base + ATA_DR);
case ATA_IOCTL_EXEC_CMD:
/* sends a command to the ATA device */
{
while( ata_dev_busy(base) ); // wait for device ready
ata_cmd(base) = argument & 0xff;
return 0;
}
 
return 0;
 
case ATA_IOCTL_READ:
{
unsigned short *buf_ptr = (short *)argument;
int n, cnt;
 
cnt = buf_ptr[0];
for (n=0; n < cnt; n++)
{
while( !ata_dev_datrdy(base) ); // wait for data
*buf_ptr++ = ata_read_dport(base); // read data
}
 
return 0;
}
 
 
229,8 → 270,11
 
 
case ATA_IOCTL_SELECT_DEVICE:
/* selects ATA device
sets the DEV bit in the device/head register */
/* selects ATA device */
{
while( ata_dev_busy(base) ); // wait for device ready
/* sets the DEV bit in the device/head register */
if ( DEVICE(inode) )
REG32(base + ATA_DHR) |= ATA_DHR_DEV; /* select device1 */
else
237,10 → 281,12
REG32(base + ATA_DHR) &= ~ATA_DHR_DEV; /* select device0 */
 
return 0;
}
 
 
case ATA_IOCTL_SET_FTE:
/* set FTE bits */
{
/* set FTE bits */
if ( MINOR(inode->i_rdev) )
if (argument)
REG32(base + ATA_CTRL) |= ATA_IORDY_FTE0;
253,6 → 299,7
REG32(base + ATA_CTRL) &= ~ATA_IORDY_FTE1;
 
return 0;
}
 
 
case ATA_IOCTL_SET_PIO:
263,8 → 310,15
 
/* do we need to read the identify_device block ?? */
if (argument & (ARG_PIO4 | ARG_PIO3) )
ata_ioctl(inode, filp, ATA_IOCTL_IDENTIFY_DEVICE, (unsigned long) buf);
{
/* identify requested ata-devices */
ata_ioctl(inode, filp, ATA_IOCTL_EXEC_CMD, IDENTIFY_DEVICE);
 
/* read block from ata-device */
buf[0] = 256;
ata_ioctl(inode, filp, ATA_IOCTL_READ, (unsigned long) buf);
}
 
/* program register transfer timing registers */
/* set the slowest pio mode for register transfers */
if (argument < current_pio_mode)
412,7 → 466,7
 
 
default:
printf( "FIXME: Unsupported IOCTL call\n" );
printf( "FIXME: Unsupported IOCTL call %1d\n", command );
return EINVAL;
}
}
488,7 → 542,7
for (n=0; n < request->nr_sectors; n++)
for (i=0; i < sector_size; i++)
{
rd_data = REG32(base + ATA_DR);
rd_data = ata_read_dport(base);
 
/* the data is byte reversed, swap high & low bytes */
*buf_ptr++ = rd_data;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.