2003-06-13 18:17:17 +02:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stream/read_bytes.h>
|
|
|
|
#include <delay.h>
|
|
|
|
#include <string.h>
|
2004-03-13 04:09:57 +01:00
|
|
|
#include <pc80/ide.h>
|
2003-06-13 18:17:17 +02:00
|
|
|
|
2004-03-13 04:09:57 +01:00
|
|
|
#ifndef IDE_BOOT_DRIVE
|
|
|
|
#define IDE_BOOT_DRIVE 0
|
|
|
|
#endif
|
2003-06-13 18:17:17 +02:00
|
|
|
|
|
|
|
static unsigned long offset;
|
|
|
|
int stream_init(void)
|
|
|
|
{
|
|
|
|
int i,res;
|
|
|
|
|
|
|
|
printk_debug ("Trying polled ide\n");
|
|
|
|
printk_debug ("Waiting for ide disks to spin up\n");
|
|
|
|
printk_notice ("This is a hard coded delay and longer than necessary.\n");
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
printk_notice (".");
|
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
printk_info ("\n");
|
|
|
|
|
|
|
|
#ifdef ONE_TRACK
|
|
|
|
offset = (ONE_TRACK*512);
|
|
|
|
#elif defined(IDE_OFFSET)
|
|
|
|
offset = IDE_OFFSET;
|
|
|
|
#else
|
|
|
|
offset = 0x7e00;
|
|
|
|
#endif
|
2004-03-13 04:09:57 +01:00
|
|
|
res = ide_probe(IDE_BOOT_DRIVE);
|
2003-06-13 18:17:17 +02:00
|
|
|
delay(1);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stream_fini(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char buffer[512];
|
|
|
|
static unsigned int block_num = 0;
|
|
|
|
static unsigned int first_fill = 1;
|
2004-01-22 00:52:49 +01:00
|
|
|
static byte_offset_t stream_ide_read(void *vdest, byte_offset_t offset, byte_offset_t count)
|
2003-06-13 18:17:17 +02:00
|
|
|
{
|
|
|
|
byte_offset_t bytes = 0;
|
|
|
|
unsigned char *dest = vdest;
|
|
|
|
|
2004-01-22 00:52:49 +01:00
|
|
|
//printk_debug("stream_ide_read count = %x\n", count);
|
2003-06-13 18:17:17 +02:00
|
|
|
while (bytes < count) {
|
|
|
|
unsigned int byte_offset, len;
|
|
|
|
|
|
|
|
/* The block is not cached in memory or frist time called */
|
|
|
|
if (block_num != offset / 512 || first_fill) {
|
|
|
|
block_num = offset / 512;
|
|
|
|
printk_notice (".");
|
2004-01-22 00:52:49 +01:00
|
|
|
ide_read(IDE_BOOT_DRIVE, block_num, buffer);
|
2003-06-13 18:17:17 +02:00
|
|
|
first_fill = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte_offset = offset % 512;
|
|
|
|
len = 512 - byte_offset;
|
|
|
|
if (len > (count - bytes)) {
|
|
|
|
len = (count - bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(dest, buffer + byte_offset, len);
|
|
|
|
|
|
|
|
offset += len;
|
|
|
|
bytes += len;
|
|
|
|
dest += len;
|
|
|
|
|
|
|
|
}
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte_offset_t stream_read(void *vdest, byte_offset_t count)
|
|
|
|
{
|
|
|
|
byte_offset_t len;
|
|
|
|
|
2004-01-22 00:52:49 +01:00
|
|
|
len = stream_ide_read(vdest, offset, count);
|
2003-06-13 18:17:17 +02:00
|
|
|
if (len > 0) {
|
|
|
|
offset += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte_offset_t stream_skip(byte_offset_t count)
|
|
|
|
{
|
|
|
|
offset += count;
|
|
|
|
return count;
|
|
|
|
}
|