blob: 0dd9a912585fed457cb99bbe41f02636665441be [file] [log] [blame]
Greg Watson0d796732003-06-13 16:17:17 +00001#include <console/console.h>
2#include <stdlib.h>
3#include <stddef.h>
4#include <stream/read_bytes.h>
5#include <delay.h>
6#include <string.h>
Greg Watsonb9f5c112004-03-13 03:09:57 +00007#include <pc80/ide.h>
Greg Watson0d796732003-06-13 16:17:17 +00008
Greg Watsonb9f5c112004-03-13 03:09:57 +00009#ifndef IDE_BOOT_DRIVE
10#define IDE_BOOT_DRIVE 0
11#endif
Greg Watson0d796732003-06-13 16:17:17 +000012
13static unsigned long offset;
14int stream_init(void)
15{
16 int i,res;
17
18 printk_debug ("Trying polled ide\n");
19 printk_debug ("Waiting for ide disks to spin up\n");
20 printk_notice ("This is a hard coded delay and longer than necessary.\n");
21 for (i = 0; i < 2; i++) {
22 printk_notice (".");
23 delay(1);
24 }
25 printk_info ("\n");
26
27#ifdef ONE_TRACK
28 offset = (ONE_TRACK*512);
29#elif defined(IDE_OFFSET)
30 offset = IDE_OFFSET;
31#else
32 offset = 0x7e00;
33#endif
Greg Watsonb9f5c112004-03-13 03:09:57 +000034 res = ide_probe(IDE_BOOT_DRIVE);
Greg Watson0d796732003-06-13 16:17:17 +000035 delay(1);
36 return res;
37}
38
39void stream_fini(void)
40{
41 return;
42}
43
Greg Watson0d796732003-06-13 16:17:17 +000044static unsigned char buffer[512];
45static unsigned int block_num = 0;
46static unsigned int first_fill = 1;
Greg Watson456764d2004-01-21 23:52:49 +000047static byte_offset_t stream_ide_read(void *vdest, byte_offset_t offset, byte_offset_t count)
Greg Watson0d796732003-06-13 16:17:17 +000048{
49 byte_offset_t bytes = 0;
50 unsigned char *dest = vdest;
51
Greg Watson456764d2004-01-21 23:52:49 +000052 //printk_debug("stream_ide_read count = %x\n", count);
Greg Watson0d796732003-06-13 16:17:17 +000053 while (bytes < count) {
54 unsigned int byte_offset, len;
55
56 /* The block is not cached in memory or frist time called */
57 if (block_num != offset / 512 || first_fill) {
58 block_num = offset / 512;
59 printk_notice (".");
Greg Watson456764d2004-01-21 23:52:49 +000060 ide_read(IDE_BOOT_DRIVE, block_num, buffer);
Greg Watson0d796732003-06-13 16:17:17 +000061 first_fill = 0;
62 }
63
64 byte_offset = offset % 512;
65 len = 512 - byte_offset;
66 if (len > (count - bytes)) {
67 len = (count - bytes);
68 }
69
Greg Watson0d796732003-06-13 16:17:17 +000070 memcpy(dest, buffer + byte_offset, len);
Greg Watson0d796732003-06-13 16:17:17 +000071
72 offset += len;
73 bytes += len;
74 dest += len;
75
76 }
77 return bytes;
78}
79
80byte_offset_t stream_read(void *vdest, byte_offset_t count)
81{
82 byte_offset_t len;
83
Greg Watson456764d2004-01-21 23:52:49 +000084 len = stream_ide_read(vdest, offset, count);
Greg Watson0d796732003-06-13 16:17:17 +000085 if (len > 0) {
86 offset += len;
87 }
88
89 return len;
90}
91
92byte_offset_t stream_skip(byte_offset_t count)
93{
94 offset += count;
95 return count;
96}