- TOM2 is filled in by the dynamic ACPI code. Don't hardcode it in the
[coreboot.git] / src / stream / ide_stream.c
1 #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>
7 #include <pc80/ide.h>
8
9 #ifndef IDE_BOOT_DRIVE
10 #define IDE_BOOT_DRIVE 0
11 #endif
12
13 static unsigned long offset;
14 int 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
34         res = ide_probe(IDE_BOOT_DRIVE);
35         delay(1);
36         return res;
37 }
38
39 void stream_fini(void)
40 {
41         return;
42 }
43
44 static unsigned char buffer[512];
45 static unsigned int block_num = 0;
46 static unsigned int first_fill = 1;
47 static byte_offset_t stream_ide_read(void *vdest, byte_offset_t offset, byte_offset_t count)
48 {
49         byte_offset_t bytes = 0;
50         unsigned char *dest = vdest;
51
52         //printk_debug("stream_ide_read count = %x\n", count);
53         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 (".");
60                         ide_read(IDE_BOOT_DRIVE, block_num, buffer);
61                         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
70                 memcpy(dest, buffer + byte_offset, len);
71
72                 offset += len;
73                 bytes += len;
74                 dest += len;
75
76         }
77         return bytes;
78 }
79
80 byte_offset_t stream_read(void *vdest, byte_offset_t count)
81 {
82         byte_offset_t len;
83
84         len = stream_ide_read(vdest, offset, count);
85         if (len > 0) {
86                 offset += len;
87         }
88
89         return len;
90 }
91
92 byte_offset_t stream_skip(byte_offset_t count)
93 {
94         offset += count;
95         return count;
96 }